@@ -43,9 +43,6 @@ public class FlowInstance {
//活动任务
private Task actInst;
//操作类型 新增/编辑/查看
private int opt_mode = FlowConst.OperatorType.VIEW;
//流程执行变量
// public Map<String, String> variables = new HashMap<>();
@@ -77,7 +74,7 @@ public class FlowInstance {
//能否编辑
public boolean canEdit() {
//新增状态可以编辑
if (opt_mode == FlowConst.OperatorType.NEW || procInst.getStatu() == FlowConst.InstanceStatu.BEGIN.value)
if (procDef.isNew() || procInst.getStatu() == FlowConst.InstanceStatu.BEGIN.value)
return true;
return false;
}
@@ -125,10 +122,9 @@ public class FlowInstance {
throw new BizException("对应的流程没有定义有效的活动步骤!");
}
opt_mode = FlowConst.OperatorType.NEW;
procInst = new ProcInst();
procInst.init();
procInst.setIsNew(true);
procInst.setEntityId(DbEngine.getInstance().nextId());
procInst.setPartyId(loginParty.getEntityId());
procInst.setDeptId(loginDept.getEntityId());
@@ -180,6 +176,7 @@ public class FlowInstance {
getTaskDao().updateEntity(actInst);
getProcInstDao().updateEntity(procInst);
updateComment(null, FlowConst.Button.HANDLE.value);
buildBillLog(FlowConst.Button.HANDLE.value, "-", actInst, null);
listener.afterHandle(actInst);
}
@@ -240,7 +237,7 @@ public class FlowInstance {
*/
public List<Task> adjustTasks() {
List<Task> listTask = new ArrayList<>();
if (opt_mode == FlowConst.OperatorType.NEW || procInst.getStatu() == FlowConst.InstanceStatu.DISUSE.value) {
if (procInst.isNew() || procInst.getStatu() == FlowConst.InstanceStatu.DISUSE.value) {
listTask.add(actInst);
return listTask;
}
@@ -310,11 +307,11 @@ public class FlowInstance {
//启动流程
public void save() {
if (opt_mode == FlowConst.OperatorType.NEW ) {
if (procInst.isNew() ) {
getProcInstDao().insertEntity(procInst);
getTaskDao().insertEntity(actInst);
getCommentDao().insertEntity(createComment(actInst));
buildBillLog(FlowConst.Button.ADD.value, "-", null, null);
opt_mode = FlowConst.OperatorType.EDIT;
} else {
getProcInstDao().updateEntity(procInst);
if (actInst != null) {
@@ -538,7 +535,7 @@ public class FlowInstance {
*
* @throws Exception
*/
public void submit() {
public void submit(String comment ) {
long user_id = us.getUserId();
//校验权限,当前人员有权限干不,没权限直接抛异常
checkPermission();
@@ -555,11 +552,12 @@ public class FlowInstance {
//待新增任务
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(act, listInsertTask, listInsertCand, listTaskRel, listTaskComment );
}
actInst.setHandler(user_id);
@@ -585,28 +583,19 @@ public class FlowInstance {
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);
updateComment(comment, FlowConst.Button.SUBMIT.value);
buildBillLog(FlowConst.Button.SUBMIT.value, comment, actInst, listInsertTask);
listener.afterSubmit(actInst, listInsertTask);
}
public void checkSubmit() {
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("您不是当前任务的办理人,不允许提交");
}
//comp.checkSubmit(FlowConst.FlowOptType.SUBMIT.value, actInst);
}
/**
* 作废
*
@@ -646,7 +635,7 @@ public class FlowInstance {
* @param listTaskRel
* @throws Exception
*/
private void buildTask(Activity act, List<Task> listInsertTask, List<Candidate> listInsertCand, List<TaskRel> listTaskRel, long submit_user ) {
private void buildTask(Activity act, List<Task> listInsertTask, List<Candidate> listInsertCand, List<TaskRel> listTaskRel, List<Comment> listTaskComment ) {
Task task = new Task();
listInsertTask.add(task);
task.init();
@@ -699,6 +688,9 @@ public class FlowInstance {
if (CommUtil.isEmpty(listInsertCand)) {
throw new BizException("没有符合条件的主办人!" + act.getLabel());
}
//创建新的审批意见
listTaskComment.add(createComment(task));
}
}
@@ -902,9 +894,43 @@ public class FlowInstance {
flowLog.setInfo("-");
}
DbEngine.getInstance().findDao(FlowLog.class).insertEntity(flowLog);
}
/**
* 构建新的审批信息,制单或首次保存、提交创建新任务时创建
*/
protected Comment createComment(Task task) {
ProcInfo procInfo = procDef.getProcInfo();
Comment bean = new Comment();
bean.setId(DbEngine.getInstance().nextId());
bean.setPriId(procInst.getId());
bean.setTskId(task.getId());
bean.setActId(task.getActId());
bean.setActName(procInfo.getActNameById(task.getActId()));
bean.setStartTime(DateUtil.nowDateTimeLong());
bean.setStatu(FlowConst.ActivityStatu.WAIT.value);
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)) {
bean.setStatu(FlowConst.ActivityStatu.SUBMIT.value);
bean.setEndTime(DateUtil.nowDateTimeLong());
bean.setComment(comment);
}
getCommentDao().updateEntity(bean);
}
private EntityDao<ProcInst> getProcInstDao() {
return DbEngine.getInstance().findDao(ProcInst.class);
}