/** * Clear Current Awt, update Instance. Go next step: insert new Awt if needed. * * @param wfInst * @param optVO * @param nextTask */ private void clearAwtUpdateInstGoNextStep( WfInstance wfInst, TaskOptVO optVO, WfTask nextTask, String currUserId) { String optdUsers = wfInst.getOptUsersPre(); if (StringUtils.isEmpty(optdUsers)) { wfInst.setOptUsersPre(currUserId + ","); } else { if (!optdUsers.contains(currUserId)) { wfInst.setOptUsersPre(optdUsers + currUserId + ","); } } String instId = wfInst.getInstId(); WfAwt parm = new WfAwt(); parm.setInstId(instId); parm.setCompleteFlag(null); this.deleteSelective(parm); // create new awt(s) with next taskId String nextAssigners = optVO.getNextAssigners(); if (nextAssigners != null && !optVO.isNextEndTaskFlag()) { String[] nextAssignersArr = nextAssigners.split(","); WfAwt awt = null; Date beginDate = new Date(); Date limitDate = calculateDate(beginDate, nextTask.getTimeLimitTp(), nextTask.getTimeLimit()); Date alarmDate = nextTask.getAlarmTime() == null ? null : calculateDate(beginDate, nextTask.getAlarmTimeTp(), nextTask.getAlarmTime()); String optUsersPre = wfInst.getOptUsersPre(); if (optUsersPre != null && optUsersPre.indexOf(",") == optUsersPre.length() - 1) { optUsersPre = optUsersPre.substring(0, optUsersPre.length() - 1); } for (String assigner : nextAssignersArr) { if (!StringUtils.isEmpty(assigner)) { awt = new WfAwt(); /** 当任务流转到下一个节点,下一个节点的awt数据:设置optUsersPre&taskIdPre */ awt.setOptUsersPre(optUsersPre); awt.setTaskIdPre(wfInst.getTaskIdCurr()); awt.setAssignerId(assigner); awt.setAwtBegin(beginDate); awt.setAwtEnd(limitDate); awt.setAwtAlarm(alarmDate); awt.setInstId(instId); awt.setTaskIdCurr(optVO.getNextTaskId()); this.insert(awt); } } } /** 当事务流转到下一个节点时,重置currTaskid&optdUsers 为上一步操作人(可能是多个)和上一个任务节点 */ wfInst.setCurrAssigners(nextAssigners); wfInst.setTaskIdPre(wfInst.getTaskIdCurr()); wfInst.setTaskIdCurr(nextTask.getTaskId()); if (optVO.isNextEndTaskFlag()) { wfInst.setWfStatus(WFConstants.WFStatus.DONE); } instService.updateById(wfInst); }
private boolean renew4Forward(WfInstance wfInst, TaskOptVO optVO, String currUserId) throws BusinessException { WfAwt awtParm = new WfAwt(); awtParm.setInstId(wfInst.getInstId()); awtParm.setAssignerId(currUserId); WfAwt awt = this.selectOne(awtParm); if (awt == null) { log.error( "renew4Forward(): no awt found for instId=" + wfInst.getInstId() + ", currUserid=" + currUserId); return false; } String nextAssigners = optVO.getNextAssigners(); String currAssigners = wfInst.getCurrAssigners(); wfInst.setCurrAssigners(currAssigners.replace(currUserId + ",", nextAssigners + ",")); String optdUsers = wfInst.getOptUsersPre(); if (optdUsers != null && optdUsers.contains(currUserId)) { wfInst.setOptUsersPre(optdUsers.replace(currUserId + ",", "")); } instService.updateById(wfInst); String[] nextAssignerArray = nextAssigners.split(","); WfAwt awtNew = null; List<WfAwt> awtNewList = new ArrayList<WfAwt>(nextAssignerArray.length); try { for (String assinger : nextAssignerArray) { if (!StringUtils.isEmpty(assinger)) { awtParm.setAssignerId(assinger); awtNew = this.selectOne(awtParm); if (awtNew != null) { continue; } awtNew = awt.clone(); awtNew.setAssignerId(assinger); awtNew.setOptUsersPre(currUserId); awtNew.setTaskIdPre(awt.getTaskIdCurr()); awtNew.setWfAwtId(null); awtNewList.add(awtNew); } } } catch (CloneNotSupportedException e) { log.error("renew4Forward(): CloneNotSupportedException ", e); throw new BusinessException("Error when create Awt for forward task"); } this.deleteById(awt.getWfAwtId()); if (!awtNewList.isEmpty()) { this.insertBatch(awtNewList); } return false; }
private void removeUserFromOptUserPrev( WfInstance wfInst, String currUserId, String currTaskId, boolean refreshCurrAssigners) { String optdUsers = wfInst.getOptUsersPre(); if (optdUsers != null && optdUsers.contains(currUserId)) { wfInst.setOptUsersPre(optdUsers.replace(currUserId + ",", "")); } String currAssigners = wfInst.getCurrAssigners(); if (currAssigners == null || refreshCurrAssigners) { currAssigners = currUserId + ","; } else { currAssigners += currUserId; } wfInst.setCurrAssigners(currAssigners); wfInst.setTaskIdCurr(currTaskId); instService.updateById(wfInst); }
private void updateCurrAssigners4CS(WfInstance wfInst, String currUserId) { String optdUsers = wfInst.getOptUsersPre(); if (optdUsers == null) { optdUsers = currUserId + ","; } else { if (!optdUsers.contains(currUserId)) { optdUsers += currUserId + ","; } } /** 事务未流转,更新该task的处理人 */ wfInst.setOptUsersPre(optdUsers); String currAssigners4Inst = wfInst.getCurrAssigners(); if (currAssigners4Inst != null) { if (currAssigners4Inst.contains(currUserId + ",")) { wfInst.setCurrAssigners(currAssigners4Inst.replace(currUserId + ",", "")); instService.updateById(wfInst); // 更新当前处理人 wfInst.setCurrAssigners(currAssigners4Inst); } } }
private boolean renew4Commit(WfAwt prev, WfTask currtask, WfInstance wfInst, String currUserId) { String instId = prev.getInstId(); if (WFConstants.TxTypes.COUNTERSIGN.equals(currtask.getTxType())) { prev.setCompleteFlag("Y"); this.updateById(prev); WfAwt parm = new WfAwt(); parm.setInstId(instId); parm.setCompleteFlag("N"); int incompletedCount = this.selectCount(parm); if (incompletedCount == 0) { return true; // 没有未完成的待办事宜 } String csOptJson = currtask.getSignChoices(); JSONObject csOpt = (JSONObject) JSONObject.parse(csOptJson); parm.setCompleteFlag("Y"); int completedCount = this.selectCount(parm); if (Boolean.TRUE.toString().equals(csOpt.getString("AllHandledThenGo"))) { parm.setCompleteFlag(null); int allCount = this.selectCount(parm); if (allCount != completedCount) { updateCurrAssigners4CS(wfInst, currUserId); // not finished, return return false; } } else { if (Boolean.TRUE.toString().equals(csOpt.getString("PartHandledThenGo"))) { int AtLeastHandled = csOpt.getIntValue("AtLeastHandled"); if (AtLeastHandled == 0) { AtLeastHandled = 1; } if (completedCount < AtLeastHandled) { updateCurrAssigners4CS(wfInst, currUserId); return false; } } } } else { wfInst.setOptUsersPre(currUserId + ","); } return true; }