From 887824662344ef267e171dbfae2b8ef2145a61c6 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期五, 26 七月 2024 10:45:17 +0800 Subject: [PATCH] 属性池所有接口完善上传(待联调) --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java index a8fb24f..f33a04a 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java @@ -1,12 +1,15 @@ package com.vci.web.controller; +import com.vci.constant.FrameWorkLangCodeConstant; import com.vci.dto.OsAttributeDTO; import com.vci.starter.web.annotation.controller.VciUnCheckRight; import com.vci.starter.web.annotation.log.VciBusinessLog; +import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.BaseQueryObject; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.pagemodel.OsAttributeVO; import com.vci.starter.web.util.ControllerUtil; +import com.vci.starter.web.util.LocalFileUtil; import com.vci.starter.web.util.VciBaseUtil; import com.vci.web.service.OsAttributeServiceI; import com.vci.web.util.Func; @@ -15,8 +18,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.util.Date; import java.util.List; @@ -65,6 +70,7 @@ * @return */ @GetMapping("/getByAttributeNames") + @VciBusinessLog(operateName = "鏍规嵁澶氫釜灞炴�у悕绉版煡璇㈠睘鎬�") public BaseResult getByAttributeNames(String[] attrNames){ try { return BaseResult.dataList(attributeService.getByAttributeNames(attrNames)); @@ -83,13 +89,12 @@ */ @PostMapping( "/addAttribute") @VciBusinessLog(operateName = "娣诲姞灞炴��") - @VciUnCheckRight public BaseResult addAttribute(@RequestBody OsAttributeDTO osAttributeDTO) { try { return attributeService.addAttribute(osAttributeDTO) ? BaseResult.success("灞炴�ф坊鍔犳垚鍔燂紒"):BaseResult.fail("灞炴�ф坊鍔犲け璐ワ紒"); }catch (Exception e) { e.printStackTrace(); - String exceptionMessage = "澧炲姞灞炴�у瀷鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e); + String exceptionMessage = "澧炲姞灞炴�ф椂鍑虹幇閿欒锛屽師鍥狅細" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } @@ -102,6 +107,7 @@ */ @PutMapping( "/updateAttribute") @VciBusinessLog(operateName = "淇敼灞炴��") + @VciUnCheckRight public BaseResult updateAttribute(@RequestBody OsAttributeDTO osAttributeDTO) { try { return attributeService.updateAttribute(osAttributeDTO) ? BaseResult.success("灞炴�т慨鏀规垚鍔燂紒"):BaseResult.fail("灞炴�т慨鏀瑰け璐ワ紒"); @@ -156,8 +162,7 @@ * @param response */ @GetMapping( "/exportAttributes") - @VciBusinessLog(operateName = "瀵煎嚭鏋氫妇绫诲瀷") - @VciUnCheckRight + @VciBusinessLog(operateName = "瀵煎嚭灞炴��") public void exportAttributes(String exportFileName,String attrNames, HttpServletResponse response){ try { String excelPath = attributeService.exportAttributes(exportFileName,attrNames); @@ -174,5 +179,51 @@ } } + /** + * 涓嬭浇灞炴�у鍏ユā鏉� + * @param exportFileName + * @param response + */ + @GetMapping( "/downloadAttributeTemplate") + @VciBusinessLog(operateName = "瀵煎嚭灞炴��") + public void downloadAttributeTemplate(String exportFileName, HttpServletResponse response){ + try { + String excelPath = attributeService.downloadAttributeTemplate(exportFileName); + ControllerUtil.writeFileToResponse(response,excelPath); + } catch (Exception e) { + String msg = "涓嬭浇鏋氫妇瀵煎叆妯℃澘鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e); + try { + //鍑洪敊鏃� + e.printStackTrace(); + ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } + + /** + * 瀵煎叆灞炴�� + * @param file + * @return + */ + @PostMapping("/importAttributes") + @VciUnCheckRight + public BaseResult importAttributes(MultipartFile file){ + String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename()); + File file1 = new File(excelFileName); + try { + file.transferTo(new File(excelFileName)); + if (file != null) { + return attributeService.importAttributes(file1); + } else { + return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"}); + } + }catch (Throwable e) { + throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e); + }finally { + file1.delete(); + } + } } -- Gitblit v1.9.3