@@ -1,6 +1,8 @@ | |||||
package cc.smtweb.system.bpm.web.design.flow; | package cc.smtweb.system.bpm.web.design.flow; | ||||
import cc.smtweb.framework.core.common.R; | import cc.smtweb.framework.core.common.R; | ||||
import cc.smtweb.framework.core.db.DbEngine; | |||||
import cc.smtweb.framework.core.db.EntityDao; | |||||
import cc.smtweb.framework.core.exception.BizException; | import cc.smtweb.framework.core.exception.BizException; | ||||
import cc.smtweb.framework.core.mvc.service.DefaultLoadHandler; | import cc.smtweb.framework.core.mvc.service.DefaultLoadHandler; | ||||
@@ -13,17 +15,15 @@ public class ModelProcLoadHandler extends DefaultLoadHandler<ModelProc> { | |||||
} | } | ||||
@Override | @Override | ||||
protected ModelProc loadComp(long id) { | |||||
ModelProc bean = super.loadComp(id); | |||||
protected void afterLoad(ModelProc bean) { | |||||
bean.getData().remove("prc_content"); | bean.getData().remove("prc_content"); | ||||
return bean; | |||||
} | } | ||||
//页面设计 - 加载页面model定义 | //页面设计 - 加载页面model定义 | ||||
public R loadModel() { | public R loadModel() { | ||||
long id = params.readLong("id"); | long id = params.readLong("id"); | ||||
ModelProc bean = super.loadComp(id); | |||||
ModelProc bean = ModelProcCache.getInstance().get(id); | |||||
if (bean == null) throw new BizException("没有找到指定定义信息!id=" + id); | if (bean == null) throw new BizException("没有找到指定定义信息!id=" + id); | ||||
return R.success(bean.getContent()); | return R.success(bean.getContent()); | ||||
} | } | ||||
@@ -60,7 +60,7 @@ public class ModelProcSaveHandler extends DefaultSaveHandler<ModelProc> { | |||||
public R saveModel() { | public R saveModel() { | ||||
long id = params.readLong("id"); | long id = params.readLong("id"); | ||||
String data = params.readString("data"); | String data = params.readString("data"); | ||||
bean = loadComp(id); | |||||
bean = ModelProcCache.getInstance().get(id); | |||||
if (StringUtils.isEmpty(data)) { | if (StringUtils.isEmpty(data)) { | ||||
throw new BizException("没有待保存的数据!"); | throw new BizException("没有待保存的数据!"); | ||||
} | } | ||||
@@ -75,7 +75,7 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> { | |||||
public R saveDataset() { | public R saveDataset() { | ||||
long id = params.readLong("id"); | long id = params.readLong("id"); | ||||
String data = params.readString("data"); | String data = params.readString("data"); | ||||
bean = loadComp(id); | |||||
bean = ModelFormCache.getInstance().get(id); | |||||
if (StringUtils.isEmpty(data)) { | if (StringUtils.isEmpty(data)) { | ||||
throw new BizException("没有待保存的数据!"); | throw new BizException("没有待保存的数据!"); | ||||
} | } | ||||
@@ -107,7 +107,7 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> { | |||||
public R saveModel() { | public R saveModel() { | ||||
long id = params.readLong("id"); | long id = params.readLong("id"); | ||||
String data = params.readString("data"); | String data = params.readString("data"); | ||||
bean = loadComp(id); | |||||
bean = ModelFormCache.getInstance().get(id); | |||||
if (StringUtils.isEmpty(data)) { | if (StringUtils.isEmpty(data)) { | ||||
throw new BizException("没有待保存的数据!"); | throw new BizException("没有待保存的数据!"); | ||||
} | } | ||||
@@ -3,6 +3,7 @@ package cc.smtweb.system.bpm.web.design.preview; | |||||
import cc.smtweb.framework.core.annotation.SwParam; | import cc.smtweb.framework.core.annotation.SwParam; | ||||
import cc.smtweb.framework.core.annotation.SwService; | import cc.smtweb.framework.core.annotation.SwService; | ||||
import cc.smtweb.framework.core.common.R; | import cc.smtweb.framework.core.common.R; | ||||
import cc.smtweb.framework.core.common.SwConsts; | |||||
import cc.smtweb.framework.core.common.SwEnum; | import cc.smtweb.framework.core.common.SwEnum; | ||||
import cc.smtweb.framework.core.db.DbEngine; | import cc.smtweb.framework.core.db.DbEngine; | ||||
import cc.smtweb.framework.core.db.vo.ModelCatalog; | import cc.smtweb.framework.core.db.vo.ModelCatalog; | ||||
@@ -31,9 +32,11 @@ public class PreviewMenuTreeService { | |||||
public R treeAll(@SwParam("module") String module, UserSession us) { | public R treeAll(@SwParam("module") String module, UserSession us) { | ||||
String prj_id = ModelProjectCache.getInstance().getIdByModule(module); | String prj_id = ModelProjectCache.getInstance().getIdByModule(module); | ||||
List<MenuVO> menuVOList = buildMenu(prj_id, module, us); | |||||
if (PubUtil.isNotEmpty(menuVOList)) { | |||||
return R.success(menuVOList); | |||||
if(!SwConsts.SYS_DEBUG){ | |||||
List<MenuVO> menuVOList = buildMenu(prj_id, module, us); | |||||
if (PubUtil.isNotEmpty(menuVOList)) { | |||||
return R.success(menuVOList); | |||||
} | |||||
} | } | ||||
List<ModelForm> listForm; | List<ModelForm> listForm; | ||||
if (StringUtils.isNotEmpty(prj_id)) { | if (StringUtils.isNotEmpty(prj_id)) { | ||||
@@ -45,6 +45,7 @@ public class DynPageHelper { | |||||
ModelTable masterTable = ModelTableCache.getInstance().get(dataSet.masterTable); | ModelTable masterTable = ModelTableCache.getInstance().get(dataSet.masterTable); | ||||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(masterTable.getName()); | EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(masterTable.getName()); | ||||
DefaultEntity bean = dao.createBean(); | DefaultEntity bean = dao.createBean(); | ||||
bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
return bean.getData(); | return bean.getData(); | ||||
} | } | ||||
@@ -14,6 +14,7 @@ import cc.smtweb.framework.core.db.vo.ModelField; | |||||
import cc.smtweb.framework.core.db.vo.ModelIndex; | import cc.smtweb.framework.core.db.vo.ModelIndex; | ||||
import cc.smtweb.framework.core.db.vo.ModelTable; | import cc.smtweb.framework.core.db.vo.ModelTable; | ||||
import cc.smtweb.framework.core.exception.BizException; | import cc.smtweb.framework.core.exception.BizException; | ||||
import cc.smtweb.framework.core.mvc.service.DefaultSaveHandler; | |||||
import cc.smtweb.framework.core.mvc.service.TreeHelper; | import cc.smtweb.framework.core.mvc.service.TreeHelper; | ||||
import cc.smtweb.framework.core.util.StringUtil; | import cc.smtweb.framework.core.util.StringUtil; | ||||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | ||||
@@ -33,10 +34,6 @@ import java.util.Map; | |||||
public class DynPageSaveHandler extends AbstractDynPageHandler { | public class DynPageSaveHandler extends AbstractDynPageHandler { | ||||
private Map<String, List<DefaultEntity>> mapTreeBean = new HashMap<>(); | private Map<String, List<DefaultEntity>> mapTreeBean = new HashMap<>(); | ||||
protected void setNewId(DefaultEntity bean) { | |||||
bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
} | |||||
/** | /** | ||||
* 保存指定数据集操作,入参:{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}} | * 保存指定数据集操作,入参:{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}} | ||||
*/ | */ | ||||
@@ -50,6 +47,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { | |||||
//对应的数据集定义 | //对应的数据集定义 | ||||
PageDataset pageDataSet = findDataset(dbName); | PageDataset pageDataSet = findDataset(dbName); | ||||
if (pageDataSet == null) throw new BizException("没有找到指定的的数据集定义:" + dbName + "!"); | if (pageDataSet == null) throw new BizException("没有找到指定的的数据集定义:" + dbName + "!"); | ||||
//读取待保存的bean | //读取待保存的bean | ||||
DefaultEntity bean = readBeanFromPage(pageDataSet, data.readMap("form")); | DefaultEntity bean = readBeanFromPage(pageDataSet, data.readMap("form")); | ||||
if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上 | if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上 | ||||
@@ -73,6 +71,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { | |||||
afterRollback(bean); | afterRollback(bean); | ||||
} | } | ||||
}); | }); | ||||
bean.removeStatus(); | |||||
return R.success(DynRetBean.createBean(bean.getData())); | return R.success(DynRetBean.createBean(bean.getData())); | ||||
} | } | ||||
@@ -133,6 +132,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { | |||||
}); | }); | ||||
Map<String, DynRetBean> mapRet = new HashMap<>(map.size()); | Map<String, DynRetBean> mapRet = new HashMap<>(map.size()); | ||||
for (Map.Entry<String, DefaultEntity> entry : map.entrySet()) { | for (Map.Entry<String, DefaultEntity> entry : map.entrySet()) { | ||||
entry.getValue().getData().remove(DefaultEntity.statusKey); | |||||
mapRet.put(entry.getKey(), DynRetBean.createBean(entry.getValue().getData())); | mapRet.put(entry.getKey(), DynRetBean.createBean(entry.getValue().getData())); | ||||
} | } | ||||
return R.success(mapRet); | return R.success(mapRet); | ||||
@@ -148,16 +148,17 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { | |||||
protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap data) { | protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap data) { | ||||
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable); | ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable); | ||||
if (table == null) throw new BizException("没有找到待保存的表定义:" + pageDataSet.name); | if (table == null) throw new BizException("没有找到待保存的表定义:" + pageDataSet.name); | ||||
long id = data.readLong(table.getIdField()); | long id = data.readLong(table.getIdField()); | ||||
boolean isNew = data.readBool(DefaultEntity.statusKey) || id <= 0L; | |||||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(table.getName()); | EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(table.getName()); | ||||
DefaultEntity bean; | DefaultEntity bean; | ||||
if (id <= 0L) { | |||||
bean = dao.createBean(); | |||||
bean.setIsNew(true); | |||||
if (isNew) { | |||||
bean = dao.createBean(us.getUserId()); | |||||
//暂时不考虑list保存的情况 | //暂时不考虑list保存的情况 | ||||
bean.getData().putAll(data); | bean.getData().putAll(data); | ||||
setNewId(bean); | |||||
if (bean.getEntityId() <= 0L) bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
} else { | } else { | ||||
bean = dao.queryEntity(id); | bean = dao.queryEntity(id); | ||||
if (bean == null) { | if (bean == null) { | ||||
@@ -165,7 +166,6 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { | |||||
} | } | ||||
//暂时不考虑list保存的情况 | //暂时不考虑list保存的情况 | ||||
bean.getData().putAll(data); | bean.getData().putAll(data); | ||||
bean.setIsNew(false); | |||||
} | } | ||||
return bean; | return bean; | ||||
@@ -23,8 +23,8 @@ public class DynRetBean { | |||||
SwMap form = (SwMap) swMap.clone(); | SwMap form = (SwMap) swMap.clone(); | ||||
DynRetBean bean = new DynRetBean(); | DynRetBean bean = new DynRetBean(); | ||||
bean.form = form; | bean.form = form; | ||||
bean.form.remove("_def_table_name"); | |||||
bean.form.remove("_status"); | |||||
bean.form.remove(DefaultEntity.tableNameKey); | |||||
//bean.form.remove(DefaultEntity.statusKey); | |||||
return bean; | return bean; | ||||
} | } | ||||
@@ -15,14 +15,11 @@ import cc.smtweb.system.bpm.web.design.flow.ModelProc; | |||||
import cc.smtweb.system.bpm.web.design.flow.ModelProcHelper; | import cc.smtweb.system.bpm.web.design.flow.ModelProcHelper; | ||||
import cc.smtweb.system.bpm.web.design.flow.define.Activity; | import cc.smtweb.system.bpm.web.design.flow.define.Activity; | ||||
import cc.smtweb.system.bpm.web.design.flow.define.ProcInfo; | import cc.smtweb.system.bpm.web.design.flow.define.ProcInfo; | ||||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||||
import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; | |||||
import cc.smtweb.system.bpm.web.engine.flow.entity.*; | import cc.smtweb.system.bpm.web.engine.flow.entity.*; | ||||
import cc.smtweb.system.bpm.web.sys.user.dept.Dept; | import cc.smtweb.system.bpm.web.sys.user.dept.Dept; | ||||
import cc.smtweb.system.bpm.web.sys.user.dept.DeptCache; | import cc.smtweb.system.bpm.web.sys.user.dept.DeptCache; | ||||
import cc.smtweb.system.bpm.web.sys.user.party.Party; | import cc.smtweb.system.bpm.web.sys.user.party.Party; | ||||
import cc.smtweb.system.bpm.web.sys.user.party.PartyCache; | import cc.smtweb.system.bpm.web.sys.user.party.PartyCache; | ||||
import cc.smtweb.system.bpm.web.sys.user.user.UserCache; | |||||
import cc.smtweb.system.bpm.web.sys.user.userGroup.UserGroupHelper; | import cc.smtweb.system.bpm.web.sys.user.userGroup.UserGroupHelper; | ||||
import lombok.Data; | import lombok.Data; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
@@ -46,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<>(); | ||||
@@ -59,7 +53,20 @@ public class FlowInstance { | |||||
private FlowListener listener; | private FlowListener listener; | ||||
public FlowInstance(@NonNull FlowListener listener, UserSession us) { | |||||
public static FlowInstance createById(UserSession us, FlowListener listener, long billId, long taskId) { | |||||
FlowInstance flowInstance = new FlowInstance(listener, us); | |||||
flowInstance.load(billId, taskId); | |||||
return flowInstance; | |||||
} | |||||
public static FlowInstance createByBillType(UserSession us, FlowListener listener, long billType) { | |||||
FlowInstance flowInstance = new FlowInstance(listener, us); | |||||
flowInstance.create(billType); | |||||
return flowInstance; | |||||
} | |||||
private FlowInstance(@NonNull FlowListener listener, UserSession us) { | |||||
this.listener = listener; | this.listener = listener; | ||||
this.us = us; | this.us = us; | ||||
} | } | ||||
@@ -67,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; | ||||
} | } | ||||
@@ -115,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()); | ||||
@@ -135,6 +141,7 @@ public class FlowInstance { | |||||
actInst.setId(procInst.getEntityId()); | actInst.setId(procInst.getEntityId()); | ||||
actInst.setPrcId(procDef.getEntityId()); | actInst.setPrcId(procDef.getEntityId()); | ||||
actInst.setActId(start.getId()); | actInst.setActId(start.getId()); | ||||
actInst.setActName(start.getLabel()); | |||||
actInst.setHandler(us.getUserId()); | actInst.setHandler(us.getUserId()); | ||||
actInst.setStartTime(DateUtil.nowDateTimeLong()); | actInst.setStartTime(DateUtil.nowDateTimeLong()); | ||||
actInst.setStatu(FlowConst.ActivityStatu.HANDLE.value); | actInst.setStatu(FlowConst.ActivityStatu.HANDLE.value); | ||||
@@ -169,8 +176,9 @@ 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.handle(actInst); | |||||
listener.afterHandle(actInst); | |||||
} | } | ||||
//从页面参数加载流程实例 | //从页面参数加载流程实例 | ||||
@@ -229,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; | ||||
} | } | ||||
@@ -299,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) { | ||||
@@ -527,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(); | ||||
@@ -544,17 +552,18 @@ 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); | ||||
actInst.setStartTime(DateUtil.nowDateTimeLong()); | actInst.setStartTime(DateUtil.nowDateTimeLong()); | ||||
actInst.setStatu(FlowConst.ActivityStatu.SUBMIT.value); | actInst.setStatu(FlowConst.ActivityStatu.SUBMIT.value); | ||||
actInst.setRetake(true); | |||||
actInst.setRetake(false); | |||||
if (listInsertTask.size() > 0) { | if (listInsertTask.size() > 0) { | ||||
procInst.setTaskId(listInsertTask.get(0).getEntityId()); | procInst.setTaskId(listInsertTask.get(0).getEntityId()); | ||||
@@ -574,26 +583,17 @@ 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); | |||||
listener.submit(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); | |||||
updateComment(comment, FlowConst.Button.SUBMIT.value); | |||||
buildBillLog(FlowConst.Button.SUBMIT.value, comment, actInst, listInsertTask); | |||||
listener.afterSubmit(actInst, listInsertTask); | |||||
} | } | ||||
/** | /** | ||||
@@ -623,7 +623,7 @@ public class FlowInstance { | |||||
getProcInstDao().updateEntity(procInst); | getProcInstDao().updateEntity(procInst); | ||||
buildBillLog(FlowConst.Button.DISUSE.value, "TODO", actInst, null); | buildBillLog(FlowConst.Button.DISUSE.value, "TODO", actInst, null); | ||||
listener.disuse(actInst); | |||||
listener.afterDisuse(actInst); | |||||
} | } | ||||
/** | /** | ||||
@@ -635,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(); | ||||
@@ -643,6 +643,7 @@ public class FlowInstance { | |||||
task.setPriId(procInst.getId()); | task.setPriId(procInst.getId()); | ||||
task.setPriId(procDef.getId()); | task.setPriId(procDef.getId()); | ||||
task.setActId(act.getId()); | task.setActId(act.getId()); | ||||
task.setActName(act.getLabel()); | |||||
task.setStartTime(DateUtil.nowDateTimeLong()); | task.setStartTime(DateUtil.nowDateTimeLong()); | ||||
task.setStatu(FlowConst.ActivityStatu.WAIT.value); | task.setStatu(FlowConst.ActivityStatu.WAIT.value); | ||||
task.setMake(false); | task.setMake(false); | ||||
@@ -661,8 +662,12 @@ public class FlowInstance { | |||||
if (act.getType() != FlowConst.ActivityType.END.value) { | if (act.getType() != FlowConst.ActivityType.END.value) { | ||||
Set<Long> listHander = new HashSet<>(); | Set<Long> listHander = new HashSet<>(); | ||||
long hanlder_group = act.getHandler().getUserGroup(); | |||||
int handler_range = act.getHandler().getFilter(); | |||||
long hanlder_group = 0L; | |||||
int handler_range = 0; | |||||
if (act.getHandler() != null) { | |||||
hanlder_group = act.getHandler().getUserGroup(); | |||||
handler_range = act.getHandler().getFilter(); | |||||
} | |||||
//获取所有候选人 | //获取所有候选人 | ||||
listHander = UserGroupHelper.getUserIdList(hanlder_group, procInst, handler_range, us); | listHander = UserGroupHelper.getUserIdList(hanlder_group, procInst, handler_range, us); | ||||
@@ -683,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)); | |||||
} | } | ||||
} | } | ||||
@@ -724,7 +732,7 @@ public class FlowInstance { | |||||
new_acts.clear(); | new_acts.clear(); | ||||
new_acts.add(old_act); | new_acts.add(old_act); | ||||
buildBillLog(FlowConst.Button.RETAKE.value, "TODO", actInst, new_acts); | buildBillLog(FlowConst.Button.RETAKE.value, "TODO", actInst, new_acts); | ||||
listener.retake(actInst, new_acts); | |||||
listener.afterRetake(actInst, new_acts); | |||||
// comp.transCallback(FlowConst.Button.RETAKE.value, actInst, new_acts); | // comp.transCallback(FlowConst.Button.RETAKE.value, actInst, new_acts); | ||||
} else { | } else { | ||||
List<Task> new_acts = provider.findAfterTasks(actInst.getId()); | List<Task> new_acts = provider.findAfterTasks(actInst.getId()); | ||||
@@ -750,7 +758,7 @@ public class FlowInstance { | |||||
getProcInstDao().updateEntity(procInst); | getProcInstDao().updateEntity(procInst); | ||||
buildBillLog(FlowConst.Button.RETAKE.value, "TODO", actInst, new_acts); | buildBillLog(FlowConst.Button.RETAKE.value, "TODO", actInst, new_acts); | ||||
listener.retake(actInst, new_acts); | |||||
listener.afterRetake(actInst, new_acts); | |||||
} | } | ||||
} | } | ||||
@@ -799,7 +807,7 @@ public class FlowInstance { | |||||
getProcInstDao().updateEntity(procInst); | getProcInstDao().updateEntity(procInst); | ||||
buildBillLog(FlowConst.Button.REJECT.value, "TODO", actInst, new_acts); | buildBillLog(FlowConst.Button.REJECT.value, "TODO", actInst, new_acts); | ||||
listener.reject(actInst, new_acts); | |||||
listener.afterReject(actInst, new_acts); | |||||
// comp.transCallback(FlowConst.FlowOptType.REJECT.value, actInst, new_acts); | // comp.transCallback(FlowConst.FlowOptType.REJECT.value, actInst, new_acts); | ||||
} | } | ||||
@@ -843,7 +851,7 @@ public class FlowInstance { | |||||
make_acts.add(make_act); | make_acts.add(make_act); | ||||
buildBillLog(FlowConst.Button.REJECT.value, "TODO", actInst, make_acts); | buildBillLog(FlowConst.Button.REJECT.value, "TODO", actInst, make_acts); | ||||
listener.reject(actInst, make_acts); | |||||
listener.afterReject(actInst, make_acts); | |||||
} | } | ||||
/** | /** | ||||
@@ -886,8 +894,42 @@ 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); | ||||
@@ -13,14 +13,14 @@ public interface FlowListener { | |||||
//设置条件计算参数 | //设置条件计算参数 | ||||
default void setExprParam(SwMap param) {} | default void setExprParam(SwMap param) {} | ||||
//提交 | //提交 | ||||
default void submit(Task srcTask, List<Task> dstTasks) {} | |||||
default void afterSubmit(Task srcTask, List<Task> dstTasks) {} | |||||
//取回 | //取回 | ||||
default void retake(Task srcTask, List<Task> dstTasks) {} | |||||
default void afterRetake(Task srcTask, List<Task> dstTasks) {} | |||||
//驳回 | //驳回 | ||||
default void reject(Task srcTask, List<Task> dstTasks) {} | |||||
default void afterReject(Task srcTask, List<Task> dstTasks) {} | |||||
//办理,签收 | //办理,签收 | ||||
default void handle(Task srcTask) {} | |||||
default void afterHandle(Task srcTask) {} | |||||
//作废 | //作废 | ||||
default void disuse(Task srcTask) {} | |||||
default void afterDisuse(Task srcTask) {} | |||||
} | } |
@@ -1,15 +0,0 @@ | |||||
package cc.smtweb.system.bpm.web.engine.flow; | |||||
import cc.smtweb.framework.core.common.R; | |||||
import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler; | |||||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; | |||||
/** | |||||
* Created by Akmm at 2022/4/21 17:53 | |||||
* 保存指定数据集操作 | |||||
* 入参:{pageId, data:} | |||||
*/ | |||||
public class FlowLoadHandler extends DynPageLoadHandler { | |||||
} |
@@ -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; | ||||
@@ -40,7 +41,7 @@ public class FlowProvider extends AbstractCompProvider { | |||||
return doGetData("a_" + taskId, () -> { | return doGetData("a_" + taskId, () -> { | ||||
EntityDao<Task> bdao = DbEngine.getInstance().findDao(Task.class); | EntityDao<Task> bdao = DbEngine.getInstance().findDao(Task.class); | ||||
Task bean = bdao.queryEntity(taskId); | Task bean = bdao.queryEntity(taskId); | ||||
if (bean == null) throw new BizException("没有找到指定流程任务(id=" + taskId + ")!"); | |||||
if (bean == null) return null; | |||||
EntityHelper.loadBeanText(bean.getTableName(), bean.getData(), null); | EntityHelper.loadBeanText(bean.getTableName(), bean.getData(), null); | ||||
return bean; | return bean; | ||||
}); | }); | ||||
@@ -98,10 +99,15 @@ public class FlowProvider extends AbstractCompProvider { | |||||
//寻找流程的制单任务 | //寻找流程的制单任务 | ||||
public Task findMakeTask(long bill_id) { | public Task findMakeTask(long bill_id) { | ||||
return DbEngine.getInstance().findDao(Task.class).queryEntityWhere("where tsk_pri_id = ? and is_make = 1 ", bill_id); | |||||
return DbEngine.getInstance().findDao(Task.class).queryEntityWhere(" tsk_pri_id = ? and is_make = 1 ", bill_id); | |||||
} | } | ||||
public List<Comment> findComment(long bill_id) { | public List<Comment> findComment(long bill_id) { | ||||
return DbEngine.getInstance().findDao(Comment.class).queryWhere("where cmt_pri_id=? order by cmt_end_time"); | |||||
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)); | |||||
} | } | ||||
} | } |
@@ -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); | ||||
} | } | ||||
/** 活动名 */ | /** 活动名 */ | ||||
@@ -0,0 +1,22 @@ | |||||
package cc.smtweb.system.bpm.web.engine.model.flow.listcard.single; | |||||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||||
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.model.listcard.single.LCSingleDelHandler; | |||||
/** | |||||
* Created by Akmm at 2022-09-01 15:03 | |||||
* 流程删除 | |||||
*/ | |||||
public class FlowDelHandler extends LCSingleDelHandler implements FlowListener { | |||||
protected FlowInstance flowInstance; | |||||
@Override | |||||
protected void localDel(long id, ModelTable table) { | |||||
long taskId = params.readLong("taskId"); | |||||
flowInstance = FlowInstance.createById(us, this, id, taskId); | |||||
flowInstance.delete(); | |||||
super.localDel(id, table); | |||||
} | |||||
} |
@@ -30,13 +30,13 @@ public class FlowSingleLoadHandler extends LCSingleLoadHandler implements FlowLi | |||||
@Override | @Override | ||||
protected void afterAdd(SwMap ret, SwMap bean) { | protected void afterAdd(SwMap ret, SwMap bean) { | ||||
FlowInstance flowInstance = new FlowInstance(this, us); | |||||
flowInstance.create(form.getBillType()); | |||||
flowInstance = FlowInstance.createByBillType(us, this, form.getBillType()); | |||||
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | ||||
ModelTable table = cardDataset.getModelTable(); | ModelTable table = cardDataset.getModelTable(); | ||||
bean.put(table.getIdField(), flowInstance.getProcInst().getId()); | bean.put(table.getIdField(), flowInstance.getProcInst().getId()); | ||||
ret.put(cardDataset.name, DynRetBean.createBean(bean)); | |||||
ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst())); | ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst())); | ||||
ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.EMPTY)); | ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.EMPTY)); | ||||
} | } | ||||
@@ -54,11 +54,10 @@ public class FlowSingleLoadHandler extends LCSingleLoadHandler implements FlowLi | |||||
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | ||||
SwMap data = provider.loadData(filter, cardDataset); | SwMap data = provider.loadData(filter, cardDataset); | ||||
ret.put(cardDataset.name, data); | |||||
ret.put(cardDataset.name, DynRetBean.createBean(data)); | |||||
//加载流程信息 | //加载流程信息 | ||||
FlowInstance flowInstance = new FlowInstance(this, us); | |||||
flowInstance.load(id, taskId); | |||||
flowInstance = FlowInstance.createById(us,this, id, taskId); | |||||
ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst())); | ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst())); | ||||
ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.create(flowInstance.loadComment(), 0))); | ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.create(flowInstance.loadComment(), 0))); | ||||
@@ -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; | ||||
@@ -18,12 +20,6 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave | |||||
protected FlowInstance flowInstance; | protected FlowInstance flowInstance; | ||||
@Override | @Override | ||||
public R save() { | |||||
return super.save(); | |||||
} | |||||
@Override | |||||
protected T readBeanFromPage(PageDataset pageDataSet, SwMap pageData) { | protected T readBeanFromPage(PageDataset pageDataSet, SwMap pageData) { | ||||
T bean = super.readBeanFromPage(pageDataSet, pageData); | T bean = super.readBeanFromPage(pageDataSet, pageData); | ||||
@@ -35,14 +31,14 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave | |||||
data = data.readMap("form"); | data = data.readMap("form"); | ||||
if (data == null) throw new BizException("没有找到待保存的流程数据!"); | if (data == null) throw new BizException("没有找到待保存的流程数据!"); | ||||
FlowInstance flowInstance = new FlowInstance(this, us); | |||||
if (bean.isNew()) { | if (bean.isNew()) { | ||||
flowInstance.create(form.getBillType()); | |||||
flowInstance = FlowInstance.createByBillType(us, this, form.getBillType()); | |||||
} else { | } else { | ||||
flowInstance.load(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()); | |||||
return bean; | return bean; | ||||
} | } | ||||
@@ -51,4 +47,26 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave | |||||
super.saveBean(bean); | super.saveBean(bean); | ||||
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() { | |||||
return ""; | |||||
} | |||||
//单据信息,在待办中显示 | |||||
protected String getBillInfo() { | |||||
return ""; | |||||
} | |||||
//单据url,待办中跳链 | |||||
protected String getBillUrl() { | |||||
return ""; | |||||
} | |||||
} | } |
@@ -1,7 +1,13 @@ | |||||
package cc.smtweb.system.bpm.web.engine.model.flow.listcard.single; | package cc.smtweb.system.bpm.web.engine.model.flow.listcard.single; | ||||
import cc.smtweb.framework.core.annotation.SwBody; | |||||
import cc.smtweb.framework.core.annotation.SwService; | import cc.smtweb.framework.core.annotation.SwService; | ||||
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.db.impl.DefaultEntity; | ||||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||||
import cc.smtweb.framework.core.mvc.service.IWorker; | |||||
import cc.smtweb.framework.core.session.UserSession; | |||||
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleDelHandler; | import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleDelHandler; | ||||
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleLoadHandler; | import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleLoadHandler; | ||||
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; | import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; | ||||
@@ -13,6 +19,13 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleService; | |||||
*/ | */ | ||||
@SwService | @SwService | ||||
public class FlowSingleService extends LCSingleService { | public class FlowSingleService extends LCSingleService { | ||||
public static final String TYPE_FLOW = "flow"; | |||||
@Override | |||||
protected AbstractHandler createHandler(String type) { | |||||
if (TYPE_FLOW.equals(type)) return new FlowTransHandler(); | |||||
return super.createHandler(type); | |||||
} | |||||
@Override | @Override | ||||
protected LCSingleSaveHandler getSaveHandler() { | protected LCSingleSaveHandler getSaveHandler() { | ||||
return new FlowSingleSaveHandler(); | return new FlowSingleSaveHandler(); | ||||
@@ -25,6 +38,22 @@ public class FlowSingleService extends LCSingleService { | |||||
@Override | @Override | ||||
protected LCSingleDelHandler getDelHandler() { | protected LCSingleDelHandler getDelHandler() { | ||||
return super.getDelHandler(); | |||||
return new FlowDelHandler(); | |||||
} | |||||
protected R flowHandler(SwMap params, UserSession us, IWorker<FlowTransHandler> worker) { | |||||
try { | |||||
FlowTransHandler handler = (FlowTransHandler)getHandler(params, us, TYPE_FLOW); | |||||
return worker.doWork(handler); | |||||
} catch (Exception e) { | |||||
return R.error("操作失败!", e); | |||||
} | |||||
} | |||||
public R submit(@SwBody SwMap params, UserSession us) { | |||||
return flowHandler(params, us, FlowTransHandler::submit); | |||||
} | |||||
public R retake(@SwBody SwMap params, UserSession us) { | |||||
return flowHandler(params, us, FlowTransHandler::submit); | |||||
} | } | ||||
} | } |
@@ -0,0 +1,48 @@ | |||||
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; | |||||
import java.util.List; | |||||
/** | |||||
* Created by Akmm at 2022-09-01 15:03 | |||||
* 流程流转 | |||||
*/ | |||||
public class FlowTransHandler extends AbstractDynPageHandler implements FlowListener{ | |||||
//流程id | |||||
protected long billId; | |||||
//任务id | |||||
protected long taskId; | |||||
protected FlowInstance flowInstance; | |||||
private void loadFlowInstance() { | |||||
if (flowInstance == null) { | |||||
billId = params.readLong("id"); | |||||
taskId = params.readLong("taskId"); | |||||
flowInstance = FlowInstance.createById(us, this, billId, taskId); | |||||
} | |||||
} | |||||
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(params.readString("comment")); | |||||
return R.success(buildRetData()); | |||||
} | |||||
} |
@@ -122,7 +122,6 @@ public class LCMsSaveHandler extends LCSingleSaveHandler { | |||||
bean.setIsNew(true); | bean.setIsNew(true); | ||||
//暂时不考虑list保存的情况 | //暂时不考虑list保存的情况 | ||||
bean.getData().putAll(data); | bean.getData().putAll(data); | ||||
setNewId(bean); | |||||
} else { | } else { | ||||
bean = dao.queryEntity(id); | bean = dao.queryEntity(id); | ||||
if (bean == null) { | if (bean == null) { | ||||
@@ -29,7 +29,7 @@ public class LCNormalDelHandler extends LCSingleDelHandler { | |||||
//数据集 | //数据集 | ||||
String dataSet = params.readString("dataset"); | String dataSet = params.readString("dataset"); | ||||
PageDataset delDataSet = this.datasets.findByName(dataSet); | PageDataset delDataSet = this.datasets.findByName(dataSet); | ||||
Assert.notNull(delDataSet,"未获取到数据集:"+dataSet); | |||||
Assert.notNull(delDataSet, "未获取到数据集:" + dataSet); | |||||
// | // | ||||
checkBean(delDataSet, id); | checkBean(delDataSet, id); | ||||
// | // | ||||
@@ -50,7 +50,7 @@ public class LCNormalDelHandler extends LCSingleDelHandler { | |||||
AbstractCache cache = CacheManager.getIntance().getCache(table.getName()); | AbstractCache cache = CacheManager.getIntance().getCache(table.getName()); | ||||
cache.remove(id); | cache.remove(id); | ||||
} | } | ||||
localDelSuccess(id, table); | |||||
afterCommit(id, table); | |||||
} | } | ||||
}); | }); | ||||
return R.success(); | return R.success(); | ||||
@@ -57,17 +57,26 @@ public class LCSingleDelHandler extends AbstractDynPageHandler { | |||||
AbstractCache cache = CacheManager.getIntance().getCache(table.getName()); | AbstractCache cache = CacheManager.getIntance().getCache(table.getName()); | ||||
cache.remove(id); | cache.remove(id); | ||||
} | } | ||||
localDelSuccess(id, table); | |||||
afterCommit(id, table); | |||||
} | |||||
@Override | |||||
public void doAfterDbRollback() { | |||||
afterRollback(id); | |||||
} | } | ||||
}); | }); | ||||
return R.success(); | return R.success(); | ||||
} | } | ||||
protected void localDel(long id, ModelTable table) { | |||||
//回调:::删除之后 | |||||
protected void localDel(long id, ModelTable table) {} | |||||
//回调:::提交成功后 | |||||
protected void afterCommit(long id, ModelTable table) { | |||||
} | } | ||||
protected void localDelSuccess(long id, ModelTable table) { | |||||
//回调:::提交失败,事务回滚后 | |||||
protected void afterRollback(long id) { | |||||
} | } | ||||
@@ -18,14 +18,9 @@ public class LCSingleLoadHandler extends AbstractDynPageHandler { | |||||
SwMap ret = new SwMap(); | SwMap ret = new SwMap(); | ||||
//返回的数据,以dataset.name为key,查出的结果(bean或list)为value | //返回的数据,以dataset.name为key,查出的结果(bean或list)为value | ||||
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | ||||
SwMap data; | |||||
//懒加载,给个空对象 | |||||
if (cardDataset.lazy) { | |||||
data = new SwMap(); | |||||
} else { | |||||
data = DynPageHelper.createBean(cardDataset); | |||||
} | |||||
ret.put(cardDataset.name, data); | |||||
SwMap data = DynPageHelper.createBean(cardDataset); | |||||
ret.put(cardDataset.name, DynRetBean.createBean(data)); | |||||
afterAdd(ret, data); | afterAdd(ret, data); | ||||
return R.success(ret); | return R.success(ret); | ||||
@@ -48,7 +43,7 @@ public class LCSingleLoadHandler extends AbstractDynPageHandler { | |||||
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | ||||
SwMap data = provider.loadData(filter, cardDataset); | SwMap data = provider.loadData(filter, cardDataset); | ||||
ret.put(cardDataset.name, data); | |||||
ret.put(cardDataset.name, DynRetBean.createBean(data)); | |||||
afterLoad(ret, data); | afterLoad(ret, data); | ||||
return R.success(ret); | return R.success(ret); | ||||
@@ -35,10 +35,6 @@ import java.util.Map; | |||||
public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPageHandler { | public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPageHandler { | ||||
private Map<String, List<T>> mapTreeBean = new HashMap<>(); | private Map<String, List<T>> mapTreeBean = new HashMap<>(); | ||||
protected void setNewId(T bean) { | |||||
bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
} | |||||
/** | /** | ||||
* 保存指定数据集操作,入参:{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}} | * 保存指定数据集操作,入参:{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}} | ||||
*/ | */ | ||||
@@ -74,9 +70,14 @@ public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPag | |||||
afterRollback(bean); | afterRollback(bean); | ||||
} | } | ||||
}); | }); | ||||
return R.success(LCSingleHelper.buildRetData(pageDataSet.name, bean.getData())); | |||||
bean.removeStatus(); | |||||
SwMap ret = LCSingleHelper.buildRetData(pageDataSet.name, bean.getData()); | |||||
afterSave(ret, bean); | |||||
return R.success(ret); | |||||
} | } | ||||
protected void afterSave(SwMap ret, T bean) {} | |||||
/** | /** | ||||
* 从页面获取待保存的bean | * 从页面获取待保存的bean | ||||
* | * | ||||
@@ -93,17 +94,15 @@ public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPag | |||||
data = data.readMap("form"); | data = data.readMap("form"); | ||||
if (data == null) throw new BizException("没有找到待保存的表数据:" + pageDataSet.name); | if (data == null) throw new BizException("没有找到待保存的表数据:" + pageDataSet.name); | ||||
long id = data.readLong(table.getIdField()); | |||||
boolean isNew = data.readBool(DefaultEntity.statusKey); | |||||
EntityDao<T> dao = DbEngine.getInstance().findDao(table.getName()); | EntityDao<T> dao = DbEngine.getInstance().findDao(table.getName()); | ||||
T bean; | T bean; | ||||
if (id <= 0L) { | |||||
if (isNew) { | |||||
bean = dao.createBean(); | bean = dao.createBean(); | ||||
bean.setIsNew(true); | |||||
//暂时不考虑list保存的情况 | //暂时不考虑list保存的情况 | ||||
bean.getData().putAll(data); | bean.getData().putAll(data); | ||||
setNewId(bean); | |||||
} else { | } else { | ||||
long id = data.readLong(table.getIdField()); | |||||
bean = dao.queryEntity(id); | bean = dao.queryEntity(id); | ||||
if (bean == null) { | if (bean == null) { | ||||
throw new BizException("没有找到待保存的记录:" + table.getName() + "." + id); | throw new BizException("没有找到待保存的记录:" + table.getName() + "." + id); | ||||
@@ -9,9 +9,9 @@ import org.apache.commons.lang3.StringUtils; | |||||
* Created by Akmm at 2022-08-25 19:11 | * Created by Akmm at 2022-08-25 19:11 | ||||
*/ | */ | ||||
public class BillTypeSaveHandler extends LCSingleSaveHandler<BillType> { | public class BillTypeSaveHandler extends LCSingleSaveHandler<BillType> { | ||||
//id=code | |||||
@Override | @Override | ||||
protected void setNewId(BillType bean) { | |||||
protected void checkBean(BillType bean) { | |||||
super.checkBean(bean); | |||||
if (StringUtils.isEmpty(bean.getCode())) { | if (StringUtils.isEmpty(bean.getCode())) { | ||||
throw new BizException("编码不能为空!"); | throw new BizException("编码不能为空!"); | ||||
} | } | ||||
@@ -13,7 +13,8 @@ public class DictHandler { | |||||
static class DictSaveHandler extends DynPageSaveHandler { | static class DictSaveHandler extends DynPageSaveHandler { | ||||
@Override | @Override | ||||
protected void setNewId(DefaultEntity bean) { | |||||
protected void checkBean(DefaultEntity bean) { | |||||
super.checkBean(bean); | |||||
//字典 id用 类型id+编码 | //字典 id用 类型id+编码 | ||||
if (bean instanceof Dict) { | if (bean instanceof Dict) { | ||||
Dict dict = (Dict) bean; | Dict dict = (Dict) bean; | ||||
@@ -26,7 +27,6 @@ public class DictHandler { | |||||
dictType.setEntityId(NumberUtil.getLongIgnoreErr(dictType.getCode())); | dictType.setEntityId(NumberUtil.getLongIgnoreErr(dictType.getCode())); | ||||
return; | return; | ||||
} | } | ||||
super.setNewId(bean); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -14,12 +14,11 @@ import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler; | |||||
public class AreaHandler { | public class AreaHandler { | ||||
static class AreaSaveHandler extends DynPageSaveHandler { | static class AreaSaveHandler extends DynPageSaveHandler { | ||||
@Override | @Override | ||||
protected void setNewId(DefaultEntity bean) { | |||||
protected void checkBean(DefaultEntity bean) { | |||||
super.checkBean(bean); | |||||
if (bean instanceof Area) { | if (bean instanceof Area) { | ||||
Area area = (Area) bean; | Area area = (Area) bean; | ||||
area.setEntityId(NumberUtil.getLongIgnoreErr(area.getCode())); | area.setEntityId(NumberUtil.getLongIgnoreErr(area.getCode())); | ||||
} else { | |||||
super.setNewId(bean); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -42,7 +42,11 @@ public class UserGroupHelper { | |||||
* @return | * @return | ||||
*/ | */ | ||||
public static Set<Long> getUserIdList(long group_id, ProcInst pro_inst, int handle_range, UserSession us) { | public static Set<Long> getUserIdList(long group_id, ProcInst pro_inst, int handle_range, UserSession us) { | ||||
if (group_id <= 0L) return null;//未设置分组,默认true | |||||
if (group_id <= 0L) { | |||||
Set<Long> set = new HashSet<>(); | |||||
set.add(1L); | |||||
return set;//未设置分组,默认所有 | |||||
} | |||||
return null; | return null; | ||||
/* | /* | ||||
List<UserGroupItemEntity> items = UserGroupItemEntityBuffer.getInstance().getListByGroup(group_id); | List<UserGroupItemEntity> items = UserGroupItemEntityBuffer.getInstance().getListByGroup(group_id); | ||||
@@ -1,5 +1,7 @@ | |||||
<#--<#assign group_num =layout.flow[0].fields?size / param.group_num>--> | |||||
{ | { | ||||
"version": 6, | "version": 6, | ||||
<#-- "group_num":${group_num?ceiling},--> | |||||
"form": [ | "form": [ | ||||
{ | { | ||||
"page": { | "page": { | ||||
@@ -75,34 +77,46 @@ | |||||
{ | { | ||||
"type": "fx-button", | "type": "fx-button", | ||||
"props": { | "props": { | ||||
"name": "button:delete", | |||||
"label": "删除", | "label": "删除", | ||||
"leftIcon": "delete", | "leftIcon": "delete", | ||||
"action": "button:delCard" | "action": "button:delCard" | ||||
}, | }, | ||||
"id": "${newId()}" | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | }, | ||||
{ | { | ||||
"id": "${newId()}", | "id": "${newId()}", | ||||
"type": "fx-button", | "type": "fx-button", | ||||
"props": { | "props": { | ||||
"name": "button:new", | |||||
"label": "新增", | "label": "新增", | ||||
"type": "primary", | "type": "primary", | ||||
"leftIcon": "plus", | "leftIcon": "plus", | ||||
"action": "button:addCard" | "action": "button:addCard" | ||||
}, | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | } | ||||
}, | }, | ||||
{ | |||||
"id": "id182e345bb7b", | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "返回", | |||||
"type": "success", | |||||
"size": "default", | |||||
"action": "button:backList", | |||||
"leftIcon": "list-top" | |||||
}, | |||||
"events": {} | |||||
} | |||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:return", | |||||
"label": "返回", | |||||
"type": "success", | |||||
"size": "default", | |||||
"action": "button:backList", | |||||
"leftIcon": "list-top" | |||||
}, | |||||
"events": {}, | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
} | |||||
] | ] | ||||
} | } | ||||
} | } | ||||
@@ -112,25 +126,6 @@ | |||||
}, | }, | ||||
{ | { | ||||
"id": "${newId()}", | "id": "${newId()}", | ||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"size": "0" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-divider", | |||||
"props": { | |||||
"label": "", | |||||
"contentPosition": "center", | |||||
"direction": "horizontal" | |||||
} | |||||
} | |||||
] | |||||
}, | |||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-split-panel", | "type": "fx-split-panel", | ||||
"shape": "panel", | "shape": "panel", | ||||
"props": { | "props": { | ||||
@@ -140,262 +135,235 @@ | |||||
"name": "s12" | "name": "s12" | ||||
}, | }, | ||||
"children": [ | "children": [ | ||||
{ | |||||
<#list layout.flow as group> | |||||
"id": "${newId()}", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"size": "0", | |||||
<#if param.col lte 1> | |||||
"gridTemplateColumns": "1fr 2fr", | |||||
<#elseif param.col gte 2> | |||||
"gridTemplateColumns": "1fr 1fr 1fr", | |||||
</#if> | |||||
"paddingTop": 32 | |||||
}, | |||||
<#assign fields = group.fields> | |||||
"children": [ | |||||
<#list fields as field> | |||||
{ | |||||
"id": "id${newId()}", | |||||
<#if (field.readonly = true)> | |||||
"type": "fx-text", | |||||
<#else> | |||||
"type": "${field.editor}", | |||||
</#if> | |||||
"props": { | |||||
"label": "${field.label}", | |||||
"type": "text", | |||||
"dataset": "${field.dataset}", | |||||
"required": "${field.required}", | |||||
"field": "${field.id}", | |||||
<#if field.maxlength gt 0> | |||||
"maxlength": ${field.maxlength}, | |||||
</#if> | |||||
<#if field.lookup??> | |||||
"lookup": { | |||||
<#list field.lookup as k, v> | |||||
"${k}": "${v}" <#if k_has_next>,</#if> | |||||
</#list> | |||||
}, | |||||
</#if> | |||||
"placeholder": "请输入内容", | |||||
<#if (param.col = 2)> | |||||
"tips": "${field.desc}", | |||||
</#if> | |||||
"labelWidth": 100, | |||||
<#if (field.readonly = true)> | |||||
"readonly": true, | |||||
<#else> | |||||
"readonly": false, | |||||
</#if> | |||||
"affixError": true | |||||
}, | |||||
"events": {} | |||||
} | |||||
<#if field_has_next> | |||||
<#if (param.col lte 1 )> | |||||
<#if (field.desc != "")> | |||||
,{ | |||||
"id": "id181d83cdb41", | |||||
"type": "fx-label", | |||||
"props": { | |||||
"label": "${field.desc}", | |||||
"labelWidth": 0, | |||||
"affixError": true, | |||||
"labelAlign": "left" | |||||
} | |||||
} | |||||
<#else> | |||||
,{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-placeholder", | |||||
"props": { | |||||
"label": "占位" | |||||
}, | |||||
"layout": { | |||||
"row": 1 | |||||
} | |||||
} | |||||
</#if> | |||||
</#if> | |||||
<#if (param.col = 2 && ((field_index+1) % 2 = 0 ) )> | |||||
,{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-placeholder", | |||||
"props": { | |||||
"label": "占位" | |||||
}, | |||||
"layout": { | |||||
"row": 1 | |||||
} | |||||
} | |||||
</#if> | |||||
, | |||||
</#if> | |||||
</#list> | |||||
] | |||||
</#list> | |||||
}, | |||||
<#list layout.card as group> | |||||
<#assign field = group.fields> | |||||
{ | { | ||||
"id": "${newId()}", | "id": "${newId()}", | ||||
"type": "fx-form-panel", | "type": "fx-form-panel", | ||||
"shape": "panel", | "shape": "panel", | ||||
"props": { | "props": { | ||||
"size": "10", | |||||
"backgroundColor": "transparent" | |||||
"size": "10", | |||||
"backgroundColor": "--color-transparent" | |||||
}, | }, | ||||
"children": [] | "children": [] | ||||
}, | }, | ||||
{ | { | ||||
"id": "${newId()}", | "id": "${newId()}", | ||||
"type": "fx-split-panel", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | "shape": "panel", | ||||
"props": { | "props": { | ||||
"size": "48", | |||||
"horizontal": true | |||||
"size": "0", | |||||
<#if param.col lte 1> | |||||
"gridTemplateColumns": "1fr 2fr", | |||||
<#elseif param.col gte 2> | |||||
"gridTemplateColumns": "1fr 1fr 1fr", | |||||
</#if> | |||||
"paddingTop": 32 | |||||
}, | }, | ||||
"children": [ | "children": [ | ||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"size": "", | |||||
"label": "", | |||||
"colNum": 2, | |||||
"alignY": "center", | |||||
"paddingLeft": 32, | |||||
"paddingRight": 32, | |||||
"shadow": "", | |||||
"backgroundImage": "bgImg-region-title" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-title", | |||||
"props": { | |||||
"label": "子表列表配置", | |||||
"fontSize": 16, | |||||
"color": "#01070D", | |||||
"fontWeight": "bold", | |||||
"showPrefix": false, | |||||
"prefixWidth": 5, | |||||
"prefixHeight": 24, | |||||
"prefixColor": "#1E90FF" | |||||
} | |||||
} | |||||
] | |||||
}, | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"alignX": "center", | |||||
"size": "150", | |||||
"alignY": "center", | |||||
"backgroundImage": "bgImg-region-title" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "新增", | |||||
"type": "primary", | |||||
"action": "button:addRow", | |||||
"size": "default", | |||||
"linkType": "dialog", | |||||
"leftIcon": "plus", | |||||
"fxLink": "dialog:cardSubDialog", | |||||
"fxLink_text": "子表编辑卡片", | |||||
"nextAction": "", | |||||
"preAction": "", | |||||
"dataset": "${layout.listSub[0].dataset}" | |||||
}, | |||||
"events": {} | |||||
} | |||||
] | |||||
} | |||||
] | |||||
<#list group.fields as fields> | |||||
<#-- <#list num..(group.fields?size?number)!0 as i>--> | |||||
{ | |||||
"id": "id${newId()}", | |||||
<#if (fields.readonly = true)> | |||||
"type": "fx-text", | |||||
<#else> | |||||
"type": "${fields.editor}", | |||||
</#if> | |||||
"props": { | |||||
"label": "${fields.label}", | |||||
"type": "text", | |||||
"dataset": "${fields.dataset}", | |||||
"required": "${fields.required}", | |||||
"field": "${fields.id}", | |||||
<#if fields.maxlength gt 0> | |||||
"maxlength": ${fields.maxlength}, | |||||
</#if> | |||||
<#if fields.lookup??> | |||||
"lookup": { | |||||
<#list fields.lookup as k, v> | |||||
"${k}": "${v}" <#if k_has_next>,</#if> | |||||
</#list> | |||||
}, | |||||
</#if> | |||||
"placeholder": "请输入内容", | |||||
<#if (param.col = 2)> | |||||
"tips": "${fields.desc}", | |||||
</#if> | |||||
"labelWidth": 100, | |||||
<#if (fields.readonly = true)> | |||||
"readonly": true, | |||||
<#else> | |||||
"readonly": false, | |||||
</#if> | |||||
"affixError": true | |||||
}, | |||||
"events": {} | |||||
} | |||||
<#if fields_has_next> | |||||
<#if (param.col lte 1 )> | |||||
<#if (fields.desc != "")> | |||||
,{ | |||||
"id": "id181d83cdb41", | |||||
"type": "fx-label", | |||||
"props": { | |||||
"label": "${fields.desc}", | |||||
"labelWidth": 0, | |||||
"affixError": true, | |||||
"labelAlign": "left" | |||||
} | |||||
} | |||||
<#else> | |||||
,{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-placeholder", | |||||
"props": { | |||||
"label": "占位" | |||||
}, | |||||
"layout": { | |||||
"row": 1 | |||||
} | |||||
} | |||||
</#if> | |||||
</#if> | |||||
<#if (param.col = 2 && ((fields_index+1) % 2 = 0 ) )> | |||||
,{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-placeholder", | |||||
"props": { | |||||
"label": "占位" | |||||
}, | |||||
"layout": { | |||||
"row": 1 | |||||
} | |||||
} | |||||
</#if> | |||||
, | |||||
</#if> | |||||
</#list> | |||||
] | |||||
}, | |||||
<#-- <#if i+1 lt param.group_num?number>--> | |||||
<#-- ,--> | |||||
<#-- </#if>--> | |||||
<#-- </#list>--> | |||||
</#list> | |||||
<#list layout.flow as group> | |||||
<#assign field = group.fields> | |||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"size": "10", | |||||
"backgroundColor": "--color-transparent" | |||||
}, | |||||
"children": [] | |||||
}, | }, | ||||
{ | { | ||||
"id": "${newId()}", | "id": "${newId()}", | ||||
"type": "fx-form-panel", | "type": "fx-form-panel", | ||||
"shape": "panel", | "shape": "panel", | ||||
"props": { | "props": { | ||||
"size": "400", | |||||
"label": "列表", | |||||
"colNum": 0, | |||||
"paddingLeft": 20, | |||||
"paddingRight": 20, | |||||
"shadow": "", | |||||
"paddingTop": 0 | |||||
"size": "0", | |||||
<#if param.col lte 1> | |||||
"gridTemplateColumns": "1fr 2fr", | |||||
<#elseif param.col gte 2> | |||||
"gridTemplateColumns": "1fr 1fr 1fr", | |||||
</#if> | |||||
"paddingTop": 32 | |||||
}, | }, | ||||
"children": [ | "children": [ | ||||
<#list group.fields as fields> | |||||
<#-- <#list num..(group.fields?size?number)!0 as i>--> | |||||
{ | { | ||||
"id": "id${newId()}", | "id": "id${newId()}", | ||||
"type": "fx-table", | |||||
<#if (fields.readonly = true)> | |||||
"type": "fx-text", | |||||
<#else> | |||||
"type": "${fields.editor}", | |||||
</#if> | |||||
"props": { | |||||
"label": "${fields.label}", | |||||
"type": "text", | |||||
"dataset": "${fields.dataset}", | |||||
"required": "${fields.required}", | |||||
"field": "${fields.id}", | |||||
<#if fields.maxlength gt 0> | |||||
"maxlength": ${fields.maxlength}, | |||||
</#if> | |||||
<#if fields.lookup??> | |||||
"lookup": { | |||||
<#list fields.lookup as k, v> | |||||
"${k}": "${v}" <#if k_has_next>,</#if> | |||||
</#list> | |||||
}, | |||||
</#if> | |||||
"placeholder": "请输入内容", | |||||
<#if (param.col = 2)> | |||||
"tips": "${fields.desc}", | |||||
</#if> | |||||
"labelWidth": 100, | |||||
<#if (fields.readonly = true)> | |||||
"readonly": true, | |||||
<#else> | |||||
"readonly": false, | |||||
</#if> | |||||
"affixError": true | |||||
}, | |||||
"events": {} | |||||
} | |||||
<#if fields_has_next> | |||||
<#if (param.col lte 1 )> | |||||
<#if (fields.desc != "")> | |||||
,{ | |||||
"id": "id181d83cdb41", | |||||
"type": "fx-label", | |||||
"props": { | |||||
"label": "${fields.desc}", | |||||
"labelWidth": 0, | |||||
"affixError": true, | |||||
"labelAlign": "left" | |||||
} | |||||
} | |||||
<#else> | |||||
,{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-placeholder", | |||||
"props": { | "props": { | ||||
"label": "表格", | |||||
"border": true, | |||||
"stripe": true, | |||||
"showHeader": true, | |||||
"fit": true, | |||||
"dataset": "${group.dataset}", | |||||
"actionWidth": 150 | |||||
"label": "占位" | |||||
}, | }, | ||||
"slots": { | |||||
"default": [ | |||||
<#list layout.comment[0].fields as field> | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-table-column", | |||||
"props": { | |||||
"field": "${field.id}", | |||||
"label": "${field.label}" | |||||
} | |||||
} | |||||
<#if field_has_next>,</#if> | |||||
</#list> | |||||
], | |||||
"button": [ | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "编辑", | |||||
"type": "text", | |||||
"leftIcon": "edit", | |||||
"action": "button:edit", | |||||
"dataset": "${layout.listSub[0].dataset}", | |||||
"link": true, | |||||
"linkType": "", | |||||
"nextAction": "", | |||||
"fxLink": "" | |||||
} | |||||
}, | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "删除", | |||||
"type": "text", | |||||
"leftIcon": "delete-themes", | |||||
"action": "button:remove", | |||||
"preAction": "", | |||||
"link": true, | |||||
"confirm": "" | |||||
} | |||||
} | |||||
] | |||||
"layout": { | |||||
"row": 1 | |||||
} | |||||
} | |||||
</#if> | |||||
</#if> | |||||
<#if (param.col = 2 && ((fields_index+1) % 2 = 0 ) )> | |||||
,{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-placeholder", | |||||
"props": { | |||||
"label": "占位" | |||||
}, | }, | ||||
"events": {} | |||||
"layout": { | |||||
"row": 1 | |||||
} | |||||
} | } | ||||
</#if> | |||||
, | |||||
</#if> | |||||
</#list> | |||||
] | ] | ||||
} | } | ||||
<#-- <#if i+1 lt param.group_num?number>--> | |||||
<#-- ,--> | |||||
<#-- </#if>--> | |||||
<#-- </#list>--> | |||||
</#list> | |||||
] | ] | ||||
}, | }, | ||||
{ | { | ||||
@@ -418,94 +386,269 @@ | |||||
"alignX": "center" | "alignX": "center" | ||||
}, | }, | ||||
"children": [ | "children": [ | ||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-button-group", | |||||
"props": { | |||||
"menus": [] | |||||
}, | |||||
"slots": { | |||||
"default": [ | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:save-and-new", | |||||
"label": "保存并新增", | |||||
"type": "primary", | |||||
"action": "button:saveAddCard", | |||||
"linkType": "curr" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:save", | |||||
"label": "保存", | |||||
"type": "success", | |||||
"action": "button:saveCard" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:submit", | |||||
"label": "提交", | |||||
"type": "primary", | |||||
"action": "button:submit" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:retake", | |||||
"label": "取回", | |||||
"type": "info", | |||||
"action": "button:retake" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:reject", | |||||
"label": "驳回", | |||||
"type": "warning", | |||||
"action": "button:reject" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:disuse", | |||||
"label": "作废", | |||||
"type": "danger", | |||||
"action": "button:cancel" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"name": "button:interrupt", | |||||
"label": "终止", | |||||
"type": "danger", | |||||
"action": "button:interrupt" | |||||
}, | |||||
"id": "${newId()}", | |||||
"vars": { | |||||
"$ref": "$ref" | |||||
} | |||||
} | |||||
] | |||||
} | |||||
} | |||||
] | |||||
}, | |||||
{ | { | ||||
"id": "${newId()}", | "id": "${newId()}", | ||||
"type": "fx-button-group", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | "props": { | ||||
"menus": [] | |||||
"size": "16", | |||||
"backgroundColor": "--color-transparent" | |||||
}, | }, | ||||
"slots": { | |||||
"default": [ | |||||
"children": [] | |||||
} | |||||
] | |||||
} | |||||
}, | |||||
{ | |||||
"page": { | |||||
"id": "id182f81da2e3", | |||||
"type": "fx-dialog", | |||||
"props": { | |||||
"title": "审批意见", | |||||
"key": "dlgOpt", | |||||
"width": "450px", | |||||
"height": "260px", | |||||
"showPrefix": true | |||||
}, | |||||
"events": {} | |||||
}, | |||||
"graph": { | |||||
"shape": "panel", | |||||
"id": "root_panel", | |||||
"type": "fx-split-panel", | |||||
"props": { | |||||
"horizontal": false, | |||||
"shadow": "never" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "182f81da2e6", | |||||
"type": "fx-split-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"horizontal": false | |||||
}, | |||||
"children": [ | |||||
{ | { | ||||
"type": "fx-button", | |||||
"shape": "panel", | |||||
"id": "form_panel", | |||||
"type": "fx-form-panel", | |||||
"props": { | "props": { | ||||
"label": "保存并新增", | |||||
"type": "primary", | |||||
"action": "button:saveAddCard", | |||||
"linkType": "curr" | |||||
"colNum": 1, | |||||
"paddingTop": 24, | |||||
"size": "0" | |||||
}, | }, | ||||
"id": "${newId()}" | |||||
"children": [ | |||||
{ | |||||
"id": "id182f81da30b", | |||||
"type": "fx-select", | |||||
"props": { | |||||
"label": "备选意见", | |||||
"clearable": true, | |||||
"labelWidth": 100, | |||||
"affixError": true, | |||||
"size": "default" | |||||
}, | |||||
"events": {} | |||||
}, | |||||
{ | |||||
"id": "id182f81da30e", | |||||
"type": "fx-textarea", | |||||
"props": { | |||||
"label": "处理意见", | |||||
"maxlength": 200, | |||||
"placeholder": "请输入内容", | |||||
"labelWidth": 100, | |||||
"affixError": true, | |||||
"size": "default", | |||||
"dataset": "ds_182edc699cc", | |||||
"field": "id_182edc699cd", | |||||
"rows": 4 | |||||
}, | |||||
"events": {} | |||||
} | |||||
] | |||||
}, | }, | ||||
{ | { | ||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "保存", | |||||
"leftIcon": "save", | |||||
"type": "success", | |||||
"action": "button:saveCard" | |||||
}, | |||||
"id": "${newId()}" | |||||
},{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "提交", | |||||
"leftIcon": "save", | |||||
"type": "success", | |||||
"action": "button:submit" | |||||
}, | |||||
"id": "${newId()}" | |||||
},{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "取回", | |||||
"leftIcon": "save", | |||||
"type": "success", | |||||
"action": "button:retake" | |||||
}, | |||||
"id": "${newId()}" | |||||
},{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "驳回", | |||||
"leftIcon": "save", | |||||
"type": "success", | |||||
"action": "button:reject" | |||||
}, | |||||
"id": "${newId()}" | |||||
},{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "作废", | |||||
"leftIcon": "save", | |||||
"type": "success", | |||||
"action": "button:cancel" | |||||
}, | |||||
"id": "${newId()}" | |||||
},{ | |||||
"type": "fx-button", | |||||
"id": "182f81da311", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": {}, | |||||
"children": [] | |||||
} | |||||
] | |||||
}, | |||||
{ | |||||
"id": "182f81da2e7", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"size": "0" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "id182f81da2e8", | |||||
"type": "fx-divider", | |||||
"props": { | "props": { | ||||
"label": "终止", | |||||
"leftIcon": "save", | |||||
"type": "success", | |||||
"action": "button:interrupt" | |||||
}, | |||||
"id": "${newId()}" | |||||
"label": "", | |||||
"contentPosition": "center", | |||||
"direction": "horizontal" | |||||
} | |||||
} | } | ||||
] | |||||
} | |||||
} | |||||
] | |||||
] | |||||
}, | }, | ||||
{ | |||||
"id": "${newId()}", | |||||
{ | |||||
"id": "182f81da2e4", | |||||
"type": "fx-form-panel", | "type": "fx-form-panel", | ||||
"shape": "panel", | "shape": "panel", | ||||
"props": { | "props": { | ||||
"size": "16", | |||||
"backgroundColor": "--color-transparent" | |||||
"size": "50", | |||||
"alignX": "end", | |||||
"alignY": "center", | |||||
"paddingRight": 10 | |||||
}, | }, | ||||
"children": [] | |||||
} | |||||
"children": [ | |||||
{ | |||||
"id": "id182f81da303", | |||||
"type": "fx-button-group", | |||||
"props": { | |||||
"showDropdown": false | |||||
}, | |||||
"slots": { | |||||
"default": [ | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "确认", | |||||
"leftIcon": "correct", | |||||
"type": "primary", | |||||
"action": "button:dlgDynConfirm", | |||||
"linkType": "" | |||||
}, | |||||
"id": "id182f81da304", | |||||
"events": {} | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "取消", | |||||
"leftIcon": "error", | |||||
"action": "button:closeDialog" | |||||
}, | |||||
"id": "id182f81da308", | |||||
"events": {} | |||||
} | |||||
], | |||||
"dropdown": [] | |||||
} | |||||
} | |||||
] | |||||
} | |||||
] | ] | ||||
} | } | ||||
} | } | ||||
@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.annotation.SwColumnForeign; | |||||
import cc.smtweb.framework.core.annotation.SwTable; | import cc.smtweb.framework.core.annotation.SwTable; | ||||
import cc.smtweb.framework.core.cache.CacheManager; | import cc.smtweb.framework.core.cache.CacheManager; | ||||
import cc.smtweb.framework.core.common.SwEnum; | import cc.smtweb.framework.core.common.SwEnum; | ||||
import cc.smtweb.framework.core.db.DbEngine; | |||||
import cc.smtweb.framework.core.exception.SwException; | import cc.smtweb.framework.core.exception.SwException; | ||||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | import cc.smtweb.framework.core.db.cache.ModelTableCache; | ||||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | import cc.smtweb.framework.core.db.impl.DefaultEntity; | ||||
@@ -66,8 +67,8 @@ public abstract class AbstractEntityDao<T> { | |||||
tableName = table.value(); | tableName = table.value(); | ||||
modelTable = ModelTableCache.getInstance().getByName(tableName); | modelTable = ModelTableCache.getInstance().getByName(tableName); | ||||
if(null == modelTable){ | |||||
log.error("未找到缓存表结构:"+tableName); | |||||
if (null == modelTable) { | |||||
log.error("未找到缓存表结构:" + tableName); | |||||
} | } | ||||
if (DefaultEntity.class.isAssignableFrom(type)) { | if (DefaultEntity.class.isAssignableFrom(type)) { | ||||
for (ModelField field : modelTable.getFields()) { | for (ModelField field : modelTable.getFields()) { | ||||
@@ -292,7 +293,7 @@ public abstract class AbstractEntityDao<T> { | |||||
private EntityColumn findIdColumn() { | private EntityColumn findIdColumn() { | ||||
ModelField field = modelTable.findIdField(); | ModelField field = modelTable.findIdField(); | ||||
EntityColumn idColumn = field != null ? columns.get(field.getName()) : null; | |||||
EntityColumn idColumn = field != null ? columns.get(field.getName()): null; | |||||
if (idColumn == null) { | if (idColumn == null) { | ||||
throw new DbException(tableName + " not define id column"); | throw new DbException(tableName + " not define id column"); | ||||
} | } | ||||
@@ -402,11 +403,26 @@ public abstract class AbstractEntityDao<T> { | |||||
DefaultEntity b = (DefaultEntity) bean; | DefaultEntity b = (DefaultEntity) bean; | ||||
b.init(); | b.init(); | ||||
b.setTableName(this.tableName); | b.setTableName(this.tableName); | ||||
b.setIsNew(true); | |||||
} | } | ||||
return bean; | return bean; | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new SwException(e); | throw new SwException(e); | ||||
} | } | ||||
} | } | ||||
public T createBean(long userId) { | |||||
T b = createBean(); | |||||
if (b instanceof DefaultEntity) { | |||||
DefaultEntity bean = (DefaultEntity) b; | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | |||||
ModelField field = table.findFieldByType(SwEnum.FieldType.CREATE_USER.value); | |||||
if (field != null) bean.put(field.getName(), userId); | |||||
field = table.findFieldByType(SwEnum.FieldType.UPDATE_USER.value); | |||||
if (field != null) bean.put(field.getName(), userId); | |||||
} | |||||
return b; | |||||
} | |||||
} | } | ||||
@@ -16,8 +16,8 @@ import java.io.Serializable; | |||||
*/ | */ | ||||
public class DefaultEntity extends BaseBean implements Serializable, Cloneable { | public class DefaultEntity extends BaseBean implements Serializable, Cloneable { | ||||
//表名 | //表名 | ||||
private final static String tableNameKey = "_def_table_name"; | |||||
private final static String statusKey = "_status"; | |||||
public final static String tableNameKey = "_def_table_name"; | |||||
public final static String statusKey = "_status"; | |||||
public DefaultEntity() { | public DefaultEntity() { | ||||
} | } | ||||
@@ -2,6 +2,7 @@ package cc.smtweb.framework.core.mvc.service; | |||||
import cc.smtweb.framework.core.annotation.SwBody; | import cc.smtweb.framework.core.annotation.SwBody; | ||||
import cc.smtweb.framework.core.common.R; | import cc.smtweb.framework.core.common.R; | ||||
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.exception.SwException; | import cc.smtweb.framework.core.exception.SwException; | ||||
import cc.smtweb.framework.core.common.SwMap; | import cc.smtweb.framework.core.common.SwMap; | ||||
@@ -41,17 +42,17 @@ public abstract class AbstractCompService { | |||||
//保存 | //保存 | ||||
public R save(@SwBody SwMap params, UserSession us) { | public R save(@SwBody SwMap params, UserSession us) { | ||||
return pageHandler(params, us, TYPE_SAVE, handler -> ((AbstractSaveHandler)handler).save()); | |||||
return pageHandler(params, us, TYPE_SAVE, handler -> ((DefaultSaveHandler)handler).save()); | |||||
} | } | ||||
//树,换爹 | //树,换爹 | ||||
public R trcp(@SwBody SwMap params, UserSession us) { | public R trcp(@SwBody SwMap params, UserSession us) { | ||||
return pageHandler(params, us, TYPE_SAVE, handler -> ((AbstractSaveHandler)handler).changeParent()); | |||||
return pageHandler(params, us, TYPE_SAVE, handler -> ((DefaultSaveHandler)handler).changeParent()); | |||||
} | } | ||||
//读取 | //读取 | ||||
public R load(@SwBody SwMap params, UserSession us) { | public R load(@SwBody SwMap params, UserSession us) { | ||||
return pageHandler(params, us, TYPE_LOAD, handler -> ((AbstractLoadHandler)handler).load()); | |||||
return pageHandler(params, us, TYPE_LOAD, handler -> ((DefaultLoadHandler)handler).load()); | |||||
} | } | ||||
//删除 | //删除 | ||||
@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.common.R; | |||||
/** | /** | ||||
* Created by Akmm at 2022/3/2 19:44 | * Created by Akmm at 2022/3/2 19:44 | ||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class AbstractLoadHandler<T> extends AbstractHandler { | public abstract class AbstractLoadHandler<T> extends AbstractHandler { | ||||
public R load() { | public R load() { | ||||
@@ -10,12 +10,11 @@ import lombok.extern.slf4j.Slf4j; | |||||
* 保存 | * 保存 | ||||
*/ | */ | ||||
@Slf4j | @Slf4j | ||||
@Deprecated | |||||
public abstract class AbstractSaveHandler<T> extends AbstractHandler { | public abstract class AbstractSaveHandler<T> extends AbstractHandler { | ||||
protected T bean; | protected T bean; | ||||
protected boolean isNew; | protected boolean isNew; | ||||
public R save() { | public R save() { | ||||
long id = readId(); | long id = readId(); | ||||
@@ -1,5 +1,6 @@ | |||||
package cc.smtweb.framework.core.mvc.service; | package cc.smtweb.framework.core.mvc.service; | ||||
import cc.smtweb.framework.core.common.R; | |||||
import cc.smtweb.framework.core.common.SwEnum; | import cc.smtweb.framework.core.common.SwEnum; | ||||
import cc.smtweb.framework.core.db.DbEngine; | import cc.smtweb.framework.core.db.DbEngine; | ||||
import cc.smtweb.framework.core.db.EntityDao; | import cc.smtweb.framework.core.db.EntityDao; | ||||
@@ -12,25 +13,27 @@ import cc.smtweb.framework.core.db.vo.ModelTable; | |||||
* Created by Akmm at 2022/3/2 19:52 | * Created by Akmm at 2022/3/2 19:52 | ||||
* 默认实体实现 | * 默认实体实现 | ||||
*/ | */ | ||||
public class DefaultLoadHandler<T extends DefaultEntity> extends AbstractLoadHandler<T> { | |||||
public class DefaultLoadHandler<T extends DefaultEntity> extends AbstractHandler { | |||||
protected String tableName; | protected String tableName; | ||||
public DefaultLoadHandler(String tableName) { | |||||
this.tableName = tableName; | |||||
public R load() { | |||||
long id = params.readLong("id", 0L); | |||||
T bean; | |||||
final EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | |||||
if (id <= 0L) { | |||||
bean = dao.createBean(us.getUserId()); | |||||
bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
} else { | |||||
bean = dao.queryEntity(id); | |||||
} | |||||
afterLoad(bean); | |||||
return R.success(bean); | |||||
} | } | ||||
@Override | |||||
protected T createComp() { | |||||
final EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | |||||
T bean = dao.createBean(); | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | |||||
ModelField field = table.findFieldByType(SwEnum.FieldType.CREATE_USER.value); | |||||
if (field != null) bean.put(field.getName(), us.getUserId()); | |||||
return bean; | |||||
public DefaultLoadHandler(String tableName) { | |||||
this.tableName = tableName; | |||||
} | } | ||||
@Override | |||||
protected T loadComp(long id) { | |||||
return new DefaultProvider<T>(tableName).getBean(id); | |||||
protected void afterLoad(T bean) { | |||||
} | } | ||||
} | } |
@@ -22,8 +22,9 @@ import java.util.List; | |||||
* Created by Akmm at 2022/3/2 19:52 | * Created by Akmm at 2022/3/2 19:52 | ||||
* 默认实体实现 | * 默认实体实现 | ||||
*/ | */ | ||||
public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHandler<T> { | |||||
public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractHandler{ | |||||
protected String tableName; | protected String tableName; | ||||
protected T bean; | |||||
private List<T> listTreeBean = null; | private List<T> listTreeBean = null; | ||||
@@ -31,41 +32,44 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
this.tableName = tableName; | this.tableName = tableName; | ||||
} | } | ||||
@Override | |||||
protected T createComp() { | |||||
final EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | |||||
T bean = dao.createBean(); | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | |||||
ModelField field = table.findFieldByType(SwEnum.FieldType.CREATE_USER.value); | |||||
if (field != null) bean.put(field.getName(), us.getUserId()); | |||||
field = table.findFieldByType(SwEnum.FieldType.UPDATE_USER.value); | |||||
if (field != null) bean.put(field.getName(), us.getUserId()); | |||||
return bean; | |||||
} | |||||
@Override | |||||
protected long readId() { | |||||
public R save() { | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
return params.readLong(table.getIdField()); | |||||
} | |||||
long id = params.readLong(table.getIdField()); | |||||
boolean isNew = params.readBool(DefaultEntity.statusKey) || id <= 0L; | |||||
final EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | |||||
if (isNew) { | |||||
bean = dao.createBean(us.getUserId()); | |||||
} else { | |||||
bean = dao.queryEntity(id); | |||||
} | |||||
readFromPage(); | |||||
if (bean.getEntityId() <= 0L) bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
checkValid(); | |||||
DbEngine.getInstance().doTrans(new AbsDbWorker() { | |||||
@Override | |||||
public void work(){ | |||||
saveDb(); | |||||
} | |||||
@Override | |||||
protected void setNewId() { | |||||
bean.setEntityId(DbEngine.getInstance().nextId()); | |||||
} | |||||
@Override | |||||
public void doAfterDbCommit(){ | |||||
saveSuccess(); | |||||
} | |||||
@Override | |||||
protected T loadComp(long id) { | |||||
return new DefaultProvider<T>(tableName).getBean(id); | |||||
@Override | |||||
public void doAfterDbRollback(){ | |||||
saveFailed(); | |||||
} | |||||
}); | |||||
bean.removeStatus(); | |||||
return R.success(bean); | |||||
} | } | ||||
@Override | |||||
protected void readFromPage() { | protected void readFromPage() { | ||||
bean.readFromMap(params); | bean.readFromMap(params); | ||||
bean.setIsNew(isNew); | |||||
} | } | ||||
@Override | |||||
protected void checkValid() { | protected void checkValid() { | ||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
for (ModelField field : table.getFields()) { | for (ModelField field : table.getFields()) { | ||||
@@ -85,10 +89,9 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
} | } | ||||
} | } | ||||
@Override | |||||
protected void saveDb() { | protected void saveDb() { | ||||
EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | ||||
if (isNew) { | |||||
if (bean.isNew()) { | |||||
insertBean(dao); | insertBean(dao); | ||||
} else { | } else { | ||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
@@ -113,9 +116,7 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
} | } | ||||
@Override | |||||
protected void saveSuccess() { | protected void saveSuccess() { | ||||
super.saveSuccess(); | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
if (table.isNeedCache()) { | if (table.isNeedCache()) { | ||||
AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | ||||
@@ -130,9 +131,7 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
} | } | ||||
} | } | ||||
@Override | |||||
protected void saveFailed() { | protected void saveFailed() { | ||||
super.saveFailed(); | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
if (table.isNeedCache()) { | if (table.isNeedCache()) { | ||||
AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | ||||
@@ -148,11 +147,12 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
long id = params.readLong("id"); | long id = params.readLong("id"); | ||||
long parentId = params.readLong("parent_id"); | long parentId = params.readLong("parent_id"); | ||||
final EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | |||||
AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | ||||
if (table.isNeedCache()) { | if (table.isNeedCache()) { | ||||
bean = cache.get(id); | bean = cache.get(id); | ||||
} else { | } else { | ||||
bean = loadComp(id); | |||||
bean = dao.queryEntity(id); | |||||
} | } | ||||
TreeHelper.getTreeHelper(tableName).checkParent(bean); | TreeHelper.getTreeHelper(tableName).checkParent(bean); | ||||
//不考虑没有级次码等情况,这个在表设计时校验 | //不考虑没有级次码等情况,这个在表设计时校验 | ||||
@@ -162,7 +162,6 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
DbEngine.getInstance().doTrans(new AbsDbWorker() { | DbEngine.getInstance().doTrans(new AbsDbWorker() { | ||||
@Override | @Override | ||||
public void work() { | public void work() { | ||||
EntityDao dao = DbEngine.getInstance().findDao(tableName); | |||||
listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | ||||
dao.updateEntity(bean, fieldParentId.getName()); | dao.updateEntity(bean, fieldParentId.getName()); | ||||
} | } | ||||
@@ -6,6 +6,6 @@ import cc.smtweb.framework.core.common.R; | |||||
* Created by Akmm at 2022/3/2 19:01 | * Created by Akmm at 2022/3/2 19:01 | ||||
* 所有handler的接口 | * 所有handler的接口 | ||||
*/ | */ | ||||
public interface IWorker { | |||||
R doWork(AbstractHandler handler); | |||||
public interface IWorker<T extends AbstractHandler> { | |||||
R doWork(T handler); | |||||
} | } |