From 6992c36126ce8645727e8473785c56c4e08e4933 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Sat, 2 May 2020 14:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=91=98=E3=80=81=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E5=92=8C=E4=BC=81=E4=B8=9A=E7=9A=84=E7=BB=91=E5=AE=9A=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/apis/data/DataController.java | 10 ++ .../com/cm/inspection/dao/data/IDataDao.java | 2 + .../excel/data/EnterprisePersonExcel.java | 47 ++++++++ .../excel/data/EnterprisePersonListener.java | 49 ++++++++ .../excel/data/VillageOrganPersonExcel.java | 37 ++++++ .../data/VillageOrganPersonListener.java | 49 ++++++++ .../listener/excel/data/VillagePerson.java | 8 +- .../inspection/service/data/IDataService.java | 16 +++ .../service/data/impl/DataServiceImpl.java | 109 +++++++++++++++++- .../mybatis/mapper/data/data-mapper.xml | 15 +++ .../mapper/enterprise/enterprise-mapper.xml | 4 + 11 files changed, 337 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonExcel.java create mode 100644 src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonListener.java create mode 100644 src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonExcel.java create mode 100644 src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonListener.java diff --git a/src/main/java/com/cm/inspection/controller/apis/data/DataController.java b/src/main/java/com/cm/inspection/controller/apis/data/DataController.java index 7273d22..b745f73 100644 --- a/src/main/java/com/cm/inspection/controller/apis/data/DataController.java +++ b/src/main/java/com/cm/inspection/controller/apis/data/DataController.java @@ -50,4 +50,14 @@ public class DataController { return dataService.saveVillageGroupPerson(); } + @PostMapping("savevillageorganperson") + public SuccessResult saveVillageOrganPerson() throws Exception { + return dataService.saveVillageOrganPerson(); + } + + @PostMapping("savecompanyperson") + public SuccessResult saveCompanyPerson() throws Exception { + return dataService.saveCompanyPerson(); + } + } diff --git a/src/main/java/com/cm/inspection/dao/data/IDataDao.java b/src/main/java/com/cm/inspection/dao/data/IDataDao.java index 47043ed..d4cb2b8 100644 --- a/src/main/java/com/cm/inspection/dao/data/IDataDao.java +++ b/src/main/java/com/cm/inspection/dao/data/IDataDao.java @@ -27,4 +27,6 @@ public interface IDataDao { UserDTO getUser(Map params); void saveUser(Map userParams); + + void saveDepartmentUser(Map params); } diff --git a/src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonExcel.java b/src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonExcel.java new file mode 100644 index 0000000..c65d76b --- /dev/null +++ b/src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonExcel.java @@ -0,0 +1,47 @@ +package com.cm.inspection.listener.excel.data; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: EnterprisePersonExcel + * @Description: 企业人员 + * @Author: WangGeng + * @Date: 2020/5/2 10:54 上午 + * @Version: 1.0 + **/ +public class EnterprisePersonExcel { + + @ExcelProperty(index = 2) + private Integer companyId; + @ExcelProperty(index = 4) + private Integer userId; + @ExcelProperty(index = 5) + private Integer isDeleted; + + public Integer getCompanyId() { + return companyId; + } + + public void setCompanyId(Integer companyId) { + this.companyId = companyId; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Integer getIsDeleted() { + return isDeleted; + } + + public void setIsDeleted(Integer isDeleted) { + this.isDeleted = isDeleted; + } +} diff --git a/src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonListener.java b/src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonListener.java new file mode 100644 index 0000000..146697d --- /dev/null +++ b/src/main/java/com/cm/inspection/listener/excel/data/EnterprisePersonListener.java @@ -0,0 +1,49 @@ +package com.cm.inspection.listener.excel.data; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: EnterprisePersonListener + * @Description: 企业人员 + * @Author: WangGeng + * @Date: 2020/5/2 10:54 上午 + * @Version: 1.0 + **/ +public abstract class EnterprisePersonListener extends AnalysisEventListener { + private static final Logger LOG = LoggerFactory.getLogger(EnterprisePersonListener.class); + private List enterprisePersonExcels = new ArrayList<>(); + + @Override + public void invoke(EnterprisePersonExcel enterprisePersonExcel, AnalysisContext analysisContext) { + enterprisePersonExcels.add(enterprisePersonExcel); + if (enterprisePersonExcels.size() > 1000) { + try { + listEnterprisePersonExcel(enterprisePersonExcels); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + enterprisePersonExcels.clear(); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + try { + listEnterprisePersonExcel(enterprisePersonExcels); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + enterprisePersonExcels.clear(); + } + + public abstract void listEnterprisePersonExcel(List enterprisePersonExcels) throws Exception; +} diff --git a/src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonExcel.java b/src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonExcel.java new file mode 100644 index 0000000..72cf6e5 --- /dev/null +++ b/src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonExcel.java @@ -0,0 +1,37 @@ +package com.cm.inspection.listener.excel.data; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: VillageOrganPersonExcel + * @Description: 机构人员 + * @Author: WangGeng + * @Date: 2020/5/2 10:49 上午 + * @Version: 1.0 + **/ +public class VillageOrganPersonExcel { + + @ExcelProperty(index = 1) + private Integer organId; + @ExcelProperty(index = 2) + private Integer userId; + + public Integer getOrganId() { + return organId; + } + + public void setOrganId(Integer organId) { + this.organId = organId; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } +} diff --git a/src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonListener.java b/src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonListener.java new file mode 100644 index 0000000..a21df8e --- /dev/null +++ b/src/main/java/com/cm/inspection/listener/excel/data/VillageOrganPersonListener.java @@ -0,0 +1,49 @@ +package com.cm.inspection.listener.excel.data; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: VillageOrganPersonListener + * @Description: 机构人员 + * @Author: WangGeng + * @Date: 2020/5/2 10:50 上午 + * @Version: 1.0 + **/ +public abstract class VillageOrganPersonListener extends AnalysisEventListener { + private static final Logger LOG = LoggerFactory.getLogger(VillageOrganPersonListener.class); + private List villageOrganPersonExcels = new ArrayList<>(); + + @Override + public void invoke(VillageOrganPersonExcel villageOrganPersonExcel, AnalysisContext analysisContext) { + villageOrganPersonExcels.add(villageOrganPersonExcel); + if (villageOrganPersonExcels.size() > 200) { + try { + listVillageOrganPersonExcel(villageOrganPersonExcels); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + villageOrganPersonExcels.clear(); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + try { + listVillageOrganPersonExcel(villageOrganPersonExcels); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + villageOrganPersonExcels.clear(); + } + + public abstract void listVillageOrganPersonExcel(List villageOrganPersonExcels) throws Exception; +} diff --git a/src/main/java/com/cm/inspection/listener/excel/data/VillagePerson.java b/src/main/java/com/cm/inspection/listener/excel/data/VillagePerson.java index eae846d..22d30a4 100644 --- a/src/main/java/com/cm/inspection/listener/excel/data/VillagePerson.java +++ b/src/main/java/com/cm/inspection/listener/excel/data/VillagePerson.java @@ -15,7 +15,7 @@ import com.alibaba.excel.annotation.ExcelProperty; public class VillagePerson { @ExcelProperty(index = 1) - private String id; + private Integer id; @ExcelProperty(index = 2) private String name; @ExcelProperty(index = 3) @@ -45,11 +45,11 @@ public class VillagePerson { @ExcelProperty(index = 32) private String belongAreaName; - public String getId() { - return id == null ? "" : id; + public Integer getId() { + return id; } - public void setId(String id) { + public void setId(Integer id) { this.id = id; } diff --git a/src/main/java/com/cm/inspection/service/data/IDataService.java b/src/main/java/com/cm/inspection/service/data/IDataService.java index ac3fcb8..e9540a5 100644 --- a/src/main/java/com/cm/inspection/service/data/IDataService.java +++ b/src/main/java/com/cm/inspection/service/data/IDataService.java @@ -51,4 +51,20 @@ public interface IDataService { * @throws Exception */ SuccessResult saveVillageGroupPerson() throws Exception; + + /** + * 网格员和部门 + * + * @return + * @throws Exception + */ + SuccessResult saveVillageOrganPerson() throws Exception; + + /** + * 网格员和企业 + * + * @return + * @throws Exception + */ + SuccessResult saveCompanyPerson() throws Exception; } diff --git a/src/main/java/com/cm/inspection/service/data/impl/DataServiceImpl.java b/src/main/java/com/cm/inspection/service/data/impl/DataServiceImpl.java index be811b1..860ec02 100644 --- a/src/main/java/com/cm/inspection/service/data/impl/DataServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/data/impl/DataServiceImpl.java @@ -8,6 +8,7 @@ import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO; import com.cm.common.plugin.pojo.vos.datadictionary.DataDictionaryVO; import com.cm.common.plugin.service.datadictionary.IDataDictionaryService; import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; import com.cm.common.utils.DateUtil; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; @@ -15,12 +16,16 @@ import com.cm.inspection.dao.data.IDataDao; import com.cm.inspection.listener.excel.data.*; import com.cm.inspection.pojo.dtos.data.DepartmentDTO; import com.cm.inspection.pojo.dtos.data.UserDTO; +import com.cm.inspection.pojo.dtos.enterprise.EnterpriseDTO; +import com.cm.inspection.pojo.dtos.enterpriseofgridoperator.EnterpriseOfGridOperatorDTO; import com.cm.inspection.pojo.vos.data.DepartmentVO; import com.cm.inspection.pojo.vos.data.UserVO; import com.cm.inspection.pojo.vos.enterprise.EnterpriseVO; +import com.cm.inspection.pojo.vos.enterpriseofgridoperator.EnterpriseOfGridOperatorVO; import com.cm.inspection.service.BaseService; import com.cm.inspection.service.data.IDataService; import com.cm.inspection.service.enterprise.IEnterpriseService; +import com.cm.inspection.service.enterpriseofgridoperator.IEnterpriseOfGridOperatorService; import com.hazelcast.util.MD5Util; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -52,6 +57,8 @@ public class DataServiceImpl extends BaseService implements IDataService { private IEnterpriseService enterpriseService; @Autowired private IDataDao dataDao; + @Autowired + private IEnterpriseOfGridOperatorService enterpriseOfGridOperatorService; @Override public SuccessResult saveArea() throws Exception { @@ -203,7 +210,7 @@ public class DataServiceImpl extends BaseService implements IDataService { @Override public SuccessResult saveVillageGroupPerson() throws Exception { - File villagePersonFile = new File("C:\\Users\\Administrator\\Desktop\\jd_village_person.xlsx"); + File villagePersonFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_village_person.xls"); EasyExcel.read(villagePersonFile, VillagePerson.class, new VillagePersonListener() { @Override public void listVillagePerson(List villagePersons) throws Exception { @@ -216,13 +223,13 @@ public class DataServiceImpl extends BaseService implements IDataService { continue; } UserVO userVO = new UserVO(); - userVO.setUserUsername(villagePerson.getAccount()); - userVO.setUserName(villagePerson.getName()); - userVO.setUserPhone(villagePerson.getHandset()); + userVO.setUserUsername(villagePerson.getAccount().replaceAll("\\s+", "")); + userVO.setUserName(villagePerson.getName().replaceAll("\\s+", "")); + userVO.setUserPhone(villagePerson.getHandset().replaceAll("\\s+", "")); userVO.setUserPassword(new BCryptPasswordEncoder().encode(MD5Util.toMD5String(MD5Util.toMD5String(MD5Util.toMD5String("123456"))))); userVO.setUserState(1); userVO.setLoginType(1); - userVO.setRemarks(villagePerson.getId()); + userVO.setRemarks(villagePerson.getId() + "|" + villagePerson.getBelongAreaCode().replaceAll("\\s+", "")); Map userParams = HashMapUtil.beanToMap(userVO); userParams.put("userId", UUIDUtil.getUUID()); userParams.put("creator", "1"); @@ -237,6 +244,98 @@ public class DataServiceImpl extends BaseService implements IDataService { return new SuccessResult(); } + @Override + public SuccessResult saveVillageOrganPerson() throws Exception { + File villageOrganPersonFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_village_organ_person_rel.xls"); + final int[] unExistUserCount = {0}; + final int[] unExistDepartmentCount = {0}; + final List unExistUserIds = new ArrayList<>(); + final List unExistDepartmentIds = new ArrayList<>(); + EasyExcel.read(villageOrganPersonFile, VillageOrganPersonExcel.class, new VillageOrganPersonListener() { + @Override + public void listVillageOrganPersonExcel(List villageOrganPersonExcels) throws Exception { + Map params = getHashMap(1); + for (VillageOrganPersonExcel villageOrganPersonExcel : villageOrganPersonExcels) { + params.put("remarksId", villageOrganPersonExcel.getUserId() + "|"); + UserDTO userDTO = dataDao.getUser(params); + if (userDTO == null) { + unExistUserCount[0]++; + unExistUserIds.add(villageOrganPersonExcel.getUserId().toString()); + continue; + } + params.clear(); + params.put("departmentSummary", villageOrganPersonExcel.getOrganId()); + DepartmentDTO departmentDTO = dataDao.getDepartment(params); + if (departmentDTO == null) { + unExistDepartmentCount[0]++; + unExistDepartmentIds.add(villageOrganPersonExcel.getOrganId() + "|" + villageOrganPersonExcel.getUserId()); + continue; + } + params.clear(); + params.put("departmentId", departmentDTO.getDepartmentId()); + params.put("userId", userDTO.getUserId()); + dataDao.saveDepartmentUser(params); + } + } + }).sheet().doRead(); + Map result = getHashMap(2); + result.put("unExistUserCount", unExistUserCount[0]); + result.put("unExistEnterpriseCount", unExistDepartmentCount[0]); + result.put("unExistUserIds", unExistUserIds); + result.put("unExistDepartmentIds", unExistDepartmentIds); + return new SuccessResultData<>(result); + } + + @Override + public SuccessResult saveCompanyPerson() throws Exception { + File companyPersonFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_com_village_rel.xlsx"); + List unExistEnterpriseIds = new ArrayList<>(); + List moreEnterpriseIds = new ArrayList<>(); + List unExistPersonIds = new ArrayList<>(); + EasyExcel.read(companyPersonFile, EnterprisePersonExcel.class, new EnterprisePersonListener() { + @Override + public void listEnterprisePersonExcel(List enterprisePersonExcels) throws Exception { + Map params = getHashMap(1); + for (EnterprisePersonExcel enterprisePersonExcel : enterprisePersonExcels) { + if (enterprisePersonExcel.getIsDeleted() != 0) { + continue; + } + params.put("remarks", enterprisePersonExcel.getCompanyId()); + List enterpriseDTOs = enterpriseService.listEnterprise(params); + if (enterpriseDTOs.size() == 0) { + unExistEnterpriseIds.add(enterprisePersonExcel.getCompanyId() + "|" + enterprisePersonExcel.getUserId()); + continue; + } + if (enterpriseDTOs.size() > 1) { + moreEnterpriseIds.add(enterprisePersonExcel.getCompanyId() + "|" + enterprisePersonExcel.getUserId()); + continue; + } + if (enterprisePersonExcel.getUserId() == null) { + continue; + } + params.put("remarksId", enterprisePersonExcel.getUserId() + "|"); + UserDTO userDTO = dataDao.getUser(params); + if (userDTO == null) { + unExistPersonIds.add(enterprisePersonExcel.getCompanyId() + "|" + enterprisePersonExcel.getUserId()); + continue; + } + EnterpriseOfGridOperatorVO enterpriseOfGridOperatorVO = new EnterpriseOfGridOperatorVO(); + enterpriseOfGridOperatorVO.setEnterpriseId(enterpriseDTOs.get(0).getEnterpriseId()); + enterpriseOfGridOperatorVO.setUserId(userDTO.getUserId()); + enterpriseOfGridOperatorService.saveEnterpriseOfGridOperator(enterpriseOfGridOperatorVO); + } + } + }).sheet().doRead(); + Map result = getHashMap(6); + result.put("unExistEnterpriseCount", unExistEnterpriseIds.size()); + result.put("unExistEnterpriseIds", unExistEnterpriseIds); + result.put("moreEnterpriseCount", moreEnterpriseIds.size()); + result.put("moreEnterpriseIds", moreEnterpriseIds); + result.put("unExistPersonCount", unExistPersonIds.size()); + result.put("unExistPersonIds", unExistPersonIds); + return new SuccessResultData<>(result); + } + /** * 设置高风险 * diff --git a/src/main/resources/mybatis/mapper/data/data-mapper.xml b/src/main/resources/mybatis/mapper/data/data-mapper.xml index 10d2608..ab010d5 100644 --- a/src/main/resources/mybatis/mapper/data/data-mapper.xml +++ b/src/main/resources/mybatis/mapper/data/data-mapper.xml @@ -100,7 +100,22 @@ FROM db_cloud_v2.sys_user WHERE + user_username = #{userUsername} + + + remarks LIKE CONCAT(#{remarksId}, '%') + + + INSERT INTO db_cloud_v2.sys_department_user( + department_id, + user_id + ) VALUES( + #{departmentId}, + #{userId} + ) + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/enterprise/enterprise-mapper.xml b/src/main/resources/mybatis/mapper/enterprise/enterprise-mapper.xml index 7c92b95..f264de9 100644 --- a/src/main/resources/mybatis/mapper/enterprise/enterprise-mapper.xml +++ b/src/main/resources/mybatis/mapper/enterprise/enterprise-mapper.xml @@ -430,6 +430,10 @@ AND t1.area5 = #{area5} + + AND + t1.remarks = #{remarks} + AND t1.enterprise_id IN