소스 검색

空调加时订单分摊金额

xiachuang 1 년 전
부모
커밋
cf098dc099

+ 11 - 0
src/main/java/com/palmnest/dao/airconditioner/ConditionerAddTimeOrderAmountDetailDao.java

@@ -0,0 +1,11 @@
+package com.palmnest.dao.airconditioner;
+
+import com.palmnest.dao.GenericDao;
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderAmountDetail;
+
+/**
+ * @author xc
+ * @since 2023/11/2 10:20
+ */
+public interface ConditionerAddTimeOrderAmountDetailDao extends GenericDao<AirConditionerAddTimeOrderAmountDetail, Long> {
+}

+ 19 - 0
src/main/java/com/palmnest/dao/airconditioner/impl/ConditionerAddTimeOrderAmountDetailDaoImpl.java

@@ -0,0 +1,19 @@
+package com.palmnest.dao.airconditioner.impl;
+
+import com.palmnest.dao.airconditioner.ConditionerAddTimeOrderAmountDetailDao;
+import com.palmnest.dao.hibernate.GenericDaoHibernate;
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderAmountDetail;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author xc
+ * @since 2023/11/2 10:21
+ */
+@Repository("conditionerAddTimeOrderAmountDetailDao")
+public class ConditionerAddTimeOrderAmountDetailDaoImpl extends GenericDaoHibernate<AirConditionerAddTimeOrderAmountDetail, Long> implements ConditionerAddTimeOrderAmountDetailDao {
+    private final Logger logger = Logger.getLogger(ConditionerAddTimeOrderExtendDaoImpl.class);
+    public ConditionerAddTimeOrderAmountDetailDaoImpl() {
+        super(AirConditionerAddTimeOrderAmountDetail.class);
+    }
+}

+ 63 - 0
src/main/java/com/palmnest/model/airconditioner/AirConditionerAddTimeOrderAmountDetail.java

@@ -0,0 +1,63 @@
+package com.palmnest.model.airconditioner;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.math.BigDecimal;
+
+/**
+ * @author xc
+ * @since 2023/11/2 10:07
+ */
+@Entity
+@Table(name = "tb_airconditioner_addtime_order_amount_detail")
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class AirConditionerAddTimeOrderAmountDetail {
+    private Long id;
+    private String code;// 订单号
+    private Integer roomId;// 房间id
+    private BigDecimal amount;// 房间分摊金额
+
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    @Column(name = "id", unique = true, nullable = false)
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    @Column(name = "code")
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    @Column(name = "room_id")
+    public Integer getRoomId() {
+        return roomId;
+    }
+
+    public void setRoomId(Integer roomId) {
+        this.roomId = roomId;
+    }
+
+    @Column(name = "amount")
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+}

+ 11 - 0
src/main/java/com/palmnest/service/estateserve/airconditioner/ConditionerAddTimeOrderAmountDetailManager.java

@@ -0,0 +1,11 @@
+package com.palmnest.service.estateserve.airconditioner;
+
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderAmountDetail;
+import com.palmnest.service.GenericManager;
+
+/**
+ * @author xc
+ * @since 2023/11/2 10:17
+ */
+public interface ConditionerAddTimeOrderAmountDetailManager extends GenericManager<AirConditionerAddTimeOrderAmountDetail, Long> {
+}

+ 24 - 0
src/main/java/com/palmnest/service/estateserve/airconditioner/impl/ConditionerAddTimeOrderAmountDetailManagerImpl.java

@@ -0,0 +1,24 @@
+package com.palmnest.service.estateserve.airconditioner.impl;
+
+import com.palmnest.dao.airconditioner.ConditionerAddTimeOrderAmountDetailDao;
+import com.palmnest.model.airconditioner.AirConditionerAddTimeOrderAmountDetail;
+import com.palmnest.service.estateserve.airconditioner.ConditionerAddTimeOrderAmountDetailManager;
+import com.palmnest.service.impl.GenericManagerImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author xc
+ * @since 2023/11/2 10:18
+ */
+@Service("conditionerAddTimeOrderAmountDetailManager")
+public class ConditionerAddTimeOrderAmountDetailManagerImpl extends GenericManagerImpl<AirConditionerAddTimeOrderAmountDetail, Long> implements ConditionerAddTimeOrderAmountDetailManager {
+    private ConditionerAddTimeOrderAmountDetailDao conditionerAddTimeOrderAmountDetailDao;
+
+
+    @Autowired
+    public void setConditionerAddTimeOrderExtendDao(ConditionerAddTimeOrderAmountDetailDao conditionerAddTimeOrderAmountDetailDao) {
+        this.conditionerAddTimeOrderAmountDetailDao = conditionerAddTimeOrderAmountDetailDao;
+        this.dao = conditionerAddTimeOrderAmountDetailDao;
+    }
+}

