TAuditController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. package com.ruoyi.web.controller.rc;
  2. import java.math.BigDecimal;
  3. import java.math.BigInteger;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.ruoyi.common.core.domain.entity.SysDept;
  11. import com.ruoyi.common.core.domain.entity.SysUser;
  12. import com.ruoyi.common.core.domain.model.LoginUser;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.rc.domain.*;
  15. import com.ruoyi.rc.mapper.TAuditMapper;
  16. import com.ruoyi.rc.service.*;
  17. import com.ruoyi.system.service.ISysDeptService;
  18. import org.springframework.security.access.prepost.PreAuthorize;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.web.bind.annotation.GetMapping;
  21. import org.springframework.web.bind.annotation.PostMapping;
  22. import org.springframework.web.bind.annotation.PutMapping;
  23. import org.springframework.web.bind.annotation.DeleteMapping;
  24. import org.springframework.web.bind.annotation.PathVariable;
  25. import org.springframework.web.bind.annotation.RequestBody;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.RestController;
  28. import com.ruoyi.common.annotation.Log;
  29. import com.ruoyi.common.core.controller.BaseController;
  30. import com.ruoyi.common.core.domain.AjaxResult;
  31. import com.ruoyi.common.enums.BusinessType;
  32. import com.ruoyi.common.utils.poi.ExcelUtil;
  33. import com.ruoyi.common.core.page.TableDataInfo;
  34. import sun.util.resources.cldr.es.CalendarData_es_AR;
  35. /**
  36. * 审计记录Controller
  37. *
  38. * @author ruoyi
  39. * @date 2024-07-19
  40. */
  41. @RestController
  42. @RequestMapping("/rc/audit")
  43. public class TAuditController extends BaseController
  44. {
  45. @Autowired
  46. private ITAuditService tAuditService;
  47. @Autowired
  48. private ISysDeptService deptService;
  49. @Autowired
  50. private ITChapterService tChapterService;
  51. @Autowired
  52. private ITQuestionnaireService tQuestionnaireService;
  53. @Autowired
  54. private ITChapterTemplateService tChapterTemplateService;
  55. @Autowired
  56. private ITQuestionnaireTemplateService tQuestionnaireTemplateService;
  57. @Autowired
  58. private ITProgressService tProgressService;
  59. @Autowired
  60. private ITOpenItemService itOpenItemService;
  61. @Autowired
  62. private TAuditMapper tAuditMapper;
  63. /**
  64. * 查询装置下次审计时间列表
  65. */
  66. @GetMapping("/getNextAuditTimeList")
  67. public AjaxResult getNextAuditTimeList() {
  68. HashMap<String, String> map = new HashMap<>();
  69. List<TAudit> tAudits = tAuditMapper.selectNextAuditTimeList();
  70. for (TAudit tAudit : tAudits) {
  71. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  72. map.put(tAudit.getDeptId(), sdf.format(tAudit.getAuditTime()));
  73. }
  74. return success(map);
  75. }
  76. /**
  77. * 查询装置上次审计时间列表
  78. */
  79. @GetMapping("/getLastAuditTimeList")
  80. public AjaxResult getLastAuditTimeList() {
  81. HashMap<String, String> map = new HashMap<>();
  82. List<TAudit> tAudits = tAuditMapper.selectLastAuditTimeList();
  83. for (TAudit tAudit : tAudits) {
  84. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  85. map.put(tAudit.getDeptId(), sdf.format(tAudit.getAuditTime()));
  86. }
  87. return success(map);
  88. }
  89. /**
  90. * 查询当前年份审计装置列表
  91. */
  92. @GetMapping("/getAuditDeptList")
  93. public AjaxResult getAuditDeptList() {
  94. TAudit audit = new TAudit();
  95. Calendar calendar = Calendar.getInstance();
  96. int i = calendar.get(Calendar.YEAR);
  97. audit.setYear(i+"");
  98. List<TAudit> tAudits = tAuditMapper.selectAllTAuditList(audit);
  99. return success(tAudits);
  100. }
  101. /**
  102. * 上级领导页面:查询首页顶部四个方框数据
  103. */
  104. @GetMapping("/homeData")
  105. public AjaxResult getHomeData() {
  106. HashMap map = new HashMap();
  107. // 当前登录用户所在部门最近一次审计记录
  108. TAudit audit = new TAudit();
  109. audit.setDeptId(getLoginUser().getDeptId().toString());
  110. TAudit latest = tAuditService.selectTAuditLatest(audit);
  111. if (latest != null) {
  112. Long auditId = latest.getId();
  113. int homeData1 = tAuditMapper.selectHomeData1();
  114. BigDecimal homeData2 = tAuditMapper.selectHomeData2();
  115. int homeData3 = tAuditMapper.selectHomeData3(auditId);
  116. int homeData4 = tAuditMapper.selectHomeData4(auditId);
  117. map.put("homeData1", homeData1);
  118. map.put("homeData2", homeData2);
  119. map.put("homeData3", homeData3);
  120. map.put("homeData4", homeData4);
  121. return AjaxResult.success(map);
  122. } else {
  123. return AjaxResult.success();
  124. }
  125. }
  126. /**
  127. * 普通员工页面:查询首页柱状图数据
  128. */
  129. @GetMapping("/bar")
  130. public AjaxResult getBar() {
  131. TAudit audit = new TAudit();
  132. audit.setDeptId(getLoginUser().getDeptId().toString());
  133. TAudit latest = tAuditService.selectTAuditLatest(audit);
  134. HashMap<String, String> map = new HashMap<String, String>();
  135. if(latest != null) {
  136. int code0Count = 0;
  137. int code1Count = 0;
  138. int code2Count = 0;
  139. int code3Count = 0;
  140. int code4Count = 0;
  141. int code5Count = 0;
  142. int code6Count = 0;
  143. int code7Count = 0;
  144. int code8Count = 0;
  145. int code9Count = 0;
  146. int code0CompleteCount = 0;
  147. int code1CompleteCount = 0;
  148. int code2CompleteCount = 0;
  149. int code3CompleteCount = 0;
  150. int code4CompleteCount = 0;
  151. int code5CompleteCount = 0;
  152. int code6CompleteCount = 0;
  153. int code7CompleteCount = 0;
  154. int code8CompleteCount = 0;
  155. int code9CompleteCount = 0;
  156. BigDecimal code0CompleteProgress = new BigDecimal(BigInteger.ZERO);
  157. BigDecimal code1CompleteProgress = new BigDecimal(BigInteger.ZERO);
  158. BigDecimal code2CompleteProgress = new BigDecimal(BigInteger.ZERO);
  159. BigDecimal code3CompleteProgress = new BigDecimal(BigInteger.ZERO);
  160. BigDecimal code4CompleteProgress = new BigDecimal(BigInteger.ZERO);
  161. BigDecimal code5CompleteProgress = new BigDecimal(BigInteger.ZERO);
  162. BigDecimal code6CompleteProgress = new BigDecimal(BigInteger.ZERO);
  163. BigDecimal code7CompleteProgress = new BigDecimal(BigInteger.ZERO);
  164. BigDecimal code8CompleteProgress = new BigDecimal(BigInteger.ZERO);
  165. BigDecimal code9CompleteProgress = new BigDecimal(BigInteger.ZERO);
  166. Long auditId = latest.getId();
  167. TChapter chapter = new TChapter();
  168. chapter.setAuditId(auditId);
  169. List<TChapter> tChapters = tChapterService.selectTChapterList(chapter);
  170. for (TChapter tChapter : tChapters) {
  171. String code = tChapter.getCode();
  172. int index = code.indexOf(".");
  173. if (index != -1) {
  174. code = code.substring(0, index);
  175. TQuestionnaire questionnaire = new TQuestionnaire();
  176. questionnaire.setChapterId(tChapter.getId());
  177. List<TQuestionnaire> tQuestionnaires = tQuestionnaireService.selectTQuestionnaireList(questionnaire);
  178. for (TQuestionnaire tQuestionnaire : tQuestionnaires) {
  179. boolean flag = "1".equals(tQuestionnaire.getCompletionStatus());
  180. switch (code) {
  181. case "0": code0Count++; if (flag) {code0CompleteCount++;} break;
  182. case "1": code1Count++; if (flag) {code1CompleteCount++;} break;
  183. case "2": code2Count++; if (flag) {code2CompleteCount++;} break;
  184. case "3": code3Count++; if (flag) {code3CompleteCount++;} break;
  185. case "5": code4Count++; if (flag) {code4CompleteCount++;} break;
  186. case "6": code5Count++; if (flag) {code5CompleteCount++;} break;
  187. case "7": code6Count++; if (flag) {code6CompleteCount++;} break;
  188. case "8": code7Count++; if (flag) {code7CompleteCount++;} break;
  189. case "9": code8Count++; if (flag) {code8CompleteCount++;} break;
  190. case "10": code9Count++; if (flag) {code9CompleteCount++;} break;
  191. }
  192. }
  193. }
  194. }
  195. if (code0Count != 0) {code0CompleteProgress = new BigDecimal(code0CompleteCount).divide(new BigDecimal(code0Count), 4, BigDecimal.ROUND_HALF_UP);}
  196. if (code1Count != 0) {code1CompleteProgress = new BigDecimal(code1CompleteCount).divide(new BigDecimal(code1Count), 4, BigDecimal.ROUND_HALF_UP);}
  197. if (code2Count != 0) {code2CompleteProgress = new BigDecimal(code2CompleteCount).divide(new BigDecimal(code2Count), 4, BigDecimal.ROUND_HALF_UP);}
  198. if (code3Count != 0) {code3CompleteProgress = new BigDecimal(code3CompleteCount).divide(new BigDecimal(code3Count), 4, BigDecimal.ROUND_HALF_UP);}
  199. if (code4Count != 0) {code4CompleteProgress = new BigDecimal(code4CompleteCount).divide(new BigDecimal(code4Count), 4, BigDecimal.ROUND_HALF_UP);}
  200. if (code5Count != 0) {code5CompleteProgress = new BigDecimal(code5CompleteCount).divide(new BigDecimal(code5Count), 4, BigDecimal.ROUND_HALF_UP);}
  201. if (code6Count != 0) {code6CompleteProgress = new BigDecimal(code6CompleteCount).divide(new BigDecimal(code6Count), 4, BigDecimal.ROUND_HALF_UP);}
  202. if (code7Count != 0) {code7CompleteProgress = new BigDecimal(code7CompleteCount).divide(new BigDecimal(code7Count), 4, BigDecimal.ROUND_HALF_UP);}
  203. if (code8Count != 0) {code8CompleteProgress = new BigDecimal(code8CompleteCount).divide(new BigDecimal(code8Count), 4, BigDecimal.ROUND_HALF_UP);}
  204. if (code9Count != 0) {code9CompleteProgress = new BigDecimal(code9CompleteCount).divide(new BigDecimal(code9Count), 4, BigDecimal.ROUND_HALF_UP);}
  205. map.put("code0", code0CompleteProgress.toString());
  206. map.put("code1", code1CompleteProgress.toString());
  207. map.put("code2", code2CompleteProgress.toString());
  208. map.put("code3", code3CompleteProgress.toString());
  209. map.put("code5", code4CompleteProgress.toString());
  210. map.put("code6", code5CompleteProgress.toString());
  211. map.put("code7", code6CompleteProgress.toString());
  212. map.put("code8", code7CompleteProgress.toString());
  213. map.put("code9", code8CompleteProgress.toString());
  214. map.put("code10", code9CompleteProgress.toString());
  215. map.put("auditId", latest.getId().toString());
  216. } else {
  217. map.put("code0", "0");
  218. map.put("code1", "0");
  219. map.put("code2", "0");
  220. map.put("code3", "0");
  221. map.put("code5", "0");
  222. map.put("code6", "0");
  223. map.put("code7", "0");
  224. map.put("code8", "0");
  225. map.put("code9", "0");
  226. map.put("code10", "0");
  227. }
  228. return success(map);
  229. }
  230. /**
  231. * 普通员工页面:查询首页饼图数据
  232. */
  233. @GetMapping("/pie")
  234. public AjaxResult getPie() {
  235. // int count = 0;
  236. // int completeCount = 0;
  237. // BigDecimal progress = new BigDecimal(BigInteger.ZERO);
  238. // TAudit audit = new TAudit();
  239. // audit.setDeptId(getLoginUser().getDeptId().toString());
  240. // TAudit latest = tAuditService.selectTAuditLatest(audit);
  241. // if (latest != null) {
  242. // Long auditId = latest.getId();
  243. // TChapter chapter = new TChapter();
  244. // chapter.setAuditId(auditId);
  245. // List<TChapter> tChapters = tChapterService.selectTChapterList(chapter);
  246. // for (TChapter tChapter : tChapters) {
  247. // TQuestionnaire questionnaire = new TQuestionnaire();
  248. // questionnaire.setChapterId(tChapter.getId());
  249. // List<TQuestionnaire> tQuestionnaires = tQuestionnaireService.selectTQuestionnaireList(questionnaire);
  250. // for (TQuestionnaire tQuestionnaire : tQuestionnaires) {
  251. // TOpenItem openItem = new TOpenItem();
  252. // openItem.setQuestionnaireId(tQuestionnaire.getId());
  253. // List<TOpenItem> tOpenItems = itOpenItemService.selectTOpenItemList(openItem);
  254. // for (TOpenItem tOpenItem : tOpenItems) {
  255. // count++;
  256. // String status = tOpenItem.getStatus();
  257. // if ("4".equals(status)) {
  258. // completeCount++;
  259. // }
  260. // }
  261. // }
  262. // }
  263. // if (count != 0) {
  264. // progress = new BigDecimal(completeCount).divide(new BigDecimal(count), 4, BigDecimal.ROUND_HALF_UP);
  265. // }
  266. //
  267. // }
  268. TAudit audit = new TAudit();
  269. audit.setDeptId(getLoginUser().getDeptId().toString());
  270. TAudit latest = tAuditService.selectTAuditLatest(audit);
  271. Double result = new Double("0");
  272. if (latest != null) {
  273. result = tAuditMapper.selectHomeDataPie(latest.getId());
  274. }
  275. return success(result);
  276. }
  277. /**
  278. * 查询当前登录用户所在部门最近一次审计记录
  279. */
  280. @GetMapping("/current")
  281. public AjaxResult getCurrent() {
  282. TAudit audit = new TAudit();
  283. audit.setDeptId(getLoginUser().getDeptId().toString());
  284. TAudit latest = tAuditService.selectTAuditLatest(audit);
  285. return success(latest);
  286. }
  287. /**
  288. * 查询审计记录列表
  289. */
  290. @PreAuthorize("@ss.hasPermi('rc:audit:list')")
  291. @GetMapping("/list")
  292. public TableDataInfo list(TAudit tAudit)
  293. {
  294. startPage();
  295. List<TAudit> list = tAuditService.selectTAuditList(tAudit);
  296. for (TAudit obj : list) {
  297. String deptId = obj.getDeptId();
  298. if (StringUtils.isNotEmpty(deptId)) {
  299. if (deptId.indexOf(",") != -1) {
  300. StringBuffer sb = new StringBuffer();
  301. String[] ids = deptId.split(",");
  302. for (String id : ids) {
  303. SysDept sysDept = deptService.selectDeptById(Long.parseLong(id));
  304. sb.append(sysDept.getDeptName()).append(" / ");
  305. }
  306. obj.setDeptName(sb.toString().substring(0, sb.length() - 3));
  307. } else {
  308. obj.setDeptName(deptService.selectDeptById(Long.parseLong(deptId)).getDeptName());
  309. }
  310. }
  311. }
  312. return getDataTable(list);
  313. }
  314. /**
  315. * 导出审计记录列表
  316. */
  317. @PreAuthorize("@ss.hasPermi('rc:audit:export')")
  318. @Log(title = "审计记录", businessType = BusinessType.EXPORT)
  319. @PostMapping("/export")
  320. public void export(HttpServletResponse response, TAudit tAudit)
  321. {
  322. List<TAudit> list = tAuditService.selectTAuditList(tAudit);
  323. ExcelUtil<TAudit> util = new ExcelUtil<TAudit>(TAudit.class);
  324. util.exportExcel(response, list, "审计记录数据");
  325. }
  326. /**
  327. * 获取审计记录详细信息
  328. */
  329. @PreAuthorize("@ss.hasPermi('rc:audit:query')")
  330. @GetMapping(value = "/{id}")
  331. public AjaxResult getInfo(@PathVariable("id") Long id)
  332. {
  333. TAudit tAudit = tAuditService.selectTAuditById(id);
  334. String year = tAudit.getYear();
  335. if (year.length() > 4) {
  336. tAudit.setYear(year.substring(0, year.indexOf("-")));
  337. }
  338. return success(tAudit);
  339. }
  340. /**
  341. * 新增审计记录
  342. */
  343. @PreAuthorize("@ss.hasPermi('rc:audit:add')")
  344. @Log(title = "审计记录", businessType = BusinessType.INSERT)
  345. @PostMapping
  346. public AjaxResult add(@RequestBody TAudit tAudit)
  347. {
  348. if (StringUtils.isNull(tAudit.getDeptId()) || "".equals(tAudit.getDeptId())) {
  349. tAudit.setDeptId(getLoginUser().getDeptId().toString());
  350. }
  351. int result = tAuditService.insertTAudit(tAudit);
  352. // 章节list
  353. List<TChapterTemplate> tChapterTemplates = tChapterTemplateService.selectTChapterTemplateList(new TChapterTemplate());
  354. for (TChapterTemplate tChapterTemplate : tChapterTemplates) {
  355. // 新增章节
  356. TChapter chapter = new TChapter();
  357. chapter.setAuditId(tAudit.getId());
  358. chapter.setCode(tChapterTemplate.getCode());
  359. chapter.setName(tChapterTemplate.getName());
  360. chapter.setDeptId(tAudit.getDeptId());
  361. tChapterService.insertTChapter(chapter);
  362. TQuestionnaireTemplate questionnaireTemplate = new TQuestionnaireTemplate();
  363. questionnaireTemplate.setChapterId(tChapterTemplate.getId());
  364. // 每个章节对应的问卷list
  365. List<TQuestionnaireTemplate> tQuestionnaireTemplates = tQuestionnaireTemplateService.selectTQuestionnaireTemplateList(questionnaireTemplate);
  366. for (TQuestionnaireTemplate tQuestionnaireTemplate : tQuestionnaireTemplates) {
  367. // 新增问卷
  368. TQuestionnaire questionnaire = new TQuestionnaire();
  369. questionnaire.setAuditId(tAudit.getId());
  370. questionnaire.setChapterId(chapter.getId());
  371. questionnaire.setType(tQuestionnaireTemplate.getType());
  372. questionnaire.setDirectory(tQuestionnaireTemplate.getDirectory());
  373. questionnaire.setCode(tQuestionnaireTemplate.getCode());
  374. questionnaire.setName(tQuestionnaireTemplate.getName());
  375. questionnaire.setDeptId(tAudit.getDeptId());
  376. questionnaire.setCompletionStatus("2");
  377. questionnaire.setYear(tAudit.getYear());
  378. tQuestionnaireService.insertTQuestionnaire(questionnaire);
  379. // 新增进度
  380. TProgress progress = new TProgress();
  381. progress.setAuditId(tAudit.getId());
  382. progress.setQuestionnaireId(questionnaire.getId());
  383. progress.setCode(questionnaire.getCode()+"");
  384. progress.setName(questionnaire.getName());
  385. progress.setPreparation("1");
  386. progress.setApplyStatus("1");
  387. String name = chapter.getName();
  388. String code = chapter.getCode();
  389. if (StringUtils.isNotNull(code) && StringUtils.isNotNull(name)) {
  390. int dotNum = this.getDotNum(code);
  391. if (dotNum == 0) {//章节
  392. progress.setSecSubChapName("-");
  393. progress.setSubChapName("-");
  394. progress.setChapName(code + " " + name);
  395. } else if (dotNum == 1) {//细分章节
  396. progress.setSecSubChapName("-");
  397. progress.setSubChapName(code + " " + name);
  398. String chapCode = code.substring(0, code.indexOf("."));
  399. progress.setChapName(chapCode + " " + tChapterTemplateService.selectNameByCode(chapCode));
  400. } else {//二级细分章节
  401. progress.setSecSubChapName(code + " " + name);
  402. String subChapCode = code.substring(0, code.lastIndexOf("."));
  403. progress.setSubChapName(subChapCode + " " + tChapterTemplateService.selectNameByCode(subChapCode));
  404. String chapCode = subChapCode.substring(0, subChapCode.indexOf("."));
  405. progress.setChapName(chapCode + " " + tChapterTemplateService.selectNameByCode(chapCode));
  406. }
  407. }
  408. tProgressService.insertTProgress(progress);
  409. }
  410. }
  411. return toAjax(result);
  412. }
  413. public int getDotNum(String code) {
  414. int num = 0;
  415. int i = code.indexOf(".");
  416. if (i != -1) {
  417. String[] split = code.split("\\.");
  418. num = split.length - 1;
  419. }
  420. return num;
  421. }
  422. /**
  423. * 修改审计记录
  424. */
  425. @PreAuthorize("@ss.hasPermi('rc:audit:edit')")
  426. @Log(title = "审计记录", businessType = BusinessType.UPDATE)
  427. @PutMapping
  428. public AjaxResult edit(@RequestBody TAudit tAudit)
  429. {
  430. return toAjax(tAuditService.updateTAudit(tAudit));
  431. }
  432. /**
  433. * 删除审计记录
  434. */
  435. @PreAuthorize("@ss.hasPermi('rc:audit:remove')")
  436. @Log(title = "审计记录", businessType = BusinessType.DELETE)
  437. @DeleteMapping("/{ids}")
  438. public AjaxResult remove(@PathVariable Long[] ids)
  439. {
  440. return toAjax(tAuditService.deleteTAuditByIds(ids));
  441. }
  442. }