Browse Source

新增:

1.ic居民信息导入所用excel模板下载
dev_shibei_match
wangxianzhang 4 years ago
parent
commit
31aa37d650
  1. 70
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  2. BIN
      epmet-user/epmet-user-server/src/main/resources/excel/ic_resi_info_import_cid_for_easy_excel.xls

70
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

@ -28,6 +28,7 @@ import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
@ -51,6 +52,7 @@ import com.epmet.feign.OperCustomizeOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.service.IcResiUserImportService;
import com.epmet.service.IcResiUserService;
import jodd.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
@ -58,6 +60,9 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -66,6 +71,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -114,6 +120,30 @@ public class IcResiUserController {
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
/**
* 模板枚举
*/
public enum IcUserTemplateEnums {
IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_info_import_cid_for_easy_excel.xls", "居民信息导入模板.xls"),
IC_RESI_EXPORT_TEMPLATE("excel/ic_resi_info_cid_for_easy_excel.xlsx", "居民信息导出模板.xlsx");
private String pathInApp;
private String templateName;
IcUserTemplateEnums(String pathInApp, String templateName) {
this.pathInApp = pathInApp;
this.templateName = templateName;
}
public String getPathInApp() {
return pathInApp;
}
public String getTemplateName() {
return templateName;
}
}
{
// 初始化上传目录
String home = System.getProperty("user.home");
@ -259,7 +289,7 @@ public class IcResiUserController {
pageFormDTO.setPageFlag(false);
//获取模版文件
File file = getExportTemplateFile(customerId);
File file = getIcResiTemplateFile(customerId, IcUserTemplateEnums.IC_RESI_EXPORT_TEMPLATE);
ExcelWriter excelWriter = null;
try {
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("居民基本信息.xlsx", response)).withTemplate(file).build();
@ -338,7 +368,7 @@ public class IcResiUserController {
* @param customerId
* @return
*/
private File getExportTemplateFile(String customerId) throws Exception{
private File getIcResiTemplateFile(String customerId, IcUserTemplateEnums template) throws Exception{
String fileType = ".xlsx";
String fileName = customerId + fileType;
File file = new File(IC_RESI_DOWNLOAD_DIR.resolve(fileName).toString());
@ -354,13 +384,12 @@ public class IcResiUserController {
Result<byte[]> result = HttpClientManager.getInstance().getDownloadFilebytes(fileUrlResult.getData(), null);
//获取模版失败 则把默认文件写入
if (result == null || !result.success()) {
log.warn("获取居民导出模版失败,path:{},走默认模版", ossFilePath);
String defaultTemplatePath = "excel/ic_resi_info_cid_for_easy_excel.xlsx";
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(defaultTemplatePath);
log.warn("获取居民模版失败,path:{},走默认模版", ossFilePath);
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(template.getPathInApp());
FileUtils.copyInputStreamToFile(resourceAsStream,file);
log.warn("getExportTemplateFile copy default file to template,customerId:{}",customerId);
log.warn("getIcResiTemplateFile copy default file to template,customerId:{}",customerId);
} else {
log.warn("getExportTemplateFile reload file form oss default file to template,customerId:{}",customerId);
log.warn("getIcResiTemplateFile reload file form oss default file to template,customerId:{}",customerId);
FileUtils.writeByteArrayToFile(file,result.getData());
}
redisUtils.hSet(RedisKeys.getResiTempChangedKey(customerId), serverIp, NumConstant.ZERO_STR);
@ -492,4 +521,31 @@ public class IcResiUserController {
ValidatorUtils.validateEntity(formDTO, DemandUserFormDTO.InternalGroup.class);
return new Result<List<DemandUserResDTO>>().ok(icResiUserService.queryDemandUsers(formDTO));
}
/**
* 下载ic居民信息导入excel模板
* @param loginUserInfo
* @return
*/
@PostMapping("import/download-template")
public ResponseEntity<byte[]> downloadIcResiDownloadTemplate(@LoginUser TokenDto loginUserInfo) {
String customerId = loginUserInfo.getCustomerId();
try {
File icResiImportTemplateFile = getIcResiTemplateFile(customerId, IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE);
HttpHeaders headers = new HttpHeaders();
headers.add("Access-Control-Expose-Headers", "Content-Disposition");
headers.add("content-Type", "application/vnd.ms-excel");
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);
} catch (Exception e) {
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e);
log.error("下载IC居民信息导入模板失败:{}", errorStackTrace);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下载IC居民信息导入模板失败");
}
}
}

BIN
epmet-user/epmet-user-server/src/main/resources/excel/ic_resi_info_import_cid_for_easy_excel.xls

Binary file not shown.
Loading…
Cancel
Save