| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- package com.template.services.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.template.common.utils.DateUtil;
- import com.template.mapper.HouseOrderMapper;
- import com.template.model.pojo.*;
- import com.template.model.result.PageUtils;
- import com.template.model.vo.*;
- import com.template.services.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.time.Duration;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.ZoneId;
- import java.time.format.DateTimeFormatter;
- import java.time.temporal.ChronoUnit;
- import java.util.Date;
- import java.util.List;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author ceshi
- * @since 2023-11-21
- */
- @Service
- public class HouseOrderServiceImpl extends ServiceImpl<HouseOrderMapper, HouseOrder> implements HouseOrderService {
- @Autowired
- HouseService houseService;
- @Autowired
- HousePriceService housePriceService;
- @Autowired
- UsersService usersService;
- @Autowired
- ClassScheduleService classScheduleService;
- @Autowired
- HouseOrderMapper houseOrderMapper;
- @Override
- public BigDecimal getHouseOrderPrice(int houseOrderNumber, String userId, String houseId, String liveTime, String leaveTime) {
- House house = houseService.getById(houseId);
- // 原价
- BigDecimal roomPrice = house.getRoomPrice();
- DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- LocalDateTime stateTime = LocalDateTime.parse(liveTime, dateTimeFormatter1);
- LocalDateTime endTime = LocalDateTime.parse(leaveTime, dateTimeFormatter1);
- LocalDate state = stateTime.toLocalDate();
- LocalDate end = endTime.toLocalDate();
- // 获取这段时间内的所有改价记录
- List<HousePrice> housePrices = housePriceService.housePrice(stateTime, endTime, houseId);
- // 是否是钟点房
- Integer roomType = house.getRoomType();
- if (roomType == 2) {
- // 计算小时差
- Duration duration = Duration.between(stateTime, endTime);
- // 小时差
- long hours = duration.toHours();
- if (ObjectUtils.isNotEmpty(housePrices)) {
- for (HousePrice housePrice : housePrices) {
- String setDate = housePrice.getSetDate();
- String[] split = setDate.split(",");
- Date startDate = DateUtil.parseDateOnly(split[0]);
- Date endDate = DateUtil.parseDateOnly(split[1]);
- Date date1 = Date.from(stateTime.atZone(ZoneId.systemDefault()).toInstant());
- // 判断当前时间是否在[startTime, endTime]区间
- assert startDate != null;
- boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
- if (effectiveDate) {
- BigDecimal price = housePrice.getPrice();
- BigDecimal totalPrice = price.multiply(new BigDecimal(houseOrderNumber));
- return totalPrice;
- }
- }
- }
- BigDecimal totalPrice = roomPrice.multiply(new BigDecimal(houseOrderNumber));
- return totalPrice;
- }
- // 计算2个时间差
- long until = state.until(end, ChronoUnit.DAYS);
- // 获取这断时间内的上 8 9节课的老师
- Users users = usersService.getById(userId);
- LambdaQueryWrapper<ClassSchedule> wrapperCS = new LambdaQueryWrapper<>();
- wrapperCS.eq(ClassSchedule::getJsgh, users.getCardNumber())
- .between(ClassSchedule::getDateTime, state, end);
- List<ClassSchedule> scheduleList = classScheduleService.list(wrapperCS);
- BigDecimal totalPrice = new BigDecimal(0);
- for (int i = 0; i < until; i++) {
- LocalDate localDate1 = state.plusDays(i);
- List<HousePrice> housePrices1 = housePriceService.getDatePrice(localDate1, houseId);
- // LocalDate localDate2 = state.plusDays(i+1);
- // List<HousePrice> housePrices = housePriceService.housePrice(localDate1, localDate2, houseId);
- if (ObjectUtils.isNotEmpty(scheduleList)) {
- for (ClassSchedule classSchedule : scheduleList) {
- String dateTime = classSchedule.getDateTime();
- String[] s = dateTime.split(" ");
- dateTime=s[0];
- LocalDate parse = LocalDate.parse(dateTime, dateTimeFormatter2);
- if (!localDate1.equals(parse)) {
- if (ObjectUtils.isNotEmpty(housePrices1)) {
- HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
- BigDecimal price = housePrice.getPrice();
- totalPrice = totalPrice.add(price);
- } else {
- totalPrice = totalPrice.add(roomPrice);
- }
- // for (HousePrice housePrice : housePrices1) {
- // String setDate = housePrice.getSetDate();
- // String[] split = setDate.split(",");
- // Date startDate = DateUtil.parseDateOnly(split[0]);
- // Date endDate = DateUtil.parseDateOnly(split[1]);
- // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
- // // 判断当前时间是否在[startTime, endTime]区间
- // assert startDate != null;
- // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
- // if (effectiveDate) {
- // BigDecimal price = housePrice.getPrice();
- // totalPrice = totalPrice.add(price);
- // } else {
- // totalPrice = totalPrice.add(roomPrice);
- // }
- // }
- }
- }
- } else {
- if (ObjectUtils.isNotEmpty(housePrices1)) {
- if (ObjectUtils.isNotEmpty(housePrices1)) {
- HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
- BigDecimal price = housePrice.getPrice();
- totalPrice = totalPrice.add(price);
- }
- // for (HousePrice housePrice : housePrices1) {
- // String setDate = housePrice.getSetDate();
- // String[] split = setDate.split(",");
- // Date startDate = DateUtil.parseDateOnly(split[0]);
- // Date endDate = DateUtil.parseDateOnly(split[1]);
- // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
- // // 判断当前时间是否在[startTime, endTime]区间
- // assert startDate != null;
- // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
- // if (effectiveDate) {
- // BigDecimal price = housePrice.getPrice();
- // totalPrice = totalPrice.add(price);
- // } else {
- // totalPrice = totalPrice.add(roomPrice);
- // }
- // }
- } else {
- totalPrice = totalPrice.add(roomPrice);
- }
- }
- }
- return totalPrice.multiply(new BigDecimal(houseOrderNumber));
- }
- @Override
- public PriceVo reservePrice(String houseId, String cardNumber, String liveTime, String leaveTime) {
- PriceVo priceVo = new PriceVo();
- House house = houseService.getById(houseId);
- // 原价
- BigDecimal roomPrice = house.getRoomPrice();
- DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- LocalDateTime stateTime = LocalDateTime.parse(liveTime, dateTimeFormatter1);
- LocalDateTime endTime = LocalDateTime.parse(leaveTime, dateTimeFormatter1);
- // 获取这段时间内的所有改价记录
- List<HousePrice> housePrices = housePriceService.housePrice(stateTime, endTime, houseId);
- // 是否是钟点房 是的话则不需要判断是否有免费的
- Integer roomType = house.getRoomType();
- if (roomType == 2) {
- // 计算小时差
- Duration duration = Duration.between(stateTime, endTime);
- // 小时差
- long hours = duration.toHours();
- if (ObjectUtils.isNotEmpty(housePrices)) {
- HousePrice housePrice = housePrices.get(housePrices.size() - 1);
- // for (HousePrice housePrice : housePrices) {
- // String setDate = housePrice.getSetDate();
- // String[] split = setDate.split(",");
- // Date startDate = DateUtil.parseDateOnly(split[0]);
- // Date endDate = DateUtil.parseDateOnly(split[1]);
- // Date date1 = Date.from(stateTime.atZone(ZoneId.systemDefault()).toInstant());
- // // 判断当前时间是否在[startTime, endTime]区间
- // assert startDate != null;
- // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
- // if (effectiveDate) {
- BigDecimal price = housePrice.getPrice();
- BigDecimal totalPrice = price;
- priceVo.setTotalPrice(totalPrice);
- priceVo.setPrice(price);
- return priceVo;
- // }
- // }
- }
- BigDecimal totalPrice = roomPrice;
- priceVo.setTotalPrice(totalPrice);
- priceVo.setPrice(roomPrice);
- return priceVo;
- }
- LocalDate state = LocalDateTime.parse(liveTime, dateTimeFormatter1).toLocalDate();
- LocalDate end = LocalDateTime.parse(leaveTime, dateTimeFormatter1).toLocalDate();
- // 计算2个时间差
- long until = state.until(end, ChronoUnit.DAYS);
- // 获取这断时间内的上 8 9节课的老师
- LambdaQueryWrapper<ClassSchedule> wrapperCS = new LambdaQueryWrapper<>();
- wrapperCS.eq(ClassSchedule::getJsgh, cardNumber)
- .between(ClassSchedule::getDateTime, state, end);
- List<ClassSchedule> scheduleList = classScheduleService.list(wrapperCS);
- BigDecimal totalPrice = new BigDecimal(0);
- for (int i = 0; i < until; i++) {
- LocalDate localDate1 = state.plusDays(i);
- List<HousePrice> housePrices1 = housePriceService.getDatePrice(localDate1, houseId);
- if (ObjectUtils.isNotEmpty(scheduleList)) {
- for (ClassSchedule classSchedule : scheduleList) {
- String dateTime = classSchedule.getDateTime();
- String[] s = dateTime.split(" ");
- dateTime=s[0];
- LocalDate parse = LocalDate.parse(dateTime, dateTimeFormatter2);
- if (!localDate1.equals(parse)) {
- if (ObjectUtils.isNotEmpty(housePrices1)) {
- HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
- BigDecimal price = housePrice.getPrice();
- totalPrice = totalPrice.add(price);
- } else {
- totalPrice = totalPrice.add(roomPrice);
- }
- // for (HousePrice housePrice : housePrices) {
- // String setDate = housePrice.getSetDate();
- // String[] split = setDate.split(",");
- // Date startDate = DateUtil.parseDateOnly(split[0]);
- // Date endDate = DateUtil.parseDateOnly(split[1]);
- // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
- // // 判断当前时间是否在[startTime, endTime]区间
- // assert startDate != null;
- // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
- // if (effectiveDate) {
- // BigDecimal price = housePrice.getPrice();
- // totalPrice = totalPrice.add(price);
- // } else {
- // totalPrice = totalPrice.add(roomPrice);
- // }
- // }
- }
- }
- } else {
- if (ObjectUtils.isNotEmpty(housePrices1)) {
- HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
- BigDecimal price = housePrice.getPrice();
- totalPrice = totalPrice.add(price);
- // for (HousePrice housePrice : housePrices) {
- // String setDate = housePrice.getSetDate();
- // String[] split = setDate.split(",");
- // Date startDate = DateUtil.parseDateOnly(split[0]);
- // Date endDate = DateUtil.parseDateOnly(split[1]);
- // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
- // // 判断当前时间是否在[startTime, endTime]区间
- // assert startDate != null;
- // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
- // if (effectiveDate) {
- // BigDecimal price = housePrice.getPrice();
- // totalPrice = totalPrice.add(price);
- // } else {
- // totalPrice = totalPrice.add(roomPrice);
- // }
- // }
- } else {
- totalPrice = totalPrice.add(roomPrice);
- }
- }
- }
- priceVo.setTotalPrice(totalPrice);
- BigDecimal price = new BigDecimal(0);
- if (totalPrice.doubleValue() > 0) {
- price = totalPrice.divide(new BigDecimal(until), 2, BigDecimal.ROUND_HALF_UP);
- }
- priceVo.setPrice(price);
- return priceVo;
- }
- @Override
- public PageUtils<HouseOrderPageListVo> pageList(int page, int size, String keyWord, String houseType, String orderStatus, String payPriceStartTime, String payPriceEndTime, String refundStartTime, String refundEndTime, String cancelStartTime, String cancelEndTime, String liveStartTime, String liveEndTime, String leaveStartTime, String leaveEndTime) {
- Page<HouseOrderPageListVo> pageVo = new Page<>(page, size);
- IPage<HouseOrderPageListVo> result = houseOrderMapper.pageList(pageVo, keyWord, houseType, orderStatus, payPriceStartTime, payPriceEndTime, refundStartTime, refundEndTime, cancelStartTime, cancelEndTime, liveStartTime, liveEndTime, leaveStartTime, leaveEndTime);
- return new PageUtils(result);
- }
- @Override
- public List<QueryExportVo> queryExport(String keyWord, String houseType, String orderStatus, String payPriceStartTime, String payPriceEndTime, String refundStartTime, String refundEndTime, String cancelStartTime, String cancelEndTime, String liveStartTime, String liveEndTime, String leaveStartTime, String leaveEndTime) {
- return houseOrderMapper.queryExport(keyWord, houseType, orderStatus, payPriceStartTime, payPriceEndTime, refundStartTime, refundEndTime, cancelStartTime, cancelEndTime, liveStartTime, liveEndTime, leaveStartTime, leaveEndTime);
- }
- @Override
- public HouseOrderCheckInShowVo getOrderNumbre(String orderNumber) {
- return houseOrderMapper.getOrderNumber(orderNumber);
- }
- @Override
- public PageUtils<ReportStatisticsVo> reportStatisticsPage(String s, String keyWord, String startTime, String endTime, int page, int size) {
- Page<ReportStatisticsVo> pageVo = new Page<>(page, size);
- IPage<ReportStatisticsVo> result = houseOrderMapper.reportStatisticsPage(pageVo, s, keyWord, startTime, endTime);
- return new PageUtils(result);
- }
- @Override
- public List<ReportStatisticsExportVo> reportStatisticsExport(String s, String keyWord, String startTime, String endTime) {
- return houseOrderMapper.reportStatisticsExport(s, keyWord, startTime, endTime);
- }
- @Override
- public List<String> payHouseOrderUser(LocalDateTime start, LocalDateTime end) {
- return houseOrderMapper.payHouseOrderUser(start, end);
- }
- }
|