ProActiService.java 139 KB

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