ActTaskController.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /**
  2. * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
  3. */
  4. package com.jeeplus.modules.act.web;
  5. import java.io.InputStream;
  6. import java.io.UnsupportedEncodingException;
  7. import java.net.URLDecoder;
  8. import java.util.ArrayList;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import javax.servlet.ServletContext;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import com.jeeplus.common.json.AjaxJson;
  16. import com.jeeplus.common.utils.SpringContextHolder;
  17. import com.jeeplus.common.websocket.service.system.SystemInfoSocketHandler;
  18. import com.jeeplus.modules.oa.entity.OaNotify;
  19. import com.jeeplus.modules.oa.entity.OaNotifyRecord;
  20. import com.jeeplus.modules.oa.service.OaNotifyService;
  21. import com.jeeplus.modules.sg.managementcenter.activiti.entity.Construction;
  22. import com.jeeplus.modules.sg.managementcenter.activiti.entity.Disclose;
  23. import com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages;
  24. import com.jeeplus.modules.sg.managementcenter.activiti.service.ConstructionService;
  25. import com.jeeplus.modules.sg.managementcenter.activiti.service.DiscloseService;
  26. import com.jeeplus.modules.sg.managementcenter.activiti.service.UploadImagesService;
  27. import org.activiti.engine.HistoryService;
  28. import org.activiti.engine.RepositoryService;
  29. import org.activiti.engine.RuntimeService;
  30. import org.activiti.engine.TaskService;
  31. import org.activiti.engine.history.HistoricProcessInstance;
  32. import org.activiti.engine.history.HistoricTaskInstance;
  33. import org.activiti.engine.impl.RepositoryServiceImpl;
  34. import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
  35. import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
  36. import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
  37. import org.activiti.engine.impl.pvm.PvmActivity;
  38. import org.activiti.engine.impl.pvm.PvmTransition;
  39. import org.activiti.engine.impl.pvm.process.ActivityImpl;
  40. import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;
  41. import org.activiti.engine.impl.pvm.process.TransitionImpl;
  42. import org.activiti.engine.impl.task.TaskDefinition;
  43. import org.activiti.engine.runtime.ProcessInstance;
  44. import org.activiti.engine.task.Task;
  45. import org.apache.commons.lang3.StringUtils;
  46. import org.apache.ibatis.annotations.Param;
  47. import org.apache.shiro.authz.annotation.RequiresPermissions;
  48. import org.springframework.beans.factory.annotation.Autowired;
  49. import org.springframework.stereotype.Controller;
  50. import org.springframework.ui.Model;
  51. import org.springframework.web.bind.annotation.PathVariable;
  52. import org.springframework.web.bind.annotation.RequestMapping;
  53. import org.springframework.web.bind.annotation.ResponseBody;
  54. import com.jeeplus.core.persistence.Page;
  55. import com.jeeplus.core.web.BaseController;
  56. import com.jeeplus.modules.act.entity.Act;
  57. import com.jeeplus.modules.act.service.ActTaskService;
  58. import com.jeeplus.modules.act.utils.ActUtils;
  59. import com.jeeplus.modules.sys.utils.UserUtils;
  60. /**
  61. * 流程个人任务相关Controller
  62. * @author jeeplus
  63. * @version 2016-11-03
  64. */
  65. @Controller
  66. @RequestMapping(value = "${adminPath}/act/task")
  67. public class ActTaskController extends BaseController {
  68. @Autowired
  69. private ActTaskService actTaskService;
  70. @Autowired
  71. private HistoryService historyService;
  72. @Autowired
  73. private RuntimeService runtimeService;
  74. @Autowired
  75. private RepositoryService repositoryService;
  76. @Autowired
  77. private TaskService taskService;
  78. @Autowired
  79. private ConstructionService constructionService;
  80. @Autowired
  81. private DiscloseService discloseService;
  82. @Autowired
  83. private UploadImagesService uploadImagesService;
  84. @Autowired
  85. private OaNotifyService oaNotifyService;
  86. /**
  87. * 获取待办列表
  88. * @return
  89. */
  90. @RequestMapping(value = {"todo", ""})
  91. public String todoList(Act act, HttpServletResponse response, Model model) throws Exception {
  92. return "modules/bpm/task/todo/taskTodoList";
  93. }
  94. @ResponseBody
  95. @RequestMapping(value = "todo/data")
  96. public Map<String, Object> todoListData(Act act, HttpServletRequest request,HttpServletResponse response, Model model) throws Exception {
  97. Page<HashMap<String,String>> page = actTaskService.todoList(new Page<HashMap<String,String>>(request, response),act);
  98. Map<String, Object> map = new HashMap<String, Object>();
  99. return getBootstrapData(page);
  100. }
  101. /**
  102. * 获取已办任务
  103. * @return
  104. */
  105. @RequestMapping(value = "historic")
  106. public String historicList(Act act, HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
  107. return "modules/bpm/task/history/taskHistoricList";
  108. }
  109. @ResponseBody
  110. @RequestMapping(value = "historic/data")
  111. public Map<String, Object> historicListData(Act act, HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
  112. Page<HashMap<String,String>> page = actTaskService.historicList(new Page<HashMap<String,String>>(request, response), act);
  113. return getBootstrapData(page);
  114. }
  115. /**
  116. * 获取我的申请列表
  117. * @return
  118. */
  119. @RequestMapping(value = "myApplyed")
  120. public String myApplyedList(Act act, HttpServletResponse response, Model model) throws Exception {
  121. return "modules/bpm/task/apply/taskMyAppledList";
  122. }
  123. @ResponseBody
  124. @RequestMapping(value = "myApplyed/data")
  125. public Map<String, Object> myApplyedListData(Act act, HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
  126. Page<HashMap> page = actTaskService.getMyStartedProcIns(UserUtils.getUser(),new Page<HashMap>(request, response));
  127. return getBootstrapData(page);
  128. }
  129. /**
  130. * 获取流转历史列表
  131. * @param startAct 开始活动节点名称
  132. * @param endAct 结束活动节点名称
  133. */
  134. @RequestMapping(value = "histoicFlow")
  135. public String histoicFlow(Act act, String startAct, String endAct, Model model){
  136. if (StringUtils.isNotBlank(act.getProcInsId())){
  137. List<Act> histoicFlowList = actTaskService.histoicFlowList(act.getProcInsId(), startAct, endAct);
  138. model.addAttribute("histoicFlowList", histoicFlowList);
  139. }
  140. return "modules/bpm/task/history/taskHistoricFlow";
  141. }
  142. /**
  143. * 获取流程流向图
  144. * @param startAct 开始活动节点名称
  145. * @param endAct 结束活动节点名称
  146. */
  147. @RequestMapping(value = "flowChart")
  148. public String flowChart(Act act, String startAct, String endAct, Model model){
  149. if (StringUtils.isNotBlank(act.getProcInsId())){
  150. List<Act> histoicFlowList = actTaskService.histoicFlowList(act.getProcInsId(), startAct, endAct);
  151. model.addAttribute("histoicFlowList", histoicFlowList);
  152. }
  153. return "modules/bpm/task/chart/taskFlowChart";
  154. }
  155. /**
  156. * 获取流程列表
  157. * @param category 流程分类
  158. */
  159. @RequestMapping(value = "process")
  160. public String processList(String category, HttpServletRequest request, HttpServletResponse response, Model model) {
  161. Page<Object[]> page = new Page<Object[]>(request, response);
  162. model.addAttribute("category", category);
  163. return "modules/bpm/task/process/taskProcessList";
  164. }
  165. /**
  166. * 获取流程表单
  167. */
  168. @RequestMapping(value = "form")
  169. public String form(Act act, HttpServletRequest request, Model model){
  170. // 获取流程XML上的表单KEY
  171. String formKey = actTaskService.getFormKey(act.getProcDefId(), act.getTaskDefKey());
  172. // 获取流程实例对象
  173. if (act.getProcInsId() != null){
  174. if(actTaskService.getProcIns(act.getProcInsId())!=null){
  175. try {
  176. act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
  177. } catch (Exception e) {
  178. e.printStackTrace();
  179. }
  180. }else{
  181. act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
  182. }
  183. if(actTaskService.isNextGatewaty(act.getProcInsId())){
  184. act.setIsNextGatewaty(true);
  185. }else{
  186. act.setIsNextGatewaty(false);
  187. }
  188. }
  189. return "redirect:" + ActUtils.getFormUrl(formKey, act);
  190. }
  191. /**
  192. * 根据流程实例ID,获取当前节点的流程表单详情
  193. */
  194. @RequestMapping(value = "formDetail")
  195. public String formDetail(Act act, HttpServletRequest request, Model model){
  196. // 获取流程XML上的表单KEY
  197. String taskDefKey = nextTaskDefinition(act.getProcInsId());
  198. String formKey = actTaskService.getFormKey(act.getProcDefId(), taskDefKey);
  199. // 获取流程实例对象
  200. if (act.getProcInsId() != null){
  201. if(actTaskService.getProcIns(act.getProcInsId())!=null){
  202. act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
  203. }else{
  204. act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
  205. }
  206. if(actTaskService.isNextGatewaty(act.getProcInsId())){
  207. act.setIsNextGatewaty(true);
  208. }else{
  209. act.setIsNextGatewaty(false);
  210. }
  211. }
  212. return "redirect:" + ActUtils.getFormUrl(formKey, act);
  213. }
  214. /**
  215. * 启动流程
  216. */
  217. @RequestMapping(value = "start")
  218. @ResponseBody
  219. public String start(Act act, String table, String id, Model model) throws Exception {
  220. actTaskService.startProcess(act.getProcDefKey(), act.getBusinessId(), act.getBusinessTable(), act.getTitle());
  221. return "true";//adminPath + "/act/task";
  222. }
  223. /**
  224. * 签收任务
  225. */
  226. @RequestMapping(value = "claim")
  227. @ResponseBody
  228. public String claim(Act act) {
  229. String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId());
  230. actTaskService.claim(act.getTaskId(), userId);
  231. return "true";//adminPath + "/act/task";
  232. }
  233. /**
  234. * 完成任务
  235. * vars.keys=flag,pass
  236. * vars.values=1,true
  237. * vars.types=S,B @see com.jeeplus.jeeplus.modules.act.utils.PropertyType
  238. */
  239. @RequestMapping(value = "complete")
  240. @ResponseBody
  241. public String complete(Act act) {
  242. actTaskService.complete(act.getTaskId(), act.getProcInsId(), act.getComment(), act.getVars().getVariableMap());
  243. return "true";//adminPath + "/act/task";
  244. }
  245. /**
  246. * 读取带跟踪的图片
  247. */
  248. @RequestMapping(value = "trace/photo/{procDefId}/{execId}")
  249. public void tracePhoto(@PathVariable("procDefId") String procDefId, @PathVariable("execId") String execId, HttpServletResponse response) throws Exception {
  250. InputStream imageStream = actTaskService.tracePhoto(procDefId, execId);
  251. // 输出资源内容到相应对象
  252. byte[] b = new byte[1024];
  253. int len;
  254. while ((len = imageStream.read(b, 0, 1024)) != -1) {
  255. response.getOutputStream().write(b, 0, len);
  256. }
  257. }
  258. /**
  259. * 输出跟踪流程信息
  260. *
  261. * @return
  262. * @throws Exception
  263. */
  264. @ResponseBody
  265. @RequestMapping(value = "trace/info/{proInsId}")
  266. public List<Map<String, Object>> traceInfo(@PathVariable("proInsId") String proInsId) throws Exception {
  267. List<Map<String, Object>> activityInfos = actTaskService.traceProcess(proInsId);
  268. return activityInfos;
  269. }
  270. /**
  271. * 显示流程图
  272. @RequestMapping(value = "processPic")
  273. public void processPic(String procDefId, HttpServletResponse response) throws Exception {
  274. ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
  275. String diagramResourceName = procDef.getDiagramResourceName();
  276. InputStream imageStream = repositoryService.getResourceAsStream(procDef.getDeploymentId(), diagramResourceName);
  277. byte[] b = new byte[1024];
  278. int len = -1;
  279. while ((len = imageStream.read(b, 0, 1024)) != -1) {
  280. response.getOutputStream().write(b, 0, len);
  281. }
  282. }*/
  283. /**
  284. * 获取跟踪信息
  285. @RequestMapping(value = "processMap")
  286. public String processMap(String procDefId, String proInstId, Model model)
  287. throws Exception {
  288. List<ActivityImpl> actImpls = new ArrayList<ActivityImpl>();
  289. ProcessDefinition processDefinition = repositoryService
  290. .createProcessDefinitionQuery().processDefinitionId(procDefId)
  291. .singleResult();
  292. ProcessDefinitionImpl pdImpl = (ProcessDefinitionImpl) processDefinition;
  293. String processDefinitionId = pdImpl.getId();// 流程标识
  294. ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
  295. .getDeployedProcessDefinition(processDefinitionId);
  296. List<ActivityImpl> activitiList = def.getActivities();// 获得当前任务的所有节点
  297. List<String> activeActivityIds = runtimeService.getActiveActivityIds(proInstId);
  298. for (String activeId : activeActivityIds) {
  299. for (ActivityImpl activityImpl : activitiList) {
  300. String id = activityImpl.getId();
  301. if (activityImpl.isScope()) {
  302. if (activityImpl.getActivities().size() > 1) {
  303. List<ActivityImpl> subAcList = activityImpl
  304. .getActivities();
  305. for (ActivityImpl subActImpl : subAcList) {
  306. String subid = subActImpl.getId();
  307. System.out.println("subImpl:" + subid);
  308. if (activeId.equals(subid)) {// 获得执行到那个节点
  309. actImpls.add(subActImpl);
  310. break;
  311. }
  312. }
  313. }
  314. }
  315. if (activeId.equals(id)) {// 获得执行到那个节点
  316. actImpls.add(activityImpl);
  317. System.out.println(id);
  318. }
  319. }
  320. }
  321. model.addAttribute("procDefId", procDefId);
  322. model.addAttribute("proInstId", proInstId);
  323. model.addAttribute("actImpls", actImpls);
  324. return "modules/act/actTaskMap";
  325. }*/
  326. /**
  327. * 删除任务
  328. * @param taskId 流程实例ID
  329. * @param reason 删除原因
  330. */
  331. @ResponseBody
  332. @RequiresPermissions("act:process:edit")
  333. @RequestMapping(value = "deleteTask")
  334. public AjaxJson deleteTask(String taskId, String reason) {
  335. AjaxJson j = new AjaxJson();
  336. if (StringUtils.isBlank(reason)){
  337. j.setSuccess(false);
  338. j.setMsg("请填写删除原因");
  339. }else{
  340. actTaskService.deleteTask(taskId, reason);
  341. j.setSuccess(true);
  342. j.setMsg("删除任务成功,任务ID=" + taskId);
  343. }
  344. return j;
  345. }
  346. /**
  347. * 审批
  348. * @param act
  349. */
  350. @ResponseBody
  351. @RequestMapping(value = "audit")
  352. public AjaxJson auditTask(Act act) {
  353. AjaxJson j = new AjaxJson();
  354. actTaskService.auditSave(act);
  355. j.setMsg("审批成功");
  356. return j;
  357. }
  358. /**
  359. * 审批
  360. * @param act
  361. */
  362. @ResponseBody
  363. @RequestMapping(value = "economics")
  364. public AjaxJson economics(Act act) {
  365. AjaxJson j = new AjaxJson();
  366. try {
  367. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  368. act.setComment(comment);
  369. actTaskService.economics(act);
  370. } catch (UnsupportedEncodingException e) {
  371. e.printStackTrace();
  372. }
  373. j.setMsg("审批成功");
  374. return j;
  375. }
  376. /**
  377. * 人工选择问题类型审批
  378. * @param act
  379. */
  380. @ResponseBody
  381. @RequestMapping(value = "artificialTask")
  382. public AjaxJson artificialTask(Act act) {
  383. AjaxJson j = new AjaxJson();
  384. try {
  385. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  386. act.setComment(comment);
  387. actTaskService.artificialTask(act);
  388. } catch (UnsupportedEncodingException e) {
  389. e.printStackTrace();
  390. }
  391. j.setMsg("审批成功");
  392. return j;
  393. }
  394. /**
  395. * 运行人员设计变更页面
  396. * @param act
  397. */
  398. @ResponseBody
  399. @RequestMapping(value = "operator")
  400. public AjaxJson operator(Act act, String design, String pic, UploadImages uploadImages) {
  401. AjaxJson j = new AjaxJson();
  402. try {
  403. if (pic!=null&&pic!="") {
  404. uploadImages.setPath(pic);
  405. uploadImages.setProcInsId(act.getProcInsId());
  406. uploadImages.setuId(UserUtils.getUser().getLoginName());
  407. uploadImagesService.save(uploadImages);
  408. }
  409. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  410. act.setComment(comment);
  411. actTaskService.operator(act,design);
  412. } catch (UnsupportedEncodingException e) {
  413. e.printStackTrace();
  414. }
  415. j.setMsg("审批成功");
  416. return j;
  417. }
  418. /**
  419. * 项目经理判断是否需要设计变更
  420. * @param act
  421. */
  422. @ResponseBody
  423. @RequestMapping(value = "managerDesign")
  424. public AjaxJson managerDesign(Act act) {
  425. AjaxJson j = new AjaxJson();
  426. try {
  427. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  428. act.setComment(comment);
  429. actTaskService.managerDesign(act);
  430. } catch (UnsupportedEncodingException e) {
  431. e.printStackTrace();
  432. }
  433. j.setMsg("审批成功");
  434. return j;
  435. }
  436. /**
  437. * 设计单位人员提交文件
  438. * @param act
  439. */
  440. @ResponseBody
  441. @RequestMapping(value = "designUpload")
  442. public AjaxJson designUpload(Act act, String design, String pic, UploadImages uploadImages) {
  443. AjaxJson j = new AjaxJson();
  444. try {
  445. if (pic!=null&&pic!="") {
  446. uploadImages.setPath(pic);
  447. uploadImages.setProcInsId(act.getProcInsId());
  448. uploadImages.setuId(UserUtils.getUser().getLoginName());
  449. uploadImagesService.save(uploadImages);
  450. }
  451. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  452. act.setComment(comment);
  453. actTaskService.designUpload(act,design);
  454. } catch (UnsupportedEncodingException e) {
  455. e.printStackTrace();
  456. }
  457. j.setMsg("审批成功");
  458. return j;
  459. }
  460. /**
  461. * 配网运行人员判断变更后材料
  462. * @param act
  463. */
  464. @ResponseBody
  465. @RequestMapping(value = "operatorUpload")
  466. public AjaxJson operatorUpload(Act act, String design) {
  467. AjaxJson j = new AjaxJson();
  468. try {
  469. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  470. act.setComment(comment);
  471. actTaskService.operatorUpload(act,design);
  472. } catch (UnsupportedEncodingException e) {
  473. e.printStackTrace();
  474. }
  475. j.setMsg("审批成功");
  476. return j;
  477. }
  478. /**
  479. * 配网项目经理判断变更后材料
  480. * @param act
  481. */
  482. @ResponseBody
  483. @RequestMapping(value = "managerUpload")
  484. public AjaxJson managerUpload(Act act, String design) {
  485. AjaxJson j = new AjaxJson();
  486. try {
  487. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  488. act.setComment(comment);
  489. actTaskService.managerUpload(act,design);
  490. } catch (UnsupportedEncodingException e) {
  491. e.printStackTrace();
  492. }
  493. j.setMsg("审批成功");
  494. return j;
  495. }
  496. /**
  497. * 施工审批
  498. * @param act
  499. */
  500. @ResponseBody
  501. @RequestMapping(value = "audit2")
  502. public AjaxJson auditTask2(Act act) {
  503. AjaxJson j = new AjaxJson();
  504. try {
  505. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  506. act.setComment(comment);
  507. actTaskService.auditSave2(act);
  508. } catch (UnsupportedEncodingException e) {
  509. e.printStackTrace();
  510. }
  511. j.setMsg("审批成功");
  512. return j;
  513. }
  514. /**
  515. * 经理审批
  516. * @param
  517. */
  518. @ResponseBody
  519. @RequestMapping(value = "audit3")
  520. public AjaxJson auditTask3(Act act) {
  521. AjaxJson j = new AjaxJson();
  522. String s = "";
  523. boolean flag = false;
  524. Disclose dc = new Disclose();
  525. dc.setProcInsId(act.getProcInsId());
  526. Disclose disclose = discloseService.get(dc);
  527. if (null==disclose){
  528. j.setSuccess(false);
  529. j.setMsg("请导入数据");
  530. return j;
  531. }
  532. Boolean flagDesign = actTaskService.isJudgeDesign(disclose);
  533. Boolean flagItemCLose =actTaskService.isJudgeItemClose(disclose);
  534. Boolean flagDeal =actTaskService.isJudgeDeal(disclose);
  535. if (null==disclose.getPrecondition()||"".equals(disclose.getPrecondition())){
  536. if (flagItemCLose){
  537. if (null==disclose.getExplanationOfNecessity()||disclose.getExplanationOfNecessity().equals("")){
  538. s="必要性问题说明不能为空!";
  539. flag = true;
  540. }
  541. }
  542. if (flagDesign){
  543. if (null==disclose.getInconsistentDescription()||disclose.getExplanationOfNecessity().equals("")){
  544. s+=" 图纸现场不一致说明不能为空!";
  545. flag = true;
  546. }
  547. }
  548. if (flagDeal){
  549. if (null==disclose.getPolicyHandlingInstructions()||disclose.getPolicyHandlingInstructions().equals("")){
  550. s+=" 政策处理说明不能为空!";
  551. flag=true;
  552. }
  553. }
  554. if (flag){
  555. j.setSuccess(false);
  556. j.setMsg(s);
  557. return j;
  558. }
  559. }
  560. try {
  561. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  562. act.setComment(comment);
  563. actTaskService.auditSave3(act,disclose,flagDesign,flagItemCLose,flagDeal);
  564. } catch (UnsupportedEncodingException e) {
  565. e.printStackTrace();
  566. }
  567. j.setMsg("审批成功");
  568. return j;
  569. }
  570. /*
  571. 项目关闭:专职
  572. */
  573. @ResponseBody
  574. @RequestMapping(value = "speciallyTask")
  575. public AjaxJson speciallyTask(Act act,String fullName,String tuser,Construction construction) {
  576. AjaxJson j = new AjaxJson();
  577. try {
  578. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  579. act.setComment(comment);
  580. actTaskService.specially(act,fullName);
  581. } catch (UnsupportedEncodingException e) {
  582. e.printStackTrace();
  583. }
  584. j.setMsg("审批成功");
  585. return j;
  586. }/*
  587. 项目关闭:项目经理
  588. */
  589. @ResponseBody
  590. @RequestMapping(value = "managerFormTask")
  591. public AjaxJson managerFormTask(Act act,String fullName,String tuser,Construction construction) {
  592. AjaxJson j = new AjaxJson();
  593. try {
  594. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  595. act.setComment(comment);
  596. actTaskService.managerFormTask(act,fullName);
  597. } catch (UnsupportedEncodingException e) {
  598. e.printStackTrace();
  599. }
  600. j.setMsg("审批成功");
  601. return j;
  602. }
  603. /*
  604. 项目关闭:运行人员
  605. */
  606. @ResponseBody
  607. @RequestMapping(value = "memberTask")
  608. public AjaxJson memberTask(Act act,String fullTime,String tuser,Construction construction) {
  609. AjaxJson j = new AjaxJson();
  610. try {
  611. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  612. act.setComment(comment);
  613. actTaskService.addMember(act,fullTime);
  614. } catch (UnsupportedEncodingException e) {
  615. e.printStackTrace();
  616. }
  617. if ("yes".equals(act.getFlag())){
  618. j.setMsg("审批成功");
  619. }else {
  620. j.setMsg("驳回成功");
  621. }
  622. return j;
  623. }
  624. /*
  625. 项目关闭:系统专职
  626. */
  627. @ResponseBody
  628. @RequestMapping(value = "departmentTask")
  629. public AjaxJson departmentTask(Act act,String tuser,Construction construction) {
  630. AjaxJson j = new AjaxJson();
  631. try {
  632. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  633. act.setComment(comment);
  634. actTaskService.addDepartment(act);
  635. } catch (UnsupportedEncodingException e) {
  636. e.printStackTrace();
  637. }
  638. OaNotify oaNotify = new OaNotify();
  639. oaNotify.setType("1");
  640. oaNotify.setTitle("施工交底结束");
  641. oaNotify.setContent("施工交底结束");
  642. oaNotify.setStatus("1");
  643. oaNotify.setOaNotifyRecordIds("9fcadb62979e4ceab459867b37bf04bc");
  644. oaNotifyService.save(oaNotify);
  645. List<OaNotifyRecord> list = oaNotify.getOaNotifyRecordList();
  646. for(OaNotifyRecord o : list){
  647. //发送通知到客户端
  648. ServletContext context = SpringContextHolder
  649. .getBean(ServletContext.class);
  650. new SystemInfoSocketHandler().sendMessageToUser(UserUtils.get(o.getUser().getId()).getLoginName(), "收到一条新通知,请到我的通知查看!");
  651. }
  652. j.setMsg("审批成功;已经通知项目经理,施工单位");
  653. return j;
  654. }
  655. /**
  656. * 施工交底审批
  657. * @param act*/
  658. @ResponseBody
  659. @RequestMapping(value = "newAudit")
  660. public AjaxJson newAuditTask(Act act,String tuser,Construction construction) {
  661. AjaxJson j = new AjaxJson();
  662. try {
  663. String comment = URLDecoder.decode(act.getComment(), "UTF-8");
  664. act.setComment(comment);
  665. actTaskService.newAuditSave(act,tuser,construction);
  666. } catch (UnsupportedEncodingException e) {
  667. e.printStackTrace();
  668. }
  669. j.setMsg("审批成功");
  670. return j;
  671. }
  672. /**
  673. * 取回流程
  674. * @param taskId
  675. */
  676. @ResponseBody
  677. @RequestMapping(value = "callback")
  678. public AjaxJson callback(@Param("taskId") String taskId) {
  679. AjaxJson j = new AjaxJson();
  680. try {
  681. Map<String, Object> variables;
  682. // 取得当前任务
  683. HistoricTaskInstance currTask = historyService
  684. .createHistoricTaskInstanceQuery().taskId(taskId)
  685. .singleResult();
  686. // 取得流程实例
  687. ProcessInstance instance = runtimeService
  688. .createProcessInstanceQuery()
  689. .processInstanceId(currTask.getProcessInstanceId())
  690. .singleResult();
  691. if (instance == null) {
  692. j.setSuccess(false);
  693. j.setMsg("流程已经结束");
  694. return j;
  695. }
  696. variables=instance.getProcessVariables();
  697. // 取得流程定义
  698. ProcessDefinitionEntity definition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
  699. .getDeployedProcessDefinition(currTask
  700. .getProcessDefinitionId());
  701. if (definition == null) {
  702. j.setSuccess(false);
  703. j.setMsg("流程定义未找到");
  704. return j;
  705. }
  706. // 取得下一步活动
  707. ActivityImpl currActivity = ((ProcessDefinitionImpl) definition)
  708. .findActivity(currTask.getTaskDefinitionKey());
  709. List<PvmTransition> nextTransitionList = currActivity
  710. .getOutgoingTransitions();
  711. for (PvmTransition nextTransition : nextTransitionList) {
  712. PvmActivity nextActivity = nextTransition.getDestination();
  713. List<HistoricTaskInstance> completeTasks = historyService
  714. .createHistoricTaskInstanceQuery()
  715. .processInstanceId(instance.getId())
  716. .taskDefinitionKey(nextActivity.getId()).finished()
  717. .list();
  718. int finished = completeTasks.size();
  719. if (finished > 0) {
  720. j.setSuccess(false);
  721. j.setMsg("存在已经完成的下一步,流程不能取回");
  722. return j;
  723. }
  724. List<Task> nextTasks = taskService.createTaskQuery().processInstanceId(instance.getId())
  725. .taskDefinitionKey(nextActivity.getId()).list();
  726. for (Task nextTask : nextTasks) {
  727. //取活动,清除活动方向
  728. List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>();
  729. List<PvmTransition> pvmTransitionList = nextActivity
  730. .getOutgoingTransitions();
  731. for (PvmTransition pvmTransition : pvmTransitionList) {
  732. oriPvmTransitionList.add(pvmTransition);
  733. }
  734. pvmTransitionList.clear();
  735. //建立新方向
  736. ActivityImpl nextActivityImpl = ((ProcessDefinitionImpl) definition)
  737. .findActivity(nextTask.getTaskDefinitionKey());
  738. TransitionImpl newTransition = nextActivityImpl
  739. .createOutgoingTransition();
  740. newTransition.setDestination(currActivity);
  741. //完成任务
  742. taskService.complete(nextTask.getId(), variables);
  743. historyService.deleteHistoricTaskInstance(nextTask.getId());
  744. //恢复方向
  745. currActivity.getIncomingTransitions().remove(newTransition);
  746. List<PvmTransition> pvmTList = nextActivity
  747. .getOutgoingTransitions();
  748. pvmTList.clear();
  749. for (PvmTransition pvmTransition : oriPvmTransitionList) {
  750. pvmTransitionList.add(pvmTransition);
  751. }
  752. }
  753. }
  754. historyService.deleteHistoricTaskInstance(currTask.getId());
  755. j.setSuccess(true);
  756. j.setMsg("取回成功");
  757. return j;
  758. } catch (Exception e) {
  759. j.setSuccess(false);
  760. j.setMsg("流程取回失败,未知错误.");
  761. return j;
  762. }
  763. }
  764. /**
  765. * 根据实例编号查找下一个任务节点
  766. * @param procInstId :实例编号
  767. * @return
  768. */
  769. public String nextTaskDefinition(String procInstId){
  770. //流程标示
  771. String processDefinitionId = historyService.createHistoricProcessInstanceQuery().processInstanceId(procInstId).singleResult().getProcessDefinitionId();
  772. ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl)repositoryService).getDeployedProcessDefinition(processDefinitionId);
  773. //执行实例
  774. ExecutionEntity execution = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(procInstId).singleResult();
  775. //当前实例的执行到哪个节点
  776. if(execution == null){
  777. TaskDefinition[] taskDefinitions = {};
  778. taskDefinitions = def.getTaskDefinitions().values().toArray(taskDefinitions);
  779. return taskDefinitions[taskDefinitions.length -1].getKey();
  780. }else{
  781. return execution.getActivityId();
  782. }
  783. }
  784. }