From eda58e0e6d4abdd2b060e28867d103045845aa69 Mon Sep 17 00:00:00 2001
From: 罗元桥 <2376770955@qq.com>
Date: 星期一, 30 八月 2021 13:13:18 +0800
Subject: [PATCH] Merge branch 'test' into 'yuyue_dev'

---
 springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngRealCompanyExcelListen.java |   36 +++++++++++++++++-------------------
 1 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngRealCompanyExcelListen.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngRealCompanyExcelListen.java
index fc0c521..88d0f24 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngRealCompanyExcelListen.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngRealCompanyExcelListen.java
@@ -1,21 +1,20 @@
 package com.panzhihua.common.listen;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
 import com.alibaba.fastjson.JSONObject;
 import com.panzhihua.common.exceptions.ServiceException;
 import com.panzhihua.common.model.vos.R;
-import com.panzhihua.common.model.vos.community.ComMngCarExcelVO;
-import com.panzhihua.common.model.vos.community.ComMngPopulationServeExcelVO;
 import com.panzhihua.common.model.vos.community.ComMngRealCompanyExcelVO;
 import com.panzhihua.common.service.community.CommunityService;
 import com.panzhihua.common.utlis.ListUtils;
 import com.panzhihua.common.utlis.StringUtils;
-import lombok.extern.slf4j.Slf4j;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * @description: 实有单位导入监听
@@ -25,35 +24,33 @@
 @Slf4j
 public class ComMngRealCompanyExcelListen extends AnalysisEventListener<ComMngRealCompanyExcelVO> {
 
+    private static final int BATCH_COUNT = 5000;
     private CommunityService communityService;
-
     private Long communityId;
+    private List<ComMngRealCompanyExcelVO> list = new ArrayList<>();
 
-    public ComMngRealCompanyExcelListen(CommunityService communityService, Long communityId){
+    public ComMngRealCompanyExcelListen(CommunityService communityService, Long communityId) {
         this.communityService = communityService;
         this.communityId = communityId;
     }
 
-
-    private static final int BATCH_COUNT = 5000;
-    private List<ComMngRealCompanyExcelVO> list = new ArrayList<>();
-
     @Override
     public void invoke(ComMngRealCompanyExcelVO comMngRealCompanyExcelVO, AnalysisContext analysisContext) {
-        if(StringUtils.isEmpty(comMngRealCompanyExcelVO.getCreditCode())){
+        if (StringUtils.isEmpty(comMngRealCompanyExcelVO.getCreditCode())) {
             throw new ServiceException("统一社会信用代码不可为空");
         }
         list.add(comMngRealCompanyExcelVO);
         // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
-        if(list.size() >= BATCH_COUNT){
+        if (list.size() >= BATCH_COUNT) {
             log.info("excel导入数据【{}】", JSONObject.toJSONString(list));
             // 根据list中的creditCode来去重
-            List<ComMngRealCompanyExcelVO> newVoList = list.stream().filter(ListUtils.distinctByKey(ComMngRealCompanyExcelVO::getCreditCode)).collect(Collectors.toList());
-            R r = this.communityService.listSaveMngRealCompanyExcelVO(newVoList,this.communityId);
+            List<ComMngRealCompanyExcelVO> newVoList = list.stream()
+                .filter(ListUtils.distinctByKey(ComMngRealCompanyExcelVO::getCreditCode)).collect(Collectors.toList());
+            R r = this.communityService.listSaveMngRealCompanyExcelVO(newVoList, this.communityId);
             if (!R.isOk(r)) {
                 throw new ServiceException(r.getMsg());
             }
-            list.clear();           //清空list
+            list.clear(); // 清空list
         }
 
     }
@@ -62,8 +59,9 @@
     public void doAfterAllAnalysed(AnalysisContext analysisContext) {
         log.info("excel导入数据【{}】", JSONObject.toJSONString(list));
         // 根据list中的creditCode来去重
-        List<ComMngRealCompanyExcelVO> newVoList = list.stream().filter(ListUtils.distinctByKey(ComMngRealCompanyExcelVO::getCreditCode)).collect(Collectors.toList());
-        R r = this.communityService.listSaveMngRealCompanyExcelVO(newVoList,this.communityId);//确保最后遗留的数据保存在数据库中
+        List<ComMngRealCompanyExcelVO> newVoList = list.stream()
+            .filter(ListUtils.distinctByKey(ComMngRealCompanyExcelVO::getCreditCode)).collect(Collectors.toList());
+        R r = this.communityService.listSaveMngRealCompanyExcelVO(newVoList, this.communityId);// 确保最后遗留的数据保存在数据库中
         if (!R.isOk(r)) {
             throw new ServiceException(r.getMsg());
         }

--
Gitblit v1.7.1