ProActiService.java 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531
  1. package com.idea.oa.activiti.service;
  2. import com.idea.oa.activiti.exception.FlowException;
  3. import com.idea.oa.activiti.model.UserTaskMore;
  4. import com.idea.oa.apply.util.constant.ConstantFlowType;
  5. import com.idea.oa.flow2.model.FlowMainLog;
  6. import com.idea.oa.flow2.model.FlowMainPush;
  7. import com.idea.oa.flow2.service.FlowMainLogService;
  8. import com.idea.oa.flow2.service.FlowMainService;
  9. import com.rockstar.common.domain.AjaxResult;
  10. import com.rockstar.common.support.Convert;
  11. import com.rockstar.flow.dto.TaskDto;
  12. import com.rockstar.flow.service.FlowService;
  13. import com.rockstar.frame.model.*;
  14. import com.rockstar.frame.service.*;
  15. import com.rockstar.system.model.SysDept;
  16. import com.rockstar.system.service.SysDeptService;
  17. import com.rockstar.util.BeanUtils;
  18. import com.rockstar.util.StringUtils;
  19. import org.activiti.bpmn.model.*;
  20. import org.activiti.bpmn.model.Process;
  21. import org.activiti.engine.RepositoryService;
  22. import org.activiti.engine.TaskService;
  23. import org.activiti.engine.task.Task;
  24. import org.activiti.engine.task.TaskInfo;
  25. import org.apache.commons.collections.CollectionUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.math.BigDecimal;
  30. import java.util.*;
  31. import java.util.stream.Collectors;
  32. @Service
  33. public class ProActiService {
  34. @Autowired
  35. private FlowMainLogService flowMainLogService;
  36. //todo 到时候如果先会签,串并联的问题,flowService.runTask和flowService.start判断一下,是否需要串联会签还是并联会签,如果是3的单人签核,1是并联会签,0是串联会签
  37. @Autowired
  38. private TaskService taskService;
  39. @Autowired
  40. private FlowService flowService;
  41. @Autowired
  42. private FlowMainService flowMainService;
  43. @Autowired
  44. private FrameUserService userService;
  45. //
  46. // @Autowired
  47. // private FramePostService postService;
  48. //
  49. @Autowired
  50. private SysDeptService sysDeptService;
  51. //
  52. //
  53. // @Autowired
  54. // private FrameUserDeptService frameUserDeptService;
  55. @Autowired
  56. private FrameUserService frameUserService;
  57. @Autowired
  58. private FrameRoleDataService frameRoleDataService;
  59. @Autowired
  60. private FrameRoleDataUserService frameRoleDataUserService;
  61. /**
  62. * ok
  63. * 删除并结束指定活动实例
  64. *
  65. * @param processInstanceId 启动流程的流程对象id
  66. * @param comments 评论/备注
  67. */
  68. @Transactional
  69. public void endTaskProcess(String processInstanceId, String comments) {
  70. flowService.deleteInstance(processInstanceId, comments);
  71. }
  72. /**
  73. * ok
  74. * 启动流程
  75. * 启动方法时,ActiDto内的必须值是:processType, currentUserId 和 businessId
  76. *
  77. * @param actiDto
  78. * @return
  79. * @throws FlowException
  80. */
  81. @Transactional
  82. public Map<String, String> startAutoTask(Map<String, Object> actiDto) throws FlowException, com.rockstar.flow.exception.FlowException {
  83. // processDefine 流程定义 apply_pay
  84. // dataRole 角色??是传什么?
  85. // businessId 流程id,就用主流程的id flow_main
  86. // targetUser 目标人员
  87. // currUser 当前人员
  88. String processDefine = "apply_pay";
  89. FrameUser targetUser = userService.selectByPrimaryKey("1080517374995595264");
  90. FrameUser currUser = userService.selectByPrimaryKey("1");
  91. // String businessId="1088138622709792768";
  92. // String businessId="1088140716548292608";
  93. String businessId = "1088140517679562752";//主申请表id
  94. Map<String, String> startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  95. //返回数据{processInstanceId=7501}{processInstanceId=12501}{processInstanceId=17501}
  96. String taskId = "任务ID:17516";
  97. String flow_id = startTask.get("processInstanceId").toString();
  98. ;
  99. return startTask;
  100. }
  101. /**
  102. * ok
  103. * 执行当前流程节点
  104. * 该方法中,ActiDto内除了businessId,其他都是必须值
  105. *
  106. * @param actiDto isEndSet,当业务发现可以结束审核的时候向方法外传送是否结束审核的信号
  107. * @return
  108. * @throws FlowException
  109. */
  110. @Transactional
  111. public Object runAutoTask(Map actiDto) throws FlowException, com.rockstar.flow.exception.FlowException {
  112. FrameUser targetUser = userService.selectByPrimaryKey("1080522875951120384");
  113. FrameUser currUser = userService.selectByPrimaryKey("1080517374995595264");
  114. // private String processType;
  115. // private String currentUserId;
  116. // private String operateUserId;
  117. // private String dataRole;
  118. // private String agree;==>yes/no
  119. // private String comments;===================>????
  120. // private String businessId;
  121. // private String taskId;===>在展示列表里面有taskId
  122. // flowDto.getTaskId(), flowDto.getDataRole(), flowDto.getAgree(), flowDto.getComments()
  123. Map<String, Object> map = new HashMap<>();
  124. map.put("billMoney", 1250);
  125. return flowService.runTask("12516", null, "yes", "zt omments", targetUser, currUser, null);
  126. }
  127. /**
  128. * 查询数据
  129. *
  130. * @param taskDto
  131. * @return
  132. * @throws FlowException
  133. */
  134. @Transactional
  135. public List findTask(TaskDto taskDto) throws FlowException {
  136. List<String> taskGroups = new ArrayList<>();
  137. return flowService.findTask(taskDto, taskGroups);
  138. }
  139. /**
  140. * 还不知道干什么用的,猜是查看备注用的
  141. *
  142. * @param taskId
  143. * @param isHistoric
  144. * @return
  145. * @throws FlowException
  146. */
  147. @Transactional
  148. public List getCommentsByTid(String taskId, Boolean isHistoric) throws FlowException {
  149. if (StringUtils.isEmpty(taskId))
  150. throw new FlowException("任务ID为空");
  151. if (null == isHistoric) {
  152. isHistoric = false;
  153. }
  154. return flowService.getComments(taskId, isHistoric);
  155. }
  156. /**
  157. * 通过taskId获取任务后续得任务组列表,任务组列表定义如下:
  158. * 1,任务组是有('岗位'和yes) 或('curr_user'和'no')组合而成得字符串,具体如:director-yes,office_leader-yes或curr_user-no等
  159. * 2,一般来说curr_user-no都是被退回之后指向得任务组,而带-yes后缀的是同意所指向得任务组
  160. * <p>
  161. * 使用方式:
  162. * 1,在待审批列表中打开某个审批任务,先通过taskId(任务ID)获取该任务后续得任务组
  163. * 2,分析所拥有得任务组,一般是2个或者1个任务组
  164. * 3,根据所获得得任务组,来安排界面'同意'和'不同意'得按钮显示或隐藏
  165. * 4,任务组含curr_user-no,就具备'不同意'按钮,点击不同意按钮,传输值:agree值为no, dataRole:'-no'之前的
  166. * 5,任务组含带-yes后缀的,就具备'同意'按钮,点击同意按钮,传输值:agree值为yes, dataRole:'-yes'之前的
  167. * 6,任务组如果只含curr_user-no,没其他的,那就具备'不同意'和'结束'按钮,点结束按钮,传输值:agree值为yes即可
  168. *
  169. * @param taskId 任务ID
  170. * @param isHistoric 是否历史任务
  171. * @return
  172. */
  173. @Transactional
  174. public List<String> nextTaskGroups(String taskId, boolean isHistoric) throws FlowException {
  175. if (StringUtils.isEmpty(taskId))
  176. throw new FlowException("任务ID为空");
  177. List<String> strings = flowService.nextTaskGroups(taskId, isHistoric);
  178. List<UserTask> userTasks = flowService.nextTasks(taskId, isHistoric);
  179. System.out.println("nextTasks数据为:" + userTasks);
  180. return strings;
  181. }
  182. //=======偏业务的,到时候要搬走的=========================================================================================================================================================
  183. public String getNodeName(FlowMainPush flowMainPush) {
  184. {
  185. Task task = null;
  186. List<Task> taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId()).taskId(flowMainPush.getTaskId()).list();
  187. if (taskList == null || taskList.isEmpty()) {
  188. return null;
  189. }
  190. task = taskList.get(0);
  191. return task.getName();
  192. }
  193. }
  194. /**
  195. * 通用方法 //当前审核人/委托人代表的用户id
  196. *
  197. * @param flowMainPush
  198. * @return
  199. */
  200. public String getMyFrameUserId(FlowMainPush flowMainPush) {
  201. //当前审核人/委托人代表的用户id
  202. String myFrameUserId = null;
  203. {
  204. Integer pushRole = flowMainPush.getPushRole();
  205. if (new Integer(1).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  206. myFrameUserId = flowMainPush.getPushUser();
  207. } else if (new Integer(2).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  208. //因为是被委托人,所以查到这个委托人的信息
  209. // {//通过流程监控进行操的时候就会有问题,不能找到原来的审核用户id 第一种方式,通过关联查询进行被委托人查询
  210. // FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId());
  211. // String auditResult = flowMainLog.getAuditResult();
  212. // if (!"4".equals(auditResult)) {// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  213. // return null;//异常情况
  214. // }
  215. // myFrameUserId = flowMainLog.getAuditUser();
  216. // }
  217. {//第二种方式
  218. // 通过 flowMainPush.getFlowPost()来获取对应的被委托人的信息,只是还没有测试不知道 第二种方式是否好用
  219. myFrameUserId = flowMainPush.getFlowPost();
  220. }
  221. } else {
  222. return null;//异常情况
  223. }
  224. }
  225. return myFrameUserId;
  226. }
  227. /**
  228. * 审核通过,进行下一步操作
  229. *
  230. * @return
  231. * @throws FlowException
  232. */
  233. @Transactional
  234. public Map<String, String> passToRunTask(FlowMainPush flowMainPush, String deploymentid, String businessId, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
  235. // 发起流程引擎操作 并查看下一节点的操作要求
  236. //0,如果是收纳且匹配上角色就正常流程审核,没有匹配上就返回null,异常错误 ok,
  237. //1. 如果当前角色是自己,就进行正常的审核流程 ok
  238. //2. 先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
  239. //当前审核人/委托人代表的用户id
  240. String myFrameUserId = this.getMyFrameUserId(flowMainPush);
  241. if (myFrameUserId == null) {
  242. return null;
  243. }
  244. // {
  245. // Integer pushRole = flowMainPush.getPushRole();
  246. // if (new Integer(1).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  247. // myFrameUserId = flowMainPush.getPushUser();
  248. // } else if (new Integer(2).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
  249. // //因为是被委托人,所以查到这个委托人的信息
  250. // {//第一种方式,通过关联查询进行被委托人查询
  251. // FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId());
  252. // String auditResult = flowMainLog.getAuditResult();
  253. // if (!"4".equals(auditResult)) {// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
  254. // return null;//异常情况
  255. // }
  256. // myFrameUserId = flowMainLog.getAuditUser();
  257. // }
  258. // {//第二种方式
  259. // //通过 flowMainPush.getFlowPost()来获取对应的被委托人的信息,只是还没有测试不知道 第二种方式是否好用
  260. //// myFrameUserId = flowMainPush.getFlowPost()
  261. // }
  262. // } else {
  263. // return null;//异常情况
  264. // }
  265. // }
  266. //当前审核人/委托人代表的用户
  267. FrameUser myframeUser = frameUserService.selectByPrimaryKey(myFrameUserId);
  268. //根据任务id获取任务信息
  269. //当前任务流程
  270. Task task = null;
  271. {
  272. List<Task> taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId()).taskId(flowMainPush.getTaskId()).list();
  273. if (taskList == null || taskList.isEmpty()) {
  274. return null;
  275. }
  276. task = taskList.get(0);
  277. }
  278. //本节点的关键子 例如flow_cnjs_1_1_0-yes
  279. String pushUserKey = flowMainPush.getPushUserKey();
  280. //本节点的角色 例如cnjs
  281. String setRurrRole = this.getSetRurrRole(pushUserKey);
  282. //判断setRurrRole是不是出纳类的角色,如果是出纳的角色,就判断当前审核人是不是也是出纳,是就继续,不是就是异常错误,返回null
  283. //判断是否符合出纳类型的要求 ok
  284. {
  285. for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  286. if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是出纳关系的查收纳
  287. //查看谁是对应角色并查找对应的人
  288. String role = ConstantFlowType.ROLES_CHECK[i];//找到是出纳类的角色
  289. // List<FrameRoleData> FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(myFrameUserId, ConstantFlowType.ROLETYPE);//"FLOW"
  290. // for (FrameRoleData frameRoleData : FrameRoleDatas) {
  291. // String roleKey = frameRoleData.getRoleKey();
  292. // if (roleKey.equals(role)) {
  293. // //匹配到对应的人,用正常流程做审核
  294. // return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  295. // }
  296. // }
  297. //如果没有匹配到就是异常错误,返回null
  298. // return null;
  299. //只所以注释掉上面的,是觉得原来订的审核人已经确认了,若中途改掉了也不需要校验了,确保流程的一致性,并能正常运行
  300. return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  301. }
  302. }
  303. }
  304. {
  305. //当前审核人/委托人代表的用户角色(只判断了是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的)
  306. String currRole = this.getCurrRole(myframeUser);
  307. //没有获取到角色,直接对到admin那里
  308. if (currRole == null || currRole.equals("")) {
  309. // 直接对到admin那里
  310. System.out.println("8没有找到对应人:" + " if (currRole == null || currRole.equals(\"\"))");
  311. FrameUser targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  312. if (targetUser == null) {
  313. System.err.println("异常,没有找到目标人");
  314. return null;
  315. }
  316. {//下面的替换这里的数据,来解决管理员无法结束流程的问题
  317. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap);
  318. // return new HashMap<>();
  319. }
  320. {
  321. return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  322. }
  323. }
  324. //当发现this.getCurrRole(myframeUser);获取的角色是普通员工的时候,就知道他作为审核人只是直接上级,并不是领导,所以把角色调上一级
  325. if (currRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[0])) {
  326. currRole = ConstantFlowType.FLOW_ROLES_DEPT[1];
  327. }
  328. // 不是出纳的情况下进行的判断
  329. //1.如果当前角色是自己,就进行正常的审核流程 ok
  330. //2.先查看当前角色是不是自己,不是自己就移动到自己的角FlowException色,然后再进行正常的审核流程 ok
  331. if (setRurrRole.equals(currRole)) {//1.如果当前角色是自己,就进行正常的审核流程 ok
  332. return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  333. } else {//2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
  334. FrameUser targetUser = null;
  335. UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
  336. // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  337. if (userPosition == null) {//没有找到数据
  338. System.out.println("9没有找到对应人:" + "if (userPosition == null) {");
  339. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  340. if (targetUser == null) {
  341. System.err.println("异常,没有找到目标人");
  342. return null;
  343. }
  344. boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap);
  345. return new HashMap<>();
  346. } else {//找到userPosition数据录了
  347. //还不是自己的角色,还要遍历查找
  348. return getNextFlow(businessId, userPosition, deploymentid, myframeUser, conditionMap, task);
  349. }
  350. }
  351. }
  352. }
  353. /**
  354. * 通用方法 写一个正常流程,正常下审核到下一个环节
  355. *
  356. * @param deploymentid 流程任务唯一id
  357. * @param currUser 当前审核人/委托人代表的用户
  358. * @param task2 当前的任务Task
  359. * @param conditionMap 所需要用到的条件
  360. * @return
  361. */
  362. public Map<String, String> donaturalTask(String deploymentid, FrameUser currUser, Task task2, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
  363. {
  364. FrameUser targetUser = null;
  365. //可以开始正常走流程了 嘻嘻...
  366. {
  367. UserTask myNowUserTask = this.getUserTaskById(task2.getTaskDefinitionKey(), deploymentid);//id的值如:_9
  368. //获取到了出去的各条路径
  369. List<SequenceFlow> outgoingFlows = myNowUserTask.getOutgoingFlows();
  370. //我的下一个节点位置
  371. SequenceFlow myNextSequenceFlow = null;
  372. for (SequenceFlow outgoingFlow : outgoingFlows) {
  373. String conditionExpression = outgoingFlow.getConditionExpression();
  374. //如果是空就跳过
  375. if (conditionExpression == null) {
  376. continue;
  377. } else
  378. //只有是yes的时候才是需要往下运行的,如果
  379. if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
  380. continue;
  381. } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
  382. continue;
  383. } else
  384. //只有是yes的时候才是需要往下运行的,如果
  385. if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
  386. //发现没有判断条件,那本流程就是下个节点
  387. myNextSequenceFlow = outgoingFlow;
  388. } else {
  389. //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
  390. //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
  391. //获取路径的判断条件
  392. // List<String> myconditionExpressions = new ArrayList<String>();
  393. // myconditionExpressions.add(conditionExpression);
  394. // int isOkNum = 0;
  395. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  396. // boolean isOk = false;
  397. // //这是我的判断条件(通过条件判断库去比对数据)
  398. // String mycondition = myconditionExpressions.get(i1);
  399. // if (mycondition.contains("billMoney")) {
  400. //// ${billMoney>3000}
  401. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  402. // if (mycondition.contains("<=")) {
  403. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  404. // if (billMoney <= Double.valueOf(substring)) {
  405. //// ok
  406. // isOk = true;
  407. //
  408. // }
  409. // } else if (mycondition.contains("<")) {
  410. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  411. // if (billMoney < Double.valueOf(substring)) {
  412. //// ok
  413. // isOk = true;
  414. // }
  415. // } else if (mycondition.contains(">=")) {
  416. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  417. // if (billMoney >= Double.valueOf(substring)) {
  418. //// ok
  419. // isOk = true;
  420. // }
  421. // } else if (mycondition.contains(">")) {
  422. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  423. // if (billMoney > Double.valueOf(substring)) {
  424. //// ok
  425. // isOk = true;
  426. // }
  427. // } else if (mycondition.contains("==")) {
  428. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  429. // BigDecimal data1 = new BigDecimal(billMoney);
  430. // BigDecimal data2 = new BigDecimal(substring);
  431. // int i2 = data1.compareTo(data2);
  432. // if (i2 == 0) {
  433. //// ok
  434. // isOk = true;
  435. // }
  436. // }
  437. // }
  438. //
  439. // if (isOk) {
  440. // isOkNum = isOkNum + 1;
  441. // }
  442. // }
  443. // if (isOkNum == myconditionExpressions.size()) {
  444. // myNextSequenceFlow = outgoingFlow;
  445. // break;
  446. // }
  447. if (this.booleanConditionIsOk(conditionExpression, conditionMap)) {
  448. myNextSequenceFlow = outgoingFlow;
  449. }
  450. }
  451. //如果没有找到下个流程节点就继续找
  452. if (myNextSequenceFlow == null) {
  453. continue;
  454. }
  455. {
  456. //下面是找到了下个流程节点,需要进行正常的运行节点了
  457. //================================================================
  458. //TaskList.get(1).getOutgoingFlows().get(1).getTargetFlowElement().getCandidateGroups()
  459. // TaskList.get(7).getOutgoingFlows().get(1).getTargetFlowElement().getClass().isInstance(EndEvent.class);
  460. FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
  461. if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
  462. System.out.println("已经是结束流程了,直接完成审核就行了1");
  463. boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
  464. HashMap<String, String> objectObjectHashMap = new HashMap<>();
  465. objectObjectHashMap.put("isEnd", "1");
  466. return objectObjectHashMap;
  467. }
  468. //class org.activiti.bpmn.model.EndEvent
  469. String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
  470. String setRurrRole = this.getSetRurrRole(candidateGroup);
  471. boolean end = false;
  472. for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  473. if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  474. {//统一到同一个方法中了:getTargerUser_FLOW_ROLES_DEPT
  475. // if (s.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导
  476. // String department = currUser.getDepartment();
  477. // SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
  478. // if (sysDept == null) {//没有部门信息
  479. //
  480. // } else {
  481. // String changedBy = sysDept.getChangedBy();
  482. // if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
  483. //
  484. // } else {
  485. // targetUser = userService.selectByPrimaryKey(changedBy);
  486. // }
  487. // }
  488. // } else {
  489. // String leader = currUser.getLeader();
  490. // if (StringUtils.isEmpty(leader)) {//没有找到直接领导
  491. // } else {
  492. // targetUser = userService.selectByPrimaryKey(leader);
  493. // }
  494. // }
  495. // if (targetUser == null) {//没有找到目标人就都传到admin中去
  496. //// return null;
  497. // targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  498. // if (targetUser == null) {
  499. // System.err.println("异常,没有找到目标人");
  500. // return null;
  501. // }
  502. // }
  503. }
  504. // 写一个通用方法,专门根据条件获取部门领导是谁
  505. targetUser = this.getTargerUser_FLOW_ROLES_DEPT(s, currUser);
  506. if (targetUser == null) {
  507. return null;
  508. }
  509. //todo SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
  510. boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  511. end = true;
  512. return new HashMap<>();
  513. }
  514. }
  515. if (!end) {
  516. for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  517. if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  518. //查看谁是对应角色并查找对应的人
  519. String role = ConstantFlowType.ROLES[i];
  520. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  521. // 在上面的方法基础上,增加groupId和用户状态的过滤
  522. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
  523. role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
  524. if (!targetUserList.isEmpty()) {
  525. if (targetUserList.size() >= 1) {
  526. targetUser = targetUserList.get(0);
  527. }
  528. }
  529. if (targetUser == null) {
  530. // return null;
  531. System.out.println("1没有找到对应人:" + "if (targetUser == null) {==>" + role + "==>" + ConstantFlowType.ROLETYPE);
  532. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  533. if (targetUser == null) {
  534. System.err.println("异常,没有找到目标人");
  535. return null;
  536. }
  537. }
  538. boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  539. end = true;
  540. return new HashMap<>();
  541. }
  542. }
  543. }
  544. if (!end) {
  545. for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  546. if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  547. //查看谁是对应角色并查找对应的人
  548. String role = ConstantFlowType.ROLES_CHECK[i];
  549. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  550. // 在上面的方法基础上,增加groupId和用户状态的过滤
  551. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
  552. role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
  553. if (!targetUserList.isEmpty()) {
  554. if (targetUserList.size() >= 1) {
  555. targetUser = targetUserList.get(0);
  556. }
  557. }
  558. if (targetUser == null) {
  559. // return null;
  560. System.out.println("2没有找到对应人:" + "if (targetUser == null) {");
  561. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  562. if (targetUser == null) {
  563. System.err.println("异常,没有找到目标人");
  564. return null;
  565. }
  566. }
  567. boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  568. end = true;
  569. return new HashMap<>();
  570. }
  571. }
  572. }
  573. if (!end) {
  574. for (int i = 0; i < ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK.length; i++) {
  575. if (ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  576. //查看谁是对应角色并查找对应的人
  577. String role = ConstantFlowType.PURCHASE_ROLES_CHECK[i];
  578. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  579. // 在上面的方法基础上,增加groupId和用户状态的过滤
  580. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
  581. role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
  582. if (!targetUserList.isEmpty()) {
  583. targetUser = targetUserList.get(0);
  584. }
  585. if (targetUser == null) {
  586. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  587. if (targetUser == null) {
  588. return null;
  589. }
  590. }
  591. flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  592. return new HashMap<>();
  593. }
  594. }
  595. }
  596. break;
  597. }
  598. }
  599. //都没有就是没有下个流程了,可以结束流程了
  600. System.out.println("已经没有下个申请流程了,已经结束了1");
  601. //
  602. boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
  603. HashMap<String, String> objectObjectHashMap = new HashMap<>();
  604. objectObjectHashMap.put("isEnd", "1");
  605. return objectObjectHashMap;
  606. }
  607. //下面的代码要替换掉==========================================================================================
  608. // {
  609. //
  610. // //可以开始正常走流程了 嘻嘻...
  611. // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task2.getTaskDefinitionKey(), false);
  612. // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
  613. // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
  614. // UserTask myNextTask = null;//我要走的流程
  615. // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
  616. // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
  617. // if (!"-yes".equals(candidateGroup.substring(candidateGroup.indexOf("-")))){
  618. // continue;
  619. // }
  620. // String setRurrRole = this.getSetRurrRole(candidateGroup);
  621. // {
  622. // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
  623. // //获取路径的判断条件
  624. // List<String> myconditionExpressions = new ArrayList<String>();
  625. // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
  626. // for (SequenceFlow outgoingFlow : outgoingFlows) {
  627. // String conditionExpression = outgoingFlow.getConditionExpression();
  628. // if (conditionExpression == null) {
  629. // continue;
  630. // }
  631. // if (conditionExpression.contains("${agree==")) {
  632. // continue;
  633. // }
  634. // myconditionExpressions.add(conditionExpression);
  635. // }
  636. // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
  637. // myNextTask = userTask;
  638. //
  639. // } else {//有条件就判断是否满足条件,不满足就运行下一个
  640. // int isOkNum = 0;
  641. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  642. // boolean isOk = false;
  643. // //这是我的判断条件(通过条件判断库去比对数据)
  644. // String mycondition = myconditionExpressions.get(i1);
  645. // if (mycondition.contains("billMoney")) {
  646. //// ${billMoney>3000}
  647. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  648. // if (mycondition.contains("<=")) {
  649. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  650. // if (billMoney <= Double.valueOf(substring)) {
  651. //// ok
  652. // isOk = true;
  653. //
  654. // }
  655. // } else if (mycondition.contains("<")) {
  656. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  657. // if (billMoney < Double.valueOf(substring)) {
  658. //// ok
  659. // isOk = true;
  660. // }
  661. // } else if (mycondition.contains(">=")) {
  662. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  663. // if (billMoney >= Double.valueOf(substring)) {
  664. //// ok
  665. // isOk = true;
  666. // }
  667. // } else if (mycondition.contains(">")) {
  668. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  669. // if (billMoney > Double.valueOf(substring)) {
  670. //// ok
  671. // isOk = true;
  672. // }
  673. // } else if (mycondition.contains("==")) {
  674. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  675. // BigDecimal data1 = new BigDecimal(billMoney);
  676. // BigDecimal data2 = new BigDecimal(substring);
  677. // int i2 = data1.compareTo(data2);
  678. // if (i2 == 0) {
  679. //// ok
  680. // isOk = true;
  681. // }
  682. // }
  683. // }
  684. //
  685. // if (isOk) {
  686. // isOkNum = isOkNum + 1;
  687. // }
  688. // }
  689. // if (isOkNum == myconditionExpressions.size()) {
  690. // myNextTask = userTask;
  691. // }
  692. //
  693. // if (myNextTask == null) {
  694. // continue;
  695. // }
  696. //
  697. // }
  698. // }
  699. // //================================================================
  700. // boolean end = false;
  701. // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  702. // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  703. // String leader = currUser.getLeader();
  704. // targetUser = userService.selectByPrimaryKey(leader);
  705. // if (targetUser == null) {
  706. // return null;
  707. // }
  708. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  709. //
  710. // end = true;
  711. // return new HashMap<>();
  712. // }
  713. // }
  714. // if (!end) {
  715. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  716. // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  717. // //查看谁是对应角色并查找对应的人
  718. // String role = ConstantFlowType.ROLES[i];
  719. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  720. // if (!targetUserList.isEmpty()) {
  721. // if (targetUserList.size() >= 1) {
  722. // targetUser = targetUserList.get(0);
  723. // }
  724. // }
  725. // if (targetUser == null) {
  726. // return null;
  727. // }
  728. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  729. // end = true;
  730. // return new HashMap<>();
  731. // }
  732. // }
  733. //
  734. // }
  735. // if (!end) {
  736. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  737. // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  738. // //查看谁是对应角色并查找对应的人
  739. // String role = ConstantFlowType.ROLES_CHECK[i];
  740. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  741. // if (!targetUserList.isEmpty()) {
  742. // if (targetUserList.size() >= 1) {
  743. // targetUser = targetUserList.get(0);
  744. // }
  745. // }
  746. // if (targetUser == null) {
  747. // return null;
  748. // }
  749. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  750. // end = true;
  751. // return new HashMap<>();
  752. // }
  753. // }
  754. // }
  755. // break;
  756. // }
  757. // //都没有就是没有下个流程了,可以结束流程了
  758. // System.out.println("已经没有下个申请流程了,已经结束了");
  759. // //
  760. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
  761. //
  762. // HashMap<String, String> objectObjectHashMap = new HashMap<>();
  763. // objectObjectHashMap.put("isEnd","1");
  764. // return objectObjectHashMap;
  765. // } else {
  766. // System.out.println("已经没有下个申请流程了,已经结束了");
  767. // //
  768. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
  769. //
  770. // HashMap<String, String> objectObjectHashMap = new HashMap<>();
  771. // objectObjectHashMap.put("isEnd","1");
  772. // return objectObjectHashMap;
  773. // }
  774. // }
  775. }
  776. }
  777. /**
  778. * 写一个通用方法判断流程中的条件是否符合要求
  779. * conditionExpression 判断的条件
  780. * conditionMap拥有的条件
  781. */
  782. public boolean booleanConditionIsOk(String conditionExpression, Map<String, Object> conditionMap) {
  783. //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
  784. //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
  785. //获取路径的判断条件
  786. List<String> myconditionExpressions = new ArrayList<String>();
  787. myconditionExpressions.add(conditionExpression);
  788. int isOkNum = 0;
  789. for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  790. boolean isOk = false;
  791. //这是我的判断条件(通过条件判断库去比对数据)
  792. String mycondition = myconditionExpressions.get(i1);
  793. if (mycondition.contains("billMoney")) {
  794. // ${billMoney>3000}
  795. Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  796. if (mycondition.contains("<=")) {
  797. String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  798. if (billMoney <= Double.valueOf(substring)) {
  799. // ok
  800. isOk = true;
  801. }
  802. } else if (mycondition.contains("<")) {
  803. String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  804. if (billMoney < Double.valueOf(substring)) {
  805. // ok
  806. isOk = true;
  807. }
  808. } else if (mycondition.contains(">=")) {
  809. String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  810. if (billMoney >= Double.valueOf(substring)) {
  811. // ok
  812. isOk = true;
  813. }
  814. } else if (mycondition.contains(">")) {
  815. String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  816. if (billMoney > Double.valueOf(substring)) {
  817. // ok
  818. isOk = true;
  819. }
  820. } else if (mycondition.contains("==")) {
  821. String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  822. BigDecimal data1 = new BigDecimal(billMoney);
  823. BigDecimal data2 = new BigDecimal(substring);
  824. int i2 = data1.compareTo(data2);
  825. if (i2 == 0) {
  826. // ok
  827. isOk = true;
  828. }
  829. }
  830. } else if (mycondition.contains("isExchangeOnly==")) {
  831. String isExchangeOnly = conditionMap.get("isExchangeOnly").toString();
  832. Integer applyDay = Integer.valueOf(conditionMap.get("applyDay").toString());
  833. if (mycondition.contains("(isExchangeOnly=='no') and (applyDay>3)")) {
  834. if ("no".equals(isExchangeOnly) && applyDay > 3) {
  835. isOk = true;
  836. }
  837. } else if (mycondition.contains("(isExchangeOnly=='yes') or (applyDay<=3)")) {
  838. if ("yes".equals(isExchangeOnly) || applyDay <= 3) {
  839. isOk = true;
  840. }
  841. }
  842. }
  843. if (isOk) {
  844. isOkNum = isOkNum + 1;
  845. }
  846. }
  847. if (isOkNum == myconditionExpressions.size()) {
  848. return true;
  849. } else {
  850. return false;
  851. }
  852. }
  853. /**
  854. * 根据用户位置启动信息启动流程
  855. * processDefine 在ConstantFlowType中的PAYMEN_PROCESSDEFINE
  856. * String businessId = "1088140517679562752";//主申请表id
  857. * deploymentid 在ConstantFlowType.USE_MONEY_DEPLOYMENTID
  858. * conditionMap 是条件数据,比如目前需要的条件是${billMoney>3000}
  859. * return 返回的数据是flow_id字段,如果是null,说明异常有问题了 如果是end就是没有下个流程了,可以结束了
  860. */
  861. public Map<String, String> startTask(String processDefine, String deploymentid, String businessId, FrameUser currUser, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
  862. FrameUser targetUser = null;
  863. String currRole = this.getCurrRole(currUser);
  864. UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
  865. // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  866. Map<String, String> startTask = null;
  867. if (userPosition == null) {//没有找到数据
  868. System.out.println("7没有找到对应人:" + " if (userPosition == null) {");
  869. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  870. if (targetUser == null) {
  871. System.err.println("异常,没有找到目标人");
  872. return null;
  873. }
  874. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  875. return startTask;
  876. } else {//找到userPosition对象数据了
  877. // 1.如果是1就正常网下写,如果发现目标审核人的角色不是正常角色,就要去找他的对应位置的角色,不管是谁都要审核通过才行, 所以开始的时候只要找到直接领导传下去就好了,在运行节点进行角色判断,将流程跳到自己的角色位置结束
  878. //1.1查看下个节点人员角色的需求
  879. //1.1.1如果是部门关系的查部门
  880. //1.1.2如果是领导关系的查领导
  881. //1.1.3如果是收纳关系的查收纳
  882. //2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  883. int nodeNum = userPosition.getNodeNum();
  884. UserTask currentUserTask = userPosition.getCurrentUserTask();
  885. if (nodeNum == 1) {
  886. {
  887. List<SequenceFlow> outgoingFlows = currentUserTask.getOutgoingFlows();
  888. //我的下一个节点位置
  889. SequenceFlow myNextSequenceFlow = null;
  890. for (SequenceFlow outgoingFlow : outgoingFlows) {
  891. String conditionExpression = outgoingFlow.getConditionExpression();
  892. //如果是空就跳过
  893. if (conditionExpression == null) {
  894. continue;
  895. } else
  896. //只有是yes的时候才是需要往下运行的,如果
  897. if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
  898. continue;
  899. } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
  900. continue;
  901. } else
  902. //只有是yes的时候才是需要往下运行的,如果
  903. if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
  904. //发现没有判断条件,那本流程就是下个节点
  905. myNextSequenceFlow = outgoingFlow;
  906. } else {
  907. //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
  908. //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
  909. //获取路径的判断条件
  910. // List<String> myconditionExpressions = new ArrayList<String>();
  911. // myconditionExpressions.add(conditionExpression);
  912. // int isOkNum = 0;
  913. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  914. // boolean isOk = false;
  915. // //这是我的判断条件(通过条件判断库去比对数据)
  916. // String mycondition = myconditionExpressions.get(i1);
  917. // if (mycondition.contains("billMoney")) {
  918. //// ${billMoney>3000}
  919. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  920. // if (mycondition.contains("<=")) {
  921. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  922. // if (billMoney <= Double.valueOf(substring)) {
  923. //// ok
  924. // isOk = true;
  925. //
  926. // }
  927. // } else if (mycondition.contains("<")) {
  928. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  929. // if (billMoney < Double.valueOf(substring)) {
  930. //// ok
  931. // isOk = true;
  932. // }
  933. // } else if (mycondition.contains(">=")) {
  934. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  935. // if (billMoney >= Double.valueOf(substring)) {
  936. //// ok
  937. // isOk = true;
  938. // }
  939. // } else if (mycondition.contains(">")) {
  940. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  941. // if (billMoney > Double.valueOf(substring)) {
  942. //// ok
  943. // isOk = true;
  944. // }
  945. // } else if (mycondition.contains("==")) {
  946. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  947. // BigDecimal data1 = new BigDecimal(billMoney);
  948. // BigDecimal data2 = new BigDecimal(substring);
  949. // int i2 = data1.compareTo(data2);
  950. // if (i2 == 0) {
  951. //// ok
  952. // isOk = true;
  953. // }
  954. // }
  955. // }
  956. //
  957. // if (isOk) {
  958. // isOkNum = isOkNum + 1;
  959. // }
  960. // }
  961. // if (isOkNum == myconditionExpressions.size()) {
  962. // myNextSequenceFlow = outgoingFlow;
  963. // break;
  964. // }
  965. if (this.booleanConditionIsOk(conditionExpression, conditionMap)) {
  966. myNextSequenceFlow = outgoingFlow;
  967. }
  968. }
  969. //如果没有找到下个流程节点就继续找
  970. if (myNextSequenceFlow == null) {
  971. continue;
  972. }
  973. //下面是找到了下个流程节点,需要进行正常的运行节点了
  974. FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
  975. if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
  976. System.out.println("已经是结束流程了,直接完成审核就行了2");
  977. return null;
  978. }
  979. String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
  980. String setRurrRole = this.getSetRurrRole(candidateGroup);
  981. boolean end = false;
  982. for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  983. if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  984. //统一到同一个方法中了:getTargerUser_FLOW_ROLES_DEPT
  985. // 写一个通用方法,专门根据条件获取部门领导是谁
  986. targetUser = this.getTargerUser_FLOW_ROLES_DEPT(s, currUser);
  987. if (targetUser == null) {
  988. return null;
  989. }
  990. //todo SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
  991. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  992. end = true;
  993. return startTask;
  994. }
  995. }
  996. if (!end) {
  997. for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  998. if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  999. //查看谁是对应角色并查找对应的人
  1000. String role = ConstantFlowType.ROLES[i];
  1001. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1002. // 在上面的方法基础上,增加groupId和用户状态的过滤
  1003. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
  1004. role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
  1005. if (!targetUserList.isEmpty()) {
  1006. if (targetUserList.size() >= 1) {
  1007. targetUser = targetUserList.get(0);
  1008. }
  1009. }
  1010. if (targetUser == null) {
  1011. // return null;
  1012. System.out.println("3没有找到对应人:" + "if (targetUser == null) {");
  1013. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  1014. if (targetUser == null) {
  1015. System.err.println("异常,没有找到目标人");
  1016. return null;
  1017. }
  1018. }
  1019. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1020. end = true;
  1021. return startTask;
  1022. }
  1023. }
  1024. }
  1025. if (!end) {
  1026. for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  1027. if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  1028. //查看谁是对应角色并查找对应的人
  1029. String role = ConstantFlowType.ROLES_CHECK[i];
  1030. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1031. // 在上面的方法基础上,增加groupId和用户状态的过滤
  1032. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
  1033. role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
  1034. if (!targetUserList.isEmpty()) {
  1035. if (targetUserList.size() >= 1) {
  1036. targetUser = targetUserList.get(0);
  1037. }
  1038. }
  1039. if (targetUser == null) {
  1040. // return null;
  1041. System.out.println("4没有找到对应人:" + "if (targetUser == null) {");
  1042. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  1043. if (targetUser == null) {
  1044. System.err.println("异常,没有找到目标人");
  1045. return null;
  1046. }
  1047. }
  1048. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1049. end = true;
  1050. return startTask;
  1051. }
  1052. }
  1053. }
  1054. return null;
  1055. }
  1056. //走到这里就没有找到对应的流程节点,所以需要报错 返回null
  1057. System.out.println("异常错误,没有找到对应的流程节点");
  1058. return null;
  1059. }
  1060. //下面的要作废了================================================================
  1061. //获取下个节点数据
  1062. // {
  1063. // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, currentUserTask.getId(), false);
  1064. // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
  1065. // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(0);
  1066. // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
  1067. // String setRurrRole = this.getSetRurrRole(candidateGroup);
  1068. // boolean end = false;
  1069. // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  1070. // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  1071. // String leader = currUser.getLeader();
  1072. // targetUser = userService.selectByPrimaryKey(leader);
  1073. // if (targetUser == null) {
  1074. // return null;
  1075. // }
  1076. // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1077. // end = true;
  1078. // return startTask;
  1079. // }
  1080. // }
  1081. // if (!end) {
  1082. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  1083. // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  1084. // //查看谁是对应角色并查找对应的人
  1085. // String role = ConstantFlowType.ROLES[i];
  1086. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1087. // if (!targetUserList.isEmpty()) {
  1088. // if (targetUserList.size() >= 1) {
  1089. // targetUser = targetUserList.get(0);
  1090. // }
  1091. // }
  1092. // if (targetUser == null) {
  1093. // return null;
  1094. // }
  1095. // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1096. // end = true;
  1097. // return startTask;
  1098. // }
  1099. // }
  1100. //
  1101. // }
  1102. // if (!end) {
  1103. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  1104. // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  1105. // //查看谁是对应角色并查找对应的人
  1106. // String role = ConstantFlowType.ROLES_CHECK[i];
  1107. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1108. // if (!targetUserList.isEmpty()) {
  1109. // if (targetUserList.size() >= 1) {
  1110. // targetUser = targetUserList.get(0);
  1111. // }
  1112. // }
  1113. // if (targetUser == null) {
  1114. // return null;
  1115. // }
  1116. // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1117. // end = true;
  1118. // return startTask;
  1119. // }
  1120. // }
  1121. // }
  1122. // return null;
  1123. //
  1124. // } else {
  1125. // return null;
  1126. // }
  1127. // }
  1128. } else if (nodeNum > 1) {
  1129. // 2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  1130. // 需要进行循环审核过程
  1131. boolean isZhuYaoLingDao="flow_zyld".equals(currRole)?true:false; //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断
  1132. // 现在没有:开始申请的时候不判断身份是否是该节点本身份 的判断了 if(isZhuYaoLingDao) {//2023年7月5日 章总在第七批次又改回来了 //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断
  1133. if(true) {
  1134. targetUser = currUser;
  1135. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1136. if (!startTask.isEmpty()) {
  1137. {
  1138. // String flow_id = startTask.get("processInstanceId").toString();//"流程实例ID:" + task.getProcessInstanceId());是会变化的所以没有用
  1139. List<Task> list = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象
  1140. .taskAssignee(targetUser.getId())//指定个人任务查询
  1141. // .processInstanceId("12516")
  1142. .list();
  1143. if (list == null || list.isEmpty() || list.size() <= 0) {
  1144. System.err.println("异常,没有找到任务对象");
  1145. return null;
  1146. }
  1147. //2.1通过flow_id和targetUser获取下一个UserTask
  1148. Task task = list.get(0);
  1149. //task是当前流程的信息
  1150. //如果发现task对应的角色就是自己的角色,就开始正常的走
  1151. //如果发现task对应的角色还不是,就需要再进行设置自己的操作
  1152. String taskDefinitionKey = task.getTaskDefinitionKey(); //id的值如:_9
  1153. String flowId = userPosition.getUserTask().getId();//流程唯一id(我猜的)
  1154. if (flowId.equals(taskDefinitionKey)) {
  1155. //可以开始正常走流程了 嘻嘻...
  1156. {
  1157. // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task.getTaskDefinitionKey(), false);
  1158. // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
  1159. // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
  1160. // UserTask myNextTask = null;//我要走的流程
  1161. // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
  1162. // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
  1163. // //需要的角色
  1164. // String setRurrRole = this.getSetRurrRole(candidateGroup);
  1165. // {
  1166. // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
  1167. // //获取路径的判断条件
  1168. // List<String> myconditionExpressions = new ArrayList<String>();
  1169. // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
  1170. // for (SequenceFlow outgoingFlow : outgoingFlows) {
  1171. // String conditionExpression = outgoingFlow.getConditionExpression();
  1172. // if (conditionExpression == null) {
  1173. // continue;
  1174. // }
  1175. // if (conditionExpression.contains("${agree==")) {
  1176. // continue;
  1177. // }
  1178. // myconditionExpressions.add(conditionExpression);
  1179. // }
  1180. // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
  1181. // myNextTask = userTask;
  1182. //
  1183. // } else {//有条件就判断是否满足条件,不满足就运行下一个
  1184. // int isOkNum = 0;
  1185. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  1186. // boolean isOk = false;
  1187. // //这是我的判断条件(通过条件判断库去比对数据)
  1188. // String mycondition = myconditionExpressions.get(i1);
  1189. // if (mycondition.contains("billMoney")) {
  1190. //// ${billMoney>3000}
  1191. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  1192. // if (mycondition.contains("<=")) {
  1193. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  1194. // if (billMoney <= Double.valueOf(substring)) {
  1195. //// ok
  1196. // isOk = true;
  1197. //
  1198. // }
  1199. // } else if (mycondition.contains("<")) {
  1200. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  1201. // if (billMoney < Double.valueOf(substring)) {
  1202. //// ok
  1203. // isOk = true;
  1204. // }
  1205. // } else if (mycondition.contains(">=")) {
  1206. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  1207. // if (billMoney >= Double.valueOf(substring)) {
  1208. //// ok
  1209. // isOk = true;
  1210. // }
  1211. // } else if (mycondition.contains(">")) {
  1212. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  1213. // if (billMoney > Double.valueOf(substring)) {
  1214. //// ok
  1215. // isOk = true;
  1216. // }
  1217. // } else if (mycondition.contains("==")) {
  1218. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  1219. // BigDecimal data1 = new BigDecimal(billMoney);
  1220. // BigDecimal data2 = new BigDecimal(substring);
  1221. // int i2 = data1.compareTo(data2);
  1222. // if (i2 == 0) {
  1223. //// ok
  1224. // isOk = true;
  1225. // }
  1226. // }
  1227. // }
  1228. //
  1229. // if (isOk) {
  1230. // isOkNum = isOkNum + 1;
  1231. // }
  1232. // }
  1233. // if (isOkNum == myconditionExpressions.size()) {
  1234. // myNextTask = userTask;
  1235. // }
  1236. //
  1237. // if (myNextTask == null) {
  1238. // continue;
  1239. // }
  1240. //
  1241. // }
  1242. // }
  1243. // //================================================================
  1244. // boolean end = false;
  1245. // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  1246. // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  1247. // String leader = currUser.getLeader();
  1248. // targetUser = userService.selectByPrimaryKey(leader);
  1249. // if (targetUser == null) {
  1250. // return null;
  1251. // }
  1252. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1253. //
  1254. // end = true;
  1255. // return new HashMap<>();
  1256. // }
  1257. // }
  1258. // if (!end) {
  1259. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  1260. // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  1261. // //查看谁是对应角色并查找对应的人
  1262. // String role = ConstantFlowType.ROLES[i];
  1263. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1264. // if (!targetUserList.isEmpty()) {
  1265. // if (targetUserList.size() >= 1) {
  1266. // targetUser = targetUserList.get(0);
  1267. // }
  1268. // }
  1269. // if (targetUser == null) {
  1270. // return null;
  1271. // }
  1272. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1273. // end = true;
  1274. // return new HashMap<>();
  1275. // }
  1276. // }
  1277. //
  1278. // }
  1279. // if (!end) {
  1280. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  1281. // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  1282. // //查看谁是对应角色并查找对应的人
  1283. // String role = ConstantFlowType.ROLES_CHECK[i];
  1284. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1285. // if (!targetUserList.isEmpty()) {
  1286. // if (targetUserList.size() >= 1) {
  1287. // targetUser = targetUserList.get(0);
  1288. // }
  1289. // }
  1290. // if (targetUser == null) {
  1291. // return null;
  1292. // }
  1293. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1294. // end = true;
  1295. // return new HashMap<>();
  1296. // }
  1297. // }
  1298. // }
  1299. // break;
  1300. // }
  1301. // } else {
  1302. // System.out.println("已经没有下个申请流程了,已经结束了");
  1303. // return null;
  1304. // }
  1305. }
  1306. Map<String, String> donaturalTaskMap = this.donaturalTask(deploymentid, currUser, task, conditionMap);
  1307. if (donaturalTaskMap == null) {
  1308. return null;
  1309. } else {
  1310. return startTask;
  1311. }
  1312. } else {
  1313. //还不是自己的角色,还要遍历查找(但是要写在getNextFlow方法里面,且通过flowServiceNextFlow方法改造一下)
  1314. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1315. {//遍历对象
  1316. Map<String, String> getNextFlowMap = getNextFlow(businessId, userPosition, deploymentid, currUser, conditionMap, task);
  1317. if (getNextFlowMap == null) {
  1318. return null;
  1319. } else {
  1320. //todo 如果getNextFlowMap返回数据是:{isEnd=1} 需要特殊处理
  1321. if (getNextFlowMap.get("isEnd") == null) {
  1322. return startTask;
  1323. } else {
  1324. startTask.put("isEnd", getNextFlowMap.get("isEnd"));
  1325. return startTask;
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. } else {
  1332. return null;
  1333. }
  1334. }else { //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以新增掉下面的操作
  1335. if (currUser.getLeader()!=null) {
  1336. targetUser = userService.selectByPrimaryKey(currUser.getLeader());
  1337. }
  1338. if (targetUser==null){
  1339. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  1340. }
  1341. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  1342. if (!startTask.isEmpty()) {
  1343. return startTask;
  1344. } else {
  1345. return null;
  1346. }
  1347. }
  1348. } else {
  1349. return null;
  1350. }
  1351. //为了实现并联串联审核流程的方法需求
  1352. //要求:flowService.startTask(processDefine, null, businessId, targetUser, currUser);改成flowService.startTask(processDefine, null, businessId, targetUsers,totalnumber, currUser);(修改内容目标人改成数组targetUsers,审核通过数量totalnumber自己定义)
  1353. //要求2:flowService.runTask(taskId, null, agree, comments, targetUser, currUser, null);改成flowService.runTask(taskId, null, agree, comments, targetUsers,totalnumber, currUser, null);(修改内容目标人改成数组targetUsers,审核通过数量totalnumber自己定义)
  1354. }
  1355. //返回数据{processInstanceId=7501}{processInstanceId=12501}{processInstanceId=17501}
  1356. }
  1357. /**
  1358. * 做一个通用方法,通过UserTask的id和deloymentId来获取指定的UserTask
  1359. */
  1360. public UserTask getUserTaskById(String id, String deloymentId) {
  1361. List<UserTask> taskList = flowService.getTaskList(deloymentId);
  1362. for (int i = 0; i < taskList.size(); i++) {
  1363. if (taskList.get(i).getId().equals(id)) {
  1364. return taskList.get(i);
  1365. }
  1366. }
  1367. return null;
  1368. // List<UserTask> collect = taskList.stream().filter(x -> x.getId().equals(id)).collect(Collectors.toList());
  1369. // if (collect.isEmpty()){
  1370. // return null;
  1371. // }else{
  1372. // return collect.get(0);
  1373. // }
  1374. }
  1375. /**
  1376. * 通过任务id获取userTask信息
  1377. *
  1378. * @param taskId
  1379. * @return
  1380. */
  1381. public UserTask getUserTaskByTaskId(String taskId) {
  1382. return (UserTask) flowService.getCurrentFlowNode(taskId);
  1383. }
  1384. /**
  1385. * 写一个方法,当还不是自己的角色时,需要进入下个节点,若下个节点是收纳就可以结束运行,返回false,说明是end结束了,若返回true,说明正常继续运行
  1386. *
  1387. * @return
  1388. */
  1389. public Boolean flowServiceNextFlow(String deploymentid, Map<String, Object> conditionMap, FrameUser currUser, Task task) throws com.rockstar.flow.exception.FlowException {
  1390. //获取到了我的userTask
  1391. {
  1392. UserTask myNowUserTask = this.getUserTaskById(task.getTaskDefinitionKey(), deploymentid);//id的值如:_9
  1393. //获取到了出去的各条路径
  1394. List<SequenceFlow> outgoingFlows = myNowUserTask.getOutgoingFlows();
  1395. //我的下一个节点位置
  1396. SequenceFlow myNextSequenceFlow = null;
  1397. for (SequenceFlow outgoingFlow : outgoingFlows) {
  1398. String conditionExpression = outgoingFlow.getConditionExpression();
  1399. //如果是空就跳过
  1400. if (conditionExpression == null) {
  1401. continue;
  1402. } else
  1403. //只有是yes的时候才是需要往下运行的,如果
  1404. if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
  1405. continue;
  1406. } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
  1407. continue;
  1408. } else
  1409. //只有是yes的时候才是需要往下运行的,如果
  1410. if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
  1411. //发现没有判断条件,那本流程就是下个节点
  1412. myNextSequenceFlow = outgoingFlow;
  1413. } else {
  1414. //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
  1415. //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
  1416. //获取路径的判断条件
  1417. // List<String> myconditionExpressions = new ArrayList<String>();
  1418. // myconditionExpressions.add(conditionExpression);
  1419. // int isOkNum = 0;
  1420. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  1421. // boolean isOk = false;
  1422. // //这是我的判断条件(通过条件判断库去比对数据)
  1423. // String mycondition = myconditionExpressions.get(i1);
  1424. // if (mycondition.contains("billMoney")) {
  1425. //// ${billMoney>3000}
  1426. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  1427. // if (mycondition.contains("<=")) {
  1428. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  1429. // if (billMoney <= Double.valueOf(substring)) {
  1430. //// ok
  1431. // isOk = true;
  1432. //
  1433. // }
  1434. // } else if (mycondition.contains("<")) {
  1435. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  1436. // if (billMoney < Double.valueOf(substring)) {
  1437. //// ok
  1438. // isOk = true;
  1439. // }
  1440. // } else if (mycondition.contains(">=")) {
  1441. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  1442. // if (billMoney >= Double.valueOf(substring)) {
  1443. //// ok
  1444. // isOk = true;
  1445. // }
  1446. // } else if (mycondition.contains(">")) {
  1447. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  1448. // if (billMoney > Double.valueOf(substring)) {
  1449. //// ok
  1450. // isOk = true;
  1451. // }
  1452. // } else if (mycondition.contains("==")) {
  1453. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  1454. // BigDecimal data1 = new BigDecimal(billMoney);
  1455. // BigDecimal data2 = new BigDecimal(substring);
  1456. // int i2 = data1.compareTo(data2);
  1457. // if (i2 == 0) {
  1458. //// ok
  1459. // isOk = true;
  1460. // }
  1461. // }
  1462. // }
  1463. //
  1464. // if (isOk) {
  1465. // isOkNum = isOkNum + 1;
  1466. // }
  1467. // }
  1468. // if (isOkNum == myconditionExpressions.size()) {
  1469. // myNextSequenceFlow = outgoingFlow;
  1470. // }
  1471. if (this.booleanConditionIsOk(conditionExpression, conditionMap)) {
  1472. myNextSequenceFlow = outgoingFlow;
  1473. }
  1474. }
  1475. //如果没有找到下个流程节点就继续找
  1476. if (myNextSequenceFlow == null) {
  1477. continue;
  1478. }
  1479. {//下面是找到了下个流程节点,需要进行正常的运行节点了
  1480. //================================================================================================
  1481. // TaskList.get(1).getOutgoingFlows().get(1).getTargetFlowElement().getCandidateGroups()
  1482. FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
  1483. if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
  1484. System.out.println("已经是结束流程了,直接完成审核就行了3");
  1485. boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1486. return null;
  1487. }
  1488. String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
  1489. String setRurrRole = this.getSetRurrRole(candidateGroup);
  1490. boolean end = false;
  1491. for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  1492. if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  1493. // String leader = currUser.getLeader();
  1494. // targetUser = userService.selectByPrimaryKey(leader);
  1495. // if (targetUser == null) {
  1496. // return null;
  1497. // }
  1498. boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1499. end = true;
  1500. return true;
  1501. }
  1502. }
  1503. if (!end) {
  1504. for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  1505. if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  1506. //查看谁是对应角色并查找对应的人
  1507. // String role = ConstantFlowType.ROLES[i];
  1508. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1509. // if (!targetUserList.isEmpty()) {
  1510. // if (targetUserList.size() >= 1) {
  1511. // targetUser = targetUserList.get(0);
  1512. // }
  1513. // }
  1514. // if (targetUser == null) {
  1515. // return null;
  1516. // }
  1517. boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1518. end = true;
  1519. return true;
  1520. }
  1521. }
  1522. }
  1523. if (!end) {
  1524. for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  1525. if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  1526. //查看谁是对应角色并查找对应的人
  1527. String role = ConstantFlowType.ROLES_CHECK[i];
  1528. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1529. // 在上面的方法基础上,增加groupId和用户状态的过滤
  1530. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
  1531. role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
  1532. FrameUser targetUser = null;
  1533. if (!targetUserList.isEmpty()) {
  1534. if (targetUserList.size() >= 1) {
  1535. targetUser = targetUserList.get(0);
  1536. }
  1537. }
  1538. if (targetUser == null) {
  1539. // return null;
  1540. System.out.println("5没有找到对应人:" + "if (targetUser == null) {");
  1541. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  1542. if (targetUser == null) {
  1543. System.err.println("异常,没有找到目标人");
  1544. return null;
  1545. }
  1546. }
  1547. boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1548. end = true;
  1549. return false;
  1550. }
  1551. }
  1552. }
  1553. break;
  1554. }
  1555. }
  1556. //如果运行找到这里就说明没有找到下个流程节点了,流程可以结束了
  1557. System.out.println("已经没有下个申请流程了,已经结束了2");
  1558. //
  1559. boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1560. return null;
  1561. }
  1562. // {
  1563. // //下面的部分将会被淘汰掉.....................................................
  1564. // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task.getTaskDefinitionKey(), false);
  1565. // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
  1566. // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
  1567. // UserTask myNextTask = null;//我要走的流程
  1568. // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
  1569. // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
  1570. // if (!"-yes".equals(candidateGroup.substring(candidateGroup.indexOf("-")))) {
  1571. // continue;
  1572. // }
  1573. // //需要的角色
  1574. // String setRurrRole = this.getSetRurrRole(candidateGroup);
  1575. // {
  1576. // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
  1577. // //获取路径的判断条件
  1578. // List<String> myconditionExpressions = new ArrayList<String>();
  1579. // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
  1580. // for (SequenceFlow outgoingFlow : outgoingFlows) {
  1581. // String conditionExpression = outgoingFlow.getConditionExpression();
  1582. // if (conditionExpression == null) {
  1583. // continue;
  1584. // }
  1585. // if (conditionExpression.contains("${agree==")) {
  1586. // continue;
  1587. // }
  1588. // myconditionExpressions.add(conditionExpression);
  1589. // }
  1590. // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
  1591. // myNextTask = userTask;
  1592. //
  1593. // } else {//有条件就判断是否满足条件,不满足就运行下一个
  1594. // int isOkNum = 0;
  1595. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  1596. // boolean isOk = false;
  1597. // //这是我的判断条件(通过条件判断库去比对数据)
  1598. // String mycondition = myconditionExpressions.get(i1);
  1599. // if (mycondition.contains("billMoney")) {
  1600. //// ${billMoney>3000}
  1601. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  1602. // if (mycondition.contains("<=")) {
  1603. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  1604. // if (billMoney <= Double.valueOf(substring)) {
  1605. //// ok
  1606. // isOk = true;
  1607. //
  1608. // }
  1609. // } else if (mycondition.contains("<")) {
  1610. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  1611. // if (billMoney < Double.valueOf(substring)) {
  1612. //// ok
  1613. // isOk = true;
  1614. // }
  1615. // } else if (mycondition.contains(">=")) {
  1616. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  1617. // if (billMoney >= Double.valueOf(substring)) {
  1618. //// ok
  1619. // isOk = true;
  1620. // }
  1621. // } else if (mycondition.contains(">")) {
  1622. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  1623. // if (billMoney > Double.valueOf(substring)) {
  1624. //// ok
  1625. // isOk = true;
  1626. // }
  1627. // } else if (mycondition.contains("==")) {
  1628. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  1629. // BigDecimal data1 = new BigDecimal(billMoney);
  1630. // BigDecimal data2 = new BigDecimal(substring);
  1631. // int i2 = data1.compareTo(data2);
  1632. // if (i2 == 0) {
  1633. //// ok
  1634. // isOk = true;
  1635. // }
  1636. // }
  1637. // }
  1638. //
  1639. // if (isOk) {
  1640. // isOkNum = isOkNum + 1;
  1641. // }
  1642. // }
  1643. // if (isOkNum == myconditionExpressions.size()) {
  1644. // myNextTask = userTask;
  1645. // }
  1646. //
  1647. // if (myNextTask == null) {
  1648. // continue;
  1649. // }
  1650. //
  1651. // }
  1652. // }
  1653. // //================================================================
  1654. // boolean end = false;
  1655. // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  1656. // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  1657. //// String leader = currUser.getLeader();
  1658. //// targetUser = userService.selectByPrimaryKey(leader);
  1659. //// if (targetUser == null) {
  1660. //// return null;
  1661. //// }
  1662. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1663. //
  1664. // end = true;
  1665. // return true;
  1666. // }
  1667. // }
  1668. // if (!end) {
  1669. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  1670. // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  1671. // //查看谁是对应角色并查找对应的人
  1672. //// String role = ConstantFlowType.ROLES[i];
  1673. //// List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1674. //// if (!targetUserList.isEmpty()) {
  1675. //// if (targetUserList.size() >= 1) {
  1676. //// targetUser = targetUserList.get(0);
  1677. //// }
  1678. //// }
  1679. //// if (targetUser == null) {
  1680. //// return null;
  1681. //// }
  1682. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1683. // end = true;
  1684. // return true;
  1685. // }
  1686. // }
  1687. //
  1688. // }
  1689. // if (!end) {
  1690. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  1691. // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  1692. // //查看谁是对应角色并查找对应的人
  1693. // String role = ConstantFlowType.ROLES_CHECK[i];
  1694. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1695. // FrameUser targetUser = null;
  1696. // if (!targetUserList.isEmpty()) {
  1697. // if (targetUserList.size() >= 1) {
  1698. // targetUser = targetUserList.get(0);
  1699. // }
  1700. // }
  1701. // if (targetUser == null) {
  1702. // return null;
  1703. // }
  1704. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1705. // end = true;
  1706. // return false;
  1707. // }
  1708. // }
  1709. // }
  1710. // break;
  1711. // }
  1712. // System.out.println("已经没有下个申请流程了,已经结束了");
  1713. // //
  1714. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1715. // return null;
  1716. // } else {
  1717. // System.out.println("已经没有下个申请流程了,已经结束了");
  1718. // //
  1719. // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
  1720. // return null;
  1721. // }
  1722. // }
  1723. }
  1724. /**
  1725. * 遍历进行操作最终获取用户自己的角色
  1726. *
  1727. * @return
  1728. */
  1729. public Map<String, String> getNextFlow(String businessId, UserTaskMore userPosition, String deploymentid, FrameUser currUser, Map<String, Object> conditionMap, Task task) throws com.rockstar.flow.exception.FlowException {
  1730. FrameUser targetUser = currUser;
  1731. Boolean aBoolean = this.flowServiceNextFlow(deploymentid, conditionMap, currUser, task);
  1732. if (aBoolean == null) {
  1733. Map<String, String> objectObjectHashMap = new HashMap<>();
  1734. objectObjectHashMap.put("isEnd", "1");
  1735. return objectObjectHashMap;
  1736. } else if (!aBoolean) {
  1737. return new HashMap<>();
  1738. } else if (aBoolean) {
  1739. //继续运行下面的步骤
  1740. }
  1741. {//遍历对象
  1742. List<Task> list2 = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象
  1743. .taskAssignee(targetUser.getId())//指定个人任务查询
  1744. // .processInstanceId("12516")
  1745. .list();
  1746. if (list2 == null || list2.isEmpty() || list2.size() <= 0) {
  1747. System.err.println("异常,没有找到任务对象2");
  1748. return null;
  1749. }
  1750. //2.1通过flow_id和targetUser获取下一个UserTask
  1751. Task task2 = list2.get(0);
  1752. //task是当前流程的信息
  1753. //如果发现task对应的角色就是自己的角色,就开始正常的走
  1754. //如果发现task对应的角色还不是,就需要再进行设置自己的操作
  1755. String taskDefinitionKey2 = task2.getTaskDefinitionKey(); //id的值如:_9
  1756. String flowId2 = userPosition.getUserTask().getId();//流程唯一id(我猜的)
  1757. if (flowId2.equals(taskDefinitionKey2)) {
  1758. //可以开始正常走流程了 嘻嘻...
  1759. {
  1760. // //可以开始正常走流程了 嘻嘻...
  1761. // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task2.getTaskDefinitionKey(), false);
  1762. // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
  1763. // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
  1764. // UserTask myNextTask = null;//我要走的流程
  1765. // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
  1766. // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
  1767. // String setRurrRole = this.getSetRurrRole(candidateGroup);
  1768. // {
  1769. // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
  1770. // //获取路径的判断条件
  1771. // List<String> myconditionExpressions = new ArrayList<String>();
  1772. // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
  1773. // for (SequenceFlow outgoingFlow : outgoingFlows) {
  1774. // String conditionExpression = outgoingFlow.getConditionExpression();
  1775. // if (conditionExpression == null) {
  1776. // continue;
  1777. // }
  1778. // if (conditionExpression.contains("${agree==")) {
  1779. // continue;
  1780. // }
  1781. // myconditionExpressions.add(conditionExpression);
  1782. // }
  1783. // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
  1784. // myNextTask = userTask;
  1785. //
  1786. // } else {//有条件就判断是否满足条件,不满足就运行下一个
  1787. // int isOkNum = 0;
  1788. // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
  1789. // boolean isOk = false;
  1790. // //这是我的判断条件(通过条件判断库去比对数据)
  1791. // String mycondition = myconditionExpressions.get(i1);
  1792. // if (mycondition.contains("billMoney")) {
  1793. //// ${billMoney>3000}
  1794. // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
  1795. // if (mycondition.contains("<=")) {
  1796. // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
  1797. // if (billMoney <= Double.valueOf(substring)) {
  1798. //// ok
  1799. // isOk = true;
  1800. //
  1801. // }
  1802. // } else if (mycondition.contains("<")) {
  1803. // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
  1804. // if (billMoney < Double.valueOf(substring)) {
  1805. //// ok
  1806. // isOk = true;
  1807. // }
  1808. // } else if (mycondition.contains(">=")) {
  1809. // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
  1810. // if (billMoney >= Double.valueOf(substring)) {
  1811. //// ok
  1812. // isOk = true;
  1813. // }
  1814. // } else if (mycondition.contains(">")) {
  1815. // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
  1816. // if (billMoney > Double.valueOf(substring)) {
  1817. //// ok
  1818. // isOk = true;
  1819. // }
  1820. // } else if (mycondition.contains("==")) {
  1821. // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
  1822. // BigDecimal data1 = new BigDecimal(billMoney);
  1823. // BigDecimal data2 = new BigDecimal(substring);
  1824. // int i2 = data1.compareTo(data2);
  1825. // if (i2 == 0) {
  1826. //// ok
  1827. // isOk = true;
  1828. // }
  1829. // }
  1830. // }
  1831. //
  1832. // if (isOk) {
  1833. // isOkNum = isOkNum + 1;
  1834. // }
  1835. // }
  1836. // if (isOkNum == myconditionExpressions.size()) {
  1837. // myNextTask = userTask;
  1838. // }
  1839. //
  1840. // if (myNextTask == null) {
  1841. // continue;
  1842. // }
  1843. //
  1844. // }
  1845. // }
  1846. // //================================================================
  1847. // boolean end = false;
  1848. // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  1849. // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
  1850. // String leader = currUser.getLeader();
  1851. // targetUser = userService.selectByPrimaryKey(leader);
  1852. // if (targetUser == null) {
  1853. // return null;
  1854. // }
  1855. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1856. //
  1857. // end = true;
  1858. // return new HashMap<>();
  1859. // }
  1860. // }
  1861. // if (!end) {
  1862. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  1863. // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  1864. // //查看谁是对应角色并查找对应的人
  1865. // String role = ConstantFlowType.ROLES[i];
  1866. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1867. // if (!targetUserList.isEmpty()) {
  1868. // if (targetUserList.size() >= 1) {
  1869. // targetUser = targetUserList.get(0);
  1870. // }
  1871. // }
  1872. // if (targetUser == null) {
  1873. // return null;
  1874. // }
  1875. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1876. // end = true;
  1877. // return new HashMap<>();
  1878. // }
  1879. // }
  1880. //
  1881. // }
  1882. // if (!end) {
  1883. // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
  1884. // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
  1885. // //查看谁是对应角色并查找对应的人
  1886. // String role = ConstantFlowType.ROLES_CHECK[i];
  1887. // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
  1888. // if (!targetUserList.isEmpty()) {
  1889. // if (targetUserList.size() >= 1) {
  1890. // targetUser = targetUserList.get(0);
  1891. // }
  1892. // }
  1893. // if (targetUser == null) {
  1894. // return null;
  1895. // }
  1896. // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
  1897. // end = true;
  1898. // return new HashMap<>();
  1899. // }
  1900. // }
  1901. // }
  1902. // break;
  1903. // }
  1904. // } else {
  1905. // System.out.println("已经没有下个申请流程了,已经结束了");
  1906. // return null;
  1907. // }
  1908. //
  1909. }
  1910. return this.donaturalTask(deploymentid, currUser, task2, conditionMap);
  1911. } else {
  1912. //还不是自己的角色,还要遍历查找
  1913. return getNextFlow(businessId, userPosition, deploymentid, currUser, conditionMap, task2);
  1914. }
  1915. }
  1916. // return null;
  1917. }
  1918. /**
  1919. * 共用方法 //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管),
  1920. * 但是注意,这只是判断是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的
  1921. *
  1922. * @param currUser
  1923. * @return
  1924. */
  1925. public String getCurrRole(FrameUser currUser) {
  1926. //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管)
  1927. String currRole = "";//flow_fgld", "flow_sjfgld", "flow_zyld或者curr_user,dept_head
  1928. {
  1929. //1获取用户流程类型
  1930. {
  1931. String[] flow_roles = ConstantFlowType.FLOW_ROLES;//{"flow_fgld", "flow_sjfgld", "flow_zyld"};
  1932. String[] roles = ConstantFlowType.ROLES;// {"fgld", "sjfgld", "zyld"};
  1933. // frame_role_data
  1934. List<FrameRoleData> FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(currUser.getId(), ConstantFlowType.ROLETYPE);//"FLOW"
  1935. Integer c = null;
  1936. //判断用户的最高用户流类型
  1937. for (FrameRoleData frameRoleData : FrameRoleDatas) {
  1938. String roleKey = frameRoleData.getRoleKey();
  1939. for (int i = 0; i < roles.length; i++) {
  1940. if (roles[i].equals(roleKey)) {
  1941. if (c == null) {
  1942. c = i;
  1943. } else if (c < i) {
  1944. c = i;
  1945. }
  1946. break;
  1947. }
  1948. }
  1949. }
  1950. if (c != null) {
  1951. currRole = flow_roles[c];
  1952. return currRole;
  1953. }
  1954. }
  1955. //2获取用户部门是否是主管
  1956. {
  1957. String department = currUser.getDepartment();
  1958. SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
  1959. if (sysDept == null) {//没有部门信息
  1960. if (currRole.equals("")) {
  1961. currRole = "";
  1962. return null;
  1963. } else {
  1964. //是领导流程类型
  1965. }
  1966. } else {
  1967. String changedBy = sysDept.getChargedBy();
  1968. if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
  1969. if (currRole.equals("")) {
  1970. currRole = "";
  1971. } else {
  1972. //是领导流程类型
  1973. }
  1974. return null;
  1975. } else {//找到部门主管
  1976. if (changedBy.equals(currUser.getId())) {//自己是部门主管
  1977. if (currRole.equals("")) {
  1978. currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head";
  1979. } else {
  1980. //是领导流程类型
  1981. }
  1982. } else {//部门主管是别人,自己不是部门主管
  1983. if (currRole.equals("")) {
  1984. currRole = ConstantFlowType.FLOW_ROLES_DEPT[0];//"curr_user";
  1985. } else {
  1986. //是领导流程类型
  1987. }
  1988. }
  1989. }
  1990. }
  1991. }
  1992. }
  1993. return currRole;
  1994. }
  1995. /**
  1996. * 写一个方法, 已知用户信息 zt ok
  1997. * 申请付款时 通过用户信号获取用户在全流程中的位置,如果没有找到对象,返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  1998. */
  1999. public UserTaskMore findUserPosition(String currRole, String deploymentid) {
  2000. //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管)
  2001. // String currRole = this.getCurrRole(currUser2);
  2002. //没有获取到角色异常返回null
  2003. if (currRole == null || currRole.equals("")) {
  2004. return null;
  2005. }
  2006. //获取活动节点
  2007. //这是流程排序编号
  2008. int nodeNum = 0;
  2009. List<UserTask> taskList = flowService.getTaskList(deploymentid);
  2010. UserTask userTask = taskList.get(0);
  2011. nodeNum = nodeNum + 1;
  2012. String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
  2013. String setRurrRole = this.getSetRurrRole(s);
  2014. if (currRole.equals(setRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上
  2015. // return userTask;
  2016. // return nodeNum;
  2017. return new UserTaskMore(userTask, nodeNum, userTask);
  2018. } else {//要进行轮查获取用户位置
  2019. UserTaskMore nextCandidateGroupByDeploy = this.getNextMyUserTask(taskList, currRole, nodeNum);
  2020. // UserTaskMore nextCandidateGroupByDeploy = getNextCandidateGroupByDeploy(userTask, currRole, nodeNum, deploymentid);
  2021. nextCandidateGroupByDeploy.setCurrentUserTask(userTask);
  2022. return nextCandidateGroupByDeploy;
  2023. }
  2024. }
  2025. /**
  2026. * 申请付款时 通过传递的数据递归获取用户角色实际的运行节点
  2027. *
  2028. * @return
  2029. */
  2030. public UserTaskMore getNextMyUserTask(List<UserTask> taskList, String currRole, Integer nodeNum) {
  2031. for (int i = 1; i < taskList.size(); i++) {
  2032. nodeNum = 2;
  2033. UserTask myuserTask = taskList.get(i);
  2034. String taskKey = myuserTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
  2035. String taskSetRurrRole = this.getSetRurrRole(taskKey);
  2036. if (currRole.equals(taskSetRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上
  2037. System.out.println("2结束节点" + nodeNum);
  2038. // return userTask;
  2039. // return nodeNum;
  2040. return new UserTaskMore(myuserTask, nodeNum);
  2041. }
  2042. }
  2043. return null;
  2044. }
  2045. /**
  2046. * 这个方法有问题,不能获取自己想要的,放弃使用了
  2047. * 申请付款时 通过传递的数据递归获取用户角色实际的运行节点
  2048. *
  2049. * @param newUserTask
  2050. * @param currRole
  2051. * @param nodeNum
  2052. * @return
  2053. */
  2054. public UserTaskMore getNextCandidateGroupByDeploy(UserTask newUserTask, String currRole, Integer nodeNum, String deploymentid) {
  2055. List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, newUserTask.getId(), false);
  2056. if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
  2057. // //进行分支判断
  2058. // for (int i = 0; i < nextCandidateGroupByDeploy.size(); i++) {
  2059. // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(i);
  2060. // String taskKey = userTask.getCandidateGroups().get(0);//dept_head_1_0_1-yes
  2061. // String yesNo = taskKey.substring(taskKey.indexOf("-"));
  2062. // if (!"yes".equals(yesNo)) {
  2063. // continue;
  2064. // }
  2065. // String setRurrRole = this.getSetRurrRole(taskKey);//获取任务的角色
  2066. //
  2067. // }
  2068. nodeNum = nodeNum + 1;
  2069. System.out.println("运行节点" + nodeNum);
  2070. UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(0);
  2071. String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
  2072. String setRurrRole = this.getSetRurrRole(s);
  2073. if (currRole.equals(setRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上
  2074. System.out.println("1结束节点" + nodeNum);
  2075. // return userTask;
  2076. // return nodeNum;
  2077. return new UserTaskMore(userTask, nodeNum);
  2078. } else {
  2079. getNextCandidateGroupByDeploy(userTask, currRole, nodeNum, deploymentid);
  2080. }
  2081. } else {
  2082. return null;
  2083. }
  2084. return null;
  2085. }
  2086. /**
  2087. * 通过原key获取角色数据
  2088. *
  2089. * @param s
  2090. * @return
  2091. */
  2092. public static String getSetRurrRole(String s) {
  2093. // String s="dept_head_1_0_1-yes";或者curr_user-no
  2094. String[] s1 = s.contains("-") ? s.substring(0, s.indexOf("-")).split("_") : s.split("_");
  2095. s = s1[0] + "_" + s1[1];
  2096. // System.out.println(s);
  2097. return s;
  2098. }
  2099. /**
  2100. * 写一个通用方法,专门根据条件获取部门领导是谁
  2101. * targetRole:下一个审核人的角色
  2102. * currUser:当前的审核人角色
  2103. */
  2104. public FrameUser getTargerUser_FLOW_ROLES_DEPT(String targetRole, FrameUser currUser) {
  2105. FrameUser targetUser = null;
  2106. if (targetRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导
  2107. String department = currUser.getDepartment();
  2108. SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
  2109. if (sysDept == null) {//没有部门信息
  2110. } else {
  2111. String changedBy = sysDept.getChargedBy();
  2112. if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
  2113. } else {
  2114. targetUser = userService.selectByPrimaryKey(changedBy);
  2115. }
  2116. }
  2117. } else {
  2118. String leader = currUser.getLeader();
  2119. if (StringUtils.isEmpty(leader)) {//没有找到直接领导
  2120. } else {
  2121. targetUser = userService.selectByPrimaryKey(leader);
  2122. }
  2123. }
  2124. if (targetUser == null) {//没有找到目标人就都传到admin中去
  2125. // return null;
  2126. System.out.println("6没有找到对应人:" + "if (targetUser == null) {");
  2127. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2128. if (targetUser == null) {
  2129. System.err.println("异常,没有找到目标人");
  2130. return null;
  2131. }
  2132. }
  2133. return targetUser;
  2134. }
  2135. public FrameUser getTargerUser_FLOW_ROLES_DEPT_PLUS(String targetRole, FrameUser currUser) {
  2136. FrameUser targetUser = null;
  2137. if (targetRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导
  2138. String department = currUser.getDepartment();
  2139. SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
  2140. if (sysDept == null) {//没有部门信息
  2141. } else {
  2142. String changedBy = sysDept.getChargedBy();
  2143. if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
  2144. } else {
  2145. targetUser = userService.selectByPrimaryKey(changedBy);
  2146. }
  2147. }
  2148. } else {
  2149. String leader = currUser.getLeader();
  2150. if (StringUtils.isEmpty(leader)) {//没有找到直接领导
  2151. // 流转给子公司超管
  2152. FrameRoleDataExample example = new FrameRoleDataExample();
  2153. example.createCriteria().andRoleKeyEqualTo(ConstantFlowType.PURCHASE_ROLES_CHECK_PLUS)
  2154. .andRoleTypeEqualTo(ConstantFlowType.ROLETYPE2);
  2155. List<FrameRoleData> frameRoleDataList = frameRoleDataService.selectByExample(example);
  2156. if(CollectionUtils.isNotEmpty(frameRoleDataList)) {
  2157. FrameRoleData frameRoleData = frameRoleDataList.get(0);
  2158. List<String> userIds = frameRoleDataUserService.selectUserByRoleDataId(frameRoleData.getId());
  2159. if(CollectionUtils.isNotEmpty(userIds)) {
  2160. FrameUserExample example1 = new FrameUserExample();
  2161. example1.createCriteria().andIdIn(userIds).andGroupIdEqualTo(currUser.getGroupId())
  2162. .andStatusEqualTo("1");
  2163. List<FrameUser> frameUserList = frameUserService.selectByExample(example1);
  2164. if(CollectionUtils.isNotEmpty(frameUserList)) {
  2165. targetUser = frameUserList.get(0);
  2166. }
  2167. }
  2168. }
  2169. } else {
  2170. targetUser = userService.selectByPrimaryKey(leader);
  2171. }
  2172. }
  2173. if (targetUser == null) {//没有找到目标人就都传到admin中去
  2174. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2175. if (targetUser == null) {
  2176. return null;
  2177. }
  2178. }
  2179. return targetUser;
  2180. }
  2181. public Map<String, String> startPurchaseTask(String processDefine, String deploymentid, String businessId,
  2182. FrameUser currUser, Map<String, Object> conditionMap)
  2183. throws com.rockstar.flow.exception.FlowException {
  2184. FrameUser targetUser = null;
  2185. String currRole = this.getCurrRole(currUser);
  2186. UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
  2187. Map<String, String> startTask;
  2188. if (userPosition == null) {
  2189. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2190. if (targetUser == null) {
  2191. return null;
  2192. }
  2193. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  2194. return startTask;
  2195. } else {
  2196. int nodeNum = userPosition.getNodeNum();
  2197. UserTask currentUserTask = userPosition.getCurrentUserTask();
  2198. if (nodeNum == 1) {
  2199. {
  2200. List<SequenceFlow> outgoingFlows = currentUserTask.getOutgoingFlows();
  2201. //我的下一个节点位置
  2202. SequenceFlow myNextSequenceFlow = null;
  2203. for (SequenceFlow outgoingFlow : outgoingFlows) {
  2204. String conditionExpression = outgoingFlow.getConditionExpression();
  2205. //如果是空就跳过
  2206. if (conditionExpression == null) {
  2207. continue;
  2208. } else if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
  2209. continue;
  2210. } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
  2211. continue;
  2212. } else if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
  2213. //发现没有判断条件,那本流程就是下个节点
  2214. myNextSequenceFlow = outgoingFlow;
  2215. }
  2216. //如果没有找到下个流程节点就继续找
  2217. if (myNextSequenceFlow == null) {
  2218. continue;
  2219. }
  2220. //下面是找到了下个流程节点,需要进行正常的运行节点了
  2221. FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
  2222. if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
  2223. return null;
  2224. }
  2225. String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
  2226. String setRurrRole = getSetRurrRole(candidateGroup);
  2227. for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
  2228. if (s.equals(setRurrRole)) {
  2229. targetUser = this.getTargerUser_FLOW_ROLES_DEPT_PLUS(s, currUser);
  2230. if (targetUser == null) {
  2231. return null;
  2232. }
  2233. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  2234. return startTask;
  2235. }
  2236. }
  2237. for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
  2238. if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
  2239. //查看谁是对应角色并查找对应的人
  2240. String role = ConstantFlowType.ROLES[i];
  2241. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(role,
  2242. ConstantFlowType.ROLETYPE, currUser.getGroupId());
  2243. if (!targetUserList.isEmpty()) {
  2244. targetUser = targetUserList.get(0);
  2245. }
  2246. if (targetUser == null) {
  2247. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2248. if (targetUser == null) {
  2249. return null;
  2250. }
  2251. }
  2252. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  2253. return startTask;
  2254. }
  2255. }
  2256. for (int i = 0; i < ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK.length; i++) {
  2257. if (ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK[i].equals(setRurrRole)) {
  2258. //查看谁是对应角色并查找对应的人
  2259. String role = ConstantFlowType.PURCHASE_ROLES_CHECK[i];
  2260. List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(role,
  2261. ConstantFlowType.ROLETYPE, currUser.getGroupId());
  2262. if (!targetUserList.isEmpty()) {
  2263. targetUser = targetUserList.get(0);
  2264. }
  2265. if (targetUser == null) {
  2266. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2267. if (targetUser == null) {
  2268. return null;
  2269. }
  2270. }
  2271. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  2272. return startTask;
  2273. }
  2274. }
  2275. return null;
  2276. }
  2277. return null;
  2278. }
  2279. } else if (nodeNum > 1) {
  2280. // 2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  2281. // 需要进行循环审核过程
  2282. boolean isZhuYaoLingDao= "flow_zyld".equals(currRole);
  2283. if(isZhuYaoLingDao) {
  2284. targetUser = currUser;
  2285. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  2286. if (!startTask.isEmpty()) {
  2287. {
  2288. List<Task> list = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象
  2289. .taskAssignee(targetUser.getId())//指定个人任务查询
  2290. .list();
  2291. if (list == null || list.isEmpty()) {
  2292. return null;
  2293. }
  2294. //2.1通过flow_id和targetUser获取下一个UserTask
  2295. Task task = list.get(0);
  2296. //task是当前流程的信息
  2297. //如果发现task对应的角色就是自己的角色,就开始正常的走
  2298. //如果发现task对应的角色还不是,就需要再进行设置自己的操作
  2299. String taskDefinitionKey = task.getTaskDefinitionKey();
  2300. String flowId = userPosition.getUserTask().getId();
  2301. if (flowId.equals(taskDefinitionKey)) {
  2302. Map<String, String> donaturalTaskMap = this.donaturalTask(deploymentid, currUser, task,
  2303. conditionMap);
  2304. if (donaturalTaskMap == null) {
  2305. return null;
  2306. } else {
  2307. return startTask;
  2308. }
  2309. } else {
  2310. {//遍历对象
  2311. Map<String, String> getNextFlowMap = getNextFlow(businessId, userPosition,
  2312. deploymentid, currUser, conditionMap, task);
  2313. if (getNextFlowMap == null) {
  2314. return null;
  2315. } else {
  2316. if (null != getNextFlowMap.get("isEnd")) {
  2317. startTask.put("isEnd", getNextFlowMap.get("isEnd"));
  2318. }
  2319. return startTask;
  2320. }
  2321. }
  2322. }
  2323. }
  2324. } else {
  2325. return null;
  2326. }
  2327. } else {
  2328. if (currUser.getLeader()!=null) {
  2329. targetUser = userService.selectByPrimaryKey(currUser.getLeader());
  2330. }
  2331. if (targetUser==null){
  2332. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2333. }
  2334. startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
  2335. if (!startTask.isEmpty()) {
  2336. return startTask;
  2337. } else {
  2338. return null;
  2339. }
  2340. }
  2341. } else {
  2342. return null;
  2343. }
  2344. }
  2345. }
  2346. public Map<String, String> passToRunPurchaseTask(FlowMainPush flowMainPush, String deploymentid, String businessId,
  2347. Map<String, Object> conditionMap)
  2348. throws com.rockstar.flow.exception.FlowException {
  2349. // 发起流程引擎操作 并查看下一节点的操作要求
  2350. //0,如果是收纳且匹配上角色就正常流程审核,没有匹配上就返回null,异常错误 ok,
  2351. //1. 如果当前角色是自己,就进行正常的审核流程 ok
  2352. //2. 先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
  2353. //当前审核人/委托人代表的用户id
  2354. String myFrameUserId = this.getMyFrameUserId(flowMainPush);
  2355. if (myFrameUserId == null) {
  2356. return null;
  2357. }
  2358. //当前审核人/委托人代表的用户
  2359. FrameUser myframeUser = frameUserService.selectByPrimaryKey(myFrameUserId);
  2360. //根据任务id获取任务信息
  2361. //当前任务流程
  2362. Task task;
  2363. {
  2364. List<Task> taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId())
  2365. .taskId(flowMainPush.getTaskId()).list();
  2366. if (taskList == null || taskList.isEmpty()) {
  2367. return null;
  2368. }
  2369. task = taskList.get(0);
  2370. }
  2371. //本节点的关键子 例如flow_cnjs_1_1_0-yes
  2372. String pushUserKey = flowMainPush.getPushUserKey();
  2373. //本节点的角色 例如cnjs
  2374. String setRurrRole = getSetRurrRole(pushUserKey);
  2375. //判断setRurrRole是不是出纳类的角色,如果是出纳的角色,就判断当前审核人是不是也是出纳,是就继续,不是就是异常错误,返回null
  2376. //判断是否符合出纳类型的要求 ok
  2377. {
  2378. for (int i = 0; i < ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK.length; i++) {
  2379. if (ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK[i].equals(setRurrRole)) {
  2380. return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  2381. }
  2382. }
  2383. }
  2384. {
  2385. //当前审核人/委托人代表的用户角色(只判断了是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的)
  2386. String currRole = this.getCurrRole(myframeUser);
  2387. //没有获取到角色,直接对到admin那里
  2388. if (!StringUtils.isNotEmpty(currRole)) {
  2389. // 直接对到admin那里
  2390. FrameUser targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2391. if (targetUser == null) {
  2392. return null;
  2393. }
  2394. return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  2395. }
  2396. //当发现this.getCurrRole(myframeUser);获取的角色是普通员工的时候,就知道他作为审核人只是直接上级,并不是领导,所以把角色调上一级
  2397. if (currRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[0])) {
  2398. currRole = ConstantFlowType.FLOW_ROLES_DEPT[1];
  2399. }
  2400. // 不是出纳的情况下进行的判断
  2401. //1.如果当前角色是自己,就进行正常的审核流程 ok
  2402. //2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
  2403. if (setRurrRole.equals(currRole)) {//1.如果当前角色是自己,就进行正常的审核流程 ok
  2404. return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
  2405. } else {//2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
  2406. FrameUser targetUser = null;
  2407. UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
  2408. // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
  2409. if (userPosition == null) {//没有找到数据
  2410. targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
  2411. if (targetUser == null) {
  2412. return null;
  2413. }
  2414. boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap);
  2415. return new HashMap<>();
  2416. } else {//找到userPosition数据录了
  2417. //还不是自己的角色,还要遍历查找
  2418. return getNextFlow(businessId, userPosition, deploymentid, myframeUser, conditionMap, task);
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }