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.UtilLinkedHashMap;
|
||||
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.PrepSqlResultImpl;
|
||||
import aiyh.utils.sqlUtil.whereUtil.Where;
|
||||
import aiyh.utils.sqlUtil.whereUtil.impl.WhereImpl;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -29,7 +26,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
|
||||
public class BuilderSqlImpl implements BuilderSql {
|
||||
private String DB_TYPE;
|
||||
private final String DB_TYPE;
|
||||
|
||||
{
|
||||
// 获取当前数据库的类型
|
||||
|
@ -38,6 +35,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建插入语句
|
||||
*
|
||||
* @param tableName 数据库表名
|
||||
* @param mapConfig 数据库字段和值
|
||||
* @return 自定义SQL实体类
|
||||
|
@ -66,6 +64,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 通过实体类构建插入SQL
|
||||
*
|
||||
* @param tableName 数据库表名
|
||||
* @param t 实体类对象
|
||||
* @param <T> 实体类对象泛型
|
||||
|
@ -109,6 +108,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建批量插入SQL
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param mapListConfig 表对应的字段和值映射list
|
||||
* @return 自定义批量SQL实体类
|
||||
|
@ -145,6 +145,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建批量插入SQL
|
||||
*
|
||||
* @param tableName 数据库表名
|
||||
* @param list 实体类数组
|
||||
* @param <T> 实体类泛型
|
||||
|
@ -195,6 +196,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建更新语句
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param mapConfig 表名所对应键值对
|
||||
* @param where 更新数据的条件
|
||||
|
@ -225,6 +227,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建更新SQL语句
|
||||
*
|
||||
* @param tableName 数据库表名
|
||||
* @param t 实体类对象
|
||||
* @param where 更新条件对象
|
||||
|
@ -308,6 +311,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 通过实体类构建批量更新SQL
|
||||
*
|
||||
* @param tableName 数据库表名
|
||||
* @param list 实体类集合
|
||||
* @param whereList 更新条件集合,一一对应更新数据集合
|
||||
|
@ -361,6 +365,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建插入SQL语句
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param mapConfig 参数
|
||||
* @return 拼接好的SQL
|
||||
|
@ -390,6 +395,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 构建更新SQL语句
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param mapConfig 参数
|
||||
* @return 拼接好的SQL
|
||||
|
@ -417,10 +423,9 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证构建SQL参数的,并且过滤到为null的数据
|
||||
*
|
||||
* @param map 验证SQL参数map对象
|
||||
* @return 验证后的UtilHashMap
|
||||
*/
|
||||
|
@ -436,6 +441,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 验证批量SQL构建的数据
|
||||
*
|
||||
* @param mapList 批量构建SQL的的工具
|
||||
* @return 验证和过滤后的数据
|
||||
*/
|
||||
|
@ -456,6 +462,7 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
|
||||
/**
|
||||
* 验证where条件是否符合
|
||||
*
|
||||
* @param where where 条件对象
|
||||
*/
|
||||
private void verifyWhere(Where where) {
|
||||
|
@ -463,8 +470,10 @@ public class BuilderSqlImpl implements BuilderSql {
|
|||
throw new RuntimeException("where为null! where is null!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证where条件集合是否符合
|
||||
*
|
||||
* @param whereList where 条件对象集合
|
||||
*/
|
||||
private void verifyWhereList(List<Where> whereList) {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package jntchina.schedule.hrmNew;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
@ -21,7 +23,8 @@ public class JobTitleMultilingualUtil {
|
|||
private JSONArray jsonArray = null;
|
||||
private Map<String, List<Map>> groupMap = null;
|
||||
|
||||
private final Long updateTime = 0L;
|
||||
private Long updateTime = 0L;
|
||||
private final Logger log = Util.getLogger();
|
||||
|
||||
static {
|
||||
extracted();
|
||||
|
@ -148,6 +151,7 @@ public class JobTitleMultilingualUtil {
|
|||
long l = System.currentTimeMillis();
|
||||
if (l - updateTime >= 1_000 * 60 * 60 * 3) {
|
||||
extracted();
|
||||
updateTime = System.currentTimeMillis();
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Map> list = jsonArray.toJavaList(Map.class);
|
||||
|
@ -156,6 +160,7 @@ public class JobTitleMultilingualUtil {
|
|||
if (!jsonArray.equals(this.jsonArray)) {
|
||||
this.jsonArray = jsonArray;
|
||||
this.groupMap = list.stream().collect(Collectors.groupingBy(getKey));
|
||||
log.info("job title group : " + JSON.toJSONString(this.groupMap));
|
||||
}
|
||||
String active = LANGUAGE_MAP.get("active");
|
||||
if (isBlank(active)) {
|
||||
|
@ -165,9 +170,12 @@ public class JobTitleMultilingualUtil {
|
|||
active += ",ZHS";
|
||||
String[] activeLanguageArray = active.split(",");
|
||||
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;
|
||||
if (!isEmpty(groupMap)) {
|
||||
List<Map> maps = groupMap.get(getKey.apply(JSONObject.toJavaObject(currentObj, Map.class)));
|
||||
log.info("current job Maps: " + JSON.toJSONString(maps));
|
||||
if (!isEmpty(maps)) {
|
||||
sb.append("~`");
|
||||
for (Map map : maps) {
|
||||
|
|
Loading…
Reference in New Issue