mapper拼接类

jingwei
youhong.ai 2023-05-12 21:12:06 +08:00
parent ce90fa1def
commit 8b8ab74483
3 changed files with 202 additions and 75 deletions

View File

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

View File

@ -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 {
}
/**
* SQLnull
*
* @param map SQLmap
* @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) {

View File

@ -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) {