郑根木 vor 2 Jahren
Ursprung
Commit
8846afa1dc
11 geänderte Dateien mit 220 neuen und 105 gelöschten Zeilen
  1. +1
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  2. +2
    -2
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java
  3. +20
    -11
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java
  4. +4
    -8
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/SqlNamedPara.java
  5. +6
    -38
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/SqlPara.java
  6. +1
    -1
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java
  7. +0
    -40
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageAddHandler.java
  8. +92
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHandler.java
  9. +48
    -1
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageListHandler.java
  10. +4
    -4
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageLoadOneHandler.java
  11. +42
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java

+ 1
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java Datei anzeigen

@@ -99,6 +99,7 @@ public interface SwEnum {
this.javaType = javaType;
this.defaultValue = defaultValue;
this.editor = editor;
this.type = type;
}

public String getSqlTypeCreate() {


+ 2
- 2
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java Datei anzeigen

@@ -60,7 +60,7 @@ public abstract class AbstractCompService {

//列表数据
public R list(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler)handler).listData());
return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler)handler).data());
}

//列表总记录数及合计栏
@@ -70,7 +70,7 @@ public abstract class AbstractCompService {

//combo数据
public R combo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).listData());
return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).data());
}

//combo总记录数及合计栏


+ 20
- 11
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java Datei anzeigen

@@ -50,12 +50,15 @@ public abstract class AbstractListHandler extends AbstractHandler {
sessionCache.remove(getCompId() + "." + key);
}

protected R listData() {
public R data() {
return R.success(buildListData());
}

public SwListData buildListData() {
List<SwMap> listData;
SqlPara sqlPara = buildDataSql();

int rows = params.readInt("rows", 0);
int page = params.readInt("page", 1);

String sort = params.readString("sort");
String order = params.readString("order");
String sql;
@@ -67,17 +70,24 @@ public abstract class AbstractListHandler extends AbstractHandler {
}
}

if (rows == 0) {
listData = DbEngine.getInstance().query(sql, SwMap.class, sqlPara.paras);
} else {
//查分页数据
listData = DbEngine.getInstance().pagedQuery(sql, SwMap.class, (page - 1) * rows, rows, sqlPara.paras);
}
listData = queryData(sql, sqlPara);

afterQuery(listData);
return R.success(SwListData.create(listData, rows));
return SwListData.create(listData, sqlPara.rows);
}

protected List<SwMap> queryData(String sql, SqlPara sqlPara) {
sqlPara.rows = params.readInt("rows", 0);
sqlPara.page = params.readInt("page", 1);


if (sqlPara.rows == 0) {
return DbEngine.getInstance().query(sql, SwMap.class, sqlPara.paras);
} else {
//查分页数据
return DbEngine.getInstance().pagedQuery(sql, SwMap.class, (sqlPara.page - 1) * sqlPara.rows, sqlPara.rows, sqlPara.paras);
}
}

