TLeakagePointsPatrolController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.ruoyi.project.asset.controller;
  2. import com.ruoyi.common.annotation.Log;
  3. import com.ruoyi.common.core.controller.BaseController;
  4. import com.ruoyi.common.core.domain.AjaxResult;
  5. import com.ruoyi.common.core.page.TableDataInfo;
  6. import com.ruoyi.common.enums.BusinessType;
  7. import com.ruoyi.common.utils.poi.ExcelUtil;
  8. import com.ruoyi.project.asset.domain.TLeakagePoints;
  9. import com.ruoyi.project.asset.domain.TLeakagePointsPatrol;
  10. import com.ruoyi.project.asset.domain.TLeakagePointsRecord;
  11. import com.ruoyi.project.asset.service.ITLeakagePointsPatrolService;
  12. import com.ruoyi.project.asset.service.ITLeakagePointsRecordService;
  13. import com.ruoyi.project.asset.service.ITLeakagePointsService;
  14. import org.apache.commons.collections4.CollectionUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.security.access.prepost.PreAuthorize;
  17. import org.springframework.web.bind.annotation.*;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.Date;
  20. import java.util.List;
  21. /**
  22. * 漏点巡检Controller
  23. *
  24. * @author ruoyi
  25. * @date 2024-04-01
  26. */
  27. @RestController
  28. @RequestMapping("/asset/pointPatrol")
  29. public class TLeakagePointsPatrolController extends BaseController {
  30. @Autowired
  31. private ITLeakagePointsPatrolService tLeakagePointsPatrolService;
  32. @Autowired
  33. private ITLeakagePointsRecordService tLeakagePointsRecordService;
  34. @Autowired
  35. private ITLeakagePointsService tLeakagePointsService;
  36. /**
  37. * 查询漏点巡检列表
  38. */
  39. @PreAuthorize("@ss.hasPermi('asset:pointPatrol:list')")
  40. @GetMapping("/list")
  41. public TableDataInfo list(TLeakagePointsPatrol tLeakagePointsPatrol) {
  42. startPage();
  43. if (tLeakagePointsPatrol.getCheckDateM() == null) {
  44. tLeakagePointsPatrol.setCheckDateM(new Date());
  45. }
  46. List<TLeakagePointsPatrol> list = tLeakagePointsPatrolService.selectTLeakagePointsPatrolList(tLeakagePointsPatrol);
  47. if (CollectionUtils.isNotEmpty(list)) {
  48. TLeakagePointsRecord record = new TLeakagePointsRecord();
  49. record.setPatrolId(list.get(0).getId());
  50. list.get(0).setRecords(tLeakagePointsRecordService.selectTLeakagePointsRecordList(record));
  51. }
  52. return getDataTable(list);
  53. }
  54. /**
  55. * 导出漏点巡检列表
  56. */
  57. @PreAuthorize("@ss.hasPermi('asset:pointPatrol:export')")
  58. @Log(title = "漏点巡检", businessType = BusinessType.EXPORT)
  59. @PostMapping("/export")
  60. public void export(HttpServletResponse response, TLeakagePointsPatrol tLeakagePointsPatrol) {
  61. List<TLeakagePointsPatrol> list = tLeakagePointsPatrolService.selectTLeakagePointsPatrolList(tLeakagePointsPatrol);
  62. ExcelUtil<TLeakagePointsPatrol> util = new ExcelUtil<TLeakagePointsPatrol>(TLeakagePointsPatrol.class);
  63. util.exportExcel(response, list, "漏点巡检数据");
  64. }
  65. /**
  66. * 获取漏点巡检详细信息
  67. */
  68. @PreAuthorize("@ss.hasPermi('asset:pointPatrol:query')")
  69. @GetMapping(value = "/{id}")
  70. public AjaxResult getInfo(@PathVariable("id") Long id) {
  71. return success(tLeakagePointsPatrolService.selectTLeakagePointsPatrolById(id));
  72. }
  73. /**
  74. * 新增漏点巡检
  75. */
  76. @PreAuthorize("@ss.hasPermi('asset:pointPatrol:add')")
  77. @Log(title = "漏点巡检", businessType = BusinessType.INSERT)
  78. @PostMapping
  79. public AjaxResult add(@RequestBody TLeakagePointsPatrol tLeakagePointsPatrol) {
  80. tLeakagePointsPatrol.setCheckDateN(tLeakagePointsPatrol.getCheckDateM());
  81. TLeakagePointsPatrol patrol = new TLeakagePointsPatrol();
  82. patrol.setCheckDateM(tLeakagePointsPatrol.getCheckDateM());
  83. List<TLeakagePointsPatrol> list = tLeakagePointsPatrolService.selectTLeakagePointsPatrolList(patrol);
  84. if (CollectionUtils.isNotEmpty(list)) {
  85. return AjaxResult.warn("当前日期已存在巡检记录!");
  86. }
  87. tLeakagePointsPatrolService.insertTLeakagePointsPatrol(tLeakagePointsPatrol);
  88. TLeakagePoints tLeakagePoints = new TLeakagePoints();
  89. tLeakagePoints.setLeakageEliminationResult("1,2");
  90. for (TLeakagePoints leakagePoints : tLeakagePointsService.selectTLeakagePointsList(tLeakagePoints)) {
  91. TLeakagePointsRecord record = new TLeakagePointsRecord();
  92. record.setPatrolId(tLeakagePointsPatrol.getId());
  93. record.setPointNo(leakagePoints.getPointNo());
  94. record.setLeakagePosition(leakagePoints.getLeakagePosition());
  95. record.setLeakageMedium(leakagePoints.getLeakageMedium());
  96. record.setCreatedate(new Date());
  97. record.setCreaterCode(getUserId().toString());
  98. tLeakagePointsRecordService.insertTLeakagePointsRecord(record);
  99. }
  100. return toAjax(1);
  101. }
  102. /**
  103. * 修改漏点巡检
  104. */
  105. @PreAuthorize("@ss.hasPermi('asset:pointPatrol:edit')")
  106. @Log(title = "漏点巡检", businessType = BusinessType.UPDATE)
  107. @PutMapping
  108. public AjaxResult edit(@RequestBody TLeakagePointsPatrol tLeakagePointsPatrol) {
  109. if (CollectionUtils.isNotEmpty(tLeakagePointsPatrol.getRecords())) {
  110. tLeakagePointsPatrol.getRecords().forEach(item -> {
  111. item.setUpdatedate(new Date());
  112. item.setUpdaterCode(getUserId().toString());
  113. tLeakagePointsRecordService.updateTLeakagePointsRecord(item);
  114. });
  115. }
  116. return toAjax(tLeakagePointsPatrolService.updateTLeakagePointsPatrol(tLeakagePointsPatrol));
  117. }
  118. /**
  119. * 删除漏点巡检
  120. */
  121. @PreAuthorize("@ss.hasPermi('asset:pointPatrol:remove')")
  122. @Log(title = "漏点巡检", businessType = BusinessType.DELETE)
  123. @DeleteMapping("/{ids}")
  124. public AjaxResult remove(@PathVariable Long[] ids) {
  125. return toAjax(tLeakagePointsPatrolService.deleteTLeakagePointsPatrolByIds(ids));
  126. }
  127. }