| | |
| | | package com.vci.web.controller; |
| | | |
| | | import com.vci.constant.FrameWorkLangCodeConstant; |
| | | import com.vci.starter.web.annotation.controller.VciUnCheckRight; |
| | | import com.vci.starter.web.annotation.log.VciBusinessLog; |
| | | import com.vci.starter.web.annotation.permission.VciPermission; |
| | | 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.web.dto.OsStatusDTO; |
| | | import com.vci.web.pageModel.OsLifeCycleVO; |
| | | import com.vci.web.pageModel.OsStatusVO; |
| | | import com.vci.dto.OsStatusDTO; |
| | | import com.vci.pagemodel.OsLifeCycleVO; |
| | | import com.vci.pagemodel.OsStatusVO; |
| | | 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.OsLifeCycleServiceI; |
| | | import com.vci.web.service.OsStatusServiceI; |
| | | 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; |
| | | |
| | | /** |
| | | * 状态的控制器 |
| | |
| | | private OsLifeCycleServiceI lifeCycleService; |
| | | |
| | | /** |
| | | * 日志 |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | /** |
| | | * 状态的列表 |
| | | * @param queryObject 查询对象 |
| | | * @return 显示对象 |
| | | */ |
| | | @GetMapping("/gridStatus") |
| | | @VciBusinessLog(operateName = "查看状态列表") |
| | | public DataGrid<OsStatusVO> gridStatus(BaseQueryObject queryObject){ |
| | | return statusService.gridStatus(queryObject.getConditionMap(),queryObject.getPageHelper()); |
| | | @VciUnCheckRight |
| | | public BaseResult<OsStatusVO> gridStatus(BaseQueryObject queryObject){ |
| | | try { |
| | | return BaseResult.dataGrid(statusService.gridStatus(queryObject.getConditionMap(),queryObject.getPageHelper())); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "属性管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 使用的生命周期的对象 |
| | | */ |
| | | @GetMapping("/listUsed") |
| | | public DataGrid<OsLifeCycleVO> listUsed(String oid){ |
| | | return lifeCycleService.listStatusUsed(oid); |
| | | @VciBusinessLog(operateName = "查询状态池的应用范围") |
| | | @VciUnCheckRight |
| | | public BaseResult<OsLifeCycleVO> listUsed(String oid){ |
| | | try { |
| | | return BaseResult.dataGrid(lifeCycleService.listStatusUsed(oid)); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "属性管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 执行结果 |
| | | */ |
| | | @PostMapping("/addSave") |
| | | public BaseResult addSave(OsStatusDTO statusDTO){ |
| | | statusService.addSave(statusDTO); |
| | | return BaseResult.success(); |
| | | public BaseResult addSave(@RequestBody OsStatusDTO statusDTO){ |
| | | try { |
| | | return statusService.addSave(statusDTO) ? BaseResult.success("添加状态成功!"):BaseResult.fail("添加状态失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "添加状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 执行结果 |
| | | */ |
| | | @PutMapping("/editSave") |
| | | public BaseResult editSave(OsStatusDTO statusDTO){ |
| | | statusService.editSave(statusDTO); |
| | | return BaseResult.success(); |
| | | public BaseResult editSave(@RequestBody OsStatusDTO statusDTO){ |
| | | try { |
| | | return statusService.editSave(statusDTO) ? BaseResult.success("修改状态成功!"):BaseResult.fail("修改状态失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "修改状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除状态 |
| | | * @param oids 状态的主键 |
| | | * @param osStatusDTOS 状态的DTO对象 |
| | | * @return 执行结果 |
| | | */ |
| | | @DeleteMapping("/delete") |
| | | public BaseResult delete(String oids){ |
| | | statusService.delete(oids); |
| | | return BaseResult.success(); |
| | | @DeleteMapping("/deleteStatus") |
| | | public BaseResult deleteStatus(@RequestBody List<OsStatusDTO> osStatusDTOS){ |
| | | try { |
| | | return statusService.deleteStatus(osStatusDTOS) ? BaseResult.success("删除状态成功!"):BaseResult.fail("删除状态失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "删除状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return BaseResult.success(statusService.getObjectByOid(oid)); |
| | | } |
| | | |
| | | /** |
| | | * 导出状态 |
| | | * @param exportFileName |
| | | * @param statusOids |
| | | * @param response |
| | | */ |
| | | @GetMapping( "/exportStatus") |
| | | @VciBusinessLog(operateName = "导出状态") |
| | | public void exportStatus(String exportFileName,String statusOids, HttpServletResponse response){ |
| | | try { |
| | | String excelPath = statusService.exportStatus(exportFileName,statusOids,true); |
| | | 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( "/downloadStatusTemplate") |
| | | @VciBusinessLog(operateName = "导出状态") |
| | | public void downloadStatusTemplate(String exportFileName, HttpServletResponse response){ |
| | | try { |
| | | String excelPath = statusService.downloadStatusTemplate(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("/importStatus") |
| | | @VciBusinessLog(operateName = "导入状态") |
| | | public BaseResult importStatus(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 statusService.importStatus(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(); |
| | | } |
| | | } |
| | | |
| | | } |