|
|
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.zsElectric.boot.charging.entity.*;
|
|
|
import com.zsElectric.boot.business.mapper.FirmInfoMapper;
|
|
|
+import com.zsElectric.boot.business.mapper.PolicyFeeMapper;
|
|
|
import com.zsElectric.boot.business.mapper.ThirdPartyEquipmentInfoMapper;
|
|
|
import com.zsElectric.boot.business.mapper.ThirdPartyInfoMapper;
|
|
|
import com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper;
|
|
|
@@ -16,6 +17,7 @@ import com.zsElectric.boot.charging.mapper.ThirdPartyConnectorInfoMapper;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyEquipmentPricePolicyMapper;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyPolicyInfoMapper;
|
|
|
import com.zsElectric.boot.business.model.entity.FirmInfo;
|
|
|
+import com.zsElectric.boot.business.model.entity.PolicyFee;
|
|
|
import com.zsElectric.boot.business.model.entity.ThirdPartyInfo;
|
|
|
import com.zsElectric.boot.business.model.query.ThirdPartyEquipmentInfoQuery;
|
|
|
import com.zsElectric.boot.business.model.query.ThirdPartyStationInfoQuery;
|
|
|
@@ -59,6 +61,7 @@ public class ThirdPartyChargingServiceImpl implements ThirdPartyChargingService
|
|
|
private final ThirdPartyPolicyInfoMapper policyInfoMapper;
|
|
|
private final FirmInfoMapper firmInfoMapper;
|
|
|
private final ThirdPartyInfoMapper thirdPartyInfoMapper;
|
|
|
+ private final PolicyFeeMapper policyFeeMapper;
|
|
|
private final ObjectMapper objectMapper;
|
|
|
|
|
|
// ==================== 充电站信息查询 ====================
|
|
|
@@ -655,6 +658,9 @@ public class ThirdPartyChargingServiceImpl implements ThirdPartyChargingService
|
|
|
// 存在且数据变化,执行更新
|
|
|
updatePolicyInfoDetail(existing, policyInfo);
|
|
|
log.debug("价格策略明细更新成功 - policyId: {}, startTime: {}", policyId, policyInfo.getStartTime());
|
|
|
+
|
|
|
+ // 价格变化后,同步更新 c_policy_fee 表中的 comp_sales_fee
|
|
|
+ updateRelatedPolicyFeeCompSalesFee(policyId, policyInfo.getStartTime());
|
|
|
} else {
|
|
|
// 数据未变化,但仍更新同步时间
|
|
|
updateSyncTime(existing);
|
|
|
@@ -700,6 +706,101 @@ public class ThirdPartyChargingServiceImpl implements ThirdPartyChargingService
|
|
|
existing.setUpdateTime(LocalDateTime.now());
|
|
|
policyInfoMapper.updateById(existing);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 价格策略变化后,同步更新 c_policy_fee 表中的 comp_sales_fee
|
|
|
+ * 根据 pricePolicyId 查询对应的 stationInfoId,然后更新相关的 policy_fee 记录
|
|
|
+ *
|
|
|
+ * @param policyId 价格策略ID
|
|
|
+ * @param startTime 时段开始时间
|
|
|
+ */
|
|
|
+ private void updateRelatedPolicyFeeCompSalesFee(Long policyId, String startTime) {
|
|
|
+ try {
|
|
|
+ // 1. 通过 policyId 查询 connectorId
|
|
|
+ ThirdPartyEquipmentPricePolicy pricePolicy = pricePolicyMapper.selectById(policyId);
|
|
|
+ if (pricePolicy == null) {
|
|
|
+ log.warn("未找到价格策略记录,policyId: {}", policyId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 通过 connectorId 查询 stationId
|
|
|
+ ThirdPartyConnectorInfo connector = connectorInfoMapper.selectOne(
|
|
|
+ Wrappers.<ThirdPartyConnectorInfo>lambdaQuery()
|
|
|
+ .eq(ThirdPartyConnectorInfo::getConnectorId, pricePolicy.getConnectorId())
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+
|
|
|
+ if (connector == null) {
|
|
|
+ log.warn("未找到充电接口记录,connectorId: {}", pricePolicy.getConnectorId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 通过 stationId 查询 stationInfoId
|
|
|
+ ThirdPartyStationInfo station = stationInfoMapper.selectOne(
|
|
|
+ Wrappers.<ThirdPartyStationInfo>lambdaQuery()
|
|
|
+ .eq(ThirdPartyStationInfo::getStationId, connector.getStationId())
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+
|
|
|
+ if (station == null) {
|
|
|
+ log.warn("未找到站点记录,stationId: {}", connector.getStationId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 查询该站点、该时段的所有 policy_fee 记录
|
|
|
+ List<PolicyFee> policyFees = policyFeeMapper.selectList(
|
|
|
+ Wrappers.<PolicyFee>lambdaQuery()
|
|
|
+ .eq(PolicyFee::getStationInfoId, station.getId())
|
|
|
+ .eq(PolicyFee::getStartTime, startTime)
|
|
|
+ .eq(PolicyFee::getIsDeleted, 0)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (policyFees.isEmpty()) {
|
|
|
+ log.debug("该站点该时段没有 policy_fee 记录,stationInfoId: {}, startTime: {}", station.getId(), startTime);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 重新计算并更新每条记录的 comp_sales_fee
|
|
|
+ for (PolicyFee policyFee : policyFees) {
|
|
|
+ BigDecimal newCompSalesFee = calculateCompSalesFeeForPolicyFee(
|
|
|
+ station.getId(),
|
|
|
+ startTime,
|
|
|
+ policyFee.getOpFee()
|
|
|
+ );
|
|
|
+
|
|
|
+ policyFee.setCompSalesFee(newCompSalesFee);
|
|
|
+ policyFeeMapper.updateById(policyFee);
|
|
|
+
|
|
|
+ log.info("更新 policy_fee 的 comp_sales_fee - id: {}, stationInfoId: {}, startTime: {}, salesType: {}, 新值: {}",
|
|
|
+ policyFee.getId(), station.getId(), startTime, policyFee.getSalesType(), newCompSalesFee);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新 policy_fee 的 comp_sales_fee 失败 - policyId: {}, startTime: {}", policyId, startTime, e);
|
|
|
+ // 不抛出异常,避免影响主流程
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算 comp_sales_fee
|
|
|
+ * 公式:compSalesFee = elec_price + service_price + op_fee
|
|
|
+ * 注意:这里不加字典值,与 PolicyFeeServiceImpl 中的计算逻辑保持一致
|
|
|
+ */
|
|
|
+ private BigDecimal calculateCompSalesFeeForPolicyFee(Long stationInfoId, String timePeriod, BigDecimal opFee) {
|
|
|
+ BigDecimal elecPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal servicePrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 查询电价和服务费
|
|
|
+ ThirdPartyPolicyInfo policyInfo = policyInfoMapper.selectElecAndServicePriceByStation(stationInfoId, timePeriod);
|
|
|
+
|
|
|
+ if (policyInfo != null) {
|
|
|
+ elecPrice = policyInfo.getElecPrice() != null ? policyInfo.getElecPrice() : BigDecimal.ZERO;
|
|
|
+ servicePrice = policyInfo.getServicePrice() != null ? policyInfo.getServicePrice() : BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal opFeeValue = opFee != null ? opFee : BigDecimal.ZERO;
|
|
|
+ return elecPrice.add(servicePrice).add(opFeeValue);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 保存价格策略明细
|