123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409 |
- 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.FlowMain;
- import com.idea.oa.flow2.model.FlowMainPush;
- import com.idea.oa.flow2.service.FlowMainLogService;
- import com.idea.oa.flow2.service.FlowMainService;
- import com.rockstar.flow.dto.TaskDto;
- import com.rockstar.flow.service.FlowService;
- import com.rockstar.frame.model.FrameRoleData;
- import com.rockstar.frame.model.FrameUser;
- import com.rockstar.frame.service.FrameUserService;
- import com.rockstar.system.model.SysDept;
- import com.rockstar.system.model.SysDeptExample;
- import com.rockstar.system.service.SysDeptService;
- import com.rockstar.util.StringUtils;
- import org.activiti.bpmn.model.*;
- import org.activiti.engine.*;
- import org.activiti.engine.runtime.ProcessInstance;
- import org.activiti.engine.task.Task;
- import org.activiti.engine.task.TaskQuery;
- 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.*;
- @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
- RuntimeService runtimeService;
- //
- // @Autowired
- // private FramePostService postService;
- //
- @Autowired
- private SysDeptService sysDeptService;
- //
- //
- // @Autowired
- // private FrameUserDeptService frameUserDeptService;
- @Autowired
- private FrameUserService frameUserService;
- /**
- * 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,businessId);
- }
- }
- }
- {
- //当前审核人/委托人代表的用户角色(只判断了是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的)
- 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,businessId);
- }
- }
- //当发现this.getCurrRole(myframeUser);获取的角色是普通员工的时候,就知道他作为审核人只是直接上级,并不是领导,所以把角色调上一级
- if (currRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[0])) {
- currRole = ConstantFlowType.FLOW_ROLES_DEPT[1];
- }
- // 不是出纳的情况下进行的判断
- //1.如果当前角色是自己,就进行正常的审核流程 ok
- //2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok
- if ("dept_head".equals(setRurrRole) || "flow_sjfgld".equals(setRurrRole) || setRurrRole.equals(currRole)) {//1.如果当前角色是自己,就进行正常的审核流程 ok
- return this.donaturalTask(deploymentid, myframeUser, task, conditionMap,businessId);
- } 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, String businessId) 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,businessId);
- 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,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;
- // }
- return this.jumpNextNode(task2,deploymentid,currUser,setRurrRole,conditionMap,businessId);
- }
- 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,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<>();
- }
- }
- }
- 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;
- }
- }
- } else if (mycondition.contains("isProSales==")) {
- String isExchangeOnly = conditionMap.get("isProSales").toString();
- Double applyDay = Double.valueOf(conditionMap.get("preSales").toString());
- if (mycondition.contains("(isProSales=='no') or (preSales>=2000000)")) {
- if ("no".equals(isExchangeOnly) && applyDay >= 2000000) {
- isOk = true;
- }
- } else if (mycondition.contains("(isProSales=='yes') or (preSales<2000000)")) {
- if ("yes".equals(isExchangeOnly) || applyDay < 2000000) {
- isOk = true;
- }
- }
- }
- if (isOk) {
- isOkNum = isOkNum + 1;
- }
- }
- if (isOkNum == myconditionExpressions.size()) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 流程重新梳理 pany 2023/11/22
- * 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> startTask2(String processDefine, String deploymentid, String businessId, FrameUser currUser, Map<String, Object> conditionMap) throws com.rockstar.flow.exception.FlowException {
- // FrameUser targetUser = null;
- // List<UserTask> taskList = flowService.getTaskList(deploymentid);
- // for(UserTask userTask : taskList){
- // String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no
- // String setRurrRole = this.getSetRurrRole(s);
- // }
- //
- // }
- /**
- * 根据用户位置启动信息启动流程
- * 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,businessId);
- 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,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,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日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断
- 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,businessId);
- 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,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)||"_5".equals(taskDefinitionKey2)||"_7".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,businessId);
- } 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.getChangedBy();
- 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 {//部门主管是别人,自己不是部门主管
- //在用该用户作为部门负责人在部门表中再查一次,防止部门的负责人不在此部门中
- SysDeptExample sysDeptExample = new SysDeptExample();
- sysDeptExample.createCriteria().andChangedByLike(currUser.getId());
- List<SysDept> sysDepts = sysDeptService.selectByExample(sysDeptExample);
- if(CollectionUtils.isNotEmpty(sysDepts)){
- 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,String businessId) {
- FrameUser targetUser = null;
- FlowMain flowMain = flowMainService.selectByPrimaryKey(businessId);
- if(flowMain!=null){
- currUser = userService.selectByPrimaryKey(flowMain.getApplyUser());
- }
- if (targetRole.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;
- System.out.println("6没有找到对应人:" + "if (targetUser == null) {");
- targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID);
- if (targetUser == null) {
- System.err.println("异常,没有找到目标人");
- return null;
- }
- }
- return targetUser;
- }
- /**
- * 共用方法 //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管),
- * 但是注意,这只是判断是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的
- *
- * @param currUser
- * @return
- */
- public Boolean getHasCurrRole(FrameUser currUser) {
- //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管)
- String currRole = "";//flow_fgld", "flow_sjfgld", "flow_zyld或者curr_user,dept_head
- Boolean currRoleBo = false;
- {
- //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) {
- if(Arrays.asList(flow_roles).contains(frameRoleData.getRoleKey())){
- currRoleBo = true;
- }
- }
- if(currRoleBo)return currRoleBo;
- }
- //2获取用户部门是否是主管
- {
- String department = currUser.getDepartment();
- SysDept sysDept = sysDeptService.selectByPrimaryKey(department);
- if (sysDept == null) {//没有部门信息
- if (currRole.equals("")) {
- currRole = "";
- return currRoleBo;
- } else {
- //是领导流程类型
- }
- } else {
- String changedBy = sysDept.getChangedBy();
- if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管
- if (currRole.equals("")) {
- currRole = "";
- } else {
- //是领导流程类型
- }
- return currRoleBo;
- } else {//找到部门主管
- if (changedBy.equals(currUser.getId())) {//自己是部门主管
- if (currRole.equals("")) {
- currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head";
- } else {
- //是领导流程类型
- }
- } else {//部门主管是别人,自己不是部门主管
- //在用该用户作为部门负责人在部门表中再查一次,防止部门的负责人不在此部门中
- SysDeptExample sysDeptExample = new SysDeptExample();
- sysDeptExample.createCriteria().andChangedByLike(currUser.getId());
- List<SysDept> sysDepts = sysDeptService.selectByExample(sysDeptExample);
- if(CollectionUtils.isNotEmpty(sysDepts)){
- 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 currRoleBo;
- }
- /**
- * 当sourceTask 的审核人是空的话,跳过该任务节点
- * @param sourceTask 当前的任务节点
- * @param deploymentId 流程ID
- * @param currUser 当前操作人
- * @param currRole 当前角色
- * @param conditionMap
- * @param businessId flowMainId
- * @return
- * @throws com.rockstar.flow.exception.FlowException
- */
- public Map<String, String> jumpNextNode(Task sourceTask,String deploymentId,FrameUser currUser,String currRole, Map<String, Object> conditionMap, String businessId) throws com.rockstar.flow.exception.FlowException {
- List<UserTask> taskList = flowService.getTaskList(deploymentId);
- UserTask myuserTask2 = null;
- for (int i = 1; i < taskList.size(); i++) {
- 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(taskSetRurrRole.equals(currRole)){
- myuserTask2 = myuserTask;
- break;
- }
- }
- //跳过当前节点
- jumpToTask(sourceTask,myuserTask2.getId());
- //获取新节点
- Task task = null;
- {
- List<Task> taskList2 = taskService.createTaskQuery().processInstanceBusinessKey(businessId).list();
- if (taskList == null || taskList.isEmpty()) {
- return new HashMap<>();
- }
- task = taskList2.get(0);
- }
- //继续正常审核
- return donaturalTask(deploymentId,currUser,task,conditionMap,businessId);
- }
- private void jumpToTask(Task sourceTask,String targetTaskDefinitionKey){
- //取得当前节点的信息
- //取得指定节点的信息(TaskDefinitionKey)
- //保存当前节点的流向
- //新建流向,由当前节点指向新节点(指定节点)
- //当前节点完成任务=流向指定节点
- //将当前节点的流向还原
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
- RepositoryService repositoryService = processEngine.getRepositoryService();
- TaskService taskService = processEngine.getTaskService();
- //获取该工作流的bpmn模板
- BpmnModel bpmnModel = repositoryService.getBpmnModel(sourceTask.getProcessDefinitionId());
- // 获取当前活动节点
- FlowNode currentFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(sourceTask.getTaskDefinitionKey());
- // 获取指定活动节点
- FlowNode lastFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(targetTaskDefinitionKey);
- // 临时保存当前活动的原始方向 ,最后需要用到他恢复正确的方向
- List<SequenceFlow> originalSequenceFlowList = new ArrayList<>();
- originalSequenceFlowList.addAll(currentFlowNode.getOutgoingFlows());
- // 清理当前活动方向
- currentFlowNode.getOutgoingFlows().clear();
- // 建立新方向
- SequenceFlow newSequenceFlow = new SequenceFlow();
- newSequenceFlow.setId("newSequenceFlowId");//这个可以随机
- newSequenceFlow.setSourceFlowElement(currentFlowNode);//源
- newSequenceFlow.setTargetFlowElement(lastFlowNode);//目标
- List<SequenceFlow> newSequenceFlowList = new ArrayList<>();
- newSequenceFlowList.add(newSequenceFlow);
- // 当前节点指向新的方向
- currentFlowNode.setOutgoingFlows(newSequenceFlowList);
- // 完成当前任务 = 跳转到指定的节点任务
- taskService.complete(sourceTask.getId());
- // 恢复原始方向
- currentFlowNode.setOutgoingFlows(originalSequenceFlowList);
- }
- }
|