瀏覽代碼

初始

master
郑根木 2 年之前
父節點
當前提交
ca85e73804
共有 13 個文件被更改,包括 406 次插入22 次删除
  1. +1
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/R.java
  2. +12
    -9
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java
  3. +1
    -1
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java
  4. +86
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultComboHandler.java
  5. +15
    -1
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java
  6. +111
    -0
      smtweb-framework/sw-framework-core/src/main/resources/config/demo.json
  7. +111
    -0
      smtweb-framework/sw-framework-core/target/classes/config/demo.json
  8. +1
    -1
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/catalog/ModelCatalogService.java
  9. +2
    -2
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/project/ModelProjectService.java
  10. +26
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelDatabaseComboHandler.java
  11. +7
    -6
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelDatabaseService.java
  12. +31
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelTableComboHandler.java
  13. +2
    -2
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelTableService.java

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

@@ -71,6 +71,7 @@ public class R extends SwMap {
R r = new R(ExceptionMessage.INNER_ERROR.getCode());
r.put("msg", msg);
r.put("exception", ex.getMessage());
ex.printStackTrace();
return r;
}



+ 12
- 9
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java 查看文件

@@ -4,14 +4,8 @@ import cc.smtweb.framework.core.R;
import cc.smtweb.framework.core.SwException;
import cc.smtweb.framework.core.SwMap;
import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.session.UserSession;

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

/**
* Created by Akmm at 2022/3/2 10:39
* 通用业务mvc总调度
@@ -24,10 +18,10 @@ public abstract class AbstractCompService {
public final static String TYPE_SAVE = "save";
public final static String TYPE_DEL = "del";

protected abstract IHandler createHanlder(String type);
protected abstract IHandler createHandler(String type);

private IHandler getHandler(SwMap params, UserSession us, String type) throws Exception {
IHandler handler = createHanlder(type);
IHandler handler = createHandler(type);
if (handler == null) throw new SwException("暂不支持此类服务:" + type);
if (params == null) params = new SwMap();
if (us == null) us = UserSession.createSys();
@@ -40,7 +34,6 @@ public abstract class AbstractCompService {
IHandler handler = getHandler(params, us, type);
return handler.doWork();
} catch (Exception e) {
e.printStackTrace();
return R.error("操作失败!", e);
}
}
@@ -100,6 +93,16 @@ public abstract class AbstractCompService {
}
}

//combo数据过滤
public R comboFilter(@SwBody SwMap params, UserSession us) {
try {
DefaultComboHandler handler = (DefaultComboHandler) getHandler(params, us, TYPE_COMBO);
return handler.filter();
} catch (Exception e) {
return R.error("操作失败!", e);
}
}

//树数据
public R tree(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_TREE);


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

@@ -58,7 +58,7 @@ public abstract class AbstractListHandler extends AbstractHandler {
}

protected SwListData listData() throws Exception {
List<SwMap> listData = new ArrayList<>();
List<SwMap> listData;
SqlPara sqlPara = buildDataSql();

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


+ 86
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultComboHandler.java 查看文件

@@ -0,0 +1,86 @@
package cc.smtweb.framework.core.mvc.service;

import cc.smtweb.framework.core.R;
import cc.smtweb.framework.core.SwException;
import cc.smtweb.framework.core.SwMap;
import cc.smtweb.framework.core.cache.AbstractCache;
import cc.smtweb.framework.core.cache.CacheManager;
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.ModelField;
import cc.smtweb.framework.core.db.vo.ModelLinkName;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.db.vo.def.FieldType;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
* Created by Akmm at 2022/3/2 19:52
* 默认实体实现
*/
public class DefaultComboHandler<T extends DefaultEntity> extends DefaultListHandler<T> {
protected String tableName;

public DefaultComboHandler(String tableName) {
super(tableName);
}

public R filter() throws Exception {
return R.success(filterData());
}

protected SwListData filterData() throws Exception {
String text = params.readString("text");
if (StringUtils.isEmpty(text)) throw new SwException("没有搜素内容!");

SqlPara sqlPara = buildDataSql();
String sort = params.readString("sort");
String order = params.readString("order");

StringBuilder sqlFilter = new StringBuilder();
List<Object> args = new ArrayList<>(sqlPara.paras.length);
Collections.addAll(args, sqlPara.paras);

buildFilterCondition(text, sqlFilter, args);
if (sqlFilter.length() == 0) throw new SwException("没有待搜索的字段!");

String sql = "select ar.* from (" + sqlPara.sql + ") ar where " + sqlFilter.substring(5);
if (StringUtils.isNotEmpty(sort)) {
sql += " order by ar." + sort + " " + order;
if (StringUtils.isNotEmpty(getPkFieldName())) {
sql += "," + getPkFieldName();
}
}

List<SwMap> listData = DbEngine.getInstance().query(sql, SwMap.class, args.toArray());
afterQuery(listData);
return SwListData.create(listData, false);
}

//搜索条件
protected void buildFilterCondition(String text, StringBuilder sqlFilter, List<Object> args) {
List<String> fields = new ArrayList<>();
getFilterFields(fields);
if (fields.isEmpty()) return;

text = text + "%";//combo不支持全模糊
for (String field: fields) {
sqlFilter.append(" and " + field + " like ?");
args.add(text);
}

}

//构建参与搜索的字段,默认为code和name字段
protected void getFilterFields(List<String> fields) {
ModelTable table = ModelTableCache.getInstance().getByName(tableName);
ModelField field = table.findFieldByType(FieldType.CODE);
if (field != null) fields.add(field.getName());

field = table.findFieldByType(FieldType.NAME);
if (field != null) fields.add(field.getName());
}
}

