TPssrPublicController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. package com.ruoyi.project.pssr.controller;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.util.*;
  7. import com.ruoyi.common.utils.DateUtils;
  8. import com.ruoyi.common.utils.file.ExcelUtils;
  9. import com.ruoyi.project.pssr.domain.TPssrApprove;
  10. import com.ruoyi.project.pssr.domain.TPssrPublic;
  11. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  12. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  13. import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
  14. import com.ruoyi.project.system.domain.SysUser;
  15. import com.ruoyi.project.system.service.ISysUserService;
  16. import org.activiti.engine.ProcessEngine;
  17. import org.activiti.engine.ProcessEngines;
  18. import org.activiti.engine.TaskService;
  19. import org.activiti.engine.task.Task;
  20. import org.apache.poi.ss.usermodel.Cell;
  21. import org.apache.poi.ss.usermodel.CellStyle;
  22. import org.apache.poi.ss.usermodel.Row;
  23. import org.apache.poi.xssf.usermodel.XSSFSheet;
  24. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  25. import org.springframework.security.access.prepost.PreAuthorize;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.GetMapping;
  28. import org.springframework.web.bind.annotation.PostMapping;
  29. import org.springframework.web.bind.annotation.PutMapping;
  30. import org.springframework.web.bind.annotation.DeleteMapping;
  31. import org.springframework.web.bind.annotation.PathVariable;
  32. import org.springframework.web.bind.annotation.RequestBody;
  33. import org.springframework.web.bind.annotation.RequestMapping;
  34. import org.springframework.web.bind.annotation.RestController;
  35. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  36. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  37. import com.ruoyi.project.pssr.domain.TPssrPublic;
  38. import com.ruoyi.project.pssr.service.ITPssrPublicService;
  39. import com.ruoyi.framework.web.controller.BaseController;
  40. import com.ruoyi.framework.web.domain.AjaxResult;
  41. import com.ruoyi.common.utils.poi.ExcelUtil;
  42. import com.ruoyi.framework.web.page.TableDataInfo;
  43. /**
  44. * 公用工程Controller
  45. *
  46. * @author ssy
  47. * @date 2024-09-18
  48. */
  49. @RestController
  50. @RequestMapping("/pssr/public")
  51. public class TPssrPublicController extends BaseController
  52. {
  53. @Autowired
  54. private ITPssrPublicService tPssrPublicService;
  55. @Autowired
  56. private ITPssrApproveService tPssrApproveService;
  57. @Autowired
  58. private ITPssrSubcontentService tPssrSubcontentService;
  59. @Autowired
  60. private ISysUserService sysUserService;
  61. /**
  62. * 查询公用工程列表
  63. */
  64. @PreAuthorize("@ss.hasPermi('pssr:public:list')")
  65. @GetMapping("/list")
  66. public TableDataInfo list(TPssrPublic tPssrPublic)
  67. {
  68. startPage();
  69. List<TPssrPublic> list = tPssrPublicService.selectTPssrPublicList(tPssrPublic);
  70. return getDataTable(list);
  71. }
  72. /**
  73. * 导出公用工程列表
  74. */
  75. @PreAuthorize("@ss.hasPermi('pssr:public:export')")
  76. @Log(title = "公用工程", businessType = BusinessType.EXPORT)
  77. @GetMapping("/export")
  78. public AjaxResult export(TPssrPublic tPssrPublic)
  79. {
  80. List<TPssrPublic> list = tPssrPublicService.selectTPssrPublicList(tPssrPublic);
  81. return AjaxResult.success(exportTmpl(list));
  82. }
  83. public String exportTmpl(List<TPssrPublic> list) {
  84. OutputStream out = null;
  85. String filename = null;
  86. try {
  87. String tempUrl = "static/word/pssr/gygc.xlsx"; // 模板文件
  88. InputStream is = null;
  89. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  90. XSSFWorkbook wb = null;
  91. wb = new XSSFWorkbook(is);
  92. XSSFSheet sheet = wb.getSheetAt(0);
  93. //填充数据
  94. int rowIndex = 3;
  95. int num = 1;
  96. Row originalRow = sheet.getRow(3);
  97. Cell originalcell = originalRow.getCell(0);
  98. // 获取单元格样式
  99. CellStyle originalStyle = originalcell.getCellStyle();
  100. for (TPssrPublic t : list) {
  101. Row row = sheet.createRow(rowIndex);
  102. row.setHeight((short) 800);
  103. row.createCell(0).setCellValue(num);
  104. row.createCell(1).setCellValue(t.getCheckContent());
  105. row.createCell(2).setCellValue(t.getCheckResult());
  106. row.createCell(3);
  107. row.createCell(4);
  108. try {
  109. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  110. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  111. String confirm1 = sysUser.getSignUrl();
  112. String confirm2= sysUser2.getSignUrl();
  113. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 3, 1, 1);
  114. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 4, 1, 1);
  115. } catch (NumberFormatException e) {
  116. throw new RuntimeException(e);
  117. }
  118. row.createCell(5).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  119. row.createCell(6).setCellValue(t.getRemarks());
  120. //渲染样式
  121. for (int i = 0; i < 6; i++) {
  122. row.getCell(i).setCellStyle(originalStyle);
  123. }
  124. num++;
  125. rowIndex++;
  126. }
  127. filename = ExcelUtil.encodingFilename("Public");
  128. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  129. wb.write(out);
  130. wb.close();
  131. } catch (IOException e) {
  132. e.printStackTrace();
  133. }
  134. return filename;
  135. }
  136. /**
  137. * 获取公用工程详细信息
  138. */
  139. @PreAuthorize("@ss.hasPermi('pssr:public:query')")
  140. @GetMapping(value = "/{id}")
  141. public AjaxResult getInfo(@PathVariable("id") Long id)
  142. {
  143. return AjaxResult.success(tPssrPublicService.selectTPssrPublicById(id));
  144. }
  145. /**
  146. * 新增公用工程
  147. */
  148. @PreAuthorize("@ss.hasPermi('pssr:public:add')")
  149. @Log(title = "公用工程", businessType = BusinessType.INSERT)
  150. @PostMapping
  151. public AjaxResult add(@RequestBody TPssrPublic tPssrPublic)
  152. {
  153. tPssrPublic.setApproveStatus(0L);
  154. return toAjax(tPssrPublicService.insertTPssrPublic(tPssrPublic));
  155. }
  156. /**
  157. * 修改公用工程
  158. */
  159. @PreAuthorize("@ss.hasPermi('pssr:public:edit')")
  160. @Log(title = "公用工程", businessType = BusinessType.UPDATE)
  161. @PutMapping
  162. public AjaxResult edit(@RequestBody TPssrPublic tPssrPublic)
  163. {
  164. return toAjax(tPssrPublicService.updateTPssrPublic(tPssrPublic));
  165. }
  166. /**
  167. * 删除公用工程
  168. */
  169. @PreAuthorize("@ss.hasPermi('pssr:public:remove')")
  170. @Log(title = "公用工程", businessType = BusinessType.DELETE)
  171. @DeleteMapping("/{ids}")
  172. public AjaxResult remove(@PathVariable Long[] ids)
  173. {
  174. return toAjax(tPssrPublicService.deleteTPssrPublicByIds(ids));
  175. }
  176. /**
  177. * 确认公用工程
  178. */
  179. @PreAuthorize("@ss.hasPermi('pssr:public:edit')")
  180. @Log(title = "公用工程", businessType = BusinessType.UPDATE)
  181. @PutMapping("/confirmPublic")
  182. public AjaxResult confirmPublic(@RequestBody TPssrPublic tPssrPublic) {
  183. long queryStatus = 0;
  184. long approveStatus = 0;
  185. Date date = null;
  186. if (tPssrPublic.getTaskType() == 4) {
  187. //拆锁确认
  188. queryStatus = 1;
  189. approveStatus = 3;
  190. date = new Date();
  191. } else if (tPssrPublic.getTaskType() == 5) {
  192. //上锁确认
  193. queryStatus = 3;
  194. approveStatus = 2;
  195. date = new Date();
  196. }
  197. // 修改状态
  198. if (tPssrPublic.getIds() != null && tPssrPublic.getIds().length > 0) {
  199. for (Long id : tPssrPublic.getIds()) {
  200. TPssrPublic item = tPssrPublicService.selectTPssrPublicById(id);
  201. item.setApproveStatus(approveStatus);
  202. if (item.getConfirmationDate()==null && queryStatus==3) {
  203. item.setConfirmationDate(date);
  204. }
  205. tPssrPublicService.updateTPssrPublic(item);
  206. }
  207. } else {
  208. TPssrPublic lock = new TPssrPublic();
  209. lock.setSubId(tPssrPublic.getSubId());
  210. lock.setApproveStatus(queryStatus);
  211. for (TPssrPublic item : tPssrPublicService.selectTPssrPublicList(lock)) {
  212. if (item.getConfirmationDate()==null && queryStatus==3) {
  213. item.setConfirmationDate(date);
  214. }
  215. item.setApproveStatus(approveStatus);
  216. tPssrPublicService.updateTPssrPublic(item);
  217. }
  218. }
  219. //查询当前待审批的确认人
  220. TPssrPublic entity = new TPssrPublic();
  221. entity.setSubId(tPssrPublic.getSubId());
  222. entity.setApproveStatus(queryStatus);
  223. for (TPssrPublic item : tPssrPublicService.selectTPssrPublicList(entity)) {
  224. if (tPssrPublic.getTaskType() == 4) {
  225. if (item.getConfirm1().equals(getUserId().toString())) {
  226. return AjaxResult.success();
  227. }
  228. } else if (tPssrPublic.getTaskType() == 5) {
  229. if (item.getConfirm2().equals(getUserId().toString())) {
  230. return AjaxResult.success();
  231. }
  232. }
  233. }
  234. //无待审批任务结束当前用户流程
  235. // 因为流程关系所以approve一定会有且只有一条数据
  236. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrPublic.getSubId());
  237. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  238. return AjaxResult.success();
  239. }
  240. /**
  241. * 驳回公用工程
  242. */
  243. @PutMapping("/turnDownPublic")
  244. public AjaxResult turnDownPublic(@RequestBody TPssrPublic tPssrPublic) {
  245. if (tPssrPublic.getIds() != null) {
  246. String userId = getUserId().toString();
  247. // 修改已选择数据的状态
  248. for (Long id : tPssrPublic.getIds()) {
  249. TPssrPublic blind = new TPssrPublic();
  250. blind.setId(id);
  251. blind.setApproveStatus(1L);
  252. blind.setUpdatedate(new Date());
  253. blind.setUpdaterCode(getUserId().toString());
  254. tPssrPublicService.updateTPssrPublic(blind);
  255. }
  256. // 查询当前流程
  257. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrPublic.getSubId());
  258. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  259. TaskService taskService = processEngine.getTaskService();
  260. Task task = processEngine.getTaskService()//获取任务service
  261. .createTaskQuery()//创建查询对象
  262. .taskAssignee(userId)
  263. .processInstanceId(approve.getProcessId()).singleResult();
  264. String taskId = task.getId();
  265. // 驳回 查询所有待审批的人员
  266. TPssrPublic blind = new TPssrPublic();
  267. blind.setSubId(tPssrPublic.getSubId());
  268. blind.setApproveStatus(1L);
  269. Set<String> installer = new HashSet<>();
  270. Set<String> remover = new HashSet<>();
  271. for (TPssrPublic item : tPssrPublicService.selectTPssrPublicList(blind)) {
  272. // 安装人员
  273. installer.add(item.getConfirm1());
  274. //拆除人员
  275. remover.add(item.getConfirm2());
  276. }
  277. //处理流程节点
  278. Map<String, Object> param = new HashMap<>();
  279. param.put("condition", 1);
  280. param.put("confirmUsers1", new ArrayList<>(installer));
  281. param.put("confirmUsers2", new ArrayList<>(remover));
  282. //认领任务
  283. processEngine.getTaskService().claim(taskId, userId);
  284. taskService.addComment(taskId, approve.getProcessId(), "驳回;" + tPssrPublic.getRemarks());
  285. taskService.complete(taskId, param);
  286. // 修改审批表和sub表
  287. approve.setApproveStatus(1L);
  288. approve.setUpdatedate(new Date());
  289. approve.setUpdaterCode(getUserId().toString());
  290. tPssrApproveService.updateTPssrApprove(approve);
  291. TPssrSubcontent subcontent = new TPssrSubcontent();
  292. subcontent.setId(approve.getSubId());
  293. subcontent.setApproveStatus(1L);
  294. subcontent.setUpdatedate(new Date());
  295. subcontent.setUpdaterCode(getUserId().toString());
  296. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  297. return AjaxResult.success();
  298. }
  299. return AjaxResult.error();
  300. }
  301. }