12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531 |
- package com.idea.oa.activiti.service;
- import com.idea.oa.activiti.exception.FlowException;
- import com.idea.oa.activiti.model.UserTaskMore;
- import com.idea.oa.apply.util.constant.ConstantFlowType;
- import com.idea.oa.flow2.model.FlowMainLog;
- import com.idea.oa.flow2.model.FlowMainPush;
- import com.idea.oa.flow2.service.FlowMainLogService;
- import com.idea.oa.flow2.service.FlowMainService;
- import com.rockstar.common.domain.AjaxResult;
- import com.rockstar.common.support.Convert;
- import com.rockstar.flow.dto.TaskDto;
- import com.rockstar.flow.service.FlowService;
- import com.rockstar.frame.model.*;
- import com.rockstar.frame.service.*;
- import com.rockstar.system.model.SysDept;
- import com.rockstar.system.service.SysDeptService;
- import com.rockstar.util.BeanUtils;
- import com.rockstar.util.StringUtils;
- import org.activiti.bpmn.model.*;
- import org.activiti.bpmn.model.Process;
- import org.activiti.engine.RepositoryService;
- import org.activiti.engine.TaskService;
- import org.activiti.engine.task.Task;
- import org.activiti.engine.task.TaskInfo;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- public class ProActiService {
- @Autowired
- private FlowMainLogService flowMainLogService;
- //todo 到时候如果先会签,串并联的问题,flowService.runTask和flowService.start判断一下,是否需要串联会签还是并联会签,如果是3的单人签核,1是并联会签,0是串联会签
- @Autowired
- private TaskService taskService;
- @Autowired
- private FlowService flowService;
- @Autowired
- private FlowMainService flowMainService;
- @Autowired
- private FrameUserService userService;
- //
- // @Autowired
- // private FramePostService postService;
- //
- @Autowired
- private SysDeptService sysDeptService;
- //
- //
- // @Autowired
- // private FrameUserDeptService frameUserDeptService;
- @Autowired
- private FrameUserService frameUserService;
- @Autowired
- private FrameRoleDataService frameRoleDataService;
- @Autowired
- private FrameRoleDataUserService frameRoleDataUserService;
- /**
- * ok
- * 删除并结束指定活动实例
- *
- * @param processInstanceId 启动流程的流程对象id
- * @param comments 评论/备注
- */
- @Transactional
- public void endTaskProcess(String processInstanceId, String comments) {
- flowService.deleteInstance(processInstanceId, comments);
- }
- /**
- * ok
- * 启动流程
- * 启动方法时,ActiDto内的必须值是:processType, currentUserId 和 businessId
- *
- * @param actiDto
- * @return
- * @throws FlowException
- */
- @Transactional
- public Map<String, String> startAutoTask(Map<String, Object> actiDto) throws FlowException, com.rockstar.flow.exception.FlowException {
- // processDefine 流程定义 apply_pay
- // dataRole 角色??是传什么?
- // businessId 流程id,就用主流程的id flow_main
- // targetUser 目标人员
- // currUser 当前人员
- String processDefine = "apply_pay";
- FrameUser targetUser = userService.selectByPrimaryKey("1080517374995595264");
- FrameUser currUser = userService.selectByPrimaryKey("1");
- // String businessId="1088138622709792768";
- // String businessId="1088140716548292608";
- String businessId = "1088140517679562752";//主申请表id
- Map<String, String> startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- //返回数据{processInstanceId=7501}{processInstanceId=12501}{processInstanceId=17501}
- String taskId = "任务ID:17516";
- String flow_id = startTask.get("processInstanceId").toString();
- ;
- return startTask;
- }
- /**
- * ok
- * 执行当前流程节点
- * 该方法中,ActiDto内除了businessId,其他都是必须值
- *
- * @param actiDto isEndSet,当业务发现可以结束审核的时候向方法外传送是否结束审核的信号
- * @return
- * @throws FlowException
- */
- @Transactional
- public Object runAutoTask(Map actiDto) throws FlowException, com.rockstar.flow.exception.FlowException {
- FrameUser targetUser = userService.selectByPrimaryKey("1080522875951120384");
- FrameUser currUser = userService.selectByPrimaryKey("1080517374995595264");
- // private String processType;
- // private String currentUserId;
- // private String operateUserId;
- // private String dataRole;
- // private String agree;==>yes/no
- // private String comments;===================>????
- // private String businessId;
- // private String taskId;===>在展示列表里面有taskId
- // flowDto.getTaskId(), flowDto.getDataRole(), flowDto.getAgree(), flowDto.getComments()
- Map<String, Object> map = new HashMap<>();
- map.put("billMoney", 1250);
- return flowService.runTask("12516", null, "yes", "zt omments", targetUser, currUser, null);
- }
- /**
- * 查询数据
- *
- * @param taskDto
- * @return
- * @throws FlowException
- */
- @Transactional
- public List findTask(TaskDto taskDto) throws FlowException {
- List<String> taskGroups = new ArrayList<>();
- return flowService.findTask(taskDto, taskGroups);
- }
- /**
- * 还不知道干什么用的,猜是查看备注用的
- *
- * @param taskId
- * @param isHistoric
- * @return
- * @throws FlowException
- */
- @Transactional
- public List getCommentsByTid(String taskId, Boolean isHistoric) throws FlowException {
- if (StringUtils.isEmpty(taskId))
- throw new FlowException("任务ID为空");
- if (null == isHistoric) {
- isHistoric = false;
- }
- return flowService.getComments(taskId, isHistoric);
- }
- /**
- * 通过taskId获取任务后续得任务组列表,任务组列表定义如下:
- * 1,任务组是有('岗位'和yes) 或('curr_user'和'no')组合而成得字符串,具体如:director-yes,office_leader-yes或curr_user-no等
- * 2,一般来说curr_user-no都是被退回之后指向得任务组,而带-yes后缀的是同意所指向得任务组
- * <p>
- * 使用方式:
- * 1,在待审批列表中打开某个审批任务,先通过taskId(任务ID)获取该任务后续得任务组
- * 2,分析所拥有得任务组,一般是2个或者1个任务组
- * 3,根据所获得得任务组,来安排界面'同意'和'不同意'得按钮显示或隐藏
- * 4,任务组含curr_user-no,就具备'不同意'按钮,点击不同意按钮,传输值:agree值为no, dataRole:'-no'之前的
- * 5,任务组含带-yes后缀的,就具备'同意'按钮,点击同意按钮,传输值:agree值为yes, dataRole:'-yes'之前的
- * 6,任务组如果只含curr_user-no,没其他的,那就具备'不同意'和'结束'按钮,点结束按钮,传输值:agree值为yes即可
- *
- * @param taskId 任务ID
- * @param isHistoric 是否历史任务
- * @return
- */
- @Transactional
- public List<String> nextTaskGroups(String taskId, boolean isHistoric) throws FlowException {
- if (StringUtils.isEmpty(taskId))
- throw new FlowException("任务ID为空");
- List<String> strings = flowService.nextTaskGroups(taskId, isHistoric);
- List<UserTask> userTasks = flowService.nextTasks(taskId, isHistoric);
- System.out.println("nextTasks数据为:" + userTasks);
- return strings;
- }
- //=======偏业务的,到时候要搬走的=========================================================================================================================================================
- public String getNodeName(FlowMainPush flowMainPush) {
- {
- Task task = null;
- List<Task> taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId()).taskId(flowMainPush.getTaskId()).list();
- if (taskList == null || taskList.isEmpty()) {
- return null;
- }
- task = taskList.get(0);
- return task.getName();
- }
- }
- /**
- * 通用方法 //当前审核人/委托人代表的用户id
- *
- * @param flowMainPush
- * @return
- */
- public String getMyFrameUserId(FlowMainPush flowMainPush) {
- //当前审核人/委托人代表的用户id
- String myFrameUserId = null;
- {
- Integer pushRole = flowMainPush.getPushRole();
- if (new Integer(1).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
- myFrameUserId = flowMainPush.getPushUser();
- } else if (new Integer(2).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
- //因为是被委托人,所以查到这个委托人的信息
- // {//通过流程监控进行操的时候就会有问题,不能找到原来的审核用户id 第一种方式,通过关联查询进行被委托人查询
- // FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId());
- // String auditResult = flowMainLog.getAuditResult();
- // if (!"4".equals(auditResult)) {// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
- // return null;//异常情况
- // }
- // myFrameUserId = flowMainLog.getAuditUser();
- // }
- {//第二种方式
- // 通过 flowMainPush.getFlowPost()来获取对应的被委托人的信息,只是还没有测试不知道 第二种方式是否好用
- myFrameUserId = flowMainPush.getFlowPost();
- }
- } else {
- return null;//异常情况
- }
- }
- return myFrameUserId;
- }
- /**
- * 审核通过,进行下一步操作
- *
- * @return
- * @throws FlowException
- */
- @Transactional
- public Map<String, String> passToRunTask(FlowMainPush flowMainPush, String deploymentid, String businessId, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
- // 发起流程引擎操作 并查看下一节点的操作要求
- //0,如果是收纳且匹配上角色就正常流程审核,没有匹配上就返回null,异常错误 ok,
- //1. 如果当前角色是自己,就进行正常的审核流程 ok
- //2. 先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
- //当前审核人/委托人代表的用户id
- String myFrameUserId = this.getMyFrameUserId(flowMainPush);
- if (myFrameUserId == null) {
- return null;
- }
- // {
- // Integer pushRole = flowMainPush.getPushRole();
- // if (new Integer(1).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
- // myFrameUserId = flowMainPush.getPushUser();
- // } else if (new Integer(2).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)',
- // //因为是被委托人,所以查到这个委托人的信息
- // {//第一种方式,通过关联查询进行被委托人查询
- // FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId());
- // String auditResult = flowMainLog.getAuditResult();
- // if (!"4".equals(auditResult)) {// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)',
- // return null;//异常情况
- // }
- // myFrameUserId = flowMainLog.getAuditUser();
- // }
- // {//第二种方式
- // //通过 flowMainPush.getFlowPost()来获取对应的被委托人的信息,只是还没有测试不知道 第二种方式是否好用
- //// myFrameUserId = flowMainPush.getFlowPost()
- // }
- // } else {
- // return null;//异常情况
- // }
- // }
- //当前审核人/委托人代表的用户
- FrameUser myframeUser = frameUserService.selectByPrimaryKey(myFrameUserId);
- //根据任务id获取任务信息
- //当前任务流程
- Task task = null;
- {
- List<Task> taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId()).taskId(flowMainPush.getTaskId()).list();
- if (taskList == null || taskList.isEmpty()) {
- return null;
- }
- task = taskList.get(0);
- }
- //本节点的关键子 例如flow_cnjs_1_1_0-yes
- String pushUserKey = flowMainPush.getPushUserKey();
- //本节点的角色 例如cnjs
- String setRurrRole = this.getSetRurrRole(pushUserKey);
- //判断setRurrRole是不是出纳类的角色,如果是出纳的角色,就判断当前审核人是不是也是出纳,是就继续,不是就是异常错误,返回null
- //判断是否符合出纳类型的要求 ok
- {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是出纳关系的查收纳
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES_CHECK[i];//找到是出纳类的角色
- // List<FrameRoleData> FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(myFrameUserId, ConstantFlowType.ROLETYPE);//"FLOW"
- // for (FrameRoleData frameRoleData : FrameRoleDatas) {
- // String roleKey = frameRoleData.getRoleKey();
- // if (roleKey.equals(role)) {
- // //匹配到对应的人,用正常流程做审核
- // return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- // }
- // }
- //如果没有匹配到就是异常错误,返回null
- // return null;
- //只所以注释掉上面的,是觉得原来订的审核人已经确认了,若中途改掉了也不需要校验了,确保流程的一致性,并能正常运行
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- }
- }
- }
- {
- //当前审核人/委托人代表的用户角色(只判断了是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的)
- String currRole = this.getCurrRole(myframeUser);
- //没有获取到角色,直接对到admin那里
- if (currRole == null || currRole.equals("")) {
- // 直接对到admin那里
- System.out.println("8没有找到对应人:" + " if (currRole == null || currRole.equals(\"\"))");
- FrameUser targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- {//下面的替换这里的数据,来解决管理员无法结束流程的问题
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap);
- // return new HashMap<>();
- }
- {
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- }
- }
- //当发现this.getCurrRole(myframeUser);获取的角色是普通员工的时候,就知道他作为审核人只是直接上级,并不是领导,所以把角色调上一级
- if (currRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[0])) {
- currRole = ConstantFlowType.FLOW_ROLES_DEPT[1];
- }
- // 不是出纳的情况下进行的判断
- //1.如果当前角色是自己,就进行正常的审核流程 ok
- //2.先查看当前角色是不是自己,不是自己就移动到自己的角FlowException色,然后再进行正常的审核流程 ok
- if (setRurrRole.equals(currRole)) {//1.如果当前角色是自己,就进行正常的审核流程 ok
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- } else {//2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
- FrameUser targetUser = null;
- UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
- // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- if (userPosition == null) {//没有找到数据
- System.out.println("9没有找到对应人:" + "if (userPosition == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap);
- return new HashMap<>();
- } else {//找到userPosition数据录了
- //还不是自己的角色,还要遍历查找
- return getNextFlow(businessId, userPosition, deploymentid, myframeUser, conditionMap, task);
- }
- }
- }
- }
- /**
- * 通用方法 写一个正常流程,正常下审核到下一个环节
- *
- * @param deploymentid 流程任务唯一id
- * @param currUser 当前审核人/委托人代表的用户
- * @param task2 当前的任务Task
- * @param conditionMap 所需要用到的条件
- * @return
- */
- public Map<String, String> donaturalTask(String deploymentid, FrameUser currUser, Task task2, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
- {
- FrameUser targetUser = null;
- //可以开始正常走流程了 嘻嘻...
- {
- UserTask myNowUserTask = this.getUserTaskById(task2.getTaskDefinitionKey(), deploymentid);//id的值如:_9
- //获取到了出去的各条路径
- List<SequenceFlow> outgoingFlows = myNowUserTask.getOutgoingFlows();
- //我的下一个节点位置
- SequenceFlow myNextSequenceFlow = null;
- for (SequenceFlow outgoingFlow : outgoingFlows) {
- String conditionExpression = outgoingFlow.getConditionExpression();
- //如果是空就跳过
- if (conditionExpression == null) {
- continue;
- } else
- //只有是yes的时候才是需要往下运行的,如果
- if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
- continue;
- } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
- continue;
- } else
- //只有是yes的时候才是需要往下运行的,如果
- if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
- //发现没有判断条件,那本流程就是下个节点
- myNextSequenceFlow = outgoingFlow;
- } else {
- //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
- //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
- //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // myconditionExpressions.add(conditionExpression);
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextSequenceFlow = outgoingFlow;
- // break;
- // }
- if (this.booleanConditionIsOk(conditionExpression, conditionMap)) {
- myNextSequenceFlow = outgoingFlow;
- }
- }
- //如果没有找到下个流程节点就继续找
- if (myNextSequenceFlow == null) {
- continue;
- }
- {
- //下面是找到了下个流程节点,需要进行正常的运行节点了
- //================================================================
- //TaskList.get(1).getOutgoingFlows().get(1).getTargetFlowElement().getCandidateGroups()
- // TaskList.get(7).getOutgoingFlows().get(1).getTargetFlowElement().getClass().isInstance(EndEvent.class);
- FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
- if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
- System.out.println("已经是结束流程了,直接完成审核就行了1");
- boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
- HashMap<String, String> objectObjectHashMap = new HashMap<>();
- objectObjectHashMap.put("isEnd", "1");
- return objectObjectHashMap;
- }
- //class org.activiti.bpmn.model.EndEvent
- String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
- String setRurrRole = this.getSetRurrRole(candidateGroup);
- boolean end = false;
- for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- {//统一到同一个方法中了:getTargerUser_FLOW_ROLES_DEPT
- // if (s.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导
- // String department = currUser.getDepartment();
- // SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- // if (sysDept == null) {//没有部门信息
- //
- // } else {
- // String changedBy = sysDept.getChangedBy();
- // if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
- //
- // } else {
- // targetUser = userService.selectByPrimaryKey(changedBy);
- // }
- // }
- // } else {
- // String leader = currUser.getLeader();
- // if (StringUtils.isEmpty(leader)) {//没有找到直接领导
- // } else {
- // targetUser = userService.selectByPrimaryKey(leader);
- // }
- // }
- // if (targetUser == null) {//没有找到目标人就都传到admin中去
- //// return null;
- // targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- // if (targetUser == null) {
- // System.err.println("异常,没有找到目标人");
- // return null;
- // }
- // }
- }
- // 写一个通用方法,专门根据条件获取部门领导是谁
- targetUser = this.getTargerUser_FLOW_ROLES_DEPT(s, currUser);
- if (targetUser == null) {
- return null;
- }
- //todo SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- end = true;
- return new HashMap<>();
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // 在上面的方法基础上,增加groupId和用户状态的过滤
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
- role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- if (targetUserList.size() >= 1) {
- targetUser = targetUserList.get(0);
- }
- }
- if (targetUser == null) {
- // return null;
- System.out.println("1没有找到对应人:" + "if (targetUser == null) {==>" + role + "==>" + ConstantFlowType.ROLETYPE);
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- end = true;
- return new HashMap<>();
- }
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // 在上面的方法基础上,增加groupId和用户状态的过滤
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
- role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- if (targetUserList.size() >= 1) {
- targetUser = targetUserList.get(0);
- }
- }
- if (targetUser == null) {
- // return null;
- System.out.println("2没有找到对应人:" + "if (targetUser == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- end = true;
- return new HashMap<>();
- }
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.PURCHASE_ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // 在上面的方法基础上,增加groupId和用户状态的过滤
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
- role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- targetUser = targetUserList.get(0);
- }
- if (targetUser == null) {
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- }
- flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- return new HashMap<>();
- }
- }
- }
- break;
- }
- }
- //都没有就是没有下个流程了,可以结束流程了
- System.out.println("已经没有下个申请流程了,已经结束了1");
- //
- boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
- HashMap<String, String> objectObjectHashMap = new HashMap<>();
- objectObjectHashMap.put("isEnd", "1");
- return objectObjectHashMap;
- }
- //下面的代码要替换掉==========================================================================================
- // {
- //
- // //可以开始正常走流程了 嘻嘻...
- // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task2.getTaskDefinitionKey(), false);
- // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
- // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
- // UserTask myNextTask = null;//我要走的流程
- // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
- // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
- // if (!"-yes".equals(candidateGroup.substring(candidateGroup.indexOf("-")))){
- // continue;
- // }
- // String setRurrRole = this.getSetRurrRole(candidateGroup);
- // {
- // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
- // //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
- // for (SequenceFlow outgoingFlow : outgoingFlows) {
- // String conditionExpression = outgoingFlow.getConditionExpression();
- // if (conditionExpression == null) {
- // continue;
- // }
- // if (conditionExpression.contains("${agree==")) {
- // continue;
- // }
- // myconditionExpressions.add(conditionExpression);
- // }
- // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
- // myNextTask = userTask;
- //
- // } else {//有条件就判断是否满足条件,不满足就运行下一个
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextTask = userTask;
- // }
- //
- // if (myNextTask == null) {
- // continue;
- // }
- //
- // }
- // }
- // //================================================================
- // boolean end = false;
- // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- // String leader = currUser.getLeader();
- // targetUser = userService.selectByPrimaryKey(leader);
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- //
- // end = true;
- // return new HashMap<>();
- // }
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return new HashMap<>();
- // }
- // }
- //
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return new HashMap<>();
- // }
- // }
- // }
- // break;
- // }
- // //都没有就是没有下个流程了,可以结束流程了
- // System.out.println("已经没有下个申请流程了,已经结束了");
- // //
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
- //
- // HashMap<String, String> objectObjectHashMap = new HashMap<>();
- // objectObjectHashMap.put("isEnd","1");
- // return objectObjectHashMap;
- // } else {
- // System.out.println("已经没有下个申请流程了,已经结束了");
- // //
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap);
- //
- // HashMap<String, String> objectObjectHashMap = new HashMap<>();
- // objectObjectHashMap.put("isEnd","1");
- // return objectObjectHashMap;
- // }
- // }
- }
- }
- /**
- * 写一个通用方法判断流程中的条件是否符合要求
- * conditionExpression 判断的条件
- * conditionMap拥有的条件
- */
- public boolean booleanConditionIsOk(String conditionExpression, Map<String, Object> conditionMap) {
- //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
- //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
- //获取路径的判断条件
- List<String> myconditionExpressions = new ArrayList<String>();
- myconditionExpressions.add(conditionExpression);
- int isOkNum = 0;
- for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- boolean isOk = false;
- //这是我的判断条件(通过条件判断库去比对数据)
- String mycondition = myconditionExpressions.get(i1);
- if (mycondition.contains("billMoney")) {
- // ${billMoney>3000}
- Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- if (mycondition.contains("<=")) {
- String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- if (billMoney <= Double.valueOf(substring)) {
- // ok
- isOk = true;
- }
- } else if (mycondition.contains("<")) {
- String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- if (billMoney < Double.valueOf(substring)) {
- // ok
- isOk = true;
- }
- } else if (mycondition.contains(">=")) {
- String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- if (billMoney >= Double.valueOf(substring)) {
- // ok
- isOk = true;
- }
- } else if (mycondition.contains(">")) {
- String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- if (billMoney > Double.valueOf(substring)) {
- // ok
- isOk = true;
- }
- } else if (mycondition.contains("==")) {
- String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- BigDecimal data1 = new BigDecimal(billMoney);
- BigDecimal data2 = new BigDecimal(substring);
- int i2 = data1.compareTo(data2);
- if (i2 == 0) {
- // ok
- isOk = true;
- }
- }
- } else if (mycondition.contains("isExchangeOnly==")) {
- String isExchangeOnly = conditionMap.get("isExchangeOnly").toString();
- Integer applyDay = Integer.valueOf(conditionMap.get("applyDay").toString());
- if (mycondition.contains("(isExchangeOnly=='no') and (applyDay>3)")) {
- if ("no".equals(isExchangeOnly) && applyDay > 3) {
- isOk = true;
- }
- } else if (mycondition.contains("(isExchangeOnly=='yes') or (applyDay<=3)")) {
- if ("yes".equals(isExchangeOnly) || applyDay <= 3) {
- isOk = true;
- }
- }
- }
- if (isOk) {
- isOkNum = isOkNum + 1;
- }
- }
- if (isOkNum == myconditionExpressions.size()) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 根据用户位置启动信息启动流程
- * processDefine 在ConstantFlowType中的PAYMEN_PROCESSDEFINE
- * String businessId = "1088140517679562752";//主申请表id
- * deploymentid 在ConstantFlowType.USE_MONEY_DEPLOYMENTID
- * conditionMap 是条件数据,比如目前需要的条件是${billMoney>3000}
- * return 返回的数据是flow_id字段,如果是null,说明异常有问题了 如果是end就是没有下个流程了,可以结束了
- */
- public Map<String, String> startTask(String processDefine, String deploymentid, String businessId, FrameUser currUser, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
- FrameUser targetUser = null;
- String currRole = this.getCurrRole(currUser);
- UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
- // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- Map<String, String> startTask = null;
- if (userPosition == null) {//没有找到数据
- System.out.println("7没有找到对应人:" + " if (userPosition == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- return startTask;
- } else {//找到userPosition对象数据了
- // 1.如果是1就正常网下写,如果发现目标审核人的角色不是正常角色,就要去找他的对应位置的角色,不管是谁都要审核通过才行, 所以开始的时候只要找到直接领导传下去就好了,在运行节点进行角色判断,将流程跳到自己的角色位置结束
- //1.1查看下个节点人员角色的需求
- //1.1.1如果是部门关系的查部门
- //1.1.2如果是领导关系的查领导
- //1.1.3如果是收纳关系的查收纳
- //2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- int nodeNum = userPosition.getNodeNum();
- UserTask currentUserTask = userPosition.getCurrentUserTask();
- if (nodeNum == 1) {
- {
- List<SequenceFlow> outgoingFlows = currentUserTask.getOutgoingFlows();
- //我的下一个节点位置
- SequenceFlow myNextSequenceFlow = null;
- for (SequenceFlow outgoingFlow : outgoingFlows) {
- String conditionExpression = outgoingFlow.getConditionExpression();
- //如果是空就跳过
- if (conditionExpression == null) {
- continue;
- } else
- //只有是yes的时候才是需要往下运行的,如果
- if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
- continue;
- } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
- continue;
- } else
- //只有是yes的时候才是需要往下运行的,如果
- if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
- //发现没有判断条件,那本流程就是下个节点
- myNextSequenceFlow = outgoingFlow;
- } else {
- //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
- //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
- //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // myconditionExpressions.add(conditionExpression);
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextSequenceFlow = outgoingFlow;
- // break;
- // }
- if (this.booleanConditionIsOk(conditionExpression, conditionMap)) {
- myNextSequenceFlow = outgoingFlow;
- }
- }
- //如果没有找到下个流程节点就继续找
- if (myNextSequenceFlow == null) {
- continue;
- }
- //下面是找到了下个流程节点,需要进行正常的运行节点了
- FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
- if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
- System.out.println("已经是结束流程了,直接完成审核就行了2");
- return null;
- }
- String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
- String setRurrRole = this.getSetRurrRole(candidateGroup);
- boolean end = false;
- for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- //统一到同一个方法中了:getTargerUser_FLOW_ROLES_DEPT
- // 写一个通用方法,专门根据条件获取部门领导是谁
- targetUser = this.getTargerUser_FLOW_ROLES_DEPT(s, currUser);
- if (targetUser == null) {
- return null;
- }
- //todo SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- end = true;
- return startTask;
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // 在上面的方法基础上,增加groupId和用户状态的过滤
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
- role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- if (targetUserList.size() >= 1) {
- targetUser = targetUserList.get(0);
- }
- }
- if (targetUser == null) {
- // return null;
- System.out.println("3没有找到对应人:" + "if (targetUser == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- end = true;
- return startTask;
- }
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // 在上面的方法基础上,增加groupId和用户状态的过滤
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
- role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- if (targetUserList.size() >= 1) {
- targetUser = targetUserList.get(0);
- }
- }
- if (targetUser == null) {
- // return null;
- System.out.println("4没有找到对应人:" + "if (targetUser == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- end = true;
- return startTask;
- }
- }
- }
- return null;
- }
- //走到这里就没有找到对应的流程节点,所以需要报错 返回null
- System.out.println("异常错误,没有找到对应的流程节点");
- return null;
- }
- //下面的要作废了================================================================
- //获取下个节点数据
- // {
- // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, currentUserTask.getId(), false);
- // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
- // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(0);
- // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
- // String setRurrRole = this.getSetRurrRole(candidateGroup);
- // boolean end = false;
- // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- // String leader = currUser.getLeader();
- // targetUser = userService.selectByPrimaryKey(leader);
- // if (targetUser == null) {
- // return null;
- // }
- // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- // end = true;
- // return startTask;
- // }
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- // end = true;
- // return startTask;
- // }
- // }
- //
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- // end = true;
- // return startTask;
- // }
- // }
- // }
- // return null;
- //
- // } else {
- // return null;
- // }
- // }
- } else if (nodeNum > 1) {
- // 2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- // 需要进行循环审核过程
- boolean isZhuYaoLingDao="flow_zyld".equals(currRole)?true:false; //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断
- // 现在没有:开始申请的时候不判断身份是否是该节点本身份 的判断了 if(isZhuYaoLingDao) {//2023年7月5日 章总在第七批次又改回来了 //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断
- if(true) {
- targetUser = currUser;
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- if (!startTask.isEmpty()) {
- {
- // String flow_id = startTask.get("processInstanceId").toString();//"流程实例ID:" + task.getProcessInstanceId());是会变化的所以没有用
- List<Task> list = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象
- .taskAssignee(targetUser.getId())//指定个人任务查询
- // .processInstanceId("12516")
- .list();
- if (list == null || list.isEmpty() || list.size() <= 0) {
- System.err.println("异常,没有找到任务对象");
- return null;
- }
- //2.1通过flow_id和targetUser获取下一个UserTask
- Task task = list.get(0);
- //task是当前流程的信息
- //如果发现task对应的角色就是自己的角色,就开始正常的走
- //如果发现task对应的角色还不是,就需要再进行设置自己的操作
- String taskDefinitionKey = task.getTaskDefinitionKey(); //id的值如:_9
- String flowId = userPosition.getUserTask().getId();//流程唯一id(我猜的)
- if (flowId.equals(taskDefinitionKey)) {
- //可以开始正常走流程了 嘻嘻...
- {
- // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task.getTaskDefinitionKey(), false);
- // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
- // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
- // UserTask myNextTask = null;//我要走的流程
- // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
- // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
- // //需要的角色
- // String setRurrRole = this.getSetRurrRole(candidateGroup);
- // {
- // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
- // //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
- // for (SequenceFlow outgoingFlow : outgoingFlows) {
- // String conditionExpression = outgoingFlow.getConditionExpression();
- // if (conditionExpression == null) {
- // continue;
- // }
- // if (conditionExpression.contains("${agree==")) {
- // continue;
- // }
- // myconditionExpressions.add(conditionExpression);
- // }
- // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
- // myNextTask = userTask;
- //
- // } else {//有条件就判断是否满足条件,不满足就运行下一个
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextTask = userTask;
- // }
- //
- // if (myNextTask == null) {
- // continue;
- // }
- //
- // }
- // }
- // //================================================================
- // boolean end = false;
- // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- // String leader = currUser.getLeader();
- // targetUser = userService.selectByPrimaryKey(leader);
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- //
- // end = true;
- // return new HashMap<>();
- // }
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return new HashMap<>();
- // }
- // }
- //
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return new HashMap<>();
- // }
- // }
- // }
- // break;
- // }
- // } else {
- // System.out.println("已经没有下个申请流程了,已经结束了");
- // return null;
- // }
- }
- Map<String, String> donaturalTaskMap = this.donaturalTask(deploymentid, currUser, task, conditionMap);
- if (donaturalTaskMap == null) {
- return null;
- } else {
- return startTask;
- }
- } else {
- //还不是自己的角色,还要遍历查找(但是要写在getNextFlow方法里面,且通过flowServiceNextFlow方法改造一下)
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- {//遍历对象
- Map<String, String> getNextFlowMap = getNextFlow(businessId, userPosition, deploymentid, currUser, conditionMap, task);
- if (getNextFlowMap == null) {
- return null;
- } else {
- //todo 如果getNextFlowMap返回数据是:{isEnd=1} 需要特殊处理
- if (getNextFlowMap.get("isEnd") == null) {
- return startTask;
- } else {
- startTask.put("isEnd", getNextFlowMap.get("isEnd"));
- return startTask;
- }
- }
- }
- }
- }
- } else {
- return null;
- }
- }else { //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以新增掉下面的操作
- if (currUser.getLeader()!=null) {
- targetUser = userService.selectByPrimaryKey(currUser.getLeader());
- }
- if (targetUser==null){
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- if (!startTask.isEmpty()) {
- return startTask;
- } else {
- return null;
- }
- }
- } else {
- return null;
- }
- //为了实现并联串联审核流程的方法需求
- //要求:flowService.startTask(processDefine, null, businessId, targetUser, currUser);改成flowService.startTask(processDefine, null, businessId, targetUsers,totalnumber, currUser);(修改内容目标人改成数组targetUsers,审核通过数量totalnumber自己定义)
- //要求2:flowService.runTask(taskId, null, agree, comments, targetUser, currUser, null);改成flowService.runTask(taskId, null, agree, comments, targetUsers,totalnumber, currUser, null);(修改内容目标人改成数组targetUsers,审核通过数量totalnumber自己定义)
- }
- //返回数据{processInstanceId=7501}{processInstanceId=12501}{processInstanceId=17501}
- }
- /**
- * 做一个通用方法,通过UserTask的id和deloymentId来获取指定的UserTask
- */
- public UserTask getUserTaskById(String id, String deloymentId) {
- List<UserTask> taskList = flowService.getTaskList(deloymentId);
- for (int i = 0; i < taskList.size(); i++) {
- if (taskList.get(i).getId().equals(id)) {
- return taskList.get(i);
- }
- }
- return null;
- // List<UserTask> collect = taskList.stream().filter(x -> x.getId().equals(id)).collect(Collectors.toList());
- // if (collect.isEmpty()){
- // return null;
- // }else{
- // return collect.get(0);
- // }
- }
- /**
- * 通过任务id获取userTask信息
- *
- * @param taskId
- * @return
- */
- public UserTask getUserTaskByTaskId(String taskId) {
- return (UserTask) flowService.getCurrentFlowNode(taskId);
- }
- /**
- * 写一个方法,当还不是自己的角色时,需要进入下个节点,若下个节点是收纳就可以结束运行,返回false,说明是end结束了,若返回true,说明正常继续运行
- *
- * @return
- */
- public Boolean flowServiceNextFlow(String deploymentid, Map<String, Object> conditionMap, FrameUser currUser, Task task) throws com.rockstar.flow.exception.FlowException {
- //获取到了我的userTask
- {
- UserTask myNowUserTask = this.getUserTaskById(task.getTaskDefinitionKey(), deploymentid);//id的值如:_9
- //获取到了出去的各条路径
- List<SequenceFlow> outgoingFlows = myNowUserTask.getOutgoingFlows();
- //我的下一个节点位置
- SequenceFlow myNextSequenceFlow = null;
- for (SequenceFlow outgoingFlow : outgoingFlows) {
- String conditionExpression = outgoingFlow.getConditionExpression();
- //如果是空就跳过
- if (conditionExpression == null) {
- continue;
- } else
- //只有是yes的时候才是需要往下运行的,如果
- if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
- continue;
- } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
- continue;
- } else
- //只有是yes的时候才是需要往下运行的,如果
- if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
- //发现没有判断条件,那本流程就是下个节点
- myNextSequenceFlow = outgoingFlow;
- } else {
- //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点
- //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧
- //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // myconditionExpressions.add(conditionExpression);
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextSequenceFlow = outgoingFlow;
- // }
- if (this.booleanConditionIsOk(conditionExpression, conditionMap)) {
- myNextSequenceFlow = outgoingFlow;
- }
- }
- //如果没有找到下个流程节点就继续找
- if (myNextSequenceFlow == null) {
- continue;
- }
- {//下面是找到了下个流程节点,需要进行正常的运行节点了
- //================================================================================================
- // TaskList.get(1).getOutgoingFlows().get(1).getTargetFlowElement().getCandidateGroups()
- FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
- if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
- System.out.println("已经是结束流程了,直接完成审核就行了3");
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- return null;
- }
- String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
- String setRurrRole = this.getSetRurrRole(candidateGroup);
- boolean end = false;
- for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- // String leader = currUser.getLeader();
- // targetUser = userService.selectByPrimaryKey(leader);
- // if (targetUser == null) {
- // return null;
- // }
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- end = true;
- return true;
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- end = true;
- return true;
- }
- }
- }
- if (!end) {
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // 在上面的方法基础上,增加groupId和用户状态的过滤
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(
- role, ConstantFlowType.ROLETYPE, currUser.getGroupId());
- FrameUser targetUser = null;
- if (!targetUserList.isEmpty()) {
- if (targetUserList.size() >= 1) {
- targetUser = targetUserList.get(0);
- }
- }
- if (targetUser == null) {
- // return null;
- System.out.println("5没有找到对应人:" + "if (targetUser == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- end = true;
- return false;
- }
- }
- }
- break;
- }
- }
- //如果运行找到这里就说明没有找到下个流程节点了,流程可以结束了
- System.out.println("已经没有下个申请流程了,已经结束了2");
- //
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- return null;
- }
- // {
- // //下面的部分将会被淘汰掉.....................................................
- // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task.getTaskDefinitionKey(), false);
- // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
- // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
- // UserTask myNextTask = null;//我要走的流程
- // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
- // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
- // if (!"-yes".equals(candidateGroup.substring(candidateGroup.indexOf("-")))) {
- // continue;
- // }
- // //需要的角色
- // String setRurrRole = this.getSetRurrRole(candidateGroup);
- // {
- // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
- // //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
- // for (SequenceFlow outgoingFlow : outgoingFlows) {
- // String conditionExpression = outgoingFlow.getConditionExpression();
- // if (conditionExpression == null) {
- // continue;
- // }
- // if (conditionExpression.contains("${agree==")) {
- // continue;
- // }
- // myconditionExpressions.add(conditionExpression);
- // }
- // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
- // myNextTask = userTask;
- //
- // } else {//有条件就判断是否满足条件,不满足就运行下一个
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextTask = userTask;
- // }
- //
- // if (myNextTask == null) {
- // continue;
- // }
- //
- // }
- // }
- // //================================================================
- // boolean end = false;
- // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- //// String leader = currUser.getLeader();
- //// targetUser = userService.selectByPrimaryKey(leader);
- //// if (targetUser == null) {
- //// return null;
- //// }
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- //
- // end = true;
- // return true;
- // }
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- // //查看谁是对应角色并查找对应的人
- //// String role = ConstantFlowType.ROLES[i];
- //// List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- //// if (!targetUserList.isEmpty()) {
- //// if (targetUserList.size() >= 1) {
- //// targetUser = targetUserList.get(0);
- //// }
- //// }
- //// if (targetUser == null) {
- //// return null;
- //// }
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- // end = true;
- // return true;
- // }
- // }
- //
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // FrameUser targetUser = null;
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return false;
- // }
- // }
- // }
- // break;
- // }
- // System.out.println("已经没有下个申请流程了,已经结束了");
- // //
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- // return null;
- // } else {
- // System.out.println("已经没有下个申请流程了,已经结束了");
- // //
- // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap);
- // return null;
- // }
- // }
- }
- /**
- * 遍历进行操作最终获取用户自己的角色
- *
- * @return
- */
- 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 {
- FrameUser targetUser = currUser;
- Boolean aBoolean = this.flowServiceNextFlow(deploymentid, conditionMap, currUser, task);
- if (aBoolean == null) {
- Map<String, String> objectObjectHashMap = new HashMap<>();
- objectObjectHashMap.put("isEnd", "1");
- return objectObjectHashMap;
- } else if (!aBoolean) {
- return new HashMap<>();
- } else if (aBoolean) {
- //继续运行下面的步骤
- }
- {//遍历对象
- List<Task> list2 = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象
- .taskAssignee(targetUser.getId())//指定个人任务查询
- // .processInstanceId("12516")
- .list();
- if (list2 == null || list2.isEmpty() || list2.size() <= 0) {
- System.err.println("异常,没有找到任务对象2");
- return null;
- }
- //2.1通过flow_id和targetUser获取下一个UserTask
- Task task2 = list2.get(0);
- //task是当前流程的信息
- //如果发现task对应的角色就是自己的角色,就开始正常的走
- //如果发现task对应的角色还不是,就需要再进行设置自己的操作
- String taskDefinitionKey2 = task2.getTaskDefinitionKey(); //id的值如:_9
- String flowId2 = userPosition.getUserTask().getId();//流程唯一id(我猜的)
- if (flowId2.equals(taskDefinitionKey2)) {
- //可以开始正常走流程了 嘻嘻...
- {
- // //可以开始正常走流程了 嘻嘻...
- // List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task2.getTaskDefinitionKey(), false);
- // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
- // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) {
- // UserTask myNextTask = null;//我要走的流程
- // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii);
- // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes
- // String setRurrRole = this.getSetRurrRole(candidateGroup);
- // {
- // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断
- // //获取路径的判断条件
- // List<String> myconditionExpressions = new ArrayList<String>();
- // List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
- // for (SequenceFlow outgoingFlow : outgoingFlows) {
- // String conditionExpression = outgoingFlow.getConditionExpression();
- // if (conditionExpression == null) {
- // continue;
- // }
- // if (conditionExpression.contains("${agree==")) {
- // continue;
- // }
- // myconditionExpressions.add(conditionExpression);
- // }
- // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用
- // myNextTask = userTask;
- //
- // } else {//有条件就判断是否满足条件,不满足就运行下一个
- // int isOkNum = 0;
- // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) {
- // boolean isOk = false;
- // //这是我的判断条件(通过条件判断库去比对数据)
- // String mycondition = myconditionExpressions.get(i1);
- // if (mycondition.contains("billMoney")) {
- //// ${billMoney>3000}
- // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString());
- // if (mycondition.contains("<=")) {
- // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1);
- // if (billMoney <= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- //
- // }
- // } else if (mycondition.contains("<")) {
- // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1);
- // if (billMoney < Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">=")) {
- // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1);
- // if (billMoney >= Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains(">")) {
- // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1);
- // if (billMoney > Double.valueOf(substring)) {
- //// ok
- // isOk = true;
- // }
- // } else if (mycondition.contains("==")) {
- // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1);
- // BigDecimal data1 = new BigDecimal(billMoney);
- // BigDecimal data2 = new BigDecimal(substring);
- // int i2 = data1.compareTo(data2);
- // if (i2 == 0) {
- //// ok
- // isOk = true;
- // }
- // }
- // }
- //
- // if (isOk) {
- // isOkNum = isOkNum + 1;
- // }
- // }
- // if (isOkNum == myconditionExpressions.size()) {
- // myNextTask = userTask;
- // }
- //
- // if (myNextTask == null) {
- // continue;
- // }
- //
- // }
- // }
- // //================================================================
- // boolean end = false;
- // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门
- // String leader = currUser.getLeader();
- // targetUser = userService.selectByPrimaryKey(leader);
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- //
- // end = true;
- // return new HashMap<>();
- // }
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return new HashMap<>();
- // }
- // }
- //
- // }
- // if (!end) {
- // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) {
- // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳
- // //查看谁是对应角色并查找对应的人
- // String role = ConstantFlowType.ROLES_CHECK[i];
- // List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE);
- // if (!targetUserList.isEmpty()) {
- // if (targetUserList.size() >= 1) {
- // targetUser = targetUserList.get(0);
- // }
- // }
- // if (targetUser == null) {
- // return null;
- // }
- // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap);
- // end = true;
- // return new HashMap<>();
- // }
- // }
- // }
- // break;
- // }
- // } else {
- // System.out.println("已经没有下个申请流程了,已经结束了");
- // return null;
- // }
- //
- }
- return this.donaturalTask(deploymentid, currUser, task2, conditionMap);
- } else {
- //还不是自己的角色,还要遍历查找
- return getNextFlow(businessId, userPosition, deploymentid, currUser, conditionMap, task2);
- }
- }
- // return null;
- }
- /**
- * 共用方法 //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管),
- * 但是注意,这只是判断是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的
- *
- * @param currUser
- * @return
- */
- public String getCurrRole(FrameUser currUser) {
- //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管)
- String currRole = "";//flow_fgld", "flow_sjfgld", "flow_zyld或者curr_user,dept_head
- {
- //1获取用户流程类型
- {
- String[] flow_roles = ConstantFlowType.FLOW_ROLES;//{"flow_fgld", "flow_sjfgld", "flow_zyld"};
- String[] roles = ConstantFlowType.ROLES;// {"fgld", "sjfgld", "zyld"};
- // frame_role_data
- List<FrameRoleData> FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(currUser.getId(), ConstantFlowType.ROLETYPE);//"FLOW"
- Integer c = null;
- //判断用户的最高用户流类型
- for (FrameRoleData frameRoleData : FrameRoleDatas) {
- String roleKey = frameRoleData.getRoleKey();
- for (int i = 0; i < roles.length; i++) {
- if (roles[i].equals(roleKey)) {
- if (c == null) {
- c = i;
- } else if (c < i) {
- c = i;
- }
- break;
- }
- }
- }
- if (c != null) {
- currRole = flow_roles[c];
- return currRole;
- }
- }
- //2获取用户部门是否是主管
- {
- String department = currUser.getDepartment();
- SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- if (sysDept == null) {//没有部门信息
- if (currRole.equals("")) {
- currRole = "";
- return null;
- } else {
- //是领导流程类型
- }
- } else {
- String changedBy = sysDept.getChargedBy();
- if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
- if (currRole.equals("")) {
- currRole = "";
- } else {
- //是领导流程类型
- }
- return null;
- } else {//找到部门主管
- if (changedBy.equals(currUser.getId())) {//自己是部门主管
- if (currRole.equals("")) {
- currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head";
- } else {
- //是领导流程类型
- }
- } else {//部门主管是别人,自己不是部门主管
- if (currRole.equals("")) {
- currRole = ConstantFlowType.FLOW_ROLES_DEPT[0];//"curr_user";
- } else {
- //是领导流程类型
- }
- }
- }
- }
- }
- }
- return currRole;
- }
- /**
- * 写一个方法, 已知用户信息 zt ok
- * 申请付款时 通过用户信号获取用户在全流程中的位置,如果没有找到对象,返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- */
- public UserTaskMore findUserPosition(String currRole, String deploymentid) {
- //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管)
- // String currRole = this.getCurrRole(currUser2);
- //没有获取到角色异常返回null
- if (currRole == null || currRole.equals("")) {
- return null;
- }
- //获取活动节点
- //这是流程排序编号
- int nodeNum = 0;
- List<UserTask> taskList = flowService.getTaskList(deploymentid);
- UserTask userTask = taskList.get(0);
- nodeNum = nodeNum + 1;
- String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
- String setRurrRole = this.getSetRurrRole(s);
- if (currRole.equals(setRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上
- // return userTask;
- // return nodeNum;
- return new UserTaskMore(userTask, nodeNum, userTask);
- } else {//要进行轮查获取用户位置
- UserTaskMore nextCandidateGroupByDeploy = this.getNextMyUserTask(taskList, currRole, nodeNum);
- // UserTaskMore nextCandidateGroupByDeploy = getNextCandidateGroupByDeploy(userTask, currRole, nodeNum, deploymentid);
- nextCandidateGroupByDeploy.setCurrentUserTask(userTask);
- return nextCandidateGroupByDeploy;
- }
- }
- /**
- * 申请付款时 通过传递的数据递归获取用户角色实际的运行节点
- *
- * @return
- */
- public UserTaskMore getNextMyUserTask(List<UserTask> taskList, String currRole, Integer nodeNum) {
- for (int i = 1; i < taskList.size(); i++) {
- nodeNum = 2;
- UserTask myuserTask = taskList.get(i);
- String taskKey = myuserTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
- String taskSetRurrRole = this.getSetRurrRole(taskKey);
- if (currRole.equals(taskSetRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上
- System.out.println("2结束节点" + nodeNum);
- // return userTask;
- // return nodeNum;
- return new UserTaskMore(myuserTask, nodeNum);
- }
- }
- return null;
- }
- /**
- * 这个方法有问题,不能获取自己想要的,放弃使用了
- * 申请付款时 通过传递的数据递归获取用户角色实际的运行节点
- *
- * @param newUserTask
- * @param currRole
- * @param nodeNum
- * @return
- */
- public UserTaskMore getNextCandidateGroupByDeploy(UserTask newUserTask, String currRole, Integer nodeNum, String deploymentid) {
- List<Object> nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, newUserTask.getId(), false);
- if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) {
- // //进行分支判断
- // for (int i = 0; i < nextCandidateGroupByDeploy.size(); i++) {
- // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(i);
- // String taskKey = userTask.getCandidateGroups().get(0);//dept_head_1_0_1-yes
- // String yesNo = taskKey.substring(taskKey.indexOf("-"));
- // if (!"yes".equals(yesNo)) {
- // continue;
- // }
- // String setRurrRole = this.getSetRurrRole(taskKey);//获取任务的角色
- //
- // }
- nodeNum = nodeNum + 1;
- System.out.println("运行节点" + nodeNum);
- UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(0);
- String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
- String setRurrRole = this.getSetRurrRole(s);
- if (currRole.equals(setRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上
- System.out.println("1结束节点" + nodeNum);
- // return userTask;
- // return nodeNum;
- return new UserTaskMore(userTask, nodeNum);
- } else {
- getNextCandidateGroupByDeploy(userTask, currRole, nodeNum, deploymentid);
- }
- } else {
- return null;
- }
- return null;
- }
- /**
- * 通过原key获取角色数据
- *
- * @param s
- * @return
- */
- public static String getSetRurrRole(String s) {
- // String s="dept_head_1_0_1-yes";或者curr_user-no
- String[] s1 = s.contains("-") ? s.substring(0, s.indexOf("-")).split("_") : s.split("_");
- s = s1[0] + "_" + s1[1];
- // System.out.println(s);
- return s;
- }
- /**
- * 写一个通用方法,专门根据条件获取部门领导是谁
- * targetRole:下一个审核人的角色
- * currUser:当前的审核人角色
- */
- public FrameUser getTargerUser_FLOW_ROLES_DEPT(String targetRole, FrameUser currUser) {
- FrameUser targetUser = null;
- if (targetRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导
- String department = currUser.getDepartment();
- SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- if (sysDept == null) {//没有部门信息
- } else {
- String changedBy = sysDept.getChargedBy();
- if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
- } else {
- targetUser = userService.selectByPrimaryKey(changedBy);
- }
- }
- } else {
- String leader = currUser.getLeader();
- if (StringUtils.isEmpty(leader)) {//没有找到直接领导
- } else {
- targetUser = userService.selectByPrimaryKey(leader);
- }
- }
- if (targetUser == null) {//没有找到目标人就都传到admin中去
- // return null;
- System.out.println("6没有找到对应人:" + "if (targetUser == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- return targetUser;
- }
- public FrameUser getTargerUser_FLOW_ROLES_DEPT_PLUS(String targetRole, FrameUser currUser) {
- FrameUser targetUser = null;
- if (targetRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导
- String department = currUser.getDepartment();
- SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- if (sysDept == null) {//没有部门信息
- } else {
- String changedBy = sysDept.getChargedBy();
- if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
- } else {
- targetUser = userService.selectByPrimaryKey(changedBy);
- }
- }
- } else {
- String leader = currUser.getLeader();
- if (StringUtils.isEmpty(leader)) {//没有找到直接领导
- // 流转给子公司超管
- FrameRoleDataExample example = new FrameRoleDataExample();
- example.createCriteria().andRoleKeyEqualTo(ConstantFlowType.PURCHASE_ROLES_CHECK_PLUS)
- .andRoleTypeEqualTo(ConstantFlowType.ROLETYPE2);
- List<FrameRoleData> frameRoleDataList = frameRoleDataService.selectByExample(example);
- if(CollectionUtils.isNotEmpty(frameRoleDataList)) {
- FrameRoleData frameRoleData = frameRoleDataList.get(0);
- List<String> userIds = frameRoleDataUserService.selectUserByRoleDataId(frameRoleData.getId());
- if(CollectionUtils.isNotEmpty(userIds)) {
- FrameUserExample example1 = new FrameUserExample();
- example1.createCriteria().andIdIn(userIds).andGroupIdEqualTo(currUser.getGroupId())
- .andStatusEqualTo("1");
- List<FrameUser> frameUserList = frameUserService.selectByExample(example1);
- if(CollectionUtils.isNotEmpty(frameUserList)) {
- targetUser = frameUserList.get(0);
- }
- }
- }
- } else {
- targetUser = userService.selectByPrimaryKey(leader);
- }
- }
- if (targetUser == null) {//没有找到目标人就都传到admin中去
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- }
- return targetUser;
- }
- public Map<String, String> startPurchaseTask(String processDefine, String deploymentid, String businessId,
- FrameUser currUser, Map<String, Object> conditionMap)
- throws com.rockstar.flow.exception.FlowException {
- FrameUser targetUser = null;
- String currRole = this.getCurrRole(currUser);
- UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
- Map<String, String> startTask;
- if (userPosition == null) {
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- return startTask;
- } else {
- int nodeNum = userPosition.getNodeNum();
- UserTask currentUserTask = userPosition.getCurrentUserTask();
- if (nodeNum == 1) {
- {
- List<SequenceFlow> outgoingFlows = currentUserTask.getOutgoingFlows();
- //我的下一个节点位置
- SequenceFlow myNextSequenceFlow = null;
- for (SequenceFlow outgoingFlow : outgoingFlows) {
- String conditionExpression = outgoingFlow.getConditionExpression();
- //如果是空就跳过
- if (conditionExpression == null) {
- continue;
- } else if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'}
- continue;
- } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'}
- continue;
- } else if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx
- //发现没有判断条件,那本流程就是下个节点
- myNextSequenceFlow = outgoingFlow;
- }
- //如果没有找到下个流程节点就继续找
- if (myNextSequenceFlow == null) {
- continue;
- }
- //下面是找到了下个流程节点,需要进行正常的运行节点了
- FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement();
- if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态
- return null;
- }
- String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups();
- String setRurrRole = getSetRurrRole(candidateGroup);
- for (String s : ConstantFlowType.FLOW_ROLES_DEPT) {
- if (s.equals(setRurrRole)) {
- targetUser = this.getTargerUser_FLOW_ROLES_DEPT_PLUS(s, currUser);
- if (targetUser == null) {
- return null;
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- return startTask;
- }
- }
- for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) {
- if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.ROLES[i];
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(role,
- ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- targetUser = targetUserList.get(0);
- }
- if (targetUser == null) {
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- return startTask;
- }
- }
- for (int i = 0; i < ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK[i].equals(setRurrRole)) {
- //查看谁是对应角色并查找对应的人
- String role = ConstantFlowType.PURCHASE_ROLES_CHECK[i];
- List<FrameUser> targetUserList = flowMainService.findFrameUsersByRoleKeyAndGroup(role,
- ConstantFlowType.ROLETYPE, currUser.getGroupId());
- if (!targetUserList.isEmpty()) {
- targetUser = targetUserList.get(0);
- }
- if (targetUser == null) {
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- return startTask;
- }
- }
- return null;
- }
- return null;
- }
- } else if (nodeNum > 1) {
- // 2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- // 需要进行循环审核过程
- boolean isZhuYaoLingDao= "flow_zyld".equals(currRole);
- if(isZhuYaoLingDao) {
- targetUser = currUser;
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- if (!startTask.isEmpty()) {
- {
- List<Task> list = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象
- .taskAssignee(targetUser.getId())//指定个人任务查询
- .list();
- if (list == null || list.isEmpty()) {
- return null;
- }
- //2.1通过flow_id和targetUser获取下一个UserTask
- Task task = list.get(0);
- //task是当前流程的信息
- //如果发现task对应的角色就是自己的角色,就开始正常的走
- //如果发现task对应的角色还不是,就需要再进行设置自己的操作
- String taskDefinitionKey = task.getTaskDefinitionKey();
- String flowId = userPosition.getUserTask().getId();
- if (flowId.equals(taskDefinitionKey)) {
- Map<String, String> donaturalTaskMap = this.donaturalTask(deploymentid, currUser, task,
- conditionMap);
- if (donaturalTaskMap == null) {
- return null;
- } else {
- return startTask;
- }
- } else {
- {//遍历对象
- Map<String, String> getNextFlowMap = getNextFlow(businessId, userPosition,
- deploymentid, currUser, conditionMap, task);
- if (getNextFlowMap == null) {
- return null;
- } else {
- if (null != getNextFlowMap.get("isEnd")) {
- startTask.put("isEnd", getNextFlowMap.get("isEnd"));
- }
- return startTask;
- }
- }
- }
- }
- } else {
- return null;
- }
- } else {
- if (currUser.getLeader()!=null) {
- targetUser = userService.selectByPrimaryKey(currUser.getLeader());
- }
- if (targetUser==null){
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- }
- startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser);
- if (!startTask.isEmpty()) {
- return startTask;
- } else {
- return null;
- }
- }
- } else {
- return null;
- }
- }
- }
- public Map<String, String> passToRunPurchaseTask(FlowMainPush flowMainPush, String deploymentid, String businessId,
- Map<String, Object> conditionMap)
- throws com.rockstar.flow.exception.FlowException {
- // 发起流程引擎操作 并查看下一节点的操作要求
- //0,如果是收纳且匹配上角色就正常流程审核,没有匹配上就返回null,异常错误 ok,
- //1. 如果当前角色是自己,就进行正常的审核流程 ok
- //2. 先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
- //当前审核人/委托人代表的用户id
- String myFrameUserId = this.getMyFrameUserId(flowMainPush);
- if (myFrameUserId == null) {
- return null;
- }
- //当前审核人/委托人代表的用户
- FrameUser myframeUser = frameUserService.selectByPrimaryKey(myFrameUserId);
- //根据任务id获取任务信息
- //当前任务流程
- Task task;
- {
- List<Task> taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId())
- .taskId(flowMainPush.getTaskId()).list();
- if (taskList == null || taskList.isEmpty()) {
- return null;
- }
- task = taskList.get(0);
- }
- //本节点的关键子 例如flow_cnjs_1_1_0-yes
- String pushUserKey = flowMainPush.getPushUserKey();
- //本节点的角色 例如cnjs
- String setRurrRole = getSetRurrRole(pushUserKey);
- //判断setRurrRole是不是出纳类的角色,如果是出纳的角色,就判断当前审核人是不是也是出纳,是就继续,不是就是异常错误,返回null
- //判断是否符合出纳类型的要求 ok
- {
- for (int i = 0; i < ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK.length; i++) {
- if (ConstantFlowType.PURCHASE_FLOW_ROLES_CHECK[i].equals(setRurrRole)) {
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- }
- }
- }
- {
- //当前审核人/委托人代表的用户角色(只判断了是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的)
- String currRole = this.getCurrRole(myframeUser);
- //没有获取到角色,直接对到admin那里
- if (!StringUtils.isNotEmpty(currRole)) {
- // 直接对到admin那里
- FrameUser targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- }
- //当发现this.getCurrRole(myframeUser);获取的角色是普通员工的时候,就知道他作为审核人只是直接上级,并不是领导,所以把角色调上一级
- if (currRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[0])) {
- currRole = ConstantFlowType.FLOW_ROLES_DEPT[1];
- }
- // 不是出纳的情况下进行的判断
- //1.如果当前角色是自己,就进行正常的审核流程 ok
- //2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
- if (setRurrRole.equals(currRole)) {//1.如果当前角色是自己,就进行正常的审核流程 ok
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap);
- } else {//2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
- FrameUser targetUser = null;
- UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid);
- // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上
- if (userPosition == null) {//没有找到数据
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- return null;
- }
- boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap);
- return new HashMap<>();
- } else {//找到userPosition数据录了
- //还不是自己的角色,还要遍历查找
- return getNextFlow(businessId, userPosition, deploymentid, myframeUser, conditionMap, task);
- }
- }
- }
- }
- }
|