diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcPublicServiceController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcPublicServiceController.java index f9b47cdb41..543e900e61 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcPublicServiceController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcPublicServiceController.java @@ -36,6 +36,7 @@ import com.epmet.utils.ImportTaskUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.VerticalAlignment; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +46,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import javax.websocket.server.PathParam; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -67,6 +69,8 @@ import java.util.UUID; @Slf4j public class IcPublicServiceController implements ResultDataResolver { + private static final String CATEGORY_TYPE = "tourism_resource"; + @Autowired private IcPublicServiceService icPublicServiceService; @@ -77,8 +81,8 @@ public class IcPublicServiceController implements ResultDataResolver { return new Result>().ok(icPublicServiceService.list(formDTO)); } - @RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) - public Result get(@PathVariable("id") String id){ + @RequestMapping(value = "{id}", method = {RequestMethod.POST, RequestMethod.GET}) + public Result get(@PathVariable("id") String id) { IcPublicServiceDTO data = icPublicServiceService.get(id); return new Result().ok(data); } @@ -118,13 +122,20 @@ public class IcPublicServiceController implements ResultDataResolver { } @RequestMapping(value = "download", method = {RequestMethod.GET, RequestMethod.POST}) - public void downloadTemplate(HttpServletResponse response) throws IOException { + public void downloadTemplate(HttpServletResponse response, @PathParam("categoryType") String categoryType) throws IOException { response.setCharacterEncoding("UTF-8"); response.addHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition"); - response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("公共服务导入模板", "UTF-8") + ".xlsx"); - - InputStream is = this.getClass().getClassLoader().getResourceAsStream("excel/public_service_template.xlsx"); + String fileName; + if (StringUtils.isNotEmpty(categoryType) && categoryType.equals(CATEGORY_TYPE)) { + response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("旅游资源导入模板", "UTF-8") + ".xlsx"); + fileName = "excel/tourism_resource_template.xlsx"; + } else { + response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("公共服务导入模板", "UTF-8") + ".xlsx"); + fileName = "excel/public_service_template.xlsx"; + } + InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); try { ServletOutputStream os = response.getOutputStream(); IOUtils.copy(is, os); @@ -144,7 +155,8 @@ public class IcPublicServiceController implements ResultDataResolver { formDTO.setPageNo(NumConstant.ONE); formDTO.setPageSize(NumConstant.TEN_THOUSAND); try { - String fileName = "公共服务管理" + DateUtils.format(new Date()) + ".xlsx"; + String fileName = formDTO.getCategoryType().equals(CATEGORY_TYPE) ? "旅游资源管理" + DateUtils.format(new Date()) + ".xlsx" : + "公共服务管理" + DateUtils.format(new Date()) + ".xlsx"; // 头的策略 WriteCellStyle headWriteCellStyle = new WriteCellStyle(); // 背景设置为红色 @@ -184,18 +196,22 @@ public class IcPublicServiceController implements ResultDataResolver { } @PostMapping("import") - public Result importExcel(MultipartFile file) { + public Result importExcel(MultipartFile file, String categoryType) { // 1.暂存文件 String originalFilename = file.getOriginalFilename(); String extName = originalFilename.substring(originalFilename.lastIndexOf(".")); Path fileSavePath; try { - Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_public_service", "import"); + Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir(categoryType, "import"); fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName)); } catch (IOException e) { String errorMsg = ExceptionUtils.getErrorStackTrace(e); - log.error("【公共服务管理导入】创建临时存储文件失败:{}", errorMsg); + if (categoryType.equals(CATEGORY_TYPE)) { + log.error("【旅游资源管理导入】创建临时存储文件失败:{}", errorMsg); + } else { + log.error("【公共服务管理导入】创建临时存储文件失败:{}", errorMsg); + } throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败"); } @@ -217,11 +233,11 @@ public class IcPublicServiceController implements ResultDataResolver { ImportTaskUtils.createImportTask(originalFilename, ImportTaskConstants.IC_PUBLIC_SERVICE), ServiceConstant.EPMET_COMMON_SERVICE, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), - "excel导入公共服务管理信息错误", - "导入公共服务管理信息失败"); + categoryType.equals(CATEGORY_TYPE) ? "excel导入旅游资源管理信息错误" : "excel导入公共服务管理信息错误", + categoryType.equals(CATEGORY_TYPE) ? "导入旅游资源管理信息失败" : "导入公共服务管理信息失败"); // 3.执行导入 - icPublicServiceService.importExcel(fileSavePath, rstData.getTaskId()); + icPublicServiceService.importExcel(fileSavePath, rstData.getTaskId(), categoryType); return new Result(); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcPublicServiceExcel.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcPublicServiceExcel.java index 872b2fd61b..8890f587a0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcPublicServiceExcel.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcPublicServiceExcel.java @@ -66,4 +66,4 @@ public class IcPublicServiceExcel { private String errorInfo; } -} \ No newline at end of file +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/handler/IcPublicServiceExcelImportListener.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/handler/IcPublicServiceExcelImportListener.java index 9feebd1fe0..3b8fbc47ba 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/handler/IcPublicServiceExcelImportListener.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/handler/IcPublicServiceExcelImportListener.java @@ -37,6 +37,7 @@ public class IcPublicServiceExcelImportListener implements ReadListener datas = new ArrayList<>(); @@ -50,12 +51,13 @@ public class IcPublicServiceExcelImportListener implements ReadListener existMap = null; - public IcPublicServiceExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, - IcPublicServiceServiceImpl IcPublicServiceServiceImpl, CoverageService coverageService, IcPublicServiceDao icPublicServiceDao) { + public IcPublicServiceExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, String categoryType, + IcPublicServiceServiceImpl IcPublicServiceServiceImpl, CoverageService coverageService, IcPublicServiceDao icPublicServiceDao) { this.currentUserId = currentUserId; this.currentCustomerId = currentCustomerId; this.currentAgencyId = currentAgencyId; this.currentAgencyPids = currentAgencyPids; + this.categoryType = categoryType; this.IcPublicServiceServiceImpl = IcPublicServiceServiceImpl; this.coverageService = coverageService; this.icPublicServiceDao = icPublicServiceDao; @@ -88,32 +90,36 @@ public class IcPublicServiceExcelImportListener implements ReadListener dictList = coverageService.dictMap(currentCustomerId, "public_service"); + List dictList = coverageService.dictMap(currentCustomerId, categoryType); Map dictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getLabel, IcCoverageCategoryDictListResultDTO::getValue)); datas.forEach(d -> { d.setCategory(dictMap.get(d.getCategory())); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcPublicServiceService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcPublicServiceService.java index 889917b05e..aa9b426600 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcPublicServiceService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcPublicServiceService.java @@ -69,5 +69,5 @@ public interface IcPublicServiceService extends BaseService