|
|
@ -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<PageData<IcPublicServiceListResultDTO>>().ok(icPublicServiceService.list(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) |
|
|
|
public Result<IcPublicServiceDTO> get(@PathVariable("id") String id){ |
|
|
|
@RequestMapping(value = "{id}", method = {RequestMethod.POST, RequestMethod.GET}) |
|
|
|
public Result<IcPublicServiceDTO> get(@PathVariable("id") String id) { |
|
|
|
IcPublicServiceDTO data = icPublicServiceService.get(id); |
|
|
|
return new Result<IcPublicServiceDTO>().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"); |
|
|
|
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"); |
|
|
|
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream("excel/public_service_template.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); |
|
|
|
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(); |
|
|
|
} |
|
|
|