HouseOrderServiceImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. package com.template.services.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.template.common.utils.DateUtil;
  8. import com.template.mapper.HouseOrderMapper;
  9. import com.template.model.pojo.*;
  10. import com.template.model.result.PageUtils;
  11. import com.template.model.vo.*;
  12. import com.template.services.*;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.math.BigDecimal;
  16. import java.time.Duration;
  17. import java.time.LocalDate;
  18. import java.time.LocalDateTime;
  19. import java.time.ZoneId;
  20. import java.time.format.DateTimeFormatter;
  21. import java.time.temporal.ChronoUnit;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * <p>
  26. * 服务实现类
  27. * </p>
  28. *
  29. * @author ceshi
  30. * @since 2023-11-21
  31. */
  32. @Service
  33. public class HouseOrderServiceImpl extends ServiceImpl<HouseOrderMapper, HouseOrder> implements HouseOrderService {
  34. @Autowired
  35. HouseService houseService;
  36. @Autowired
  37. HousePriceService housePriceService;
  38. @Autowired
  39. UsersService usersService;
  40. @Autowired
  41. ClassScheduleService classScheduleService;
  42. @Autowired
  43. HouseOrderMapper houseOrderMapper;
  44. @Override
  45. public BigDecimal getHouseOrderPrice(int houseOrderNumber, String userId, String houseId, String liveTime, String leaveTime) {
  46. House house = houseService.getById(houseId);
  47. // 原价
  48. BigDecimal roomPrice = house.getRoomPrice();
  49. DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  50. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  51. LocalDateTime stateTime = LocalDateTime.parse(liveTime, dateTimeFormatter1);
  52. LocalDateTime endTime = LocalDateTime.parse(leaveTime, dateTimeFormatter1);
  53. LocalDate state = stateTime.toLocalDate();
  54. LocalDate end = endTime.toLocalDate();
  55. // 获取这段时间内的所有改价记录
  56. List<HousePrice> housePrices = housePriceService.housePrice(stateTime, endTime, houseId);
  57. // 是否是钟点房
  58. Integer roomType = house.getRoomType();
  59. if (roomType == 2) {
  60. // 计算小时差
  61. Duration duration = Duration.between(stateTime, endTime);
  62. // 小时差
  63. long hours = duration.toHours();
  64. if (ObjectUtils.isNotEmpty(housePrices)) {
  65. for (HousePrice housePrice : housePrices) {
  66. String setDate = housePrice.getSetDate();
  67. String[] split = setDate.split(",");
  68. Date startDate = DateUtil.parseDateOnly(split[0]);
  69. Date endDate = DateUtil.parseDateOnly(split[1]);
  70. Date date1 = Date.from(stateTime.atZone(ZoneId.systemDefault()).toInstant());
  71. // 判断当前时间是否在[startTime, endTime]区间
  72. assert startDate != null;
  73. boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
  74. if (effectiveDate) {
  75. BigDecimal price = housePrice.getPrice();
  76. BigDecimal totalPrice = price.multiply(new BigDecimal(houseOrderNumber));
  77. return totalPrice;
  78. }
  79. }
  80. }
  81. BigDecimal totalPrice = roomPrice.multiply(new BigDecimal(houseOrderNumber));
  82. return totalPrice;
  83. }
  84. // 计算2个时间差
  85. long until = state.until(end, ChronoUnit.DAYS);
  86. // 获取这断时间内的上 8 9节课的老师
  87. Users users = usersService.getById(userId);
  88. LambdaQueryWrapper<ClassSchedule> wrapperCS = new LambdaQueryWrapper<>();
  89. wrapperCS.eq(ClassSchedule::getJsgh, users.getCardNumber())
  90. .between(ClassSchedule::getDateTime, state, end);
  91. List<ClassSchedule> scheduleList = classScheduleService.list(wrapperCS);
  92. BigDecimal totalPrice = new BigDecimal(0);
  93. for (int i = 0; i < until; i++) {
  94. LocalDate localDate1 = state.plusDays(i);
  95. List<HousePrice> housePrices1 = housePriceService.getDatePrice(localDate1, houseId);
  96. // LocalDate localDate2 = state.plusDays(i+1);
  97. // List<HousePrice> housePrices = housePriceService.housePrice(localDate1, localDate2, houseId);
  98. if (ObjectUtils.isNotEmpty(scheduleList)) {
  99. for (ClassSchedule classSchedule : scheduleList) {
  100. String dateTime = classSchedule.getDateTime();
  101. String[] s = dateTime.split(" ");
  102. dateTime=s[0];
  103. LocalDate parse = LocalDate.parse(dateTime, dateTimeFormatter2);
  104. if (!localDate1.equals(parse)) {
  105. if (ObjectUtils.isNotEmpty(housePrices1)) {
  106. HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
  107. BigDecimal price = housePrice.getPrice();
  108. totalPrice = totalPrice.add(price);
  109. } else {
  110. totalPrice = totalPrice.add(roomPrice);
  111. }
  112. // for (HousePrice housePrice : housePrices1) {
  113. // String setDate = housePrice.getSetDate();
  114. // String[] split = setDate.split(",");
  115. // Date startDate = DateUtil.parseDateOnly(split[0]);
  116. // Date endDate = DateUtil.parseDateOnly(split[1]);
  117. // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
  118. // // 判断当前时间是否在[startTime, endTime]区间
  119. // assert startDate != null;
  120. // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
  121. // if (effectiveDate) {
  122. // BigDecimal price = housePrice.getPrice();
  123. // totalPrice = totalPrice.add(price);
  124. // } else {
  125. // totalPrice = totalPrice.add(roomPrice);
  126. // }
  127. // }
  128. }
  129. }
  130. } else {
  131. if (ObjectUtils.isNotEmpty(housePrices1)) {
  132. if (ObjectUtils.isNotEmpty(housePrices1)) {
  133. HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
  134. BigDecimal price = housePrice.getPrice();
  135. totalPrice = totalPrice.add(price);
  136. }
  137. // for (HousePrice housePrice : housePrices1) {
  138. // String setDate = housePrice.getSetDate();
  139. // String[] split = setDate.split(",");
  140. // Date startDate = DateUtil.parseDateOnly(split[0]);
  141. // Date endDate = DateUtil.parseDateOnly(split[1]);
  142. // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
  143. // // 判断当前时间是否在[startTime, endTime]区间
  144. // assert startDate != null;
  145. // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
  146. // if (effectiveDate) {
  147. // BigDecimal price = housePrice.getPrice();
  148. // totalPrice = totalPrice.add(price);
  149. // } else {
  150. // totalPrice = totalPrice.add(roomPrice);
  151. // }
  152. // }
  153. } else {
  154. totalPrice = totalPrice.add(roomPrice);
  155. }
  156. }
  157. }
  158. return totalPrice.multiply(new BigDecimal(houseOrderNumber));
  159. }
  160. @Override
  161. public PriceVo reservePrice(String houseId, String cardNumber, String liveTime, String leaveTime) {
  162. PriceVo priceVo = new PriceVo();
  163. House house = houseService.getById(houseId);
  164. // 原价
  165. BigDecimal roomPrice = house.getRoomPrice();
  166. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  167. DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  168. LocalDateTime stateTime = LocalDateTime.parse(liveTime, dateTimeFormatter1);
  169. LocalDateTime endTime = LocalDateTime.parse(leaveTime, dateTimeFormatter1);
  170. // 获取这段时间内的所有改价记录
  171. List<HousePrice> housePrices = housePriceService.housePrice(stateTime, endTime, houseId);
  172. // 是否是钟点房 是的话则不需要判断是否有免费的
  173. Integer roomType = house.getRoomType();
  174. if (roomType == 2) {
  175. // 计算小时差
  176. Duration duration = Duration.between(stateTime, endTime);
  177. // 小时差
  178. long hours = duration.toHours();
  179. if (ObjectUtils.isNotEmpty(housePrices)) {
  180. HousePrice housePrice = housePrices.get(housePrices.size() - 1);
  181. // for (HousePrice housePrice : housePrices) {
  182. // String setDate = housePrice.getSetDate();
  183. // String[] split = setDate.split(",");
  184. // Date startDate = DateUtil.parseDateOnly(split[0]);
  185. // Date endDate = DateUtil.parseDateOnly(split[1]);
  186. // Date date1 = Date.from(stateTime.atZone(ZoneId.systemDefault()).toInstant());
  187. // // 判断当前时间是否在[startTime, endTime]区间
  188. // assert startDate != null;
  189. // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
  190. // if (effectiveDate) {
  191. BigDecimal price = housePrice.getPrice();
  192. BigDecimal totalPrice = price;
  193. priceVo.setTotalPrice(totalPrice);
  194. priceVo.setPrice(price);
  195. return priceVo;
  196. // }
  197. // }
  198. }
  199. BigDecimal totalPrice = roomPrice;
  200. priceVo.setTotalPrice(totalPrice);
  201. priceVo.setPrice(roomPrice);
  202. return priceVo;
  203. }
  204. LocalDate state = LocalDateTime.parse(liveTime, dateTimeFormatter1).toLocalDate();
  205. LocalDate end = LocalDateTime.parse(leaveTime, dateTimeFormatter1).toLocalDate();
  206. // 计算2个时间差
  207. long until = state.until(end, ChronoUnit.DAYS);
  208. // 获取这断时间内的上 8 9节课的老师
  209. LambdaQueryWrapper<ClassSchedule> wrapperCS = new LambdaQueryWrapper<>();
  210. wrapperCS.eq(ClassSchedule::getJsgh, cardNumber)
  211. .between(ClassSchedule::getDateTime, state, end);
  212. List<ClassSchedule> scheduleList = classScheduleService.list(wrapperCS);
  213. BigDecimal totalPrice = new BigDecimal(0);
  214. for (int i = 0; i < until; i++) {
  215. LocalDate localDate1 = state.plusDays(i);
  216. List<HousePrice> housePrices1 = housePriceService.getDatePrice(localDate1, houseId);
  217. if (ObjectUtils.isNotEmpty(scheduleList)) {
  218. for (ClassSchedule classSchedule : scheduleList) {
  219. String dateTime = classSchedule.getDateTime();
  220. String[] s = dateTime.split(" ");
  221. dateTime=s[0];
  222. LocalDate parse = LocalDate.parse(dateTime, dateTimeFormatter2);
  223. if (!localDate1.equals(parse)) {
  224. if (ObjectUtils.isNotEmpty(housePrices1)) {
  225. HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
  226. BigDecimal price = housePrice.getPrice();
  227. totalPrice = totalPrice.add(price);
  228. } else {
  229. totalPrice = totalPrice.add(roomPrice);
  230. }
  231. // for (HousePrice housePrice : housePrices) {
  232. // String setDate = housePrice.getSetDate();
  233. // String[] split = setDate.split(",");
  234. // Date startDate = DateUtil.parseDateOnly(split[0]);
  235. // Date endDate = DateUtil.parseDateOnly(split[1]);
  236. // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
  237. // // 判断当前时间是否在[startTime, endTime]区间
  238. // assert startDate != null;
  239. // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
  240. // if (effectiveDate) {
  241. // BigDecimal price = housePrice.getPrice();
  242. // totalPrice = totalPrice.add(price);
  243. // } else {
  244. // totalPrice = totalPrice.add(roomPrice);
  245. // }
  246. // }
  247. }
  248. }
  249. } else {
  250. if (ObjectUtils.isNotEmpty(housePrices1)) {
  251. HousePrice housePrice = housePrices1.get(housePrices1.size() - 1);
  252. BigDecimal price = housePrice.getPrice();
  253. totalPrice = totalPrice.add(price);
  254. // for (HousePrice housePrice : housePrices) {
  255. // String setDate = housePrice.getSetDate();
  256. // String[] split = setDate.split(",");
  257. // Date startDate = DateUtil.parseDateOnly(split[0]);
  258. // Date endDate = DateUtil.parseDateOnly(split[1]);
  259. // Date date1 = Date.from(localDate1.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
  260. // // 判断当前时间是否在[startTime, endTime]区间
  261. // assert startDate != null;
  262. // boolean effectiveDate = DateUtil.isEffectiveDate(date1, startDate, endDate);
  263. // if (effectiveDate) {
  264. // BigDecimal price = housePrice.getPrice();
  265. // totalPrice = totalPrice.add(price);
  266. // } else {
  267. // totalPrice = totalPrice.add(roomPrice);
  268. // }
  269. // }
  270. } else {
  271. totalPrice = totalPrice.add(roomPrice);
  272. }
  273. }
  274. }
  275. priceVo.setTotalPrice(totalPrice);
  276. BigDecimal price = new BigDecimal(0);
  277. if (totalPrice.doubleValue() > 0) {
  278. price = totalPrice.divide(new BigDecimal(until), 2, BigDecimal.ROUND_HALF_UP);
  279. }
  280. priceVo.setPrice(price);
  281. return priceVo;
  282. }
  283. @Override
  284. 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) {
  285. Page<HouseOrderPageListVo> pageVo = new Page<>(page, size);
  286. IPage<HouseOrderPageListVo> result = houseOrderMapper.pageList(pageVo, keyWord, houseType, orderStatus, payPriceStartTime, payPriceEndTime, refundStartTime, refundEndTime, cancelStartTime, cancelEndTime, liveStartTime, liveEndTime, leaveStartTime, leaveEndTime);
  287. return new PageUtils(result);
  288. }
  289. @Override
  290. 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) {
  291. return houseOrderMapper.queryExport(keyWord, houseType, orderStatus, payPriceStartTime, payPriceEndTime, refundStartTime, refundEndTime, cancelStartTime, cancelEndTime, liveStartTime, liveEndTime, leaveStartTime, leaveEndTime);
  292. }
  293. @Override
  294. public HouseOrderCheckInShowVo getOrderNumbre(String orderNumber) {
  295. return houseOrderMapper.getOrderNumber(orderNumber);
  296. }
  297. @Override
  298. public PageUtils<ReportStatisticsVo> reportStatisticsPage(String s, String keyWord, String startTime, String endTime, int page, int size) {
  299. Page<ReportStatisticsVo> pageVo = new Page<>(page, size);
  300. IPage<ReportStatisticsVo> result = houseOrderMapper.reportStatisticsPage(pageVo, s, keyWord, startTime, endTime);
  301. return new PageUtils(result);
  302. }
  303. @Override
  304. public List<ReportStatisticsExportVo> reportStatisticsExport(String s, String keyWord, String startTime, String endTime) {
  305. return houseOrderMapper.reportStatisticsExport(s, keyWord, startTime, endTime);
  306. }
  307. @Override
  308. public List<String> payHouseOrderUser(LocalDateTime start, LocalDateTime end) {
  309. return houseOrderMapper.payHouseOrderUser(start, end);
  310. }
  311. }