|
|
@@ -1,5 +1,6 @@
|
|
|
package com.chuanghai.ihotel.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -18,42 +19,22 @@ import com.chuanghai.ihotel.config.RabbitMQConfig;
|
|
|
import com.chuanghai.ihotel.constant.TimeConstant;
|
|
|
import com.chuanghai.ihotel.controller.request.ConfrimOrderRequest;
|
|
|
import com.chuanghai.ihotel.controller.request.OrderQueryRequest;
|
|
|
+import com.chuanghai.ihotel.controller.request.StatisticalReportRequest;
|
|
|
import com.chuanghai.ihotel.controller.request.SubmitOrderRequest;
|
|
|
import com.chuanghai.ihotel.dao.HotelOrderDao;
|
|
|
-import com.chuanghai.ihotel.dto.BillHandleResultDTO;
|
|
|
-import com.chuanghai.ihotel.dto.EventMessageDTO;
|
|
|
-import com.chuanghai.ihotel.dto.LockRoomDTO;
|
|
|
-import com.chuanghai.ihotel.entity.HotelOrderBillEntity;
|
|
|
-import com.chuanghai.ihotel.entity.HotelOrderEntity;
|
|
|
-import com.chuanghai.ihotel.entity.HotelUserEntity;
|
|
|
-import com.chuanghai.ihotel.entity.RoomDoorLockDataEntity;
|
|
|
-import com.chuanghai.ihotel.entity.RoomEntity;
|
|
|
-import com.chuanghai.ihotel.entity.RoomTypeEntity;
|
|
|
-import com.chuanghai.ihotel.entity.SystemSettingEntity;
|
|
|
+import com.chuanghai.ihotel.dto.*;
|
|
|
+import com.chuanghai.ihotel.entity.*;
|
|
|
import com.chuanghai.ihotel.enums.EventMessageTypeEnum;
|
|
|
import com.chuanghai.ihotel.enums.OrderBillStatuEnum;
|
|
|
import com.chuanghai.ihotel.enums.OrderStatuEnum;
|
|
|
import com.chuanghai.ihotel.enums.SystemNoticeTypeEnum;
|
|
|
import com.chuanghai.ihotel.enums.UserIdentityTypeEnum;
|
|
|
-import com.chuanghai.ihotel.service.HotelOrderBillService;
|
|
|
-import com.chuanghai.ihotel.service.HotelOrderService;
|
|
|
-import com.chuanghai.ihotel.service.HotelUserService;
|
|
|
-import com.chuanghai.ihotel.service.RoomDoorLockDataService;
|
|
|
-import com.chuanghai.ihotel.service.RoomRealtimeStatuService;
|
|
|
-import com.chuanghai.ihotel.service.RoomService;
|
|
|
-import com.chuanghai.ihotel.service.RoomTypeService;
|
|
|
-import com.chuanghai.ihotel.service.SystemNoticeService;
|
|
|
-import com.chuanghai.ihotel.service.SystemSettingService;
|
|
|
+import com.chuanghai.ihotel.service.*;
|
|
|
import com.chuanghai.ihotel.util.CommonUtil;
|
|
|
-import com.chuanghai.ihotel.vo.AdminOrderIndexVO;
|
|
|
-import com.chuanghai.ihotel.vo.ConfirmOrderVO;
|
|
|
-import com.chuanghai.ihotel.dto.LoginUserDTO;
|
|
|
-import com.chuanghai.ihotel.vo.OrderBillHandleVO;
|
|
|
-import com.chuanghai.ihotel.vo.OrderSubmitVO;
|
|
|
-import com.chuanghai.ihotel.vo.RoomRealDataStatuVO;
|
|
|
-import com.chuanghai.ihotel.vo.UserOrderDetailVO;
|
|
|
-import com.chuanghai.ihotel.vo.UserOrderIndexVO;
|
|
|
+import com.chuanghai.ihotel.util.FiledUtil;
|
|
|
+import com.chuanghai.ihotel.vo.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.xmlbeans.impl.piccolo.util.DuplicateKeyException;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -61,16 +42,17 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.sql.SQLIntegrityConstraintViolationException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -105,6 +87,8 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
@Autowired
|
|
|
private RabbitMQConfig rabbitMQConfig;
|
|
|
+ @Autowired
|
|
|
+ private StatisticalReportService statisticalReportService;
|
|
|
|
|
|
private DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
private String noticeTemplate = "办理入住成功,您的房号为【%s】,房间锁密码为:【%s】,密码有效时间为【%s】,请妥善保管,退房后密码自动失效。";
|
|
|
@@ -196,6 +180,194 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
return pageUtils;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出订单
|
|
|
+ *
|
|
|
+ * @param pageParam
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void downOrder(HttpServletResponse response, PageParam pageParam, OrderQueryRequest request) {
|
|
|
+ List<HotelAndBillVO> hotelAndBillVOList = new ArrayList<>();
|
|
|
+ List<AdminOrderIndexVO> list = this.pageForAdmin(pageParam, request).getList();
|
|
|
+ list.forEach(orderAndBill -> {
|
|
|
+ HotelAndBillVO hotelAndBillVO = new HotelAndBillVO();
|
|
|
+ HotelOrderEntity order = orderAndBill.getOrder();
|
|
|
+ HotelOrderBillEntity orderBill = orderAndBill.getOrderBill();
|
|
|
+ hotelAndBillVO.setOrderNo(order.getOrderNo());
|
|
|
+ hotelAndBillVO.setRoomNo(order.getRoomNo());
|
|
|
+ hotelAndBillVO.setOrderStatu(order.getOrderStatu());
|
|
|
+ hotelAndBillVO.setPayTime(order.getPayTime());
|
|
|
+
|
|
|
+ //电费计算
|
|
|
+ String startOfElectric = this.check(orderBill, "startOfWater");
|
|
|
+
|
|
|
+ String endOfElectric = this.check(orderBill, "endOfWater");
|
|
|
+
|
|
|
+ String priceOfElectric = this.check(orderBill, "priceOfElectric");
|
|
|
+
|
|
|
+ String calculateElectric = this.calculate(startOfElectric, endOfElectric, priceOfElectric);
|
|
|
+ hotelAndBillVO.setElectricity(calculateElectric);
|
|
|
+
|
|
|
+ //水费计算
|
|
|
+ String startOfWater = this.check(orderBill, "startOfWater");
|
|
|
+
|
|
|
+ String endOfWater = this.check(orderBill, "endOfWater");
|
|
|
+
|
|
|
+ String priceOfWater = this.check(orderBill, "priceOfWater");
|
|
|
+
|
|
|
+ String calculateWater = this.calculate(startOfWater, endOfWater, priceOfWater);
|
|
|
+ hotelAndBillVO.setWaterBill(calculateWater);
|
|
|
+ SystemSettingEntity systemSetting = systemSettingService.get();
|
|
|
+ //收预付款
|
|
|
+ hotelAndBillVO.setAcceptPayment(systemSetting.getFreeTotal());
|
|
|
+ //退预付款
|
|
|
+ BigDecimal refundPayment = systemSetting.getFreeTotal().subtract(order.getPayAmount());
|
|
|
+ hotelAndBillVO.setRefundPayment(refundPayment);
|
|
|
+ hotelAndBillVO.setCreateTime(order.getCreateTime());
|
|
|
+ hotelAndBillVO.setPayTime(order.getPayTime());
|
|
|
+ hotelAndBillVOList.add(hotelAndBillVO);
|
|
|
+ });
|
|
|
+
|
|
|
+ String fileName;
|
|
|
+ try {
|
|
|
+ fileName = URLEncoder.encode("订单管理" + new Date().getTime(), "UTF-8");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+
|
|
|
+ EasyExcel.write(response.getOutputStream(), HotelAndBillVO.class).sheet("订单管理").doWrite(hotelAndBillVOList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计报表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void statisticalReport() {
|
|
|
+ LocalDateTime firstDayOfMonth = LocalDateTime.of(LocalDate.from(LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth())), LocalTime.MIN);
|
|
|
+ LocalDateTime lastDayOfMonth = LocalDateTime.of(LocalDate.from(LocalDateTime.now().with(TemporalAdjusters.lastDayOfMonth())), LocalTime.MAX);
|
|
|
+ List<AdminOrderIndexVO> voList = this.queryByMonthHotelOrder(firstDayOfMonth, lastDayOfMonth);
|
|
|
+ BigDecimal waterPayment = BigDecimal.ZERO;
|
|
|
+ BigDecimal electricPayment = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalPayment = BigDecimal.ZERO;
|
|
|
+ //住房总押金 单价 * 天数
|
|
|
+ int housDay = 0;
|
|
|
+
|
|
|
+ StatisticalReportEntity statisticalReport = new StatisticalReportEntity();
|
|
|
+ for (AdminOrderIndexVO orderAndBill : voList) {
|
|
|
+
|
|
|
+ HotelOrderEntity order = orderAndBill.getOrder();
|
|
|
+ HotelOrderBillEntity orderBill = orderAndBill.getOrderBill();
|
|
|
+ //电费计算
|
|
|
+ String startOfElectric = this.check(orderBill, "startOfWater");
|
|
|
+
|
|
|
+ String endOfElectric = this.check(orderBill, "endOfWater");
|
|
|
+
|
|
|
+ String priceOfElectric = this.check(orderBill, "priceOfElectric");
|
|
|
+
|
|
|
+ String calculateElectric = this.calculate(startOfElectric, endOfElectric, priceOfElectric);
|
|
|
+
|
|
|
+ electricPayment = electricPayment.add(new BigDecimal(calculateElectric)).setScale(2, BigDecimal.ROUND_UP);
|
|
|
+ //水费计算
|
|
|
+ String startOfWater = this.check(orderBill, "startOfWater");
|
|
|
+
|
|
|
+ String endOfWater = this.check(orderBill, "endOfWater");
|
|
|
+
|
|
|
+ String priceOfWater = this.check(orderBill, "priceOfWater");
|
|
|
+
|
|
|
+ String calculateWater = this.calculate(startOfWater, endOfWater, priceOfWater);
|
|
|
+ waterPayment = waterPayment.add(new BigDecimal(calculateWater)).setScale(2, BigDecimal.ROUND_UP);
|
|
|
+
|
|
|
+ //收款总计
|
|
|
+ totalPayment = totalPayment.add(order.getPayAmount()).setScale(2, BigDecimal.ROUND_UP);
|
|
|
+
|
|
|
+ housDay = order.getEnableEndTime().getDayOfMonth() - order.getEnableStartTime().getDayOfMonth();
|
|
|
+ }
|
|
|
+
|
|
|
+ StatisticalReportEntity statisticalReportEntity = queryByMonth(firstDayOfMonth);
|
|
|
+ if (statisticalReportEntity != null) {
|
|
|
+ statisticalReport.setId(statisticalReportEntity.getId());
|
|
|
+ }
|
|
|
+ SystemSettingEntity systemSetting = systemSettingService.get();
|
|
|
+ //住房总押金 单价 * 天数
|
|
|
+ BigDecimal totalHousDeposit = systemSetting.getDeposit().multiply(new BigDecimal(housDay)).setScale(2, BigDecimal.ROUND_UP);
|
|
|
+
|
|
|
+
|
|
|
+ statisticalReport.setTime(firstDayOfMonth);
|
|
|
+ statisticalReport.setElectricPayment(electricPayment);
|
|
|
+ statisticalReport.setWaterPayment(waterPayment);
|
|
|
+ //退预付款 = 水电减免 + 住房押金 - 水费总额 - 电费总额
|
|
|
+ statisticalReport.setRefundPayment(systemSetting.getFreeTotal().add(totalHousDeposit).subtract(electricPayment).subtract(waterPayment));
|
|
|
+ statisticalReport.setTotalPayment(totalPayment);
|
|
|
+
|
|
|
+ statisticalReportService.saveOrUpdate(statisticalReport);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String check (HotelOrderBillEntity orderBill, String field) {
|
|
|
+ String result = "0.0";
|
|
|
+ boolean isPWaterNull = FiledUtil.checkObjFieldsIsNull(orderBill, field);
|
|
|
+ if (!isPWaterNull) {
|
|
|
+ result = orderBill.getPriceOfWater();
|
|
|
+ result = result.equals("0E-8") ? "0.0" : result;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public StatisticalReportEntity queryByMonth(LocalDateTime dateTime){
|
|
|
+ QueryWrapper<StatisticalReportEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("time", dateTime);
|
|
|
+ return statisticalReportService.getOne(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AdminOrderIndexVO> queryByMonthHotelOrder(LocalDateTime startTime, LocalDateTime endTime) {
|
|
|
+
|
|
|
+ QueryWrapper<HotelOrderEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("order_statu", "5");
|
|
|
+ wrapper.between("pay_time", startTime, endTime);
|
|
|
+ List<HotelOrderEntity> orderList = this.list(wrapper);
|
|
|
+ List<AdminOrderIndexVO> voList = new ArrayList<>();
|
|
|
+ Set<Long> ids = orderList.stream().map(order -> order.getId()).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ List<HotelOrderBillEntity> orderBillList = orderBillService.findByOrderIds(ids);
|
|
|
+ Map<Long, HotelOrderBillEntity> orderBillMap = orderBillList.stream().collect(Collectors.toMap(HotelOrderBillEntity::getHotelOrderId, e -> e));
|
|
|
+
|
|
|
+ voList = orderList.stream().map(order -> {
|
|
|
+ AdminOrderIndexVO vo = new AdminOrderIndexVO();
|
|
|
+ vo.setOrder(order);
|
|
|
+ vo.setOrderBill(orderBillMap.get(order.getId()));
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算水电费用
|
|
|
+ *
|
|
|
+ * @param start
|
|
|
+ * @param end
|
|
|
+ * @param price
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String calculate(String start, String end, String price) {
|
|
|
+ Double sum = Double.parseDouble(end) - Double.parseDouble(start);
|
|
|
+ String result = String.valueOf(sum * Double.parseDouble(price));
|
|
|
+ result = result.equals("-0.0") ? "0.0" : result;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public HotelOrderEntity findByOrderNo(String orderNo) {
|
|
|
QueryWrapper<HotelOrderEntity> queryWrapper = new QueryWrapper<>();
|
|
|
@@ -240,7 +412,7 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
ConfirmOrderVO vo = new ConfirmOrderVO();
|
|
|
vo.setStartTime(startTime);
|
|
|
vo.setEndTime(endTime);
|
|
|
- vo.setNums(Integer.valueOf((int)days));
|
|
|
+ vo.setNums(Integer.valueOf((int) days));
|
|
|
vo.setRoomTypeId(roomTypeId);
|
|
|
vo.setRoomTypeName(roomType.getTypeName());
|
|
|
vo.setFreeNum(enableNum >= 0 ? enableNum : 0);
|
|
|
@@ -388,7 +560,7 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
public void handleOrderMessage(EventMessageDTO eventMessageDTO) {
|
|
|
String messageType = eventMessageDTO.getEventMessageType();
|
|
|
try {
|
|
|
- if(EventMessageTypeEnum.PRODUCT_ORDER_NEW.name().equalsIgnoreCase(messageType)) {
|
|
|
+ if (EventMessageTypeEnum.PRODUCT_ORDER_NEW.name().equalsIgnoreCase(messageType)) {
|
|
|
// 关单消息
|
|
|
this.closeOrder(eventMessageDTO);
|
|
|
}
|
|
|
@@ -607,11 +779,13 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
LocalDateTime endTime = roomDoorLockDataEntity.getEndTime();
|
|
|
|
|
|
String content = String.format(noticeTemplate, order.getRoomNo(), lockRealtimePassword, dtf.format(startTime) + "-" + dtf.format(endTime));
|
|
|
- weiXiaoComponent.sendNotice(Arrays.asList(order.getUserFlag()),"公寓办理入住成功", "办理入住成功", content, null);
|
|
|
- } catch (Exception e) {}
|
|
|
+ weiXiaoComponent.sendNotice(Arrays.asList(order.getUserFlag()), "公寓办理入住成功", "办理入住成功", content, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
String returnOrderTemplate = "订单id【%s】,用户【%s】,房间号【%s】已退房,需要清扫";
|
|
|
+
|
|
|
@Override
|
|
|
public OrderBillHandleVO userReturnOrder(Long orderId) {
|
|
|
HotelOrderEntity order = userGetOrderById(orderId);
|
|
|
@@ -732,8 +906,10 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 用户根据订单id获取订单
|
|
|
+ *
|
|
|
* @param orderId
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -756,4 +932,4 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
|
|
|
return orderEntity;
|
|
|
}
|
|
|
-}
|
|
|
+}
|