浏览代码

页面设计及引擎

master
郑根木 2 年前
父节点
当前提交
c4eaf42930
共有 9 个文件被更改,包括 114 次插入26 次删除
  1. +1
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java
  2. +25
    -1
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  3. +5
    -3
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java
  4. +2
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/PageDatasetField.java
  5. +23
    -2
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageHelper.java
  6. +6
    -4
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageLoadOneHandler.java
  7. +5
    -4
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageSaveHandler.java
  8. +13
    -11
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageService.java
  9. +34
    -1
      smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java

+ 1
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java 查看文件

@@ -16,4 +16,5 @@ public interface SwConsts {
//列表分页的页码和每页记录数
String PARAM_PAGE = "page";
String PARAM_ROWS = "rows";
String TOTAL_KEY = "total_count";
}

+ 25
- 1
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java 查看文件

@@ -1,6 +1,7 @@
package cc.smtweb.framework.core.common;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
* Created by Akmm at 2022/3/23 9:39
@@ -129,6 +130,12 @@ public interface SwEnum {
mapAll.put(value, bean);
return bean;
}

@Override
public DataTypeBean getByValue(String value) {
if (value == null) return null;
return super.getByValue(value.toLowerCase());
}
}

/**
@@ -197,7 +204,7 @@ public interface SwEnum {
* 操作符类型:::and/or/=/>=/<=/like/p
*/
class OptType extends StrEnum {
public static FilterType instance = new FilterType();
public static OptType instance = new OptType();

public static StrEnumBean AND = instance.addEnum("and", "且");
public static StrEnumBean OR = instance.addEnum("or", "或");
@@ -212,4 +219,21 @@ public interface SwEnum {
public static StrEnumBean PLIKE = instance.addEnum("plike", "开始以");
public static StrEnumBean LIKE = instance.addEnum("like", "包含");
}

//合计栏类型 "summary": "COUNT/SUM/AVG/MAX/MIN/其他为文本"
class SummaryType extends StrEnum {
public static SummaryType instance = new SummaryType();

public static StrEnumBean COUNT = instance.addEnum("count", "计数");
public static StrEnumBean SUM = instance.addEnum("sum", "求和");
public static StrEnumBean AVG = instance.addEnum("avg", "均值");
public static StrEnumBean MAX = instance.addEnum("max", "最大值");
public static StrEnumBean MIN = instance.addEnum("min", "最小值");

//是字符串
public boolean isText(String v) {
if (StringUtils.isEmpty(v)) return true;
return !mapAll.containsKey(v.toLowerCase());
}
}
}

+ 5
- 3
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java 查看文件

@@ -18,6 +18,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY;

/**
* Created by Akmm at 2022/3/2 19:44
* 列表服务
@@ -91,7 +93,7 @@ public abstract class AbstractListHandler extends AbstractHandler {

List<FooterField> footerFields = getFooterFields();
StringBuilder sql = new StringBuilder(128);
sql.append("select count(1) total_count");
sql.append("select count(1) " + TOTAL_KEY);
int n = 2;
for (FooterField cn : footerFields) {
if (!FooterField.STATIC_TEXT.equals(cn.type)) {
@@ -123,10 +125,10 @@ public abstract class AbstractListHandler extends AbstractHandler {
if (sqlParaSum == null) return R.success();
setCache(KEY_SQLPARA_SUM, sqlParaSum);

Map<String, Object> mapFooter = DbEngine.getInstance().queryEntity(sqlParaSum.sql, Map.class, sqlParaSum.paras);
SwMap mapFooter = DbEngine.getInstance().queryEntity(sqlParaSum.sql, SwMap.class, sqlParaSum.paras);

R r = R.success();
r.put("total", mapFooter.get("total_count"));
r.put("total", mapFooter.get(TOTAL_KEY));
r.put("footer", mapFooter);
return r;
} catch (Exception e) {


+ 2
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/PageDatasetField.java 查看文件

@@ -14,6 +14,8 @@ public class PageDatasetField {
//有别名取别名,无别名同字段名
public String name;
public String label;
//合计栏
public String summary;

public String remark;
//字段类型,如编码字段,参见FieldTypeDef


+ 23
- 2
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageHelper.java 查看文件

@@ -19,6 +19,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY;

/**
* Created by Akmm at 2022/4/23 10:01
* 动态页面辅助类
@@ -26,6 +28,7 @@ import java.util.Set;
public class DynPageHelper {
/**
* 新建bean
*
* @param dataSet
* @return
*/
@@ -71,6 +74,23 @@ public class DynPageHelper {
return sqlNamedPara;
}

