Jelajahi Sumber

合并读取私有非车, 私有车险,平台数据的Listener为一个公共的controller方法

在原有方法的基础上,添加一个type,进行区分
lipf 1 bulan lalu
induk
melakukan
7e44ccb560

+ 31 - 0
commons/src/main/java/com/jzg/commons/entity/finance/vo/importimcome/InsuranceData.java

@@ -9,4 +9,35 @@ import java.io.Serializable;
  * @date 2026/8/17 15:49
  */
 public interface InsuranceData extends Serializable {
+
+    /**
+     * 交强险保单号。
+     * <p>
+     * 用于在统一处理各 {@link InsuranceData} 实体时按接口多态读取,
+     * 实体若不存在该字段则返回 {@code null}。
+     * </p>
+     *
+     * @return 交强险保单号,实体无此字段时返回 null
+     */
+    default String getJqPolicyNo() {
+        return null;
+    }
+
+    /**
+     * 商业险保单号。
+     *
+     * @return 商业险保单号,实体无此字段时返回 null
+     */
+    default String getSyPolicyNo() {
+        return null;
+    }
+
+    /**
+     * 非车险保单号。
+     *
+     * @return 非车险保单号,实体无此字段时返回 null
+     */
+    default String getJyPolicyNo() {
+        return null;
+    }
 }

+ 11 - 16
tenant/organization/src/main/java/com/jzg/organization/controller/ReceivableController.java

