Browse Source

流程引擎:load\save\submit

4.0
郑根木 2 years ago
parent
commit
bcb6eb735e
6 changed files with 91 additions and 35 deletions
  1. +54
    -28
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java
  2. +7
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java
  3. +3
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java
  4. +10
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java
  5. +12
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java
  6. +5
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java

+ 54
- 28
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java View File

@@ -43,9 +43,6 @@ public class FlowInstance {
//活动任务 //活动任务
private Task actInst; private Task actInst;


//操作类型 新增/编辑/查看
private int opt_mode = FlowConst.OperatorType.VIEW;

//流程执行变量 //流程执行变量
// public Map<String, String> variables = new HashMap<>(); // public Map<String, String> variables = new HashMap<>();


@@ -77,7 +74,7 @@ public class FlowInstance {
//能否编辑 //能否编辑
public boolean canEdit() { 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 true;
return false; return false;
} }
@@ -125,10 +122,9 @@ public class FlowInstance {
throw new BizException("对应的流程没有定义有效的活动步骤!"); throw new BizException("对应的流程没有定义有效的活动步骤!");
} }


opt_mode = FlowConst.OperatorType.NEW;

procInst = new ProcInst(); procInst = new ProcInst();
procInst.init(); procInst.init();
procInst.setIsNew(true);
procInst.setEntityId(DbEngine.getInstance().nextId()); procInst.setEntityId(DbEngine.getInstance().nextId());
procInst.setPartyId(loginParty.getEntityId()); procInst.setPartyId(loginParty.getEntityId());
procInst.setDeptId(loginDept.getEntityId()); procInst.setDeptId(loginDept.getEntityId());
@@ -180,6 +176,7 @@ public class FlowInstance {
getTaskDao().updateEntity(actInst); getTaskDao().updateEntity(actInst);
getProcInstDao().updateEntity(procInst); getProcInstDao().updateEntity(procInst);


updateComment(null, FlowConst.Button.HANDLE.value);
buildBillLog(FlowConst.Button.HANDLE.value, "-", actInst, null); buildBillLog(FlowConst.Button.HANDLE.value, "-", actInst, null);
listener.afterHandle(actInst); listener.afterHandle(actInst);
} }
@@ -240,7 +237,7 @@ public class FlowInstance {
*/ */
public List<Task> adjustTasks() { public List<Task> adjustTasks() {
List<Task> listTask = new ArrayList<>(); 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); listTask.add(actInst);
return listTask; return listTask;
} }
@@ -310,11 +307,11 @@ public class FlowInstance {


//启动流程 //启动流程
public void save() { public void save() {
if (opt_mode == FlowConst.OperatorType.NEW) {
if (procInst.isNew()) {
getProcInstDao().insertEntity(procInst); getProcInstDao().insertEntity(procInst);
getTaskDao().insertEntity(actInst); getTaskDao().insertEntity(actInst);
getCommentDao().insertEntity(createComment(actInst));
buildBillLog(FlowConst.Button.ADD.value, "-", null, null); buildBillLog(FlowConst.Button.ADD.value, "-", null, null);
opt_mode = FlowConst.OperatorType.EDIT;
} else { } else {
getProcInstDao().updateEntity(procInst); getProcInstDao().updateEntity(procInst);
if (actInst != null) { if (actInst != null) {
@@ -538,7 +535,7 @@ public class FlowInstance {
* *
* @throws Exception * @throws Exception
*/ */
public void submit() {
public void submit(String comment) {
long user_id = us.getUserId(); long user_id = us.getUserId();
//校验权限,当前人员有权限干不,没权限直接抛异常 //校验权限,当前人员有权限干不,没权限直接抛异常
checkPermission(); checkPermission();
@@ -555,11 +552,12 @@ public class FlowInstance {
//待新增任务 //待新增任务
List<Task> listInsertTask = new ArrayList<>(); List<Task> listInsertTask = new ArrayList<>();
List<TaskRel> listTaskRel = new ArrayList<>(); List<TaskRel> listTaskRel = new ArrayList<>();
List<Comment> listTaskComment = new ArrayList<>();
//待新增任务候选人 //待新增任务候选人
List<Candidate> listInsertCand = new ArrayList<>(); List<Candidate> listInsertCand = new ArrayList<>();


for (Activity act : new_acts) { for (Activity act : new_acts) {
buildTask(act, listInsertTask, listInsertCand, listTaskRel, user_id);
buildTask(act, listInsertTask, listInsertCand, listTaskRel, listTaskComment);
} }


actInst.setHandler(user_id); actInst.setHandler(user_id);
@@ -585,28 +583,19 @@ public class FlowInstance {
getTaskDao().batchInsertEntity(listInsertTask); getTaskDao().batchInsertEntity(listInsertTask);
getCandidateDao().batchInsertEntity(listInsertCand); getCandidateDao().batchInsertEntity(listInsertCand);
getTaskRelDao().batchInsertEntity(listTaskRel); getTaskRelDao().batchInsertEntity(listTaskRel);

if (!listTaskComment.isEmpty()) {
getCommentDao().batchInsertEntity(listTaskComment);
}
} }
getTaskDao().updateEntity(actInst); getTaskDao().updateEntity(actInst);
getProcInstDao().updateEntity(procInst); 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); 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 * @param listTaskRel
* @throws Exception * @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(); Task task = new Task();
listInsertTask.add(task); listInsertTask.add(task);
task.init(); task.init();
@@ -699,6 +688,9 @@ public class FlowInstance {
if (CommUtil.isEmpty(listInsertCand)) { if (CommUtil.isEmpty(listInsertCand)) {
throw new BizException("没有符合条件的主办人!" + act.getLabel()); throw new BizException("没有符合条件的主办人!" + act.getLabel());
} }

//创建新的审批意见
listTaskComment.add(createComment(task));
} }
} }


@@ -902,9 +894,43 @@ public class FlowInstance {
flowLog.setInfo("-"); flowLog.setInfo("-");
} }
DbEngine.getInstance().findDao(FlowLog.class).insertEntity(flowLog); 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() { private EntityDao<ProcInst> getProcInstDao() {
return DbEngine.getInstance().findDao(ProcInst.class); return DbEngine.getInstance().findDao(ProcInst.class);
} }


+ 7
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java View File

@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.db.EntityHelper; import cc.smtweb.framework.core.db.EntityHelper;
import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.mvc.service.AbstractCompProvider; import cc.smtweb.framework.core.mvc.service.AbstractCompProvider;
import cc.smtweb.framework.core.mvc.service.IDataProvider;
import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.CommUtil;
import cc.smtweb.system.bpm.web.design.flow.FlowConst; import cc.smtweb.system.bpm.web.design.flow.FlowConst;
@@ -102,6 +103,11 @@ public class FlowProvider extends AbstractCompProvider {
} }


public List<Comment> findComment(long bill_id) { public List<Comment> findComment(long bill_id) {
return DbEngine.getInstance().findDao(Comment.class).queryWhere(" cmt_pri_id=? order by cmt_end_time", bill_id);
return doGetData("cp_" + bill_id, () -> DbEngine.getInstance().findDao(Comment.class).queryWhere(" cmt_pri_id=? and cmt_statu>? order by cmt_end_time", bill_id, FlowConst.ActivityStatu.WAIT.value));

}

public Comment findTaskComment(long task_id) {
return doGetData("ct_" + task_id, () -> DbEngine.getInstance().findDao(Comment.class).queryEntityWhere(" cmt_tsk_id=?", task_id));
} }
} }

+ 3
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java View File

@@ -44,12 +44,12 @@ public class Comment extends DefaultEntity {
put("cmt_tsk_id", cmt_tsk_id); put("cmt_tsk_id", cmt_tsk_id);
} }
/** 活动id */ /** 活动id */
public long getActId() {
return getLong("cmt_act_id");
public String getActId() {
return getStr("cmt_act_id");
} }


/** 活动id */ /** 活动id */
public void setActId(long cmt_act_id) {
public void setActId(String cmt_act_id) {
put("cmt_act_id", cmt_act_id); put("cmt_act_id", cmt_act_id);
} }
/** 活动名 */ /** 活动名 */


+ 10
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java View File

@@ -4,7 +4,9 @@ import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean;
import cc.smtweb.system.bpm.web.engine.flow.FlowHelper; import cc.smtweb.system.bpm.web.engine.flow.FlowHelper;
import cc.smtweb.system.bpm.web.engine.flow.FlowInstance; import cc.smtweb.system.bpm.web.engine.flow.FlowInstance;
import cc.smtweb.system.bpm.web.engine.flow.FlowListener; import cc.smtweb.system.bpm.web.engine.flow.FlowListener;
@@ -35,6 +37,7 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
flowInstance = FlowInstance.createById(us,this, id, taskId); flowInstance = FlowInstance.createById(us,this, id, taskId);
} }
flowInstance.readFromPage(data); flowInstance.readFromPage(data);
flowInstance.getProcInst().setIsNew(bean.isNew());
flowInstance.setBillInfo(getBillCode(), getBillInfo(), getBillUrl()); flowInstance.setBillInfo(getBillCode(), getBillInfo(), getBillUrl());
return bean; return bean;
} }
@@ -45,6 +48,13 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
flowInstance.save(); flowInstance.save();
} }


