Pārlūkot izejas kodu

流程引擎:load\save\submit;调整模型,以Bean方式处理

4.0
郑根木 pirms 2 gadiem
vecāks
revīzija
e6ddfb8fb6
8 mainītis faili ar 131 papildinājumiem un 63 dzēšanām
  1. +18
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java
  2. +26
    -15
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java
  3. +9
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/ProcInst.java
  4. +19
    -14
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/TaskRel.java
  5. +7
    -12
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java
  6. +10
    -5
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java
  7. +21
    -8
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java
  8. +21
    -9
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java

+ 18
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java Parādīt failu

@@ -1,11 +1,14 @@
package cc.smtweb.system.bpm.web.engine.dynPage;

import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityHelper;
import cc.smtweb.framework.core.db.cache.ModelTableCache;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.framework.core.mvc.service.AbstractCompProvider;
import cc.smtweb.framework.core.mvc.service.SqlNamedPara;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
@@ -34,5 +37,20 @@ public class DynPageProvider extends AbstractCompProvider {
});
}

public <T extends DefaultEntity> T loadBean(String tableName, long id) {
return doGetData(tableName + "." + id, () -> {
EntityDao<T> bdao = (EntityDao<T>) DbEngine.getInstance().findDao(tableName);
T bean = bdao.queryEntity(id);
if (bean == null) throw new BizException("没有找到指定数据(" + tableName + ".id=" + id + ")");
EntityHelper.loadBeanText(bean.getTableName(), bean.getData(), null);
return bean;
});
}

public <T extends DefaultEntity> T loadBean(PageDataset dataset, long id) {
ModelTable table = dataset.getModelTable();
if (table == null) throw new SwException("数据集主表未找到(" + dataset.name + ")!");
return loadBean(table.getName(), id);
}

}

+ 26
- 15
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java Parādīt failu

@@ -151,6 +151,7 @@ public class FlowInstance {
actInst.setRetake(false);

procInst.setTaskId(actInst.getEntityId());
procInst.setActName(actInst.getActName());
}