protected SqlPara buildSumSqlPara() {
SqlPara sqlPara = getCache(KEY_SQLPARA);
@@ -86,7 +96,6 @@ public abstract class AbstractListHandler extends AbstractHandler {
List<FooterField> footerFields = getFooterFields();
StringBuilder sql = new StringBuilder(128);
sql.append("select count(1) " + TOTAL_KEY);
int n = 2;
for (FooterField cn : footerFields) {
if (!FooterField.STATIC_TEXT.equals(cn.type)) {
if (FooterField.SUM_TYPE_COUNT_ALL.equals(cn.type)) {


+ 4
- 8
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/SqlNamedPara.java Datei anzeigen

@@ -6,13 +6,9 @@ import java.util.HashMap;
import java.util.Map;

//一个sql及其参数,具名参数
public class SqlNamedPara {
public class SqlNamedPara extends SqlPara {
public String sql = "";
public SwMap paras = new SwMap();
//页码,从1开始;为0,则不需要分页
public int page = 0;
//每页记录数
public int rows = 20;
public SwMap mapParas = new SwMap();
//字段别名
public Map<String, String> mapFieldAlias = new HashMap<>();

@@ -22,11 +18,11 @@ public class SqlNamedPara {

public SqlNamedPara(String sql, SwMap paras) {
this.sql = sql;
this.paras = paras;
this.mapParas = paras;
}

public void addParas(String name, Object value) {
paras.put(name, value);
mapParas.put(name, value);
}

public void addFieldAlias(String fieldName, String alias) {


+ 6
- 38
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/SqlPara.java Datei anzeigen

@@ -1,42 +1,18 @@
package cc.smtweb.framework.core.mvc.service;

import org.apache.commons.lang3.ArrayUtils;

//一个sql及其参数
public class SqlPara {
public String sql = "";
public Object[] paras = null;
public int[] types = null;
public boolean hasLob = false; //是否有lob字段

public SqlPara(String sql, Object... paras) {
this.sql = sql;
this.paras = paras;
}
public String sql;
public Object[] paras;
public int rows;
public int page;

public SqlPara(String sql, int[] types, Object... paras) {
this.sql = sql;
this.paras = paras;
this.types = types;
public SqlPara() {
}

public SqlPara(String sql, int[] types, boolean hasLob, Object... paras) {
public SqlPara(String sql, Object... paras) {
this.sql = sql;
this.paras = paras;
this.types = types;
this.hasLob = hasLob;
}

@Override
public int hashCode() {
//计算Hash值,以判断条件参数是否有变更;
if (paras == null) return sql.hashCode();
int result = 1;
for (Object element : paras) {
result = 31 * result + (element == null ? 0: element.hashCode());
}
result = 31 * result + sql.hashCode();
return result;
}

//获取不带order by 的sql语句
@@ -57,12 +33,4 @@ public class SqlPara {
}
return retSql;
}

public void addParas(Object... ps) {
if (paras == null) {
paras = ps;
return;
}
paras = ArrayUtils.addAll(paras, ps);
}
}

+ 1
- 1
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java Datei anzeigen

@@ -102,7 +102,7 @@ public class ModelFormService extends AbstractCompService {
String sql = params.readString("sql");
if (StringUtils.isEmpty(sql)) return R.error("没有传入的sql!");
sql = sql.trim().toLowerCase();
if (!sql.startsWith("select ")) return R.error("非查询类sql,禁止执行!");
if (!sql.startsWith("select")) return R.error("非查询类sql,禁止执行!");
if (sql.contains(";")) return R.error("sql内禁止出现分号!");
sql = SqlUtil.replaceTable(sql);
List<SwMap> ret = DbEngine.getInstance().query(sql + " where 1=0", rs -> {


+ 0
- 40
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageAddHandler.java Datei anzeigen

@@ -1,40 +0,0 @@
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.common.SwEnum;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;

import java.util.HashMap;
import java.util.Map;

/**
* Created by Akmm at 2022/4/21 17:53
* 新增操作,初始化定义的数据集
*/
public class DynPageAddHandler extends AbstractDynPageHandler {

public R add() {
//返回的数据,以dataset.name为key,查出的结果(bean或list)为value
Map<String, Object> mapRet = new HashMap<>();
for (PageDataset dataSet : datasets.list) {
if (!dataSet.canEdit) {
continue;
}
if (SwEnum.DatasetType.FORM.value.equals(dataSet.type)) {//单表
//懒加载,给个空对象
if (dataSet.lazy) {
mapRet.put(dataSet.name, new SwMap());
continue;
}
mapRet.put(dataSet.name, DynPageHelper.createBean(dataSet));
} else if (SwEnum.DatasetType.TREE.value.equals(dataSet.type)) {//树
mapRet.put(dataSet.name, new SwMap());
} else if (!SwEnum.DatasetType.ENUM.value.equals(dataSet.type)) {//非枚举
mapRet.put(dataSet.name, SwListData.create(null, 0));
}
}
return R.success(mapRet);
}
}

+ 92
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHandler.java Datei anzeigen

@@ -0,0 +1,92 @@
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.mvc.service.AbstractHandler;
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;

/**
* Created by Akmm at 2022/5/26 17:45
*/
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 R add() {
//返回的数据,以dataset.name为key,查出的结果(bean或list)为value
SwMap mapRet = new SwMap();
for (PageDataset dataSet : datasets.list) {
if (!dataSet.canEdit) {
continue;
}
if (SwEnum.DatasetType.FORM.value.equals(dataSet.type)) {//单表
//懒加载,给个空对象
if (dataSet.lazy) {
mapRet.put(dataSet.name, new SwMap());
continue;
}
mapRet.put(dataSet.name, DynPageHelper.createBean(dataSet));
} else if (SwEnum.DatasetType.TREE.value.equals(dataSet.type)) {//树
mapRet.put(dataSet.name, new SwMap());
} else if (!SwEnum.DatasetType.ENUM.value.equals(dataSet.type)) {//非枚举
mapRet.put(dataSet.name, SwListData.create(null, 0));
}
}
return R.success(mapRet);
}

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 + "!");

DynRetBean bean = null;
if (SwEnum.DatasetType.LIST.value.equals(pageDataSet.type)) {//列表类
bean = DynRetBean.createList(provider.loadList(filter, pageDataSet));
} else if (SwEnum.DatasetType.TREE.value.equals(pageDataSet.type)) {//树类
// return new DynRetBean(loadTree());
} else {//列表类
bean = DynRetBean.createBean(provider.loadData(filter, pageDataSet));
}

return R.success(bean);
}
}

+ 48
- 1
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageListHandler.java Datei anzeigen

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

import cc.smtweb.framework.core.common.SwMap;
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.AbstractListHandler;
import cc.smtweb.framework.core.mvc.service.SqlNamedPara;
import cc.smtweb.framework.core.mvc.service.SqlPara;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;

import java.util.List;

/**
* Created by Akmm at 2022/5/26 15:58
*/
public class DynPageListHandler extends AbstractListHandler {
protected long pageId;
//过滤条件
private SwMap filter;

//对应的数据集定义
private PageDataset pageDataSet;

public DynPageListHandler(long pageId, SwMap filter, PageDataset pageDataSet) {
this.pageId = pageId;
this.filter = filter;
this.pageDataSet = pageDataSet;
}

@Override
protected String getCompId() {
return "dynpage_" + pageId + "_" + pageDataSet.id;
}

@Override
protected String getPkFieldName() {
return pageDataSet.idField;
}

@Override
protected SqlPara buildSqlPara() {
return null;
return DynPageHelper.buildSelectSql(pageDataSet, filter);
}

@Override
protected List<SwMap> queryData(String sql, SqlPara sqlPara) {
List<SwMap> list;
SqlNamedPara sp = (SqlNamedPara)sqlPara;
if (sqlPara.page > 0 && sqlPara.rows > 0) {
list = DbEngine.getInstance().pagedQueryN(sqlPara.sql, SwMap.class, (sqlPara.page - 1) * sqlPara.rows, sqlPara.rows, sp.mapParas);
} else {
list = DbEngine.getInstance().queryN(sqlPara.sql, sp.mapParas, SwMap.class);
}
ModelTable masterTable = ModelTableCache.getInstance().get(pageDataSet.masterTable);
EntityHelper.loadBeanLink(masterTable.getName(), list, sp.mapFieldAlias);
return list;
}

}

+ 4
- 4
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageLoadOneHandler.java Datei anzeigen

@@ -53,7 +53,7 @@ public class DynPageLoadOneHandler extends AbstractDynPageHandler {
*/
private SwMap loadOne() {
SqlNamedPara sqlPara = DynPageHelper.buildSelectSql(pageDataSet, filter);
SwMap map = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.paras, SwMap.class);
SwMap map = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.mapParas, SwMap.class);
if (map == null) {
throw new SwException("没有找到指定数据(ds=" + pageDataSet.name + ")");
}
@@ -70,9 +70,9 @@ public class DynPageLoadOneHandler extends AbstractDynPageHandler {
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.paras);
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.paras, SwMap.class);
list = DbEngine.getInstance().queryN(sqlPara.sql, sqlPara.mapParas, SwMap.class);
}
ModelTable masterTable = ModelTableCache.getInstance().get(pageDataSet.masterTable);
EntityHelper.loadBeanLink(masterTable.getName(), list, sqlPara.mapFieldAlias);
@@ -87,7 +87,7 @@ public class DynPageLoadOneHandler extends AbstractDynPageHandler {
try {
SqlNamedPara sqlPara = DynPageHelper.buildSumSql(pageDataSet, filter);

SwMap mapFooter = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.paras, SwMap.class);
SwMap mapFooter = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.mapParas, SwMap.class);

R r = R.success();
r.put("total", mapFooter.get(TOTAL_KEY));


+ 42
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java Datei anzeigen

@@ -0,0 +1,42 @@
package cc.smtweb.system.bpm.web.engine.dynPage;

import cc.smtweb.framework.core.common.SwException;
import cc.smtweb.framework.core.common.SwMap;
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.AbstractCompProvider;
import cc.smtweb.framework.core.mvc.service.IDataProvider;
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 cc.smtweb.system.bpm.web.design.form.define.PageDatasets;

/**
* Created by Akmm at 2022/5/26 18:40
*/
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, () -> {
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;
});

}
}

Laden…
Abbrechen
Speichern