TApproveController.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. package com.ruoyi.project.sems.controller;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.text.SimpleDateFormat;
  5. import java.util.*;
  6. import java.util.concurrent.CopyOnWriteArrayList;
  7. import java.util.concurrent.CountDownLatch;
  8. import java.util.concurrent.ExecutorService;
  9. import java.util.concurrent.Executors;
  10. import com.alibaba.fastjson.JSON;
  11. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  12. import com.fasterxml.jackson.databind.ObjectMapper;
  13. import com.ruoyi.common.utils.document.DocumentHandler;
  14. import com.ruoyi.common.utils.document.PDFTemplateUtil;
  15. import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
  16. import com.ruoyi.project.approve.damain.DevTask;
  17. import com.ruoyi.project.listener.monthSemsApprove.*;
  18. import com.ruoyi.project.listener.semsApprove.*;
  19. import com.ruoyi.project.listener.yearSemsApprove.*;
  20. import com.ruoyi.project.sems.domain.*;
  21. import com.ruoyi.project.sems.mapper.TApproveMapper;
  22. import com.ruoyi.project.sems.service.*;
  23. import com.ruoyi.project.system.domain.SysUser;
  24. import com.ruoyi.project.system.service.ISysUserService;
  25. import freemarker.template.Template;
  26. import org.activiti.engine.*;
  27. import org.activiti.engine.history.HistoricProcessInstance;
  28. import org.activiti.engine.history.HistoricTaskInstance;
  29. import org.activiti.engine.history.HistoricTaskInstanceQuery;
  30. import org.activiti.engine.impl.identity.Authentication;
  31. import org.activiti.engine.runtime.ProcessInstance;
  32. import org.activiti.engine.task.Comment;
  33. import org.activiti.engine.task.Task;
  34. import org.springframework.security.access.prepost.PreAuthorize;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.web.bind.annotation.*;
  37. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  38. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  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. import javax.annotation.Resource;
  44. import javax.servlet.http.HttpServletRequest;
  45. import javax.servlet.http.HttpServletResponse;
  46. /**
  47. * 特种设备申请Controller
  48. *
  49. * @author ruoyi
  50. * @date 2021-08-05
  51. */
  52. @RestController
  53. @RequestMapping("/sems/approve")
  54. public class TApproveController extends BaseController {
  55. @Autowired
  56. private ITApproveService tApproveService;
  57. @Autowired
  58. private RuntimeService runtimeService;
  59. @Autowired
  60. private HistoryService historyService;
  61. @Autowired
  62. private TaskService taskService;
  63. @Autowired
  64. private ITSpecdevDtService tSpecdevDtService;
  65. @Autowired
  66. private ITSpecdevDzsbService tSpecdevDzsbService;
  67. @Autowired
  68. private ITSpecdevGlService tSpecdevGlService;
  69. @Autowired
  70. private ITSpecdevYlgdService tSpecdevYlgdService;
  71. @Autowired
  72. private ITSpecdevYlrqService tSpecdevYlrqService;
  73. @Autowired
  74. private ITSpecdevCcService tSpecdevCcService;
  75. @Autowired
  76. private ITApproverFileService tApproverFileService;
  77. @Autowired
  78. private ISysUserService sysUserService;
  79. @Resource
  80. private TApproveMapper tApproveMapper;
  81. @Autowired
  82. private ITReportYlrqService tReportYlrqService;
  83. @Autowired
  84. private ITReportYlgdService tReportYlgdService;
  85. @Autowired
  86. private ITReportMonthService tReportMonthService;
  87. /**
  88. * 查询特种设备申请列表
  89. */
  90. @PreAuthorize("@ss.hasPermi('sems:approve:list')")
  91. @GetMapping("/list")
  92. public TableDataInfo list(TApprove tApprove) {
  93. startPage();
  94. List<TApprove> list = tApproveService.selectTApproveList(tApprove);
  95. return getDataTable(list);
  96. }
  97. /**
  98. * 历史申请列表
  99. */
  100. @RequestMapping("/hisApprovelist")
  101. public AjaxResult hisApprovelist(@RequestParam Map<String, Object> params) {
  102. String sql = params.get("devId") + " in (SELECT REGEXP_SUBSTR (DEV_ID, '[^,]+', 1,rownum) from dual connect by rownum<=LENGTH (DEV_ID) - LENGTH (regexp_replace(DEV_ID, ',', ''))+1 )";
  103. List<TApprove> list = tApproveMapper.selectList(new QueryWrapper<TApprove>().apply(sql).orderByDesc("CREATTIME")
  104. );
  105. for (TApprove t : list
  106. ) {
  107. SysUser userEntity = sysUserService.selectUserById(t.getUserId());
  108. t.setUserName(userEntity.getNickName());
  109. }
  110. return AjaxResult.success(list);
  111. }
  112. /**
  113. * 导出特种设备申请列表
  114. */
  115. @PreAuthorize("@ss.hasPermi('sems:approve:export')")
  116. @Log(title = "特种设备申请", businessType = BusinessType.EXPORT)
  117. @GetMapping("/export")
  118. public AjaxResult export(TApprove tApprove) {
  119. List<TApprove> list = tApproveService.selectTApproveList(tApprove);
  120. ExcelUtil<TApprove> util = new ExcelUtil<TApprove>(TApprove.class);
  121. return util.exportExcel(list, "approve");
  122. }
  123. /**
  124. * 获取特种设备申请详细信息
  125. */
  126. @PreAuthorize("@ss.hasPermi('sems:approve:query')")
  127. @GetMapping(value = "/{id}")
  128. public AjaxResult getInfo(@PathVariable("id") Long id) {
  129. return AjaxResult.success(tApproveService.selectTApproveById(id));
  130. }
  131. /**
  132. * 新增特种设备申请
  133. */
  134. @Log(title = "特种设备申请", businessType = BusinessType.INSERT)
  135. @PostMapping
  136. public AjaxResult add(@RequestBody TApprove tApprove) {
  137. logger.info(JSON.toJSONString(tApprove));
  138. Long userid = getUserId();
  139. tApprove.setUserId(userid);
  140. //审批编号
  141. Date dt = new Date();
  142. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  143. String data = sdf.format(dt) + userid;
  144. tApprove.setApNo(data);
  145. tApproveService.insertTApprove(tApprove);
  146. if (tApprove.getFiles().size() > 0) {
  147. for (TApproverFile t : tApprove.getFiles()
  148. ) {
  149. t.setApproveId(tApprove.getId());
  150. t.setFileType(1l);
  151. tApproverFileService.save(t);
  152. }
  153. }
  154. String[] ids = tApprove.getDevId().split(",");
  155. switch (Integer.parseInt(tApprove.getDevType().toString())) {
  156. case 1:
  157. for (String i : ids
  158. ) {
  159. TSpecdevYlrq ylrqEntity = tSpecdevYlrqService.getById(i);
  160. ylrqEntity.setApproveStatus(tApprove.getApproveType());
  161. ylrqEntity.setApproveTime(new Date());
  162. tSpecdevYlrqService.updateById(ylrqEntity);
  163. }
  164. break;
  165. case 2:
  166. for (String i : ids
  167. ) {
  168. TSpecdevYlgd ylgdEntity = tSpecdevYlgdService.getById(i);
  169. ylgdEntity.setApproveStatus(tApprove.getApproveType());
  170. ylgdEntity.setApproveTime(new Date());
  171. tSpecdevYlgdService.updateById(ylgdEntity);
  172. }
  173. break;
  174. case 3:
  175. for (String i : ids
  176. ) {
  177. TSpecdevDzsb dzsbEntity = tSpecdevDzsbService.getById(i);
  178. dzsbEntity.setApproveStatus(tApprove.getApproveType());
  179. dzsbEntity.setApproveTime(new Date());
  180. tSpecdevDzsbService.updateById(dzsbEntity);
  181. }
  182. break;
  183. case 4:
  184. for (String i : ids
  185. ) {
  186. TSpecdevGl glEntity = tSpecdevGlService.getById(i);
  187. glEntity.setApproveStatus(tApprove.getApproveType());
  188. glEntity.setApproveTime(new Date());
  189. tSpecdevGlService.updateById(glEntity);
  190. }
  191. break;
  192. case 5:
  193. for (String i : ids
  194. ) {
  195. TSpecdevDt dtEntity = tSpecdevDtService.getById(i);
  196. dtEntity.setApproveStatus(tApprove.getApproveType());
  197. dtEntity.setApproveTime(new Date());
  198. tSpecdevDtService.updateById(dtEntity);
  199. }
  200. break;
  201. case 6:
  202. for (String i : ids
  203. ) {
  204. TSpecdevCc ccEntity = tSpecdevCcService.getById(i);
  205. ccEntity.setApproveStatus(tApprove.getApproveType());
  206. ccEntity.setApproveTime(new Date());
  207. tSpecdevCcService.updateById(ccEntity);
  208. }
  209. break;
  210. }
  211. //
  212. long bussniseeKey = tApprove.getId();
  213. Authentication.setAuthenticatedUserId(userid.toString());
  214. //开始工作流、监听
  215. Map<String, Object> variables = new HashMap<>();
  216. variables.put("applyUser", userid.toString());
  217. variables.put("wxjlusers", tApprove.getWxjl().toString());
  218. variables.put("gyjlusers", tApprove.getGyjl().toString());
  219. variables.put("gyzjusers", tApprove.getGyzj().toString());
  220. variables.put("ctmusers", tApprove.getWxzj().toString());
  221. variables.put("zfusers", tApprove.getZf().toString());
  222. variables.put("specEndSucessListener", new SpecEndSucessListener());
  223. variables.put("specEndFaileListener", new SpecEndFaileListener());
  224. variables.put("wxjlTaskCreateListener", new WxjlTaskCreateListener());
  225. variables.put("gyjlTaskCreateListener", new GyjlTaskCreateListener());
  226. variables.put("gyzjTaskCreateListener", new GyzjTaskCreateListener());
  227. variables.put("ctmTaskCreateListener", new CtmTaskCreateListener());
  228. variables.put("zfhzTaskCreateListener", new ZfhzTaskCreateListener());
  229. //采用key来启动流程定义并设置流程变量,返回流程实例
  230. ProcessInstance pi = runtimeService.startProcessInstanceByKey("myProcess", String.valueOf(bussniseeKey), variables);
  231. logger.info("流程部署id:" + pi.getDeploymentId());
  232. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  233. logger.info("流程实例id:" + pi.getProcessInstanceId());
  234. tApprove.setProcessId(pi.getProcessInstanceId());
  235. tApproveService.updateTApprove(tApprove);
  236. return AjaxResult.success();
  237. }
  238. /**
  239. * 任务详情
  240. */
  241. @RequestMapping("/info/{id}")
  242. // @RequiresPermissions("approve:tapprove:info")
  243. public AjaxResult info(@PathVariable("id") Long id) {
  244. TApprove tApprove = tApproveService.selectTApproveById(id);
  245. List<TApproverFile> files = tApproverFileService.list(new QueryWrapper<TApproverFile>().eq("APPROVE_ID", id).eq("FILE_TYPE", 1));
  246. tApprove.setFiles(files);
  247. List<TApproverFile> govfiles = tApproverFileService.list(new QueryWrapper<TApproverFile>().eq("APPROVE_ID", id).eq("FILE_TYPE", 2));
  248. tApprove.setGovFiles(govfiles);
  249. String[] ids = null;
  250. if (tApprove.getApproveType() == 7) {
  251. ids = tApprove.getReportId().split(",");
  252. } else if (tApprove.getApproveType() == 8) {
  253. ids = tApprove.getMonthId().split(",");
  254. } else {
  255. ids = tApprove.getDevId().split(",");
  256. }
  257. CopyOnWriteArrayList<Object> devList = new CopyOnWriteArrayList<>();
  258. //线程池
  259. ExecutorService executorService = Executors.newFixedThreadPool(30);
  260. final CountDownLatch latch = new CountDownLatch(ids.length); //相同线程数量的计数
  261. if (tApprove.getDevType() != null && tApprove.getApproveType() != 7) {
  262. switch (Integer.parseInt(tApprove.getDevType().toString())) {
  263. case 1:
  264. for (String i : ids
  265. ) {
  266. TSpecdevYlrq ylrqEntity = tSpecdevYlrqService.getById(i);
  267. devList.add(ylrqEntity);
  268. }
  269. break;
  270. case 2:
  271. for (String i : ids
  272. ) {
  273. TSpecdevYlgd ylgdEntity = tSpecdevYlgdService.getById(i);
  274. devList.add(ylgdEntity);
  275. }
  276. break;
  277. case 3:
  278. for (String i : ids
  279. ) {
  280. TSpecdevDzsb dzsbEntity = tSpecdevDzsbService.getById(i);
  281. devList.add(dzsbEntity);
  282. }
  283. break;
  284. case 4:
  285. for (String i : ids
  286. ) {
  287. TSpecdevGl glEntity = tSpecdevGlService.getById(i);
  288. devList.add(glEntity);
  289. }
  290. break;
  291. case 5:
  292. for (String i : ids
  293. ) {
  294. TSpecdevDt dtEntity = tSpecdevDtService.getById(i);
  295. devList.add(dtEntity);
  296. }
  297. break;
  298. case 6:
  299. for (String i : ids
  300. ) {
  301. TSpecdevCc ccEntity = tSpecdevCcService.getById(i);
  302. devList.add(ccEntity);
  303. }
  304. break;
  305. case 7:
  306. for (String i : ids
  307. ) {
  308. // TOtherTankEntity tankEntity = tOtherTankService.getById(i);
  309. // devList.add(tankEntity);
  310. }
  311. }
  312. }
  313. switch (Integer.parseInt(tApprove.getApproveType().toString())) {
  314. case 7:
  315. switch (tApprove.getDevType().toString()) {
  316. case "1":
  317. for (String i : ids
  318. ) {
  319. executorService.execute(() -> {
  320. //-- 业务模块
  321. try {
  322. TReportYlrq reportYlrqEntity = tReportYlrqService.selectTReportYlrqById(Long.parseLong(i));
  323. reportYlrqEntity.setDevEntity(tSpecdevYlrqService.getById(reportYlrqEntity.getDevId()));
  324. devList.add(reportYlrqEntity);
  325. } catch (Exception e) {
  326. } finally {
  327. latch.countDown(); //线程计数
  328. }
  329. });
  330. }
  331. break;
  332. case "2":
  333. for (String i : ids
  334. ) {
  335. executorService.execute(() -> {
  336. //-- 业务模块
  337. try {
  338. TReportYlgd reportYlgdEntity = tReportYlgdService.selectTReportYlgdById(Long.parseLong(i));
  339. reportYlgdEntity.setDevEntity(tSpecdevYlgdService.getById(reportYlgdEntity.getDevId()));
  340. devList.add(reportYlgdEntity);
  341. } catch (Exception e) {
  342. } finally {
  343. latch.countDown(); //线程计数
  344. }
  345. });
  346. }
  347. }
  348. break;
  349. case 8:
  350. for (String i : ids
  351. ) {
  352. TReportMonth reportMonthEntity = tReportMonthService.selectTReportMonthById(Long.parseLong(i));
  353. devList.add(reportMonthEntity);
  354. tApprove.setDevType(0l);
  355. }
  356. }
  357. try {
  358. latch.await(); //线程计数完毕后继续执行
  359. } catch (InterruptedException e) {
  360. e.printStackTrace();
  361. }
  362. executorService.shutdown();
  363. tApprove.setDevList(devList);
  364. return AjaxResult.success(tApprove);
  365. }
  366. /**
  367. * 审核处理
  368. */
  369. @Log(title = "特种设备审核处理", businessType = BusinessType.UPDATE)
  370. @PutMapping("/handle")
  371. public AjaxResult handle(@RequestBody DevTask devTask) {
  372. Map<String, Object> param = new HashMap<>();
  373. //流程审批意见
  374. String symbol = "";
  375. if (devTask.getComment() != "") {
  376. symbol = ",";
  377. }
  378. if (devTask.getCondition().equals("1")) {
  379. /* devTask.setComment("通过" + symbol + devTask.getComment());*/
  380. devTask.setComment("批准" + symbol + devTask.getComment());
  381. } else if (devTask.getCondition().equals("0")) {
  382. devTask.setComment("未通过" + symbol + devTask.getComment());
  383. }
  384. //使用任务服务完成任务(提交任务)
  385. String taskId = devTask.getTaskId();
  386. // 使用任务id,获取任务对象,获取流程实例id
  387. Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
  388. //利用任务对象,获取流程实例id
  389. String processInstancesId = task.getProcessInstanceId();
  390. System.out.println(processInstancesId);
  391. //年度报告申请检查人员会签判断
  392. if (task.getName().equals("检查人员")) {
  393. //获取当前任务流转列表
  394. HistoricTaskInstanceQuery htiq = historyService.createHistoricTaskInstanceQuery();
  395. List<HistoricTaskInstance> htiLists = htiq.processInstanceId(processInstancesId).finished().orderByHistoricTaskInstanceEndTime().asc().list();
  396. List<DevTask> devTaskList = new ArrayList<>();
  397. if (htiLists.size() > 0) {
  398. for (HistoricTaskInstance hi : htiLists
  399. ) {
  400. List<Comment> commentList = taskService.getTaskComments(hi.getId());
  401. DevTask dev = new DevTask();
  402. if (commentList.size() > 0) {
  403. dev.setComment(commentList.get(0).getFullMessage());
  404. }
  405. devTaskList.add(dev);
  406. }
  407. }
  408. if (devTaskList.size() == 2) {
  409. for (DevTask d : devTaskList) {
  410. if (d.getComment().substring(0, 1).equals("未")) {
  411. devTask.setCondition("0");
  412. }
  413. }
  414. }
  415. }
  416. param.put("condition", devTask.getCondition());
  417. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  418. TaskService taskService = processEngine.getTaskService();
  419. //认领任务
  420. processEngine.getTaskService()//
  421. .claim(taskId, getUserId().toString());
  422. // Authentication.setAuthenticatedUserId("cmc"); // 添加批注时候的审核人
  423. taskService.addComment(taskId, processInstancesId, devTask.getComment());
  424. //业务监听处理
  425. // tApproveService.handleApprove(task ,devTask);
  426. taskService.complete(taskId, param);
  427. //添加回执信息
  428. if (devTask.getGovFiles().size() > 0) {
  429. HistoricProcessInstance pi = processEngine.getHistoryService()
  430. .createHistoricProcessInstanceQuery().processInstanceId(processInstancesId).singleResult();
  431. String approveId = pi.getBusinessKey();
  432. TApprove approveEntity = tApproveService.selectTApproveById(Long.parseLong(approveId));
  433. approveEntity.setGovDate(devTask.getGovDate());
  434. tApproveService.updateTApprove(approveEntity);
  435. for (TApproverFile t : devTask.getGovFiles()
  436. ) {
  437. t.setApproveId(Long.parseLong(approveId));
  438. t.setFileType(2l);
  439. tApproverFileService.save(t);
  440. }
  441. }
  442. return AjaxResult.success();
  443. }
  444. @RequestMapping("/exportPDF")
  445. public AjaxResult exportWorld(@RequestParam String approveId, String processId, HttpServletRequest request, HttpServletResponse response) {
  446. String pid = processId;
  447. logger.info("processId:" + JSON.toJSONString(pid));
  448. HistoricTaskInstanceQuery htiq = historyService.createHistoricTaskInstanceQuery();
  449. List<HistoricTaskInstance> htiLists = htiq.processInstanceId(pid).finished().orderByHistoricTaskInstanceEndTime().asc().list();
  450. logger.info("历史任务:" + JSON.toJSONString(htiLists));
  451. List<DevTask> devTaskList = new ArrayList<>();
  452. if (htiLists.size() > 0) {
  453. for (HistoricTaskInstance hi : htiLists
  454. ) {
  455. List<Comment> commentList = taskService.getTaskComments(hi.getId());
  456. logger.info("评论列表:" + JSON.toJSONString(commentList));
  457. DevTask devTask = new DevTask();
  458. devTask.setTaskName(hi.getName());
  459. devTask.setTaskCreateTime(hi.getCreateTime());
  460. devTask.setTaskEndTime(hi.getEndTime());
  461. if (commentList.size() > 0) {
  462. devTask.setComment(commentList.get(0).getFullMessage());
  463. }
  464. SysUser user = sysUserService.selectUserById(Long.parseLong(hi.getAssignee()));
  465. devTask.setUserName(user.getNickName());
  466. devTaskList.add(devTask);
  467. }
  468. }
  469. TApprove tApprove = tApproveService.selectTApproveById(Long.parseLong(approveId));
  470. String[] ids = tApprove.getDevId().split(",");
  471. List<Object> devList = new ArrayList<>();
  472. switch (Integer.parseInt(tApprove.getDevType().toString())) {
  473. case 1:
  474. for (String i : ids
  475. ) {
  476. TSpecdevYlrq ylrqEntity = tSpecdevYlrqService.getById(i);
  477. devList.add(ylrqEntity);
  478. }
  479. break;
  480. case 2:
  481. for (String i : ids
  482. ) {
  483. TSpecdevYlgd ylgdEntity = tSpecdevYlgdService.getById(i);
  484. devList.add(ylgdEntity);
  485. }
  486. break;
  487. case 3:
  488. for (String i : ids
  489. ) {
  490. TSpecdevDzsb dzsbEntity = tSpecdevDzsbService.getById(i);
  491. devList.add(dzsbEntity);
  492. }
  493. break;
  494. case 4:
  495. for (String i : ids
  496. ) {
  497. TSpecdevGl glEntity = tSpecdevGlService.getById(i);
  498. devList.add(glEntity);
  499. }
  500. break;
  501. case 5:
  502. for (String i : ids
  503. ) {
  504. TSpecdevDt dtEntity = tSpecdevDtService.getById(i);
  505. devList.add(dtEntity);
  506. }
  507. break;
  508. case 6:
  509. for (String i : ids
  510. ) {
  511. TSpecdevCc ccEntity = tSpecdevCcService.getById(i);
  512. devList.add(ccEntity);
  513. }
  514. break;
  515. // case 7:
  516. // for (String i : ids
  517. // ) {
  518. // TOtherTank tankEntity = tOtherTankService.getById(i);
  519. // devList.add(tankEntity);
  520. // }
  521. }
  522. tApprove.setDevList(devList);
  523. OutputStream out = null;
  524. try {
  525. out = response.getOutputStream();
  526. //获取信息,就是上面的结构
  527. HashMap<String, Object> map = new HashMap<>();
  528. DocumentHandler dh = new DocumentHandler();
  529. Template t = dh.getTemplate();
  530. //申请设备信息
  531. List list = tApprove.getDevList();
  532. int devCount = list.size();
  533. Object plantCode = tApprove.getDevList().get(0);
  534. logger.info("DevList:" + list);
  535. map.put("plantCode", plantCode);
  536. map.put("list", list);
  537. map.put("devCount", devCount);
  538. //申请类型
  539. String devType = "";
  540. if (tApprove.getDevType() == 1) {
  541. devType = "压力容器";
  542. }
  543. if (tApprove.getDevType() == 2) {
  544. devType = "压力管道";
  545. }
  546. if (tApprove.getDevType() == 3) {
  547. devType = "吊装设备";
  548. }
  549. if (tApprove.getDevType() == 4) {
  550. devType = "锅炉";
  551. }
  552. if (tApprove.getDevType() == 5) {
  553. devType = "电梯";
  554. }
  555. if (tApprove.getDevType() == 6) {
  556. devType = "叉车";
  557. }
  558. if (tApprove.getDevType() == 7) {
  559. devType = "空气罐";
  560. }
  561. //延期时间
  562. Date dd = tApprove.getDelayDate();
  563. SimpleDateFormat sd = new SimpleDateFormat("yyyy年MM月dd日");
  564. String delayDate = sd.format(dd);
  565. //申请人及时间
  566. logger.info(JSON.toJSONString(tApprove));
  567. Long userId = tApprove.getUserId();
  568. SysUser user = sysUserService.selectUserById(userId);
  569. String createTime = sd.format(tApprove.getCreattime());
  570. //申请单位会签
  571. logger.info(JSON.toJSONString(devTaskList));
  572. for (int i = 0; i < devTaskList.size(); i++) {
  573. ObjectMapper objectMapper = new ObjectMapper();
  574. DevTask devTask = objectMapper.convertValue(devTaskList.get(i), DevTask.class);
  575. String taskEndTime = sd.format(devTask.getTaskEndTime());
  576. if (i == 0) {
  577. map.put("equipmentMaintenance", devTask);
  578. map.put("emEndTime", taskEndTime);
  579. }//装置维修经理
  580. if (i == 1) {
  581. map.put("equipmentProcess", devTask);
  582. map.put("epEndTime", taskEndTime);
  583. }//装置工艺经理
  584. if (i == 2) {
  585. map.put("processDirector", devTask);
  586. map.put("pdEndTime", taskEndTime);
  587. }//工艺总监
  588. if (i == 3) {
  589. map.put("mechanicalMaintenance", devTask);
  590. map.put("mmEndTime", taskEndTime);
  591. }//机械维修总监
  592. }
  593. //注意 变量名要与xml中占位符保持一致
  594. map.put("delayReason", tApprove.getDelayReason().replaceAll("\n", "<p></p>"));
  595. map.put("delayMeasure", tApprove.getDelayMeasure().replaceAll("\n", "<p></p>"));
  596. map.put("delayNotice", tApprove.getDelayNotice());
  597. map.put("devType", devType);
  598. map.put("delayDate", delayDate);
  599. map.put("userName", user.getNickName());
  600. map.put("createTime", createTime);
  601. logger.info("delayNotice:" + tApprove.getDelayNotice());
  602. if (map == null)
  603. return AjaxResult.error("导出失败!");
  604. /*ExportWordUtils word =new ExportWordUtils("/freeMaker", "fmaker.ftl"); // 项目使用的spring boot 。/excel/questionnaire.ftl文件存放在src/main/resources目录下
  605. word.setHeader(request, response, encodeFilename("1.doc" ,request ));
  606. word.doExport(out, map);*/
  607. if (tApprove.getDevType() == 1) {
  608. PDFTemplateUtil.exportPdf("ylrqFMaker.ftl", "压力容器延期检验报请备案函.pdf", "", map, response);
  609. }
  610. if (tApprove.getDevType() == 2) {
  611. PDFTemplateUtil.exportPdf("ylgdFMaker.ftl", "压力管道延期检验报请备案函.pdf", "", map, response);
  612. }
  613. if (tApprove.getDevType() == 3) {
  614. PDFTemplateUtil.exportPdf("dzsbFMaker.ftl", "吊装设备延期检验报请备案函.pdf", "", map, response);
  615. }
  616. if (tApprove.getDevType() == 4) {
  617. PDFTemplateUtil.exportPdf("glFMaker.ftl", "锅炉延期检验报请备案函.pdf", "", map, response);
  618. }
  619. if (tApprove.getDevType() == 5) {
  620. PDFTemplateUtil.exportPdf("dtFMaker.ftl", "电梯延期检验报请备案函.pdf", "", map, response);
  621. }
  622. if (tApprove.getDevType() == 6) {
  623. PDFTemplateUtil.exportPdf("ccFMaker.ftl", "叉车延期检验报请备案函.pdf", "", map, response);
  624. }
  625. if (tApprove.getDevType() == 7) {
  626. PDFTemplateUtil.exportPdf("tankFMaker.ftl", "空气罐延期检验报请备案函.pdf", "", map, response);
  627. }
  628. } catch (Exception e) {
  629. e.printStackTrace();
  630. } finally {
  631. if (out != null)
  632. try {
  633. out.close();
  634. } catch (IOException e) {
  635. e.printStackTrace();
  636. }
  637. }
  638. return null;
  639. }
  640. /**
  641. * 修改特种设备申请
  642. */
  643. @PreAuthorize("@ss.hasPermi('sems:approve:edit')")
  644. @Log(title = "特种设备申请", businessType = BusinessType.UPDATE)
  645. @PutMapping
  646. public AjaxResult edit(@RequestBody TApprove tApprove) {
  647. return toAjax(tApproveService.updateTApprove(tApprove));
  648. }
  649. /**
  650. * 删除特种设备申请
  651. */
  652. @PreAuthorize("@ss.hasPermi('sems:approve:remove')")
  653. @Log(title = "特种设备申请", businessType = BusinessType.DELETE)
  654. @DeleteMapping("/{ids}")
  655. public AjaxResult remove(@PathVariable Long[] ids) {
  656. return toAjax(tApproveService.deleteTApproveByIds(ids));
  657. }
  658. /**
  659. * 年度检查报告任务申请
  660. */
  661. @RequestMapping("/year")
  662. @RepeatSubmit
  663. public AjaxResult year(@RequestBody TApprove tApprove) {
  664. //任务开始时间
  665. long startTime = System.currentTimeMillis();
  666. logger.info("任务申请" + JSON.toJSONString(tApprove));
  667. Long userid = getUserId();
  668. //审批编号
  669. Date dt = new Date();
  670. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  671. String data = sdf.format(dt) + userid;
  672. tApprove.setApNo(data);
  673. tApprove.setUserId(userid);
  674. tApproveService.insertTApprove(tApprove);
  675. //修改设备申请状态
  676. String[] ids = tApprove.getReportId().split(",");
  677. ExecutorService executorService = Executors.newFixedThreadPool(30);
  678. switch (tApprove.getDevType().toString()) {
  679. case "1":
  680. for (String i : ids
  681. ) {
  682. executorService.execute(() -> {
  683. TReportYlrq rq = tReportYlrqService.selectTReportYlrqById(Long.parseLong(i));
  684. rq.setApproveStatus(7l);
  685. rq.setApproveTime(new Date());
  686. tReportYlrqService.updateTReportYlrq(rq);
  687. });
  688. }
  689. break;
  690. case "2":
  691. for (String i : ids
  692. ) {
  693. executorService.execute(() -> {
  694. TReportYlgd gd = tReportYlgdService.selectTReportYlgdById(Long.parseLong(i));
  695. gd.setApproveStatus(7l);
  696. gd.setApproveTime(new Date());
  697. tReportYlgdService.updateTReportYlgd(gd);
  698. });
  699. }
  700. }
  701. executorService.shutdown();
  702. Map<String, Object> variables = new HashMap<>();
  703. //开始工作流、监听
  704. variables.put("endSucessListener", new YearEndSucessListener());
  705. variables.put("endFaileListener", new YearEndFaileListener());
  706. variables.put("inspectorsTaskCreateListener", new InspectorTaskCreateListener());
  707. variables.put("auditorTaskCreateListener", new AuditorTaskCreateListener());
  708. variables.put("approverTaskCreateListener", new ApproverTaskCreateListener());
  709. //初始化会签人员
  710. List<Long> inspectorlist = new ArrayList<>();
  711. inspectorlist.add(tApprove.getInspectorOne());
  712. inspectorlist.add(tApprove.getInspectorTwo());
  713. inspectorlist.add(tApprove.getInspectorThree());
  714. //条件表达式方法 一定要序列号
  715. variables.put("inspectorlist", inspectorlist);
  716. //审批人员设置
  717. variables.put("auditor", tApprove.getAuditor());
  718. variables.put("approver", tApprove.getApprover());
  719. long bussniseeKey = tApprove.getId();
  720. logger.info("bussniseeKey:" + bussniseeKey);
  721. Authentication.setAuthenticatedUserId(userid.toString());
  722. //任务执行总时长
  723. long times = System.currentTimeMillis() - startTime;
  724. logger.debug(" 总共耗时:" + times + "毫秒");
  725. //采用key来启动流程定义并设置流程变量,返回流程实例
  726. ProcessInstance pi = runtimeService.startProcessInstanceByKey("yearProcess", String.valueOf(bussniseeKey), variables);
  727. logger.info("流程部署id:" + pi.getDeploymentId());
  728. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  729. logger.info("流程实例id:" + pi.getProcessInstanceId());
  730. logger.info("流程定义对象:" + pi.getProcessVariables());
  731. tApprove.setProcessId(pi.getProcessInstanceId());
  732. tApproveService.updateById(tApprove);
  733. //任务执行总时长
  734. long times2 = System.currentTimeMillis() - startTime;
  735. logger.debug(" 总共耗时:" + times2 + "毫秒");
  736. return AjaxResult.success();
  737. }
  738. /**
  739. * 月度检查报告任务申请
  740. */
  741. @RequestMapping("/month")
  742. public AjaxResult month(@RequestBody TApprove tApprove) {
  743. //任务开始时间
  744. long startTime = System.currentTimeMillis();
  745. logger.info("任务申请" + JSON.toJSONString(tApprove));
  746. Long userid = getUserId();
  747. //审批编号
  748. Date dt = new Date();
  749. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  750. String data = sdf.format(dt) + userid;
  751. tApprove.setApNo(data);
  752. tApprove.setUserId(userid);
  753. tApproveService.insertTApprove(tApprove);
  754. //修改设备申请状态
  755. String[] ids = tApprove.getMonthId().split(",");
  756. for (String i : ids
  757. ) {
  758. TReportMonth tReportMonthEntity = tReportMonthService.selectTReportMonthById(Long.parseLong(i));
  759. tReportMonthEntity.setApproveStatus(7l);
  760. tReportMonthEntity.setApproveId(tApprove.getId().toString());
  761. tReportMonthEntity.setApproveTime(new Date());
  762. tReportMonthService.updateTReportMonth(tReportMonthEntity);
  763. }
  764. Map<String, Object> variables = new HashMap<>();
  765. //开始工作流、监听
  766. variables.put("endSucessListener", new MonthEndSucessListener());
  767. variables.put("endFaileListener", new MonthEndFaileListener());
  768. variables.put("mechanicalTaskCreateListener", new MechanicalTaskCreateListener());
  769. variables.put("electricTaskCreateListener", new ElectricTaskCreateListener());
  770. variables.put("craftTaskCreateListener", new CraftTaskCreateListener());
  771. //审批人员设置
  772. variables.put("mechanical", tApprove.getMechanical());
  773. variables.put("electric", tApprove.getElectric());
  774. variables.put("craft", tApprove.getCraft());
  775. long bussniseeKey = tApprove.getId();
  776. logger.info("bussniseeKey:" + bussniseeKey);
  777. Authentication.setAuthenticatedUserId(userid.toString());
  778. //任务执行总时长
  779. long times = System.currentTimeMillis() - startTime;
  780. logger.debug(" 总共耗时:" + times + "毫秒");
  781. //采用key来启动流程定义并设置流程变量,返回流程实例
  782. ProcessInstance pi = runtimeService.startProcessInstanceByKey("monthProcess", String.valueOf(bussniseeKey), variables);
  783. logger.info("流程部署id:" + pi.getDeploymentId());
  784. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  785. logger.info("流程实例id:" + pi.getProcessInstanceId());
  786. logger.info("流程定义对象:" + pi.getProcessVariables());
  787. tApprove.setProcessId(pi.getProcessInstanceId());
  788. tApproveService.updateById(tApprove);
  789. //任务执行总时长
  790. long times2 = System.currentTimeMillis() - startTime;
  791. logger.debug(" 总共耗时:" + times2 + "毫秒");
  792. return AjaxResult.success();
  793. }
  794. }