TDeptInfoController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.ruoyi.web.controller.rc;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletResponse;
  4. import com.ruoyi.common.core.domain.entity.SysDept;
  5. import com.ruoyi.system.service.ISysDeptService;
  6. import org.springframework.security.access.prepost.PreAuthorize;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.PutMapping;
  11. import org.springframework.web.bind.annotation.DeleteMapping;
  12. import org.springframework.web.bind.annotation.PathVariable;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import com.ruoyi.common.annotation.Log;
  17. import com.ruoyi.common.core.controller.BaseController;
  18. import com.ruoyi.common.core.domain.AjaxResult;
  19. import com.ruoyi.common.enums.BusinessType;
  20. import com.ruoyi.rc.domain.TDeptInfo;
  21. import com.ruoyi.rc.service.ITDeptInfoService;
  22. import com.ruoyi.common.utils.poi.ExcelUtil;
  23. import com.ruoyi.common.core.page.TableDataInfo;
  24. import com.ruoyi.common.utils.StringUtils;
  25. /**
  26. * 装置信息Controller
  27. *
  28. * @author ruoyi
  29. * @date 2024-07-19
  30. */
  31. @RestController
  32. @RequestMapping("/rc/deptinfo")
  33. public class TDeptInfoController extends BaseController
  34. {
  35. @Autowired
  36. private ITDeptInfoService tDeptInfoService;
  37. @Autowired
  38. private ISysDeptService deptService;
  39. /**
  40. * 查询装置信息列表
  41. */
  42. @PreAuthorize("@ss.hasPermi('rc:deptinfo:list')")
  43. @GetMapping("/list")
  44. public TableDataInfo list(TDeptInfo tDeptInfo)
  45. {
  46. startPage();
  47. List<TDeptInfo> list = tDeptInfoService.selectTDeptInfoList(tDeptInfo);
  48. for (TDeptInfo obj : list) {
  49. String deptId = obj.getDeptId();
  50. if (StringUtils.isNotEmpty(deptId)) {
  51. if (deptId.indexOf(",") != -1) {
  52. StringBuffer sb = new StringBuffer();
  53. String[] ids = deptId.split(",");
  54. for (String id : ids) {
  55. SysDept sysDept = deptService.selectDeptById(Long.parseLong(id));
  56. sb.append(sysDept.getDeptName()).append(" / ");
  57. }
  58. obj.setDeptName(sb.toString().substring(0, sb.length() - 3));
  59. } else {
  60. obj.setDeptName(deptService.selectDeptById(Long.parseLong(deptId)).getDeptName());
  61. }
  62. }
  63. }
  64. return getDataTable(list);
  65. }
  66. /**
  67. * 导出装置信息列表
  68. */
  69. @PreAuthorize("@ss.hasPermi('rc:deptinfo:export')")
  70. @Log(title = "装置信息", businessType = BusinessType.EXPORT)
  71. @PostMapping("/export")
  72. public void export(HttpServletResponse response, TDeptInfo tDeptInfo)
  73. {
  74. List<TDeptInfo> list = tDeptInfoService.selectTDeptInfoList(tDeptInfo);
  75. ExcelUtil<TDeptInfo> util = new ExcelUtil<TDeptInfo>(TDeptInfo.class);
  76. util.exportExcel(response, list, "装置信息数据");
  77. }
  78. /**
  79. * 获取装置信息详细信息
  80. */
  81. @PreAuthorize("@ss.hasPermi('rc:deptinfo:query')")
  82. @GetMapping(value = "/{id}")
  83. public AjaxResult getInfo(@PathVariable("id") Long id)
  84. {
  85. TDeptInfo tDeptInfo = tDeptInfoService.selectTDeptInfoById(id);
  86. String year = tDeptInfo.getYear();
  87. if (year.length() > 4) {
  88. tDeptInfo.setYear(year.substring(0, year.indexOf("-")));
  89. }
  90. return success(tDeptInfo);
  91. }
  92. /**
  93. * 新增装置信息
  94. */
  95. @PreAuthorize("@ss.hasPermi('rc:deptinfo:add')")
  96. @Log(title = "装置信息", businessType = BusinessType.INSERT)
  97. @PostMapping
  98. public AjaxResult add(@RequestBody TDeptInfo tDeptInfo)
  99. {
  100. if (StringUtils.isNull(tDeptInfo.getDeptId()) || "".equals(tDeptInfo.getDeptId())) {
  101. tDeptInfo.setDeptId(getLoginUser().getDeptId().toString());
  102. }
  103. return toAjax(tDeptInfoService.insertTDeptInfo(tDeptInfo));
  104. }
  105. /**
  106. * 修改装置信息
  107. */
  108. @PreAuthorize("@ss.hasPermi('rc:deptinfo:edit')")
  109. @Log(title = "装置信息", businessType = BusinessType.UPDATE)
  110. @PutMapping
  111. public AjaxResult edit(@RequestBody TDeptInfo tDeptInfo)
  112. {
  113. return toAjax(tDeptInfoService.updateTDeptInfo(tDeptInfo));
  114. }
  115. /**
  116. * 删除装置信息
  117. */
  118. @PreAuthorize("@ss.hasPermi('rc:deptinfo:remove')")
  119. @Log(title = "装置信息", businessType = BusinessType.DELETE)
  120. @DeleteMapping("/{ids}")
  121. public AjaxResult remove(@PathVariable Long[] ids)
  122. {
  123. return toAjax(tDeptInfoService.deleteTDeptInfoByIds(ids));
  124. }
  125. }