@@ -150,7 +150,7 @@ public class ReceivableController {
     /**
      * 导入应收的模板
      *
-     * @param paramVO  20 表示平台协议  11表示车险手续费 12 表示非车险手续费 13 表示车险跟单费 14 表示非车险跟单费
+     * @param paramVO  20 表示平台协议  11表示车险手续费 12 表示非车险手续费 13 表示车险跟单费 14 表示非车险跟单费 (13、14 暂时不需要实现)
      * @author lipf
      * @date 2026/8/3 10:23
      */
@@ -161,24 +161,19 @@ public class ReceivableController {
         return HttpResult.ok(receivablePageIds);
     }
 
-    @PostMapping("/importAccountsReceivableInvoice")
-    @Operation(summary = "导入应收开票数据")
-    public HttpResult<ImportUpdateExcelResultVo> importAccountsReceivableInvoice(@RequestParam("file") MultipartFile file){
-        ImportUpdateExcelResultVo importExcelResultVo = receivableService.importAccountsReceivableInvoice4NoCarRisk(file);
-        return HttpResult.ok(importExcelResultVo);
-    }
 
-    @PostMapping("/importAccountsReceivableInvoice4CarRisk")
-    @Operation(summary = "导入应收开票数据")
-    public HttpResult<ImportUpdateExcelResultVo> importAccountsReceivableInvoice4CarRisk(@RequestParam("file") MultipartFile file){
-        ImportUpdateExcelResultVo importExcelResultVo = receivableService.importAccountsReceivableInvoice4CarRisk(file);
-        return HttpResult.ok(importExcelResultVo);
-    }
 
+    /**
+     * 导入应收开票数据
+     *      私有车险应收/私有非车险应收/平台应收
+     * @author lipf
+     * @date 2026/8/17 17:05
+     */
     @PostMapping("/importPlatformReceivableInvoice")
-    @Operation(summary = "导入平台应收开票数据")
-    public HttpResult<ImportUpdateExcelResultVo> importPlatformReceivableInvoice(@RequestParam("file") MultipartFile file){
-        ImportUpdateExcelResultVo importExcelResultVo = receivableService.importPlatformReceivableInvoice(file);
+    @Operation(summary = "导入应收开票数据")
+    public HttpResult<ImportUpdateExcelResultVo> importPlatformReceivableInvoice(@RequestParam("file") MultipartFile file,
+                                                                                @RequestParam("type") String type){
+        ImportUpdateExcelResultVo importExcelResultVo = receivableService.importPlatformReceivableInvoice(file, type);
         return HttpResult.ok(importExcelResultVo);
     }
 

+ 1 - 19
tenant/organization/src/main/java/com/jzg/organization/service/ReceivableService.java

@@ -437,30 +437,12 @@ public interface ReceivableService extends IService<InsPlyIncome> {
      */
     String exportAccountsReceivableInvoiceTemplate(String type);
 
-    /**
-     *
-     * 非车险应收数据导入
-     *
-     * @param file
-     * @return
-     */
-    ImportUpdateExcelResultVo importAccountsReceivableInvoice4NoCarRisk(MultipartFile file);
-
-    /**
-     * 车险应收数据导入
-     *
-     * @author lipf
-     * @date 2026/8/17 15:43
-     */
-    ImportUpdateExcelResultVo importAccountsReceivableInvoice4CarRisk(MultipartFile file);
-
-
     /**
      * 导入应收开票数据
      * @param file
      * @return
      */
-    ImportUpdateExcelResultVo importPlatformReceivableInvoice(MultipartFile file);
+    ImportUpdateExcelResultVo importPlatformReceivableInvoice(MultipartFile file, String type);
 
     /**
      * 删除结算记录

+ 29 - 134
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -2534,148 +2534,16 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 "应收开票-导出模板(平台)-" + Instant.now());
     }
 
-    /**
-     * 车险应收数据导入
-     *
-     * @param file
-     * @author lipf
-     * @date 2026/8/17 15:43
-     */
-    @Override
-    public ImportUpdateExcelResultVo importAccountsReceivableInvoice4CarRisk(MultipartFile file) {
-        String userName = baseController.getUserName();
-        log.info("用户[{}]导入私有车险应收文件",userName);
-
-        List<ExcelContent4PrivateSuperviseCar> excelContents = importIncomeService.parseImportExcel4PrivateCar(file);
-        if (CollUtil.isEmpty(excelContents)){
-            log.info("数据不能为空,导入失败");
-            throw new SystemException("数据不能为空,导入失败");
-        }
-        AssertionUtils.isEmpty(excelContents, "车险应收数据处理失败,导入失败");
-        //List<ImportContentExt> datas = importIncomeService.fillExcelContent4Private(excelContents);
-
-
-        return null;
-    }
-
-    /**
-     * 导入应收开票数据
-     * @param file Excel文件,包含应收开票数据,文件格式应符合InvoiceReceivableExportExcelVo的定义
-     * @return ImportUpdateExcelResultVo 返回导入结果对象,包含:
-     *         - successNumber: 成功导入的记录数(新增或更新)
-     *         - failedNumber: 失败的记录数
-     *         - failedData: 失败的数据列表,包含错误原因说明
-     *         - failFileUrl: 失败数据Excel文件的下载链接(如果有失败数据)
-     *         - orderNos: 成功导入的订单号列表
-     */
-    @Override
-    public ImportUpdateExcelResultVo importAccountsReceivableInvoice4NoCarRisk(MultipartFile file) {
-        String userName = baseController.getUserName();
-        log.info("用户[{}]导入私有非车险应收文件",userName);
-
-        List<ExcelContent4PrivateSuperviseNoCar> excelContents = importIncomeService.parseImportExcel4PrivateNoCar(file);
-        if (CollUtil.isEmpty(excelContents)){
-            throw new SystemException("数据不能为空,导入失败");
-        }
-        AssertionUtils.isEmpty(excelContents, "数据处理失败,导入失败");
-        List<ImportContentExt> datas = importIncomeService.fillExcelContent4Private(excelContents);
-
-
-        // int failedNumber = 0;
-        List<ImportContentExt> failedExcel = new ArrayList<>();
-        // 只存储需要【修改】的数据
-        List<InsPlyIncome> updateExcel = new ArrayList<>();
-        List<InsPlyIncome> insertExcel = new ArrayList<>();
-        // 存储导入成功的订单号
-        List<String> successOrderNoList = new ArrayList<>();
-
-        // 校验Excel内部保单号重复
-        Set<String> existPolicyNoSet = new HashSet<>();
-        Set<String> repeatPolicyNoSet = new HashSet<>();
-        Set<String> existCompanyIdSet = new HashSet<>();
-
-        for (ImportContentExt vo : datas) {
-            String policyNo = vo.getJqPolicyNo();
-            if (existPolicyNoSet.contains(policyNo)) {
-                repeatPolicyNoSet.add(policyNo);
-            } else {
-                existPolicyNoSet.add(policyNo);
-            }
-            existCompanyIdSet.add(vo.getCompanyName());
-        }
-
-        // 导入只能一个保司
-        if (existCompanyIdSet.size() > 1) {
-            throw new SystemException("导入数据不能包含多个保险公司");
-        }
-
-        // 处理数据
-        for (ImportContentExt vo : datas) {
-            // 1. 空数据校验
-            ImportResultVo resultVo = vo.checkEmpty();
-            if (!resultVo.isSuccess()) {
-                vo.setErrorMessage(resultVo.convert2Str());
-                failedExcel.add(vo);
-                continue;
-            }
-
-            // 2. Excel内部保单号重复
-            if (repeatPolicyNoSet.contains(vo.getJqPolicyNo())) {
-                vo.setErrorMessage("保单号重复");
-                failedExcel.add(vo);
-                continue;
-            }
-
-            // 查询订单
-            HttpResult<InsOrdersVo> insOrdersVoHttpResult = insOrdersClient.selectById(vo.getOrderNo());
-            InsOrdersVo data = insOrdersVoHttpResult.getData();
-            if (null == data){
-                vo.setErrorMessage("订单号不存在");
-                failedExcel.add(vo);
-                continue;
-            }
-
-            // 查询数据库中是否已存在该协议
-            PtlAgreement ptlAgreement = ptlAgreementMapper.selectOne(new LambdaQueryWrapper<PtlAgreement>()
-                    .eq(PtlAgreement::getId, data.getAgreementId()));
-
-            // 数据库不存在 → 直接失败
-            if (Objects.isNull(ptlAgreement) || !"2".equals(ptlAgreement.getAgreementType().toString())) {
-                vo.setErrorMessage("协议编码在协议中不存在");
-                failedExcel.add(vo);
-                continue;
-            }
-
-            // 查询数据库中是否已存在该保单号
-            ImportContentExt failedVO = importIncomeService.spliceData(vo, insertExcel, updateExcel);
-            if(failedVO != null){
-                failedExcel.add(failedVO);
-            }
-        }
-        ImportUpdateExcelResultVo importExcelResultVo = importIncomeService.getDataManipulationResult(updateExcel, insertExcel, failedExcel);
-        log.info("私有应收:导入结果。importExcelResultVo=[{}]", JSONUtil.toJsonStr(importExcelResultVo));
-        return importExcelResultVo;
-    }
-
     /**
      * 导入平台的应收数据
      * @param file
      * @return
      */
     @Override
-    public ImportUpdateExcelResultVo importPlatformReceivableInvoice(MultipartFile file) {
+    public ImportUpdateExcelResultVo importPlatformReceivableInvoice(MultipartFile file, String type) {
         String userName = baseController.getUserName();
         log.info("用户[{}]导入平台应收文件",userName);
-
-        List<ExcelContent4Platform> excelContents = importIncomeService.parseImportExcel4Platform(file);
-        log.info("从Excel文件中读取到[{}]条记录", CollUtil.size(excelContents));
-        if (CollUtil.isEmpty(excelContents)){
-            log.error("用户[{}]导入平台应收文件,数据不能为空,导入失败",userName);
-            throw new SystemException("数据不能为空,导入失败");
-        }
-        AssertionUtils.isEmpty(excelContents, "数据处理失败,导入失败");
-        List<ImportContentExt> datas = importIncomeService.fillExcelContent4Platform(excelContents);
-
+        List<ImportContentExt> datas = this.parseAndFillContent(file, type);
         // 只存储需要【修改】的数据
         List<InsPlyIncome> updateExcel = new ArrayList<>();
         List<InsPlyIncome> insertExcel = new ArrayList<>();
@@ -2731,6 +2599,33 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         return importExcelResultVo;
     }
 
+    /**
+     * 解析Excel内容并填充缺失的字段
+     *
+     * @param type 类型 20 表示平台协议  11表示车险手续费 12 表示非车险手续费
+     * @param file 上传的文件
+     * @author lipf
+     * @date 2026/8/17 16:57
+     */
+    private List<ImportContentExt> parseAndFillContent(MultipartFile file, String type) {
+        log.info("解析Excel内容并填充缺失的字段. type=[{}]", type);
+
+        if("11".equals(type)){
+            List<ExcelContent4PrivateSuperviseCar> excelContents2 = importIncomeService.parseImportExcel4PrivateCar(file);
+            return importIncomeService.fillExcelContent4All(excelContents2);
+        } if("12".equals(type)){
+            List<ExcelContent4PrivateSuperviseNoCar> excelContents3 = importIncomeService.parseImportExcel4PrivateNoCar(file);
+            return importIncomeService.fillExcelContent4All(excelContents3);
+//        } if("20".equals(type)){
+//            List<ExcelContent4Platform> excelContents = importIncomeService.parseImportExcel4Platform(file);
+//            return importIncomeService.fillExcelContent4All(excelContents);
+        }else{
+            List<ExcelContent4Platform> excelContents = importIncomeService.parseImportExcel4Platform(file);
+            return importIncomeService.fillExcelContent4All(excelContents);
+//            log.info("解析Excel内容并填充缺失的字段.类型不支持 type=[{}]", type);
+//            return Collections.emptyList();
+        }
+    }
 
 
     /**

+ 8 - 2
tenant/organization/src/main/java/com/jzg/organization/service/impl/importincome/ImportIncomeServiceImpl.java

@@ -192,18 +192,24 @@ public class ImportIncomeServiceImpl implements ImportIncomeService {
 
     /**
      * 对表格中的内容进行扩展
+     * <p>
+     * 支持同时传入不同的 {@link InsuranceData} 实现类集合(如平台、私有车险、私有非车险),
+     * 统一进行数据扩展处理。
+     * </p>
      *
+     * @param excelContents {@link InsuranceData} 实现类集合
+     * @return 扩展后的数据列表
      * @author lipf
      * @date 2026/8/4 9:22
      */
     @Override
-    public List<ImportContentExt> fillExcelContent4Platform(List<ExcelContent4Platform> excelContents) {
+    public <T extends InsuranceData> List<ImportContentExt> fillExcelContent4All(List<T> excelContents) {
         log.info("填充excel中没有的内容: excelContents.size=[{}]", CollUtil.size(excelContents));
         if(CollUtil.isEmpty(excelContents)){
             return Collections.emptyList();
         }
         List<ImportContentExt> res = new ArrayList<>();
-        for (ExcelContent4Platform excelContent : excelContents) {
+        for (InsuranceData excelContent : excelContents) {
             ImportContentExt ext = new ImportContentExt();
             BeanUtil.copyProperties(excelContent,ext);
             // 查询订单

+ 7 - 1
tenant/organization/src/main/java/com/jzg/organization/service/importincome/ImportIncomeService.java

@@ -12,11 +12,17 @@ public interface ImportIncomeService {
 
     /**
      * 对表格中的内容进行扩展
+     * <p>
+     * 支持同时传入不同的 {@link InsuranceData} 实现类集合(如平台、私有车险、私有非车险),
+     * 统一进行数据扩展处理。
+     * </p>
      *
+     * @param excelContents {@link InsuranceData} 实现类集合
+     * @return 扩展后的数据列表
      * @author lipf
      * @date 2026/8/4 9:22
      */
-    public List<ImportContentExt> fillExcelContent4Platform(List<ExcelContent4Platform> excelContents);
+    <T extends InsuranceData> List<ImportContentExt> fillExcelContent4All(List<T> excelContents);
 
     /**
      * 对表格中的内容进行扩展