Browse Source

修改空调加时订单 & web端详情增加历史记录

xiachuang 1 year ago
parent
commit
74bbe6b08d

+ 5 - 0
src/main/java/com/palmnest/application/dto/ConditionerAddTimeOrderFeeVO.java

@@ -1,11 +1,13 @@
 package com.palmnest.application.dto;
 
+import com.palmnest.model.RoomInfo;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * @author xc
@@ -21,4 +23,7 @@ public class ConditionerAddTimeOrderFeeVO {
     private String feeDetail;// 费用明细
     private BigDecimal feeTotal;// 费用总计
     private BigDecimal monthlyFee;// 月结费用
+    private String applyArea;// 申请面积
+    private String useDisplayTime;// 使用时间段
+    private List<RoomInfo> roomInfos;// 房间信息
 }

+ 25 - 0
src/main/java/com/palmnest/application/dto/output/AirConditionerAddTimeHistoryRecord.java

@@ -0,0 +1,25 @@
+package com.palmnest.application.dto.output;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+/**
+ * @author xc
+ * @since 2023/8/9 20:22
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class AirConditionerAddTimeHistoryRecord {
+    private String roomNames;// 申请位置
+    private String applyArea;// 申请面积
+    private String useDisplayTime;// 使用时间
+    private String priceDisplay;// 单价
+    private BigDecimal freeTotal;// 费用总计
+    private BigDecimal monthlyFree;// 月结费用
+}

+ 24 - 0
src/main/java/com/palmnest/application/dto/output/AirConditionerAddTimeHistoryVO.java

@@ -0,0 +1,24 @@
+package com.palmnest.application.dto.output;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author xc
+ * @since 2023/8/9 20:20
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class AirConditionerAddTimeHistoryVO {
+    private String createUser;//修改人
+    private String createTime;//修改时间
+    private AirConditionerAddTimeHistoryRecord beforeUpdate;//修改前
+    private AirConditionerAddTimeHistoryRecord afterUpdate;//修改后
+    private String remark;//备注
+    private Integer modificationDisabled;//是否禁用修改 0 否 1 是
+
+}

+ 21 - 0
src/main/java/com/palmnest/application/dto/output/AirConditionerAddTimeOutWebVO.java

@@ -0,0 +1,21 @@
+package com.palmnest.application.dto.output;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * @author xc
+ * @since 2023/8/9 20:18
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class AirConditionerAddTimeOutWebVO {
+    private AirConditionerAddTimeOutDto dto;// 订单信息
+    private List<AirConditionerAddTimeHistoryVO> historyList; // 历史记录
+}

+ 14 - 0
src/main/java/com/palmnest/dao/airconditioner/AirConditionerAddTimeOrderHistoryDao.java

@@ -0,0 +1,14 @@
+package com.palmnest.dao.airconditioner;
+
+import com.palmnest.dao.GenericDao;
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderHistory;
+
+import java.util.List;
+
+/**
+ * @author xc
+ * @since 2023/8/9 20:07
+ */
+public interface AirConditionerAddTimeOrderHistoryDao extends GenericDao<AirConditionerAddTimeOrderHistory, Long> {
+    List<AirConditionerAddTimeOrderHistory> getByOrderNo(String code);
+}

+ 31 - 0
src/main/java/com/palmnest/dao/airconditioner/impl/AirConditionerAddTimeOrderHistoryDaoImpl.java

@@ -0,0 +1,31 @@
+package com.palmnest.dao.airconditioner.impl;
+
+import com.palmnest.dao.airconditioner.AirConditionerAddTimeOrderHistoryDao;
+import com.palmnest.dao.hibernate.GenericDaoHibernate;
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderExtend;
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderHistory;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * @author xc
+ * @since 2023/8/9 20:08
+ */
+@Repository
+public class AirConditionerAddTimeOrderHistoryDaoImpl extends GenericDaoHibernate<AirConditionerAddTimeOrderHistory, Long> implements AirConditionerAddTimeOrderHistoryDao {
+
+    private static final Logger logger = Logger.getLogger(AirConditionerAddTimeOrderHistoryDaoImpl.class);
+    public AirConditionerAddTimeOrderHistoryDaoImpl() {
+        super(AirConditionerAddTimeOrderHistory.class);
+    }
+
+    @Override
+    public List<AirConditionerAddTimeOrderHistory> getByOrderNo(String orderNo) {
+        String sql = "select * from tb_airconditioner_addtime_order_history" + "\n" +
+                " where order_no = '" + orderNo + "'";
+        logger.info("根据空调加时订单获取历史记录 sql: " + sql);
+        return getSession().createSQLQuery(sql).addEntity(AirConditionerAddTimeOrderExtend.class).list();
+    }
+}

