|  |  | @ -1,10 +1,12 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.excel.EasyExcelFactory; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.ServiceConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.OptionResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.ExceptionUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.feign.ResultDataResolver; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.security.user.LoginUserUtil; | 
			
		
	
	
		
			
				
					|  |  | @ -19,6 +21,7 @@ import com.epmet.dto.result.FormItem; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.LoginUserDetailsResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.OptionDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcResiUserEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.enums.IcResiUserTableEnums; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.excel.handler.DynamicEasyExcelListener; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetAdminOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetUserOpenFeignClient; | 
			
		
	
	
		
			
				
					|  |  | @ -47,7 +50,9 @@ import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | public class IcResiUserImportServiceImpl implements IcResiUserImportService, ResultDataResolver { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     public static final ThreadLocal errorRow = new ThreadLocal<ErrorRow>(); | 
			
		
	
		
			
				
					|  |  |  |     // 错误和跳过excel行暂存
 | 
			
		
	
		
			
				
					|  |  |  |     public static final ThreadLocal<Map<String, List<ErrorRow>>> errorRows = new ThreadLocal<>(); | 
			
		
	
		
			
				
					|  |  |  |     public static final ThreadLocal<Map<String, List<SkipedRow>>> skipedRows = new ThreadLocal<>(); | 
			
		
	
		
			
				
					|  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private LoginUserUtil loginUserUtil; | 
			
		
	
	
		
			
				
					|  |  | @ -80,6 +85,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         private String columnName; | 
			
		
	
		
			
				
					|  |  |  |         private String itemType; | 
			
		
	
		
			
				
					|  |  |  |         private String itemId; | 
			
		
	
		
			
				
					|  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |         // 是否必填
 | 
			
		
	
		
			
				
					|  |  |  |         private Integer required; | 
			
		
	
		
			
				
					|  |  |  |         private List<Integer> colIndexs; | 
			
		
	
		
			
				
					|  |  |  |         //private List<String> colContents;
 | 
			
		
	
		
			
				
					|  |  |  |         // 单元格内容
 | 
			
		
	
	
		
			
				
					|  |  | @ -104,13 +112,20 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 错误行信息 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Data | 
			
		
	
		
			
				
					|  |  |  |     public static class ErrorRow { | 
			
		
	
		
			
				
					|  |  |  |         private String sheetName; | 
			
		
	
		
			
				
					|  |  |  |         private String idCard; | 
			
		
	
		
			
				
					|  |  |  |         private String name; | 
			
		
	
		
			
				
					|  |  |  |         private String errorInfo; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Data | 
			
		
	
		
			
				
					|  |  |  |     public static class SkipedRow { | 
			
		
	
		
			
				
					|  |  |  |         private String idCard; | 
			
		
	
		
			
				
					|  |  |  |         private String name; | 
			
		
	
		
			
				
					|  |  |  |         private String info; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 导入居民信息 | 
			
		
	
		
			
				
					|  |  |  |      *  导入主表和所有子表信息 | 
			
		
	
	
		
			
				
					|  |  | @ -134,19 +149,62 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(currUserAgencyId), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null); | 
			
		
	
		
			
				
					|  |  |  |         String customerId = agencyInfo.getCustomerId(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         importIcResiBaseInfoFromExcel(excelPathName, 0, 3, currUserAgencyId, agencyInfo.getPids(), loginUserId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 1, 2, currUserAgencyId, loginUserId, "ic_party_member", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 2, 2, currUserAgencyId, loginUserId, "ic_ensure_house", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 3, 2, currUserAgencyId, loginUserId, "ic_unemployed", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 4, 2, currUserAgencyId, loginUserId, "ic_veterans", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 5, 2, currUserAgencyId, loginUserId, "ic_united_front", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 6, 3, currUserAgencyId, loginUserId, "ic_volunteer", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 7, 2, currUserAgencyId, loginUserId, "ic_old_people", customerId); | 
			
		
	
		
			
				
					|  |  |  |         importIcResiExtraInfoFromExcel(excelPathName, 8, 3, currUserAgencyId, loginUserId, "ic_special", customerId); | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             initThreadLocalRowsStorage(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 上传主表信息
 | 
			
		
	
		
			
				
					|  |  |  |             importIcResiBaseInfoFromExcel(excelPathName, IcResiUserTableEnums.IC_RESI_USER.getSheetNo(), IcResiUserTableEnums.IC_RESI_USER.getHeadRowNo(),  | 
			
		
	
		
			
				
					|  |  |  |                                 currUserAgencyId, agencyInfo.getPids(), loginUserId, IcResiUserTableEnums.IC_RESI_USER.getTableName()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 上传附表信息
 | 
			
		
	
		
			
				
					|  |  |  |             for (IcResiUserTableEnums sheet : IcResiUserTableEnums.values()) { | 
			
		
	
		
			
				
					|  |  |  |                 if (sheet == IcResiUserTableEnums.IC_RESI_USER) { | 
			
		
	
		
			
				
					|  |  |  |                     continue;     | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |                     importIcResiExtraInfoFromExcel(excelPathName, sheet.getSheetNo(), sheet.getHeadRowNo(), currUserAgencyId, loginUserId, sheet.getTableName(), customerId); | 
			
		
	
		
			
				
					|  |  |  |                 } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                     String errorMsg = ExceptionUtils.getErrorStackTrace(e); | 
			
		
	
		
			
				
					|  |  |  |                     log.error("导入IC居民附加信息【{}】错误:{}", sheet.getTableComment(), errorMsg); | 
			
		
	
		
			
				
					|  |  |  |                     ErrorRow errorRow = new ErrorRow(); | 
			
		
	
		
			
				
					|  |  |  |                     errorRow.setName("*"); | 
			
		
	
		
			
				
					|  |  |  |                     errorRow.setIdCard("*"); | 
			
		
	
		
			
				
					|  |  |  |                     errorRows.get().get(sheet.getTableName()).add(errorRow); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             String errors = JSON.toJSONString(errorRows.get()); | 
			
		
	
		
			
				
					|  |  |  |             String skipeds = JSON.toJSONString(skipedRows.get()); | 
			
		
	
		
			
				
					|  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |             log.error(errors); | 
			
		
	
		
			
				
					|  |  |  |             log.error(skipeds); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         } finally { | 
			
		
	
		
			
				
					|  |  |  |             skipedRows.remove(); | 
			
		
	
		
			
				
					|  |  |  |             errorRows.remove(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return null; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 暂存rows信息初始化 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private void initThreadLocalRowsStorage() { | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<SkipedRow>> skipedRowsMap = new LinkedHashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         for (IcResiUserTableEnums e : IcResiUserTableEnums.values()) { | 
			
		
	
		
			
				
					|  |  |  |             skipedRowsMap.put(e.getTableName(), new LinkedList<>()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         skipedRows.set(skipedRowsMap); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<ErrorRow>> errorRowsMap = new LinkedHashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         for (IcResiUserTableEnums e : IcResiUserTableEnums.values()) { | 
			
		
	
		
			
				
					|  |  |  |             errorRowsMap.put(e.getTableName(), new LinkedList<>()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         errorRows.set(errorRowsMap); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * excel导入居民基本信息 | 
			
		
	
		
			
				
					|  |  |  |      * @param sheetNo | 
			
		
	
	
		
			
				
					|  |  | @ -156,7 +214,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |      * @param currentUserId | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private Object importIcResiBaseInfoFromExcel(String excelPathName, int sheetNo, int headRowNumber, String currUserAgencyId, String currUserAgencyPids, String currentUserId) { | 
			
		
	
		
			
				
					|  |  |  |     private Object importIcResiBaseInfoFromExcel(String excelPathName, int sheetNo, int headRowNumber, String currUserAgencyId, String currUserAgencyPids, String currentUserId, | 
			
		
	
		
			
				
					|  |  |  |                                                  String tableName) { | 
			
		
	
		
			
				
					|  |  |  |         DynamicEasyExcelListener readListener = new DynamicEasyExcelListener(); | 
			
		
	
		
			
				
					|  |  |  |         EasyExcelFactory.read(new File(excelPathName)).registerReadListener(readListener).headRowNumber(headRowNumber).sheet(sheetNo).doRead(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -189,7 +248,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         Map<String, ColumnWrapper> headerColumnWrapper = convertExcelHeaders2DBColumnWrappers(formItemMap, combinedHeaders, dataList, abandonedHeaders); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 持久化
 | 
			
		
	
		
			
				
					|  |  |  |         persistIcResiBaseInfo(headerColumnWrapper, dataList, currUserAgencyId, abandonedHeaders, currUserAgencyPids, currentUserId); | 
			
		
	
		
			
				
					|  |  |  |         persistIcResiBaseInfo(headerColumnWrapper, dataList, currUserAgencyId, abandonedHeaders, currUserAgencyPids, currentUserId, tableName); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return headers; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  | @ -249,39 +308,64 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private void persistIcResiBaseInfo(Map<String, ColumnWrapper> headerColumnWrapper, List<Map<Integer, String>> dataRows, | 
			
		
	
		
			
				
					|  |  |  |                                        String currUserAgencyId, Map<Integer, String> checkBoxOptionColumnIdxAndLabel, | 
			
		
	
		
			
				
					|  |  |  |                                        String currUserAgencyPids, String currentUserId) { | 
			
		
	
		
			
				
					|  |  |  |                                        String currUserAgencyPids, String currentUserId, String tableName) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 遍历每一行,将行内容转化为
 | 
			
		
	
		
			
				
					|  |  |  |         for (Map<Integer, String> row : dataRows) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             LinkedHashMap<String, String> columnAndValues = convertColumnWrappers2Map4Persist(headerColumnWrapper, row, currUserAgencyId, checkBoxOptionColumnIdxAndLabel); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_ENSURE_HOUSE", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_OLD_PEOPLE", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_PARTY", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_SPECIAL", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_UNEMPLOYED", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_UNITED_FRONT", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_VETERANS", "0"); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IS_VOLUNTEER", "0"); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("AGENCY_ID", currUserAgencyId); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("PIDS", currUserAgencyPids); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("CUSTOMER_ID", loginUserUtil.getCurrentCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("CREATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("UPDATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("ID", UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 验证居民信息是否存在
 | 
			
		
	
		
			
				
					|  |  |  |             String idCard = columnAndValues.get("ID_CARD"); | 
			
		
	
		
			
				
					|  |  |  |             LambdaQueryWrapper<IcResiUserEntity> idCardQuery = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |             idCardQuery.eq(IcResiUserEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (icResiUserDao.selectCount(idCardQuery) > 0) { | 
			
		
	
		
			
				
					|  |  |  |                 log.info("身份证号为【{}】的居民信息已存在,跳过导入", idCard); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             LinkedHashMap<String, String> columnAndValues = new LinkedHashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 convertColumnWrappers2Map4Persist(headerColumnWrapper, row, currUserAgencyId, checkBoxOptionColumnIdxAndLabel, columnAndValues); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_ENSURE_HOUSE", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_OLD_PEOPLE", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_PARTY", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_SPECIAL", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_UNEMPLOYED", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_UNITED_FRONT", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_VETERANS", "0"); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IS_VOLUNTEER", "0"); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("AGENCY_ID", currUserAgencyId); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("PIDS", currUserAgencyPids); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("CUSTOMER_ID", loginUserUtil.getCurrentCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("CREATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("UPDATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("ID", UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 // 验证居民信息是否存在
 | 
			
		
	
		
			
				
					|  |  |  |                 String idCard = columnAndValues.get("ID_CARD"); | 
			
		
	
		
			
				
					|  |  |  |                 LambdaQueryWrapper<IcResiUserEntity> idCardQuery = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |                 idCardQuery.eq(IcResiUserEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 if (icResiUserDao.selectCount(idCardQuery) > 0) { | 
			
		
	
		
			
				
					|  |  |  |                     //log.info("身份证号为【{}】的居民信息已存在,跳过导入", idCard);
 | 
			
		
	
		
			
				
					|  |  |  |                     SkipedRow skipedRow = new SkipedRow(); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRow.setName(columnAndValues.get("NAME")); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRow.setIdCard(idCard); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRow.setInfo("身份证号已存在,跳过导入"); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRows.get().get(IcResiUserTableEnums.IC_RESI_USER.getTableName()).add(skipedRow); | 
			
		
	
		
			
				
					|  |  |  |                     continue; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             icResiUserDao.add("ic_resi_user", columnAndValues); | 
			
		
	
		
			
				
					|  |  |  |                 icResiUserDao.add(tableName, columnAndValues); | 
			
		
	
		
			
				
					|  |  |  |             } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                 String errorMsg; | 
			
		
	
		
			
				
					|  |  |  |                 if (e instanceof RenException) { | 
			
		
	
		
			
				
					|  |  |  |                     errorMsg = e.getMessage(); | 
			
		
	
		
			
				
					|  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |                     errorMsg = "未知系统错误"; | 
			
		
	
		
			
				
					|  |  |  |                     log.error(ExceptionUtils.getErrorStackTrace(e)); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 ErrorRow errorRow = new ErrorRow(); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setIdCard(columnAndValues.get("ID_CARD")); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setName(columnAndValues.get("NAME")); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setErrorInfo(errorMsg); | 
			
		
	
		
			
				
					|  |  |  |                 errorRows.get().get(IcResiUserTableEnums.IC_RESI_USER.getTableName()).add(errorRow); | 
			
		
	
		
			
				
					|  |  |  |             } finally { | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.clear(); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -297,44 +381,73 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |                                         String currUserAgencyId, Map<Integer, String> checkBoxOptionColumnIdxAndLabel, | 
			
		
	
		
			
				
					|  |  |  |                                         String currentUserId, String targetTableName, String customerId) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         LinkedHashMap<String, String> columnAndValues = new LinkedHashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |         // 遍历每一行,将行内容转化为
 | 
			
		
	
		
			
				
					|  |  |  |         for (Map<Integer, String> row : dataRows) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             LinkedHashMap<String, String> columnAndValues = convertColumnWrappers2Map4Persist(headerColumnWrapper, row, currUserAgencyId, checkBoxOptionColumnIdxAndLabel); | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 convertColumnWrappers2Map4Persist(headerColumnWrapper, row, currUserAgencyId, checkBoxOptionColumnIdxAndLabel, columnAndValues); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 检验身份证号
 | 
			
		
	
		
			
				
					|  |  |  |             String idCard = columnAndValues.get("ID_CARD"); | 
			
		
	
		
			
				
					|  |  |  |             if (StringUtils.isBlank(idCard)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException(EpmetErrorCode.IDCARDNO_ERROR.getCode(), String.format("用户【%s】身份证号未填写或格式错误", columnAndValues.get("NAME"))); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |                 // 检验身份证号
 | 
			
		
	
		
			
				
					|  |  |  |                 String idCard = columnAndValues.get("ID_CARD"); | 
			
		
	
		
			
				
					|  |  |  |                 if (StringUtils.isBlank(idCard)) { | 
			
		
	
		
			
				
					|  |  |  |                     throw new RenException(EpmetErrorCode.IDCARDNO_ERROR.getCode(), String.format("用户【%s】身份证号未填写或格式错误", columnAndValues.get("NAME"))); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 检查用户是否存在
 | 
			
		
	
		
			
				
					|  |  |  |             LambdaQueryWrapper<IcResiUserEntity> idCardQuery = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |             idCardQuery.eq(IcResiUserEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  |                 // 检查用户是否存在
 | 
			
		
	
		
			
				
					|  |  |  |                 LambdaQueryWrapper<IcResiUserEntity> idCardQuery = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |                 idCardQuery.eq(IcResiUserEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             IcResiUserEntity icResiUserBaseInfo = icResiUserDao.selectOne(idCardQuery); | 
			
		
	
		
			
				
					|  |  |  |             if (icResiUserBaseInfo == null) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException(EpmetErrorCode.RESI_NOT_FOUND.getCode(), String.format("身份证号为【%s】的居民信息未找到,请确认该居民信息存在", idCard)); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |                 IcResiUserEntity icResiUserBaseInfo = icResiUserDao.selectOne(idCardQuery); | 
			
		
	
		
			
				
					|  |  |  |                 if (icResiUserBaseInfo == null) { | 
			
		
	
		
			
				
					|  |  |  |                     throw new RenException(EpmetErrorCode.RESI_NOT_FOUND.getCode(), String.format("身份证号为【%s】的居民信息未找到,请确认该居民信息存在", idCard)); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             String icResiId = icResiUserBaseInfo.getId(); | 
			
		
	
		
			
				
					|  |  |  |                 String icResiId = icResiUserBaseInfo.getId(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 验证党员信息是否存在
 | 
			
		
	
		
			
				
					|  |  |  |             if (CollectionUtils.isNotEmpty(icResiUserDao.selectSubTableRecords(customerId, icResiId, targetTableName))) { | 
			
		
	
		
			
				
					|  |  |  |                 log.info("身份证号为【{}】的居民【{}】信息已存在,跳过导入", idCard, targetTableName); | 
			
		
	
		
			
				
					|  |  |  |                 continue; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |                 // 验证党员信息是否存在
 | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isNotEmpty(icResiUserDao.selectSubTableRecords(customerId, icResiId, targetTableName))) { | 
			
		
	
		
			
				
					|  |  |  |                     log.info("身份证号为【{}】的居民【{}】信息已存在,跳过导入", idCard, targetTableName); | 
			
		
	
		
			
				
					|  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |                     SkipedRow skipedRow = new SkipedRow(); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRow.setName(columnAndValues.get("NAME")); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRow.setIdCard(columnAndValues.get("ID_CARD")); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRow.setInfo("信息已存在,跳过导入"); | 
			
		
	
		
			
				
					|  |  |  |                     skipedRows.get().get(targetTableName).add(skipedRow); | 
			
		
	
		
			
				
					|  |  |  |                      | 
			
		
	
		
			
				
					|  |  |  |                     continue; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("IC_RESI_USER", icResiId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("IC_RESI_USER", icResiId); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("CUSTOMER_ID", loginUserUtil.getCurrentCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("CREATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("UPDATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.put("ID", UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("CUSTOMER_ID", loginUserUtil.getCurrentCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("CREATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("UPDATED_BY", currentUserId); | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put("ID", UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues = removeNeedlessColumns(columnAndValues); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues = removeNeedlessColumns(columnAndValues); | 
			
		
	
		
			
				
					|  |  |  |                 icResiUserDao.add(targetTableName, columnAndValues); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             icResiUserDao.add(targetTableName, columnAndValues); | 
			
		
	
		
			
				
					|  |  |  |                 updateMainTableResiTypeFlag(Objects.requireNonNull(IcResiUserTableEnums.getObjectByTableName(targetTableName)), icResiId); | 
			
		
	
		
			
				
					|  |  |  |             } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                 String errorMsg; | 
			
		
	
		
			
				
					|  |  |  |                 if (e instanceof RenException) { | 
			
		
	
		
			
				
					|  |  |  |                     errorMsg = e.getMessage(); | 
			
		
	
		
			
				
					|  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |                     errorMsg = "未知系统错误"; | 
			
		
	
		
			
				
					|  |  |  |                     log.error(ExceptionUtils.getErrorStackTrace(e)); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |                 ErrorRow errorRow = new ErrorRow(); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setName(columnAndValues.get("NAME")); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setIdCard(columnAndValues.get("ID_CARD")); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setErrorInfo(errorMsg); | 
			
		
	
		
			
				
					|  |  |  |                 errorRows.get().get(targetTableName).add(errorRow); | 
			
		
	
		
			
				
					|  |  |  |             } finally { | 
			
		
	
		
			
				
					|  |  |  |                 columnAndValues.clear(); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -365,12 +478,16 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |      * @param row  当前行数据 | 
			
		
	
		
			
				
					|  |  |  |      * @param currUserAgencyId 当前用户所属机构ID | 
			
		
	
		
			
				
					|  |  |  |      * @param checkBoxOptionColumnIdxAndLabel 复选框options列表。key:列号,value:复选框中文 | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      * @param target 要将数据放到哪个对象中 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private LinkedHashMap<String, String> convertColumnWrappers2Map4Persist(Map<String, ColumnWrapper> headerColumnWrapper, Map<Integer, String> row, | 
			
		
	
		
			
				
					|  |  |  |                                                                             String currUserAgencyId, Map<Integer, String> checkBoxOptionColumnIdxAndLabel) { | 
			
		
	
		
			
				
					|  |  |  |         LinkedHashMap<String, String> columnAndValues = new LinkedHashMap<>(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     private void convertColumnWrappers2Map4Persist(Map<String, ColumnWrapper> headerColumnWrapper, Map<Integer, String> row, | 
			
		
	
		
			
				
					|  |  |  |                                                                             String currUserAgencyId, Map<Integer, String> checkBoxOptionColumnIdxAndLabel, | 
			
		
	
		
			
				
					|  |  |  |                                                                             LinkedHashMap<String, String> target) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         boolean interupt = false; | 
			
		
	
		
			
				
					|  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |         List<String> errorColumnNames = new LinkedList<>(); | 
			
		
	
		
			
				
					|  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |         for (Map.Entry<String, ColumnWrapper> columnWrapperEntry : headerColumnWrapper.entrySet()) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             ColumnWrapper columnWrapper = columnWrapperEntry.getValue(); | 
			
		
	
	
		
			
				
					|  |  | @ -408,10 +525,19 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |                 String checkBoxColValue = getCheckBoxColValue(columnWrapper, row, checkBoxOptionColumnIdxAndLabel); | 
			
		
	
		
			
				
					|  |  |  |                 columnWrapper.setColValue(checkBoxColValue); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             columnAndValues.put(columnWrapper.columnName, columnWrapper.colValue); | 
			
		
	
		
			
				
					|  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |             // requiredColumns中的值为必填项
 | 
			
		
	
		
			
				
					|  |  |  |             if (columnWrapper.getRequired() == 1 && StringUtils.isBlank(columnWrapper.colValue)) { | 
			
		
	
		
			
				
					|  |  |  |                 interupt = true; | 
			
		
	
		
			
				
					|  |  |  |                 errorColumnNames.add(columnWrapper.combinedLabel); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |             target.put(columnWrapper.columnName, columnWrapper.colValue); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |         if (interupt) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(String.join(",", errorColumnNames) + "的值未填写"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return columnAndValues; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -517,6 +643,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |             columnWrapper.setCombinedLabel(combinedLabel); | 
			
		
	
		
			
				
					|  |  |  |             columnWrapper.setColumnName(item.getColumnName()); | 
			
		
	
		
			
				
					|  |  |  |             columnWrapper.setColIndexs(entry.getValue()); | 
			
		
	
		
			
				
					|  |  |  |             columnWrapper.setRequired(item.getRequired()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             columnWrapper.setOptionSourceType(item.getOptionSourceType()); | 
			
		
	
		
			
				
					|  |  |  |             columnWrapper.setOptionSourceValue(item.getOptionSourceValue()); | 
			
		
	
	
		
			
				
					|  |  | @ -714,5 +841,16 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         }*/ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 更新主表中人员类别标记 | 
			
		
	
		
			
				
					|  |  |  |      * @param icResiUserTableEnum | 
			
		
	
		
			
				
					|  |  |  |      * @param resiUserId | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private void updateMainTableResiTypeFlag(IcResiUserTableEnums icResiUserTableEnum, String resiUserId) { | 
			
		
	
		
			
				
					|  |  |  |         HashMap<String, Boolean> map = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         map.put(icResiUserTableEnum.getMainTableFlagColumnName(), true); | 
			
		
	
		
			
				
					|  |  |  |         icResiUserDao.upTable("ic_resi_user", resiUserId, map); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |      | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |