TBasePlantController.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.ruoyi.project.base.controller;
  2. import java.util.Date;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.ruoyi.common.annotation.RepeatSubmit;
  6. import com.ruoyi.common.constant.UserConstants;
  7. import com.ruoyi.common.core.domain.entity.SysDept;
  8. import com.ruoyi.system.service.ISysDeptService;
  9. import org.springframework.security.access.prepost.PreAuthorize;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.PutMapping;
  14. import org.springframework.web.bind.annotation.DeleteMapping;
  15. import org.springframework.web.bind.annotation.PathVariable;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import com.ruoyi.common.annotation.Log;
  20. import com.ruoyi.common.core.controller.BaseController;
  21. import com.ruoyi.common.core.domain.AjaxResult;
  22. import com.ruoyi.common.enums.BusinessType;
  23. import com.ruoyi.project.base.domain.TBasePlant;
  24. import com.ruoyi.project.base.service.ITBasePlantService;
  25. import com.ruoyi.common.utils.poi.ExcelUtil;
  26. import com.ruoyi.common.core.page.TableDataInfo;
  27. /**
  28. * 装置Controller
  29. *
  30. * @author ruoyi
  31. * @date 2022-11-14
  32. */
  33. @RestController
  34. @RequestMapping("/base/plant")
  35. public class TBasePlantController extends BaseController
  36. {
  37. @Autowired
  38. private ITBasePlantService tBasePlantService;
  39. @Autowired
  40. private ISysDeptService deptService;
  41. /**
  42. * 查询装置列表
  43. */
  44. @PreAuthorize("@ss.hasPermi('base:plant:list')")
  45. @GetMapping("/list")
  46. public TableDataInfo list(TBasePlant tBasePlant)
  47. {
  48. startPage();
  49. List<TBasePlant> list = tBasePlantService.selectTBasePlantList(tBasePlant);
  50. return getDataTable(list);
  51. }
  52. @GetMapping("/allPlantName")
  53. public AjaxResult selectAllPlantName()
  54. {
  55. return AjaxResult.success(tBasePlantService.selectAllPlantName());
  56. }
  57. /**
  58. * 导出装置列表
  59. */
  60. @PreAuthorize("@ss.hasPermi('base:plant:export')")
  61. @Log(title = "装置导出", businessType = BusinessType.EXPORT)
  62. @RepeatSubmit
  63. @PostMapping("/export")
  64. public void export(HttpServletResponse response, TBasePlant tBasePlant)
  65. {
  66. List<TBasePlant> list = tBasePlantService.selectTBasePlantList(tBasePlant);
  67. ExcelUtil<TBasePlant> util = new ExcelUtil<TBasePlant>(TBasePlant.class);
  68. util.exportExcel(response, list, "装置数据");
  69. }
  70. /**
  71. * 获取装置详细信息
  72. */
  73. @PreAuthorize("@ss.hasPermi('base:plant:query')")
  74. @GetMapping(value = "/{id}")
  75. public AjaxResult getInfo(@PathVariable("id") Long id)
  76. {
  77. return AjaxResult.success(tBasePlantService.selectTBasePlantById(id));
  78. }
  79. /**
  80. * 新增装置
  81. */
  82. @PreAuthorize("@ss.hasPermi('base:plant:add')")
  83. @Log(title = "装置新增", businessType = BusinessType.INSERT)
  84. @RepeatSubmit
  85. @PostMapping
  86. public AjaxResult add(@RequestBody TBasePlant tBasePlant)
  87. {
  88. TBasePlant plant = tBasePlantService.selectTBasePlantByName(tBasePlant.getPlantName());
  89. if (plant != null){
  90. return AjaxResult.success("当前装置已存在!");
  91. }
  92. tBasePlant.setUpdatedate(new Date());
  93. tBasePlant.setUpdaterCode(getUserId());
  94. tBasePlant.setCreaterCode(getUserId());
  95. return toAjax(tBasePlantService.insertTBasePlant(tBasePlant));
  96. }
  97. /**
  98. * 修改装置
  99. */
  100. @PreAuthorize("@ss.hasPermi('base:plant:edit')")
  101. @Log(title = "装置修改", businessType = BusinessType.UPDATE)
  102. @RepeatSubmit
  103. @PutMapping
  104. public AjaxResult edit(@RequestBody TBasePlant tBasePlant)
  105. {
  106. tBasePlant.setUpdatedate(new Date());
  107. tBasePlant.setUpdaterCode(getUserId());
  108. return toAjax(tBasePlantService.updateTBasePlant(tBasePlant));
  109. }
  110. /**
  111. * 删除装置
  112. */
  113. @PreAuthorize("@ss.hasPermi('base:plant:remove')")
  114. @Log(title = "装置删除", businessType = BusinessType.DELETE)
  115. @DeleteMapping("/{ids}")
  116. public AjaxResult remove(@PathVariable Long[] ids)
  117. {
  118. return toAjax(tBasePlantService.deleteTBasePlantByIds(ids));
  119. }
  120. @PutMapping("/handleApprove")
  121. @Log(title = "装置审核", businessType = BusinessType.APPROVE)
  122. @RepeatSubmit
  123. public AjaxResult handleApprove(@RequestBody TBasePlant tBasePlant) {
  124. tBasePlant.setApproveTime(new Date());
  125. int i = tBasePlantService.updateTBasePlantByPlantIds(tBasePlant);
  126. if (i > 0 && tBasePlant.getApproveStatus() == 2) {
  127. for (Long plantId : tBasePlant.getPlantIds()) {
  128. TBasePlant plant = tBasePlantService.selectTBasePlantById(plantId);
  129. List<SysDept> sysDepts = deptService.selectDeptList(new SysDept());
  130. SysDept dept = new SysDept();
  131. dept.setDeptId(plantId);
  132. dept.setParentId(100L);
  133. dept.setDeptName(plant.getPlantName());
  134. dept.setOrderNum(sysDepts.size());
  135. dept.setStatus("0");
  136. if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
  137. logger.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
  138. continue;
  139. }
  140. dept.setCreateBy(getUsername());
  141. deptService.insertDept(dept);
  142. }
  143. }
  144. return AjaxResult.success();
  145. }
  146. }