Sfoglia il codice sorgente

树型数据加载

master
郑根木 2 anni fa
parent
commit
d9a5a6a33a
3 ha cambiato i file con 292 aggiunte e 111 eliminazioni
  1. +62
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java
  2. +32
    -6
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageTreeHandler.java
  3. +198
    -102
      smtweb-framework/core/src/main/resources/demo.json

+ 62
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java Vedi File

@@ -2,6 +2,7 @@ package cc.smtweb.system.bpm.web.engine.dynPage;

import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
@@ -9,6 +10,7 @@ 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.vo.ModelTable;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.framework.core.mvc.service.SqlNamedPara;
import cc.smtweb.framework.core.util.MapUtil;
import cc.smtweb.framework.core.util.NumberUtil;
@@ -48,10 +50,13 @@ public class DynPageHelper {
* @return
*/
public static SqlNamedPara buildSelectSql(PageDataset dataSet, Map<String, Object> params) {
StringBuilder sql = new StringBuilder(512);

SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params);
buildSelectSql(dataSet, params, sqlNamedPara);
return sqlNamedPara;
}

public static void buildSelectSql(PageDataset dataSet, Map<String, Object> params, SqlNamedPara sqlNamedPara) {
StringBuilder sql = new StringBuilder(512);
sql.append(buildSelFieldsSql(dataSet, sqlNamedPara));
if (StringUtils.isNotEmpty(sqlNamedPara.sql)) {
sql.append(" where ").append(sqlNamedPara.sql);
@@ -68,11 +73,64 @@ public class DynPageHelper {
sqlNamedPara.sql = sql.toString();
sqlNamedPara.page = MapUtil.readInt(params, SwConsts.PARAM_PAGE);
sqlNamedPara.rows = MapUtil.readInt(params, SwConsts.PARAM_ROWS);
}

//构建树型查询语句,插入parent_id=?
public static SqlNamedPara buildTreeSelectSql(PageDataset dataSet, SwMap params) {
ModelTable table = ModelTableCache.getInstance().get(dataSet.masterTable);
if (table == null) throw new SwException("没有找到指定的表:" + dataSet.masterTable);
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params);
if (table.getType() == SwEnum.TableType.TYPE_TREE.value) {//是树型结构,才做处理
long parentId = params.readLong("parent_id");
ModelField field = table.findFieldByType(SwEnum.FieldType.PARENT_ID.value);
if (field == null) throw new SwException("树型表(" + table.getName() + ")未定义上级id字段!");

if (StringUtils.isNotEmpty(sqlNamedPara.sql)) {
sqlNamedPara.sql = field.getName() + "=:parent_id and (" + sqlNamedPara.sql + ")";
} else {
sqlNamedPara.sql = field.getName() + "=:parent_id ";
}
sqlNamedPara.addParas("parent_id", parentId);
}

buildSelectSql(dataSet, params, sqlNamedPara);
return sqlNamedPara;
}

//构建过滤查询语句
public static SqlNamedPara buildFilterSelectSql(PageDataset dataSet, SwMap params, String text) {
ModelTable table = ModelTableCache.getInstance().get(dataSet.masterTable);
if (table == null) throw new SwException("没有找到指定的表:" + dataSet.masterTable);
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params);
if (StringUtils.isNotEmpty(text)) {//有文本信息
StringBuilder sql = new StringBuilder(128);
ModelField field = table.findFieldByType(SwEnum.FieldType.CODE.value);
if (field != null) {
sql.append(" or ").append(field.getName()).append(" like :q_txt");
}

field = table.findFieldByType(SwEnum.FieldType.NAME.value);
if (field != null) {
sql.append(" or ").append(field.getName()).append(" like :q_txt");
}

if (sql.length() > 0) {
if (StringUtils.isNotEmpty(sqlNamedPara.sql)) {
sqlNamedPara.sql = "(" + sqlNamedPara.sql + ") and (" + sql.substring(4) + ")";
} else {
sqlNamedPara.sql = sql.substring(4);
}
sqlNamedPara.addParas("q_txt", text);
}
}

buildSelectSql(dataSet, params, sqlNamedPara);
return sqlNamedPara;
}

