Bläddra i källkod

提交查询固定企业

chenxiaofei 14 timmar sedan
förälder
incheckning
8c91d328c4

+ 9 - 0
sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/RemoteSystemService.java

@@ -291,6 +291,15 @@ public interface RemoteSystemService {
 
     KwsEnterpriseResDto findEnterpriseByName(String consignCompany);
 
+    /**
+     * 根据企业名称和企业类型精确查询企业,适用于存在同名企业时需要按类型确定唯一企业的场景。
+     *
+     * @param enterpriseName 企业名称
+     * @param entType 企业类型
+     * @return 企业信息
+     */
+    KwsEnterpriseResDto findEnterpriseByNameAndType(String enterpriseName, Integer entType);
+
     PageDataResult<KwsEnterpriseResDto> pageEnt(int pageNum, int pageSize, Long entId);
 
     KwsEnterpriseResDto queryEnterpriseByEntId(Long entId);

+ 8 - 2
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java

@@ -140,6 +140,10 @@ public class KwoTradeOrderService {
      * 服务费冻结使用的固定供应方企业名称。
      */
     private static final String SERVICE_FEE_SUPPLY_ENTERPRISE_NAME = "四川开物信息技术有限公司";
+    /**
+     * 服务费固定供应方企业类型。
+     */
+    private static final int SERVICE_FEE_SUPPLY_ENTERPRISE_TYPE = -1;
 
     @DubboReference(version = "1.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
@@ -2831,7 +2835,9 @@ public class KwoTradeOrderService {
             throw new BusinessException("供应方企业名称不能为空");
         }
         try {
-            KwsEnterpriseResDto enterprise = remoteSystemService.findEnterpriseByName(enterpriseName);
+            KwsEnterpriseResDto enterprise = remoteSystemService.findEnterpriseByNameAndType(
+                    enterpriseName,
+                    SERVICE_FEE_SUPPLY_ENTERPRISE_TYPE);
             return resolveEnterpriseIdByName(enterprise, enterpriseName);
         } catch (BusinessException e) {
             throw e;
@@ -2851,7 +2857,7 @@ public class KwoTradeOrderService {
     static Long resolveEnterpriseIdByName(KwsEnterpriseResDto enterprise, String enterpriseName) {
         if (enterprise == null || enterprise.getId() == null) {
             log.warn("根据企业名称未查询到有效企业,enterpriseName={}", enterpriseName);
-            return null;
+            throw new BusinessException("固定服务费供应方企业不存在:" + enterpriseName);
         }
         return enterprise.getId();
     }

+ 9 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEnterpriseDao.java

@@ -240,6 +240,15 @@ public interface KwsEnterpriseDao extends BaseMapper<KwsEnterprise> {
 
     KwsEnterprise findEnterpriseByName(@Param("enterpriseName") String enterpriseName);
 
+    /**
+     * 根据企业名称和企业类型查询企业,避免同名企业时取错企业ID。
+     *
+     * @param enterpriseName 企业名称
+     * @param entType 企业类型
+     * @return 企业信息
+     */
+    KwsEnterprise findEnterpriseByNameAndType(@Param("enterpriseName") String enterpriseName, @Param("entType") Integer entType);
+
     EntInfo query(@Param("entName") String entName);
 
     List<EntBaseInfo> queryCte(Long entId);

+ 17 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteBaseService.java

@@ -339,6 +339,23 @@ public class RemoteBaseService {
         return kwsEnterpriseResDto;
     }
 
+    /**
+     * 根据企业名称和企业类型精确查询企业,避免同名企业时取错企业ID。
+     *
+     * @param enterpriseName 企业名称
+     * @param entType 企业类型
+     * @return 企业信息
+     */
+    public KwsEnterpriseResDto findEnterpriseByNameAndType(String enterpriseName, Integer entType) {
+        KwsEnterprise kwsEnterprise = kwsEnterpriseDao.findEnterpriseByNameAndType(enterpriseName, entType);
+        if (Objects.isNull(kwsEnterprise)) {
+            return null;
+        }
+        KwsEnterpriseResDto kwsEnterpriseResDto = new KwsEnterpriseResDto();
+        BeanUtils.copyProperties(kwsEnterprise, kwsEnterpriseResDto);
+        return kwsEnterpriseResDto;
+    }
+
     public PageDataResult<KwsEnterpriseResDto> pageEnt(int pageNum, int pageSize, Long entId) {
         IPage<KwsEnterprise> kwsEnterprisePage = kwsEnterpriseReposiory.pageEnt(pageNum, pageSize, entId);
         List<KwsEnterprise> records = kwsEnterprisePage.getRecords();

+ 12 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java

@@ -958,6 +958,18 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
         return dto;
     }
 
+    /**
+     * 根据企业名称和企业类型精确查询企业,避免同名企业时取错企业ID。
+     *
+     * @param enterpriseName 企业名称
+     * @param entType        企业类型
+     * @return 企业信息
+     */
+    @Override
+    public KwsEnterpriseResDto findEnterpriseByNameAndType(String enterpriseName, Integer entType) {
+        return remoteBaseService.findEnterpriseByNameAndType(enterpriseName, entType);
+    }
+
     /**
      * 分页查询企业信息
      *

+ 17 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsEnterpriseDao.xml

@@ -920,6 +920,23 @@
         where firm_name = #{enterpriseName}
     </select>
 
+    <select id="findEnterpriseByNameAndType" resultMap="BaseResultMap">
+        select a.*
+        from kws_enterprise a
+        where a.firm_name = #{enterpriseName}
+          and a.status = 0
+          and a.del_flag = 0
+          and exists (
+              select 1
+              from kws_ent_type b
+              where b.ent_id = a.id
+                and b.type = #{entType}
+                and b.status = 0
+                and b.del_flag = 0
+          )
+        limit 1
+    </select>
+
     <select id="query" resultType="com.sckw.system.model.vo.res.EntInfo">
         select id as entId, firm_name as entName
         from kws_enterprise

+ 46 - 4
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/ParkingWalletFeeService.java

@@ -14,6 +14,7 @@ import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.result.PageDataResult;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.EntCacheResDto;
+import com.sckw.system.api.model.dto.res.KwsEnterpriseResDto;
 import com.sckw.transport.api.model.param.ParkingWalletFeeFreezeParam;
 import com.sckw.transport.api.model.vo.ParkingWalletFeeFreezeResult;
 import com.sckw.transport.model.*;
@@ -66,6 +67,14 @@ public class ParkingWalletFeeService {
     private static final int TRADE_TYPE_UNFREEZE = 5;
     /** 钱包明细交易类型:消费(订单完结按实际履约量正式扣减服务费) */
     private static final int TRADE_TYPE_CONSUME = 6;
+    /**
+     * 平台服务费供应方企业名称。
+     */
+    private static final String PLATFORM_SERVICE_FEE_SUPPLY_ENTERPRISE_NAME = "四川开物信息技术有限公司";
+    /**
+     * 平台服务费供应方企业类型。
+     */
+    private static final int PLATFORM_SERVICE_FEE_SUPPLY_ENTERPRISE_TYPE = -1;
 
     /**
      * 查询汇总服务费
@@ -74,7 +83,7 @@ public class ParkingWalletFeeService {
     public ParkingWalletFeeResp queryTotalServerFee(ParkingWalletFeeTotalQueryParam param) {
         log.info("查询汇总服务费:{}", JSON.toJSONString(param));
         if (param.getSupEntId() != null) {
-            param.setSupEntId(551429255406292993L);
+            param.setSupEntId(resolvePlatformServiceFeeSupEntId());
         }
 
         //构建查询条件
@@ -157,7 +166,7 @@ public class ParkingWalletFeeService {
     public PageDataResult<ParkingWalletFeeResp> pageQueryServerFee(ParkingWalletFeeQueryParam param) {
         log.info("分页查询服务费:{}", JSON.toJSONString(param));
         if (param.getSupEntId() != null) {
-            param.setSupEntId(551429255406292993L);
+            param.setSupEntId(resolvePlatformServiceFeeSupEntId());
         }
 
         //构建查询条件
@@ -222,7 +231,7 @@ public class ParkingWalletFeeService {
     public void saveServerFee(ParkingWalletFeeSaveParam param) {
         log.info("保存服务费,param:{}", JSON.toJSONString(param));
         if (param.getSupEntId() != null) {
-            param.setSupEntId(551429255406292993L);
+            param.setSupEntId(resolvePlatformServiceFeeSupEntId());
         }
 
         KwtParkingWalletFee walletFee = parkingWalletFeeRepository.getById(param.getId());
@@ -264,7 +273,7 @@ public class ParkingWalletFeeService {
     public PageDataResult<ParkingWalletFeeBalanceResp> pageQueryServerFeeDetails(ParkingWalletFeeBalanceQueryParam param) {
         log.info("分页查询服务费明细:{}", JSON.toJSONString(param));
         if (param.getSupEntId() != null) {
-            param.setSupEntId(551429255406292993L);
+            param.setSupEntId(resolvePlatformServiceFeeSupEntId());
         }
         //构建查询条件
         LambdaQueryWrapper<KwtParkingWalletFeeBalance> wrapper = buildAndExecuteQuery(param);
@@ -1126,5 +1135,38 @@ public class ParkingWalletFeeService {
         return walletFee.getServiceFeeBalance();
     }
 
+    /**
+     * 解析平台服务费供应方企业ID。
+     *
+     * @return 平台服务费供应方企业ID
+     */
+    private Long resolvePlatformServiceFeeSupEntId() {
+        try {
+            KwsEnterpriseResDto enterprise = remoteSystemService.findEnterpriseByNameAndType(
+                    PLATFORM_SERVICE_FEE_SUPPLY_ENTERPRISE_NAME,
+                    PLATFORM_SERVICE_FEE_SUPPLY_ENTERPRISE_TYPE);
+            return resolveEnterpriseIdByName(enterprise, PLATFORM_SERVICE_FEE_SUPPLY_ENTERPRISE_NAME);
+        } catch (BusinessPlatfromException e) {
+            throw e;
+        } catch (Exception e) {
+            log.error("查询平台固定服务费供应方企业失败,enterpriseName={}", PLATFORM_SERVICE_FEE_SUPPLY_ENTERPRISE_NAME, e);
+            throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "查询平台固定服务费供应方企业失败");
+        }
+    }
+
+    /**
+     * 校验企业名称查询结果并提取企业ID。
+     *
+     * @param enterprise     企业信息
+     * @param enterpriseName 企业名称
+     * @return 企业ID
+     */
+    static Long resolveEnterpriseIdByName(KwsEnterpriseResDto enterprise, String enterpriseName) {
+        if (enterprise == null || enterprise.getId() == null) {
+            log.warn("根据企业名称未查询到有效企业,enterpriseName={}", enterpriseName);
+            throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "平台服务费供应方企业不存在:" + enterpriseName);
+        }
+        return enterprise.getId();
+    }
 
 }

+ 34 - 0
sckw-modules/sckw-transport/src/test/java/com/sckw/transport/service/ParkingWalletFeeServiceTest.java

@@ -0,0 +1,34 @@
+package com.sckw.transport.service;
+
+import com.sckw.core.exception.BusinessPlatfromException;
+import com.sckw.system.api.model.dto.res.KwsEnterpriseResDto;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 服务费钱包单元测试。
+ */
+public class ParkingWalletFeeServiceTest {
+
+    /**
+     * 企业名称查询结果有效时,应返回企业ID。
+     */
+    @Test
+    public void resolveEnterpriseIdByNameWhenEnterpriseExists() {
+        KwsEnterpriseResDto enterprise = new KwsEnterpriseResDto();
+        enterprise.setId(551429255406292993L);
+        enterprise.setFirmName("四川开物信息技术有限公司");
+
+        Long actual = ParkingWalletFeeService.resolveEnterpriseIdByName(enterprise, enterprise.getFirmName());
+
+        Assert.assertEquals(Long.valueOf(551429255406292993L), actual);
+    }
+
+    /**
+     * 企业名称查询结果无效时,应抛出业务异常,避免继续使用空供应方ID。
+     */
+    @Test(expected = BusinessPlatfromException.class)
+    public void resolveEnterpriseIdByNameWhenEnterpriseMissing() {
+        ParkingWalletFeeService.resolveEnterpriseIdByName(null, "四川开物信息技术有限公司");
+    }
+}