Преглед на файлове

Merge remote-tracking branch 'origin/master'

wzq преди 1 ден
родител
ревизия
8f2c889a45

+ 3 - 2
src/main/java/com/zsElectric/boot/business/model/vo/AppletStationPriceListVO.java

@@ -61,13 +61,14 @@ public class AppletStationPriceListVO implements Serializable {
         @Schema(description = "电费(元/度)")
         private BigDecimal elecPrice;
 
+
         @Schema(description = "服务费(元/度)")
         private BigDecimal servicePrice;
 
-        @Schema(description = "合计充电价(元/度)= 电费 + 服务费")
+        @Schema(description = "合计充电价(元/度)= c_policy_fee.综合销售费")
         private BigDecimal totalPrice;
 
-        @Schema(description = "企业价格(元/度)= 电费 + 服务费 + 运营费 + 综合销售费")
+        @Schema(description = "企业价格(元/度)= c_policy_fee.综合销售费(sales_type=1)")
         private BigDecimal enterprisePrice;
 
         @Schema(description = "是否当前时段")

+ 39 - 27
src/main/java/com/zsElectric/boot/business/service/impl/AppletHomeServiceImpl.java

@@ -467,7 +467,20 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             return result;
         }
         
-        // 4. 如果是企业用户,查询企业价格
+        // 4. 查询平台价格(salesType=0),用于普通用户的价格计算
+        Map<Integer, PolicyFee> platformPriceMap = new HashMap<>();
+        List<PolicyFee> platformPolicyFeeList = policyFeeMapper.selectList(
+                new LambdaQueryWrapper<PolicyFee>()
+                        .eq(PolicyFee::getStationInfoId, stationId)
+                        .eq(PolicyFee::getSalesType, 0) // 0-平台
+                        .eq(PolicyFee::getIsDeleted, 0)
+        );
+        log.info("查询平台价格记录数: {}, stationInfoId: {}", platformPolicyFeeList.size(), stationId);
+        for (PolicyFee policyFee : platformPolicyFeeList) {
+            platformPriceMap.put(policyFee.getPeriodFlag(), policyFee);
+        }
+        
+        // 5. 如果是企业用户,查询企业价格
         Map<Integer, BigDecimal> enterprisePriceMap = new HashMap<>();
         boolean hasEnterprisePrice = false;
         if (firmId != null) {
@@ -489,26 +502,11 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             
             // 构建企业价格映射 (periodFlag -> enterprisePrice)
             for (PolicyFee policyFee : policyFeeList) {
-                // 查找对应的时段价格信息(通过periodFlag匹配)
-                ThirdPartyPolicyInfo matchedPolicyInfo = policyInfoList.stream()
-                        .filter(info -> info.getPeriodFlag() != null && info.getPeriodFlag().equals(policyFee.getPeriodFlag()))
-                        .findFirst()
-                        .orElse(null);
-                
-                if (matchedPolicyInfo != null) {
-                    // 企业价格 = 电费 + 服务费 + 运营费 + 综合销售费
-                    BigDecimal elecPrice = matchedPolicyInfo.getElecPrice() != null ? matchedPolicyInfo.getElecPrice() : BigDecimal.ZERO;
-                    BigDecimal servicePrice = matchedPolicyInfo.getServicePrice() != null ? matchedPolicyInfo.getServicePrice() : BigDecimal.ZERO;
-                    BigDecimal opFee = policyFee.getOpFee() != null ? policyFee.getOpFee() : BigDecimal.ZERO;
-                    BigDecimal compSalesFee = policyFee.getCompSalesFee() != null ? policyFee.getCompSalesFee() : BigDecimal.ZERO;
-                    
-                    BigDecimal enterprisePrice = elecPrice.add(servicePrice).add(opFee).add(compSalesFee);
-                    enterprisePriceMap.put(policyFee.getPeriodFlag(), enterprisePrice);
-                    log.debug("企业价格计算 - periodFlag: {}, 电费: {}, 服务费: {}, 运营费: {}, 综合销售费: {}, 企业价: {}",
-                            policyFee.getPeriodFlag(), elecPrice, servicePrice, opFee, compSalesFee, enterprisePrice);
-                } else {
-                    log.warn("未找到匹配的价格策略明细,periodFlag: {}", policyFee.getPeriodFlag());
-                }
+                // 企业价格 = 综合销售费(直接取c_policy_fee.comp_sales_fee)
+                BigDecimal compSalesFee = policyFee.getCompSalesFee() != null ? policyFee.getCompSalesFee() : BigDecimal.ZERO;
+                enterprisePriceMap.put(policyFee.getPeriodFlag(), compSalesFee);
+                log.debug("企业价格计算 - periodFlag: {}, 综合销售费(企业价): {}",
+                        policyFee.getPeriodFlag(), compSalesFee);
             }
         }
         