public static SqlNamedPara buildSumSql(PageDataSet dataSet, Map<String, Object> params) {
SqlNamedPara sqlNamedPara = buildSelectSql(dataSet, params);
StringBuilder sql = new StringBuilder(256);
sql.append("select count(1) " + TOTAL_KEY);
for (PageDatasetField field : dataSet.fields) {
if (StringUtils.isEmpty(field.summary)) continue;
sql.append(",");
if (!SwEnum.SummaryType.instance.isText(field.summary)) {
sql.append(field.summary).append("(").append(field.name).append(") ").append(field.name);
} else {
sql.append("'").append(field.summary).append("' ").append(field.name);
}
}
sqlNamedPara.sql = sql.toString() + " from (" + sqlNamedPara.sql + ") xxxxa";
return sqlNamedPara;
}

private static String buildSelFieldsSql(PageDataSet dataSet, SqlNamedPara sqlNamedPara) {
StringBuilder sql = new StringBuilder(512);
//主表
@@ -111,7 +131,7 @@ public class DynPageHelper {
}
//记录归属于固定条件的filter,最后设置参数
Set<String> setFixedFilter = new HashSet<>();
for (PageDatasetFilter filter: dataSet.filters) {
for (PageDatasetFilter filter : dataSet.filters) {
setFixedFilter.add(filter.name);
}
if (!dataSet.dynCond.isEmpty()) {
@@ -121,7 +141,7 @@ public class DynPageHelper {
sql.append(s);
}
}
for (String s: setFixedFilter) {
for (String s : setFixedFilter) {
args.put(s, params.get(s));
}
return new SqlNamedPara(sql.toString(), args);
@@ -129,6 +149,7 @@ public class DynPageHelper {

/**
* 构建动态条件
*
* @param dataSet
* @param dynCond
* @param params


+ 6
- 4
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageLoadOneHandler.java 查看文件

@@ -17,6 +17,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY;

/**
* Created by Akmm at 2022/4/21 17:53
*/
@@ -87,13 +89,13 @@ public class DynPageLoadOneHandler extends AbstractDynPageHandler {
*/
public R getTotal() {
try {
SqlNamedPara sqlPara = DynPageHelper.buildSelectSql(pageDataSet, filter);
SqlNamedPara sqlPara = DynPageHelper.buildSumSql(pageDataSet, filter);

int total = DbEngine.getInstance().queryIntN("select count(1) from (" + sqlPara.sql + ") xxxa", sqlPara.paras);
SwMap mapFooter = DbEngine.getInstance().queryEntityN(sqlPara.sql, sqlPara.paras, SwMap.class);

R r = R.success();
r.put("total", total);
// r.put("footer", mapFooter);
r.put("total", mapFooter.get(TOTAL_KEY));
r.put("footer", mapFooter);
return r;
} catch (Exception e) {
return R.error("计算合计失败!", e);


+ 5
- 4
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageSaveHandler.java 查看文件

@@ -10,6 +10,7 @@ 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.jdbc.IDbWorker;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelIndex;
@@ -29,10 +30,10 @@ import java.util.*;
* 入参:{pageId, data:}
*/
public class DynPageSaveHandler extends AbstractDynPageHandler {
private Map<String, List<DefaultEntity>> mapTreeBean = null;
private Map<String, List<DefaultEntity>> mapTreeBean = new HashMap<>();

@Override
public R doWork() throws Exception {
public R doWork() {
return saveAll();
}

@@ -56,7 +57,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
}
checkBean(bean);

DbEngine.getInstance().doTrans(new IDbWorker() {
DbEngine.getInstance().doTrans(new AbsDbWorker() {
@Override
public void work() {
saveBean(bean);
@@ -107,7 +108,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler {
}
checkBean(bean);
}
DbEngine.getInstance().doTrans(new IDbWorker() {
DbEngine.getInstance().doTrans(new AbsDbWorker() {
@Override
public void work() {
for (DefaultEntity bean: map.values()) {


+ 13
- 11
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/engine/DynPageService.java 查看文件

@@ -16,26 +16,18 @@ import cc.smtweb.system.bpm.web.design.table.ModelCatalogTreeHandler;
@SwService
public class DynPageService extends AbstractCompService {
public final static String TYPE_ADD = "add";
public final static String TYPE_LOAD_ONE = "loadOne";
public final static String TYPE_DEL_ONE = "delOne";

@Override
protected IHandler createHandler(String type) {
switch (type) {
case TYPE_ADD:
return new DynPageAddHandler();
case TYPE_LOAD_ONE:
case TYPE_LOAD:
return new DynPageLoadOneHandler();
case TYPE_SAVE:
return new DynPageSaveHandler();
case TYPE_DEL:
return new DefaultDelHandler<>(ModelCatalog.ENTITY_NAME);
case TYPE_DEL_ONE:
return new DefaultDelHandler<>(ModelCatalog.ENTITY_NAME);
case TYPE_LIST:
return new DefaultListHandler<>(ModelCatalog.ENTITY_NAME);
case TYPE_TREE:
return new ModelCatalogTreeHandler();
return new DynPageDelHandler();
}
return null;
}
@@ -55,10 +47,20 @@ public class DynPageService extends AbstractCompService {
}
}

//删除指定数据集
public R delOne(@SwBody SwMap params, UserSession us) {
try {
DynPageDelHandler handler = (DynPageDelHandler) getHandler(params, us, TYPE_DEL);
return handler.delOne();
} catch (Exception e) {
return R.error("操作失败!", e);
}
}

//列表总记录数及合计栏
public R total(@SwBody SwMap params, UserSession us) {
try {
DynPageLoadOneHandler handler = (DynPageLoadOneHandler) getHandler(params, us, TYPE_LOAD_ONE);
DynPageLoadOneHandler handler = (DynPageLoadOneHandler) getHandler(params, us, TYPE_LOAD);
return handler.getTotal();
} catch (Exception e) {
return R.error("操作失败!", e);


+ 34
- 1
smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java 查看文件

@@ -27,11 +27,44 @@ public class ModelFormTest {
SwMap params = new SwMap();
params.put("pageId", 1);
params.put("dataset", "modelProject");
Map<String, Object> filter = new HashMap<>();
SwMap filter = new SwMap();
filter.put("prj_name", "测试");
params.put("filter", filter);
DynPageService service = new DynPageService();
R r = service.load(params, null);
System.out.println(r.readSuccess());
}

@Test
public void testSave() {
//{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}}
SwMap params = new SwMap();
params.put("pageId", 1);
params.put("dataset", "modelProject");
SwMap data = new SwMap();
SwMap form = new SwMap();
form.put("prj_id", "12345");
form.put("prj_name", "test12345");
form.put("prj_desc", "this is test12345");
data.put("form", form);
params.put("data", data);
SwMap filter = new SwMap();
filter.put("prj_name", "测试");
params.put("filter", filter);
DynPageService service = new DynPageService();
R r = service.saveOne(params, null);
System.out.println(r.readSuccess());
}

@Test
public void testDel() {
//{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}}
SwMap params = new SwMap();
params.put("pageId", 1);
params.put("id", 12345);

DynPageService service = new DynPageService();
R r = service.del(params, null);
System.out.println(r.readSuccess());
}
}

正在加载...
取消
保存