|
|
@@ -49,29 +49,16 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
|
|
|
|
|
|
@Override
|
|
|
public boolean addPolicyFee(AddPolicyFeeDTO addPolicyFeeDTO) {
|
|
|
- // 先校验 third_party_policy_info 表中是否存在对应的价格策略数据
|
|
|
- ThirdPartyPolicyInfo policyInfo = policyInfoMapper.selectElecAndServicePriceByStation(
|
|
|
- addPolicyFeeDTO.getStationInfoId(),
|
|
|
- addPolicyFeeDTO.getTimePeriod()
|
|
|
- );
|
|
|
-
|
|
|
- if (policyInfo == null) {
|
|
|
- log.error("无法添加策略费用:third_party_policy_info表中不存在对应的价格策略数据。stationInfoId: {}, timePeriod: {}",
|
|
|
- addPolicyFeeDTO.getStationInfoId(), addPolicyFeeDTO.getTimePeriod());
|
|
|
- throw new IllegalArgumentException(
|
|
|
- String.format("站点ID[%d]的时段[%s]未配置价格策略,请先配置third_party_policy_info表数据",
|
|
|
- addPolicyFeeDTO.getStationInfoId(), addPolicyFeeDTO.getTimePeriod())
|
|
|
- );
|
|
|
+ // 校验 periodFlag 合法性
|
|
|
+ Integer periodFlag = addPolicyFeeDTO.getPeriodFlag();
|
|
|
+ if (periodFlag == null || periodFlag < 1 || periodFlag > 4) {
|
|
|
+ throw new IllegalArgumentException("时段标志必须为 1-尖、2-峰、3-平、4-谷");
|
|
|
}
|
|
|
|
|
|
- log.info("校验通过,找到对应的价格策略。stationInfoId: {}, timePeriod: {}, elecPrice: {}, servicePrice: {}",
|
|
|
- addPolicyFeeDTO.getStationInfoId(), addPolicyFeeDTO.getTimePeriod(),
|
|
|
- policyInfo.getElecPrice(), policyInfo.getServicePrice());
|
|
|
-
|
|
|
- // 根据站点+时段+销售类型+企业/渠道方查询是否已存在
|
|
|
+ // 根据站点+时段标志+销售类型+企业/渠道方查询是否已存在
|
|
|
PolicyFee existPolicyFee = policyFeeMapper.selectOne(Wrappers.<PolicyFee>lambdaQuery()
|
|
|
.eq(PolicyFee::getStationInfoId, addPolicyFeeDTO.getStationInfoId())
|
|
|
- .eq(PolicyFee::getStartTime, addPolicyFeeDTO.getTimePeriod())
|
|
|
+ .eq(PolicyFee::getPeriodFlag, periodFlag)
|
|
|
.eq(PolicyFee::getSalesType, addPolicyFeeDTO.getSalesType())
|
|
|
.eq(addPolicyFeeDTO.getSalesType() == 1, PolicyFee::getFirmId, addPolicyFeeDTO.getFirmId())
|
|
|
.eq(addPolicyFeeDTO.getSalesType() == 2, PolicyFee::getThirdPartyId, addPolicyFeeDTO.getThirdPartyId())
|
|
|
@@ -84,8 +71,7 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
|
|
|
// 计算并设置综合销售费
|
|
|
BigDecimal compSalesFee = calculateCompSalesFee(
|
|
|
addPolicyFeeDTO.getStationInfoId(),
|
|
|
- addPolicyFeeDTO.getTimePeriod(),
|
|
|
- addPolicyFeeDTO.getPeriodFlag(),
|
|
|
+ periodFlag,
|
|
|
addPolicyFeeDTO.getOperationServiceFee()
|
|
|
);
|
|
|
existPolicyFee.setCompSalesFee(compSalesFee);
|
|
|
@@ -94,13 +80,12 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
|
|
|
// 不存在,执行新增
|
|
|
PolicyFee policyFee = new PolicyFee();
|
|
|
policyFee.setStationInfoId(addPolicyFeeDTO.getStationInfoId());
|
|
|
- policyFee.setStartTime(addPolicyFeeDTO.getTimePeriod());
|
|
|
+ policyFee.setPeriodFlag(periodFlag);
|
|
|
policyFee.setOpFee(addPolicyFeeDTO.getOperationServiceFee());
|
|
|
// 计算并设置综合销售费
|
|
|
BigDecimal compSalesFee = calculateCompSalesFee(
|
|
|
addPolicyFeeDTO.getStationInfoId(),
|
|
|
- addPolicyFeeDTO.getTimePeriod(),
|
|
|
- addPolicyFeeDTO.getPeriodFlag(),
|
|
|
+ periodFlag,
|
|
|
addPolicyFeeDTO.getOperationServiceFee()
|
|
|
);
|
|
|
policyFee.setCompSalesFee(compSalesFee);
|
|
|
@@ -128,18 +113,17 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
|
|
|
* 公式:compSalesFee = elec_price + service_price + 字典表值 + op_fee
|
|
|
*
|
|
|
* @param stationInfoId 站点信息ID
|
|
|
- * @param timePeriod 时间段(HHmmss格式)
|
|
|
* @param periodFlag 时段标志
|
|
|
* @param opFee 运营费
|
|
|
* @return 综合销售费
|
|
|
*/
|
|
|
- private BigDecimal calculateCompSalesFee(Long stationInfoId, String timePeriod, Integer periodFlag, BigDecimal opFee) {
|
|
|
+ private BigDecimal calculateCompSalesFee(Long stationInfoId, Integer periodFlag, BigDecimal opFee) {
|
|
|
BigDecimal elecPrice = BigDecimal.ZERO;
|
|
|
BigDecimal servicePrice = BigDecimal.ZERO;
|
|
|
|
|
|
- // 直接通过stationInfoId和timePeriod查询电价和服务费
|
|
|
- ThirdPartyPolicyInfo policyInfo = policyInfoMapper.selectElecAndServicePriceByStation(stationInfoId, timePeriod);
|
|
|
- log.info("计算compSalesFee - stationInfoId: {}, timePeriod: {}, policyInfo: {}", stationInfoId, timePeriod, policyInfo);
|
|
|
+ // 通过stationInfoId和periodFlag查询电价和服务费(取该时段标志的第一条记录)
|
|
|
+ ThirdPartyPolicyInfo policyInfo = policyInfoMapper.selectElecAndServicePriceByStationAndPeriodFlag(stationInfoId, periodFlag);
|
|
|
+ log.info("计算compSalesFee - stationInfoId: {}, periodFlag: {}, policyInfo: {}", stationInfoId, periodFlag, policyInfo);
|
|
|
|
|
|
if (policyInfo != null) {
|
|
|
elecPrice = policyInfo.getElecPrice() != null ? policyInfo.getElecPrice() : BigDecimal.ZERO;
|
|
|
@@ -153,8 +137,8 @@ public class PolicyFeeServiceImpl implements PolicyFeeService {
|
|
|
BigDecimal opFeeValue = opFee != null ? opFee : BigDecimal.ZERO;
|
|
|
BigDecimal compSalesFee = elecPrice.add(servicePrice).add(dictValue).add(opFeeValue);
|
|
|
|
|
|
- log.info("计算综合销售费 - stationInfoId: {}, timePeriod: {}, elecPrice: {}, servicePrice: {}, dictValue: {}, opFee: {}, compSalesFee: {}",
|
|
|
- stationInfoId, timePeriod, elecPrice, servicePrice, dictValue, opFeeValue, compSalesFee);
|
|
|
+ log.info("计算综合销售费 - stationInfoId: {}, periodFlag: {}, elecPrice: {}, servicePrice: {}, dictValue: {}, opFee: {}, compSalesFee: {}",
|
|
|
+ stationInfoId, periodFlag, elecPrice, servicePrice, dictValue, opFeeValue, compSalesFee);
|
|
|
|
|
|
return compSalesFee;
|
|
|
}
|