|
|
@@ -3,6 +3,7 @@ package com.chuanghai.ihotel.service.impl;
|
|
|
import com.chuanghai.ihotel.common.exception.BizCodeEnume;
|
|
|
import com.chuanghai.ihotel.common.exception.RRException;
|
|
|
import com.chuanghai.ihotel.component.WaterElectricComponent;
|
|
|
+import com.chuanghai.ihotel.dto.BillHandleResultDTO;
|
|
|
import com.chuanghai.ihotel.entity.RoomThirdSettingEntity;
|
|
|
import com.chuanghai.ihotel.entity.SystemSettingEntity;
|
|
|
import com.chuanghai.ihotel.service.RoomThirdSettingService;
|
|
|
@@ -22,6 +23,9 @@ import com.chuanghai.ihotel.service.HotelOrderBillService;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
@Service("hotelOrderBillService")
|
|
|
@@ -58,19 +62,9 @@ public class HotelOrderBillServiceImpl extends ServiceImpl<HotelOrderBillDao, Ho
|
|
|
SystemSettingEntity systemSetting = systemSettingService.get();
|
|
|
|
|
|
// 水电抄表
|
|
|
- RoomThirdSettingEntity waterElectricEntity = roomWaterElectricService.findByRoomId(roomId);
|
|
|
- if (waterElectricEntity == null) {
|
|
|
- throw new RRException(BizCodeEnume.PERMISSION_DENIED, "房间水电表数据读取失败");
|
|
|
- }
|
|
|
-
|
|
|
- String electricData = waterElectricComponent.queryPowerRealTimeData(waterElectricEntity.getElectricId());
|
|
|
- if (!StringUtils.hasText(electricData)) {
|
|
|
- throw new RRException(BizCodeEnume.UNKNOW_EXCEPTION, "读取电表数据异常");
|
|
|
- }
|
|
|
- String waterData = waterElectricComponent.queryLastHistoryCumulantInfo(waterElectricEntity.getWaterId());
|
|
|
- if (!StringUtils.hasText(waterData)) {
|
|
|
- throw new RRException(BizCodeEnume.UNKNOW_EXCEPTION, "读取电表数据异常");
|
|
|
- }
|
|
|
+ Map<String, String> returnParam = readWaterElectricData(roomId);
|
|
|
+ String electricData = returnParam.get("electricData");
|
|
|
+ String waterData = returnParam.get("waterData");
|
|
|
|
|
|
// 生成结账单
|
|
|
HotelOrderBillEntity orderBill = new HotelOrderBillEntity();
|
|
|
@@ -89,4 +83,95 @@ public class HotelOrderBillServiceImpl extends ServiceImpl<HotelOrderBillDao, Ho
|
|
|
this.save(orderBill);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public BillHandleResultDTO calcBill(Long orderId) {
|
|
|
+ // 系统设置
|
|
|
+ SystemSettingEntity systemSetting = systemSettingService.get();
|
|
|
+ HotelOrderBillEntity orderBill = findByOrderId(orderId);
|
|
|
+ if (orderBill == null) {
|
|
|
+ throw new RRException(BizCodeEnume.UNKNOW_EXCEPTION, "订单账单信息不存在");
|
|
|
+ }
|
|
|
+ Map<String, String> returnParam = readWaterElectricData(orderBill.getRoomId());
|
|
|
+ String electricData = returnParam.get("electricData");
|
|
|
+ String waterData = returnParam.get("waterData");
|
|
|
+
|
|
|
+ orderBill.setEndOfElectric(electricData);
|
|
|
+ orderBill.setEndOfWater(waterData);
|
|
|
+
|
|
|
+ // 订单结算
|
|
|
+ // 水用量
|
|
|
+ BigDecimal useOfWater = new BigDecimal(orderBill.getEndOfWater()).subtract(new BigDecimal(orderBill.getStartOfWater()));
|
|
|
+ // 电用量
|
|
|
+ BigDecimal useOfElectric = new BigDecimal(orderBill.getEndOfElectric()).subtract(new BigDecimal(orderBill.getStartOfElectric()));
|
|
|
+ // 水费
|
|
|
+ BigDecimal waterFee = useOfWater.multiply(new BigDecimal(orderBill.getPriceOfWater()));
|
|
|
+ // 电费
|
|
|
+ BigDecimal electricFee = useOfElectric.multiply(new BigDecimal(orderBill.getPriceOfElectric()));
|
|
|
+ // 总费用 【实际花费】
|
|
|
+ BigDecimal totalFee = waterFee.add(electricFee);
|
|
|
+ // 应缴费用 【总费用-减免费用】
|
|
|
+ BigDecimal shouldFee = totalFee.subtract(orderBill.getDiscountFree());
|
|
|
+ if (shouldFee.doubleValue() < 0) {
|
|
|
+ shouldFee = new BigDecimal("0");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 补缴费用 【应缴费用-预缴费用】
|
|
|
+ BigDecimal realFee = shouldFee.subtract(systemSetting.getFreeTotal());
|
|
|
+ if (realFee.doubleValue() < 0.01) {
|
|
|
+ realFee = new BigDecimal("0");
|
|
|
+ }
|
|
|
+
|
|
|
+ orderBill.setTotalFree(totalFee);
|
|
|
+ orderBill.setShouldFree(shouldFee);
|
|
|
+ orderBill.setRealFree(realFee);
|
|
|
+
|
|
|
+ BillHandleResultDTO dto = new BillHandleResultDTO();
|
|
|
+ dto.setBillId(orderBill.getId());
|
|
|
+ if (orderBill.getRealFree().doubleValue() <= 0) {
|
|
|
+ // 自动完成结账
|
|
|
+ orderBill.setStatu("3");
|
|
|
+ orderBill.setFinishTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ dto.setResultFlag("1");
|
|
|
+ dto.setReturnFee(systemSetting.getDeposit().subtract(shouldFee));
|
|
|
+ } else {
|
|
|
+ orderBill.setStatu("2");
|
|
|
+
|
|
|
+ // 发起缴费
|
|
|
+ dto.setResultFlag("2");
|
|
|
+ dto.setRealFee(realFee);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.updateById(orderBill);
|
|
|
+
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取水电表数据
|
|
|
+ * @param roomId 房间号
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> readWaterElectricData(Long roomId) {
|
|
|
+ // 水电抄表
|
|
|
+ RoomThirdSettingEntity waterElectricEntity = roomWaterElectricService.findByRoomId(roomId);
|
|
|
+ if (waterElectricEntity == null) {
|
|
|
+ throw new RRException(BizCodeEnume.PERMISSION_DENIED, "房间水电表计信息读取失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ String electricData = waterElectricComponent.queryPowerRealTimeData(waterElectricEntity.getElectricId());
|
|
|
+ if (!StringUtils.hasText(electricData)) {
|
|
|
+ throw new RRException(BizCodeEnume.UNKNOW_EXCEPTION, "读取电表数据异常");
|
|
|
+ }
|
|
|
+ String waterData = waterElectricComponent.queryLastHistoryCumulantInfo(waterElectricEntity.getWaterId());
|
|
|
+ if (!StringUtils.hasText(waterData)) {
|
|
|
+ throw new RRException(BizCodeEnume.UNKNOW_EXCEPTION, "读取电表数据异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> param = new HashMap<>();
|
|
|
+ param.put("electricData", electricData);
|
|
|
+ param.put("waterData", waterData);
|
|
|
+ return param;
|
|
|
+ }
|
|
|
+
|
|
|
}
|