+ 36 - 0
src/main/java/com/palmnest/service/estateserve/airconditioner/impl/ConditionerAddTimeServiceImpl.java

@@ -92,6 +92,8 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
     private EnterprisePermissionDao enterprisePermissionDao;
     @Autowired
     private ConditionerAddTimeOrderExtendManager conditionerAddTimeOrderExtendManager;
+    @Autowired
+    private ConditionerAddTimeOrderAmountDetailManager conditionerAddTimeOrderAmountDetailManager;
 
 
     MathContext mc = new MathContext(2, RoundingMode.HALF_UP);
@@ -618,6 +620,40 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
                             .build()
             );
 
+            /*
+             * 保存每个房间均摊的金额
+             * 1.单个房间:申请房间面积=订单总金额。
+             * 2.多个房间:
+             *      申请房间费用=(申请房间面积/订单申请面积)*订单总金额。
+             *      最后一个申请房间的费用=订单总金额-申请房间1费用-申请房间N费用。
+             */
+            BigDecimal totalAmount = airConditionerAddTime.getFreeTotal();
+            BigDecimal remainingAmount = totalAmount;
+            BigDecimal totalArea = calcapplyArea;
+            List<AirConditionerAddTimeOrderAmountDetail> airConditionerAddTimeOrderAmountDetails = new ArrayList<>();
+
+            for (int i = 0; i < listRoomInfos.size(); i++) {
+                RoomInfo roomInfo = listRoomInfos.get(i);
+                BigDecimal roomArea = roomInfo.getArea();
+                AirConditionerAddTimeOrderAmountDetail airConditionerAddTimeOrderAmountDetail = new AirConditionerAddTimeOrderAmountDetail();
+                airConditionerAddTimeOrderAmountDetail.setCode(code);
+                airConditionerAddTimeOrderAmountDetail.setRoomId(roomInfo.getId());
+                if (i == listRoomInfos.size() - 1) {
+                    airConditionerAddTimeOrderAmountDetail.setAmount(remainingAmount);
+                } else {
+                    BigDecimal roomCost = roomArea.divide(totalArea, 2, RoundingMode.HALF_UP).multiply(totalAmount);
+                    airConditionerAddTimeOrderAmountDetail.setAmount(roomCost);
+                    remainingAmount = remainingAmount.subtract(roomCost);
+                }
+                airConditionerAddTimeOrderAmountDetails.add(airConditionerAddTimeOrderAmountDetail);
+            }
+
+            if (cn.superdesk.libs.common.util.CollectionUtils.isNotEmpty(airConditionerAddTimeOrderAmountDetails)) {
+                for (AirConditionerAddTimeOrderAmountDetail airConditionerAddTimeOrderAmountDetail : airConditionerAddTimeOrderAmountDetails) {
+                    conditionerAddTimeOrderAmountDetailManager.save(airConditionerAddTimeOrderAmountDetail);
+                }
+            }
+
             AirConditionerAddTime bill = conditionerAddTimeManager.save(airConditionerAddTime);
 
             return AppResultUtil.createSuccesDto(convert(bill));

+ 1 - 0
src/main/resources/hibernate.cfg.xml

@@ -122,6 +122,7 @@
         <mapping class="com.palmnest.model.airconditioner.AirConditionerAddTime"/>
         <mapping class="com.palmnest.model.airconditioner.AirConditionerAddTimeOrderExtend"/>
         <mapping class="com.palmnest.model.airconditioner.AirConditionerAddTimeOrderHistory"/>
+        <mapping class="com.palmnest.model.airconditioner.AirConditionerAddTimeOrderAmountDetail"/>
         <mapping class="com.palmnest.model.airconditioner.AirRule"/>
         <mapping class="com.palmnest.model.airconditioner.ProjectConfig"/>
         <mapping class="com.palmnest.model.OrgElement"/>