FlowMainService.java 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  1. package com.idea.oa.flow2.service;
  2. import com.github.pagehelper.PageHelper;
  3. import com.github.pagehelper.PageInfo;
  4. import com.idea.oa.activiti.service.ProActiService;
  5. import com.idea.oa.apply.model.inout.AddConfirmResult;
  6. import com.idea.oa.apply.model.inout.OperaterManage;
  7. //import com.idea.oa.apply.service.ApplyOffWorkTimeService;
  8. //import com.idea.oa.apply.service.ApplyUseMoneyDetailService;
  9. import com.idea.oa.apply.util.constant.ConstantFlowType;
  10. import com.idea.oa.flow2.mapper.FlowMainExtendMapper;
  11. import com.idea.oa.flow2.mapper.FlowMainMapper;
  12. import com.idea.oa.flow2.model.*;
  13. import com.idea.oa.flow2.model.in.FlowMainIn;
  14. import com.idea.oa.flow2.model.out.FlowHistoryInfo;
  15. import com.idea.oa.flow2.model.out.IMGFlowHistoryInfo;
  16. import com.rockstar.common.base.BaseService;
  17. import com.rockstar.common.domain.AjaxResult;
  18. import com.rockstar.common.support.Convert;
  19. import com.rockstar.flow.service.FlowService;
  20. import com.rockstar.frame.model.FrameRoleData;
  21. import com.rockstar.frame.model.FrameUser;
  22. import com.rockstar.frame.model.extend.DateTrans;
  23. import com.rockstar.frame.model.extend.Tablepar;
  24. import com.rockstar.frame.service.FrameUserService;
  25. import com.rockstar.shiro.util.ShiroUtils;
  26. import com.rockstar.util.UUIDUtils;
  27. import org.activiti.bpmn.model.UserTask;
  28. import org.activiti.engine.TaskService;
  29. import org.activiti.engine.task.Task;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.stereotype.Service;
  32. import org.springframework.util.StringUtils;
  33. import java.math.BigDecimal;
  34. import java.math.MathContext;
  35. import java.util.*;
  36. @Service
  37. public class FlowMainService implements BaseService<FlowMain, FlowMainExample> {
  38. // @Autowired
  39. // private ApplyOffWorkTimeService applyOffWorkTimeService;
  40. // @Autowired
  41. // private ApplyUseMoneyDetailService applyUseMoneyDetailService;
  42. @Autowired
  43. public FrameUserService frameUserService;
  44. @Autowired
  45. private TaskService taskService;
  46. @Autowired
  47. private FlowService flowService;
  48. @Autowired
  49. private FlowMainPushService flowMainPushService;
  50. //文件mapper
  51. @Autowired
  52. private FlowMainMapper flowMainMapper;
  53. @Autowired
  54. private FlowMainExtendMapper flowMainExtendMapper;
  55. @Autowired
  56. private ProActiService proActiService;
  57. @Autowired
  58. private FlowMainLogService flowMainLogService;
  59. @Autowired
  60. private FlowMainCcService flowMainCcService;
  61. /**
  62. * 添加审核结果
  63. * 根据不同的状态值confirmResult判断是 1:审核通过,转下一步;2:退回发起人;3:退回上节点;4:结束流程(不同意,并且结束流程);
  64. *
  65. * @return string 如果为ok就是成功,不然就是失败message
  66. */
  67. public String doConfirmResult(AddConfirmResult addConfirmResult, String deploymentid, String constantFlowType, FlowMainPush flowMainPush, HashMap<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
  68. if (addConfirmResult.getConfirmResult() == null) {
  69. return "没有获取到confirmResult值";
  70. }
  71. // String deploymentid = ConstantFlowType.USE_MONEY_DEPLOYMENTID;
  72. // String constantFlowType = ConstantFlowType.USE_MONEY;
  73. OperaterManage operaterManage = new OperaterManage();
  74. FrameUser frameUser = new FrameUser();
  75. try {
  76. frameUser.setId(ShiroUtils.getUser().getId());
  77. } catch (Exception e) {
  78. frameUser.setId(addConfirmResult.getOperaterId());
  79. }
  80. operaterManage.setUser(frameUser);
  81. // FlowMainPush flowMainPush = flowMainPushService.selectByPrimaryKey(addConfirmResult.getFlowMainPushId());
  82. if (!flowMainPush.getStatus().equals(0)) {
  83. if (flowMainPush.getStatus().equals(1)) {
  84. return "已经在" + flowMainPush.getUpdatedAt() + "时操作过了,请重新确认";
  85. } else if (flowMainPush.getStatus().equals(2)) {
  86. return "已经在" + flowMainPush.getUpdatedAt() + "时由其他审核人操作过了,请重新确认";
  87. }
  88. }
  89. {//提前逻辑删除推送信息,保证数据不会因为同步操作出现冲突
  90. FlowMainPush updateFlowMainPush = new FlowMainPush();
  91. updateFlowMainPush.setId(flowMainPush.getId());
  92. updateFlowMainPush.setStatus(1);
  93. updateFlowMainPush.setUpdatedAt(new Date());
  94. updateFlowMainPush.setUpdatedBy(operaterManage.getUser().getId());
  95. flowMainPushService.updateByPrimaryKeySelective(updateFlowMainPush);
  96. }
  97. FlowMain flowMain = this.selectByPrimaryKey(flowMainPush.getFlowMainId());
  98. //当前任务流程 目的是获取节点名称,存起来nodeName
  99. String nodeName = flowMainPush.getNodeName() == null ? proActiService.getNodeName(flowMainPush) : flowMainPush.getNodeName();
  100. if (nodeName == null) {
  101. return "异常:没有找到对应的任务...请通知管理员";
  102. }
  103. String mypushUserKey = flowMainPush.getPushUserKey();
  104. // flowMain.
  105. // Map<String, Object> conditionMap
  106. //审核通过,转下一步
  107. boolean isEnd = false;//是否审核到最后一步了
  108. if (addConfirmResult.getConfirmResult().equals("1")) {//审核通过 ok
  109. {// 发起流程引擎操作 并查看下一节点的操作要求
  110. //1.如果当前角色是自己,就进行正常的审核流程
  111. //2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程
  112. Map<String, String> stringStringMap = proActiService.passToRunTask(flowMainPush, deploymentid, flowMainPush.getFlowMainId(), conditionMap);
  113. if (stringStringMap == null) {
  114. return "流程引擎开启失败,请查看原因!";
  115. }
  116. isEnd = stringStringMap.get("isEnd") == null ? false : true;
  117. }
  118. {
  119. //存入流程日志表的id
  120. String flowMainLogUuid = UUIDUtils.middleUUID();
  121. //1修改主表状态 ok
  122. {
  123. FlowMain flowMain1 = new FlowMain();
  124. flowMain1.setId(flowMainPush.getFlowMainId());
  125. if (isEnd) {
  126. flowMain1.setFlowStatus(3);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  127. flowMain1.setFlowResult(1); //审核结果0无状态,1审核通过结束,2审核不通过结束
  128. } else {
  129. flowMain1.setFlowStatus(1);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  130. flowMain1.setFlowResult(0); //审核结果0无状态,1审核通过结束,2审核不通过结束
  131. }
  132. flowMain1.setLastMainLogId(flowMainLogUuid);
  133. flowMain1.setUpdatedAt(new Date());
  134. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  135. this.updateByPrimaryKeySelective(flowMain1);
  136. }
  137. //2添加日志 ok
  138. FlowMainLog flowMainLog = new FlowMainLog();
  139. {
  140. flowMainLog.setId(flowMainLogUuid);
  141. flowMainLog.setFlowMainId(flowMain.getId());
  142. flowMainLog.setFormId(flowMain.getFormId());
  143. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  144. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  145. flowMainLog.setAuditResult("1");// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  146. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  147. if (isEnd) {
  148. flowMainLog.setAuditType("2");
  149. } else {
  150. flowMainLog.setAuditType("1");
  151. }
  152. flowMainLog.setFlowType(constantFlowType);
  153. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  154. {// 需要工作流引擎的支持
  155. flowMainLog.setFlowId(flowMain.getFlowId());
  156. flowMainLog.setTaskId(flowMainPush.getTaskId());
  157. flowMainLog.setNodeName(nodeName);
  158. flowMainLog.setPushUserKey(mypushUserKey);
  159. }
  160. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  161. // 因为感觉用不到,暂时不放进去
  162. // flowMainLog.setNextPersons();
  163. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  164. flowMainLog.setCcList(null);
  165. flowMainLog.setCreatedAt(new Date());
  166. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  167. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  168. flowMainLog.setStatus(0);
  169. flowMainLogService.insertWithoutId(flowMainLog);
  170. }
  171. // 3存入抄送人信息 ok
  172. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  173. String[] split = addConfirmResult.getCcList().split(",");
  174. for (String ccId : split) {
  175. if (!StringUtils.isEmpty(ccId)) {
  176. FlowMainCc flowMainCc = new FlowMainCc();
  177. flowMainCc.setFlowMainId(flowMain.getId());
  178. flowMainCc.setCcUser(ccId);
  179. //选择抄送人时的记录表id(flow_main_log):例如:112122
  180. flowMainCc.setMainLogIds(flowMainLog.getId());
  181. flowMainCc.setUpdatedAt(new Date());
  182. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  183. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  184. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  185. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  186. flowMainCc.setStatus(0);
  187. flowMainCcService.insert(flowMainCc);
  188. }
  189. }
  190. }
  191. //4.0判断是否存在串并联并修改推送状态 逻辑删除旧的推送人
  192. {
  193. //todo推送类型1单流程推送,2串联推送,3并联推送
  194. Integer pushType = flowMainPush.getPushType();
  195. //逻辑删除本推送
  196. {
  197. // FlowMainPush updateFlowMainPush = new FlowMainPush();
  198. // updateFlowMainPush.setId(flowMainPush.getId());
  199. // updateFlowMainPush.setStatus(1);
  200. // updateFlowMainPush.setUpdatedAt(new Date());
  201. // updateFlowMainPush.setUpdatedBy(operaterManage.getUser().getId());
  202. // flowMainPushService.updateByPrimaryKeySelective(updateFlowMainPush);
  203. }
  204. if (pushType.equals(1) || pushType.equals(2)) {
  205. //只要逻辑删除本推送
  206. } else if (pushType.equals(3)) {
  207. //要逻辑删除自己和其他推送
  208. //将其他并联推送的人员推送状态status改成2状态值
  209. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  210. }
  211. }
  212. //4添加新的推送人员
  213. if (!isEnd) {//查看各个任务
  214. List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  215. // taskService.createTaskQuery().processInstanceId();
  216. //查看总的数据流程
  217. List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  218. for (Task task : listTask) {
  219. {
  220. //获取推送类型1单流程推送,2串联推送,3并联推送',
  221. Integer pushType = null;
  222. //'推送时彭总给的key值',
  223. String pushUserKey = null;
  224. UserTask myUserTask = null;
  225. {
  226. String taskDefinitionKey = task.getTaskDefinitionKey();
  227. for (int i = 0; i < TaskList.size(); i++) {
  228. if (TaskList.get(i).getId().equals(taskDefinitionKey)) {
  229. myUserTask = TaskList.get(i);
  230. break;
  231. }
  232. }
  233. //判断是否存在串并联并修改推送状态
  234. if (myUserTask != null) {
  235. pushUserKey = myUserTask.getCandidateGroups().get(0);
  236. if (listTask.size() > 1) {
  237. String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_");
  238. if (s1.length >= 5) {
  239. String pushTypeNum = s1[4];
  240. if ("0".equals(pushTypeNum)) {
  241. pushType = 2;
  242. } else if ("1".equals(pushTypeNum)) {
  243. pushType = 3;
  244. }
  245. }
  246. } else {
  247. pushType = 1;
  248. }
  249. }
  250. }
  251. FlowMainPush newflowMainPush = new FlowMainPush();
  252. newflowMainPush.setFlowMainId(flowMain.getId());
  253. newflowMainPush.setFormId(flowMain.getFormId());
  254. {// 需要工作流引擎的支持
  255. newflowMainPush.setPushUser(task.getAssignee());//推送人id'
  256. newflowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  257. newflowMainPush.setNodeName(myUserTask.getName());
  258. newflowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  259. newflowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  260. newflowMainPush.setFlowType(constantFlowType);
  261. newflowMainPush.setFlowPost(task.getAssignee());
  262. ////2023年5月10日 修改成上面的了 张洮
  263. // newflowMainPush.setFlowPost(operaterManage.getUser().getId());
  264. newflowMainPush.setFlowId(flowMain.getFlowId());
  265. newflowMainPush.setTaskId(task.getId());
  266. }
  267. newflowMainPush.setUpMainLogId(flowMainLog.getId());
  268. newflowMainPush.setUpdatedAt(new Date());
  269. newflowMainPush.setCreatedAt(newflowMainPush.getUpdatedAt());
  270. newflowMainPush.setCreatedBy(operaterManage.getUser().getId());
  271. newflowMainPush.setUpdatedBy(newflowMainPush.getCreatedBy());
  272. newflowMainPush.setGroupId(operaterManage.getUser().getGroupId());
  273. newflowMainPush.setStatus(0);
  274. flowMainPushService.insert(newflowMainPush);
  275. }
  276. }
  277. }
  278. }
  279. } else if (addConfirmResult.getConfirmResult().equals("2")) {//退回发起人 ok
  280. {// 退回发起人
  281. isEnd = true;
  282. // flowService.deleteInstance(flowMain.getFlowId(), "退回发起人");
  283. //当前审核人/委托人代表的用户id
  284. String myFrameUserId = proActiService.getMyFrameUserId(flowMainPush);
  285. if (myFrameUserId == null) {
  286. return null;
  287. }
  288. //当前审核人/委托人代表的用户
  289. FrameUser myFrameUser = frameUserService.selectByPrimaryKey(myFrameUserId);
  290. FrameUser targetUser = frameUserService.selectByPrimaryKey(flowMain.getApplyUser());
  291. // FrameUser currUser = operaterManage.getUser();
  292. boolean yes = flowService.runTask(flowMainPush.getTaskId(), null, "no", "退回发起人", targetUser, myFrameUser, null);
  293. }
  294. {
  295. //存入流程日志表的id
  296. String flowMainLogUuid = UUIDUtils.middleUUID();
  297. //1修改主表状态
  298. {
  299. FlowMain flowMain1 = new FlowMain();
  300. flowMain1.setId(flowMainPush.getFlowMainId());
  301. flowMain1.setFlowStatus(2);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  302. flowMain1.setLastMainLogId(flowMainLogUuid);
  303. flowMain1.setUpdatedAt(new Date());
  304. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  305. this.updateByPrimaryKeySelective(flowMain1);
  306. }
  307. //2添加日志 ok
  308. FlowMainLog flowMainLog = new FlowMainLog();
  309. {
  310. flowMainLog.setId(flowMainLogUuid);
  311. flowMainLog.setFlowMainId(flowMain.getId());
  312. flowMainLog.setFormId(flowMain.getFormId());
  313. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  314. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  315. flowMainLog.setAuditResult("2");// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  316. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  317. flowMainLog.setAuditType("1");
  318. flowMainLog.setFlowType(constantFlowType);
  319. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  320. {// 需要工作流引擎的支持
  321. flowMainLog.setFlowId(flowMain.getFlowId());
  322. flowMainLog.setTaskId(flowMainPush.getTaskId());
  323. flowMainLog.setNodeName(nodeName);
  324. flowMainLog.setPushUserKey(mypushUserKey);
  325. }
  326. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  327. // 因为感觉用不到,暂时不放进去
  328. // flowMainLog.setNextPersons();
  329. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  330. flowMainLog.setCcList(null);
  331. flowMainLog.setCreatedAt(new Date());
  332. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  333. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  334. flowMainLog.setStatus(0);
  335. flowMainLogService.insertWithoutId(flowMainLog);
  336. }
  337. //2.1添加抄送
  338. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  339. String[] split = addConfirmResult.getCcList().split(",");
  340. for (String ccId : split) {
  341. if (!StringUtils.isEmpty(ccId)) {
  342. FlowMainCc flowMainCc = new FlowMainCc();
  343. flowMainCc.setFlowMainId(flowMain.getId());
  344. flowMainCc.setCcUser(ccId);
  345. //选择抄送人时的记录表id(flow_main_log):例如:112122
  346. flowMainCc.setMainLogIds(flowMainLog.getId());
  347. flowMainCc.setUpdatedAt(new Date());
  348. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  349. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  350. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  351. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  352. flowMainCc.setStatus(0);
  353. flowMainCcService.insert(flowMainCc);
  354. }
  355. }
  356. }
  357. //3判断是否存在串并联并修改推送状态 逻辑删除旧的推送人
  358. {
  359. //todo推送类型1单流程推送,2串联推送,3并联推送
  360. Integer pushType = flowMainPush.getPushType();
  361. //逻辑删除本推送
  362. {
  363. // FlowMainPush updateFlowMainPush = new FlowMainPush();
  364. // updateFlowMainPush.setId(flowMainPush.getId());
  365. // updateFlowMainPush.setStatus(1);
  366. // updateFlowMainPush.setUpdatedAt(new Date());
  367. // updateFlowMainPush.setUpdatedBy(operaterManage.getUser().getId());
  368. // flowMainPushService.updateByPrimaryKeySelective(updateFlowMainPush);
  369. }
  370. if (pushType.equals(1) || pushType.equals(2)) {
  371. //只要逻辑删除本推送
  372. } else if (pushType.equals(3)) {
  373. //要逻辑删除自己和其他推送
  374. //将其他并联推送的人员推送状态status改成2状态值
  375. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  376. }
  377. }
  378. //4添加推送人(因为退回发起人之后 发起人不需要再审核,所以改成推送人就不要了,下面的注释掉了)
  379. {//查看各个任务
  380. // List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  381. //// taskService.createTaskQuery().processInstanceId();
  382. // //查看总的数据流程
  383. // List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  384. // for (Task task : listTask) {
  385. // UserTask myUserTask = null;
  386. // {
  387. // String taskDefinitionKey = task.getTaskDefinitionKey();
  388. // for (int i = 0; i < TaskList.size(); i++) {
  389. // if (TaskList.get(i).getId().equals(taskDefinitionKey)) {
  390. // myUserTask = TaskList.get(i);
  391. // break;
  392. // }
  393. // }
  394. // //判断是否存在串并联并修改推送状态
  395. // //'推送时彭总给的key值',
  396. // String pushUserKey = null;
  397. // if (myUserTask != null) {
  398. // pushUserKey = myUserTask.getCandidateGroups().get(0);
  399. // }
  400. // //'推送类型1单流程推送,2串联推送,3并联推送',
  401. // Integer pushType = 1;
  402. //// if (myUserTask != null) {
  403. //// pushUserKey = myUserTask.getCandidateGroups().get(0);
  404. //// if (listTask.size() > 1) {
  405. //// String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_");
  406. //// if (s1.length >= 5) {
  407. //// String pushTypeNum = s1[4];
  408. //// if ("0".equals(pushTypeNum)) {
  409. //// pushType = 2;
  410. //// } else if ("1".equals(pushTypeNum)) {
  411. //// pushType = 3;
  412. //// }
  413. ////
  414. //// }
  415. //// } else {
  416. //// pushType = 1;
  417. //// }
  418. //// }
  419. // FlowMainPush newflowMainPush = new FlowMainPush();
  420. // newflowMainPush.setFlowMainId(flowMain.getId());
  421. // newflowMainPush.setFormId(flowMain.getFormId());
  422. // {// 需要工作流引擎的支持
  423. // newflowMainPush.setPushUser(task.getAssignee());//推送人id'
  424. // newflowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  425. // newflowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  426. // newflowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  427. // newflowMainPush.setFlowType(constantFlowType);
  428. // newflowMainPush.setFlowPost(operaterManage.getUser().getId());
  429. // newflowMainPush.setFlowId(flowMain.getFlowId());
  430. // newflowMainPush.setTaskId(task.getId());
  431. // }
  432. // newflowMainPush.setUpMainLogId(flowMainLog.getId());
  433. // newflowMainPush.setUpdatedAt(new Date());
  434. // newflowMainPush.setCreatedAt(newflowMainPush.getUpdatedAt());
  435. // newflowMainPush.setCreatedBy(operaterManage.getUser().getId());
  436. // newflowMainPush.setUpdatedBy(newflowMainPush.getCreatedBy());
  437. // newflowMainPush.setGroupId(operaterManage.getUser().getGroupId());
  438. // newflowMainPush.setStatus(0);
  439. // flowMainPushService.insert(newflowMainPush);
  440. // }
  441. // }
  442. }
  443. }
  444. } else if (addConfirmResult.getConfirmResult().equals("3")) {//退回上节点
  445. FrameUser targetUser = null;
  446. {// 发起流程引擎操作
  447. //当前审核人/委托人代表的用户id
  448. String myFrameUserId = proActiService.getMyFrameUserId(flowMainPush);
  449. if (myFrameUserId == null) {
  450. return null;
  451. }
  452. //当前审核人/委托人代表的用户
  453. FrameUser myFrameUser = frameUserService.selectByPrimaryKey(myFrameUserId);
  454. FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId());
  455. while ("4".equals(flowMainLog.getAuditResult())) {
  456. flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainLog.getUpMainLogId());
  457. }
  458. targetUser = frameUserService.selectByPrimaryKey(flowMainLog.getAuditUser());
  459. // FrameUser currUser = operaterManage.getUser();
  460. boolean yes = flowService.runTask(flowMainPush.getTaskId(), null, "back", "退回上节点", targetUser, myFrameUser, null);
  461. }
  462. {
  463. //存入流程日志表的id
  464. String flowMainLogUuid = UUIDUtils.middleUUID();
  465. //1修改主表状态
  466. {
  467. FlowMain flowMain1 = new FlowMain();
  468. flowMain1.setId(flowMainPush.getFlowMainId());
  469. flowMain1.setFlowStatus(1);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  470. flowMain1.setLastMainLogId(flowMainLogUuid);
  471. flowMain1.setUpdatedAt(new Date());
  472. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  473. this.updateByPrimaryKeySelective(flowMain1);
  474. }
  475. //2添加日志 ok
  476. FlowMainLog flowMainLog = new FlowMainLog();
  477. {
  478. flowMainLog.setId(flowMainLogUuid);
  479. flowMainLog.setFlowMainId(flowMain.getId());
  480. flowMainLog.setFormId(flowMain.getFormId());
  481. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  482. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  483. flowMainLog.setAuditResult("3");// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  484. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  485. flowMainLog.setAuditType("1");
  486. flowMainLog.setFlowType(constantFlowType);
  487. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  488. {// 需要工作流引擎的支持
  489. flowMainLog.setFlowId(flowMain.getFlowId());
  490. flowMainLog.setTaskId(flowMainPush.getTaskId());
  491. flowMainLog.setNodeName(nodeName);
  492. flowMainLog.setPushUserKey(mypushUserKey);
  493. }
  494. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  495. // 因为感觉用不到,暂时不放进去
  496. // flowMainLog.setNextPersons();
  497. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  498. flowMainLog.setCcList(null);
  499. flowMainLog.setCreatedAt(new Date());
  500. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  501. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  502. flowMainLog.setStatus(0);
  503. flowMainLogService.insertWithoutId(flowMainLog);
  504. }
  505. //2.1添加抄送
  506. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  507. String[] split = addConfirmResult.getCcList().split(",");
  508. for (String ccId : split) {
  509. if (!StringUtils.isEmpty(ccId)) {
  510. FlowMainCc flowMainCc = new FlowMainCc();
  511. flowMainCc.setFlowMainId(flowMain.getId());
  512. flowMainCc.setCcUser(ccId);
  513. //选择抄送人时的记录表id(flow_main_log):例如:112122
  514. flowMainCc.setMainLogIds(flowMainLog.getId());
  515. flowMainCc.setUpdatedAt(new Date());
  516. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  517. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  518. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  519. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  520. flowMainCc.setStatus(0);
  521. flowMainCcService.insert(flowMainCc);
  522. }
  523. }
  524. }
  525. //3判断是否存在串并联并修改推送状态 逻辑删除旧的推送人
  526. {
  527. //todo推送类型1单流程推送,2串联推送,3并联推送
  528. Integer pushType = flowMainPush.getPushType();
  529. //逻辑删除本推送
  530. {
  531. // FlowMainPush updateFlowMainPush = new FlowMainPush();
  532. // updateFlowMainPush.setId(flowMainPush.getId());
  533. // updateFlowMainPush.setStatus(1);
  534. // updateFlowMainPush.setUpdatedAt(new Date());
  535. // updateFlowMainPush.setUpdatedBy(operaterManage.getUser().getId());
  536. // flowMainPushService.updateByPrimaryKeySelective(updateFlowMainPush);
  537. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  538. }
  539. }
  540. //4添加新的推送人员
  541. {//查看各个任务
  542. List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  543. // taskService.createTaskQuery().processInstanceId();
  544. //查看总的数据流程
  545. List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  546. for (Task task : listTask) {
  547. UserTask myUserTask = null;
  548. {
  549. String taskDefinitionKey = task.getTaskDefinitionKey();
  550. for (int i = 0; i < TaskList.size(); i++) {
  551. if (TaskList.get(i).getId().equals(taskDefinitionKey)) {
  552. myUserTask = TaskList.get(i);
  553. break;
  554. }
  555. }
  556. //判断是否存在串并联并修改推送状态
  557. //'推送时彭总给的key值',
  558. String pushUserKey = null;
  559. if (myUserTask != null) {
  560. pushUserKey = myUserTask.getCandidateGroups().get(0);
  561. }
  562. //'推送类型1单流程推送,2串联推送,3并联推送',
  563. Integer pushType = 1;
  564. // if (myUserTask != null) {
  565. // pushUserKey = myUserTask.getCandidateGroups().get(0);
  566. // if (listTask.size() > 1) {
  567. // String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_");
  568. // if (s1.length >= 5) {
  569. // String pushTypeNum = s1[4];
  570. // if ("0".equals(pushTypeNum)) {
  571. // pushType = 2;
  572. // } else if ("1".equals(pushTypeNum)) {
  573. // pushType = 3;
  574. // }
  575. //
  576. // }
  577. // } else {
  578. // pushType = 1;
  579. // }
  580. // }
  581. FlowMainPush newflowMainPush = new FlowMainPush();
  582. newflowMainPush.setFlowMainId(flowMain.getId());
  583. newflowMainPush.setFormId(flowMain.getFormId());
  584. {// 需要工作流引擎的支持
  585. if (!task.getAssignee().equals(targetUser.getId())) {
  586. continue;
  587. }
  588. newflowMainPush.setPushUser(task.getAssignee());//推送人id'
  589. newflowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  590. newflowMainPush.setNodeName(myUserTask.getName());
  591. newflowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  592. newflowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  593. newflowMainPush.setFlowType(constantFlowType);
  594. newflowMainPush.setFlowPost(task.getAssignee());
  595. ////2023年5月10日 修改成上面的了 张洮
  596. // newflowMainPush.setFlowPost(operaterManage.getUser().getId());
  597. newflowMainPush.setFlowId(flowMain.getFlowId());
  598. newflowMainPush.setTaskId(task.getId());
  599. }
  600. newflowMainPush.setUpMainLogId(flowMainLog.getId());
  601. newflowMainPush.setUpdatedAt(new Date());
  602. newflowMainPush.setCreatedAt(newflowMainPush.getUpdatedAt());
  603. newflowMainPush.setCreatedBy(operaterManage.getUser().getId());
  604. newflowMainPush.setUpdatedBy(newflowMainPush.getCreatedBy());
  605. newflowMainPush.setGroupId(operaterManage.getUser().getGroupId());
  606. newflowMainPush.setStatus(0);
  607. flowMainPushService.insert(newflowMainPush);
  608. }
  609. }
  610. }
  611. }
  612. } else if (addConfirmResult.getConfirmResult().equals("4")) {//结束流程 ok
  613. isEnd = true;
  614. {// 发起流程引擎操作 并结束该流程
  615. flowService.deleteInstance(flowMain.getFlowId(), "结束流程");
  616. }
  617. {
  618. //存入流程日志表的id
  619. String flowMainLogUuid = UUIDUtils.middleUUID();
  620. //1修改主表状态
  621. {
  622. FlowMain flowMain1 = new FlowMain();
  623. flowMain1.setId(flowMainPush.getFlowMainId());
  624. flowMain1.setFlowStatus(3);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  625. flowMain1.setFlowResult(2); //审核结果0无状态,1审核通过结束,2审核不通过结束
  626. flowMain1.setLastMainLogId(flowMainLogUuid);
  627. flowMain1.setUpdatedAt(new Date());
  628. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  629. this.updateByPrimaryKeySelective(flowMain1);
  630. }
  631. //2添加日志 ok
  632. FlowMainLog flowMainLog = new FlowMainLog();
  633. {
  634. flowMainLog.setId(flowMainLogUuid);
  635. flowMainLog.setFlowMainId(flowMain.getId());
  636. flowMainLog.setFormId(flowMain.getFormId());
  637. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  638. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  639. flowMainLog.setAuditResult("5");// `audit_result` varchar(4) DEFAULT NULL COMMENT 审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,5,不同意且结束流程,null没有审核)',
  640. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  641. flowMainLog.setAuditType("2");
  642. flowMainLog.setFlowType(constantFlowType);
  643. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  644. {// 需要工作流引擎的支持
  645. flowMainLog.setFlowId(flowMain.getFlowId());
  646. flowMainLog.setTaskId(flowMainPush.getTaskId());
  647. flowMainLog.setNodeName(nodeName);
  648. flowMainLog.setPushUserKey(mypushUserKey);
  649. }
  650. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  651. // 因为感觉用不到,暂时不放进去
  652. // flowMainLog.setNextPersons();
  653. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  654. flowMainLog.setCcList(null);
  655. flowMainLog.setCreatedAt(new Date());
  656. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  657. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  658. flowMainLog.setStatus(0);
  659. flowMainLogService.insertWithoutId(flowMainLog);
  660. }
  661. //3 存入抄送人信息
  662. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  663. String[] split = addConfirmResult.getCcList().split(",");
  664. for (String ccId : split) {
  665. if (!StringUtils.isEmpty(ccId)) {
  666. FlowMainCc flowMainCc = new FlowMainCc();
  667. flowMainCc.setFlowMainId(flowMain.getId());
  668. flowMainCc.setCcUser(ccId);
  669. //选择抄送人时的记录表id(flow_main_log):例如:112122
  670. flowMainCc.setMainLogIds(flowMainLog.getId());
  671. flowMainCc.setUpdatedAt(new Date());
  672. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  673. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  674. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  675. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  676. flowMainCc.setStatus(0);
  677. flowMainCcService.insert(flowMainCc);
  678. }
  679. }
  680. }
  681. //4.0逻辑删除旧的推送人
  682. {
  683. //todo推送类型1单流程推送,2串联推送,3并联推送
  684. Integer pushType = flowMainPush.getPushType();
  685. //逻辑删除本推送
  686. {
  687. // FlowMainPush updateFlowMainPush = new FlowMainPush();
  688. // updateFlowMainPush.setId(flowMainPush.getId());
  689. // updateFlowMainPush.setStatus(1);
  690. // updateFlowMainPush.setUpdatedAt(new Date());
  691. // updateFlowMainPush.setUpdatedBy(operaterManage.getUser().getId());
  692. // flowMainPushService.updateByPrimaryKeySelective(updateFlowMainPush);
  693. }
  694. if (pushType.equals(1) || pushType.equals(2)) {
  695. //只要逻辑删除本推送
  696. } else if (pushType.equals(3)) {
  697. //要逻辑删除自己和其他推送
  698. //将其他并联推送的人员推送状态status改成2状态值
  699. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  700. }
  701. }
  702. }
  703. }
  704. if (isEnd) {
  705. return "ok_end";
  706. } else {
  707. return "ok_noEnd";
  708. }
  709. }
  710. /**
  711. * 通用方法,加载到流程业务模块
  712. *
  713. * @return
  714. */
  715. public AjaxResult doFlowMain(String ApplyTheme, String recordId, String recordRemark, String recordCcList, String processdefine, String deploymentid, Map<String, Object> conditionMap, String constantFlowTypeNAME, String constantFlowType,FrameUser currUser) throws com.rockstar.flow.exception.FlowException {
  716. // 存入流程主表 ok
  717. FlowMain flowMain = new FlowMain();
  718. flowMain.setId(UUIDUtils.middleUUID());
  719. // 进入流程引擎,开始启动流程
  720. String processInstanceId = null;
  721. // 判断启动申请后是否结束
  722. boolean isEnd = false;
  723. {
  724. //启动流程引擎
  725. Map<String, String> stringStringMap = proActiService.startTask(processdefine, deploymentid, flowMain.getId(),currUser, conditionMap);
  726. if (stringStringMap == null) {
  727. return AjaxResult.error("流程引擎开启失败,请查看原因!");
  728. }
  729. processInstanceId = stringStringMap.get("processInstanceId");
  730. if (stringStringMap.get("isEnd") != null) {
  731. isEnd = true;
  732. }
  733. }
  734. //存入流程日志表的id
  735. String flowMainLogUuid = UUIDUtils.middleUUID();
  736. {
  737. // conditionMap
  738. // if (conditionMap!=null) {
  739. // Object conditionMapString = JSONObject.toJSON(conditionMap);
  740. // flowMain.setConditionMap(conditionMapString.toString());
  741. // }
  742. // 关于@客户名称@项目名称@供应商名称@付款名称的付款申请单
  743. flowMain.setApplyTheme(ApplyTheme);
  744. flowMain.setFormId(recordId);
  745. flowMain.setApplyUser(currUser.getId());
  746. flowMain.setDeptId(currUser.getDepartment());
  747. //todo 判断是否结束
  748. if (isEnd) {
  749. flowMain.setFlowStatus(3);//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  750. flowMain.setFlowResult(1); //审核结果0无状态,1审核通过结束,2审核不通过结束
  751. } else {
  752. flowMain.setFlowStatus(1);//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  753. flowMain.setFlowResult(0); //审核结果0无状态,1审核通过结束,2审核不通过结束
  754. }
  755. flowMain.setReturnStatus(0);//'0/null无状态,1已撤回并且已重新发起',
  756. flowMain.setCcList(null);
  757. flowMain.setFlowName(constantFlowTypeNAME);
  758. flowMain.setFlowType(constantFlowType);
  759. //当前流程邮递操作人(frame_user)id 去除岗位的设定
  760. flowMain.setFlowPost(currUser.getId());
  761. {// 需要工作流引擎的支持
  762. flowMain.setFlowId(processInstanceId);
  763. flowMain.setTaskId(null);
  764. }
  765. flowMain.setLastMainLogId(flowMainLogUuid);
  766. flowMain.setUpdatedAt(new Date());
  767. flowMain.setCreatedAt(flowMain.getUpdatedAt());
  768. flowMain.setCreatedBy(currUser.getId());
  769. flowMain.setUpdatedBy(flowMain.getCreatedBy());
  770. flowMain.setGroupId(currUser.getGroupId());
  771. flowMain.setStatus(0);
  772. if (!StringUtils.isEmpty(recordRemark)) {
  773. flowMain.setRemark(recordRemark);
  774. }
  775. this.insertWithoutId(flowMain);
  776. }
  777. // 存入流程日志表 ok
  778. FlowMainLog flowMainLog = new FlowMainLog();
  779. {
  780. flowMainLog.setId(flowMainLogUuid);
  781. flowMainLog.setFlowMainId(flowMain.getId());
  782. flowMainLog.setFormId(recordId);
  783. flowMainLog.setAuditUser(currUser.getId());
  784. //todo 判断是否结束
  785. if (isEnd) {
  786. flowMainLog.setAuditType("2"); //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  787. flowMainLog.setAuditContent("自审通过");
  788. flowMainLog.setAuditResult("1");
  789. } else {
  790. flowMainLog.setAuditType("0"); //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  791. flowMainLog.setAuditContent(null);
  792. flowMainLog.setAuditResult(null);
  793. }
  794. flowMainLog.setFlowType(constantFlowType);
  795. flowMainLog.setFlowPost(currUser.getId());
  796. {// 需要工作流引擎的支持
  797. flowMainLog.setFlowId(processInstanceId);
  798. flowMainLog.setTaskId(null);
  799. flowMainLog.setNodeName(ConstantFlowType.nodeKeysName.get(1));
  800. flowMainLog.setPushUserKey(ConstantFlowType.nodeKeysName.get(11));
  801. }
  802. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  803. // 因为感觉用不到,暂时不放进去
  804. // flowMainLog.setNextPersons();
  805. flowMainLog.setUpMainLogId(null);
  806. flowMainLog.setCcList(null);
  807. flowMainLog.setCreatedAt(new Date());
  808. flowMainLog.setCreatedBy(currUser.getId());
  809. flowMainLog.setGroupId(currUser.getGroupId());
  810. flowMainLog.setStatus(0);
  811. flowMainLogService.insertWithoutId(flowMainLog);
  812. }
  813. // 存入抄送人信息 ok
  814. if (!StringUtils.isEmpty(recordCcList)) {
  815. String[] split = recordCcList.split(",");
  816. for (String ccId : split) {
  817. if (!StringUtils.isEmpty(ccId)) {
  818. FlowMainCc flowMainCc = new FlowMainCc();
  819. flowMainCc.setFlowMainId(flowMain.getId());
  820. flowMainCc.setCcUser(ccId);
  821. //选择抄送人时的记录表id(flow_main_log):例如:112122
  822. flowMainCc.setMainLogIds(flowMainLog.getId());
  823. flowMainCc.setUpdatedAt(new Date());
  824. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  825. flowMainCc.setCreatedBy(currUser.getId());
  826. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  827. flowMainCc.setGroupId(currUser.getGroupId());
  828. flowMainCc.setStatus(0);
  829. flowMainCcService.insert(flowMainCc);
  830. }
  831. }
  832. }
  833. // 存入推送人
  834. //查看各个任务
  835. List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  836. List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  837. for (Task task : listTask) {
  838. UserTask myUserTask = null;
  839. {
  840. String taskDefinitionKey = task.getTaskDefinitionKey();
  841. for (int i = 0; i < TaskList.size(); i++) {
  842. if (TaskList.get(i).getId().equals(taskDefinitionKey)) {
  843. myUserTask = TaskList.get(i);
  844. break;
  845. }
  846. }
  847. //'推送时彭总给的key值',
  848. String pushUserKey = null;
  849. //'推送类型1单流程推送,2串联推送,3并联推送',
  850. Integer pushType = null;
  851. if (myUserTask != null) {
  852. pushUserKey = myUserTask.getCandidateGroups().get(0);
  853. if (listTask.size() > 1) {
  854. String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_");
  855. if (s1.length >= 5) {
  856. String pushTypeNum = s1[4];
  857. if ("0".equals(pushTypeNum)) {
  858. pushType = 2;
  859. } else if ("1".equals(pushTypeNum)) {
  860. pushType = 3;
  861. }
  862. }
  863. } else {
  864. pushType = 1;
  865. }
  866. }
  867. FlowMainPush flowMainPush = new FlowMainPush();
  868. flowMainPush.setFlowMainId(flowMain.getId());
  869. flowMainPush.setFormId(recordId);
  870. {// 需要工作流引擎的支持
  871. flowMainPush.setPushUser(task.getAssignee());//推送人id'
  872. flowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  873. flowMainPush.setNodeName(myUserTask.getName());
  874. flowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  875. flowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  876. flowMainPush.setFlowType(constantFlowType);
  877. flowMainPush.setFlowPost(task.getAssignee());
  878. //2023年5月10日 修改成上面的了 张洮
  879. // flowMainPush.setFlowPost(currUser.getId());
  880. flowMainPush.setFlowId(processInstanceId);
  881. flowMainPush.setTaskId(task.getId());
  882. }
  883. flowMainPush.setUpMainLogId(flowMainLog.getId());
  884. flowMainPush.setUpdatedAt(new Date());
  885. flowMainPush.setCreatedAt(flowMainPush.getUpdatedAt());
  886. flowMainPush.setCreatedBy(currUser.getId());
  887. flowMainPush.setUpdatedBy(flowMainPush.getCreatedBy());
  888. flowMainPush.setGroupId(currUser.getGroupId());
  889. flowMainPush.setStatus(0);
  890. flowMainPushService.insert(flowMainPush);
  891. }
  892. }
  893. if (isEnd) {
  894. return AjaxResult.successData(1688, null);
  895. } else {
  896. return AjaxResult.success();
  897. }
  898. }
  899. /**
  900. * 申请人撤回申请
  901. *
  902. * @param flowMainid
  903. */
  904. public AjaxResult recallApply(String flowMainid) {
  905. if (com.rockstar.util.StringUtils.isEmpty(flowMainid)) {
  906. return AjaxResult.error("数据不能为空");
  907. }
  908. FlowMain flowMain = this.selectByPrimaryKey(flowMainid);
  909. //流转状态为审核中时,可以由发起人撤回。ok
  910. if (!flowMain.getFlowStatus().equals(1)) {
  911. return AjaxResult.error("流程状态不在审核中,请重新确认");
  912. }
  913. String mypushUserKey = null;
  914. {//开始申请人撤回申请
  915. //先搜索目前有哪些人在审核中 ,获取key
  916. // select * from flow_main_push WHERE flow_main_push.flow_main_id=#{flowMainId} and STATUS=0
  917. FlowMainPushExample example = new FlowMainPushExample();
  918. example.createCriteria().andFlowMainIdEqualTo(flowMain.getId()).andStatusEqualTo(0);
  919. List<FlowMainPush> flowMainPushes = flowMainPushService.selectByExample(example);
  920. mypushUserKey = flowMainPushes.get(0).getPushUserKey();
  921. //1.关闭所有推送人数据信息表 ok
  922. {
  923. flowMainPushService.updateStatusThreeByFlowMainId(ShiroUtils.getUser().getId(), flowMain.getId());
  924. }
  925. //2.关闭主流程 ok
  926. {// 发起流程引擎操作 并结束该流程
  927. try {
  928. flowService.deleteInstance(flowMain.getFlowId(), "申请人撤回申请_结束流程");
  929. } catch (Exception e) {
  930. System.err.println("流程引擎异常");
  931. e.printStackTrace();
  932. // throw new RuntimeException(e);
  933. }
  934. }
  935. //3.关闭主流程表 ok
  936. //存入流程日志表的id
  937. String flowMainLogUuid = UUIDUtils.middleUUID();
  938. {
  939. FlowMain flowMain1 = new FlowMain();
  940. flowMain1.setId(flowMain.getId());
  941. flowMain1.setFlowStatus(4);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  942. flowMain1.setLastMainLogId(flowMainLogUuid);
  943. flowMain1.setUpdatedAt(new Date());
  944. flowMain1.setUpdatedBy(ShiroUtils.getUser().getId());
  945. this.updateByPrimaryKeySelective(flowMain1);
  946. }
  947. //4 添加日志表
  948. FlowMainLog flowMainLog = new FlowMainLog();
  949. {//其表单对应的流转历史该节点审核结果显示为”发起人撤回”
  950. // flowMainLogUuid
  951. flowMainLog.setId(flowMainLogUuid);
  952. flowMainLog.setFlowMainId(flowMain.getId());
  953. flowMainLog.setFormId(flowMain.getFormId());
  954. flowMainLog.setAuditUser(ShiroUtils.getUser().getId());
  955. flowMainLog.setAuditContent(null);
  956. flowMainLog.setAuditResult(null);
  957. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  958. flowMainLog.setAuditType("4");
  959. flowMainLog.setFlowType(flowMain.getFlowType());
  960. flowMainLog.setFlowPost(ShiroUtils.getUser().getId());
  961. {// 需要工作流引擎的支持
  962. flowMainLog.setFlowId(flowMain.getFlowId());
  963. flowMainLog.setTaskId(null);
  964. flowMainLog.setNodeName("发起人撤回");
  965. flowMainLog.setPushUserKey(mypushUserKey);//发起人撤回时 当时的审核人所对应的角色
  966. }
  967. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  968. // 因为感觉用不到,暂时不放进去
  969. // flowMainLog.setNextPersons();
  970. flowMainLog.setUpMainLogId(flowMain.getLastMainLogId());
  971. flowMainLog.setCcList(null);
  972. flowMainLog.setCreatedAt(new Date());
  973. flowMainLog.setCreatedBy(ShiroUtils.getUser().getId());
  974. flowMainLog.setGroupId(ShiroUtils.getUser().getGroupId());
  975. flowMainLog.setStatus(0);
  976. flowMainLogService.insertWithoutId(flowMainLog);
  977. }
  978. }
  979. return AjaxResult.success();
  980. }
  981. /**
  982. * 分页查询
  983. *
  984. * @return
  985. */
  986. public PageInfo<FlowMain> list(Tablepar tablepar, FlowMain model, DateTrans dt) {
  987. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  988. List<FlowMain> list = null;//modelMapper.selectByExample(getCondition(model,dt));
  989. PageInfo<FlowMain> pageInfo = new PageInfo<>(list);
  990. return pageInfo;
  991. }
  992. public Object listAll(FlowMain model, DateTrans dt) {
  993. List<FlowMain> list = null;//modelMapper.selectByExample(getCondition(model,dt));
  994. return list;
  995. }
  996. @Override
  997. public int deleteByPrimaryKey(String ids) {
  998. List<String> lista = Convert.toListStrArray(ids);
  999. FlowMainExample example = new FlowMainExample();
  1000. example.createCriteria().andIdIn(lista);
  1001. return flowMainMapper.deleteByExample(example);
  1002. }
  1003. @Override
  1004. public FlowMain selectByPrimaryKey(String id) {
  1005. return flowMainMapper.selectByPrimaryKey(id);
  1006. }
  1007. @Override
  1008. public int updateByPrimaryKeySelective(FlowMain record) {
  1009. return flowMainMapper.updateByPrimaryKeySelective(record);
  1010. }
  1011. @Override
  1012. public int updateByExampleSelective(FlowMain record, FlowMainExample example) {
  1013. return flowMainMapper.updateByExampleSelective(record, example);
  1014. }
  1015. @Override
  1016. public int updateByExample(FlowMain record, FlowMainExample example) {
  1017. return flowMainMapper.updateByExample(record, example);
  1018. }
  1019. @Override
  1020. public List<FlowMain> selectByExample(FlowMainExample example) {
  1021. return flowMainMapper.selectByExample(example);
  1022. }
  1023. @Override
  1024. public long countByExample(FlowMainExample example) {
  1025. return flowMainMapper.countByExample(example);
  1026. }
  1027. @Override
  1028. public int deleteByExample(FlowMainExample example) {
  1029. return flowMainMapper.deleteByExample(example);
  1030. }
  1031. public int insert(FlowMain record) {
  1032. record.setId(UUIDUtils.middleUUID());
  1033. return insertWithoutId(record);
  1034. }
  1035. public int insertWithoutId(FlowMain record) {
  1036. return flowMainMapper.insert(record);
  1037. }
  1038. @Override
  1039. public int insertSelective(FlowMain record) {
  1040. record.setId(UUIDUtils.middleUUID());
  1041. record.setCreatedAt(new Date());
  1042. return flowMainMapper.insertSelective(record);
  1043. }
  1044. public PageInfo<FlowMainIn> hasDolistByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1045. model.setAuditResult(new String[]{"1", "2", "3", "5"});
  1046. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1047. List<FlowMainIn> list = flowMainExtendMapper.listByInfo(model, dt);
  1048. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1049. return pageInfo;
  1050. }
  1051. public List<FrameRoleData> findFrameRoleDatasByUserId(String userId, String roleType) {
  1052. return flowMainExtendMapper.findFrameRoleDatasByUserId(userId, roleType);
  1053. }
  1054. public List<FrameUser> findFrameUsersByRoleKey(String roleKey, String roleType) {
  1055. List<FrameUser> frameUsersByRoleKey = null;
  1056. try {
  1057. // System.out.println("SELECT frame_user.* FROM frame_role_data_user LEFT JOIN frame_role_data ON frame_role_data.id=frame_role_data_user.role_data_id LEFT JOIN frame_user ON frame_user.id=frame_role_data_user.user_id WHERE frame_role_data.role_key='"+roleKey+"' AND frame_role_data.role_type='"+roleType+"'");
  1058. frameUsersByRoleKey = flowMainExtendMapper.findFrameUsersByRoleKey(roleKey, roleType);
  1059. } catch (Exception e) {
  1060. e.printStackTrace();
  1061. frameUsersByRoleKey = new ArrayList<>();
  1062. }
  1063. return frameUsersByRoleKey;
  1064. }
  1065. public List<FrameUser> findFrameUsersByRoleKeyAndGroup(String roleKey, String roleType, String groupId) {
  1066. List<FrameUser> frameUsersByRoleKey = null;
  1067. try {
  1068. frameUsersByRoleKey = flowMainExtendMapper.findFrameUsersByRoleKeyAndGroup(roleKey, roleType, groupId);
  1069. } catch (Exception e) {
  1070. e.printStackTrace();
  1071. frameUsersByRoleKey = new ArrayList<>();
  1072. }
  1073. return frameUsersByRoleKey;
  1074. }
  1075. public PageInfo<FlowMainIn> myApplylistByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1076. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1077. List<FlowMainIn> list = flowMainExtendMapper.myApplylistByInfo(model, dt);
  1078. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1079. return pageInfo;
  1080. }
  1081. /**
  1082. * 抄送事项 ok
  1083. * web端开始页面查询,不同类型, 流程名称,主题,发起人查询
  1084. */
  1085. public PageInfo<FlowMainIn> cclistByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1086. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1087. List<FlowMainIn> list = flowMainExtendMapper.cclistByInfo(model, dt);
  1088. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1089. return pageInfo;
  1090. }
  1091. public PageInfo<FlowMainIn> myEntrustlistByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1092. model.setAuditResult(new String[]{"4"});
  1093. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1094. List<FlowMainIn> list = flowMainExtendMapper.listByInfo(model, dt);
  1095. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1096. return pageInfo;
  1097. }
  1098. /**
  1099. * 待办事项
  1100. *
  1101. * @param tablepar
  1102. * @param model
  1103. * @param dt
  1104. * @return
  1105. */
  1106. public PageInfo<FlowMainIn> toDolistByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1107. model.setAuditResult(new String[]{"1"});
  1108. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1109. List<FlowMainIn> list = flowMainExtendMapper.toDolistByInfo(model, dt);
  1110. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1111. return pageInfo;
  1112. }
  1113. /**
  1114. * 委托代办事项
  1115. *
  1116. * @param tablepar
  1117. * @param model
  1118. * @param dt
  1119. * @return
  1120. */
  1121. public PageInfo<FlowMainIn> entrustToDolistByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1122. model.setAuditResult(new String[]{"2"});
  1123. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1124. List<FlowMainIn> list = flowMainExtendMapper.toDolistByInfo(model, dt);
  1125. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1126. return pageInfo;
  1127. }
  1128. public List<FlowHistoryInfo> getFlowHistroyByFlowMainId(String flowMainId) {
  1129. return flowMainExtendMapper.getFlowHistroyByFlowMainId(flowMainId);
  1130. }
  1131. public Integer numtoDolistByInfo(FlowMainIn model, DateTrans dt) {
  1132. model.setAuditResult(new String[]{"1"});
  1133. return flowMainExtendMapper.numtoDolistByInfo(model, dt);
  1134. }
  1135. public PageInfo<FlowMainIn> toDolisAndEntrusttByInfo(Tablepar tablepar, FlowMainIn model, DateTrans dt) {
  1136. model.setAuditResult(new String[]{"1", "2"});
  1137. // model.setAuditResult(new String[]{"2"});
  1138. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1139. List<FlowMainIn> list = flowMainExtendMapper.toDolistByInfo(model, dt);
  1140. PageInfo<FlowMainIn> pageInfo = new PageInfo<>(list);
  1141. return pageInfo;
  1142. }
  1143. public Integer numtoDolisAndEntrusttByInfo(FlowMainIn model, DateTrans dt) {
  1144. model.setAuditResult(new String[]{"1", "2"});
  1145. return flowMainExtendMapper.numtoDolistByInfo(model, dt);
  1146. }
  1147. public List<IMGFlowHistoryInfo> getIMGFlowHistroyByFlowMainId(String flowMainId) {
  1148. FlowMain flowMain = flowMainMapper.selectByPrimaryKey(flowMainId);
  1149. // 判断流程是哪种流程
  1150. String[] flowStep = null;
  1151. {
  1152. if (flowMain.getFlowType().equals(ConstantFlowType.PAYMENT)) {
  1153. flowStep = ConstantFlowType.PAYMENT_FLOWSTEPS;
  1154. }
  1155. }
  1156. //获取返回值
  1157. ArrayList<IMGFlowHistoryInfo> imgFlowHistoryInfos = new ArrayList<>();
  1158. {//`flow_status` int(4) DEFAULT NULL COMMENT //'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1159. if (flowMain.getFlowStatus().equals(1)) { //ok //需要找到最新推送人 //'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1160. List<FlowMainPush> pushByFlowMainId = flowMainPushService.findPushByFlowMainId(flowMainId);
  1161. String pushUserKey = pushByFlowMainId.get(0).getPushUserKey();
  1162. for (int i = 0; i < flowStep.length; i++) {
  1163. if (flowStep[i].startsWith(pushUserKey)) {
  1164. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1165. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1166. imgFlowHistoryInfo.setType("3");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1167. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1168. break;
  1169. } else {
  1170. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1171. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1172. imgFlowHistoryInfo.setType("1");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1173. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1174. }
  1175. }
  1176. return imgFlowHistoryInfos;
  1177. } else if (flowMain.getFlowStatus().equals(2)) {//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1178. //需要找到最新操作日志
  1179. FlowMainLog flowMainLog= flowMainLogService.selectLastOneByFlowMainId(flowMainId);
  1180. if (flowMainLog==null){
  1181. return null;
  1182. }
  1183. String pushUserKey = flowMainLog.getPushUserKey();
  1184. for (int i = 0; i < flowStep.length; i++) {
  1185. if (flowStep[i].startsWith(pushUserKey)) {
  1186. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1187. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1188. imgFlowHistoryInfo.setType("2");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1189. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1190. break;
  1191. } else {
  1192. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1193. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1194. imgFlowHistoryInfo.setType("1");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1195. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1196. }
  1197. }
  1198. return imgFlowHistoryInfos;
  1199. } else if (flowMain.getFlowStatus().equals(3)) {//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1200. //需要找到最新操作日志
  1201. FlowMainLog flowMainLog= flowMainLogService.selectLastOneByFlowMainId(flowMainId);
  1202. if (flowMainLog==null){
  1203. return null;
  1204. }
  1205. String pushUserKey = flowMainLog.getPushUserKey();
  1206. for (int i = 0; i < flowStep.length; i++) {
  1207. if (flowStep[i].startsWith(pushUserKey)) {
  1208. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1209. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1210. if ("1".equals(flowMainLog.getAuditResult())){//1,同意
  1211. imgFlowHistoryInfo.setType("1");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1212. imgFlowHistoryInfo.setIsPass("1");
  1213. }else{
  1214. imgFlowHistoryInfo.setType("6");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1215. }
  1216. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1217. } else {
  1218. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1219. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1220. imgFlowHistoryInfo.setType("1");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1221. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1222. }
  1223. }
  1224. return imgFlowHistoryInfos;
  1225. } else if (flowMain.getFlowStatus().equals(4)) {//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1226. //判断是监控室撤回还是自己撤回
  1227. //需要找到最新操作日志
  1228. FlowMainLog flowMainLog= flowMainLogService.selectLastOneByFlowMainId(flowMainId);
  1229. if (flowMainLog==null){
  1230. return null;
  1231. }
  1232. String pushUserKey = flowMainLog.getPushUserKey();
  1233. for (int i = 0; i < flowStep.length; i++) {
  1234. if (flowStep[i].startsWith(pushUserKey)) {
  1235. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1236. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1237. if (flowMainLog.getAuditType().equals(5)){
  1238. //监控室撤回
  1239. imgFlowHistoryInfo.setType("5");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1240. }else{
  1241. imgFlowHistoryInfo.setType("4");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1242. }
  1243. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1244. break;
  1245. } else {
  1246. IMGFlowHistoryInfo imgFlowHistoryInfo = new IMGFlowHistoryInfo();
  1247. imgFlowHistoryInfo.setNodeKey(flowStep[i]);
  1248. imgFlowHistoryInfo.setType("1");// 1 审核通过,2退回,3审核中,4申请人撤回,5,监控室撤回,6审核不同意,结束流程
  1249. imgFlowHistoryInfos.add(imgFlowHistoryInfo);
  1250. }
  1251. }
  1252. return imgFlowHistoryInfos;
  1253. }
  1254. }
  1255. return null;
  1256. }
  1257. public AjaxResult doFlowMainForPurchase(String ApplyTheme, String recordId, String recordRemark,
  1258. String recordCcList, String processdefine, String deploymentid,
  1259. Map<String, Object> conditionMap, String constantFlowTypeNAME,
  1260. String constantFlowType,FrameUser currUser)
  1261. throws com.rockstar.flow.exception.FlowException {
  1262. // 存入流程主表 ok
  1263. FlowMain flowMain = new FlowMain();
  1264. flowMain.setId(UUIDUtils.middleUUID());
  1265. String processInstanceId = null;
  1266. // 判断申请人是否是主要领导,是的话直接通过,不启动流程,保存相关信息
  1267. boolean isEnd = false;
  1268. List<FrameRoleData> frameRoleDataList = findFrameRoleDatasByUserId(currUser.getId(), ConstantFlowType.ROLETYPE);
  1269. for (FrameRoleData data : frameRoleDataList) {
  1270. if(data.getRoleKey().equals("zyld")){
  1271. isEnd = true;
  1272. }
  1273. }
  1274. // 进入流程引擎,开始启动流程
  1275. if(!isEnd) {
  1276. //启动流程引擎
  1277. Map<String, String> stringStringMap = proActiService.startPurchaseTask(processdefine, deploymentid,
  1278. flowMain.getId(),currUser, conditionMap);
  1279. if (stringStringMap == null) {
  1280. return AjaxResult.error("流程引擎开启失败,请查看原因!");
  1281. }
  1282. processInstanceId = stringStringMap.get("processInstanceId");
  1283. if (stringStringMap.get("isEnd") != null) {
  1284. isEnd = true;
  1285. }
  1286. }
  1287. //存入流程日志表的id
  1288. String flowMainLogUuid = UUIDUtils.middleUUID();
  1289. {
  1290. flowMain.setApplyTheme(ApplyTheme);
  1291. flowMain.setFormId(recordId);
  1292. flowMain.setApplyUser(currUser.getId());
  1293. flowMain.setDeptId(currUser.getDepartment());
  1294. if (isEnd) {
  1295. flowMain.setFlowStatus(3);//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1296. flowMain.setFlowResult(1); //审核结果0无状态,1审核通过结束,2审核不通过结束
  1297. } else {
  1298. flowMain.setFlowStatus(1);//'申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)',
  1299. flowMain.setFlowResult(0); //审核结果0无状态,1审核通过结束,2审核不通过结束
  1300. }
  1301. flowMain.setReturnStatus(0);//'0/null无状态,1已撤回并且已重新发起',
  1302. flowMain.setCcList(null);
  1303. flowMain.setFlowName(constantFlowTypeNAME);
  1304. flowMain.setFlowType(constantFlowType);
  1305. //当前流程邮递操作人(frame_user)id 去除岗位的设定
  1306. flowMain.setFlowPost(currUser.getId());
  1307. {// 需要工作流引擎的支持
  1308. flowMain.setFlowId(processInstanceId);
  1309. flowMain.setTaskId(null);
  1310. }
  1311. flowMain.setLastMainLogId(flowMainLogUuid);
  1312. flowMain.setUpdatedAt(new Date());
  1313. flowMain.setCreatedAt(flowMain.getUpdatedAt());
  1314. flowMain.setCreatedBy(currUser.getId());
  1315. flowMain.setUpdatedBy(flowMain.getCreatedBy());
  1316. flowMain.setGroupId(currUser.getGroupId());
  1317. flowMain.setStatus(0);
  1318. if (!StringUtils.isEmpty(recordRemark)) {
  1319. flowMain.setRemark(recordRemark);
  1320. }
  1321. this.insertWithoutId(flowMain);
  1322. }
  1323. // 存入流程日志表 ok
  1324. FlowMainLog flowMainLog = new FlowMainLog();
  1325. {
  1326. flowMainLog.setId(flowMainLogUuid);
  1327. flowMainLog.setFlowMainId(flowMain.getId());
  1328. flowMainLog.setFormId(recordId);
  1329. flowMainLog.setAuditUser(currUser.getId());
  1330. if (isEnd) {
  1331. flowMainLog.setAuditType("2"); //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  1332. flowMainLog.setAuditContent("自审通过");
  1333. flowMainLog.setAuditResult("1");
  1334. } else {
  1335. flowMainLog.setAuditType("0"); //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  1336. flowMainLog.setAuditContent(null);
  1337. flowMainLog.setAuditResult(null);
  1338. }
  1339. flowMainLog.setFlowType(constantFlowType);
  1340. flowMainLog.setFlowPost(currUser.getId());
  1341. {// 需要工作流引擎的支持
  1342. flowMainLog.setFlowId(processInstanceId);
  1343. flowMainLog.setTaskId(null);
  1344. flowMainLog.setNodeName(ConstantFlowType.nodeKeysName.get(1));
  1345. flowMainLog.setPushUserKey(ConstantFlowType.nodeKeysName.get(11));
  1346. }
  1347. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  1348. // 因为感觉用不到,暂时不放进去
  1349. // flowMainLog.setNextPersons();
  1350. flowMainLog.setUpMainLogId(null);
  1351. flowMainLog.setCcList(null);
  1352. flowMainLog.setCreatedAt(new Date());
  1353. flowMainLog.setCreatedBy(currUser.getId());
  1354. flowMainLog.setGroupId(currUser.getGroupId());
  1355. flowMainLog.setStatus(0);
  1356. flowMainLogService.insertWithoutId(flowMainLog);
  1357. }
  1358. // 存入抄送人信息 ok
  1359. if (!StringUtils.isEmpty(recordCcList)) {
  1360. String[] split = recordCcList.split(",");
  1361. for (String ccId : split) {
  1362. if (!StringUtils.isEmpty(ccId)) {
  1363. FlowMainCc flowMainCc = new FlowMainCc();
  1364. flowMainCc.setFlowMainId(flowMain.getId());
  1365. flowMainCc.setCcUser(ccId);
  1366. //选择抄送人时的记录表id(flow_main_log):例如:112122
  1367. flowMainCc.setMainLogIds(flowMainLog.getId());
  1368. flowMainCc.setUpdatedAt(new Date());
  1369. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  1370. flowMainCc.setCreatedBy(currUser.getId());
  1371. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  1372. flowMainCc.setGroupId(currUser.getGroupId());
  1373. flowMainCc.setStatus(0);
  1374. flowMainCcService.insert(flowMainCc);
  1375. }
  1376. }
  1377. }
  1378. // 存入推送人
  1379. //查看各个任务
  1380. List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  1381. List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  1382. for (Task task : listTask) {
  1383. UserTask myUserTask = null;
  1384. {
  1385. String taskDefinitionKey = task.getTaskDefinitionKey();
  1386. for (UserTask userTask : TaskList) {
  1387. if (userTask.getId().equals(taskDefinitionKey)) {
  1388. myUserTask = userTask;
  1389. break;
  1390. }
  1391. }
  1392. //'推送时彭总给的key值',
  1393. String pushUserKey = null;
  1394. //'推送类型1单流程推送,2串联推送,3并联推送',
  1395. Integer pushType = null;
  1396. if (myUserTask != null) {
  1397. pushUserKey = myUserTask.getCandidateGroups().get(0);
  1398. if (listTask.size() > 1) {
  1399. String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_");
  1400. if (s1.length >= 5) {
  1401. String pushTypeNum = s1[4];
  1402. if ("0".equals(pushTypeNum)) {
  1403. pushType = 2;
  1404. } else if ("1".equals(pushTypeNum)) {
  1405. pushType = 3;
  1406. }
  1407. }
  1408. } else {
  1409. pushType = 1;
  1410. }
  1411. }
  1412. FlowMainPush flowMainPush = new FlowMainPush();
  1413. flowMainPush.setFlowMainId(flowMain.getId());
  1414. flowMainPush.setFormId(recordId);
  1415. {// 需要工作流引擎的支持
  1416. flowMainPush.setPushUser(task.getAssignee());//推送人id'
  1417. flowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  1418. flowMainPush.setNodeName(null!=myUserTask?myUserTask.getName():null);
  1419. flowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  1420. flowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  1421. flowMainPush.setFlowType(constantFlowType);
  1422. flowMainPush.setFlowPost(task.getAssignee());
  1423. flowMainPush.setFlowId(processInstanceId);
  1424. flowMainPush.setTaskId(task.getId());
  1425. }
  1426. flowMainPush.setUpMainLogId(flowMainLog.getId());
  1427. flowMainPush.setUpdatedAt(new Date());
  1428. flowMainPush.setCreatedAt(flowMainPush.getUpdatedAt());
  1429. flowMainPush.setCreatedBy(currUser.getId());
  1430. flowMainPush.setUpdatedBy(flowMainPush.getCreatedBy());
  1431. flowMainPush.setGroupId(currUser.getGroupId());
  1432. flowMainPush.setStatus(0);
  1433. flowMainPushService.insert(flowMainPush);
  1434. }
  1435. }
  1436. if (isEnd) {
  1437. return AjaxResult.successData(1688, null);
  1438. } else {
  1439. return AjaxResult.success();
  1440. }
  1441. }
  1442. public String doConfirmResultForPurchase(AddConfirmResult addConfirmResult, String deploymentid,
  1443. String constantFlowType, FlowMainPush flowMainPush,
  1444. HashMap<String, Object> conditionMap)
  1445. throws com.rockstar.flow.exception.FlowException {
  1446. if (addConfirmResult.getConfirmResult() == null) {
  1447. return "没有获取到confirmResult值";
  1448. }
  1449. OperaterManage operaterManage = new OperaterManage();
  1450. FrameUser frameUser = new FrameUser();
  1451. try {
  1452. frameUser.setId(ShiroUtils.getUser().getId());
  1453. } catch (Exception e) {
  1454. frameUser.setId(addConfirmResult.getOperaterId());
  1455. }
  1456. operaterManage.setUser(frameUser);
  1457. if (!flowMainPush.getStatus().equals(0)) {
  1458. if (flowMainPush.getStatus().equals(1)) {
  1459. return "已经在" + flowMainPush.getUpdatedAt() + "时操作过了,请重新确认";
  1460. } else if (flowMainPush.getStatus().equals(2)) {
  1461. return "已经在" + flowMainPush.getUpdatedAt() + "时由其他审核人操作过了,请重新确认";
  1462. }
  1463. }
  1464. {//提前逻辑删除推送信息,保证数据不会因为同步操作出现冲突
  1465. FlowMainPush updateFlowMainPush = new FlowMainPush();
  1466. updateFlowMainPush.setId(flowMainPush.getId());
  1467. updateFlowMainPush.setStatus(1);
  1468. updateFlowMainPush.setUpdatedAt(new Date());
  1469. updateFlowMainPush.setUpdatedBy(operaterManage.getUser().getId());
  1470. flowMainPushService.updateByPrimaryKeySelective(updateFlowMainPush);
  1471. }
  1472. FlowMain flowMain = this.selectByPrimaryKey(flowMainPush.getFlowMainId());
  1473. //当前任务流程 目的是获取节点名称,存起来nodeName
  1474. String nodeName = flowMainPush.getNodeName() == null ? proActiService.getNodeName(flowMainPush) :
  1475. flowMainPush.getNodeName();
  1476. if (nodeName == null) {
  1477. return "异常:没有找到对应的任务...请通知管理员";
  1478. }
  1479. String mypushUserKey = flowMainPush.getPushUserKey();
  1480. //审核通过,转下一步
  1481. boolean isEnd = false;//是否审核到最后一步了
  1482. if (addConfirmResult.getConfirmResult().equals("1")) {//审核通过 ok
  1483. {// 发起流程引擎操作 并查看下一节点的操作要求
  1484. Map<String, String> stringStringMap = proActiService.passToRunPurchaseTask(flowMainPush, deploymentid,
  1485. flowMainPush.getFlowMainId(), conditionMap);
  1486. if (stringStringMap == null) {
  1487. return "流程引擎开启失败,请查看原因!";
  1488. }
  1489. isEnd = stringStringMap.get("isEnd") != null;
  1490. }
  1491. {
  1492. //存入流程日志表的id
  1493. String flowMainLogUuid = UUIDUtils.middleUUID();
  1494. //1修改主表状态 ok
  1495. {
  1496. FlowMain flowMain1 = new FlowMain();
  1497. flowMain1.setId(flowMainPush.getFlowMainId());
  1498. if (isEnd) {
  1499. flowMain1.setFlowStatus(3);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  1500. flowMain1.setFlowResult(1); //审核结果0无状态,1审核通过结束,2审核不通过结束
  1501. } else {
  1502. flowMain1.setFlowStatus(1);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  1503. flowMain1.setFlowResult(0); //审核结果0无状态,1审核通过结束,2审核不通过结束
  1504. }
  1505. flowMain1.setLastMainLogId(flowMainLogUuid);
  1506. flowMain1.setUpdatedAt(new Date());
  1507. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  1508. this.updateByPrimaryKeySelective(flowMain1);
  1509. }
  1510. //2添加日志 ok
  1511. FlowMainLog flowMainLog = new FlowMainLog();
  1512. {
  1513. flowMainLog.setId(flowMainLogUuid);
  1514. flowMainLog.setFlowMainId(flowMain.getId());
  1515. flowMainLog.setFormId(flowMain.getFormId());
  1516. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  1517. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  1518. flowMainLog.setAuditResult("1");// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  1519. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  1520. if (isEnd) {
  1521. flowMainLog.setAuditType("2");
  1522. } else {
  1523. flowMainLog.setAuditType("1");
  1524. }
  1525. flowMainLog.setFlowType(constantFlowType);
  1526. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  1527. {// 需要工作流引擎的支持
  1528. flowMainLog.setFlowId(flowMain.getFlowId());
  1529. flowMainLog.setTaskId(flowMainPush.getTaskId());
  1530. flowMainLog.setNodeName(nodeName);
  1531. flowMainLog.setPushUserKey(mypushUserKey);
  1532. }
  1533. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  1534. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  1535. flowMainLog.setCcList(null);
  1536. flowMainLog.setCreatedAt(new Date());
  1537. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  1538. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  1539. flowMainLog.setStatus(0);
  1540. flowMainLogService.insertWithoutId(flowMainLog);
  1541. }
  1542. // 3存入抄送人信息 ok
  1543. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  1544. String[] split = addConfirmResult.getCcList().split(",");
  1545. for (String ccId : split) {
  1546. if (!StringUtils.isEmpty(ccId)) {
  1547. FlowMainCc flowMainCc = new FlowMainCc();
  1548. flowMainCc.setFlowMainId(flowMain.getId());
  1549. flowMainCc.setCcUser(ccId);
  1550. //选择抄送人时的记录表id(flow_main_log):例如:112122
  1551. flowMainCc.setMainLogIds(flowMainLog.getId());
  1552. flowMainCc.setUpdatedAt(new Date());
  1553. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  1554. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  1555. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  1556. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  1557. flowMainCc.setStatus(0);
  1558. flowMainCcService.insert(flowMainCc);
  1559. }
  1560. }
  1561. }
  1562. //4.0判断是否存在串并联并修改推送状态 逻辑删除旧的推送人
  1563. {
  1564. //todo推送类型1单流程推送,2串联推送,3并联推送
  1565. Integer pushType = flowMainPush.getPushType();
  1566. if (pushType.equals(3)) {
  1567. //要逻辑删除自己和其他推送
  1568. //将其他并联推送的人员推送状态status改成2状态值
  1569. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  1570. }
  1571. }
  1572. //4添加新的推送人员
  1573. if (!isEnd) {//查看各个任务
  1574. List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  1575. //查看总的数据流程
  1576. List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  1577. for (Task task : listTask) {
  1578. {
  1579. //获取推送类型1单流程推送,2串联推送,3并联推送',
  1580. Integer pushType = null;
  1581. //'推送时彭总给的key值',
  1582. String pushUserKey = null;
  1583. UserTask myUserTask = null;
  1584. {
  1585. String taskDefinitionKey = task.getTaskDefinitionKey();
  1586. for (UserTask userTask : TaskList) {
  1587. if (userTask.getId().equals(taskDefinitionKey)) {
  1588. myUserTask = userTask;
  1589. break;
  1590. }
  1591. }
  1592. //判断是否存在串并联并修改推送状态
  1593. if (myUserTask != null) {
  1594. pushUserKey = myUserTask.getCandidateGroups().get(0);
  1595. if (listTask.size() > 1) {
  1596. String[] s1 = pushUserKey.substring(0, pushUserKey.indexOf("-")).split("_");
  1597. if (s1.length >= 5) {
  1598. String pushTypeNum = s1[4];
  1599. if ("0".equals(pushTypeNum)) {
  1600. pushType = 2;
  1601. } else if ("1".equals(pushTypeNum)) {
  1602. pushType = 3;
  1603. }
  1604. }
  1605. } else {
  1606. pushType = 1;
  1607. }
  1608. }
  1609. }
  1610. FlowMainPush newflowMainPush = new FlowMainPush();
  1611. newflowMainPush.setFlowMainId(flowMain.getId());
  1612. newflowMainPush.setFormId(flowMain.getFormId());
  1613. {// 需要工作流引擎的支持
  1614. newflowMainPush.setPushUser(task.getAssignee());//推送人id'
  1615. newflowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  1616. newflowMainPush.setNodeName(myUserTask.getName());
  1617. newflowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  1618. newflowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  1619. newflowMainPush.setFlowType(constantFlowType);
  1620. newflowMainPush.setFlowPost(task.getAssignee());
  1621. newflowMainPush.setFlowId(flowMain.getFlowId());
  1622. newflowMainPush.setTaskId(task.getId());
  1623. }
  1624. newflowMainPush.setUpMainLogId(flowMainLog.getId());
  1625. newflowMainPush.setUpdatedAt(new Date());
  1626. newflowMainPush.setCreatedAt(newflowMainPush.getUpdatedAt());
  1627. newflowMainPush.setCreatedBy(operaterManage.getUser().getId());
  1628. newflowMainPush.setUpdatedBy(newflowMainPush.getCreatedBy());
  1629. newflowMainPush.setGroupId(operaterManage.getUser().getGroupId());
  1630. newflowMainPush.setStatus(0);
  1631. flowMainPushService.insert(newflowMainPush);
  1632. }
  1633. }
  1634. }
  1635. }
  1636. } else if (addConfirmResult.getConfirmResult().equals("2")) {//退回发起人 ok
  1637. {// 退回发起人
  1638. isEnd = true;
  1639. //当前审核人/委托人代表的用户id
  1640. String myFrameUserId = proActiService.getMyFrameUserId(flowMainPush);
  1641. if (myFrameUserId == null) {
  1642. return null;
  1643. }
  1644. //当前审核人/委托人代表的用户
  1645. FrameUser myFrameUser = frameUserService.selectByPrimaryKey(myFrameUserId);
  1646. FrameUser targetUser = frameUserService.selectByPrimaryKey(flowMain.getApplyUser());
  1647. flowService.runTask(flowMainPush.getTaskId(), null, "no", "退回发起人", targetUser, myFrameUser, null);
  1648. }
  1649. {
  1650. //存入流程日志表的id
  1651. String flowMainLogUuid = UUIDUtils.middleUUID();
  1652. //1修改主表状态
  1653. {
  1654. FlowMain flowMain1 = new FlowMain();
  1655. flowMain1.setId(flowMainPush.getFlowMainId());
  1656. flowMain1.setFlowStatus(2);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  1657. flowMain1.setLastMainLogId(flowMainLogUuid);
  1658. flowMain1.setUpdatedAt(new Date());
  1659. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  1660. this.updateByPrimaryKeySelective(flowMain1);
  1661. }
  1662. //2添加日志 ok
  1663. FlowMainLog flowMainLog = new FlowMainLog();
  1664. {
  1665. flowMainLog.setId(flowMainLogUuid);
  1666. flowMainLog.setFlowMainId(flowMain.getId());
  1667. flowMainLog.setFormId(flowMain.getFormId());
  1668. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  1669. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  1670. flowMainLog.setAuditResult("2");// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  1671. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  1672. flowMainLog.setAuditType("1");
  1673. flowMainLog.setFlowType(constantFlowType);
  1674. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  1675. {// 需要工作流引擎的支持
  1676. flowMainLog.setFlowId(flowMain.getFlowId());
  1677. flowMainLog.setTaskId(flowMainPush.getTaskId());
  1678. flowMainLog.setNodeName(nodeName);
  1679. flowMainLog.setPushUserKey(mypushUserKey);
  1680. }
  1681. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  1682. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  1683. flowMainLog.setCcList(null);
  1684. flowMainLog.setCreatedAt(new Date());
  1685. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  1686. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  1687. flowMainLog.setStatus(0);
  1688. flowMainLogService.insertWithoutId(flowMainLog);
  1689. }
  1690. //2.1添加抄送
  1691. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  1692. String[] split = addConfirmResult.getCcList().split(",");
  1693. for (String ccId : split) {
  1694. if (!StringUtils.isEmpty(ccId)) {
  1695. FlowMainCc flowMainCc = new FlowMainCc();
  1696. flowMainCc.setFlowMainId(flowMain.getId());
  1697. flowMainCc.setCcUser(ccId);
  1698. //选择抄送人时的记录表id(flow_main_log):例如:112122
  1699. flowMainCc.setMainLogIds(flowMainLog.getId());
  1700. flowMainCc.setUpdatedAt(new Date());
  1701. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  1702. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  1703. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  1704. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  1705. flowMainCc.setStatus(0);
  1706. flowMainCcService.insert(flowMainCc);
  1707. }
  1708. }
  1709. }
  1710. //3判断是否存在串并联并修改推送状态 逻辑删除旧的推送人
  1711. {
  1712. //todo推送类型1单流程推送,2串联推送,3并联推送
  1713. Integer pushType = flowMainPush.getPushType();
  1714. if (pushType.equals(3)) {
  1715. //要逻辑删除自己和其他推送
  1716. //将其他并联推送的人员推送状态status改成2状态值
  1717. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  1718. }
  1719. }
  1720. }
  1721. } else if (addConfirmResult.getConfirmResult().equals("3")) {//退回上节点
  1722. FrameUser targetUser = null;
  1723. {// 发起流程引擎操作
  1724. //当前审核人/委托人代表的用户id
  1725. String myFrameUserId = proActiService.getMyFrameUserId(flowMainPush);
  1726. if (myFrameUserId == null) {
  1727. return null;
  1728. }
  1729. //当前审核人/委托人代表的用户
  1730. FrameUser myFrameUser = frameUserService.selectByPrimaryKey(myFrameUserId);
  1731. FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId());
  1732. while ("4".equals(flowMainLog.getAuditResult())) {
  1733. flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainLog.getUpMainLogId());
  1734. }
  1735. targetUser = frameUserService.selectByPrimaryKey(flowMainLog.getAuditUser());
  1736. flowService.runTask(flowMainPush.getTaskId(), null, "back", "退回上节点", targetUser, myFrameUser, null);
  1737. }
  1738. {
  1739. //存入流程日志表的id
  1740. String flowMainLogUuid = UUIDUtils.middleUUID();
  1741. //1修改主表状态
  1742. {
  1743. FlowMain flowMain1 = new FlowMain();
  1744. flowMain1.setId(flowMainPush.getFlowMainId());
  1745. flowMain1.setFlowStatus(1);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  1746. flowMain1.setLastMainLogId(flowMainLogUuid);
  1747. flowMain1.setUpdatedAt(new Date());
  1748. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  1749. this.updateByPrimaryKeySelective(flowMain1);
  1750. }
  1751. //2添加日志 ok
  1752. FlowMainLog flowMainLog = new FlowMainLog();
  1753. {
  1754. flowMainLog.setId(flowMainLogUuid);
  1755. flowMainLog.setFlowMainId(flowMain.getId());
  1756. flowMainLog.setFormId(flowMain.getFormId());
  1757. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  1758. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  1759. flowMainLog.setAuditResult("3");// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  1760. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  1761. flowMainLog.setAuditType("1");
  1762. flowMainLog.setFlowType(constantFlowType);
  1763. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  1764. {// 需要工作流引擎的支持
  1765. flowMainLog.setFlowId(flowMain.getFlowId());
  1766. flowMainLog.setTaskId(flowMainPush.getTaskId());
  1767. flowMainLog.setNodeName(nodeName);
  1768. flowMainLog.setPushUserKey(mypushUserKey);
  1769. }
  1770. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  1771. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  1772. flowMainLog.setCcList(null);
  1773. flowMainLog.setCreatedAt(new Date());
  1774. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  1775. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  1776. flowMainLog.setStatus(0);
  1777. flowMainLogService.insertWithoutId(flowMainLog);
  1778. }
  1779. //2.1添加抄送
  1780. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  1781. String[] split = addConfirmResult.getCcList().split(",");
  1782. for (String ccId : split) {
  1783. if (!StringUtils.isEmpty(ccId)) {
  1784. FlowMainCc flowMainCc = new FlowMainCc();
  1785. flowMainCc.setFlowMainId(flowMain.getId());
  1786. flowMainCc.setCcUser(ccId);
  1787. //选择抄送人时的记录表id(flow_main_log):例如:112122
  1788. flowMainCc.setMainLogIds(flowMainLog.getId());
  1789. flowMainCc.setUpdatedAt(new Date());
  1790. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  1791. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  1792. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  1793. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  1794. flowMainCc.setStatus(0);
  1795. flowMainCcService.insert(flowMainCc);
  1796. }
  1797. }
  1798. }
  1799. //3判断是否存在串并联并修改推送状态 逻辑删除旧的推送人
  1800. {
  1801. //todo推送类型1单流程推送,2串联推送,3并联推送
  1802. Integer pushType = flowMainPush.getPushType();
  1803. //逻辑删除本推送
  1804. {
  1805. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  1806. }
  1807. }
  1808. //4添加新的推送人员
  1809. {//查看各个任务
  1810. List<Task> listTask = taskService.createTaskQuery().processInstanceBusinessKey(flowMain.getId()).list();
  1811. //查看总的数据流程
  1812. List<UserTask> TaskList = flowService.getTaskList(deploymentid);
  1813. for (Task task : listTask) {
  1814. UserTask myUserTask = null;
  1815. {
  1816. String taskDefinitionKey = task.getTaskDefinitionKey();
  1817. for (UserTask userTask : TaskList) {
  1818. if (userTask.getId().equals(taskDefinitionKey)) {
  1819. myUserTask = userTask;
  1820. break;
  1821. }
  1822. }
  1823. //判断是否存在串并联并修改推送状态
  1824. //'推送时彭总给的key值',
  1825. String pushUserKey = null;
  1826. if (myUserTask != null) {
  1827. pushUserKey = myUserTask.getCandidateGroups().get(0);
  1828. }
  1829. //'推送类型1单流程推送,2串联推送,3并联推送',
  1830. Integer pushType = 1;
  1831. FlowMainPush newflowMainPush = new FlowMainPush();
  1832. newflowMainPush.setFlowMainId(flowMain.getId());
  1833. newflowMainPush.setFormId(flowMain.getFormId());
  1834. {// 需要工作流引擎的支持
  1835. if (!task.getAssignee().equals(targetUser.getId())) {
  1836. continue;
  1837. }
  1838. newflowMainPush.setPushUser(task.getAssignee());//推送人id'
  1839. newflowMainPush.setPushUserKey(pushUserKey);//推送时彭总给的key值
  1840. newflowMainPush.setNodeName(myUserTask.getName());
  1841. newflowMainPush.setPushType(pushType);//推送类型1单流程推送,2串联推送,3并联推送
  1842. newflowMainPush.setPushRole(1);//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  1843. newflowMainPush.setFlowType(constantFlowType);
  1844. newflowMainPush.setFlowPost(task.getAssignee());
  1845. newflowMainPush.setFlowId(flowMain.getFlowId());
  1846. newflowMainPush.setTaskId(task.getId());
  1847. }
  1848. newflowMainPush.setUpMainLogId(flowMainLog.getId());
  1849. newflowMainPush.setUpdatedAt(new Date());
  1850. newflowMainPush.setCreatedAt(newflowMainPush.getUpdatedAt());
  1851. newflowMainPush.setCreatedBy(operaterManage.getUser().getId());
  1852. newflowMainPush.setUpdatedBy(newflowMainPush.getCreatedBy());
  1853. newflowMainPush.setGroupId(operaterManage.getUser().getGroupId());
  1854. newflowMainPush.setStatus(0);
  1855. flowMainPushService.insert(newflowMainPush);
  1856. }
  1857. }
  1858. }
  1859. }
  1860. } else if (addConfirmResult.getConfirmResult().equals("4")) {//结束流程 ok
  1861. isEnd = true;
  1862. {// 发起流程引擎操作 并结束该流程
  1863. flowService.deleteInstance(flowMain.getFlowId(), "结束流程");
  1864. }
  1865. {
  1866. //存入流程日志表的id
  1867. String flowMainLogUuid = UUIDUtils.middleUUID();
  1868. //1修改主表状态
  1869. {
  1870. FlowMain flowMain1 = new FlowMain();
  1871. flowMain1.setId(flowMainPush.getFlowMainId());
  1872. flowMain1.setFlowStatus(3);//申请状态(1审批中,2,退回发起人,3,已结束,4已撤回)
  1873. flowMain1.setFlowResult(2); //审核结果0无状态,1审核通过结束,2审核不通过结束
  1874. flowMain1.setLastMainLogId(flowMainLogUuid);
  1875. flowMain1.setUpdatedAt(new Date());
  1876. flowMain1.setUpdatedBy(operaterManage.getUser().getId());
  1877. this.updateByPrimaryKeySelective(flowMain1);
  1878. }
  1879. //2添加日志 ok
  1880. FlowMainLog flowMainLog = new FlowMainLog();
  1881. {
  1882. flowMainLog.setId(flowMainLogUuid);
  1883. flowMainLog.setFlowMainId(flowMain.getId());
  1884. flowMainLog.setFormId(flowMain.getFormId());
  1885. flowMainLog.setAuditUser(operaterManage.getUser().getId());
  1886. flowMainLog.setAuditContent(addConfirmResult.getConfirmContent());
  1887. flowMainLog.setAuditResult("5");// `audit_result` varchar(4) DEFAULT NULL COMMENT 审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,5,不同意且结束流程,null没有审核)',
  1888. //审批类型(0流程开始状态还是1流程审核状态还是2流程结束状态还是3申请人暂停状态4申请人结束状态
  1889. flowMainLog.setAuditType("2");
  1890. flowMainLog.setFlowType(constantFlowType);
  1891. flowMainLog.setFlowPost(operaterManage.getUser().getId());
  1892. {// 需要工作流引擎的支持
  1893. flowMainLog.setFlowId(flowMain.getFlowId());
  1894. flowMainLog.setTaskId(flowMainPush.getTaskId());
  1895. flowMainLog.setNodeName(nodeName);
  1896. flowMainLog.setPushUserKey(mypushUserKey);
  1897. }
  1898. // 下一环节操作人(审核人/委托人/退回申请人),列表例如:,张三,李四,
  1899. flowMainLog.setUpMainLogId(flowMainPush.getUpMainLogId());
  1900. flowMainLog.setCcList(null);
  1901. flowMainLog.setCreatedAt(new Date());
  1902. flowMainLog.setCreatedBy(operaterManage.getUser().getId());
  1903. flowMainLog.setGroupId(operaterManage.getUser().getGroupId());
  1904. flowMainLog.setStatus(0);
  1905. flowMainLogService.insertWithoutId(flowMainLog);
  1906. }
  1907. //3 存入抄送人信息
  1908. if (!StringUtils.isEmpty(addConfirmResult.getCcList())) {
  1909. String[] split = addConfirmResult.getCcList().split(",");
  1910. for (String ccId : split) {
  1911. if (!StringUtils.isEmpty(ccId)) {
  1912. FlowMainCc flowMainCc = new FlowMainCc();
  1913. flowMainCc.setFlowMainId(flowMain.getId());
  1914. flowMainCc.setCcUser(ccId);
  1915. //选择抄送人时的记录表id(flow_main_log):例如:112122
  1916. flowMainCc.setMainLogIds(flowMainLog.getId());
  1917. flowMainCc.setUpdatedAt(new Date());
  1918. flowMainCc.setCreatedAt(flowMainCc.getUpdatedAt());
  1919. flowMainCc.setCreatedBy(operaterManage.getUser().getId());
  1920. flowMainCc.setUpdatedBy(flowMainCc.getCreatedBy());
  1921. flowMainCc.setGroupId(operaterManage.getUser().getGroupId());
  1922. flowMainCc.setStatus(0);
  1923. flowMainCcService.insert(flowMainCc);
  1924. }
  1925. }
  1926. }
  1927. //4.0逻辑删除旧的推送人
  1928. {
  1929. //todo推送类型1单流程推送,2串联推送,3并联推送
  1930. Integer pushType = flowMainPush.getPushType();
  1931. if (pushType.equals(3)) {
  1932. //要逻辑删除自己和其他推送
  1933. //将其他并联推送的人员推送状态status改成2状态值
  1934. flowMainPushService.updateStatusTwoByUpMainLogId(operaterManage.getUser().getId(), flowMainPush.getUpMainLogId(), flowMainPush.getId());
  1935. }
  1936. }
  1937. }
  1938. }
  1939. if (isEnd) {
  1940. return "ok_end";
  1941. } else {
  1942. return "ok_noEnd";
  1943. }
  1944. }
  1945. }