Procházet zdrojové kódy

代码调整:add即返回id,根据_status判断是否新增

4.0
郑根木 před 2 roky
rodič
revize
a852cbe539
27 změnil soubory, kde provedl 197 přidání a 146 odebrání
  1. +4
    -4
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcLoadHandler.java
  2. +1
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcSaveHandler.java
  3. +2
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java
  4. +11
    -10
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageSaveHandler.java
  5. +2
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynRetBean.java
  6. +7
    -10
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java
  7. +5
    -5
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowListener.java
  8. +0
    -15
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowLoadHandler.java
  9. +3
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java
  10. +1
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java
  11. +0
    -6
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java
  12. +29
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java
  13. +38
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java
  14. +0
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsSaveHandler.java
  15. +4
    -9
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java
  16. +4
    -9
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java
  17. +2
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeSaveHandler.java
  18. +2
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictHandler.java
  19. +2
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaHandler.java
  20. +19
    -3
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java
  21. +2
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultEntity.java
  22. +4
    -3
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java
  23. +1
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractLoadHandler.java
  24. +1
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractSaveHandler.java
  25. +17
    -14
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultLoadHandler.java
  26. +34
    -35
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java
  27. +2
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/IWorker.java

+ 4
- 4
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcLoadHandler.java Zobrazit soubor

@@ -1,6 +1,8 @@
package cc.smtweb.system.bpm.web.design.flow;

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.mvc.service.DefaultLoadHandler;

@@ -13,17 +15,15 @@ public class ModelProcLoadHandler extends DefaultLoadHandler<ModelProc> {
}

@Override
protected ModelProc loadComp(long id) {
ModelProc bean = super.loadComp(id);
protected void afterLoad(ModelProc bean) {
bean.getData().remove("prc_content");
return bean;
}


//页面设计 - 加载页面model定义
public R loadModel() {
long id = params.readLong("id");
ModelProc bean = super.loadComp(id);
ModelProc bean = ModelProcCache.getInstance().get(id);
if (bean == null) throw new BizException("没有找到指定定义信息!id=" + id);
return R.success(bean.getContent());
}


+ 1
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcSaveHandler.java Zobrazit soubor

@@ -60,7 +60,7 @@ public class ModelProcSaveHandler extends DefaultSaveHandler<ModelProc> {
public R saveModel() {
long id = params.readLong("id");
String data = params.readString("data");
bean = loadComp(id);
bean = ModelProcCache.getInstance().get(id);
if (StringUtils.isEmpty(data)) {
throw new BizException("没有待保存的数据!");
}


+ 2
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java Zobrazit soubor

@@ -75,7 +75,7 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> {
public R saveDataset() {
long id = params.readLong("id");
String data = params.readString("data");
bean = loadComp(id);
bean = ModelFormCache.getInstance().get(id);
if (StringUtils.isEmpty(data)) {
throw new BizException("没有待保存的数据!");
}
@@ -107,7 +107,7 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> {
public R saveModel() {
long id = params.readLong("id");
String data = params.readString("data");
bean = loadComp(id);
bean = ModelFormCache.getInstance().get(id);
if (StringUtils.isEmpty(data)) {
throw new BizException("没有待保存的数据!");
}


+ 11
- 10
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageSaveHandler.java Zobrazit soubor

@@ -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.ModelTable;
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.util.StringUtil;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
@@ -33,10 +34,6 @@ import java.util.Map;
public class DynPageSaveHandler extends AbstractDynPageHandler {
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:{}}
*/
@@ -50,6 +47,8 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
//对应的数据集定义
PageDataset pageDataSet = findDataset(dbName);
if (pageDataSet == null) throw new BizException("没有找到指定的的数据集定义:" + dbName + "!");
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable);

//读取待保存的bean
DefaultEntity bean = readBeanFromPage(pageDataSet, data.readMap("form"));
if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上
@@ -73,6 +72,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
afterRollback(bean);
}
});
bean.removeStatus();
return R.success(DynRetBean.createBean(bean.getData()));
}

@@ -133,6 +133,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
});
Map<String, DynRetBean> mapRet = new HashMap<>(map.size());
for (Map.Entry<String, DefaultEntity> entry : map.entrySet()) {
entry.getValue().getData().remove(DefaultEntity.statusKey);
mapRet.put(entry.getKey(), DynRetBean.createBean(entry.getValue().getData()));
}
return R.success(mapRet);
@@ -148,16 +149,17 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap data) {
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable);
if (table == null) throw new BizException("没有找到待保存的表定义:" + pageDataSet.name);
long id = data.readLong(table.getIdField());

long id = params.readLong(table.getIdField());
boolean isNew = params.readBool(DefaultEntity.statusKey) || id <= 0L;

EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(table.getName());
DefaultEntity bean;
if (id <= 0L) {
bean = dao.createBean();
bean.setIsNew(true);
if (isNew) {
bean = dao.createBean(us.getUserId());
//暂时不考虑list保存的情况
bean.getData().putAll(data);
setNewId(bean);
if (bean.getEntityId() <= 0L) bean.setEntityId(DbEngine.getInstance().nextId());
} else {
bean = dao.queryEntity(id);
if (bean == null) {
@@ -165,7 +167,6 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
}
//暂时不考虑list保存的情况
bean.getData().putAll(data);
bean.setIsNew(false);
}

return bean;


+ 2
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynRetBean.java Zobrazit soubor

@@ -23,8 +23,8 @@ public class DynRetBean {
SwMap form = (SwMap) swMap.clone();
DynRetBean bean = new DynRetBean();
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;
}



+ 7
- 10
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java Zobrazit soubor

@@ -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.define.Activity;
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.sys.user.dept.Dept;
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.PartyCache;
import cc.smtweb.system.bpm.web.sys.user.user.UserCache;
import cc.smtweb.system.bpm.web.sys.user.userGroup.UserGroupHelper;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@@ -184,7 +181,7 @@ public class FlowInstance {
getProcInstDao().updateEntity(procInst);

buildBillLog(FlowConst.Button.HANDLE.value, "-", actInst, null);
listener.handle(actInst);
listener.afterHandle(actInst);
}

//从页面参数加载流程实例
@@ -593,7 +590,7 @@ public class FlowInstance {
getProcInstDao().updateEntity(procInst);

buildBillLog(FlowConst.Button.SUBMIT.value, "TODO", actInst, listInsertTask);
listener.submit(actInst, listInsertTask);
listener.afterSubmit(actInst, listInsertTask);
}


@@ -637,7 +634,7 @@ public class FlowInstance {
getProcInstDao().updateEntity(procInst);

buildBillLog(FlowConst.Button.DISUSE.value, "TODO", actInst, null);
listener.disuse(actInst);
listener.afterDisuse(actInst);
}

/**
@@ -739,7 +736,7 @@ public class FlowInstance {
new_acts.clear();
new_acts.add(old_act);
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);
} else {
List<Task> new_acts = provider.findAfterTasks(actInst.getId());
@@ -765,7 +762,7 @@ public class FlowInstance {
getProcInstDao().updateEntity(procInst);

buildBillLog(FlowConst.Button.RETAKE.value, "TODO", actInst, new_acts);
listener.retake(actInst, new_acts);
listener.afterRetake(actInst, new_acts);
}
}

@@ -814,7 +811,7 @@ public class FlowInstance {
getProcInstDao().updateEntity(procInst);

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

@@ -858,7 +855,7 @@ public class FlowInstance {
make_acts.add(make_act);

buildBillLog(FlowConst.Button.REJECT.value, "TODO", actInst, make_acts);
listener.reject(actInst, make_acts);
listener.afterReject(actInst, make_acts);
}

/**


+ 5
- 5
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowListener.java Zobrazit soubor

@@ -13,14 +13,14 @@ public interface FlowListener {
//设置条件计算参数
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) {}

}

+ 0
- 15
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowLoadHandler.java Zobrazit soubor

@@ -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 {


}

+ 3
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java Zobrazit soubor

@@ -40,7 +40,7 @@ public class FlowProvider extends AbstractCompProvider {
return doGetData("a_" + taskId, () -> {
EntityDao<Task> bdao = DbEngine.getInstance().findDao(Task.class);
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);
return bean;
});
@@ -98,10 +98,10 @@ public class FlowProvider extends AbstractCompProvider {

//寻找流程的制单任务
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) {
return DbEngine.getInstance().findDao(Comment.class).queryWhere("where cmt_pri_id=? order by cmt_end_time");
return DbEngine.getInstance().findDao(Comment.class).queryWhere(" cmt_pri_id=? order by cmt_end_time", bill_id);
}
}

+ 1
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java Zobrazit soubor

@@ -53,7 +53,7 @@ public class FlowSingleLoadHandler extends LCSingleLoadHandler implements FlowLi
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);

SwMap data = provider.loadData(filter, cardDataset);
ret.put(cardDataset.name, data);
ret.put(cardDataset.name, DynRetBean.createBean(data));

//加载流程信息
flowInstance = FlowInstance.createById(us,this, id, taskId);


+ 0
- 6
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java Zobrazit soubor

@@ -18,12 +18,6 @@ public class FlowSingleSaveHandler<T extends DefaultEntity> extends LCSingleSave
protected FlowInstance flowInstance;

@Override
public R save() {

return super.save();
}

@Override
protected T readBeanFromPage(PageDataset pageDataSet, SwMap pageData) {
T bean = super.readBeanFromPage(pageDataSet, pageData);



+ 29
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java Zobrazit soubor

@@ -1,7 +1,13 @@
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.common.R;
import cc.smtweb.framework.core.common.SwMap;
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.LCSingleLoadHandler;
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
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
protected LCSingleSaveHandler getSaveHandler() {
return new FlowSingleSaveHandler();
@@ -27,4 +40,20 @@ public class FlowSingleService extends LCSingleService {
protected LCSingleDelHandler 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);
}
}

+ 38
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java Zobrazit soubor

@@ -0,0 +1,38 @@
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.system.bpm.web.engine.dynPage.AbstractDynPageHandler;
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);
}
}

public R submit() {
loadFlowInstance();
flowInstance.submit();
return R.success();
}

}

+ 0
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsSaveHandler.java Zobrazit soubor

@@ -122,7 +122,6 @@ public class LCMsSaveHandler extends LCSingleSaveHandler {
bean.setIsNew(true);
//暂时不考虑list保存的情况
bean.getData().putAll(data);
setNewId(bean);
} else {
bean = dao.queryEntity(id);
if (bean == null) {


+ 4
- 9
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java Zobrazit soubor

@@ -19,14 +19,9 @@ public class LCSingleLoadHandler extends AbstractDynPageHandler {
SwMap ret = new SwMap();
//返回的数据,以dataset.name为key,查出的结果(bean或list)为value
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);
return R.success(ret);
@@ -49,7 +44,7 @@ public class LCSingleLoadHandler extends AbstractDynPageHandler {
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets);

SwMap data = provider.loadData(filter, cardDataset);
ret.put(cardDataset.name, data);
ret.put(cardDataset.name, DynRetBean.createBean(data));

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


+ 4
- 9
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java Zobrazit soubor

@@ -35,10 +35,6 @@ import java.util.Map;
public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPageHandler {
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:{}}
*/
@@ -74,6 +70,7 @@ public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPag
afterRollback(bean);
}
});
bean.removeStatus();
return R.success(LCSingleHelper.buildRetData(pageDataSet.name, bean.getData()));
}

