package com.vci.web.controller; import com.vci.constant.FrameWorkLangCodeConstant; import com.vci.dto.OsLifeCycleDTO; 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.OsERVO; import com.vci.pagemodel.OsLifeCycleVO; 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.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.*; 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; /** * 生命周期的控制器 * @author weidy * @date 2022-3-26 */ @RequestMapping("/lifeCycleController") @RestController public class OsLifeCycleController { /** * 生命周期的服务 */ @Autowired private OsLifeCycleServiceI lifeCycleService; /** * 日志 */ private Logger logger = LoggerFactory.getLogger(getClass()); /** * 生命周期列表 * @param baseQueryObject 基础查询对象,包含分页和查询 * @return 生命周期的对象 */ @GetMapping("/gridLifeCycle") public DataGrid gridLifeCycle(BaseQueryObject baseQueryObject){ return lifeCycleService.gridLifeCycle(baseQueryObject); } /** * 生命周期的链接线 * @param id 编号 * @return ER图内容 */ @GetMapping("/listLinesPic") public BaseResult listLinesPic(String id){ return BaseResult.success(lifeCycleService.listLinesPic(id)); } /** * 查询应用范围 * @param lifeCycleName 版本规则英文名称 * @return */ @GetMapping("/getUsedLifeCycleList") public BaseResult getUsedLifeCycleList(String lifeCycleName){ try { return BaseResult.dataList(lifeCycleService.getUsedLifeCycleList(lifeCycleName)); }catch (Exception e) { e.printStackTrace(); String exceptionMessage = "版本规则应用范围查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } } /** * 添加单条生命周期 * @param osLifeCycleVO * @return 列表的内容 */ @PostMapping( "/addLifeCycle") @VciBusinessLog(operateName = "添加生命周期") public BaseResult addLifeCycle(@RequestBody OsLifeCycleVO osLifeCycleVO) { try { return lifeCycleService.addLifeCycle(osLifeCycleVO) ? BaseResult.success("生命周期添加成功!"):BaseResult.fail("生命周期添加失败!"); }catch (Exception e) { e.printStackTrace(); String exceptionMessage = "添加生命周期时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } } /** * 修改单条生命周期 * @param osLifeCycleVO * @return 列表的内容 */ @PutMapping( "/updateLifeCycle") @VciBusinessLog(operateName = "修改生命周期") public BaseResult updateLifeCycle(@RequestBody OsLifeCycleVO osLifeCycleVO) { try { return lifeCycleService.updateLifeCycle(osLifeCycleVO) ? BaseResult.success("生命周期修改成功!"):BaseResult.fail("生命周期修改失败!"); }catch (Exception e) { e.printStackTrace(); String exceptionMessage = "修改生命周期时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } } /** * 删除生命周期 * @param lifeCycleDTOS * @return 列表的内容 */ @DeleteMapping( "/deleteLifeCycles") @VciBusinessLog(operateName = "删除生命周期") public BaseResult deleteLifeCycles(@RequestBody List lifeCycleDTOS) { try { return lifeCycleService.deleteLifeCycles(lifeCycleDTOS) ? BaseResult.success("生命周期删除成功!"):BaseResult.fail("生命周期删除失败!"); }catch (Exception e) { e.printStackTrace(); String exceptionMessage = "删除生命周期时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } } /** * 导出选中的生命周期 * @param exportFileName 导出的文件名 * @param lcNames 需要导出的生命周期英文名称 * @param response */ @GetMapping( "/exportLifeCycles") @VciBusinessLog(operateName = "导出生命周期") public void exportLifeCycles(String exportFileName,String lcNames, HttpServletResponse response){ try { String excelPath = lifeCycleService.exportLifeCycles(exportFileName,lcNames,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( "/downloadLifeCycleTemplate") @VciBusinessLog(operateName = "下载生命周期导入模板") public void downloadLifeCycleTemplate(String exportFileName, HttpServletResponse response){ try { String excelPath = lifeCycleService.downloadLifeCycleTemplate(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("/importLifeCycles") @VciBusinessLog(operateName = "导入生命周期") public BaseResult importLifeCycles(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 lifeCycleService.importLifeCycles(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(); } } /** * 查询所有跃迁事件key * @return */ @GetMapping("/getLCEventKeys") public BaseResult getLCEventKeys(){ try { return BaseResult.dataList(lifeCycleService.getLCEventKeys()); }catch (Exception e) { e.printStackTrace(); String exceptionMessage = "跃迁事件查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); return BaseResult.fail(exceptionMessage); } } }