瀏覽代碼

loadSqlFields接口调整

master
郑根木 2 年之前
父節點
當前提交
8c7ce13dd5
共有 1 個檔案被更改,包括 19 行新增1 行删除
  1. +19
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java

+ 19
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java 查看文件

@@ -6,6 +6,9 @@ import cc.smtweb.framework.core.common.R;
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.cache.ModelTableCache;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.mvc.service.AbstractCompService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.mvc.service.DefaultDelHandler;
@@ -127,6 +130,11 @@ public class ModelFormService extends AbstractCompService {
try {
String sql = params.readString("sql");
if (StringUtils.isEmpty(sql)) return R.error("没有传入的sql!");
long masterTable = params.readLong("masterTable");
if (masterTable <= 0L) return R.error("没有传入的masterTable!");
ModelTable table = ModelTableCache.getInstance().get(masterTable);
if (table == null) return R.error("没有找到表定义信息(masterTable=" + masterTable + ")!");

sql = sql.trim().toLowerCase();
if (!sql.startsWith("select")) return R.error("非查询类sql,禁止执行!");
if (sql.contains(";")) return R.error("sql内禁止出现分号!");
@@ -137,9 +145,19 @@ public class ModelFormService extends AbstractCompService {

for (int i = 1, count = metaData.getColumnCount(); i <= count; i++) {
SwMap col = new SwMap(2);
col.put("name", metaData.getColumnLabel(i));
final String colName = metaData.getColumnLabel(i).toLowerCase();
col.put("name", colName);
SwEnum.DataTypeBean dtb = SwEnum.DataType.getBySqlType(metaData.getColumnType(i), metaData.getPrecision(i), metaData.getScale(i));
col.put("dataType", dtb.value);
ModelField field = table.findField(colName);
if (field != null) {
col.put("null", field.getNotNull());
col.put("default", field.getDefaultValue());
col.put("title", field.getTitle());
col.put("link", field.getLink());
col.put("table", table.getId());
col.put("table_text", table.getTitle());
}
fields.add(col);
}
return fields;


Loading…
取消
儲存