+ 103 - 0
src/main/java/com/palmnest/model/airconditioner/AirConditionerAddTimeOrderHistory.java

@@ -0,0 +1,103 @@
+package com.palmnest.model.airconditioner;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.util.Date;
+
+/**
+ * @author xc
+ * @since 2023/8/9 19:48
+ */
+@Entity
+@Table(name = "tb_airconditioner_addtime_order_history")
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class AirConditionerAddTimeOrderHistory {
+    private Long id;
+    private String orderNo;
+    private String beforeUpdate;
+    private String afterUpdate;
+    private Date createTime;
+    private String createUser;
+    private String remark;
+    private Integer modificationDisabled;
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    @Column(name = "ID", unique = true, nullable = false)
+    public Long getId() {
+        return id;
+    }
+
+    @Column(name = "order_no")
+    public String getOrderNo() {
+        return orderNo;
+    }
+
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
+    }
+
+
+    @Column(name = "before_update")
+    public String getBeforeUpdate() {
+        return beforeUpdate;
+    }
+
+    public void setBeforeUpdate(String beforeUpdate) {
+        this.beforeUpdate = beforeUpdate;
+    }
+
+    @Column(name = "after_update")
+    public String getAfterUpdate() {
+        return afterUpdate;
+    }
+
+    public void setAfterUpdate(String afterUpdate) {
+        this.afterUpdate = afterUpdate;
+    }
+
+    @Column(name = "create_time")
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    @Column(name = "create_user")
+    public String getCreateUser() {
+        return createUser;
+    }
+
+    public void setCreateUser(String createUser) {
+        this.createUser = createUser;
+    }
+
+    @Column(name = "remark")
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    @Column(name = "modification_disabled")
+    public Integer getModificationDisabled() {
+        return modificationDisabled;
+    }
+
+    public void setModificationDisabled(Integer modificationDisabled) {
+        this.modificationDisabled = modificationDisabled;
+    }
+}

+ 6 - 0
src/main/java/com/palmnest/service/estateserve/airconditioner/ConditionerAddTimeService.java

@@ -6,7 +6,9 @@ import com.palmnest.application.bean.Page;
 import com.palmnest.application.dto.ConditionerAddTimeOrderFeeVO;
 import com.palmnest.application.dto.input.*;
 import com.palmnest.application.dto.output.AirConditionerAddTimeOutDto;
+import com.palmnest.application.dto.output.AirConditionerAddTimeOutWebVO;
 import com.palmnest.model.RoomInfo;
+import com.palmnest.model.User;
 import com.palmnest.model.airconditioner.AirConditionerAddTime;
 import com.palmnest.model.airconditioner.AirRule;
 
@@ -112,4 +114,8 @@ public interface ConditionerAddTimeService {
 	List<RoomInfo> getAddTimeOrderHistoryRooms(String orderNo);
 
 	ConditionerAddTimeOrderFeeVO calcAddTimeOrderFee(ConditionerAddTimeOrderUpdateParam order);
+
+	void updateAddTimeOrder(ConditionerAddTimeOrderUpdateParam order, User user);
+
+	AirConditionerAddTimeOutWebVO assembleOrderHistory(AirConditionerAddTimeOutDto dto);
 }

+ 177 - 7
src/main/java/com/palmnest/service/estateserve/airconditioner/impl/ConditionerAddTimeServiceImpl.java

@@ -11,14 +11,11 @@ import com.palmnest.application.dto.ConditionerAddTimeOrderFeeVO;
 import com.palmnest.application.dto.WechatMessageDto;
 import com.palmnest.application.dto.WxMessageConfigVo;
 import com.palmnest.application.dto.input.*;
-import com.palmnest.application.dto.output.AirConditionerAddTimeOutDto;
-import com.palmnest.application.dto.output.GoodsOperateDto;
+import com.palmnest.application.dto.output.*;
+import com.palmnest.dao.airconditioner.AirConditionerAddTimeOrderHistoryDao;
 import com.palmnest.dao.estateserve.EnterprisePermissionDao;
 import com.palmnest.model.*;
