|
@ -72,6 +72,7 @@ import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
@ -135,7 +136,7 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
* 模板枚举 |
|
|
* 模板枚举 |
|
|
*/ |
|
|
*/ |
|
|
public enum IcUserTemplateEnums { |
|
|
public enum IcUserTemplateEnums { |
|
|
IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_info_import_cid_for_easy_excel.xls", "居民信息导入模板.xls"), |
|
|
IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_import_template.xls", "居民信息导入模板.xls"), |
|
|
IC_RESI_EXPORT_TEMPLATE("excel/ic_resi_info_cid_for_easy_excel.xlsx", "居民信息导出模板.xlsx"); |
|
|
IC_RESI_EXPORT_TEMPLATE("excel/ic_resi_info_cid_for_easy_excel.xlsx", "居民信息导出模板.xlsx"); |
|
|
|
|
|
|
|
|
private String pathInApp; |
|
|
private String pathInApp; |
|
@ -157,18 +158,13 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
// 初始化上传目录
|
|
|
// 初始化上传目录
|
|
|
String home = System.getProperty("user.home"); |
|
|
try { |
|
|
Path importDir = Paths.get(home, "epmet_files", "ic_user_import"); |
|
|
IC_RESI_UPLOAD_DIR = com.epmet.commons.tools.utils.FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_user_import"); |
|
|
if (Files.notExists(importDir)) { |
|
|
} catch (IOException e) { |
|
|
try { |
|
|
log.error("初始化居民信息上传目录失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
Files.createDirectories(importDir); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
log.error("创建数字赋能平台上传目录失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
IC_RESI_UPLOAD_DIR = importDir; |
|
|
|
|
|
|
|
|
|
|
|
Path exportDir = Paths.get(home, "epmet_files", "ic_user_export"); |
|
|
Path exportDir = Paths.get(System.getProperty("user.home"), "epmet_files", "ic_user_export"); |
|
|
if (Files.notExists(exportDir)) { |
|
|
if (Files.notExists(exportDir)) { |
|
|
try { |
|
|
try { |
|
|
Files.createDirectories(exportDir); |
|
|
Files.createDirectories(exportDir); |
|
@ -469,10 +465,10 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
|
|
|
|
|
// 三.异步执行导入
|
|
|
// 三.异步执行导入
|
|
|
executorService.execute(() -> { |
|
|
executorService.execute(() -> { |
|
|
|
|
|
boolean isAllSuccess = false; |
|
|
try { |
|
|
try { |
|
|
List<FormItemResult> formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); |
|
|
List<FormItemResult> formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); |
|
|
icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); |
|
|
isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); |
|
|
} catch (Throwable e) { |
|
|
} catch (Throwable e) { |
|
|
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); |
|
|
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); |
|
|
log.error("【导入居民信息失败】导入失败:{}", errorMsg); |
|
|
log.error("【导入居民信息失败】导入失败:{}", errorMsg); |
|
@ -488,8 +484,13 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
icResiUserImportService.finishImportTask(importTaskId, operatorId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, resultDesc, null); |
|
|
icResiUserImportService.finishImportTask(importTaskId, operatorId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, resultDesc, null); |
|
|
} finally { |
|
|
} finally { |
|
|
try { |
|
|
try { |
|
|
|
|
|
// 都导入成功了没问题,才删除
|
|
|
if (importTempFileSavePath != null){ |
|
|
if (importTempFileSavePath != null){ |
|
|
Files.delete(importTempFileSavePath); |
|
|
if (isAllSuccess) { |
|
|
|
|
|
Files.delete(importTempFileSavePath); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("【导入居民信息】未完全成功,上传文件:{}", importTempFileSavePath); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
@ -585,28 +586,30 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 下载ic居民信息导入excel模板 |
|
|
* 下载ic居民信息导入excel模板 |
|
|
* @param loginUserInfo |
|
|
|
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@PostMapping("import/download-template") |
|
|
@PostMapping("import/download-template") |
|
|
public ResponseEntity<byte[]> downloadIcResiDownloadTemplate(@LoginUser TokenDto loginUserInfo) { |
|
|
public void downloadIcResiDownloadTemplate(HttpServletResponse response) { |
|
|
String customerId = loginUserInfo.getCustomerId(); |
|
|
InputStream is = null; |
|
|
|
|
|
ServletOutputStream os = null; |
|
|
try { |
|
|
try { |
|
|
File icResiImportTemplateFile = getIcResiTemplateFile(customerId, IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE); |
|
|
os = response.getOutputStream(); |
|
|
|
|
|
|
|
|
|
|
|
is = this.getClass().getClassLoader().getResourceAsStream(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getPathInApp()); |
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
|
|
headers.add("Access-Control-Expose-Headers", "Content-Disposition"); |
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
headers.add("content-Type", "application/vnd.ms-excel"); |
|
|
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getTemplateName(), "UTF-8")); |
|
|
headers.add("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getTemplateName(), "UTF-8")); |
|
|
|
|
|
|
|
|
|
|
|
return new ResponseEntity<>(FileUtil.readBytes(icResiImportTemplateFile), headers, HttpStatus.OK); |
|
|
IOUtils.copy(is, os); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); |
|
|
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
|
|
|
log.error("下载IC居民信息导入模板失败:{}", errorStackTrace); |
|
|
log.error("下载IC居民信息导入模板失败:{}", errorStackTrace); |
|
|
|
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下载IC居民信息导入模板失败"); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下载IC居民信息导入模板失败"); |
|
|
|
|
|
} finally { |
|
|
|
|
|
org.apache.poi.util.IOUtils.closeQuietly(is); |
|
|
|
|
|
org.apache.poi.util.IOUtils.closeQuietly(os); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|