|
|
@@ -17,6 +17,7 @@ import cc.smtweb.framework.core.util.NumberUtil; |
|
|
|
import cc.smtweb.framework.core.util.PubUtil; |
|
|
|
import cc.smtweb.system.bpm.web.design.form.define.*; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import reactor.util.annotation.Nullable; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashSet; |
|
|
@@ -47,21 +48,9 @@ public class DynPageHelper { |
|
|
|
return bean.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建select fields from table |
|
|
|
* |
|
|
|
* @param dataSet |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static SqlNamedPara buildSelectSql(PageDataset dataSet, Map<String, Object> params) { |
|
|
|
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params); |
|
|
|
buildSelectSql(dataSet, params, sqlNamedPara); |
|
|
|
return sqlNamedPara; |
|
|
|
} |
|
|
|
|
|
|
|
public static void buildSelectSql(PageDataset dataSet, Map<String, Object> params, SqlNamedPara sqlNamedPara) { |
|
|
|
private static void buildSelectSql(PageDataset dataSet, Map<String, Object> params, SqlNamedPara sqlNamedPara, IBuildSqlListener listener) { |
|
|
|
StringBuilder sql = new StringBuilder(512); |
|
|
|
sql.append(buildSelFieldsSql(dataSet, sqlNamedPara)); |
|
|
|
sql.append(buildSelFieldsSql(dataSet, sqlNamedPara, listener)); |
|
|
|
if (StringUtils.isNotEmpty(sqlNamedPara.sql)) { |
|
|
|
sql.append(" where ").append(sqlNamedPara.sql); |
|
|
|
} |
|
|
@@ -79,11 +68,27 @@ public class DynPageHelper { |
|
|
|
sqlNamedPara.rows = MapUtil.readInt(params, SwConsts.PARAM_ROWS); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建select fields from table |
|
|
|
* |
|
|
|
* @param dataSet |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static SqlNamedPara buildSelectSql(PageDataset dataSet, Map<String, Object> params) { |
|
|
|
return buildSelectSqlEx(dataSet, params, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static SqlNamedPara buildSelectSqlEx(PageDataset dataSet, Map<String, Object> params, IBuildSqlListener listener) { |
|
|
|
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params, listener); |
|
|
|
buildSelectSql(dataSet, params, sqlNamedPara, listener); |
|
|
|
return sqlNamedPara; |
|
|
|
} |
|
|
|
|
|
|
|
//构建树型查询语句,插入parent_id=? |
|
|
|
public static SqlNamedPara buildTreeSelectSql(PageDataset dataSet, SwMap params, long parentId) { |
|
|
|
ModelTable table = ModelTableCache.getInstance().get(dataSet.masterTable); |
|
|
|
if (table == null) throw new SwException("没有找到指定的表:" + dataSet.masterTable); |
|
|
|
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params); |
|
|
|
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params, null); |
|
|
|
if (table.getType() == SwEnum.TableType.TYPE_TREE.value) {//是树型结构,才做处理 |
|
|
|
ModelField field = table.findFieldByType(SwEnum.FieldType.PARENT_ID.value); |
|
|
|
if (field == null) throw new SwException("树型表(" + table.getName() + ")未定义上级id字段!"); |
|
|
@@ -96,7 +101,7 @@ public class DynPageHelper { |
|
|
|
sqlNamedPara.addParas("parent_id", parentId); |
|
|
|
} |
|
|
|
|
|
|
|
buildSelectSql(dataSet, params, sqlNamedPara); |
|
|
|
buildSelectSql(dataSet, params, sqlNamedPara, null); |
|
|
|
return sqlNamedPara; |
|
|
|
} |
|
|
|
|
|
|
@@ -104,7 +109,7 @@ public class DynPageHelper { |
|
|
|
public static SqlNamedPara buildFilterSelectSql(PageDataset dataSet, SwMap params, String text) { |
|
|
|
ModelTable table = ModelTableCache.getInstance().get(dataSet.masterTable); |
|
|
|
if (table == null) throw new SwException("没有找到指定的表:" + dataSet.masterTable); |
|
|
|
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params); |
|
|
|
SqlNamedPara sqlNamedPara = buildWhereSql(dataSet, params, null); |
|
|
|
if (StringUtils.isNotEmpty(text)) {//有文本信息 |
|
|
|
StringBuilder sql = new StringBuilder(128); |
|
|
|
ModelField field = table.findFieldByType(SwEnum.FieldType.CODE.value); |
|
|
@@ -127,7 +132,7 @@ public class DynPageHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
buildSelectSql(dataSet, params, sqlNamedPara); |
|
|
|
buildSelectSql(dataSet, params, sqlNamedPara, null); |
|
|
|
return sqlNamedPara; |
|
|
|
} |
|
|
|
|
|
|
@@ -139,7 +144,11 @@ public class DynPageHelper { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static SqlNamedPara buildSumSql(PageDataset dataSet, Map<String, Object> params) { |
|
|
|
SqlNamedPara sqlNamedPara = buildSelectSql(dataSet, params); |
|
|
|
return buildSumSqlEx(dataSet, params, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static SqlNamedPara buildSumSqlEx(PageDataset dataSet, Map<String, Object> params, IBuildSqlListener listener) { |
|
|
|
SqlNamedPara sqlNamedPara = buildSelectSqlEx(dataSet, params, listener); |
|
|
|
StringBuilder sql = new StringBuilder(256); |
|
|
|
sql.append("select count(1) " + TOTAL_KEY); |
|
|
|
for (PageDatasetField field : dataSet.fields) { |
|
|
@@ -156,7 +165,7 @@ public class DynPageHelper { |
|
|
|
return sqlNamedPara; |
|
|
|
} |
|
|
|
|
|
|
|
private static String buildSelFieldsSql(PageDataset dataSet, SqlNamedPara sqlNamedPara) { |
|
|
|
private static String buildSelFieldsSql(PageDataset dataSet, SqlNamedPara sqlNamedPara, IBuildSqlListener listener) { |
|
|
|
StringBuilder sql = new StringBuilder(512); |
|
|
|
//主表 |
|
|
|
ModelTable masterTable = ModelTableCache.getInstance().get(dataSet.masterTable); |
|
|
@@ -175,6 +184,7 @@ public class DynPageHelper { |
|
|
|
} |
|
|
|
sql.setCharAt(sql.length() - 1, ' '); |
|
|
|
sql.append(" from ").append(masterTable.getSchemaTableName()); |
|
|
|
if (listener != null) listener.buildSelect(dataSet, sql); |
|
|
|
return sql.toString(); |
|
|
|
} else { |
|
|
|
return dataSet.sql; |
|
|
@@ -188,7 +198,7 @@ public class DynPageHelper { |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static SqlNamedPara buildWhereSql(PageDataset dataSet, Map<String, Object> params) { |
|
|
|
private static SqlNamedPara buildWhereSql(PageDataset dataSet, Map<String, Object> params, IBuildSqlListener listener) { |
|
|
|
StringBuilder sql = new StringBuilder(512); |
|
|
|
SwMap args = new SwMap(); |
|
|
|
|
|
|
@@ -210,6 +220,7 @@ public class DynPageHelper { |
|
|
|
for (String s : setFixedFilter) { |
|
|
|
args.put(s, MapUtil.readString(params, s, "")); |
|
|
|
} |
|
|
|
if (listener != null) listener.buildWhere(dataSet, sql, args); |
|
|
|
return new SqlNamedPara(sql.toString(), args); |
|
|
|
} |
|
|
|
|
|
|
|