Ver código fonte

feat(policy-fee): 增加时段标志及综合销售费计算功能

- 在AddPolicyFeeDTO中添加periodFlag字段用于时段标志
- 在PolicyFeeServiceImpl中新增根据时段标志查询字典获取综合销售费的方法
- 新增综合销售费字段设置逻辑,更新和新增政策费用时计算并设置该值
- 第三方计费服务实现中更新策略信息时设置更新时间字段
- 在ThirdPartyPolicyInfo实体中新增updateTime字段用于记录更新时间
SheepHy 1 dia atrás
pai
commit
2d72935c26

+ 4 - 0
src/main/java/com/zsElectric/boot/business/model/dto/AddPolicyFeeDTO.java

@@ -12,6 +12,10 @@ import java.math.BigDecimal;
 public class AddPolicyFeeDTO {
     @Schema(description = "时间段")
     private String timePeriod;
+    
+    @Schema(description = "时段标志(1-尖 2-峰 3-平 4-谷),用于计算综合销售费")
+    private Integer periodFlag;
+    
     @Schema(description = "运营服务费(元)")
     private BigDecimal operationServiceFee;
     @Schema(description = "站点信息ID(关联third_party_station_info表)")

+ 67 - 0
src/main/java/com/zsElectric/boot/business/service/impl/PolicyFeeServiceImpl.java

@@ -1,5 +1,6 @@
 package com.zsElectric.boot.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.zsElectric.boot.business.mapper.PolicyFeeMapper;
 import com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper;
@@ -8,11 +9,14 @@ import com.zsElectric.boot.business.model.entity.PolicyFee;
 import com.zsElectric.boot.business.model.vo.TimePeriodPriceVO;
 import com.zsElectric.boot.business.service.PolicyFeeService;
 import com.zsElectric.boot.charging.entity.ThirdPartyStationInfo;
+import com.zsElectric.boot.system.mapper.DictItemMapper;
+import com.zsElectric.boot.system.model.entity.DictItem;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -28,6 +32,12 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
 
     private final PolicyFeeMapper policyFeeMapper;
     private final ThirdPartyStationInfoMapper stationInfoMapper;
+    private final DictItemMapper dictItemMapper;
+    
+    /**
+     * 时段标志字典编码
+     */
+    private static final String TIME_PERIOD_FLAG_DICT_CODE = "time_period_flag";
 
     @Override
     public List<TimePeriodPriceVO> getPolicyFee(long stationId, int salesType, Long firmId, Long thirdPartyId) {
@@ -49,6 +59,9 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
         if (existPolicyFee != null) {
             // 已存在,执行更新
             existPolicyFee.setOpFee(addPolicyFeeDTO.getOperationServiceFee());
+            // 计算并设置综合销售费
+            BigDecimal compSalesFee = getCompSalesFeeByPeriodFlag(addPolicyFeeDTO.getPeriodFlag());
+            existPolicyFee.setCompSalesFee(compSalesFee);
             return policyFeeMapper.updateById(existPolicyFee) > 0;
         } else {
             // 不存在,执行新增
@@ -56,6 +69,9 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
             policyFee.setStationInfoId(addPolicyFeeDTO.getStationInfoId());
             policyFee.setStartTime(addPolicyFeeDTO.getTimePeriod());
             policyFee.setOpFee(addPolicyFeeDTO.getOperationServiceFee());
+            // 计算并设置综合销售费
+            BigDecimal compSalesFee = getCompSalesFeeByPeriodFlag(addPolicyFeeDTO.getPeriodFlag());
+            policyFee.setCompSalesFee(compSalesFee);
             policyFee.setSalesType(addPolicyFeeDTO.getSalesType());
             // 根据销售类型设置对应的ID
             if (addPolicyFeeDTO.getSalesType() == 1) {
@@ -74,6 +90,57 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
             return inserted;
         }
     }
+    
+    /**
+     * 根据时段标志获取综合销售费(从字典表查询)
+     *
+     * @param periodFlag 时段标志(1-尖 2-峰 3-平 4-谷)
+     * @return 综合销售费
+     */
+    private BigDecimal getCompSalesFeeByPeriodFlag(Integer periodFlag) {
+        if (periodFlag == null) {
+            return BigDecimal.ZERO;
+        }
+        
+        // 根据时段标志获取对应的label
+        String label;
+        switch (periodFlag) {
+            case 1:
+                label = "尖";
+                break;
+            case 2:
+                label = "峰";
+                break;
+            case 3:
+                label = "平";
+                break;
+            case 4:
+                label = "谷";
+                break;
+            default:
+                return BigDecimal.ZERO;
+        }
+        
+        // 从字典表查询对应的value
+        DictItem dictItem = dictItemMapper.selectOne(
+                new LambdaQueryWrapper<DictItem>()
+                        .eq(DictItem::getDictCode, TIME_PERIOD_FLAG_DICT_CODE)
+                        .eq(DictItem::getStatus, 1)
+                        .eq(DictItem::getLabel, label)
+                        .last("LIMIT 1")
+        );
+        
+        if (dictItem != null && dictItem.getValue() != null) {
+            try {
+                return new BigDecimal(dictItem.getValue());
+            } catch (NumberFormatException e) {
+                log.warn("字典值value转换为BigDecimal失败: {}", dictItem.getValue());
+                return BigDecimal.ZERO;
+            }
+        }
+        
+        return BigDecimal.ZERO;
+    }
 
     @Override
     @Transactional(rollbackFor = Exception.class)

+ 1 - 0
src/main/java/com/zsElectric/boot/business/service/impl/ThirdPartyChargingServiceImpl.java

@@ -675,6 +675,7 @@ public class ThirdPartyChargingServiceImpl implements ThirdPartyChargingService
         existing.setElecPrice(policyInfo.getElecPrice());
         existing.setServicePrice(policyInfo.getServicePrice());
         existing.setPeriodFlag(policyInfo.getPeriodFlag());
+        existing.setUpdateTime(LocalDateTime.now());
         policyInfoMapper.updateById(existing);
     }
 

+ 4 - 0
src/main/java/com/zsElectric/boot/charging/entity/ThirdPartyPolicyInfo.java

@@ -52,6 +52,10 @@ public class ThirdPartyPolicyInfo {
     @TableField("create_time")
     private LocalDateTime createTime;
 
+    @Schema(description = "更新时间")
+    @TableField("update_time")
+    private LocalDateTime updateTime;
+
     @Schema(description = "创建人ID")
     @TableField("create_by")
     private Long createBy;