-import com.palmnest.model.airconditioner.AirConditionerAddTime;
-import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderExtend;
-import com.palmnest.model.airconditioner.AirRule;
-import com.palmnest.model.airconditioner.ProjectConfig;
+import com.palmnest.model.airconditioner.*;
 import com.palmnest.model.estateserve.AppUser;
 import com.palmnest.model.estateserve.VirtualAccount;
 import com.palmnest.model.estateserve.WxUser;
@@ -37,6 +34,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
@@ -95,6 +93,8 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
     private EnterprisePermissionDao enterprisePermissionDao;
     @Autowired
     private ConditionerAddTimeOrderExtendManager conditionerAddTimeOrderExtendManager;
+    @Autowired
+    private AirConditionerAddTimeOrderHistoryDao airConditionerAddTimeOrderHistoryDao;
 
 
     MathContext mc = new MathContext(2, RoundingMode.HALF_UP);
@@ -2627,13 +2627,75 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
 
             }
 
+            Integer dataType = 0;// 根据api 获得
+            // String currentDateStr=DateUtils.getTime(new Date(),"yyyyMMdd");//换成申请日期的
+            String applyTimeStr = DateUtils.getTime(airConditionerAddTime.getUseStartTime(), "yyyy-MM-dd");
+
+            String jsonStr = HttpKit.holidayGet("https://timor.tech/api/holiday/info/" + applyTimeStr, false);
+            System.out.println("节假日接口调用返回===>" + jsonStr);
+            Map<String, Object> jsApiMap = com.alibaba.fastjson.JSONObject.parseObject(jsonStr);
+            if (null != jsApiMap && jsApiMap.containsKey("code")) {
+                if (jsApiMap.get("code").equals(0)) {
+                    // dataType = (Integer) jsApiMap.get("type");
+                    Map<String, Object> jsApiMapType = (Map) jsApiMap.get("type");
+                    if (jsApiMapType.containsKey("type")) {
+                        dataType = (Integer) jsApiMapType.get("type");
+                        if (dataType == 3) {
+                            // 0, 1, 2, 3- 节假日类型,分别表示 工作日、周末、节日、调休 调休改为工作日
+                            dataType = 0;
+                        }
+                    }
+                } else {
+                    throw new RuntimeException("空调加时订单请求失败,节假日API异常");
+                }
+            }
+
+            // 勾选后非节假日的周六为工作日=================================================2018.10.17
+            // 如果为 true 如果get为周六且非2节假日 将 dataType设置为0工作日
+            boolean isSaturday = DateUtils.checkIsSaturday(airConditionerAddTime.getUseStartTime());
+            if (isSaturday) {
+                dataType = 1;
+            }
+
+            VirtualArchitecture virtual = virtualArchManager.get(airConditionerAddTime.getVirtualId().intValue());
+            if (null != virtual && virtual.getOrganizationId() != null) {
+                ProjectConfig projectConfig = projectConfigManager.getProjectConfigByOrganizationId(Long.valueOf(virtual.getOrganizationId()));
+                if (null == projectConfig) {
+                    throw new RuntimeException("空调部分项目配置为空,请系统管理员");
+                }
+                Integer satDataType = projectConfig.getSatDataType();
+                if (null != satDataType && satDataType == 1) {///如果为 true
+                    if (isSaturday && dataType != 2) {// 如果get为周六且非2节假日 将 dataType设置为0工作日
+                        dataType = 0;
+                    }
+                }
+            }
+            String dataTypeStr = "工作日";
+            if (dataType == GoodsCodeConstants.DATATYPE_WORKINGDAY) {// 工作日
+                dataTypeStr = "工作日";
+            } else if (dataType == GoodsCodeConstants.DATATYPE_RESTDAY) {// 休息日
+                dataTypeStr = "休息日";
+            } else if (dataType == GoodsCodeConstants.DATATYPE_VACATIONS) {// 节假日
+                dataTypeStr = "节假日";
+            }
+
+            // 使用时间(合并显示  工作日2018-09-18 07:00~21:00
+            // 使用时间(合并显示  10月25日  07:00~21:00(工作日)
+            // String UseStartTimeStr=DateUtils.getDate(repairBill.getUseStartTime(), "yyyy-MM-dd HH:mm");
+            String UseStartTimeStr = DateUtils.getDate(airConditionerAddTime.getUseStartTime(), "MM月dd日 HH:mm");
+            String useEndTimeStr = DateUtils.getDate(airConditionerAddTime.getUseEndTime(), "HH:mm");
+
+
 
             return ConditionerAddTimeOrderFeeVO.builder()
                     .priceDisplay(priceDisplay)// 单价
                     .useLengthTime(useLengthTime)// 使用时长
                     .feeDetail(freeDetail)// 费用明细
                     .feeTotal(calcFee)// 费用总计