/**
* 构建合计栏sql
*
* @param dataSet
* @param params
* @return
@@ -208,12 +266,13 @@ public class DynPageHelper {

/**
* 处理计算字段
*
* @param data
* @param dataset
*/
public static void setCalcFields(SwMap data, PageDataset dataset) {
if (!dataset.hasCalcField()) return;
for (PageDatasetField field: dataset.fields) {
for (PageDatasetField field : dataset.fields) {
if (!field.fieldIsCalc()) continue;
data.put(field.name, NumberUtil.calcExprMapObject(field.expr, data));
}


+ 32
- 6
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageTreeHandler.java Vedi File

@@ -1,14 +1,18 @@
package cc.smtweb.system.bpm.web.engine.dynPage;

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.vo.ModelCatalog;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.mvc.service.AbstractTreeHandler;
import cc.smtweb.framework.core.mvc.service.SqlNamedPara;
import cc.smtweb.framework.core.mvc.service.SqlPara;
import cc.smtweb.system.bpm.web.design.form.ModelForm;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;

@@ -36,26 +40,48 @@ public class DynPageTreeHandler extends AbstractTreeHandler<SwMap> {
protected List<SwMap> filterData() {
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable);
if (table == null) throw new BizException("未找到数据集表定义:" + pageDataSet.masterTable);
EntityDao dao = DbEngine.getInstance().findDao(table.getName());

String text = "%" + params.readString("text") + "%";
List<SwMap> list = null;//dao.queryWhere(" mc_prj_id=? and (mc_name like ? or mc_code like ?) order by mc_name", prj_id, text, text);
SqlNamedPara sqlPara = buildFilterSqlPara(text);

return list;
return DbEngine.getInstance().queryN(sqlPara.sql, sqlPara.mapParas, SwMap.class);
}

/**
* 构建sql
* @return
*/
protected SqlNamedPara buildDataSqlPara() {
return DynPageHelper.buildTreeSelectSql(pageDataSet, filter);
}

/**
* 构建sql
* @return
*/
protected SqlNamedPara buildFilterSqlPara(String text) {
return DynPageHelper.buildFilterSelectSql(pageDataSet, filter, text);
}

@Override
protected List<SwMap> getChildren(long id) {
return null;
SqlNamedPara sqlPara = buildDataSqlPara();
return DbEngine.getInstance().queryN(sqlPara.sql, sqlPara.mapParas, SwMap.class);
}

@Override
protected long getId(SwMap bean) {
return 0;
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable);
if (table == null) throw new BizException("未找到数据集表定义:" + pageDataSet.masterTable);

return bean.readLong(table.getIdField());
}

@Override
protected String getText(SwMap bean) {
return null;
ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable);
if (table == null) throw new BizException("未找到数据集表定义:" + pageDataSet.masterTable);
ModelField field = table.findFieldByType(SwEnum.FieldType.NAME.value);
return field != null ? bean.readString(field.getName()) : bean.readString(table.getIdField());
}
}

+ 198
- 102
smtweb-framework/core/src/main/resources/demo.json Vedi File

