From bcb6eb735ea13e1719895c093448b32b2cf8aed9 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Fri, 2 Sep 2022 12:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=BC=95=E6=93=8E=EF=BC=9Alo?= =?UTF-8?q?ad\save\submit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/bpm/web/engine/flow/FlowInstance.java | 82 ++++++++++++++-------- .../system/bpm/web/engine/flow/FlowProvider.java | 8 ++- .../system/bpm/web/engine/flow/entity/Comment.java | 6 +- .../listcard/single/FlowSingleSaveHandler.java | 10 +++ .../flow/listcard/single/FlowTransHandler.java | 14 +++- .../model/listcard/single/LCSingleSaveHandler.java | 6 +- 6 files changed, 91 insertions(+), 35 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java index 844768f..c8ea2eb 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java +++ b/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 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 adjustTasks() { List 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 listInsertTask = new ArrayList<>(); List listTaskRel = new ArrayList<>(); + List listTaskComment = new ArrayList<>(); //待新增任务候选人 List 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 listInsertTask, List listInsertCand, List listTaskRel, long submit_user) { + private void buildTask(Activity act, List listInsertTask, List listInsertCand, List listTaskRel, List 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 getProcInstDao() { return DbEngine.getInstance().findDao(ProcInst.class); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java index 72c5888..1b42970 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java +++ b/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 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)); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java index 30a3deb..1a35236 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java +++ b/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); } /** 活动名 */ diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java index 316ca92..3875c86 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java +++ b/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 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 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 ""; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java index 602f91a..c79c45c 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java +++ b/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()); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java index 194a986..66032c2 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java @@ -71,9 +71,13 @@ public class LCSingleSaveHandler 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 *