@@ -4,11 +4,19 @@ 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.R; | ||||
import cc.smtweb.framework.core.common.SwMap; | import cc.smtweb.framework.core.common.SwMap; | ||||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||||
import cc.smtweb.framework.core.db.vo.ModelField; | |||||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||||
import cc.smtweb.framework.core.mvc.service.AbstractCompService; | import cc.smtweb.framework.core.mvc.service.AbstractCompService; | ||||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | import cc.smtweb.framework.core.mvc.service.AbstractHandler; | ||||
import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; | import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; | ||||
import cc.smtweb.framework.core.mvc.service.DefaultListHandler; | import cc.smtweb.framework.core.mvc.service.DefaultListHandler; | ||||
import cc.smtweb.framework.core.session.UserSession; | import cc.smtweb.framework.core.session.UserSession; | ||||
import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; | |||||
import cc.smtweb.system.bpm.web.engine.flow.entity.ProcInst; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
/** | /** | ||||
* Created by Akmm at 2022/3/22 9:12 | * Created by Akmm at 2022/3/22 9:12 | ||||
@@ -40,5 +48,20 @@ public class ModelProcService extends AbstractCompService { | |||||
public R loadModel(@SwBody SwMap params, UserSession us) { | public R loadModel(@SwBody SwMap params, UserSession us) { | ||||
return pageHandler(params, us, TYPE_LOAD, handler -> ((ModelProcLoadHandler)handler).loadModel()); | return pageHandler(params, us, TYPE_LOAD, handler -> ((ModelProcLoadHandler)handler).loadModel()); | ||||
} | } | ||||
//加载工作流的列表字段 | |||||
public R loadProcInstFields(@SwBody SwMap params, UserSession us) { | |||||
ModelTable table = ModelTableCache.getInstance().get(ProcInst.ENTITY_NAME); | |||||
if (table == null) return R.error("没有找到表定义信息(table=" + ProcInst.ENTITY_NAME + ")!"); | |||||
List<SwMap> ret = new ArrayList<>(); | |||||
for (ModelField field : table.getFields()) { | |||||
SwMap col = new SwMap(2); | |||||
ModelFormHelper.buildFieldInfo(table, field, col); | |||||
ret.add(col); | |||||
} | |||||
return R.success(ret); | |||||
} | |||||
} | } |
@@ -32,10 +32,10 @@ import java.util.Map; | |||||
* 保存操作 | * 保存操作 | ||||
* 入参:{pageId, data:} | * 入参:{pageId, data:} | ||||
*/ | */ | ||||
public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
private Map<String, List<DefaultEntity>> mapTreeBean = new HashMap<>(); | |||||
public class LCSingleSaveHandler<T extends DefaultEntity> extends AbstractDynPageHandler { | |||||
private Map<String, List<T>> mapTreeBean = new HashMap<>(); | |||||
protected void setNewId(DefaultEntity bean) { | |||||
protected void setNewId(T bean) { | |||||
bean.setEntityId(DbEngine.getInstance().nextId()); | bean.setEntityId(DbEngine.getInstance().nextId()); | ||||
} | } | ||||
@@ -52,7 +52,7 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
//对应的数据集定义 | //对应的数据集定义 | ||||
PageDataset pageDataSet = LCSingleHelper.findCardDataset(datasets); | PageDataset pageDataSet = LCSingleHelper.findCardDataset(datasets); | ||||
//读取待保存的bean | //读取待保存的bean | ||||
DefaultEntity bean = readBeanFromPage(pageDataSet, data); | |||||
T bean = readBeanFromPage(pageDataSet, data); | |||||
if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上 | if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上 | ||||
setLinkValue(pageDataSet, bean, f -> filter.get(f.name)); | setLinkValue(pageDataSet, bean, f -> filter.get(f.name)); | ||||
} | } | ||||
@@ -84,7 +84,7 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
* @param data | * @param data | ||||
* @return | * @return | ||||
*/ | */ | ||||
protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap pageData) { | |||||
protected T readBeanFromPage(PageDataset pageDataSet, SwMap pageData) { | |||||
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); | ||||
@@ -95,8 +95,8 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
long id = data.readLong(table.getIdField()); | long id = data.readLong(table.getIdField()); | ||||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(table.getName()); | |||||
DefaultEntity bean; | |||||
EntityDao<T> dao = DbEngine.getInstance().findDao(table.getName()); | |||||
T bean; | |||||
if (id <= 0L) { | if (id <= 0L) { | ||||
bean = dao.createBean(); | bean = dao.createBean(); | ||||
bean.setIsNew(true); | bean.setIsNew(true); | ||||
@@ -121,7 +121,7 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
* | * | ||||
* @param bean | * @param bean | ||||
*/ | */ | ||||
protected void checkBean(DefaultEntity bean) { | |||||
protected void checkBean(T bean) { | |||||
ModelTable table = ModelTableCache.getInstance().getByName(bean.getTableName()); | ModelTable table = ModelTableCache.getInstance().getByName(bean.getTableName()); | ||||
for (ModelField field : table.getFields()) { | for (ModelField field : table.getFields()) { | ||||
String value = bean.getStr(field.getName()); | String value = bean.getStr(field.getName()); | ||||
@@ -139,7 +139,7 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
} | } | ||||
} | } | ||||
//唯一键校验 | //唯一键校验 | ||||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(bean.getTableName()); | |||||
EntityDao<T> dao = DbEngine.getInstance().findDao(bean.getTableName()); | |||||
for (ModelIndex mi : table.getIndexes()) { | for (ModelIndex mi : table.getIndexes()) { | ||||
if (mi.isUnique()) { | if (mi.isUnique()) { | ||||
dao.checkUnique(bean, mi.getFields().split(",")); | dao.checkUnique(bean, mi.getFields().split(",")); | ||||
@@ -147,9 +147,9 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
} | } | ||||
} | } | ||||
protected void saveBean(DefaultEntity bean) { | |||||
protected void saveBean(T bean) { | |||||
final String tableName = bean.getTableName(); | final String tableName = bean.getTableName(); | ||||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(tableName); | |||||
EntityDao<T> dao = DbEngine.getInstance().findDao(tableName); | |||||
if (bean.isNew()) { | if (bean.isNew()) { | ||||
dao.insertEntity(bean); | dao.insertEntity(bean); | ||||
} else { | } else { | ||||
@@ -159,18 +159,18 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
dao.updateEntity(bean); | dao.updateEntity(bean); | ||||
if (table.getType() == SwEnum.TableType.TYPE_TREE.value) { | if (table.getType() == SwEnum.TableType.TYPE_TREE.value) { | ||||
List<DefaultEntity> listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | |||||
List<T> listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | |||||
mapTreeBean.put(tableName, listTreeBean); | mapTreeBean.put(tableName, listTreeBean); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
protected void afterCommit(DefaultEntity bean) { | |||||
protected void afterCommit(T bean) { | |||||
final String tableName = bean.getTableName(); | final String tableName = bean.getTableName(); | ||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
if (table.isNeedCache()) { | if (table.isNeedCache()) { | ||||
AbstractCache<DefaultEntity> cache = CacheManager.getIntance().getCache(tableName); | AbstractCache<DefaultEntity> cache = CacheManager.getIntance().getCache(tableName); | ||||
List<DefaultEntity> listTreeBean = mapTreeBean.get(tableName); | |||||
List<T> listTreeBean = mapTreeBean.get(tableName); | |||||
//树型表,父亲改变了,要多处理下缓存;还有个东东:级次码 | //树型表,父亲改变了,要多处理下缓存;还有个东东:级次码 | ||||
if (listTreeBean != null && !listTreeBean.isEmpty()) { | if (listTreeBean != null && !listTreeBean.isEmpty()) { | ||||
for (DefaultEntity b : listTreeBean) { | for (DefaultEntity b : listTreeBean) { | ||||
@@ -182,17 +182,17 @@ public class LCSingleSaveHandler extends AbstractDynPageHandler { | |||||
} | } | ||||
} | } | ||||
protected void afterRollback(DefaultEntity bean) { | |||||
protected void afterRollback(T bean) { | |||||
final String tableName = bean.getTableName(); | final String tableName = bean.getTableName(); | ||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
if (table.isNeedCache()) { | if (table.isNeedCache()) { | ||||
AbstractCache<DefaultEntity> cache = CacheManager.getIntance().getCache(tableName); | |||||
AbstractCache<T> cache = CacheManager.getIntance().getCache(tableName); | |||||
cache.reset(bean); | cache.reset(bean); | ||||
} | } | ||||
} | } | ||||
//将关联的值设上 | //将关联的值设上 | ||||
protected void setLinkValue(PageDataset pageDataSet, DefaultEntity bean, IGetValue iGetValue) { | |||||
protected void setLinkValue(PageDataset pageDataSet, T bean, IGetValue iGetValue) { | |||||
ModelTable table = ModelTableCache.getInstance().getByName(bean.getTableName()); | ModelTable table = ModelTableCache.getInstance().getByName(bean.getTableName()); | ||||
for (PageDatasetFilter f : pageDataSet.filters) { | for (PageDatasetFilter f : pageDataSet.filters) { | ||||
String v = bean.getStr(f.field); | String v = bean.getStr(f.field); | ||||
@@ -27,15 +27,27 @@ public class LCSingleService extends DynPageService { | |||||
case TYPE_MODEL_LIST: | case TYPE_MODEL_LIST: | ||||
case TYPE_MODEL_LOAD: | case TYPE_MODEL_LOAD: | ||||
case TYPE_MODEL_ADD: | case TYPE_MODEL_ADD: | ||||
return new LCSingleLoadHandler(); | |||||
return getLoadHandler(); | |||||
case TYPE_MODEL_SAVE: | case TYPE_MODEL_SAVE: | ||||
return new LCSingleSaveHandler(); | |||||
return getSaveHandler(); | |||||
case TYPE_MODEL_DEL: | case TYPE_MODEL_DEL: | ||||
return new LCSingleDelHandler(); | |||||
return getDelHandler(); | |||||
} | } | ||||
return super.createHandler(type); | return super.createHandler(type); | ||||
} | } | ||||
protected LCSingleSaveHandler getSaveHandler() { | |||||
return new LCSingleSaveHandler(); | |||||
} | |||||
protected LCSingleLoadHandler getLoadHandler() { | |||||
return new LCSingleLoadHandler(); | |||||
} | |||||
protected LCSingleDelHandler getDelHandler() { | |||||
return new LCSingleDelHandler(); | |||||
} | |||||
//保存 | //保存 | ||||
public R modelSave(@SwBody SwMap params, UserSession us) { | public R modelSave(@SwBody SwMap params, UserSession us) { | ||||
return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCSingleSaveHandler)handler).save()); | return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCSingleSaveHandler)handler).save()); | ||||
@@ -0,0 +1,55 @@ | |||||
package cc.smtweb.system.bpm.web.sys.base.billType; | |||||
import cc.smtweb.framework.core.annotation.SwTable; | |||||
import cc.smtweb.framework.core.common.SwMap; | |||||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||||
/** | |||||
* Created by 1 at 2022-08-25 18:13:32 | |||||
* 实体【[单据类型](SYS_BILL_TYPE)】的Entity类 | |||||
*/ | |||||
@SwTable("SYS_BILL_TYPE") | |||||
public class BillType extends DefaultEntity { | |||||
public static final String ENTITY_NAME = "SYS_BILL_TYPE"; | |||||
public BillType() { | |||||
super(ENTITY_NAME); | |||||
} | |||||
/** 主键 */ | |||||
public long getId() { | |||||
return getLong("sbtp_id"); | |||||
} | |||||
/** 主键 */ | |||||
public void setId(long sbtp_id) { | |||||
put("sbtp_id", sbtp_id); | |||||
} | |||||
/** 编码 */ | |||||
public String getCode() { | |||||
return getStr("sbtp_code"); | |||||
} | |||||
/** 编码 */ | |||||
public void setCode(String sbtp_code) { | |||||
put("sbtp_code", sbtp_code); | |||||
} | |||||
/** 名称 */ | |||||
public String getName() { | |||||
return getStr("sbtp_name"); | |||||
} | |||||
/** 名称 */ | |||||
public void setName(String sbtp_name) { | |||||
put("sbtp_name", sbtp_name); | |||||
} | |||||
/** 备注 */ | |||||
public String getRemark() { | |||||
return getStr("sbtp_remark"); | |||||
} | |||||
/** 备注 */ | |||||
public void setRemark(String sbtp_remark) { | |||||
put("sbtp_remark", sbtp_remark); | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
package cc.smtweb.system.bpm.web.sys.base.billType; | |||||
import cc.smtweb.framework.core.annotation.SwCache; | |||||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||||
import cc.smtweb.framework.core.cache.CacheManager; | |||||
/** | |||||
* Created by 1 at 2022-08-25 18:13:32 | |||||
* 实体【[单据类型](SYS_BILL_TYPE)】的缓存类 | |||||
*/ | |||||
@SwCache(ident = "SYS_BILL_TYPE", title = "单据类型") | |||||
public class BillTypeCache extends AbstractEntityCache<BillType> { | |||||
//缓存key:按编码 | |||||
public final static String mk_code = "code"; | |||||
public static BillTypeCache getInstance() { | |||||
return CacheManager.getIntance().getCache(BillTypeCache.class); | |||||
} | |||||
public BillTypeCache() { | |||||
//缓存key:按编码 | |||||
regMap(mk_code, "sbtp_code"); | |||||
} | |||||
//缓存key:按编码 | |||||
public final BillType getByCode(String key) { | |||||
return getByKey(mk_code, key); | |||||
} | |||||
public String getName(long id) { | |||||
BillType bean = get(id); | |||||
return bean != null ? bean.getName() : String.valueOf(id); | |||||
} | |||||
} |
@@ -0,0 +1,21 @@ | |||||
package cc.smtweb.system.bpm.web.sys.base.billType; | |||||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||||
import cc.smtweb.framework.core.exception.BizException; | |||||
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; | |||||
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) { | |||||
if (StringUtils.isEmpty(bean.getCode())) { | |||||
throw new BizException("编码不能为空!"); | |||||
} | |||||
bean.setId(Long.parseLong(bean.getCode())); | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
package cc.smtweb.system.bpm.web.sys.base.billType; | |||||
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.mvc.service.DefaultComboHandler; | |||||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; | |||||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||||
import cc.smtweb.framework.core.session.UserSession; | |||||
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; | |||||
import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleService; | |||||
/** | |||||
* Created by 1 at 2022-08-25 18:44:57 | |||||
* 页面【[单据类型列表]的服务类 | |||||
*/ | |||||
@SwService | |||||
public class BillTypeService extends LCSingleService { | |||||
@Override | |||||
protected AbstractHandler createHandler(String type) { | |||||
if (TYPE_COMBO.equals(type)) return new DefaultComboHandler<BillType>(BillType.ENTITY_NAME); | |||||
return super.createHandler(type); | |||||
} | |||||
@Override | |||||
protected LCSingleSaveHandler getSaveHandler() { | |||||
return new BillTypeSaveHandler(); | |||||
} | |||||
} |