| | |
| | | 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.LangBaseUtil; |
| | | import com.vci.starter.web.util.LocalFileUtil; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.web.service.OsEnumServiceI; |
| | | import com.vci.web.util.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.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | |
| | | private OsEnumServiceI enumService; |
| | | |
| | | /** |
| | | * 日志 |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | /** |
| | | * 获取枚举的下拉框 |
| | | * @param comboxKey 枚举的名称 |
| | | * @return 枚举的下拉值 |
| | | */ |
| | | @VciBusinessLog(notStore=true,operateName="获取枚举") |
| | | @VciUnCheckRight |
| | | @GetMapping("/getEnum") |
| | | public BaseResult<List<KeyValue>> getEnum(String comboxKey){ |
| | | return BaseResult.success(enumService.getEnum(comboxKey)); |
| | | } |
| | | |
| | | /** |
| | | * 参照枚举列表 |
| | | * @param baseQueryObject 查询条件 |
| | | * @return 列表的内容 |
| | | */ |
| | | @GetMapping( "/referDataGrid") |
| | | @VciBusinessLog(operateName = "参照枚举列表") |
| | | public DataGrid<OsEnumVO> referDataGrid(BaseQueryObject baseQueryObject){ |
| | | return enumService.referDataGrid(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper()); |
| | | } |
| | | |
| | | /** |
| | | * 获取枚举的明细 |
| | | * @param pkEnum 枚举的主键 |
| | | * @return 枚举的选项 |
| | | */ |
| | | @GetMapping("/gridEnumItemByOid") |
| | | @VciBusinessLog(operateName = "获取枚举的明细") |
| | | public DataGrid<OsEnumItemVO> gridEnumItemByOid(String pkEnum){ |
| | | return enumService.gridEnumItemByOid(pkEnum); |
| | | } |
| | | |
| | | /** |
| | | * 获取数据的密级 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 枚举列表 |
| | | * @param baseQueryObject 查询条件 |
| | | * 根据枚举类型获取枚举 |
| | | * @param enumType 查询条件name |
| | | * @return 列表的内容 |
| | | */ |
| | | @GetMapping( "/gridEnum") |
| | | @GetMapping( "/getEnumMapByType") |
| | | @VciBusinessLog(operateName = "枚举列表") |
| | | public DataGrid<OsEnumVO> gridEnum(BaseQueryObject baseQueryObject){ |
| | | return enumService.referDataGrid(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper()); |
| | | 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 pkEnum 枚举的主键 |
| | | * @return 枚举的选项 |
| | | * 枚举列表 |
| | | * @param enumName 查询条件name |
| | | * @return 列表的内容 |
| | | */ |
| | | @GetMapping("/gridEnumItemByOid") |
| | | @VciBusinessLog(operateName = "获取枚举的明细") |
| | | public DataGrid<OsEnumItemVO> gridEnumItemByOid(String pkEnum){ |
| | | return enumService.gridEnumItemByOid(pkEnum); |
| | | @GetMapping( "/getEnumTypeList") |
| | | @VciBusinessLog(operateName = "枚举列表") |
| | | public BaseResult<List<OsEnumVO>> getEnumTypeList(String enumName) { |
| | | try { |
| | | return BaseResult.dataList(enumService.getEnumTypeList(enumName)); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "枚举管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加单条枚举 |
| | | * @param osEnumDTO |
| | | * @return 列表的内容 |
| | | */ |
| | | @PostMapping( "/addEnumType") |
| | | @VciBusinessLog(operateName = "添加枚举") |
| | | public BaseResult addEnumType(@RequestBody OsEnumDTO osEnumDTO) { |
| | | try { |
| | | return enumService.addEnumType(osEnumDTO) ? BaseResult.success("枚举类型添加成功!"):BaseResult.fail("枚举类型添加失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "增加枚举类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改单条枚举(带修改枚举项功能) |
| | | * @param osEnumDTO |
| | | * @return 列表的内容 |
| | | */ |
| | | @PutMapping( "/updateEnumType") |
| | | @VciBusinessLog(operateName = "修改枚举") |
| | | public BaseResult updateEnumType(@RequestBody OsEnumDTO osEnumDTO) { |
| | | try { |
| | | return enumService.updateEnumType(osEnumDTO) ? BaseResult.success("枚举类型修改成功!"):BaseResult.fail("枚举类型修改失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "修改枚举类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除枚举 |
| | | * @param osEnumDTOS |
| | | * @return 列表的内容 |
| | | */ |
| | | @DeleteMapping( "/deleteEnumTypes") |
| | | @VciBusinessLog(operateName = "删除枚举") |
| | | public BaseResult deleteEnumTypes(@RequestBody List<OsEnumDTO> osEnumDTOS) { |
| | | try { |
| | | return enumService.deleteEnumTypes(osEnumDTOS) ? BaseResult.success("枚举类型删除成功!"):BaseResult.fail("枚举类型删除失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "删除枚举类型时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查看枚举的使用范围 |
| | | * @param enumName 枚举名称 |
| | | * @return map对象 |
| | | */ |
| | | @GetMapping( "/getUsedEnumList") |
| | | @VciBusinessLog(operateName = "查看枚举的使用范围") |
| | | public BaseResult getUsedEnumList(String enumName) { |
| | | try { |
| | | return BaseResult.dataList(enumService.getUsedEnumList(enumName)); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "获取枚举的使用范围时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导出选中的枚举类型 |
| | | * @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); |
| | | 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(e.getMessage(),new String[0],e); |
| | | }finally { |
| | | file1.delete(); |
| | | } |
| | | } |
| | | |
| | | } |