|  |  | @ -24,6 +24,7 @@ import com.epmet.commons.tools.redis.common.CustomerStaffRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.security.user.LoginUserUtil; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constant.ImportTaskConstants; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcResiUserDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcUserChangeDetailedDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcUserChangeRecordDao; | 
			
		
	
	
		
			
				
					|  |  | @ -72,7 +73,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     // 错误和跳过excel行暂存
 | 
			
		
	
		
			
				
					|  |  |  |     public static final ThreadLocal<Map<String, List<ErrorRow>>> errorRows = new ThreadLocal<>(); | 
			
		
	
		
			
				
					|  |  |  |     public static final ThreadLocal<Map<String, List<SkipedRow>>> skipedRows = new ThreadLocal<>(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 导入的居民中,新增或者变动的居民 | 
			
		
	
	
		
			
				
					|  |  | @ -126,6 +126,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private RedisUtils redisUtils; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private ImportTaskService importTaskService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 字表中不需要的列 | 
			
		
	
	
		
			
				
					|  |  | @ -212,11 +215,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 导入居民信息 | 
			
		
	
		
			
				
					|  |  |  |      *  导入主表和所有子表信息 | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      * @param importTaskId 导入任务id | 
			
		
	
		
			
				
					|  |  |  |      * @param formItemList item列表 | 
			
		
	
		
			
				
					|  |  |  |      * @param excelPathName excel缓存路径 | 
			
		
	
		
			
				
					|  |  |  |      * @param response 响应对象 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void importIcResiInfoFromExcel(List<FormItemResult> formItemList, String excelPathName, HttpServletResponse response) { | 
			
		
	
		
			
				
					|  |  |  |     public void importIcResiInfoFromExcel(String importTaskId, List<FormItemResult> formItemList, String excelPathName, HttpServletResponse response) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         String loginUserId = loginUserUtil.getLoginUserId(); | 
			
		
	
		
			
				
					|  |  |  |         String loginUserApp = loginUserUtil.getLoginUserApp(); | 
			
		
	
	
		
			
				
					|  |  | @ -235,6 +240,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(currUserAgencyId), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null, null); | 
			
		
	
		
			
				
					|  |  |  |         String customerId = agencyInfo.getCustomerId(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         boolean hasErrorRows = false; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             initImportThreadLocal(customerId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -273,11 +280,27 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |             saveResiCategoryChangedRecord(categoryChangedResis); | 
			
		
	
		
			
				
					|  |  |  |             saveTransferedResiRecord(transferedResis); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             hasErrorRows = hasErrorRows(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 downLoadResults(response); | 
			
		
	
		
			
				
					|  |  |  |                 // todo 做了导入记录之后,这里就要判断,没有错误就不生成文件了
 | 
			
		
	
		
			
				
					|  |  |  |                 downLoadResults(hasErrorRows, response); | 
			
		
	
		
			
				
					|  |  |  |             } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |                 log.error("【导入IC居民附加信息】下载导入结果信息失败:{}", ExceptionUtils.getErrorStackTrace(e)); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 更新上传记录
 | 
			
		
	
		
			
				
					|  |  |  |             if (hasErrorRows) { | 
			
		
	
		
			
				
					|  |  |  |                 importTaskService.finish(importTaskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, loginUserId, | 
			
		
	
		
			
				
					|  |  |  |                         null, null); | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 importTaskService.finish(importTaskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS, loginUserId, | 
			
		
	
		
			
				
					|  |  |  |                         null, null); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |             // 抛出,让外层捕获处理,记录
 | 
			
		
	
		
			
				
					|  |  |  |             throw e; | 
			
		
	
		
			
				
					|  |  |  |         } finally { | 
			
		
	
		
			
				
					|  |  |  |             // 清空rediskey
 | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
	
		
			
				
					|  |  | @ -289,7 +312,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 清空线程变量
 | 
			
		
	
		
			
				
					|  |  |  |             skipedRows.remove(); | 
			
		
	
		
			
				
					|  |  |  |             errorRows.remove(); | 
			
		
	
		
			
				
					|  |  |  |             newlyOrChangedResi.remove(); | 
			
		
	
		
			
				
					|  |  |  |             resiCategoryColumnNameAndLabel.remove(); | 
			
		
	
	
		
			
				
					|  |  | @ -297,6 +319,22 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 是否有错误行 | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private Boolean hasErrorRows() { | 
			
		
	
		
			
				
					|  |  |  |         boolean hasError = false; | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<ErrorRow>> tableAndErrorRows = errorRows.get(); | 
			
		
	
		
			
				
					|  |  |  |         for (Map.Entry<String, List<ErrorRow>> entry:tableAndErrorRows.entrySet()) { | 
			
		
	
		
			
				
					|  |  |  |             if (entry.getValue().size() != 0) { | 
			
		
	
		
			
				
					|  |  |  |                 hasError = true; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return hasError; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * threadLocal初始化 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
	
		
			
				
					|  |  | @ -310,7 +348,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |         for (IcResiUserTableEnum e : IcResiUserTableEnum.values()) { | 
			
		
	
		
			
				
					|  |  |  |             skipedRowsMap.put(e.getTableName(), new LinkedList<>()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         skipedRows.set(skipedRowsMap); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 错误信息
 | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<ErrorRow>> errorRowsMap = new LinkedHashMap<>(); | 
			
		
	
	
		
			
				
					|  |  | @ -1000,19 +1037,11 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res | 
			
		
	
		
			
				
					|  |  |  |      * @param response | 
			
		
	
		
			
				
					|  |  |  |      * @throws IOException | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public void downLoadResults(HttpServletResponse response) throws IOException { | 
			
		
	
		
			
				
					|  |  |  |     public void downLoadResults(Boolean hasErrorRows, HttpServletResponse response) throws IOException { | 
			
		
	
		
			
				
					|  |  |  |         String fileName; | 
			
		
	
		
			
				
					|  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |         // 判断是否有错误信息,以确定文件名
 | 
			
		
	
		
			
				
					|  |  |  |         boolean hasError = false; | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<ErrorRow>> tableAndErrorRows = errorRows.get(); | 
			
		
	
		
			
				
					|  |  |  |         for (Map.Entry<String, List<ErrorRow>> entry:tableAndErrorRows.entrySet()) { | 
			
		
	
		
			
				
					|  |  |  |             if (entry.getValue().size() != 0) { | 
			
		
	
		
			
				
					|  |  |  |                 hasError = true; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         if (hasError) { | 
			
		
	
		
			
				
					|  |  |  |         if (hasErrorRows) { | 
			
		
	
		
			
				
					|  |  |  |             fileName = "导入失败条目清单.xls"; | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             fileName = "导入成功.xls"; | 
			
		
	
	
		
			
				
					|  |  | 
 |