@Override
protected void afterSave(SwMap ret, T bean) {
super.afterSave(ret, bean);
ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst()));
ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.EMPTY));
}

//单据编号 //单据编号
protected String getBillCode() { protected String getBillCode() {
return ""; return "";


+ 12
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java View File

@@ -2,7 +2,10 @@ package cc.smtweb.system.bpm.web.engine.model.flow.listcard.single;


import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler; import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean;
import cc.smtweb.system.bpm.web.engine.flow.FlowHelper;
import cc.smtweb.system.bpm.web.engine.flow.FlowInstance; import cc.smtweb.system.bpm.web.engine.flow.FlowInstance;
import cc.smtweb.system.bpm.web.engine.flow.FlowListener; import cc.smtweb.system.bpm.web.engine.flow.FlowListener;
import cc.smtweb.system.bpm.web.engine.flow.entity.Task; import cc.smtweb.system.bpm.web.engine.flow.entity.Task;
@@ -28,10 +31,17 @@ public class FlowTransHandler extends AbstractDynPageHandler implements FlowList
} }
} }


private SwMap buildRetData() {
SwMap ret = new SwMap();
ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst()));
ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.EMPTY));
return ret;
}

public R submit() { public R submit() {
loadFlowInstance(); loadFlowInstance();
flowInstance.submit();
return R.success();
flowInstance.submit(params.readString("comment"));
return R.success(buildRetData());
} }




+ 5
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java View File

@@ -71,9 +71,13 @@ public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPag
} }
}); });
bean.removeStatus(); bean.removeStatus();
return R.success(LCSingleHelper.buildRetData(pageDataSet.name, bean.getData()));
SwMap ret = LCSingleHelper.buildRetData(pageDataSet.name, bean.getData());
afterSave(ret, bean);
return R.success(ret);
} }


protected void afterSave(SwMap ret, T bean) {}

/** /**
* 从页面获取待保存的bean * 从页面获取待保存的bean
* *


Loading…
Cancel
Save