|
|
@@ -9,6 +9,7 @@ import cc.smtweb.framework.core.exception.SwException; |
|
|
|
import cc.smtweb.framework.core.session.UserSession; |
|
|
|
import cc.smtweb.framework.core.util.CommUtil; |
|
|
|
import cc.smtweb.framework.core.util.DateUtil; |
|
|
|
import cc.smtweb.framework.core.util.MathUtil; |
|
|
|
import cc.smtweb.framework.core.util.NumberUtil; |
|
|
|
import cc.smtweb.system.bpm.web.design.flow.FlowConst; |
|
|
|
import cc.smtweb.system.bpm.web.design.flow.ModelProc; |
|
|
@@ -157,7 +158,7 @@ public class FlowInstance { |
|
|
|
* |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void handler() { |
|
|
|
public void handle() { |
|
|
|
long user_id = us.getUserId(); |
|
|
|
//校验权限,当前人员有权限干不,没权限直接抛异常 |
|
|
|
// checkPermission(); |
|
|
@@ -341,7 +342,7 @@ public class FlowInstance { |
|
|
|
* 返回页面前的设置 |
|
|
|
*/ |
|
|
|
public void setPageRetExtra(SwMap ret) { |
|
|
|
SwMap extra = ret.computeMapIfAbsent("extra", k->new SwMap()); |
|
|
|
SwMap extra = ret.computeMapIfAbsent("extra", k -> new SwMap()); |
|
|
|
|
|
|
|
List<Task> listTask = adjustTasks(); |
|
|
|
//可选步骤 |
|
|
@@ -361,6 +362,36 @@ public class FlowInstance { |
|
|
|
index++; |
|
|
|
} |
|
|
|
extra.put("tasks", tasks); |
|
|
|
|
|
|
|
//前置动作 |
|
|
|
if (!actInst.isMake()) { |
|
|
|
//前置动作 |
|
|
|
listTask = provider.findBeforeTasks(actInst.getId()); |
|
|
|
if (CommUtil.isEmpty(listTask)) throw new SwException("未发现前置动作!"); |
|
|
|
List<SwMap> bTasks = new ArrayList<>(); |
|
|
|
boolean hasMake = false; |
|
|
|
for (Task act : listTask) { |
|
|
|
SwMap row = new SwMap(); |
|
|
|
tasks.add(row); |
|
|
|
row.put("id", act.getId()); |
|
|
|
row.put("label", procDef.getProcInfo().getActNameById(act.getActId())); |
|
|
|
if (act.isMake()) { |
|
|
|
row.put("type", 0); |
|
|
|
hasMake = true; |
|
|
|
} else { |
|
|
|
row.put("type", 1); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!hasMake && procDef.getProcInfo().isRejectToMake()) { |
|
|
|
SwMap row = new SwMap(); |
|
|
|
tasks.add(0, row); |
|
|
|
Task act = provider.findMakeTask(procInst.getId()); |
|
|
|
row.put("id", act.getId()); |
|
|
|
row.put("label", procDef.getProcInfo().getActNameById(act.getActId())); |
|
|
|
row.put("type", 0); |
|
|
|
} |
|
|
|
} |
|
|
|
extra.put("preTasks", tasks); |
|
|
|
resetButtons(); |
|
|
|
} |
|
|
|
|
|
|
@@ -476,7 +507,10 @@ public class FlowInstance { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*public void submitToEnd() { |
|
|
|
/** |
|
|
|
* 中止,不通过 |
|
|
|
*/ |
|
|
|
public void interrupt(String comment) { |
|
|
|
long user_id = us.getUserId(); |
|
|
|
//校验权限,当前人员有权限干不,没权限直接抛异常 |
|
|
|
checkPermission(); |
|
|
@@ -488,51 +522,53 @@ public class FlowInstance { |
|
|
|
throw new BizException("您不是当前任务的办理人,不允许提交"); |
|
|
|
} |
|
|
|
//校验完毕,接下来干活。 |
|
|
|
List<Activity> new_acts = procDef.getProcInfo().findEndActivity(); |
|
|
|
if (CommUtil.isEmpty(new_acts)) { |
|
|
|
throw new BizException("结束任务为空,不允许提交到结束!"); |
|
|
|
} |
|
|
|
List<Activity> new_acts = getProcDef().getProcInfo().findEndActivity(); |
|
|
|
if (CommUtil.isEmpty(new_acts)) throw new SwException("该流程无结束节点!"); |
|
|
|
|
|
|
|
//待新增任务 |
|
|
|
List<Task> listInsertTask = new ArrayList<>(); |
|
|
|
List<TaskRel> listTaskRel = new ArrayList<>(); |
|
|
|
List<Comment> listTaskComment = new ArrayList<>(); |
|
|
|
//待新增任务候选人 |
|
|
|
List<Candidate> listInsertCand = new ArrayList<>(); |
|
|
|
|
|
|
|
for (Activity act : new_acts) { |
|
|
|
buildTask(act, listInsertTask, listInsertCand, listTaskRel, user_id); |
|
|
|
} |
|
|
|
//只要一个就行 |
|
|
|
buildTask(new_acts.get(0), listInsertTask, listInsertCand, listTaskRel, listTaskComment); |
|
|
|
|
|
|
|
actInst.setHandler(user_id); |
|
|
|
actInst.setStartTime(DateUtil.nowDateTimeLong()); |
|
|
|
actInst.setStatu(FlowConst.ActivityStatu.SUBMIT.value); |
|
|
|
actInst.setRetake(true); |
|
|
|
actInst.setStatu(FlowConst.ActivityStatu.INTERRUPT.value); |
|
|
|
actInst.setRetake(false); |
|
|
|
|
|
|
|
if (listInsertTask.size() > 0) { |
|
|
|
procInst.setTaskId(listInsertTask.get(0).getEntityId()); |
|
|
|
procInst.setActName(listInsertTask.get(0).getActName()); |
|
|
|
} else { |
|
|
|
procInst.setTaskId(actInst.getEntityId()); |
|
|
|
procInst.setActName(actInst.getActName()); |
|
|
|
} |
|
|
|
|
|
|
|
if (new_acts.size() == 1 && new_acts.get(0).getType() == FlowConst.ActivityType.END.value) { |
|
|
|
procInst.setStatu(FlowConst.InstanceStatu.FINISH.value); |
|
|
|
procInst.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
} else { |
|
|
|
procInst.setStatu(FlowConst.InstanceStatu.RUNING.value); |
|
|
|
} |
|
|
|
|
|
|
|
procInst.setStatu(FlowConst.InstanceStatu.INTERRUPT.value); |
|
|
|
procInst.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
|
|
|
|
//保存入库 |
|
|
|
if (!listInsertTask.isEmpty()) { |
|
|
|
getTaskDao().batchInsertEntity(listInsertTask); |
|
|
|
getCandidateDao().batchInsertEntity(listInsertCand); |
|
|
|
getTaskRelDao().batchInsertEntity(listTaskRel); |
|
|
|
|
|
|
|
if (!listTaskComment.isEmpty()) { |
|
|
|
getCommentDao().batchInsertEntity(listTaskComment); |
|
|
|
} |
|
|
|
} |
|
|
|
getTaskDao().updateEntity(actInst); |
|
|
|
getProcInstDao().updateEntity(procInst); |
|
|
|
|
|
|
|
buildBillLog(FlowConst.Button.SUBMIT.value, "TODO", actInst, listInsertTask); |
|
|
|
listener.submit(actInst, listInsertTask); |
|
|
|
}*/ |
|
|
|
updateComment(comment, FlowConst.Button.INTERRUPT.value); |
|
|
|
buildBillLog(FlowConst.Button.INTERRUPT.value, comment, actInst, listInsertTask); |
|
|
|
listener.afterSubmit(actInst, listInsertTask); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@@ -608,7 +644,7 @@ public class FlowInstance { |
|
|
|
* |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void disuse() { |
|
|
|
public void disuse(String comment) { |
|
|
|
long user_id = us.getUserId(); |
|
|
|
//校验权限,当前人员有权限干不,没权限直接抛异常 |
|
|
|
checkPermission(); |
|
|
@@ -629,7 +665,8 @@ public class FlowInstance { |
|
|
|
getTaskDao().updateEntity(actInst); |
|
|
|
getProcInstDao().updateEntity(procInst); |
|
|
|
|
|
|
|
buildBillLog(FlowConst.Button.DISUSE.value, "TODO", actInst, null); |
|
|
|
updateComment(comment, FlowConst.Button.DISUSE.value); |
|
|
|
buildBillLog(FlowConst.Button.DISUSE.value, comment, actInst, null); |
|
|
|
listener.afterDisuse(actInst); |
|
|
|
} |
|
|
|
|
|
|
@@ -657,7 +694,7 @@ public class FlowInstance { |
|
|
|
task.setSign(false); |
|
|
|
task.setReject(false); |
|
|
|
task.setRetake(false); |
|
|
|
task.setIsAuto(false); |
|
|
|
task.setAuto(false); |
|
|
|
|
|
|
|
TaskRel rel = new TaskRel(); |
|
|
|
rel.setEntityId(DbEngine.getInstance().nextId()); |
|
|
@@ -764,7 +801,7 @@ public class FlowInstance { |
|
|
|
|
|
|
|
taskDao.updateEntity(actInst); |
|
|
|
taskDao.batchDelete(new_acts); |
|
|
|
getCommentDao().deleteEntity("where cmt_tsk_id in ("+ EntityHelper.getSqlInIds(new_acts) + ")"); |
|
|
|
getCommentDao().deleteEntity("where cmt_tsk_id in (" + EntityHelper.getSqlInIds(new_acts) + ")"); |
|
|
|
getTaskRelDao().deleteEntity("where trl_src_task_id=?", actInst.getEntityId()); |
|
|
|
getProcInstDao().updateEntity(procInst); |
|
|
|
|
|
|
@@ -779,7 +816,95 @@ public class FlowInstance { |
|
|
|
* |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void reject() { |
|
|
|
public void reject(String comment, String toTasks) { |
|
|
|
if (StringUtils.isEmpty(toTasks)) { |
|
|
|
throw new BizException("未指定驳回的目标步骤!"); |
|
|
|
} |
|
|
|
String[] dstTasks = toTasks.split(","); |
|
|
|
if (dstTasks.length == 0) throw new BizException("未指定驳回的目标步骤!"); |
|
|
|
|
|
|
|
long user_id = us.getUserId(); |
|
|
|
//校验权限,当前人员有权限干不,没权限直接抛异常 |
|
|
|
checkPermission(); |
|
|
|
if (actInst.getStatu() == FlowConst.ActivityStatu.SUBMIT.value) { |
|
|
|
throw new BizException("当前任务已经提交,不能驳回!"); |
|
|
|
} |
|
|
|
|
|
|
|
if (actInst.getStatu() == FlowConst.ActivityStatu.WAIT.value && !FlowHelper.isMyWaitedTask(actInst.getEntityId(), user_id)) { |
|
|
|
throw new BizException("您不是当前任务的办理人,不允许驳回!"); |
|
|
|
} |
|
|
|
|
|
|
|
//待新增任务 |
|
|
|
List<Task> listInsertTask = new ArrayList<>(); |
|
|
|
List<TaskRel> listTaskRel = new ArrayList<>(); |
|
|
|
List<Comment> listTaskComment = new ArrayList<>(); |
|
|
|
//待新增任务候选人 |
|
|
|
List<Candidate> listInsertCand = new ArrayList<>(); |
|
|
|
|
|
|
|
//校验完毕,接下来干活。 |
|
|
|
//并发考虑:找到此任务的前置任务,创建对应的新任务,原流程其他未办理任务删除,办理中及已提交的,置为 |
|
|
|
for (String dstTaskId : dstTasks) { |
|
|
|
//rejectTo(comment, NumberUtil.getLongIgnoreErr(dstTaskId), listInsertTask, listTaskRel, listTaskComment, listInsertCand); |
|
|
|
long toTaskId = NumberUtil.getLongIgnoreErr(dstTaskId); |
|
|
|
Task toTask = provider.findTask(toTaskId); |
|
|
|
if (toTask == null) throw new SwException("没有找到驳回目标节点(" + toTaskId + ")!"); |
|
|
|
|
|
|
|
buildRejectTask(toTask, listInsertTask, listInsertCand, listTaskRel, listTaskComment); |
|
|
|
} |
|
|
|
//先停止其他待办或办理中的任务 |
|
|
|
FlowHelper.stopTask(procInst.getId()); |
|
|
|
//保存入库 |
|
|
|
if (!listInsertTask.isEmpty()) { |
|
|
|
getTaskDao().batchInsertEntity(listInsertTask); |
|
|
|
getCandidateDao().batchInsertEntity(listInsertCand); |
|
|
|
getTaskRelDao().batchInsertEntity(listTaskRel); |
|
|
|
|
|
|
|
if (!listTaskComment.isEmpty()) { |
|
|
|
getCommentDao().batchInsertEntity(listTaskComment); |
|
|
|
} |
|
|
|
} |
|
|
|
getTaskDao().updateEntity(actInst); |
|
|
|
getProcInstDao().updateEntity(procInst); |
|
|
|
|
|
|
|
updateComment(comment, FlowConst.Button.REJECT.value); |
|
|
|
buildBillLog(FlowConst.Button.SUBMIT.value, comment, actInst, listInsertTask); |
|
|
|
listener.afterSubmit(actInst, listInsertTask); |
|
|
|
} |
|
|
|
|
|
|
|
private void buildRejectTask(Task oldTask, List<Task> listInsertTask, List<Candidate> listInsertCand, List<TaskRel> listTaskRel, List<Comment> listTaskComment) { |
|
|
|
Task task = new Task(); |
|
|
|
listInsertTask.add(task); |
|
|
|
task.getData().putAll(oldTask.getData()); |
|
|
|
task.setEntityId(DbEngine.getInstance().nextId()); |
|
|
|
|
|
|
|
task.setStatu(FlowConst.ActivityStatu.WAIT.value); |
|
|
|
task.setReject(true); |
|
|
|
|
|
|
|
TaskRel rel = new TaskRel(); |
|
|
|
rel.setEntityId(DbEngine.getInstance().nextId()); |
|
|
|
rel.setPriId(task.getPriId()); |
|
|
|
rel.setDstTaskId(task.getId()); |
|
|
|
rel.setSrcTaskId(actInst.getId()); |
|
|
|
listTaskRel.add(rel); |
|
|
|
|
|
|
|
Candidate cand = new Candidate(); |
|
|
|
cand.init(); |
|
|
|
cand.setEntityId(DbEngine.getInstance().nextId()); |
|
|
|
cand.setPriId(task.getPriId()); |
|
|
|
cand.setTskId(task.getId()); |
|
|
|
cand.setUserId(oldTask.getHandler()); |
|
|
|
|
|
|
|
listInsertCand.add(cand); |
|
|
|
|
|
|
|
//创建新的审批意见 |
|
|
|
listTaskComment.add(createComment(task)); |
|
|
|
} |
|
|
|
|
|
|
|
private void rejectTo(String comment, long toTaskId, List<Task> listInsertTask, List<TaskRel> listTaskRel, List<Comment> listTaskComment, List<Candidate> listInsertCand) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void rejectEx(String comment) { |
|
|
|
long user_id = us.getUserId(); |
|
|
|
//校验权限,当前人员有权限干不,没权限直接抛异常 |
|
|
|
checkPermission(); |
|
|
@@ -787,7 +912,7 @@ public class FlowInstance { |
|
|
|
throw new BizException("当前任务已提交,不能驳回!"); |
|
|
|
} |
|
|
|
|
|
|
|
//获取前置任务,前置任务需要置为被驳回的办理状态,同时,前置任务的其他后置任务需要删除 |
|
|
|
//获取前置任务,前置任务需要置为被驳回的办理状态,为保证流程信息,复制一份,作为新建任务处理 |
|
|
|
List<Task> new_acts = provider.findBeforeTasks(actInst.getEntityId()); |
|
|
|
if (CommUtil.isEmpty(new_acts)) { |
|
|
|
throw new BizException("没有找到前续任务,驳回失败!"); |
|
|
@@ -819,7 +944,7 @@ public class FlowInstance { |
|
|
|
getTaskRelDao().deleteEntity("where trl_src_task_id in (" + sqlIn.substring(1) + ")"); |
|
|
|
getProcInstDao().updateEntity(procInst); |
|
|
|
|
|
|
|
buildBillLog(FlowConst.Button.REJECT.value, "TODO", actInst, new_acts); |
|
|
|
buildBillLog(FlowConst.Button.REJECT.value, comment, actInst, new_acts); |
|
|
|
listener.afterReject(actInst, new_acts); |
|
|
|
// comp.transCallback(FlowConst.FlowOptType.REJECT.value, actInst, new_acts); |
|
|
|
} |
|
|
@@ -928,35 +1053,6 @@ public class FlowInstance { |
|
|
|
return bean; |
|
|
|
} |
|
|
|
|
|
|
|
protected void updateComment(String comment, String optType) { |
|
|
|
Comment bean = provider.findTaskComment(actInst.getId()); |
|
|
|
if (bean == null) throw new SwException("没有找到对应的记录(comment)!"); |
|
|
|
//签收 |
|
|
|
if (FlowConst.Button.HANDLE.value.equals(optType)) { |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.HANDLE.value); |
|
|
|
bean.setHandler(us.getUserId()); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
} else if (FlowConst.Button.SUBMIT.value.equals(optType)) { |
|
|
|
if (bean.getHandlerTime() <= 0L) { |
|
|
|
bean.setHandler(us.getUserId()); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
} |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.SUBMIT.value); |
|
|
|
bean.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setComment(comment); |
|
|
|
} else if (FlowConst.Button.RETAKE.value.equals(optType)) { |
|
|
|
if (bean.getHandlerTime() <= 0L) { |
|
|
|
bean.setHandler(us.getUserId()); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
} |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.HANDLE.value); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setEndTime(0L); |
|
|
|
} |
|
|
|
getCommentDao().updateEntity(bean); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private EntityDao<ProcInst> getProcInstDao() { |
|
|
|
return DbEngine.getInstance().findDao(ProcInst.class); |
|
|
|
} |
|
|
@@ -984,4 +1080,68 @@ public class FlowInstance { |
|
|
|
private EntityDao<TaskRel> getTaskRelDao() { |
|
|
|
return DbEngine.getInstance().findDao(TaskRel.class); |
|
|
|
} |
|
|
|
|
|
|
|
interface ICommentWorker { |
|
|
|
void work(Comment bean, String comment, long userId); |
|
|
|
} |
|
|
|
|
|
|
|
private static Map<String, ICommentWorker> mapComment; |
|
|
|
|
|
|
|
static { |
|
|
|
mapComment = new HashMap<>(); |
|
|
|
mapComment.put(FlowConst.Button.HANDLE.value, (bean, comment, userId) -> { |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.HANDLE.value); |
|
|
|
bean.setHandler(userId); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
}); |
|
|
|
mapComment.put(FlowConst.Button.SUBMIT.value, (bean, comment, userId) -> { |
|
|
|
checkHandler(bean, userId); |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.SUBMIT.value); |
|
|
|
bean.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setComment(comment); |
|
|
|
}); |
|
|
|
mapComment.put(FlowConst.Button.RETAKE.value, (bean, comment, userId) -> { |
|
|
|
checkHandler(bean, userId); |
|
|
|
|
|
|
|
bean.setStatu(FlowConst.ActivityStatu.HANDLE.value); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setEndTime(0L); |
|
|
|
}); |
|
|
|
mapComment.put(FlowConst.Button.REJECT.value, (bean, comment, userId) -> { |
|
|
|
checkHandler(bean, userId); |
|
|
|
|
|
|
|
bean.setStatu(FlowConst.ActivityStatu.REJECT.value); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setComment(comment); |
|
|
|
}); |
|
|
|
mapComment.put(FlowConst.Button.DISUSE.value, (bean, comment, userId) -> { |
|
|
|
checkHandler(bean, userId); |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.DISUSE.value); |
|
|
|
bean.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setComment(comment); |
|
|
|
}); |
|
|
|
mapComment.put(FlowConst.Button.INTERRUPT.value, (bean, comment, userId) -> { |
|
|
|
checkHandler(bean, userId); |
|
|
|
bean.setStatu(FlowConst.ActivityStatu.INTERRUPT.value); |
|
|
|
bean.setEndTime(DateUtil.nowDateTimeLong()); |
|
|
|
bean.setComment(comment); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private static void checkHandler(Comment bean, long userId) { |
|
|
|
if (bean.getHandlerTime() <= 0L) { |
|
|
|
bean.setHandler(userId); |
|
|
|
bean.setHandlerTime(DateUtil.nowDateTimeLong()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected void updateComment(String comment, String optType) { |
|
|
|
Comment bean = provider.findTaskComment(actInst.getId()); |
|
|
|
if (bean == null) throw new SwException("没有找到对应的记录(comment)!"); |
|
|
|
ICommentWorker worker = mapComment.get(optType); |
|
|
|
if (worker == null) throw new SwException("该类型(" + optType + ")没有实现审批意见!"); |
|
|
|
worker.work(bean, comment, us.getUserId()); |
|
|
|
getCommentDao().updateEntity(bean); |
|
|
|
} |
|
|
|
} |