ludc
2024-12-04 e405b861b9521f5ea38c5402203a5b05988f9de2
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/WebEnumController.java
@@ -1,21 +1,31 @@
package com.vci.web.controller;
import com.vci.constant.FrameWorkLangCodeConstant;
import com.vci.dto.OsEnumDTO;
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.starter.web.pagemodel.DataGrid;
import com.vci.pagemodel.KeyValue;
import com.vci.pagemodel.OsEnumItemVO;
import com.vci.pagemodel.OsEnumVO;
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.OsEnumServiceI;
import com.vci.starter.web.util.Lcm.Func;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
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;
@@ -46,7 +56,6 @@
    * @return 枚举的下拉值
    */
   @VciBusinessLog(notStore=true,operateName="获取枚举")
   @VciUnCheckRight
   @GetMapping("/getEnum")
   public BaseResult<List<KeyValue>> getEnum(String comboxKey){
      return BaseResult.success(enumService.getEnum(comboxKey));
@@ -87,13 +96,30 @@
   }
   /**
    * 根据枚举类型获取枚举
    * @param enumType 查询条件name
    * @return 列表的内容
    */
   @GetMapping( "/getEnumMapByType")
   @VciBusinessLog(operateName = "枚举列表")
   public BaseResult getEnumMapByType(String enumType) {
      try {
         return BaseResult.dataList(enumService.getEnumMapByType(enumType));
      }catch (Exception e) {
         e.printStackTrace();
         String exceptionMessage = "枚举管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
         logger.error(exceptionMessage);
         return BaseResult.fail(exceptionMessage);
      }
   }
   /**
    * 枚举列表
    * @param enumName 查询条件name
    * @return 列表的内容
    */
   @GetMapping( "/getEnumTypeList")
   @VciBusinessLog(operateName = "枚举列表")
   @VciUnCheckRight
   public BaseResult<List<OsEnumVO>> getEnumTypeList(String enumName) {
      try {
         return BaseResult.dataList(enumService.getEnumTypeList(enumName));
@@ -112,7 +138,6 @@
    */
   @PostMapping( "/addEnumType")
   @VciBusinessLog(operateName = "添加枚举")
   @VciUnCheckRight
   public BaseResult addEnumType(@RequestBody OsEnumDTO osEnumDTO) {
      try {
         return enumService.addEnumType(osEnumDTO) ? BaseResult.success("枚举类型添加成功!"):BaseResult.fail("枚举类型添加失败!");
@@ -131,7 +156,6 @@
    */
   @PutMapping( "/updateEnumType")
   @VciBusinessLog(operateName = "修改枚举")
   @VciUnCheckRight
   public BaseResult updateEnumType(@RequestBody OsEnumDTO osEnumDTO) {
      try {
         return enumService.updateEnumType(osEnumDTO) ? BaseResult.success("枚举类型修改成功!"):BaseResult.fail("枚举类型修改失败!");
@@ -150,7 +174,6 @@
    */
   @DeleteMapping( "/deleteEnumTypes")
   @VciBusinessLog(operateName = "删除枚举")
   @VciUnCheckRight
   public BaseResult deleteEnumTypes(@RequestBody List<OsEnumDTO> osEnumDTOS) {
      try {
         return enumService.deleteEnumTypes(osEnumDTOS) ? BaseResult.success("枚举类型删除成功!"):BaseResult.fail("枚举类型删除失败!");
@@ -164,12 +187,11 @@
   /**
    * 查看枚举的使用范围
    * @param enumName
    * @return 列表的内容
    * @param enumName 枚举名称
    * @return map对象
    */
   @GetMapping( "/getUsedEnumList")
   @VciBusinessLog(operateName = "查看枚举的使用范围")
   @VciUnCheckRight
   public BaseResult getUsedEnumList(String enumName) {
      try {
         return BaseResult.dataList(enumService.getUsedEnumList(enumName));
@@ -181,4 +203,74 @@
      }
   }
   /**
    * 导出选中的枚举类型
    * @param exportFileName 导出的文件名
    * @param enumNames 需要导出的枚举名称
    * @param response
    */
   @GetMapping( "/exportEnumTypes")
   @VciBusinessLog(operateName = "导出枚举类型")
   public void exportEnumTypes(String exportFileName,String enumNames, HttpServletResponse response){
      try {
         String excelPath = enumService.exportEnumTypes(exportFileName,enumNames,false);
         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 exportFileName
    * @param response
    */
   @GetMapping( "/downloadEnumTemplate")
   @VciBusinessLog(operateName = "导出枚举类型")
   public void downloadEnumTemplate(String exportFileName, HttpServletResponse response){
      try {
         String excelPath = enumService.downloadEnumTemplate(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
    */
   @RequestMapping(value = "/importEnumTypes",method = RequestMethod.POST)
   public BaseResult importEnumTypes(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 enumService.importEnumTypes(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();
      }
   }
}