+ 15
- 1
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java 查看文件

@@ -32,7 +32,21 @@ public class DefaultListHandler<T extends DefaultEntity> extends AbstractListHan
StringBuilder sql = new StringBuilder(512);
List<Object> args = new ArrayList<>();
dao.handleSelect(sql, null);
buildCondition(sql, args);

StringBuilder sqlCondition = new StringBuilder(128);
buildCondition(sqlCondition, args);
String filter = sqlCondition.toString().trim();
if (StringUtils.isNotEmpty(filter)) {
if (filter.startsWith("or ")) {
sql.append("\nwhere ").append(filter.substring(3));
} else if (filter.startsWith("and ")) {
sql.append("\nwhere ").append(filter.substring(4));
} else if (!filter.startsWith("where ")) {
sql.append("\nwhere ").append(filter);
} else {
sql.append(filter);
}
}

buildOrder(sql);



+ 111
- 0
smtweb-framework/sw-framework-core/src/main/resources/config/demo.json 查看文件

@@ -0,0 +1,111 @@
{
"fields": [
{
"name": "mc_id",
"fieldType": "ID",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID"
},
{
"name": "mc_parent_id",
"fieldType": "PARENT",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "2"
},
{
"name": "mc_prj_id",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "1"
},
{
"name": "mc_code",
"fieldType": "CODE",
"dataType": "CODE",
"null": "0",
"default": "",
"title": "编码",
"link": "",
"editor": ""
},
{
"name": "mc_create_uid",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "创建人",
"link": "",
"editor": ""
},
{
"name": "mc_update_uid",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "最后更新人",
"link": "",
"editor": ""
},
{
"name": "mc_create_at",
"fieldType": "",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "创建时间",
"link": "",
"editor": ""
},
{
"name": "mc_create_at",
"fieldType": "",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "创建时间",
"link": "",
"editor": ""
},
{
"name": "mc_update_at",
"fieldType": "",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "最后更新时间",
"link": "",
"editor": ""
}
],
"indexes": [
{
"name": "pk",
"fields": "mc_id",
"type": "P"
}
],
"caches": [
{
"name": "pr",
"title": "按树型",
"fields": "mc_parent_id",
"type": "L"
},
{
"name": "prj",
"title": "按目录",
"fields": "mc_prj_id",
"type": "L"
}
]
}

+ 111
- 0
smtweb-framework/sw-framework-core/target/classes/config/demo.json 查看文件

@@ -0,0 +1,111 @@
{
"fields": [
{
"name": "mc_id",
"fieldType": "ID",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID"
},
{
"name": "mc_parent_id",
"fieldType": "PARENT",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "2"
},
{
"name": "mc_prj_id",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "1"
},
{
"name": "mc_code",
"fieldType": "CODE",
"dataType": "CODE",
"null": "0",
"default": "",
"title": "编码",
"link": "",
"editor": ""
},
{
"name": "mc_create_uid",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "创建人",
"link": "",
"editor": ""
},
{
"name": "mc_update_uid",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "最后更新人",
"link": "",
"editor": ""
},
{
"name": "mc_create_at",
"fieldType": "",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "创建时间",
"link": "",
"editor": ""
},
{
"name": "mc_create_at",
"fieldType": "",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "创建时间",
"link": "",
"editor": ""
},
{
"name": "mc_update_at",
"fieldType": "",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "最后更新时间",
"link": "",
"editor": ""
}
],
"indexes": [
{
"name": "pk",
"fields": "mc_id",
"type": "P"
}
],
"caches": [
{
"name": "pr",
"title": "按树型",
"fields": "mc_parent_id",
"type": "L"
},
{
"name": "prj",
"title": "按目录",
"fields": "mc_prj_id",
"type": "L"
}
]
}

+ 1
- 1
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/catalog/ModelCatalogService.java 查看文件

