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