@@ -18,6 +18,8 @@ public abstract class AbstractDynPageHandler extends AbstractHandler { | |||
protected long pageId; | |||
protected PageDatasets datasets; | |||
protected DynPageProvider provider = new DynPageProvider(); | |||
@Override | |||
public void init(SwMap params, UserSession us) { | |||
super.init(params, us); | |||
@@ -25,6 +27,9 @@ public abstract class AbstractDynPageHandler extends AbstractHandler { | |||
datasets = ModelFormHelper.parsePageDataset(pageId); | |||
if (datasets == null || datasets.list == null) throw new SwException("没有找到页面定义数据!"); | |||
provider.pageId = pageId; | |||
provider.datasets = datasets; | |||
} | |||
protected PageDataset findDataset(String name) { | |||
@@ -35,4 +40,14 @@ public abstract class AbstractDynPageHandler extends AbstractHandler { | |||
protected PageDataset findMasterDataset() { | |||
return datasets.list.get(0); | |||
} | |||
//从参数读取数据集定义 | |||
protected PageDataset readParamDs() { | |||
//数据集 | |||
String dbName = params.readString("dataset"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = findDataset(dbName); | |||
if (pageDataSet == null) throw new SwException("没有找到指定的的数据集定义:" + dbName + "!"); | |||
return pageDataSet; | |||
} | |||
} |
@@ -31,14 +31,10 @@ public class DynPageDelHandler extends AbstractDynPageHandler { | |||
* @return | |||
*/ | |||
public R delOne() { | |||
//数据集 | |||
String dbName = params.readString("dataset"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = findDataset(dbName); | |||
if (pageDataSet == null) throw new SwException("没有找到指定的的数据集定义:" + dbName + "!"); | |||
long id = params.readLong("id"); | |||
if (id == 0) throw new SwException("没有收到待删除记录Id!"); | |||
//数据集 | |||
PageDataset pageDataSet = readParamDs(); | |||
checkBean(pageDataSet, id); | |||
@@ -137,7 +133,6 @@ public class DynPageDelHandler extends AbstractDynPageHandler { | |||
//校验外键引用关系 | |||
} | |||
/** | |||
* 待删除信息 | |||
*/ | |||
@@ -1,5 +1,6 @@ | |||
package cc.smtweb.system.bpm.web.engine.dynPage; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.EntityHelper; | |||
@@ -12,6 +13,8 @@ import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import java.util.List; | |||
import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY; | |||
/** | |||
* Created by Akmm at 2022/5/26 15:58 | |||
*/ | |||
@@ -58,4 +61,15 @@ public class DynPageListHandler extends AbstractListHandler { | |||
return list; | |||
} | |||
@Override | |||
public R getTotal() { | |||
SqlNamedPara sqlPara = DynPageHelper.buildSumSql(pageDataSet, filter); | |||
SwMap mapFooter = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.mapParas, SwMap.class); | |||
R r = R.success(); | |||
r.put("total", mapFooter.get(TOTAL_KEY)); | |||
r.put("footer", mapFooter); | |||
return r; | |||
} | |||
} |
@@ -1,52 +1,36 @@ | |||
package cc.smtweb.system.bpm.web.engine.dynPage; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.common.SwException; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
import cc.smtweb.framework.core.db.EntityHelper; | |||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.mvc.service.SqlNamedPara; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDatasets; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.List; | |||
import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY; | |||
/** | |||
* Created by Akmm at 2022/5/26 17:45 | |||
* Created by Akmm at 2022/4/21 17:53 | |||
*/ | |||
public class DynPageHandler extends AbstractHandler { | |||
//页面定义id | |||
protected long pageId; | |||
protected PageDatasets datasets; | |||
protected DynPageProvider provider = new DynPageProvider(); | |||
@Override | |||
public void init(SwMap params, UserSession us) { | |||
super.init(params, us); | |||
pageId = params.readLong("pageId"); | |||
datasets = ModelFormHelper.parsePageDataset(pageId); | |||
if (datasets == null || datasets.list == null) throw new SwException("没有找到页面定义数据!"); | |||
provider.pageId = pageId; | |||
provider.datasets = datasets; | |||
} | |||
protected PageDataset findDataset(String name) { | |||
return datasets.findByName(name); | |||
} | |||
//获取第一个,主数据集 | |||
protected PageDataset findMasterDataset() { | |||
return datasets.list.get(0); | |||
public class DynPageLoadHandler extends AbstractDynPageHandler { | |||
//数据集 | |||
private String dbName; | |||
//过滤条件 | |||
private SwMap filter = new SwMap(); | |||
//对应的数据集定义 | |||
private PageDataset pageDataSet; | |||
//列表工具类 | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
return new DynPageListHandler(pageId, filter, pageDataSet); | |||
} | |||
//新增操作,初始化定义的数据集 | |||
@@ -73,18 +57,27 @@ public class DynPageHandler extends AbstractHandler { | |||
return R.success(mapRet); | |||
} | |||
//新增操作,初始化定义的数据集 | |||
public R addOne() { | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = readParamDs(); | |||
if (!pageDataSet.canEdit) { | |||
return R.error("指定数据集为只读数据集[" + pageDataSet.label + "]!"); | |||
} | |||
//懒加载,给个空对象 | |||
return R.success(DynPageHelper.createBean(pageDataSet)); | |||
} | |||
public R loadOne() { | |||
//数据集 | |||
String dbName = params.readString("dataset"); | |||
//过滤条件 | |||
SwMap filter = (SwMap) params.get("filter"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = findDataset(dbName); | |||
if (pageDataSet == null) throw new SwException("没有找到指定的的数据集定义:" + dbName + "!"); | |||
PageDataset pageDataSet = readParamDs(); | |||
DynRetBean bean = null; | |||
if (SwEnum.DatasetType.LIST.value.equals(pageDataSet.type)) {//列表类 | |||
bean = DynRetBean.createList(provider.loadList(filter, pageDataSet)); | |||
bean = DynRetBean.createList(getListWorker(filter, pageDataSet).buildListData()); | |||
} else if (SwEnum.DatasetType.TREE.value.equals(pageDataSet.type)) {//树类 | |||
// return new DynRetBean(loadTree()); | |||
} else {//列表类 | |||
@@ -101,21 +94,10 @@ public class DynPageHandler extends AbstractHandler { | |||
*/ | |||
public R getTotal() { | |||
//数据集 | |||
String dbName = params.readString("dataset"); | |||
PageDataset pageDataSet = readParamDs(); | |||
//过滤条件 | |||
SwMap filter = (SwMap) params.get("filter"); | |||
//对应的数据集定义 | |||
PageDataset pageDataSet = findDataset(dbName); | |||
if (pageDataSet == null) throw new SwException("没有找到指定的的数据集定义:" + dbName + "!"); | |||
SqlNamedPara sqlPara = DynPageHelper.buildSumSql(pageDataSet, filter); | |||
SwMap mapFooter = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.mapParas, SwMap.class); | |||
R r = R.success(); | |||
r.put("total", mapFooter.get(TOTAL_KEY)); | |||
r.put("footer", mapFooter); | |||
return r; | |||
return getListWorker(filter, pageDataSet).getTotal(); | |||
} | |||
} |
@@ -1,100 +0,0 @@ | |||
package cc.smtweb.system.bpm.web.engine.dynPage; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwException; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.EntityHelper; | |||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.mvc.service.SqlNamedPara; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import java.util.List; | |||
import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY; | |||
/** | |||
* Created by Akmm at 2022/4/21 17:53 | |||
*/ | |||
public class DynPageLoadOneHandler extends AbstractDynPageHandler { | |||
//数据集 | |||
private String dbName; | |||
//过滤条件 | |||
private SwMap filter = new SwMap(); | |||
//对应的数据集定义 | |||
private PageDataset pageDataSet; | |||
public R load() { | |||
dbName = params.readString("dataset"); | |||
filter = (SwMap)params.get("filter"); | |||
pageDataSet = findDataset(dbName); | |||
if (pageDataSet == null) throw new SwException("没有找到指定的的数据集定义:" + dbName + "!"); | |||
DynRetBean bean = null; | |||
if (SwEnum.DatasetType.LIST.value.equals(pageDataSet.type)) {//列表类 | |||
bean = DynRetBean.createList(loadList()); | |||
} else if (SwEnum.DatasetType.TREE.value.equals(pageDataSet.type)) {//列表类 | |||
// return new DynRetBean(loadTree()); | |||
} else {//列表类 | |||
bean = DynRetBean.createBean(loadOne()); | |||
} | |||
return R.success(bean); | |||
} | |||
/** | |||
* 返回单个对象 | |||
* @return | |||
*/ | |||
private SwMap loadOne() { | |||
SqlNamedPara sqlPara = DynPageHelper.buildSelectSql(pageDataSet, filter); | |||
SwMap map = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.mapParas, SwMap.class); | |||
if (map == null) { | |||
throw new SwException("没有找到指定数据(ds=" + pageDataSet.name + ")"); | |||
} | |||
ModelTable masterTable = ModelTableCache.getInstance().get(pageDataSet.masterTable); | |||
EntityHelper.loadBeanLink(masterTable.getName(), map, sqlPara.mapFieldAlias); | |||
return map; | |||
} | |||
/** | |||
* 返回list | |||
* @return | |||
*/ | |||
private SwListData loadList() { | |||
SqlNamedPara sqlPara = DynPageHelper.buildSelectSql(pageDataSet, filter); | |||
List<SwMap> list; | |||
if (sqlPara.page > 0 && sqlPara.rows > 0) { | |||
list = DbEngine.getInstance().pagedQueryN(sqlPara.sql, SwMap.class, (sqlPara.page - 1) * sqlPara.rows, sqlPara.rows, sqlPara.mapParas); | |||
} else { | |||
list = DbEngine.getInstance().queryN(sqlPara.sql, sqlPara.mapParas, SwMap.class); | |||
} | |||
ModelTable masterTable = ModelTableCache.getInstance().get(pageDataSet.masterTable); | |||
EntityHelper.loadBeanLink(masterTable.getName(), list, sqlPara.mapFieldAlias); | |||
return SwListData.create(list, sqlPara.rows); | |||
} | |||
/** | |||
* 计算分页数据 | |||
* @return | |||
*/ | |||
public R getTotal() { | |||
try { | |||
SqlNamedPara sqlPara = DynPageHelper.buildSumSql(pageDataSet, filter); | |||
SwMap mapFooter = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.mapParas, SwMap.class); | |||
R r = R.success(); | |||
r.put("total", mapFooter.get(TOTAL_KEY)); | |||
r.put("footer", mapFooter); | |||
return r; | |||
} catch (Exception e) { | |||
return R.error("计算合计失败!", e); | |||
} | |||
} | |||
} |
@@ -20,11 +20,6 @@ public class DynPageProvider extends AbstractCompProvider { | |||
protected long pageId; | |||
protected PageDatasets datasets; | |||
//加载列表类数据集 | |||
public SwListData loadList(SwMap filter, PageDataset pageDataSet) { | |||
return new DynPageListHandler(pageId, filter, pageDataSet).buildListData(); | |||
} | |||
//加载表单类数据集(单条) | |||
public SwMap loadData(SwMap filter, PageDataset pageDataSet) { | |||
return doGetData(pageDataSet.id, () -> { | |||
@@ -13,15 +13,12 @@ import cc.smtweb.framework.core.session.UserSession; | |||
*/ | |||
@SwService | |||
public class DynPageService extends AbstractCompService { | |||
public final static String TYPE_ADD = "add"; | |||
@Override | |||
protected AbstractHandler createHandler(String type) { | |||
switch (type) { | |||
case TYPE_ADD: | |||
return new DynPageHandler(); | |||
case TYPE_LOAD: | |||
return new DynPageLoadOneHandler(); | |||
return new DynPageLoadHandler(); | |||
case TYPE_SAVE: | |||
return new DynPageSaveHandler(); | |||
case TYPE_DEL: | |||
@@ -32,7 +29,17 @@ public class DynPageService extends AbstractCompService { | |||
//新增 | |||
public R add(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_ADD, handler -> ((DynPageHandler)handler).add()); | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).add()); | |||
} | |||
//新增 | |||
public R addOne(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).addOne()); | |||
} | |||
//加载 | |||
public R loadOne(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).loadOne()); | |||
} | |||
//保存指定数据集 | |||
@@ -40,13 +47,23 @@ public class DynPageService extends AbstractCompService { | |||
return pageHandler(params, us, TYPE_SAVE, handler -> ((DynPageSaveHandler)handler).saveOne()); | |||
} | |||
//保存指定数据集 | |||
public R save(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_SAVE, handler -> ((DynPageSaveHandler)handler).saveAll()); | |||
} | |||
//删除指定数据集 | |||
public R delOne(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_DEL, handler -> ((DynPageDelHandler)handler).delOne()); | |||
} | |||
//删除数据 | |||
public R del(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_DEL, handler -> ((DynPageDelHandler)handler).delAll()); | |||
} | |||
//列表总记录数及合计栏 | |||
public R total(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadOneHandler)handler).getTotal()); | |||
return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).getTotal()); | |||
} | |||
} |