@@ -14,7 +14,7 @@ import cc.smtweb.framework.core.session.UserSession;
@SwService
public class ModelCatalogService extends AbstractCompService {
@Override
protected IHandler createHanlder(String type) {
protected IHandler createHandler(String type) {
switch (type) {
case TYPE_LOAD:
return new DefaultLoadHandler<ModelCatalog>(ModelCatalog.ENTITY_NAME);


+ 2
- 2
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/project/ModelProjectService.java 查看文件

@@ -10,7 +10,7 @@ import cc.smtweb.framework.core.mvc.service.*;
@SwService
public class ModelProjectService extends AbstractCompService {
@Override
protected IHandler createHanlder(String type) {
protected IHandler createHandler(String type) {
switch (type) {
case TYPE_LOAD:
return new DefaultLoadHandler<ModelProject>(ModelProject.ENTITY_NAME);
@@ -21,7 +21,7 @@ public class ModelProjectService extends AbstractCompService {
case TYPE_LIST:
return new DefaultListHandler<>(ModelProject.ENTITY_NAME);
case TYPE_COMBO:
return new DefaultListHandler<>(ModelProject.ENTITY_NAME);
return new DefaultComboHandler<>(ModelProject.ENTITY_NAME);
}
return null;
}


+ 26
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelDatabaseComboHandler.java 查看文件

@@ -0,0 +1,26 @@
package cc.smtweb.system.bpm.web.design.table;

import cc.smtweb.framework.core.db.vo.ModelDatabase;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.mvc.service.DefaultComboHandler;

import java.util.List;

/**
* Created by Akmm at 2022/3/22 19:25
*/
public class ModelDatabaseComboHandler extends DefaultComboHandler<ModelDatabase> {
public ModelDatabaseComboHandler() {
super(ModelDatabase.ENTITY_NAME);
}

@Override
protected void buildCondition(StringBuilder sql, List<Object> args) {
super.buildCondition(sql, args);
long prj_id = params.readLong("prj_id");
if (prj_id > 0) {
sql.append(" and db_prj_id=?");
args.add(prj_id);
}
}
}

+ 7
- 6
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelDatabaseService.java 查看文件

@@ -1,6 +1,7 @@
package cc.smtweb.system.bpm.web.design.table;

import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.db.vo.ModelDatabase;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.mvc.service.*;
import cc.smtweb.system.bpm.web.design.catalog.ModelCatalog;
@@ -11,18 +12,18 @@ import cc.smtweb.system.bpm.web.design.catalog.ModelCatalog;
@SwService
public class ModelDatabaseService extends AbstractCompService {
@Override
protected IHandler createHanlder(String type) {
protected IHandler createHandler(String type) {
switch (type) {
case TYPE_LOAD:
return new DefaultLoadHandler<ModelCatalog>(ModelTable.ENTITY_NAME);
return new DefaultLoadHandler<ModelCatalog>(ModelDatabase.ENTITY_NAME);
case TYPE_SAVE:
return new DefaultSaveHandler<>(ModelTable.ENTITY_NAME);
return new DefaultSaveHandler<>(ModelDatabase.ENTITY_NAME);
case TYPE_DEL:
return new DefaultDelHandler<>(ModelTable.ENTITY_NAME);
return new DefaultDelHandler<>(ModelDatabase.ENTITY_NAME);
case TYPE_LIST:
return new DefaultListHandler<>(ModelTable.ENTITY_NAME);
return new DefaultListHandler<>(ModelDatabase.ENTITY_NAME);
case TYPE_COMBO:
return new DefaultListHandler<>(ModelTable.ENTITY_NAME);
return new ModelDatabaseComboHandler();

}
return null;


+ 31
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelTableComboHandler.java 查看文件

@@ -0,0 +1,31 @@
package cc.smtweb.system.bpm.web.design.table;

import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.mvc.service.DefaultComboHandler;

import java.util.List;

/**
* Created by Akmm at 2022/3/22 19:25
*/
public class ModelTableComboHandler extends DefaultComboHandler<ModelTable> {
public ModelTableComboHandler() {
super(ModelTable.ENTITY_NAME);
}

@Override
protected void buildCondition(StringBuilder sql, List<Object> args) {
super.buildCondition(sql, args);
long prj_id = params.readLong("prj_id");
if (prj_id > 0) {
sql.append(" and tb_prj_id=?");
args.add(prj_id);
}

long db_id = params.readLong("db_id");
if (db_id > 0) {
sql.append(" and tb_db_id=?");
args.add(db_id);
}
}
}

+ 2
- 2
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelTableService.java 查看文件

@@ -12,7 +12,7 @@ import cc.smtweb.system.bpm.web.design.catalog.ModelCatalogTreeHandler;
@SwService
public class ModelTableService extends AbstractCompService {
@Override
protected IHandler createHanlder(String type) {
protected IHandler createHandler(String type) {
switch (type) {
case TYPE_LOAD:
return new DefaultLoadHandler<ModelCatalog>(ModelTable.ENTITY_NAME);
@@ -23,7 +23,7 @@ public class ModelTableService extends AbstractCompService {
case TYPE_LIST:
return new DefaultListHandler<>(ModelTable.ENTITY_NAME);
case TYPE_COMBO:
return new DefaultListHandler<>(ModelTable.ENTITY_NAME);
return new ModelTableComboHandler();

}
return null;


Loading…
取消
儲存