@@ -516,7 +514,7 @@ public class AppletHomeServiceImpl implements AppletHomeService {
         result.setHasEnterprisePrice(hasEnterprisePrice);
         log.info("是否有企业价格: {}", hasEnterprisePrice);
         
-        // 5. 构建价格列表
+        // 6. 构建价格列表
         List<AppletStationPriceListVO.PriceItemVO> priceList = new ArrayList<>();
         for (int i = 0; i < policyInfoList.size(); i++) {
             ThirdPartyPolicyInfo policyInfo = policyInfoList.get(i);
@@ -533,12 +531,26 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             priceItem.setPeriodFlag(policyInfo.getPeriodFlag());
             priceItem.setPeriodFlagName(getPeriodFlagName(policyInfo.getPeriodFlag()));
             priceItem.setElecPrice(policyInfo.getElecPrice());
-            priceItem.setServicePrice(policyInfo.getServicePrice());
             
-            // 合计充电价 = 电费 + 服务费
-            BigDecimal elecPrice = policyInfo.getElecPrice() != null ? policyInfo.getElecPrice() : BigDecimal.ZERO;
-            BigDecimal servicePrice = policyInfo.getServicePrice() != null ? policyInfo.getServicePrice() : BigDecimal.ZERO;
-            priceItem.setTotalPrice(elecPrice.add(servicePrice));
+            // 从平台价格映射中获取运营费和综合销售费
+            BigDecimal originalServicePrice = policyInfo.getServicePrice() != null ? policyInfo.getServicePrice() : BigDecimal.ZERO;
+            BigDecimal platformOpFee = BigDecimal.ZERO;
+            BigDecimal platformCompSalesFee = BigDecimal.ZERO;
+            
+            PolicyFee platformPolicyFee = platformPriceMap.get(policyInfo.getPeriodFlag());
+            if (platformPolicyFee != null) {
+                platformOpFee = platformPolicyFee.getOpFee() != null ? platformPolicyFee.getOpFee() : BigDecimal.ZERO;
+                platformCompSalesFee = platformPolicyFee.getCompSalesFee() != null ? platformPolicyFee.getCompSalesFee() : BigDecimal.ZERO;
+            }
+            
+            // 服务费 = 原服务费 + 运营费
+            BigDecimal servicePrice = originalServicePrice.add(platformOpFee);
+            priceItem.setServicePrice(servicePrice);
+            
+            // 合计充电价 = 综合销售费(直接取c_policy_fee.comp_sales_fee)
+            priceItem.setTotalPrice(platformCompSalesFee);
+            log.debug("平台价格计算 - periodFlag: {}, 电费: {}, 原服务费: {}, 运营费: {}, 服务费(含运营): {}, 综合销售费(totalPrice): {}",
+                    policyInfo.getPeriodFlag(), policyInfo.getElecPrice(), originalServicePrice, platformOpFee, servicePrice, platformCompSalesFee);
             
             // 设置企业价格(如果有)- 通过periodFlag匹配
             BigDecimal enterprisePrice = enterprisePriceMap.get(policyInfo.getPeriodFlag());

+ 33 - 0
src/main/java/com/zsElectric/boot/business/service/impl/UserFirmServiceImpl.java

@@ -1,17 +1,21 @@
 package com.zsElectric.boot.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zsElectric.boot.business.mapper.UserFirmMapper;
+import com.zsElectric.boot.business.mapper.UserInfoMapper;
 import com.zsElectric.boot.business.service.UserFirmService;
 import com.zsElectric.boot.business.model.entity.UserFirm;
+import com.zsElectric.boot.business.model.entity.UserInfo;
 import com.zsElectric.boot.business.model.form.UserFirmForm;
 import com.zsElectric.boot.business.model.query.UserFirmQuery;
 import com.zsElectric.boot.business.model.vo.UserFirmVO;
 import com.zsElectric.boot.business.converter.UserFirmConverter;
+import com.zsElectric.boot.core.exception.BusinessException;
 
 import java.util.Arrays;
 import java.util.List;
@@ -40,6 +44,7 @@ public class UserFirmServiceImpl extends ServiceImpl<UserFirmMapper, UserFirm> i
 
     private final UserFirmConverter userFirmConverter;
     private final FirmInfoService firmInfoService;
+    private final UserInfoMapper userInfoMapper;
 
     /**
     * 获取企业与用户关系分页列表
@@ -84,6 +89,34 @@ public class UserFirmServiceImpl extends ServiceImpl<UserFirmMapper, UserFirm> i
      */
     @Override
     public boolean saveUserFirm(UserFirmForm formData) {
+        // 通过手机号查询c_user_info表,验证用户是否存在
+        String phone = formData.getPhone();
+        Assert.isTrue(StrUtil.isNotBlank(phone), "手机号不能为空");
+        
+        UserInfo userInfo = userInfoMapper.selectOne(
+                new LambdaQueryWrapper<UserInfo>()
+                        .eq(UserInfo::getPhone, phone)
+                        .eq(UserInfo::getIsDeleted, 0)
+        );
+        
+        if (userInfo == null) {
+            throw new BusinessException("该手机号用户不存在,请先在小程序端注册");
+        }
+        
+        // 检查该用户是否已经关联了企业
+        UserFirm existingUserFirm = this.getOne(
+                new LambdaQueryWrapper<UserFirm>()
+                        .eq(UserFirm::getUserId, userInfo.getId())
+                        .eq(UserFirm::getIsDeleted, 0)
+        );
+        
+        if (existingUserFirm != null) {
+            throw new BusinessException("该用户已经关联了企业,不能重复添加");
+        }
+        
+        // 设置用户ID
+        formData.setUserId(userInfo.getId());
+        
         UserFirm entity = userFirmConverter.toEntity(formData);
         return this.save(entity);
     }