@@ -2,11 +2,11 @@
"form": [
{
"page": {
"id": "p721060295212011520",
"id": "p729297538913406976",
"type": "fx-page",
"props": {
"title": "区划列表",
"key": "721060295216205824"
"title": "测试",
"key": "729297538913406977"
}
},
"graph": {
@@ -15,92 +15,145 @@
"type": "fx-split-panel",
"props": {
"horizontal": false,
"shadow": "never"
"shadow": ""
},
"children": [
{
"id": "721060295295897600",
"type": "fx-form-panel",
{
"shape": "panel",
"id": "form_panel",
"type": "fx-form-panel",
"props": {
"paddingY": 5,
"paddingX": 10,
"size": "35",
"colNum": 2
"colNum": 3,
"name": "query",
"label": "按钮区",
"size": "80",
"shadow": "",
"alignY": "center",
"paddingRight": 10
},
"children": [
{
"id": "id721060295295897601",
"type": "fx-",
"props": {
"label": "名称",
"type": "text",
"maxlength": 100,
"placeholder": "请输入查询内容",
"labelWidth": 100,
"dataset": "ds_1815c554ef8",
"field": "id_1815c554f1b",
"name": "ar_code"
},
"events": {}
},
{
"id": "id721060295321063424",
"id": "id729297538913406978",
"type": "fx-button-group",
"props": {
"menus": []
"menus": [],
"textAlign": "right"
},
"slots": {
"default": [
{
"type": "fx-button",
"props": {
"label": "查询",
"leftIcon": "history-query",
"type": "primary",
"action": "button:search",
"dataset": "ds_1815c554ef8"
"label": "重置",
"leftIcon": "clear",
"type": "",
"action": "button:reset",
"dataset": "",
"link": false,
"linkType": ""
},
"id": "id721060295321063425"
"id": "id729297538913406979"
},
{
"type": "fx-button",
"props": {
"label": "重置",
"type": "danger",
"action": "button:reset",
"leftIcon": "figma-reset-instance"
"label": "查询",
"leftIcon": "search",
"type": "primary",
"action": "button:search",
"dataset": "ds_181d12ba801"
},
"id": "id721060295321063426"
},
"id": "id729297538913406980"
}
]
},
"layout": {
"col": 1
}
}
]
},
{
"id": "729297538913406981",
"type": "fx-form-panel",
"shape": "panel",
"props": {
"size": "20",
"backgroundColor": "transparent"
},
"children": []
},
{
"id": "729297538913406982",
"type": "fx-form-panel",
"shape": "panel",
"props": {
"size": "68",
"label": "查询条件",
"colNum": 2,
"alignY": "center",
"paddingLeft": 32,
"paddingRight": 32,
"shadow": ""
},
"children": [
{
"id": "id729297538913406983",
"type": "fx-title",
"props": {
"label": "测试",
"fontSize": 16,
"color": "#01070D",
"fontWeight": "bold",
"showPrefix": false,
"prefixWidth": 5,
"prefixHeight": 24,
"prefixColor": "#1E90FF"
}
},
{
"id": "id729297538913406984",
"type": "fx-button-group",
"props": {
"menus": [],
"textAlign": "right"
},
"slots": {
"default": [
{
"id": "id721060295321063427",
"type": "fx-button",
"props": {
"label": "新增",
"type": "success",
"leftIcon": "shield-add",
"leftIcon": "plus",
"type": "primary",
"action": "button:add",
"dataset": "ds_1815c554ef8"
}
"link": false,
"linkType": "",
"fxLink": "",
"dataset": ""
},
"id": "id729297538913406985"
}
]
}
}
]
},{
"shape": "panel",
"id": "form_panel",
},
{
"id": "729297538913406986",
"type": "fx-form-panel",
"shape": "panel",
"props": {
"size": "",
"label": "列表",
"colNum": 0,
"paddingX": 5,
"paddingY": 5,
"align": "full"
"paddingLeft": 32,
"paddingRight": 32,
"shadow": ""
},
"children": [
{
"id": "id721060295329452032",
"id": "id729297538913406987",
"type": "fx-table",
"props": {
"label": "表格",
@@ -108,57 +161,65 @@
"stripe": true,
"showHeader": true,
"fit": true,
"dataset": "ds_1815c554ef8",
"actionWidth": 120
"dataset": "ds_181d12ba801",
"actionWidth": 150
},
"slots": {
"default": [
{
"id": "id721060295329452033",
"id": "id729297538913406988",
"type": "fx-table-column",
"props": {
"field": "ar_code",
"label": "编码"
"field": "id_181d173427e",
"label": "id"
}
},
{
"id": "id721060295337840640",
"id": "id729297538913406989",
"type": "fx-table-column",
"props": {
"field": "ar_name",
"label": "名称"
"field": "id_181d173427f",
"label": "项目"
}
},
{
"id": "id721060295337840641",
"id": "id729297538913406990",
"type": "fx-table-column",
"props": {
"field": "ar_full_name",
"label": "全称"
"field": "id_181d1734280",
"label": "目录"
}
},
{
"id": "id721060295337840642",
"id": "id729297538913406991",
"type": "fx-table-column",
"props": {
"field": "ar_seq",
"label": "排序码"
"field": "id_181d1734281",
"label": "数据库"
}
},
{
"id": "id721060295337840643",
"id": "id729297538913406992",
"type": "fx-table-column",
"props": {
"field": "ar_parent_id",
"label": "父ID"
"field": "id_181d1734282",
"label": "依赖"
}
},
{
"id": "id721060295337840644",
"id": "id729297538913406993",
"type": "fx-table-column",
"props": {
"field": "ar_remark",
"label": "备注"
"field": "id_181d1734283",
"label": "表名"
}
},
{
"id": "id729297538913406994",
"type": "fx-table-column",
"props": {
"field": "id_181d1734284",
"label": "标题"
}
}
],
@@ -166,67 +227,102 @@
{
"type": "fx-button",
"props": {
"label": "编",
"label": "编",
"type": "text",
"leftIcon": "edit",
"action": "button:edit",
"linkType": "dialog",
"dataset": "ds_1815c554ef8"
"dataset": "",
"link": true,
"linkType": "",
"nextAction": "",
"fxLink": ""
},
"id": "id1813718bf36"
"id": "id729297538917601280"
},
{
"type": "fx-button",
"props": {
"label": "删",
"label": "删",
"type": "text",
"leftIcon": "delete",
"action": "button:del",
"dataset": "ds_1815c554ef8"
"leftIcon": "delete-themes",
"action": "button:remove",
"preAction": "",
"link": true,
"confirm": ""
},
"id": "id721060295337840645"
"id": "id729297538917601281"
}
]
},
"events": {}
}
]
},
{
"id": "729297538917601282",
"type": "fx-form-panel",
"shape": "panel",
"props": {
"size": "24",
"backgroundColor": "transparent"
},
"children": []
}
]
}
},
{
"page": {
"id": "id729297538917601283",
"type": "fx-dialog",
"props": {
"title": "查询条件",
"key": "qrueydialog",
"destroyOnClose": true,
"closeOnClickModal": true,
"width": "20%",
"height": ""
},
"events": {
}
}
}
],
"model": [
{
"dataset": "ds_1815c554ef8",
{
"dataset": "ds_181d12ba801",
"label": "主数据集",
"fields": [
{
"id": "id_1815c554efc",
"field": "ar_code" },
"id": "id_181d173427e",
"field": ""
},
{
"id": "id_1815c554efd",
"field": "ar_name" },
"id": "id_181d173427f",
"field": ""
},
{
"id": "id_1815c554eff",
"field": "ar_full_name" },
"id": "id_181d1734280",
"field": ""
},
{
"id": "id_1815c554f01",
"field": "ar_seq" },
"id": "id_181d1734281",
"field": ""
},
{
"id": "id_1815c554efe",
"field": "ar_parent_id" },
"id": "id_181d1734282",
"field": ""
},
{
"id": "id_1815c554f00",
"field": "ar_remark" }
],
"filters": [
"id": "id_181d1734283",
"field": ""
},
{
"id": "id_1815c554f1b",
"field": "ar_name",
"required": false,
"type": "input"
"id": "id_181d1734284",
"field": ""
}
],
"filters": [
]
}
],
@@ -234,4 +330,4 @@
"widgetRef": [],
"vars": []
}
}
}

Caricamento…
Annulla
Salva