| | |
| | | package com.vci.web.controller; |
| | | |
| | | import com.vci.constant.FrameWorkLangCodeConstant; |
| | | import com.vci.dto.OsRevisionRuleDTO; |
| | | import com.vci.pagemodel.OsRevisionRuleVO; |
| | | 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.BaseResult; |
| | | 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.OsRevisionRuleServiceI; |
| | | 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; |
| | | |
| | | /** |
| | | * 版本规则控制器 |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping("/getVersionRuleAllList") |
| | | @VciUnCheckRight |
| | | public BaseResult getVersionRuleAllList(){ |
| | | try { |
| | | return BaseResult.dataList(revisionRuleServiceI.selectAllRevision()); |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping("/getUsedVersionRuleList") |
| | | @VciUnCheckRight |
| | | public BaseResult getUsedVersionRuleList(String vrName){ |
| | | try { |
| | | return BaseResult.dataList(revisionRuleServiceI.getUsedVersionRuleList(vrName)); |
| | |
| | | * @return |
| | | */ |
| | | @PostMapping("/addVersionRule") |
| | | @VciUnCheckRight |
| | | public BaseResult addVersionRule(@RequestBody OsRevisionRuleDTO osRevisionRuleDTO){ |
| | | try { |
| | | return revisionRuleServiceI.addVersionRule(osRevisionRuleDTO) ? BaseResult.success("版本规则添加成功!"):BaseResult.fail("版本规则添加失败!"); |
| | |
| | | * @param osRevisionRuleDTO 版本规则数据传输对象 |
| | | * @return |
| | | */ |
| | | @PostMapping("/updateVersionRule") |
| | | @VciUnCheckRight |
| | | @PutMapping("/updateVersionRule") |
| | | public BaseResult updateVersionRule(@RequestBody OsRevisionRuleDTO osRevisionRuleDTO){ |
| | | try { |
| | | return revisionRuleServiceI.updateVersionRule(osRevisionRuleDTO) ? BaseResult.success("版本规则添加成功!"):BaseResult.fail("版本规则添加失败!"); |
| | | return revisionRuleServiceI.updateVersionRule(osRevisionRuleDTO) ? 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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除版本规则 |
| | | * @param osRevisionRuleDTOS 版本规则数据传输对象 |
| | | * @return |
| | | */ |
| | | @DeleteMapping("/deleteVersionRule") |
| | | public BaseResult deleteVersionRule(@RequestBody List<OsRevisionRuleDTO> osRevisionRuleDTOS){ |
| | | try { |
| | | return revisionRuleServiceI.deleteVersionRule(osRevisionRuleDTOS) ? BaseResult.success("版本规则删除成功!"):BaseResult.fail("版本规则删除失败!"); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "删除版本规则时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导出选中的版本规则 |
| | | * @param exportFileName 导出的文件名 |
| | | * @param vrNames 需要导出的规则英文名称 |
| | | * @param response |
| | | */ |
| | | @GetMapping( "/exportVersionRule") |
| | | @VciBusinessLog(operateName = "导出版本规则") |
| | | public void exportVersionRule(String exportFileName,String vrNames, HttpServletResponse response){ |
| | | try { |
| | | String excelPath = revisionRuleServiceI.exportVersionRule(exportFileName,vrNames,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( "/downloadAttributeTemplate") |
| | | @VciBusinessLog(operateName = "下载版本规则导入模板") |
| | | public void downloadVersionRuleTemplate(String exportFileName, HttpServletResponse response){ |
| | | try { |
| | | String excelPath = revisionRuleServiceI.downloadVersionRuleTemplate(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("/importVersionRules") |
| | | @VciBusinessLog(operateName = "导入版本规则") |
| | | public BaseResult importVersionRules(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 revisionRuleServiceI.importVersionRules(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(); |
| | | } |
| | | } |
| | | |
| | | } |