|
|
@ -1,5 +1,8 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.annotation.Excel; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
import com.alibaba.excel.EasyExcelFactory; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
@ -32,10 +35,14 @@ import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -114,15 +121,37 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
*/ |
|
|
|
@Data |
|
|
|
public static class ErrorRow { |
|
|
|
|
|
|
|
@Excel(name = "工作表", width = 30) |
|
|
|
private String sheetName; |
|
|
|
|
|
|
|
private String tableName; |
|
|
|
|
|
|
|
@Excel(name = "身份证号", width = 40) |
|
|
|
private String idCard; |
|
|
|
|
|
|
|
@Excel(name = "姓名", width = 25) |
|
|
|
private String name; |
|
|
|
|
|
|
|
@Excel(name = "错误信息", width = 40) |
|
|
|
private String errorInfo; |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class SkipedRow { |
|
|
|
|
|
|
|
@Excel(name = "工作表") |
|
|
|
private String sheetName; |
|
|
|
|
|
|
|
private String tableName; |
|
|
|
|
|
|
|
@Excel(name = "身份证号") |
|
|
|
private String idCard; |
|
|
|
|
|
|
|
@Excel(name = "姓名") |
|
|
|
private String name; |
|
|
|
|
|
|
|
@Excel(name = "信息") |
|
|
|
private String info; |
|
|
|
} |
|
|
|
|
|
|
@ -132,7 +161,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Object importIcResiInfoFromExcel() { |
|
|
|
public void importIcResiInfoFromExcel(String excelPathName, HttpServletResponse response) { |
|
|
|
String loginUserId = loginUserUtil.getLoginUserId(); |
|
|
|
String loginUserApp = loginUserUtil.getLoginUserApp(); |
|
|
|
String loginUserClient = loginUserUtil.getLoginUserClient(); |
|
|
@ -145,7 +174,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
LoginUserDetailsResultDTO loginUserDetails = getResultDataOrThrowsException(epmetUserOpenFeignClient.getLoginUserDetails(userForm), ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null); |
|
|
|
String currUserAgencyId = loginUserDetails.getAgencyId(); |
|
|
|
|
|
|
|
String excelPathName = "/opt/test/基础信息表/resi_info.xls"; |
|
|
|
//String excelPathName = "/opt/test/基础信息表/resi_info.xls";
|
|
|
|
CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(currUserAgencyId), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null); |
|
|
|
String customerId = agencyInfo.getCustomerId(); |
|
|
|
|
|
|
@ -175,17 +204,20 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
} |
|
|
|
|
|
|
|
String errors = JSON.toJSONString(errorRows.get()); |
|
|
|
String skipeds = JSON.toJSONString(skipedRows.get()); |
|
|
|
//String skipeds = JSON.toJSONString(skipedRows.get());
|
|
|
|
|
|
|
|
log.error(errors); |
|
|
|
log.error(skipeds); |
|
|
|
//log.error(skipeds);
|
|
|
|
|
|
|
|
try { |
|
|
|
downLoadResults(response); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("【导入IC居民附加信息】下载导入结果信息失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
skipedRows.remove(); |
|
|
|
errorRows.remove(); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -344,6 +376,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
skipedRow.setName(columnAndValues.get("NAME")); |
|
|
|
skipedRow.setIdCard(idCard); |
|
|
|
skipedRow.setInfo("身份证号已存在,跳过导入"); |
|
|
|
skipedRow.setTableName(tableName); |
|
|
|
skipedRows.get().get(IcResiUserTableEnums.IC_RESI_USER.getTableName()).add(skipedRow); |
|
|
|
continue; |
|
|
|
} |
|
|
@ -362,6 +395,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
errorRow.setIdCard(columnAndValues.get("ID_CARD")); |
|
|
|
errorRow.setName(columnAndValues.get("NAME")); |
|
|
|
errorRow.setErrorInfo(errorMsg); |
|
|
|
errorRow.setTableName(tableName); |
|
|
|
errorRows.get().get(IcResiUserTableEnums.IC_RESI_USER.getTableName()).add(errorRow); |
|
|
|
} finally { |
|
|
|
columnAndValues.clear(); |
|
|
@ -414,6 +448,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
skipedRow.setName(columnAndValues.get("NAME")); |
|
|
|
skipedRow.setIdCard(columnAndValues.get("ID_CARD")); |
|
|
|
skipedRow.setInfo("信息已存在,跳过导入"); |
|
|
|
skipedRow.setTableName(targetTableName); |
|
|
|
skipedRows.get().get(targetTableName).add(skipedRow); |
|
|
|
|
|
|
|
continue; |
|
|
@ -444,6 +479,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
errorRow.setName(columnAndValues.get("NAME")); |
|
|
|
errorRow.setIdCard(columnAndValues.get("ID_CARD")); |
|
|
|
errorRow.setErrorInfo(errorMsg); |
|
|
|
errorRow.setTableName(targetTableName); |
|
|
|
errorRows.get().get(targetTableName).add(errorRow); |
|
|
|
} finally { |
|
|
|
columnAndValues.clear(); |
|
|
@ -852,5 +888,29 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
|
map.put(icResiUserTableEnum.getMainTableFlagColumnName(), true); |
|
|
|
icResiUserDao.upTable("ic_resi_user", resiUserId, map); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 下载导入结果 |
|
|
|
* @param response |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
public void downLoadResults(HttpServletResponse response) throws IOException { |
|
|
|
//public static final ThreadLocal<Map<String, List<ErrorRow>>> errorRows = new ThreadLocal<>();
|
|
|
|
|
|
|
|
String fileName = "导入失败条目清单.xls"; |
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8")); |
|
|
|
|
|
|
|
LinkedList<ErrorRow> list = new LinkedList<>(); |
|
|
|
for (Map.Entry<String, List<ErrorRow>> entry : errorRows.get().entrySet()) { |
|
|
|
list.addAll(entry.getValue()); |
|
|
|
} |
|
|
|
|
|
|
|
list.forEach(row -> row.setSheetName(IcResiUserTableEnums.getObjectByTableName(row.tableName).getTableComment())); |
|
|
|
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的条目列表","导入失败"), |
|
|
|
ErrorRow.class, list); |
|
|
|
|
|
|
|
workbook.write(response.getOutputStream()); |
|
|
|
} |
|
|
|
} |
|
|
|