/**
@@ -171,6 +172,7 @@ public class FlowInstance {
actInst.setStatu(FlowConst.ActivityStatu.HANDLE.value);

procInst.setTaskId(actInst.getEntityId());
procInst.setActName(actInst.getActName());
procInst.setStatu(FlowConst.InstanceStatu.RUNING.value);

getTaskDao().updateEntity(actInst);
@@ -197,8 +199,9 @@ public class FlowInstance {
public void load(long bill_id, long task_id) {
procInst = provider.findProcInst(bill_id);
procDef = ModelProcHelper.getFromCache(procInst.getPrcId());
actInst = null;
task_id = getTaskId(task_id);
if (task_id > 0L) {
if (task_id > 0L && actInst == null) {
actInst = provider.findTask(task_id);
}
}
@@ -217,12 +220,22 @@ public class FlowInstance {
*/
private long getTaskId(long task_id) {
if (task_id > 0L) return task_id;
task_id = procInst.getTaskId();
Task curTask = provider.findTask(task_id);
if (EntityHelper.isEmpty(curTask) || curTask.getStatu() != FlowConst.ActivityStatu.WAIT.value) return task_id;
if (EntityHelper.isEmpty(curTask)) throw new SwException("单据任务缺失(" + procInst.getId() + ":::" + task_id + ")!");
actInst = curTask;
if (curTask.getStatu() != FlowConst.ActivityStatu.WAIT.value) return task_id;
//是自己的待办任务
if (curTask.getStatu() == FlowConst.ActivityStatu.WAIT.value && FlowHelper.isMyWaitedTask(curTask.getId(), us.getUserId())) {
return task_id;
}

//待办任务不是自己的,则去找前一个自己提交的任务
List<Task> preActs = provider.findBeforeTasks(task_id);
if (CommUtil.isEmpty(preActs)) return task_id;
for (Task act : preActs) {
if (act.getHandler() == us.getUserId()) {
actInst = act;
return act.getId();
}
}
@@ -293,18 +306,6 @@ public class FlowInstance {
return listTask;
}

/**
* 设置单据描述及链接地址,待办中展示
*
* @param bill_info
* @param bill_url
*/
public void setBillInfo(String bill_code, String bill_info, String bill_url) {
procInst.setBillInfo(bill_info);
procInst.setBillCode(bill_code);
procInst.setUrl(bill_url);
}

//启动流程
public void save() {
if (procInst.isNew()) {
@@ -567,8 +568,10 @@ public class FlowInstance {

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) {
@@ -641,7 +644,7 @@ public class FlowInstance {
task.init();
task.setEntityId(DbEngine.getInstance().nextId());
task.setPriId(procInst.getId());
task.setPriId(procDef.getId());
task.setPrcId(procDef.getId());
task.setActId(act.getId());
task.setActName(act.getLabel());
task.setStartTime(DateUtil.nowDateTimeLong());
@@ -723,6 +726,7 @@ public class FlowInstance {
}

procInst.setTaskId(actInst.getEntityId());
procInst.setActName(actInst.getActName());
procInst.setStatu(actInst.isMake() ? FlowConst.InstanceStatu.BEGIN.value: FlowConst.InstanceStatu.RUNING.value);

taskDao.updateEntity(actInst);
@@ -748,6 +752,7 @@ public class FlowInstance {
actInst.setStatu(FlowConst.ActivityStatu.HANDLE.value);

procInst.setTaskId(actInst.getEntityId());
procInst.setActName(actInst.getActName());

procInst.setStatu(FlowConst.InstanceStatu.RUNING.value);
if (actInst.isMake()) procInst.setStatu(FlowConst.InstanceStatu.BEGIN.value);
@@ -793,6 +798,7 @@ public class FlowInstance {
actInst.setStatu(FlowConst.ActivityStatu.REJECT.value);

procInst.setTaskId(new_acts.get(0).getEntityId());
procInst.setActName(new_acts.get(0).getActName());
if (new_acts.size() == 1 && new_acts.get(0).isMake()) {
procInst.setStatu(FlowConst.InstanceStatu.BEGIN.value);
} else {
@@ -836,6 +842,7 @@ public class FlowInstance {
actInst.setStatu(FlowConst.ActivityStatu.REJECT.value);

procInst.setTaskId(make_act.getEntityId());
procInst.setActName(make_act.getActName());
procInst.setStatu(FlowConst.InstanceStatu.BEGIN.value);

EntityDao<Task> taskDao = getTaskDao();
@@ -923,6 +930,10 @@ public class FlowInstance {
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);


+ 9
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/ProcInst.java Parādīt failu

@@ -123,6 +123,15 @@ public class ProcInst extends DefaultEntity {
public void setTaskId(long pri_task_id) {
put("pri_task_id", pri_task_id);
}

public String getActName() {
return getStr("pri_act_name");
}

public void setActName(String priActName) {
put("pri_act_name", priActName);
}

/** 单据状态 */
public int getStatu() {
return getInt("pri_statu");


+ 19
- 14
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/TaskRel.java Parādīt failu

@@ -7,43 +7,48 @@ import cc.smtweb.framework.core.db.impl.DefaultEntity;
* Created by Akmm at 2022/5/23 14:25
* 活动之间的关系
*/
@SwTable("WF_CARE")
@SwTable("WF_TASK_REL")
public class TaskRel extends DefaultEntity {
public static final String ENTITY_NAME = "WF_CARE";
public static final String ENTITY_NAME = "WF_TASK_REL";

public TaskRel() {
super(ENTITY_NAME);
}

/** 主键 */
public long getId() {
return getLong("trl_id");
}

public void setId(long trlId) {
put("trl_id", trlId);
/** 主键 */
public void setId(long trl_id) {
put("trl_id", trl_id);
}
/** 流程实例id */
public long getPriId() {
return getLong("trl_pri_id");
}

public void setPriId(long trlPriId) {
put("trl_pri_id", trlPriId);
/** 流程实例id */
public void setPriId(long trl_pri_id) {
put("trl_pri_id", trl_pri_id);
}
/** 前任务id */
public long getSrcTaskId() {
return getLong("trl_src_task_id");
}

public void setSrcTaskId(long trlSrcTaskId) {
put("trl_src_task_id", trlSrcTaskId);
/** 前任务id */
public void setSrcTaskId(long trl_src_task_id) {
put("trl_src_task_id", trl_src_task_id);
}
/** 目标任务id */
public long getDstTaskId() {
return getLong("trl_dst_task_id");
}

public void setDstTaskId(long trlDstTaskId) {
put("trl_dst_task_id", trlDstTaskId);
/** 目标任务id */
public void setDstTaskId(long trl_dst_task_id) {
put("trl_dst_task_id", trl_dst_task_id);
}
}
}

+ 7
- 12
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java Parādīt failu

@@ -25,16 +25,15 @@ import java.util.ArrayList;
/**
* Created by Akmm at 2022-08-26 17:15
*/
public class FlowSingleLoadHandler extends LCSingleLoadHandler implements FlowListener {
public class FlowSingleLoadHandler<T extends DefaultEntity> extends LCSingleLoadHandler<T> implements FlowListener {
protected FlowInstance flowInstance;

@Override
protected void afterAdd(SwMap ret, SwMap bean) {
protected void afterAdd(SwMap ret, T bean) {
flowInstance = FlowInstance.createByBillType(us, this, form.getBillType());
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);
ModelTable table = cardDataset.getModelTable();
bean.put(table.getIdField(), flowInstance.getProcInst().getId());
bean.setEntityId(flowInstance.getProcInst().getId());

ret.put(cardDataset.name, DynRetBean.createBean(bean));
ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst()));
@@ -47,14 +46,10 @@ public class FlowSingleLoadHandler extends LCSingleLoadHandler implements FlowLi
//过滤条件
long id = params.readLong("id");
long taskId = params.readLong("taskId");
// SwMap filter = params.readMap("filter");
SwMap filter = new SwMap();
filter.put(SwConsts.NAME_ID, id);
//对应的数据集定义
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);

SwMap data = provider.loadData(filter, cardDataset);
ret.put(cardDataset.name, DynRetBean.createBean(data));
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);
T bean = provider.loadBean(cardDataset, id);
ret.put(cardDataset.name, DynRetBean.createBean(bean));

//加载流程信息
flowInstance = FlowInstance.createById(us,this, id, taskId);
@@ -62,7 +57,7 @@ public class FlowSingleLoadHandler extends LCSingleLoadHandler implements FlowLi
ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst()));
ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.create(flowInstance.loadComment(), 0)));
afterLoad(ret, data);
afterLoad(ret, bean);
return R.success(ret);
}



+ 10
- 5
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java Parādīt failu

@@ -5,6 +5,7 @@ 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.framework.core.util.DateUtil;
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;
@@ -38,7 +39,11 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
}
flowInstance.readFromPage(data);
flowInstance.getProcInst().setIsNew(bean.isNew());
flowInstance.setBillInfo(getBillCode(), getBillInfo(), getBillUrl());
if (bean.isNew()) {
flowInstance.getProcInst().setBillCode(getBillCode());
flowInstance.getProcInst().setUrl(getBillUrl());
}
flowInstance.getProcInst().setBillInfo(getBillInfo());
return bean;
}

@@ -55,14 +60,14 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.EMPTY));
}

//单据编号
//单据编号,新增保存时调用
protected String getBillCode() {
return "";
return flowInstance.getProcInst().getBillCode();
}

//单据信息,在待办中显示
//单据信息,在待办中显示,每次保存均计算
protected String getBillInfo() {
return "";
return flowInstance.getProcInst().getBillCode() + "-" + DateUtil.nowDate();
}

//单据url,待办中跳链


+ 21
- 8
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java Parādīt failu

@@ -2,13 +2,16 @@ 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.db.impl.DefaultEntity;
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.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;
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleHelper;

import java.util.List;

@@ -16,30 +19,40 @@ import java.util.List;
* Created by Akmm at 2022-09-01 15:03
* 流程流转
*/
public class FlowTransHandler extends AbstractDynPageHandler implements FlowListener{
public class FlowTransHandler<T extends DefaultEntity> extends AbstractDynPageHandler implements FlowListener{
//流程id
protected long billId;
//任务id
protected long taskId;
protected FlowInstance flowInstance;

private void loadFlowInstance() {
protected T bean;

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

protected void load() {
if (flowInstance == null) {
billId = params.readLong("id");
taskId = params.readLong("taskId");
flowInstance = FlowInstance.createById(us, this, billId, taskId);

loadBean();
}
}

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;
protected void loadBean() {
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);
bean = provider.loadBean(cardDataset, billId);
}

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


+ 21
- 9
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java Parādīt failu

@@ -1,7 +1,14 @@
package cc.smtweb.system.bpm.web.engine.model.listcard.single;

import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.db.cache.ModelTableCache;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageHelper;
@@ -11,28 +18,33 @@ import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean;
/**
* Created by Akmm at 2022-08-16 15:43
*/
public class LCSingleLoadHandler extends AbstractDynPageHandler {
public class LCSingleLoadHandler<T extends DefaultEntity> extends AbstractDynPageHandler {

//新增卡片操作,初始化定义的数据集
public R add() {
SwMap ret = new SwMap();
//返回的数据,以dataset.name为key,查出的结果(bean或list)为value
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);
SwMap data = DynPageHelper.createBean(cardDataset);
ModelTable table = cardDataset.getModelTable();
if (table == null) throw new SwException("卡片主表未找到!");
final EntityDao<T> dao = DbEngine.getInstance().findDao(table.getName());

ret.put(cardDataset.name, DynRetBean.createBean(data));
T bean = dao.createBean(us.getUserId());
bean.setEntityId(DbEngine.getInstance().nextId());

afterAdd(ret, data);
ret.put(cardDataset.name, DynRetBean.createBean(bean));

afterAdd(ret, bean);
return R.success(ret);
}


//新增初始化 - bean
protected void afterAdd(SwMap ret, SwMap bean) {
protected void afterAdd(SwMap ret, T bean) {
}

//加载之后
protected void afterLoad(SwMap ret, SwMap bean) {
protected void afterLoad(SwMap ret, T bean) {
}

public R load() {
@@ -42,10 +54,10 @@ public class LCSingleLoadHandler extends AbstractDynPageHandler {
//对应的数据集定义
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);

SwMap data = provider.loadData(filter, cardDataset);
ret.put(cardDataset.name, DynRetBean.createBean(data));
T bean = provider.loadBean(cardDataset, filter.readLong(SwConsts.NAME_ID));
ret.put(cardDataset.name, DynRetBean.createBean(bean));

afterLoad(ret, data);
afterLoad(ret, bean);
return R.success(ret);
}



Notiek ielāde…
Atcelt
Saglabāt