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 b745f73..3ce14df 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 @@ -60,4 +60,14 @@ public class DataController { return dataService.saveCompanyPerson(); } + @PostMapping("saveuser") + public SuccessResult saveUser() throws Exception { + return dataService.saveUser(); + } + + @PostMapping("saveuserarea") + public SuccessResult saveUserArea() throws Exception { + return dataService.saveUserArea(); + } + } 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 d4cb2b8..8b1b86b 100644 --- a/src/main/java/com/cm/inspection/dao/data/IDataDao.java +++ b/src/main/java/com/cm/inspection/dao/data/IDataDao.java @@ -1,10 +1,12 @@ package com.cm.inspection.dao.data; +import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO; import com.cm.inspection.pojo.dtos.data.DepartmentDTO; import com.cm.inspection.pojo.dtos.data.UserDTO; import com.cm.inspection.pojo.vos.data.DepartmentVO; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Map; /** @@ -29,4 +31,8 @@ public interface IDataDao { void saveUser(Map userParams); void saveDepartmentUser(Map params); + + List listDepartmentUser(); + + DataDictionaryDTO getArea(Map params); } diff --git a/src/main/java/com/cm/inspection/listener/excel/data/UserExcel.java b/src/main/java/com/cm/inspection/listener/excel/data/UserExcel.java new file mode 100644 index 0000000..bbf9d73 --- /dev/null +++ b/src/main/java/com/cm/inspection/listener/excel/data/UserExcel.java @@ -0,0 +1,87 @@ +package com.cm.inspection.listener.excel.data; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: UserExcel + * @Description: 用户 + * @Author: WangGeng + * @Date: 2020/5/2 16:34 + * @Version: 1.0 + **/ +public class UserExcel { + + @ExcelProperty(index = 2) + private String area1; + @ExcelProperty(index = 3) + private String area2; + @ExcelProperty(index = 4) + private String area3; + @ExcelProperty(index = 5) + private String area4; + @ExcelProperty(index = 15) + private String area5; + @ExcelProperty(index = 6) + private String name; + @ExcelProperty(index = 11) + private String phone; + + public String getArea1() { + return area1 == null ? "" : area1; + } + + public void setArea1(String area1) { + this.area1 = area1; + } + + public String getArea2() { + return area2 == null ? "" : area2; + } + + public void setArea2(String area2) { + this.area2 = area2; + } + + public String getArea3() { + return area3 == null ? "" : area3; + } + + public void setArea3(String area3) { + this.area3 = area3; + } + + public String getArea4() { + return area4 == null ? "" : area4; + } + + public void setArea4(String area4) { + this.area4 = area4; + } + + public String getArea5() { + return area5 == null ? "" : area5; + } + + public void setArea5(String area5) { + this.area5 = area5; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone == null ? "" : phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } +} diff --git a/src/main/java/com/cm/inspection/listener/excel/data/UserExcelListener.java b/src/main/java/com/cm/inspection/listener/excel/data/UserExcelListener.java new file mode 100644 index 0000000..79046dd --- /dev/null +++ b/src/main/java/com/cm/inspection/listener/excel/data/UserExcelListener.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: UserExcelListener + * @Description: 用户 + * @Author: WangGeng + * @Date: 2020/5/2 16:34 + * @Version: 1.0 + **/ +public abstract class UserExcelListener extends AnalysisEventListener { + private static final Logger LOG = LoggerFactory.getLogger(UserExcelListener.class); + private List userExcels = new ArrayList<>(); + + @Override + public void invoke(UserExcel userExcel, AnalysisContext analysisContext) { + userExcels.add(userExcel); + if (userExcels.size() > 500) { + try { + listUserExcel(userExcels); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + userExcels.clear(); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + try { + listUserExcel(userExcels); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + userExcels.clear(); + } + + public abstract void listUserExcel(List userExcels) throws Exception; +} diff --git a/src/main/java/com/cm/inspection/pojo/dtos/data/UserDTO.java b/src/main/java/com/cm/inspection/pojo/dtos/data/UserDTO.java index 87c707a..22d5338 100644 --- a/src/main/java/com/cm/inspection/pojo/dtos/data/UserDTO.java +++ b/src/main/java/com/cm/inspection/pojo/dtos/data/UserDTO.java @@ -11,6 +11,8 @@ public class UserDTO { private Integer userState; private Integer loginType; private String remarks; + private String departmentId; + private String departmentName; public String getUserId() { return userId == null ? "" : userId; @@ -75,4 +77,20 @@ public class UserDTO { public void setRemarks(String remarks) { this.remarks = remarks; } + + public String getDepartmentId() { + return departmentId == null ? "" : departmentId; + } + + public void setDepartmentId(String departmentId) { + this.departmentId = departmentId; + } + + public String getDepartmentName() { + return departmentName == null ? "" : departmentName; + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } } 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 e9540a5..d4d5cb1 100644 --- a/src/main/java/com/cm/inspection/service/data/IDataService.java +++ b/src/main/java/com/cm/inspection/service/data/IDataService.java @@ -67,4 +67,21 @@ public interface IDataService { * @throws Exception */ SuccessResult saveCompanyPerson() throws Exception; + + /** + * 保存人员 + * + * @return + * @throws Exception + */ + SuccessResult saveUser() throws Exception; + + /** + * 保存人员地区 + * + * @return + * @throws Exception + */ + SuccessResult saveUserArea() 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 860ec02..7a3497a 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 @@ -22,10 +22,12 @@ 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.pojo.vos.gridpersonnel.GridPersonnelVO; 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.cm.inspection.service.gridpersonnel.IGridPersonnelService; import com.hazelcast.util.MD5Util; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -59,6 +61,8 @@ public class DataServiceImpl extends BaseService implements IDataService { private IDataDao dataDao; @Autowired private IEnterpriseOfGridOperatorService enterpriseOfGridOperatorService; + @Autowired + private IGridPersonnelService gridPersonnelService; @Override public SuccessResult saveArea() throws Exception { @@ -336,6 +340,125 @@ public class DataServiceImpl extends BaseService implements IDataService { return new SuccessResultData<>(result); } + @Override + public SuccessResult saveUser() throws Exception { + File userFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_com_village_rel.xlsx"); + List existUsers = new ArrayList<>(); + EasyExcel.read(userFile, UserExcel.class, new UserExcelListener() { + @Override + public void listUserExcel(List userExcels) throws Exception { + Map params = getHashMap(1); + String currentDate = DateUtil.getTime(); + for (UserExcel userExcel : userExcels) { + params.put("userUsername", userExcel.getPhone()); + UserDTO userDTO = dataDao.getUser(params); + if (userDTO != null) { + existUsers.add(String.format("%s|%s", userDTO.getUserUsername(), userDTO.getUserName())); + continue; + } + UserVO userVO = new UserVO(); + userVO.setUserUsername(userExcel.getPhone().replaceAll("\\s+", "")); + userVO.setUserName(userExcel.getName().replaceAll("\\s+", "")); + userVO.setUserPhone(userExcel.getPhone().replaceAll("\\s+", "")); + userVO.setUserPassword(new BCryptPasswordEncoder().encode(MD5Util.toMD5String(MD5Util.toMD5String(MD5Util.toMD5String("123456"))))); + userVO.setUserState(1); + userVO.setLoginType(1); + String remarks = ""; + if (!StringUtils.isBlank(userExcel.getArea1())) { + remarks += userExcel.getArea1(); + if (!StringUtils.isBlank(userExcel.getArea2())) { + remarks += "|" + userExcel.getArea2(); + if (!StringUtils.isBlank(userExcel.getArea3())) { + remarks += "|" + userExcel.getArea3(); + if (!StringUtils.isBlank(userExcel.getArea4())) { + remarks += "|" + userExcel.getArea4(); + if (!StringUtils.isBlank(userExcel.getArea5())) { + remarks += "|" + userExcel.getArea5(); + } + } + } + } + } + userVO.setRemarks(remarks); + Map userParams = HashMapUtil.beanToMap(userVO); + userParams.put("userId", UUIDUtil.getUUID()); + userParams.put("creator", "1"); + userParams.put("gmtCreate", currentDate); + userParams.put("modifier", "1"); + userParams.put("gmtModified", currentDate); + userParams.put("isDelete", 0); + dataDao.saveUser(userParams); + } + } + }).sheet().doRead(); + Map result = getHashMap(2); + result.put("existUsers", existUsers); + result.put("existUserCount", existUsers.size()); + return new SuccessResultData<>(result); + } + + @Override + public SuccessResult saveUserArea() throws Exception { + List userDTOs = dataDao.listDepartmentUser(); + List unBindUserIds = new ArrayList<>(); + Map params = getHashMap(1); + for (UserDTO userDTO : userDTOs) { + if (StringUtils.isBlank(userDTO.getRemarks())) { + unBindUserIds.add(userDTO.getUserUsername()); + continue; + } + if (StringUtils.isBlank(userDTO.getRemarks())) { + continue; + } + String[] remarkArray = userDTO.getRemarks().split("\\|"); + String userArea = remarkArray[remarkArray.length - 1]; + params.put("dictionarySummary", userArea); + List dataDictionaryDTOs = new ArrayList<>(); + DataDictionaryDTO dataDictionaryDTO = dataDao.getArea(params); + areaDataList(dataDictionaryDTOs, dataDictionaryDTO); + String gridUserId = String.format("%s|%s|%s|【%s】%s", userDTO.getUserId(), userDTO.getDepartmentId(), userDTO.getUserName(), userDTO.getDepartmentName(), userDTO.getUserName()); + + GridPersonnelVO gridPersonnelVO = new GridPersonnelVO(); + gridPersonnelVO.setLevel(dataDictionaryDTOs.size()); + gridPersonnelVO.setIsGridOperator(1); + gridPersonnelVO.setUserId(gridUserId); + for (int i = dataDictionaryDTOs.size(); i > 0; i--) { + String dictionaryId = dataDictionaryDTOs.get(i - 1).getDictionaryId(); + if (i == 5) { + gridPersonnelVO.setArea5(dictionaryId); + } else if (i == 4) { + gridPersonnelVO.setArea4(dictionaryId); + } else if (i == 3) { + gridPersonnelVO.setArea4(dictionaryId); + } else if (i == 2) { + gridPersonnelVO.setArea4(dictionaryId); + } else if (i == 1) { + gridPersonnelVO.setArea4(dictionaryId); + } + } + gridPersonnelService.saveGridPersonnel(gridPersonnelVO); + } + Map result = getHashMap(2); + result.put("unBindUserIds", unBindUserIds); + result.put("unBindUserIdCount", unBindUserIds.size()); + return new SuccessResultData<>(result); + } + + /** + * 地区列表,倒叙 + * + * @param dataDictionaryDTOs + * @param dataDictionaryDTO + */ + private void areaDataList(List dataDictionaryDTOs, DataDictionaryDTO dataDictionaryDTO) { + dataDictionaryDTOs.add(dataDictionaryDTO); + if (StringUtils.equals("81583ade-5466-49aa-b7b6-c643c131ea34", dataDictionaryDTO.getDictionaryId())) { + return; + } + DataDictionaryDTO parentDataDictionary = dataDictionaryService.getDictionaryById(dataDictionaryDTO.getDictionaryParentId()); + areaDataList(dataDictionaryDTOs, parentDataDictionary); + } + /** * 设置高风险 * diff --git a/src/main/resources/mybatis/mapper/data/data-mapper.xml b/src/main/resources/mybatis/mapper/data/data-mapper.xml index ab010d5..bf646d9 100644 --- a/src/main/resources/mybatis/mapper/data/data-mapper.xml +++ b/src/main/resources/mybatis/mapper/data/data-mapper.xml @@ -21,6 +21,18 @@ + + + + + + + + + + + + @@ -94,6 +106,27 @@ ) + + + SELECT + * + FROM + data_dictionary + WHERE + is_delete = 0 + + AND + dictionary_id = #{dictionaryId} + + + AND + dictionary_summary = #{dictionarySummary} + + + + \ No newline at end of file