-                    .monthlyFee(calcFee)//月结费用
+                    .monthlyFee(calcFee)// 月结费用
+                    .applyArea(applyArea)// 申请面积
+                    .useDisplayTime(UseStartTimeStr + "~" + useEndTimeStr + "(" + dataTypeStr + ")")// 使用时间段
+                    .roomInfos(roomInfos)// 房间信息
                     .build();
         } catch (Exception e) {
             log.error("计算空调加时费用异常", e);
@@ -2641,4 +2703,112 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
         }
     }
 
+    /**
+     * 更新空调加时订单
+     * @param order 订单参数
+     * @param user  用户
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateAddTimeOrder(ConditionerAddTimeOrderUpdateParam order, User user) {
+        AirConditionerAddTime airConditionerAddTime = conditionerAddTimeManager.get(order.getOrderId());
+        if (airConditionerAddTime == null || !airConditionerAddTime.getCode().equalsIgnoreCase(order.getOrderNo())) {
+            throw new RuntimeException("订单不存在");
+        }
+        if (airConditionerAddTime.getModificationDisabled() != 0) {
+            throw new RuntimeException("订单不允许修改");
+        }
+        ConditionerAddTimeOrderFeeVO conditionerAddTimeOrderFeeVO = calcAddTimeOrderFee(order);
+
+        // 更新前
+        String history = JSON.toJSONString(airConditionerAddTime);
+
+        /**
+         * 更新订单信息
+         */
+        StringBuilder roomNos = new StringBuilder();
+        for (Integer roomId : order.getRoomIds()) {
+            roomNos.append(roomId).append(",");
+        }
+        List<RoomInfo> roomInfos = conditionerAddTimeOrderFeeVO.getRoomInfos();
+        Map<Integer,RoomInfo> map = new HashMap<>();
+        for (RoomInfo roomInfo : roomInfos) {
+            map.put(roomInfo.getId(), roomInfo);
+        }
+        StringBuilder roomNames = new StringBuilder();
+        HashSet<Integer> floorSet = new HashSet<>();
+        for (Integer roomId : order.getRoomIds()) {
+            roomNames.append(map.get(roomId).getName()).append(",");
+            floorSet.add(map.get(roomId).getFloorId().intValue());
+        }
+
+        StringBuilder floorIds = new StringBuilder();
+        for (Integer floorId : floorSet) {
+            floorIds.append(floorId).append(",");
+        }
+
+
+        airConditionerAddTime.setRoomNos(roomNos.toString());//申请房间id
+        airConditionerAddTime.setRoomNames(roomNames.toString());// 申请房间名称
+        airConditionerAddTime.setApplyArea(conditionerAddTimeOrderFeeVO.getApplyArea());// 申请面积
+        airConditionerAddTime.setUseLengthTime(conditionerAddTimeOrderFeeVO.getUseLengthTime()); // 使用时长
+        airConditionerAddTime.setUseStartTime(order.getUseStartTime());// 使用开始时间
+        airConditionerAddTime.setUseEndTime(order.getUseEndTime());// 使用结束时间
+        airConditionerAddTime.setPriceDisplay(conditionerAddTimeOrderFeeVO.getPriceDisplay());// 单价
+        airConditionerAddTime.setFreeDetail(conditionerAddTimeOrderFeeVO.getFeeDetail());// 费用明细
+        airConditionerAddTime.setFreeTotal(conditionerAddTimeOrderFeeVO.getFeeTotal());// 费用总计
+        airConditionerAddTime.setMonthlyFree(conditionerAddTimeOrderFeeVO.getMonthlyFee());// 月结费用
+        airConditionerAddTime.setModifier(user.getFullName());// 修改人
+        airConditionerAddTime.setModifyTime(new Date());// 修改时间
+        airConditionerAddTime.setFloorId(floorIds.toString());// 楼层id
+        airConditionerAddTime.setModificationDisabled(order.getModificationDisabled());// 是否关闭修改功能
+
+        // 保存修改记录
+        airConditionerAddTimeOrderHistoryDao.save(
+                AirConditionerAddTimeOrderHistory.builder()
+                .orderNo(airConditionerAddTime.getCode())// 订单号
+                .beforeUpdate(history)// 更新前
+                .afterUpdate(JSON.toJSONString(airConditionerAddTime)) // 更新后
+                .createTime(new Date())
+                .createUser(user.getFullName())
+                .remark(order.getRemark())// 备注
+                .modificationDisabled(order.getModificationDisabled()) // 是否关闭修改功能
+                .build()
+        );
+
+        // 更新原订单
+        conditionerAddTimeManager.updateModel(airConditionerAddTime);
+    }
+
+    /**
+     * 空调加时订单WEB端需要展示修改历史记录
+     * @param dto
+     * @return
+     */
+    @Override
+    public AirConditionerAddTimeOutWebVO assembleOrderHistory(AirConditionerAddTimeOutDto dto) {
+        String code = dto.getCode();// 订单号
+        List<AirConditionerAddTimeOrderHistory> list = airConditionerAddTimeOrderHistoryDao.getByOrderNo(code);
+
+        List<AirConditionerAddTimeHistoryVO> history = new ArrayList<>();
+
+        if (list != null && !list.isEmpty()) {
+            for (AirConditionerAddTimeOrderHistory airConditionerAddTimeOrderHistory : list) {
+                AirConditionerAddTimeHistoryVO.builder()
+                        .createUser(airConditionerAddTimeOrderHistory.getCreateUser())
+                        .createTime(DateUtils.getDate(airConditionerAddTimeOrderHistory.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))
+                        .remark(airConditionerAddTimeOrderHistory.getRemark())
+                        .modificationDisabled(airConditionerAddTimeOrderHistory.getModificationDisabled())
+                        .beforeUpdate(JSON.parseObject(airConditionerAddTimeOrderHistory.getBeforeUpdate(), AirConditionerAddTimeHistoryRecord.class))
+                        .afterUpdate(JSON.parseObject(airConditionerAddTimeOrderHistory.getAfterUpdate(), AirConditionerAddTimeHistoryRecord.class))
+                        .build();
+            }
+        }
+
+        return AirConditionerAddTimeOutWebVO.builder()
+                .dto(dto)
+                .historyList(history)
+                .build();
+    }
+
 }

