|
|
@@ -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)
|