TAuditController.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package com.ruoyi.web.controller.rc;
  2. import java.util.Date;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.ruoyi.common.core.domain.entity.SysDept;
  6. import com.ruoyi.common.core.domain.entity.SysUser;
  7. import com.ruoyi.common.core.domain.model.LoginUser;
  8. import com.ruoyi.common.utils.StringUtils;
  9. import com.ruoyi.rc.domain.*;
  10. import com.ruoyi.rc.service.*;
  11. import com.ruoyi.system.service.ISysDeptService;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.PutMapping;
  17. import org.springframework.web.bind.annotation.DeleteMapping;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import com.ruoyi.common.annotation.Log;
  23. import com.ruoyi.common.core.controller.BaseController;
  24. import com.ruoyi.common.core.domain.AjaxResult;
  25. import com.ruoyi.common.enums.BusinessType;
  26. import com.ruoyi.common.utils.poi.ExcelUtil;
  27. import com.ruoyi.common.core.page.TableDataInfo;
  28. /**
  29. * 审计记录Controller
  30. *
  31. * @author ruoyi
  32. * @date 2024-07-19
  33. */
  34. @RestController
  35. @RequestMapping("/rc/audit")
  36. public class TAuditController extends BaseController
  37. {
  38. @Autowired
  39. private ITAuditService tAuditService;
  40. @Autowired
  41. private ISysDeptService deptService;
  42. @Autowired
  43. private ITChapterService tChapterService;
  44. @Autowired
  45. private ITQuestionnaireService tQuestionnaireService;
  46. @Autowired
  47. private ITChapterTemplateService tChapterTemplateService;
  48. @Autowired
  49. private ITQuestionnaireTemplateService tQuestionnaireTemplateService;
  50. @Autowired
  51. private ITProgressService tProgressService;
  52. /**
  53. * 查询当前登录用户所在部门最近一次审计记录
  54. */
  55. @GetMapping("/current")
  56. public AjaxResult getCurrent() {
  57. TAudit audit = new TAudit();
  58. audit.setDeptId(getLoginUser().getDeptId().toString());
  59. TAudit latest = tAuditService.selectTAuditLatest(audit);
  60. return success(latest);
  61. }
  62. /**
  63. * 查询审计记录列表
  64. */
  65. @PreAuthorize("@ss.hasPermi('rc:audit:list')")
  66. @GetMapping("/list")
  67. public TableDataInfo list(TAudit tAudit)
  68. {
  69. startPage();
  70. List<TAudit> list = tAuditService.selectTAuditList(tAudit);
  71. for (TAudit obj : list) {
  72. String deptId = obj.getDeptId();
  73. if (StringUtils.isNotEmpty(deptId)) {
  74. if (deptId.indexOf(",") != -1) {
  75. StringBuffer sb = new StringBuffer();
  76. String[] ids = deptId.split(",");
  77. for (String id : ids) {
  78. SysDept sysDept = deptService.selectDeptById(Long.parseLong(id));
  79. sb.append(sysDept.getDeptName()).append(" / ");
  80. }
  81. obj.setDeptName(sb.toString().substring(0, sb.length() - 3));
  82. } else {
  83. obj.setDeptName(deptService.selectDeptById(Long.parseLong(deptId)).getDeptName());
  84. }
  85. }
  86. }
  87. return getDataTable(list);
  88. }
  89. /**
  90. * 导出审计记录列表
  91. */
  92. @PreAuthorize("@ss.hasPermi('rc:audit:export')")
  93. @Log(title = "审计记录", businessType = BusinessType.EXPORT)
  94. @PostMapping("/export")
  95. public void export(HttpServletResponse response, TAudit tAudit)
  96. {
  97. List<TAudit> list = tAuditService.selectTAuditList(tAudit);
  98. ExcelUtil<TAudit> util = new ExcelUtil<TAudit>(TAudit.class);
  99. util.exportExcel(response, list, "审计记录数据");
  100. }
  101. /**
  102. * 获取审计记录详细信息
  103. */
  104. @PreAuthorize("@ss.hasPermi('rc:audit:query')")
  105. @GetMapping(value = "/{id}")
  106. public AjaxResult getInfo(@PathVariable("id") Long id)
  107. {
  108. TAudit tAudit = tAuditService.selectTAuditById(id);
  109. String year = tAudit.getYear();
  110. if (year.length() > 4) {
  111. tAudit.setYear(year.substring(0, year.indexOf("-")));
  112. }
  113. return success(tAudit);
  114. }
  115. /**
  116. * 新增审计记录
  117. */
  118. @PreAuthorize("@ss.hasPermi('rc:audit:add')")
  119. @Log(title = "审计记录", businessType = BusinessType.INSERT)
  120. @PostMapping
  121. public AjaxResult add(@RequestBody TAudit tAudit)
  122. {
  123. if (StringUtils.isNull(tAudit.getDeptId()) || "".equals(tAudit.getDeptId())) {
  124. tAudit.setDeptId(getLoginUser().getDeptId().toString());
  125. }
  126. int result = tAuditService.insertTAudit(tAudit);
  127. // 章节list
  128. List<TChapterTemplate> tChapterTemplates = tChapterTemplateService.selectTChapterTemplateList(new TChapterTemplate());
  129. for (TChapterTemplate tChapterTemplate : tChapterTemplates) {
  130. // 新增章节
  131. TChapter chapter = new TChapter();
  132. chapter.setAuditId(tAudit.getId());
  133. chapter.setCode(tChapterTemplate.getCode());
  134. chapter.setName(tChapterTemplate.getName());
  135. chapter.setDeptId(tAudit.getDeptId());
  136. tChapterService.insertTChapter(chapter);
  137. TQuestionnaireTemplate questionnaireTemplate = new TQuestionnaireTemplate();
  138. questionnaireTemplate.setChapterId(tChapterTemplate.getId());
  139. // 每个章节对应的问卷list
  140. List<TQuestionnaireTemplate> tQuestionnaireTemplates = tQuestionnaireTemplateService.selectTQuestionnaireTemplateList(questionnaireTemplate);
  141. for (TQuestionnaireTemplate tQuestionnaireTemplate : tQuestionnaireTemplates) {
  142. // 新增问卷
  143. TQuestionnaire questionnaire = new TQuestionnaire();
  144. questionnaire.setAuditId(tAudit.getId());
  145. questionnaire.setChapterId(chapter.getId());
  146. questionnaire.setType(tQuestionnaireTemplate.getType());
  147. questionnaire.setDirectory(tQuestionnaireTemplate.getDirectory());
  148. questionnaire.setCode(tQuestionnaireTemplate.getCode());
  149. questionnaire.setName(tQuestionnaireTemplate.getName());
  150. questionnaire.setDeptId(tAudit.getDeptId());
  151. questionnaire.setCompletionStatus("2");
  152. tQuestionnaireService.insertTQuestionnaire(questionnaire);
  153. // 新增进度
  154. TProgress progress = new TProgress();
  155. progress.setAuditId(tAudit.getId());
  156. progress.setQuestionnaireId(questionnaire.getId());
  157. progress.setChapName(chapter.getName());
  158. progress.setCode(questionnaire.getCode()+"");
  159. progress.setName(questionnaire.getName());
  160. progress.setPreparation("1");
  161. progress.setApplyStatus("1");
  162. tProgressService.insertTProgress(progress);
  163. }
  164. }
  165. return toAjax(result);
  166. }
  167. /**
  168. * 修改审计记录
  169. */
  170. @PreAuthorize("@ss.hasPermi('rc:audit:edit')")
  171. @Log(title = "审计记录", businessType = BusinessType.UPDATE)
  172. @PutMapping
  173. public AjaxResult edit(@RequestBody TAudit tAudit)
  174. {
  175. return toAjax(tAuditService.updateTAudit(tAudit));
  176. }
  177. /**
  178. * 删除审计记录
  179. */
  180. @PreAuthorize("@ss.hasPermi('rc:audit:remove')")
  181. @Log(title = "审计记录", businessType = BusinessType.DELETE)
  182. @DeleteMapping("/{ids}")
  183. public AjaxResult remove(@PathVariable Long[] ids)
  184. {
  185. return toAjax(tAuditService.deleteTAuditByIds(ids));
  186. }
  187. }