@@ -0,0 +1,84 @@ | |||
package cc.smtweb.system.bpm.web.engine.model.listcard.single; | |||
import cc.smtweb.framework.core.cache.AbstractCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
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; | |||
import cc.smtweb.framework.core.db.EntityHelper; | |||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.db.jdbc.AbsDbWorker; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDatasetFilter; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* Created by Akmm at 2022/4/21 17:53 | |||
* 删除操作 | |||
*/ | |||
public class LCSingleDelHandler extends AbstractDynPageHandler { | |||
/** | |||
* 删除指定数据集,入参{pageId, dataset, id} | |||
* | |||
* @return | |||
*/ | |||
public R del() { | |||
long id = params.readLong("id"); | |||
if (id == 0L) throw new BizException("没有收到待删除记录Id(" + id + ")!"); | |||
//数据集 | |||
PageDataset pageDataSet = LCSingleHelper.findCardDataset(datasets); | |||
checkBean(pageDataSet, id); | |||
DbEngine.getInstance().doTrans(new AbsDbWorker() { | |||
@Override | |||
public void work() { | |||
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable); | |||
if (table == null) throw new BizException("没有找到指定的的表定义:" + pageDataSet.name + "!"); | |||
EntityDao dao = DbEngine.getInstance().findDao(table.getName()); | |||
dao.deleteEntity(id); | |||
localDel(id, table); | |||
} | |||
@Override | |||
public void doAfterDbCommit() { | |||
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable); | |||
if (table.isNeedCache()) { | |||
AbstractCache cache = CacheManager.getIntance().getCache(table.getName()); | |||
cache.remove(id); | |||
} | |||
localDelSuccess(id, table); | |||
} | |||
}); | |||
return R.success(); | |||
} | |||
protected void localDel(long id, ModelTable table) { | |||
} | |||
protected void localDelSuccess(long id, ModelTable table) { | |||
} | |||
/** | |||
* 删除校验 | |||
* | |||
* @param pageDataSet | |||
* @param id | |||
*/ | |||
protected void checkBean(PageDataset pageDataSet, long id) { | |||
//校验外键引用关系 | |||
EntityHelper.checkExists(pageDataSet.masterTable, id); | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
package cc.smtweb.system.bpm.web.engine.model.listcard.single; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.exception.SwException; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDatasets; | |||
/** | |||
* Created by Akmm at 2022-08-16 16:07 | |||
* 常量定义 | |||
*/ | |||
public interface LCSingleHelper { | |||
String DATASET_NAME_LIST = "list"; | |||
String DATASET_NAME_CARD = "card"; | |||
static PageDataset findCardDataset(PageDatasets datasets) { | |||
PageDataset cardDataset = datasets.findByName(DATASET_NAME_CARD); | |||
if (cardDataset == null) throw new SwException("没有找到卡片数据集!"); | |||
if (!SwEnum.DatasetType.FORM.value.equals(cardDataset.type)) {//单表 | |||
throw new SwException("卡片数据集定义错误!"); | |||
} | |||
return cardDataset; | |||
} | |||
static PageDataset findListDataset(PageDatasets datasets) { | |||
PageDataset cardDataset = datasets.findByName(DATASET_NAME_LIST); | |||
if (cardDataset == null) throw new SwException("没有找到列表数据集!"); | |||
if (!SwEnum.DatasetType.LIST.value.equals(cardDataset.type)) {//列表 | |||
throw new SwException("列表数据集定义错误!"); | |||
} | |||
return cardDataset; | |||
} | |||
} |
@@ -0,0 +1,92 @@ | |||
package cc.smtweb.system.bpm.web.engine.model.listcard.single; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageHelper; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean; | |||
/** | |||
* Created by Akmm at 2022-08-16 15:43 | |||
*/ | |||
public class LCSingleLoadHandler extends AbstractDynPageHandler { | |||
//新增卡片操作,初始化定义的数据集 | |||
public R add() { | |||
//返回的数据,以dataset.name为key,查出的结果(bean或list)为value | |||
SwMap mapRet = new SwMap(); | |||
PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); | |||
SwMap data; | |||
//懒加载,给个空对象 | |||
if (cardDataset.lazy) { | |||
data = new SwMap(); | |||
} else { | |||
data = DynPageHelper.createBean(cardDataset); | |||
} | |||
afterAddBean(cardDataset, data); | |||
mapRet.put(cardDataset.name, DynRetBean.createBean(data)); | |||
return R.success(mapRet); | |||
} | |||
//新增初始化 - bean | |||
protected void afterAddBean(PageDataset dataset, SwMap bean) { | |||
} | |||
//加载之后 | |||
protected void afterLoadBean(PageDataset dataset, SwMap bean) { | |||
} | |||
public R load() { | |||
//过滤条件 | |||
SwMap filter = params.readMap("filter"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = LCSingleHelper.findCardDataset(datasets); | |||
DynRetBean bean = null; | |||
SwMap data = provider.loadData(filter, pageDataSet); | |||
afterLoadBean(pageDataSet, data); | |||
bean = DynRetBean.createBean(data); | |||
return R.success(bean); | |||
} | |||
protected DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new DynPageListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
/** | |||
* 列表数据 | |||
* @return | |||
*/ | |||
public R list() { | |||
//过滤条件 | |||
SwMap filter = params.readMap("filter"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = LCSingleHelper.findListDataset(datasets); | |||
DynRetBean bean = DynRetBean.createList(getListWorker(filter, pageDataSet).buildListData()); | |||
return R.success(bean); | |||
} | |||
/** | |||
* 计算分页数据 | |||
* | |||
* @return | |||
*/ | |||
public R getTotal() { | |||
//数据集 | |||
PageDataset pageDataSet = LCSingleHelper.findListDataset(datasets); | |||
//过滤条件 | |||
SwMap filter = params.readMap("filter"); | |||
return getListWorker(filter, pageDataSet).getTotal(); | |||
} | |||
} |
@@ -0,0 +1,212 @@ | |||
package cc.smtweb.system.bpm.web.engine.model.listcard.single; | |||
import cc.smtweb.framework.core.cache.AbstractCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.EntityDao; | |||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.db.jdbc.AbsDbWorker; | |||
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.TreeHelper; | |||
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.PageDatasetFilter; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.AbstractDynPageHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.HashMap; | |||
import java.util.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* Created by Akmm at 2022/4/21 17:53 | |||
* 保存操作 | |||
* 入参:{pageId, data:} | |||
*/ | |||
public class LCSingleSaveHandler 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:{}} | |||
*/ | |||
public R save() { | |||
//数据集 | |||
String dbName = params.readString("dataset"); | |||
SwMap filter = params.readMap("filter"); | |||
//待保存数据 | |||
SwMap data = params.readMap("data"); | |||
if (data == null) throw new BizException("没有收到待保存的的数据:" + dbName + "!"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = LCSingleHelper.findCardDataset(datasets); | |||
//读取待保存的bean | |||
DefaultEntity bean = readBeanFromPage(pageDataSet, data.readMap("form")); | |||
if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上 | |||
setLinkValue(pageDataSet, bean, f -> filter.get(f.name)); | |||
} | |||
checkBean(bean); | |||
DbEngine.getInstance().doTrans(new AbsDbWorker() { | |||
@Override | |||
public void work() { | |||
saveBean(bean); | |||
} | |||
@Override | |||
public void doAfterDbCommit() { | |||
afterCommit(bean); | |||
} | |||
@Override | |||
public void doAfterDbRollback() { | |||
afterRollback(bean); | |||
} | |||
}); | |||
return R.success(DynRetBean.createBean(bean.getData())); | |||
} | |||
/** | |||
* 从页面获取待保存的bean | |||
* | |||
* @param pageDataSet | |||
* @param data | |||
* @return | |||
*/ | |||
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()); | |||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(table.getName()); | |||
DefaultEntity bean; | |||
if (id <= 0L) { | |||
bean = dao.createBean(); | |||
bean.setIsNew(true); | |||
//暂时不考虑list保存的情况 | |||
bean.getData().putAll(data); | |||
setNewId(bean); | |||
} else { | |||
bean = dao.queryEntity(id); | |||
if (bean == null) { | |||
throw new BizException("没有找到待保存的记录:" + table.getName() + "." + id); | |||
} | |||
//暂时不考虑list保存的情况 | |||
bean.getData().putAll(data); | |||
bean.setIsNew(false); | |||
} | |||
return bean; | |||
} | |||
/** | |||
* 保存校验 | |||
* | |||
* @param bean | |||
*/ | |||
protected void checkBean(DefaultEntity bean) { | |||
ModelTable table = ModelTableCache.getInstance().getByName(bean.getTableName()); | |||
for (ModelField field : table.getFields()) { | |||
String value = bean.getStr(field.getName()); | |||
//非空校验 | |||
if (field.isNotNull() && StringUtils.isEmpty(value)) { | |||
throw new BizException("字段不允许为空:" + field.getTitle()); | |||
} | |||
//长度校验 | |||
if (StringUtils.isNotEmpty(value)) { | |||
int len = SwEnum.DataType.instance.getByValue(field.getDataType()).dataLength; | |||
if (len > 0 && StringUtil.getStrLenB(value) > len) { | |||
throw new BizException("字段值超长:" + field.getTitle()); | |||
} | |||
} | |||
} | |||
//唯一键校验 | |||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(bean.getTableName()); | |||
for (ModelIndex mi : table.getIndexes()) { | |||
if (mi.isUnique()) { | |||
dao.checkUnique(bean, mi.getFields().split(",")); | |||
} | |||
} | |||
} | |||
protected void saveBean(DefaultEntity bean) { | |||
final String tableName = bean.getTableName(); | |||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(tableName); | |||
if (bean.isNew()) { | |||
dao.insertEntity(bean); | |||
} else { | |||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | |||
ModelField field = table.findFieldByType(SwEnum.FieldType.UPDATE_USER.value); | |||
if (field != null) bean.put(field.getName(), us.getUserId()); | |||
dao.updateEntity(bean); | |||
if (table.getType() == SwEnum.TableType.TYPE_TREE.value) { | |||
List<DefaultEntity> listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | |||
mapTreeBean.put(tableName, listTreeBean); | |||
} | |||
} | |||
} | |||
protected void afterCommit(DefaultEntity bean) { | |||
final String tableName = bean.getTableName(); | |||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | |||
if (table.isNeedCache()) { | |||
AbstractCache<DefaultEntity> cache = CacheManager.getIntance().getCache(tableName); | |||
List<DefaultEntity> listTreeBean = mapTreeBean.get(tableName); | |||
//树型表,父亲改变了,要多处理下缓存;还有个东东:级次码 | |||
if (listTreeBean != null && !listTreeBean.isEmpty()) { | |||
for (DefaultEntity b : listTreeBean) { | |||
cache.put(b); | |||
} | |||
} else { | |||
cache.put(bean); | |||
} | |||
} | |||
} | |||
protected void afterRollback(DefaultEntity bean) { | |||
final String tableName = bean.getTableName(); | |||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | |||
if (table.isNeedCache()) { | |||
AbstractCache<DefaultEntity> cache = CacheManager.getIntance().getCache(tableName); | |||
cache.reset(bean); | |||
} | |||
} | |||
//将关联的值设上 | |||
protected void setLinkValue(PageDataset pageDataSet, DefaultEntity bean, IGetValue iGetValue) { | |||
ModelTable table = ModelTableCache.getInstance().getByName(bean.getTableName()); | |||
for (PageDatasetFilter f : pageDataSet.filters) { | |||
String v = bean.getStr(f.field); | |||
//有值,就不管 | |||
if (v != null && !v.equals(table.findField(f.field).getDefaultValue())) continue; | |||
if (SwEnum.FilterType.CONST.value.equals(f.type)) {//常量 | |||
bean.put(f.field, f.value); | |||
} else if (SwEnum.FilterType.PARAM.value.equals(f.type)) {//参数 | |||
bean.put(f.field, f.value); | |||
} else if (SwEnum.FilterType.LINK.value.equals(f.type)) {//参数 | |||
Object value = iGetValue.getValue(f); | |||
if (value != null) { | |||
bean.put(f.field, value); | |||
} | |||
} | |||
} | |||
} | |||
interface IGetValue { | |||
Object getValue(PageDatasetFilter f); | |||
} | |||
} |
@@ -1,5 +1,11 @@ | |||
package cc.smtweb.system.bpm.web.engine.model.listcard.single; | |||
import cc.smtweb.framework.core.annotation.SwBody; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.mvc.service.*; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.system.bpm.web.design.form.*; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; | |||
/** | |||
@@ -7,4 +13,54 @@ import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; | |||
* 单页面简单列表卡片服务类 | |||
*/ | |||
public class LCSingleService extends DynPageService { | |||
public final static String TYPE_MODEL_LIST = "modelList"; | |||
public final static String TYPE_MODEL_ADD = "modelAdd"; | |||
public final static String TYPE_MODEL_LOAD = "modelLoad"; | |||
public final static String TYPE_MODEL_SAVE = "modelSave"; | |||
public final static String TYPE_MODEL_DEL = "modelDel"; | |||
@Override | |||
protected AbstractHandler createHandler(String type) { | |||
switch (type) { | |||
case TYPE_MODEL_LIST: | |||
case TYPE_MODEL_LOAD: | |||
case TYPE_MODEL_ADD: | |||
return new LCSingleLoadHandler(); | |||
case TYPE_MODEL_SAVE: | |||
return new LCSingleSaveHandler(); | |||
case TYPE_MODEL_DEL: | |||
return new LCSingleDelHandler(); | |||
} | |||
return super.createHandler(type); | |||
} | |||
//保存 | |||
public R modelSave(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCSingleSaveHandler)handler).save()); | |||
} | |||
//读取 | |||
public R modelLoad(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((LCSingleLoadHandler)handler).load()); | |||
} | |||
//读取 | |||
public R modelAdd(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((LCSingleLoadHandler)handler).add()); | |||
} | |||
//删除 | |||
public R modelDel(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_DEL, handler -> ((LCSingleDelHandler)handler).del()); | |||
} | |||
//列表数据 | |||
public R modelList(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LIST, handler -> ((LCSingleLoadHandler)handler).list()); | |||
} | |||
//列表总记录数及合计栏 | |||
public R modelListTotal(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LIST, handler -> ((LCSingleLoadHandler)handler).getTotal()); | |||
} | |||
} |
@@ -6,13 +6,13 @@ smtweb: | |||
#访问路径,需/结尾 | |||
attach-http-path: 'http://bjjt.jujiatech.cn/files/' | |||
#此配置原则上可以和local-path一致,可本机路径可ftp附件路径,需/结尾 | |||
attach-path: /jjkj/attach/files/persistent/ | |||
attach-path: /jjkj/attach/ | |||
#临时文件路径,需/结尾 | |||
attach-temp-path: /jjkj/attach/files/temp/ | |||
attach-temp-path: /jujia/tomcat_api/webapps/files/tempFile/ | |||
#附件上传方式 sftp/ftp/local | |||
attach-type: local | |||
attach-type: sftp | |||
#ftp IP地址 | |||
attach-ftp-ip: 127.0.0.1 | |||
attach-ftp-ip: 172.26.60.191 | |||
#ftp 端口 | |||
attach-ftp-port: 22 | |||
#ftp 用户名 | |||
@@ -21,7 +21,10 @@ smtweb: | |||
attach-ftp-pwd: Bjjt@2021 | |||
bpm: | |||
debug: true | |||
code-java-path: 'D:\Git\dfpDepository\smtweb2\smtweb-framework' | |||
# 有.idea或pom.xml文件的目录 | |||
code-java-path: 'd:/work/smtweb2/smtweb-framework' | |||
# 读取模式 1-读取pom.xml,要求module名同目录 2-读取.idea/modules.xml | |||
mode: 1 | |||
db: | |||
type: mysql | |||
default: | |||
@@ -43,12 +46,11 @@ spring: | |||
password: | |||
datasource: | |||
driver-class-name: com.mysql.cj.jdbc.Driver | |||
url: jdbc:mysql://139.9.38.43:6032/smt?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false | |||
# url: jdbc:mysql://139.9.38.43:6032/smt?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false | |||
url: jdbc:mysql://127.0.0.1:3306/smt?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false | |||
username: root | |||
password: Ncmz@2022_jjkj | |||
# url: jdbc:mysql://127.0.0.1:3306/smt_asp?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false | |||
# username: root | |||
# password: 123456 | |||
# password: Ncmz@2022_jjkj | |||
password: ssqsoft | |||
servlet: | |||
multipart: | |||
max-file-size: 104857600000 | |||
@@ -27,6 +27,5 @@ | |||
<modules> | |||
<module>core</module> | |||
<module>bpm</module> | |||
<module>unit</module> | |||
</modules> | |||
</project> |