TApproveController.java 41 KB

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