浏览代码

流程引擎:load\save\submit

4.0
郑根木 2 年前
父节点
当前提交
bcb6eb735e
共有 6 个文件被更改,包括 91 次插入35 次删除
  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 查看文件

@@ -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);
}


+ 7
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java 查看文件

@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.db.EntityHelper;
import cc.smtweb.framework.core.exception.BizException;
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.util.CommUtil;
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) {
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 查看文件

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

/** 活动id */
public void setActId(long cmt_act_id) {
public void setActId(String 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 查看文件

@@ -4,7 +4,9 @@ import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
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.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.FlowListener;
@@ -35,6 +37,7 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
flowInstance = FlowInstance.createById(us,this, id, taskId);
}
flowInstance.readFromPage(data);
flowInstance.getProcInst().setIsNew(bean.isNew());
flowInstance.setBillInfo(getBillCode(), getBillInfo(), getBillUrl());
return bean;
}
@@ -45,6 +48,13 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
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() {
return "";


+ 12
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java 查看文件

@@ -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.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.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.FlowListener;
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() {
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 查看文件

@@ -71,9 +71,13 @@ public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPag
}
});
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
*


正在加载...
取消
保存