@@ -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; | |||
} | |||
@@ -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); | |||
@@ -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); | |||
@@ -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()); | |||
} | |||
} |
@@ -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); | |||
@@ -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" | |||
} | |||
] | |||
} |
@@ -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" | |||
} | |||
] | |||
} |
@@ -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); | |||
@@ -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; | |||
} | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -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; | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -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; | |||