TCheckLawsController.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.ruoyi.project.check.controller;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletResponse;
  6. import com.ruoyi.common.core.domain.entity.SysDictData;
  7. import com.ruoyi.common.utils.StringUtils;
  8. import com.ruoyi.project.check.domain.TCheckLawitems;
  9. import com.ruoyi.project.check.service.ITCheckLawitemsService;
  10. import com.ruoyi.system.service.ISysDictTypeService;
  11. import org.springframework.security.access.prepost.PreAuthorize;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.PostMapping;
  15. import org.springframework.web.bind.annotation.PutMapping;
  16. import org.springframework.web.bind.annotation.DeleteMapping;
  17. import org.springframework.web.bind.annotation.PathVariable;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import com.ruoyi.common.annotation.Log;
  22. import com.ruoyi.common.core.controller.BaseController;
  23. import com.ruoyi.common.core.domain.AjaxResult;
  24. import com.ruoyi.common.enums.BusinessType;
  25. import com.ruoyi.project.check.domain.TCheckLaws;
  26. import com.ruoyi.project.check.service.ITCheckLawsService;
  27. import com.ruoyi.common.utils.poi.ExcelUtil;
  28. import com.ruoyi.common.core.page.TableDataInfo;
  29. /**
  30. * 法规Controller
  31. *
  32. * @author ruoyi
  33. * @date 2022-11-28
  34. */
  35. @RestController
  36. @RequestMapping("/check/laws")
  37. public class TCheckLawsController extends BaseController {
  38. @Autowired
  39. private ITCheckLawsService tCheckLawsService;
  40. @Autowired
  41. private ISysDictTypeService isysDictTypeService;
  42. @Autowired
  43. private ITCheckLawitemsService tCheckLawitemsService;
  44. /**
  45. * 查询法规列表
  46. */
  47. @PreAuthorize("@ss.hasPermi('check:laws:list')")
  48. @GetMapping("/list")
  49. public TableDataInfo list(TCheckLaws tCheckLaws) {
  50. startPage();
  51. List<TCheckLaws> list = tCheckLawsService.selectTCheckLawsList(tCheckLaws);
  52. return getDataTable(list);
  53. }
  54. /**
  55. * 导出法规列表
  56. */
  57. @PreAuthorize("@ss.hasPermi('check:laws:export')")
  58. @Log(title = "法规", businessType = BusinessType.EXPORT)
  59. @PostMapping("/export")
  60. public void export(HttpServletResponse response, TCheckLaws tCheckLaws) {
  61. List<TCheckLaws> list = tCheckLawsService.selectTCheckLawsList(tCheckLaws);
  62. ExcelUtil<TCheckLaws> util = new ExcelUtil<TCheckLaws>(TCheckLaws.class);
  63. util.exportExcel(response, list, "法规数据");
  64. }
  65. /**
  66. * 获取法规详细信息
  67. */
  68. @PreAuthorize("@ss.hasPermi('check:laws:query')")
  69. @GetMapping(value = "/{id}")
  70. public AjaxResult getInfo(@PathVariable("id") Long id) {
  71. return AjaxResult.success(tCheckLawsService.selectTCheckLawsById(id));
  72. }
  73. /**
  74. * 新增法规
  75. */
  76. @PreAuthorize("@ss.hasPermi('check:laws:add')")
  77. @Log(title = "法规", businessType = BusinessType.INSERT)
  78. @PostMapping
  79. public AjaxResult add(@RequestBody TCheckLaws tCheckLaws) {
  80. tCheckLaws.setCreaterCode(getUserId());
  81. tCheckLaws.setUpdatedate(new Date());
  82. tCheckLaws.setUpdaterCode(getUserId());
  83. tCheckLawsService.insertTCheckLaws(tCheckLaws); // 新增法规表
  84. // 开始创建法规项内容
  85. List<SysDictData> pointTypes = isysDictTypeService.selectDictDataByType("point_type"); // 密封点类型
  86. List<SysDictData> plantTypes = isysDictTypeService.selectDictDataByType("plant_type"); // 装置类型
  87. List<SysDictData> mediumTypes = isysDictTypeService.selectDictDataByType("medium_type"); // 介质状态
  88. List<TCheckLawitems> tCheckLawitems = new ArrayList<>();
  89. for (SysDictData plantType : plantTypes) { // 遍历装置
  90. for (SysDictData pointType : pointTypes) { // 遍历密封点
  91. for (SysDictData mediumType : mediumTypes) { // 遍历介质状态
  92. // 根据装置类型、密封点类型、介质状态生成法规项
  93. TCheckLawitems tCheckLawitem = new TCheckLawitems();
  94. tCheckLawitem.setLawId(tCheckLaws.getId());
  95. tCheckLawitem.setPlantType(plantType.getDictValue());
  96. tCheckLawitem.setPointType(pointType.getDictValue());
  97. tCheckLawitem.setMediumType(mediumType.getDictValue());
  98. // TODO 频率、泄露标准、维修天数需确认
  99. tCheckLawitem.setDetectionFrequency("3");
  100. tCheckLawitem.setGeneral("50");
  101. tCheckLawitem.setSerious("200");
  102. tCheckLawitem.setStratFix("15");
  103. tCheckLawitem.setEndFix("15");
  104. tCheckLawitem.setCreaterCode(getUserId());
  105. tCheckLawitem.setCreatedate(new Date());
  106. tCheckLawitem.setUpdatedate(new Date());
  107. tCheckLawitem.setUpdaterCode(getUserId());
  108. tCheckLawitems.add(tCheckLawitem);
  109. }
  110. }
  111. }
  112. // 新增法规项表
  113. return toAjax(tCheckLawitemsService.insertTCheckLawitemsByList(tCheckLawitems));
  114. }
  115. /**
  116. * 修改法规
  117. */
  118. @PreAuthorize("@ss.hasPermi('check:laws:edit')")
  119. @Log(title = "法规", businessType = BusinessType.UPDATE)
  120. @PutMapping
  121. public AjaxResult edit(@RequestBody TCheckLaws tCheckLaws) {
  122. tCheckLaws.setUpdatedate(new Date());
  123. tCheckLaws.setUpdaterCode(getUserId());
  124. if (StringUtils.isNotEmpty(tCheckLaws.getStatus())) {
  125. tCheckLaws.setStarttime(new Date());
  126. }
  127. return toAjax(tCheckLawsService.updateTCheckLaws(tCheckLaws));
  128. }
  129. @PreAuthorize("@ss.hasPermi('check:laws:edit')")
  130. @Log(title = "法规匹配", businessType = BusinessType.UPDATE)
  131. @PutMapping("/matchLaws")
  132. public AjaxResult matchLaws(@RequestBody TCheckLaws tCheckLaws) {
  133. tCheckLaws.setStarttime(new Date());
  134. return toAjax(tCheckLawsService.updateTCheckLawsStatus(tCheckLaws));
  135. }
  136. /**
  137. * 删除法规
  138. */
  139. @PreAuthorize("@ss.hasPermi('check:laws:remove')")
  140. @Log(title = "法规", businessType = BusinessType.DELETE)
  141. @DeleteMapping("/{ids}")
  142. public AjaxResult remove(@PathVariable Long[] ids) {
  143. return toAjax(tCheckLawsService.deleteTCheckLawsByIds(ids));
  144. }
  145. }