mapper拼接类
parent
ce90fa1def
commit
8b8ab74483
|
@ -0,0 +1,110 @@
|
||||||
|
package aiyh.utils.recordset;
|
||||||
|
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>构建sql</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/5/12 20:51</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class MapperBuilderSql {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>构建更新sql</h2>
|
||||||
|
*
|
||||||
|
* @param table 表名称
|
||||||
|
* @param param 参数
|
||||||
|
* @return 构建的sql
|
||||||
|
*/
|
||||||
|
public static String builderUpdateSql(String table, Map<String, Object> param) {
|
||||||
|
if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) {
|
||||||
|
throw new CustomerException("tableName or param can not to be null!");
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("update ").append(table).append(" set ");
|
||||||
|
for (Map.Entry<String, Object> entry : param.entrySet()) {
|
||||||
|
sb.append(" ")
|
||||||
|
.append(entry.getKey())
|
||||||
|
.append(" = ")
|
||||||
|
.append("#{")
|
||||||
|
.append(entry.getKey())
|
||||||
|
.append("}")
|
||||||
|
.append(",");
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>构建插入sql</h2>
|
||||||
|
*
|
||||||
|
* @param table 表名称
|
||||||
|
* @param param 参数
|
||||||
|
* @return 构建的sql
|
||||||
|
*/
|
||||||
|
public static String builderInsertSql(String table, Map<String, Object> param) {
|
||||||
|
if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) {
|
||||||
|
throw new CustomerException("tableName or param can not to be null!");
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
StringBuilder sbValue = new StringBuilder();
|
||||||
|
sb.append("insert into ").append(table).append(" (");
|
||||||
|
sbValue.append(") values ( ");
|
||||||
|
for (Map.Entry<String, Object> entry : param.entrySet()) {
|
||||||
|
sb.append(entry.getKey()).append(" ,");
|
||||||
|
sbValue.append(" #{").append(entry.getKey()).append("},");
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
sbValue.deleteCharAt(sbValue.length() - 1);
|
||||||
|
sb.append(sbValue).append(")");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String builderWhereAnd(Map<String, Object> param, boolean containsWhere) {
|
||||||
|
return builderWhereAnd(param, "whereParam", containsWhere);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String builderWhereAnd(Map<String, Object> param) {
|
||||||
|
return builderWhereAnd(param, "whereParam", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String builderNoWhereAndEn(Map<String, Object> param, boolean containsWhere) {
|
||||||
|
return builderWhereAnd(param, "", containsWhere);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String builderNoWhereAndEn(Map<String, Object> param) {
|
||||||
|
return builderWhereAnd(param, "", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>构建and条件</h2>
|
||||||
|
*
|
||||||
|
* @param param 参数
|
||||||
|
* @param wherePrefix 条件拼接前缀
|
||||||
|
* @param containsWhere 是否包含where
|
||||||
|
* @return 构建的where条件
|
||||||
|
*/
|
||||||
|
public static String builderWhereAnd(Map<String, Object> param, String wherePrefix, boolean containsWhere) {
|
||||||
|
if (CollectionUtil.isEmpty(param)) {
|
||||||
|
throw new CustomerException("tableName or param can not to be null!");
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (containsWhere) {
|
||||||
|
sb.append(" where ");
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Object> entry : param.entrySet()) {
|
||||||
|
sb.append(entry.getKey()).append(" and ").append("#{");
|
||||||
|
if (StrUtil.isNotBlank(wherePrefix)) {
|
||||||
|
sb.append(wherePrefix).append(".");
|
||||||
|
}
|
||||||
|
sb.append(entry.getKey()).append("}");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,18 +5,15 @@ import aiyh.utils.Util;
|
||||||
import aiyh.utils.mapUtil.UtilHashMap;
|
import aiyh.utils.mapUtil.UtilHashMap;
|
||||||
import aiyh.utils.mapUtil.UtilLinkedHashMap;
|
import aiyh.utils.mapUtil.UtilLinkedHashMap;
|
||||||
import aiyh.utils.sqlUtil.builderSql.BuilderSql;
|
import aiyh.utils.sqlUtil.builderSql.BuilderSql;
|
||||||
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
|
|
||||||
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
|
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
|
||||||
|
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
|
||||||
import aiyh.utils.sqlUtil.whereUtil.Where;
|
import aiyh.utils.sqlUtil.whereUtil.Where;
|
||||||
import aiyh.utils.sqlUtil.whereUtil.impl.WhereImpl;
|
import aiyh.utils.sqlUtil.whereUtil.impl.WhereImpl;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
|
||||||
|
|
||||||
import java.beans.BeanInfo;
|
import java.beans.BeanInfo;
|
||||||
import java.beans.IntrospectionException;
|
|
||||||
import java.beans.Introspector;
|
import java.beans.Introspector;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
@ -29,15 +26,16 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
public class BuilderSqlImpl implements BuilderSql {
|
public class BuilderSqlImpl implements BuilderSql {
|
||||||
private String DB_TYPE;
|
private final String DB_TYPE;
|
||||||
|
|
||||||
{
|
{
|
||||||
// 获取当前数据库的类型
|
// 获取当前数据库的类型
|
||||||
this.DB_TYPE = (new RecordSet()).getDBType();
|
this.DB_TYPE = (new RecordSet()).getDBType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建插入语句
|
* 构建插入语句
|
||||||
|
*
|
||||||
* @param tableName 数据库表名
|
* @param tableName 数据库表名
|
||||||
* @param mapConfig 数据库字段和值
|
* @param mapConfig 数据库字段和值
|
||||||
* @return 自定义SQL实体类
|
* @return 自定义SQL实体类
|
||||||
|
@ -63,21 +61,22 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(" )");
|
sqlBuilder.append(" )");
|
||||||
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过实体类构建插入SQL
|
* 通过实体类构建插入SQL
|
||||||
* @param tableName 数据库表名
|
*
|
||||||
* @param t 实体类对象
|
* @param tableName 数据库表名
|
||||||
* @param <T> 实体类对象泛型
|
* @param t 实体类对象
|
||||||
* @return SQL结果对象
|
* @param <T> 实体类对象泛型
|
||||||
*/
|
* @return SQL结果对象
|
||||||
public <T> PrepSqlResultImpl insertSqlByEntity(String tableName, T t){
|
*/
|
||||||
|
public <T> PrepSqlResultImpl insertSqlByEntity(String tableName, T t) {
|
||||||
List<Object> args = new ArrayList<>();
|
List<Object> args = new ArrayList<>();
|
||||||
StringBuilder sqlBuilder = new StringBuilder("insert into ");
|
StringBuilder sqlBuilder = new StringBuilder("insert into ");
|
||||||
sqlBuilder.append(tableName);
|
sqlBuilder.append(tableName);
|
||||||
StringBuilder fieldBuilder = new StringBuilder();
|
StringBuilder fieldBuilder = new StringBuilder();
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
StringBuilder valueBuilder = new StringBuilder();
|
||||||
|
|
||||||
BeanInfo beanInfo = null;
|
BeanInfo beanInfo = null;
|
||||||
try {
|
try {
|
||||||
beanInfo = Introspector.getBeanInfo(t.getClass(), Object.class);
|
beanInfo = Introspector.getBeanInfo(t.getClass(), Object.class);
|
||||||
|
@ -88,7 +87,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
Object invoke = readMethod.invoke(t);
|
Object invoke = readMethod.invoke(t);
|
||||||
// System.out.println(name);
|
// System.out.println(name);
|
||||||
// System.out.println(invoke);
|
// System.out.println(invoke);
|
||||||
if(invoke == null){
|
if (invoke == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fieldBuilder.append(name);
|
fieldBuilder.append(name);
|
||||||
|
@ -106,10 +105,11 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(" )");
|
sqlBuilder.append(" )");
|
||||||
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建批量插入SQL
|
* 构建批量插入SQL
|
||||||
* @param tableName 表名
|
*
|
||||||
|
* @param tableName 表名
|
||||||
* @param mapListConfig 表对应的字段和值映射list
|
* @param mapListConfig 表对应的字段和值映射list
|
||||||
* @return 自定义批量SQL实体类
|
* @return 自定义批量SQL实体类
|
||||||
*/
|
*/
|
||||||
|
@ -142,14 +142,15 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(" )");
|
sqlBuilder.append(" )");
|
||||||
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建批量插入SQL
|
* 构建批量插入SQL
|
||||||
* @param tableName 数据库表名
|
*
|
||||||
* @param list 实体类数组
|
* @param tableName 数据库表名
|
||||||
* @param <T> 实体类泛型
|
* @param list 实体类数组
|
||||||
* @return SQL对象
|
* @param <T> 实体类泛型
|
||||||
*/
|
* @return SQL对象
|
||||||
|
*/
|
||||||
public <T> BatchSqlResultImpl insertBatchSqlByEntity(String tableName, List<T> list) {
|
public <T> BatchSqlResultImpl insertBatchSqlByEntity(String tableName, List<T> list) {
|
||||||
StringBuilder sqlBuilder = new StringBuilder("insert into ");
|
StringBuilder sqlBuilder = new StringBuilder("insert into ");
|
||||||
sqlBuilder.append(tableName);
|
sqlBuilder.append(tableName);
|
||||||
|
@ -157,11 +158,11 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
StringBuilder valueBuilder = new StringBuilder();
|
||||||
List<List> args = new ArrayList<>();
|
List<List> args = new ArrayList<>();
|
||||||
AtomicInteger i = new AtomicInteger();
|
AtomicInteger i = new AtomicInteger();
|
||||||
|
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
List<Object> arg = new ArrayList<>();
|
List<Object> arg = new ArrayList<>();
|
||||||
BeanInfo beanInfo = null;
|
BeanInfo beanInfo = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
beanInfo = Introspector.getBeanInfo(item.getClass(), Object.class);
|
beanInfo = Introspector.getBeanInfo(item.getClass(), Object.class);
|
||||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||||
|
@ -169,7 +170,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
String name = proper.getName();
|
String name = proper.getName();
|
||||||
Method readMethod = proper.getReadMethod();
|
Method readMethod = proper.getReadMethod();
|
||||||
Object invoke = readMethod.invoke(item);
|
Object invoke = readMethod.invoke(item);
|
||||||
if(invoke == null){
|
if (invoke == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i.get() == 0) {
|
if (i.get() == 0) {
|
||||||
|
@ -192,12 +193,13 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(" )");
|
sqlBuilder.append(" )");
|
||||||
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建更新语句
|
* 构建更新语句
|
||||||
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param mapConfig 表名所对应键值对
|
* @param mapConfig 表名所对应键值对
|
||||||
* @param where 更新数据的条件
|
* @param where 更新数据的条件
|
||||||
* @return 自定义SQL实体类
|
* @return 自定义SQL实体类
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,16 +224,17 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
}
|
}
|
||||||
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建更新SQL语句
|
* 构建更新SQL语句
|
||||||
* @param tableName 数据库表名
|
*
|
||||||
* @param t 实体类对象
|
* @param tableName 数据库表名
|
||||||
* @param where 更新条件对象
|
* @param t 实体类对象
|
||||||
* @param <T> 实体类泛型
|
* @param where 更新条件对象
|
||||||
* @return 构建后的SQL对象
|
* @param <T> 实体类泛型
|
||||||
*/
|
* @return 构建后的SQL对象
|
||||||
public <T> PrepSqlResultImpl updateSqlByEntity(String tableName, T t, Where where){
|
*/
|
||||||
|
public <T> PrepSqlResultImpl updateSqlByEntity(String tableName, T t, Where where) {
|
||||||
this.verifyWhere(where);
|
this.verifyWhere(where);
|
||||||
StringBuilder sqlBuilder = new StringBuilder("update ");
|
StringBuilder sqlBuilder = new StringBuilder("update ");
|
||||||
StringBuilder fieldValue = new StringBuilder();
|
StringBuilder fieldValue = new StringBuilder();
|
||||||
|
@ -246,7 +249,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
String name = proper.getName();
|
String name = proper.getName();
|
||||||
Method readMethod = proper.getReadMethod();
|
Method readMethod = proper.getReadMethod();
|
||||||
Object invoke = readMethod.invoke(t);
|
Object invoke = readMethod.invoke(t);
|
||||||
if(invoke == null){
|
if (invoke == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fieldValue.append(name);
|
fieldValue.append(name);
|
||||||
|
@ -264,12 +267,12 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
}
|
}
|
||||||
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param mapListConfig 表名所对应的键值对数组
|
* @param mapListConfig 表名所对应的键值对数组
|
||||||
* @param whereList 条件数组
|
* @param whereList 条件数组
|
||||||
* @return 批量更新只适用于更新条件一样,但是参数不同的时候,比如更新条件都是id= ?,但是各id的数值不一样
|
* @return 批量更新只适用于更新条件一样,但是参数不同的时候,比如更新条件都是id= ?,但是各id的数值不一样
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -305,15 +308,16 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(whereList.get(0).getSql());
|
sqlBuilder.append(whereList.get(0).getSql());
|
||||||
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过实体类构建批量更新SQL
|
* 通过实体类构建批量更新SQL
|
||||||
* @param tableName 数据库表名
|
*
|
||||||
* @param list 实体类集合
|
* @param tableName 数据库表名
|
||||||
* @param whereList 更新条件集合,一一对应更新数据集合
|
* @param list 实体类集合
|
||||||
* @param <T> 泛型
|
* @param whereList 更新条件集合,一一对应更新数据集合
|
||||||
* @return 构建后的批量SQL对象
|
* @param <T> 泛型
|
||||||
*/
|
* @return 构建后的批量SQL对象
|
||||||
|
*/
|
||||||
public <T> BatchSqlResultImpl updateBatchSqlByEntity(String tableName, List<T> list, List<Where> whereList) {
|
public <T> BatchSqlResultImpl updateBatchSqlByEntity(String tableName, List<T> list, List<Where> whereList) {
|
||||||
this.verifyWhereList(whereList);
|
this.verifyWhereList(whereList);
|
||||||
if (list.size() != whereList.size()) {
|
if (list.size() != whereList.size()) {
|
||||||
|
@ -335,7 +339,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
String name = proper.getName();
|
String name = proper.getName();
|
||||||
Method readMethod = proper.getReadMethod();
|
Method readMethod = proper.getReadMethod();
|
||||||
Object invoke = readMethod.invoke(item);
|
Object invoke = readMethod.invoke(item);
|
||||||
if(invoke == null){
|
if (invoke == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i.get() == 0) {
|
if (i.get() == 0) {
|
||||||
|
@ -358,9 +362,10 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(whereList.get(0).getSql());
|
sqlBuilder.append(whereList.get(0).getSql());
|
||||||
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
return new BatchSqlResultImpl(sqlBuilder.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建插入SQL语句
|
* 构建插入SQL语句
|
||||||
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param mapConfig 参数
|
* @param mapConfig 参数
|
||||||
* @return 拼接好的SQL
|
* @return 拼接好的SQL
|
||||||
|
@ -387,9 +392,10 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(" )");
|
sqlBuilder.append(" )");
|
||||||
return sqlBuilder.toString();
|
return sqlBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建更新SQL语句
|
* 构建更新SQL语句
|
||||||
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param mapConfig 参数
|
* @param mapConfig 参数
|
||||||
* @return 拼接好的SQL
|
* @return 拼接好的SQL
|
||||||
|
@ -415,27 +421,27 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
sqlBuilder.append(where.getSql());
|
sqlBuilder.append(where.getSql());
|
||||||
return sqlBuilder.toString();
|
return sqlBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证构建SQL参数的,并且过滤到为null的数据
|
* 验证构建SQL参数的,并且过滤到为null的数据
|
||||||
|
*
|
||||||
* @param map 验证SQL参数map对象
|
* @param map 验证SQL参数map对象
|
||||||
* @return 验证后的UtilHashMap
|
* @return 验证后的UtilHashMap
|
||||||
*/
|
*/
|
||||||
public UtilHashMap<String, Object> verifyMap(Map<String, Object> map) {
|
public UtilHashMap<String, Object> verifyMap(Map<String, Object> map) {
|
||||||
UtilHashMap<String, Object> filterMap = Util.createUtilHashMap()
|
UtilHashMap<String, Object> filterMap = Util.createUtilHashMap()
|
||||||
.uPutAll(map)
|
.uPutAll(map)
|
||||||
.filter((key, value) -> !Objects.isNull(key) && !Objects.isNull(value));
|
.filter((key, value) -> !Objects.isNull(key) && !Objects.isNull(value));
|
||||||
if (Util.mapIsNullOrEmpty(filterMap)) {
|
if (Util.mapIsNullOrEmpty(filterMap)) {
|
||||||
throw new RuntimeException("map为空或没有数据! map is null or empty!");
|
throw new RuntimeException("map为空或没有数据! map is null or empty!");
|
||||||
}
|
}
|
||||||
return filterMap;
|
return filterMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证批量SQL构建的数据
|
* 验证批量SQL构建的数据
|
||||||
|
*
|
||||||
* @param mapList 批量构建SQL的的工具
|
* @param mapList 批量构建SQL的的工具
|
||||||
* @return 验证和过滤后的数据
|
* @return 验证和过滤后的数据
|
||||||
*/
|
*/
|
||||||
|
@ -444,18 +450,19 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
throw new RuntimeException("mapList为null!mapList is null!");
|
throw new RuntimeException("mapList为null!mapList is null!");
|
||||||
}
|
}
|
||||||
List<UtilLinkedHashMap<String, Object>> collect = mapList.stream().map(item ->
|
List<UtilLinkedHashMap<String, Object>> collect = mapList.stream().map(item ->
|
||||||
Util.createUtilLinkedHashMap()
|
Util.createUtilLinkedHashMap()
|
||||||
.uPutAll(item)
|
.uPutAll(item)
|
||||||
.filter((key, value) -> !Objects.isNull(key) && !Objects.isNull(value))
|
.filter((key, value) -> !Objects.isNull(key) && !Objects.isNull(value))
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
if (mapList.size() == 0) {
|
if (mapList.size() == 0) {
|
||||||
throw new RuntimeException("mapList没有数据!mapList is empty!");
|
throw new RuntimeException("mapList没有数据!mapList is empty!");
|
||||||
}
|
}
|
||||||
return collect;
|
return collect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证where条件是否符合
|
* 验证where条件是否符合
|
||||||
|
*
|
||||||
* @param where where 条件对象
|
* @param where where 条件对象
|
||||||
*/
|
*/
|
||||||
private void verifyWhere(Where where) {
|
private void verifyWhere(Where where) {
|
||||||
|
@ -463,16 +470,18 @@ public class BuilderSqlImpl implements BuilderSql {
|
||||||
throw new RuntimeException("where为null! where is null!");
|
throw new RuntimeException("where为null! where is null!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证where条件集合是否符合
|
* 验证where条件集合是否符合
|
||||||
|
*
|
||||||
* @param whereList where 条件对象集合
|
* @param whereList where 条件对象集合
|
||||||
*/
|
*/
|
||||||
private void verifyWhereList(List<Where> whereList) {
|
private void verifyWhereList(List<Where> whereList) {
|
||||||
if (whereList == null) {
|
if (whereList == null) {
|
||||||
throw new RuntimeException("whereList为null! whereList is null!");
|
throw new RuntimeException("whereList为null! whereList is null!");
|
||||||
}
|
}
|
||||||
whereList.forEach(item->{
|
whereList.forEach(item -> {
|
||||||
if(item == null){
|
if (item == null) {
|
||||||
throw new RuntimeException("whereList中数据为null! whereDate is null in whereList!");
|
throw new RuntimeException("whereList中数据为null! whereDate is null in whereList!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package jntchina.schedule.hrmNew;
|
package jntchina.schedule.hrmNew;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -21,7 +23,8 @@ public class JobTitleMultilingualUtil {
|
||||||
private JSONArray jsonArray = null;
|
private JSONArray jsonArray = null;
|
||||||
private Map<String, List<Map>> groupMap = null;
|
private Map<String, List<Map>> groupMap = null;
|
||||||
|
|
||||||
private final Long updateTime = 0L;
|
private Long updateTime = 0L;
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
extracted();
|
extracted();
|
||||||
|
@ -148,6 +151,7 @@ public class JobTitleMultilingualUtil {
|
||||||
long l = System.currentTimeMillis();
|
long l = System.currentTimeMillis();
|
||||||
if (l - updateTime >= 1_000 * 60 * 60 * 3) {
|
if (l - updateTime >= 1_000 * 60 * 60 * 3) {
|
||||||
extracted();
|
extracted();
|
||||||
|
updateTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
List<Map> list = jsonArray.toJavaList(Map.class);
|
List<Map> list = jsonArray.toJavaList(Map.class);
|
||||||
|
@ -156,6 +160,7 @@ public class JobTitleMultilingualUtil {
|
||||||
if (!jsonArray.equals(this.jsonArray)) {
|
if (!jsonArray.equals(this.jsonArray)) {
|
||||||
this.jsonArray = jsonArray;
|
this.jsonArray = jsonArray;
|
||||||
this.groupMap = list.stream().collect(Collectors.groupingBy(getKey));
|
this.groupMap = list.stream().collect(Collectors.groupingBy(getKey));
|
||||||
|
log.info("job title group : " + JSON.toJSONString(this.groupMap));
|
||||||
}
|
}
|
||||||
String active = LANGUAGE_MAP.get("active");
|
String active = LANGUAGE_MAP.get("active");
|
||||||
if (isBlank(active)) {
|
if (isBlank(active)) {
|
||||||
|
@ -165,9 +170,12 @@ public class JobTitleMultilingualUtil {
|
||||||
active += ",ZHS";
|
active += ",ZHS";
|
||||||
String[] activeLanguageArray = active.split(",");
|
String[] activeLanguageArray = active.split(",");
|
||||||
List<String> activeList = Arrays.stream(activeLanguageArray).distinct().collect(Collectors.toList());
|
List<String> activeList = Arrays.stream(activeLanguageArray).distinct().collect(Collectors.toList());
|
||||||
|
log.info("active language: " + JSON.toJSONString(activeList));
|
||||||
|
log.info("language map: " + JSON.toJSONString(LANGUAGE_MAP));
|
||||||
groupMap = this.groupMap;
|
groupMap = this.groupMap;
|
||||||
if (!isEmpty(groupMap)) {
|
if (!isEmpty(groupMap)) {
|
||||||
List<Map> maps = groupMap.get(getKey.apply(JSONObject.toJavaObject(currentObj, Map.class)));
|
List<Map> maps = groupMap.get(getKey.apply(JSONObject.toJavaObject(currentObj, Map.class)));
|
||||||
|
log.info("current job Maps: " + JSON.toJSONString(maps));
|
||||||
if (!isEmpty(maps)) {
|
if (!isEmpty(maps)) {
|
||||||
sb.append("~`");
|
sb.append("~`");
|
||||||
for (Map map : maps) {
|
for (Map map : maps) {
|
||||||
|
|
Loading…
Reference in New Issue