+ 20 - 2
src/main/java/com/palmnest/webapp/controller/backstage/AirConditionerAddTimeController.java

@@ -12,6 +12,8 @@ import com.palmnest.application.dto.OrgDto;
 import com.palmnest.application.dto.WebPageResultDto;
 import com.palmnest.application.dto.input.AirConditionerAddTimeInputDto;
 import com.palmnest.application.dto.input.ConditionerAddTimeOrderUpdateParam;
+import com.palmnest.application.dto.output.AirConditionerAddTimeOutDto;
+import com.palmnest.application.dto.output.AirConditionerAddTimeOutWebVO;
 import com.palmnest.model.AppUserFloorRelation;
 import com.palmnest.model.RoomInfo;
 import com.palmnest.model.User;
@@ -406,8 +408,9 @@ public class AirConditionerAddTimeController {
 	@ResponseBody
 	public AppResultDto getDetail(@RequestParam("id") Long id) {
 		log.info("ApiContractInformationController getDetail======");
-
-		return AppResultUtil.createSuccesDto(conditionerAddTimeService.findById(id));
+		AirConditionerAddTimeOutDto dto = conditionerAddTimeService.findById(id);
+		AirConditionerAddTimeOutWebVO vo = conditionerAddTimeService.assembleOrderHistory(dto);
+		return AppResultUtil.createSuccesDto(vo);
 	}
 
 	/**
@@ -644,4 +647,19 @@ public class AirConditionerAddTimeController {
 		ConditionerAddTimeOrderFeeVO vo = conditionerAddTimeService.calcAddTimeOrderFee(order);
 		return AppResultUtil.createSuccesDto(vo);
 	}
+
+	/**
+	 * 更新空调加时订单
+	 * @param order
+	 * @param request
+	 * @return
+	 */
+	@RequestMapping(value = "updateAddTimeOrder", method = RequestMethod.POST)
+	@ResponseBody
+	public AppResultDto updateAddTimeOrder(@RequestBody @Validated ConditionerAddTimeOrderUpdateParam order, HttpServletRequest request) {
+		User  user  = (User) request.getSession().getAttribute("UserCache");
+		log.info("更新空调加时订单, user: {}, order:{}", user.getFullName(), JSON.toJSONString(order));
+		conditionerAddTimeService.updateAddTimeOrder(order, user);
+		return AppResultUtil.createSuccesDto();
+	}
 }