@@ -93,17 +90,15 @@ public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPag
data = data.readMap("form");
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());
T bean;
if (id <= 0L) {
if (isNew) {
bean = dao.createBean();
bean.setIsNew(true);
//暂时不考虑list保存的情况
bean.getData().putAll(data);
setNewId(bean);
} else {
long id = data.readLong(table.getIdField());
bean = dao.queryEntity(id);
if (bean == null) {
throw new BizException("没有找到待保存的记录:" + table.getName() + "." + id);


+ 2
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeSaveHandler.java Zobrazit soubor

@@ -9,9 +9,9 @@ import org.apache.commons.lang3.StringUtils;
* Created by Akmm at 2022-08-25 19:11
*/
public class BillTypeSaveHandler extends LCSingleSaveHandler<BillType> {
//id=code
@Override
protected void setNewId(BillType bean) {
protected void checkBean(BillType bean) {
super.checkBean(bean);
if (StringUtils.isEmpty(bean.getCode())) {
throw new BizException("编码不能为空!");
}


+ 2
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictHandler.java Zobrazit soubor

@@ -13,7 +13,8 @@ public class DictHandler {
static class DictSaveHandler extends DynPageSaveHandler {

@Override
protected void setNewId(DefaultEntity bean) {
protected void checkBean(DefaultEntity bean) {
super.checkBean(bean);
//字典 id用 类型id+编码
if (bean instanceof Dict) {
Dict dict = (Dict) bean;
@@ -26,7 +27,6 @@ public class DictHandler {
dictType.setEntityId(NumberUtil.getLongIgnoreErr(dictType.getCode()));
return;
}
super.setNewId(bean);
}
}
}

+ 2
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaHandler.java Zobrazit soubor

@@ -14,12 +14,11 @@ import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler;
public class AreaHandler {
static class AreaSaveHandler extends DynPageSaveHandler {
@Override
protected void setNewId(DefaultEntity bean) {
protected void checkBean(DefaultEntity bean) {
super.checkBean(bean);
if (bean instanceof Area) {
Area area = (Area) bean;
area.setEntityId(NumberUtil.getLongIgnoreErr(area.getCode()));
} else {
super.setNewId(bean);
}
}
}


+ 19
- 3
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java Zobrazit soubor

@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.annotation.SwColumnForeign;
import cc.smtweb.framework.core.annotation.SwTable;
import cc.smtweb.framework.core.cache.CacheManager;
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.db.cache.ModelTableCache;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
@@ -66,8 +67,8 @@ public abstract class AbstractEntityDao<T> {

tableName = table.value();
modelTable = ModelTableCache.getInstance().getByName(tableName);
if(null == modelTable){
log.error("未找到缓存表结构:"+tableName);
if (null == modelTable) {
log.error("未找到缓存表结构:" + tableName);
}
if (DefaultEntity.class.isAssignableFrom(type)) {
for (ModelField field : modelTable.getFields()) {
@@ -292,7 +293,7 @@ public abstract class AbstractEntityDao<T> {

private EntityColumn findIdColumn() {
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) {
throw new DbException(tableName + " not define id column");
}
@@ -402,11 +403,26 @@ public abstract class AbstractEntityDao<T> {
DefaultEntity b = (DefaultEntity) bean;
b.init();
b.setTableName(this.tableName);
b.setIsNew(true);
}
return bean;
} catch (Exception 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;

}
}


+ 2
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultEntity.java Zobrazit soubor

@@ -16,8 +16,8 @@ import java.io.Serializable;
*/
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() {
}


+ 4
- 3
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java Zobrazit soubor

@@ -2,6 +2,7 @@ package cc.smtweb.framework.core.mvc.service;

import cc.smtweb.framework.core.annotation.SwBody;
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.SwException;
import cc.smtweb.framework.core.common.SwMap;
@@ -41,17 +42,17 @@ public abstract class AbstractCompService {

//保存
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) {
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) {
return pageHandler(params, us, TYPE_LOAD, handler -> ((AbstractLoadHandler)handler).load());
return pageHandler(params, us, TYPE_LOAD, handler -> ((DefaultLoadHandler)handler).load());
}

//删除


+ 1
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractLoadHandler.java Zobrazit soubor

@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.common.R;
/**
* Created by Akmm at 2022/3/2 19:44
*/
@Deprecated
public abstract class AbstractLoadHandler<T> extends AbstractHandler {

public R load() {


+ 1
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractSaveHandler.java Zobrazit soubor

@@ -10,12 +10,11 @@ import lombok.extern.slf4j.Slf4j;
* 保存
*/
@Slf4j
@Deprecated
public abstract class AbstractSaveHandler<T> extends AbstractHandler {
protected T bean;
protected boolean isNew;



public R save() {
long id = readId();



+ 17
- 14
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultLoadHandler.java Zobrazit soubor

@@ -1,5 +1,6 @@
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.db.DbEngine;
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
* 默认实体实现
*/
public class DefaultLoadHandler<T extends DefaultEntity> extends AbstractLoadHandler<T> {
public class DefaultLoadHandler<T extends DefaultEntity> extends AbstractHandler {
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) {
}
}

+ 34
- 35
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java Zobrazit soubor

@@ -22,8 +22,9 @@ import java.util.List;
* 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 T bean;

private List<T> listTreeBean = null;

@@ -31,41 +32,44 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan
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);
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() {
bean.readFromMap(params);
bean.setIsNew(isNew);
}

@Override
protected void checkValid() {
ModelTable table = ModelTableCache.getInstance().getByName(tableName);
for (ModelField field : table.getFields()) {
@@ -85,10 +89,9 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan
}
}

@Override
protected void saveDb() {
EntityDao<T> dao = DbEngine.getInstance().findDao(tableName);
if (isNew) {
if (bean.isNew()) {
insertBean(dao);
} else {
ModelTable table = ModelTableCache.getInstance().getByName(tableName);
@@ -113,9 +116,7 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan
}


@Override
protected void saveSuccess() {
super.saveSuccess();
ModelTable table = ModelTableCache.getInstance().getByName(tableName);
if (table.isNeedCache()) {
AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName);
@@ -130,9 +131,7 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan
}
}

@Override
protected void saveFailed() {
super.saveFailed();
ModelTable table = ModelTableCache.getInstance().getByName(tableName);
if (table.isNeedCache()) {
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 parentId = params.readLong("parent_id");

final EntityDao<T> dao = DbEngine.getInstance().findDao(tableName);
AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName);
if (table.isNeedCache()) {
bean = cache.get(id);
} else {
bean = loadComp(id);
bean = dao.queryEntity(id);
}
TreeHelper.getTreeHelper(tableName).checkParent(bean);
//不考虑没有级次码等情况,这个在表设计时校验
@@ -162,7 +162,6 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan
DbEngine.getInstance().doTrans(new AbsDbWorker() {
@Override
public void work() {
EntityDao dao = DbEngine.getInstance().findDao(tableName);
listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean);
dao.updateEntity(bean, fieldParentId.getName());
}


+ 2
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/IWorker.java Zobrazit soubor

@@ -6,6 +6,6 @@ import cc.smtweb.framework.core.common.R;
* Created by Akmm at 2022/3/2 19:01
* 所有handler的接口
*/
public interface IWorker {
R doWork(AbstractHandler handler);
public interface IWorker<T extends AbstractHandler> {
R doWork(T handler);
}

Načítá se…
Zrušit
Uložit