支持批量参数传递名称
parent
d776524824
commit
2ea391e814
|
@ -586,25 +586,25 @@ $(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let date = new Date()
|
let date = new Date();
|
||||||
let month = date.getMonth() + 1
|
let month = date.getMonth() + 1;
|
||||||
let year = date.getFullYear();
|
let year = date.getFullYear();
|
||||||
let n = window.prompt("请输入日期:", date.getDate().toString())
|
let n = window.prompt("请输入日期:", date.getDate().toString());
|
||||||
let workDate = year + "-" + fillNum(month) + "-" + fillNum(n)
|
let workDate = year + "-" + fillNum(month) + "-" + fillNum(n);
|
||||||
n = fillNum(n)
|
n = fillNum(n);
|
||||||
WfForm.changeFieldValue("field607", {value: workDate})
|
WfForm.changeFieldValue("field607", {value: workDate});
|
||||||
let workflowTitle = WfForm.getFieldValue("field-1");
|
let workflowTitle = WfForm.getFieldValue("field-1");
|
||||||
WfForm.changeFieldValue("field-1", {value: workflowTitle.substring(0, workflowTitle.length - 2) + n})
|
WfForm.changeFieldValue("field-1", {value: workflowTitle.substring(0, workflowTitle.length - 2) + n});
|
||||||
WfForm.changeFieldValue("field609", {value: workDate})
|
WfForm.changeFieldValue("field609", {value: workDate});
|
||||||
WfForm.changeFieldValue("field608", {value: "00:00"})
|
WfForm.changeFieldValue("field608", {value: "00:00"});
|
||||||
WfForm.changeFieldValue("field610", {value: "23:59"})
|
WfForm.changeFieldValue("field610", {value: "23:59"});
|
||||||
WfForm.changeFieldValue("field30038", {value: 0})
|
WfForm.changeFieldValue("field30038", {value: 0});
|
||||||
WfForm.changeFieldValue("field611", {value: "出差"})
|
WfForm.changeFieldValue("field611", {value: "出差"});
|
||||||
WfForm.changeFieldValue("field8715", {value: "2"})
|
WfForm.changeFieldValue("field8715", {value: "2"});
|
||||||
$("button[ecid='_Route@vmt0lk_Comp@upn4fo_FormContent@g9f33k_MainLayout@kdmfyn_LayoutTr@ds2cqb@main_0_CellType@27chqt@main_17_10_FieldContent@r045n3_BrowserElement@2mq6lm_WeaBrowser@j1zg9h_WrappedComponent@i9q2c5_Component@iiw91q_Associative@zt8qgk_Button@ztqsd2_button@xq1ea3']").trigger("click")
|
$("button[ecid='_Route@vmt0lk_Comp@upn4fo_FormContent@g9f33k_MainLayout@kdmfyn_LayoutTr@ds2cqb@main_0_CellType@27chqt@main_17_10_FieldContent@r045n3_BrowserElement@2mq6lm_WeaBrowser@j1zg9h_WrappedComponent@i9q2c5_Component@iiw91q_Associative@zt8qgk_Button@ztqsd2_button@xq1ea3']").trigger("click");
|
||||||
WfForm.registerCheckEvent(WfForm.OPER_CLOSE, function (callback) {
|
WfForm.registerCheckEvent(WfForm.OPER_CLOSE, function (callback) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = "/spa/workflow/static4form/index.html#/main/workflow/req?iscreate=1&workflowid=746"
|
window.location.href = "/spa/workflow/static4form/index.html#/main/workflow/req?iscreate=1&workflowid=746";
|
||||||
}, 500)
|
}, 500)
|
||||||
});
|
});
|
||||||
})()
|
})()
|
||||||
|
|
|
@ -15,4 +15,5 @@ import java.lang.annotation.*;
|
||||||
@Documented
|
@Documented
|
||||||
public @interface BatchSqlArgs {
|
public @interface BatchSqlArgs {
|
||||||
|
|
||||||
|
String value() default "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class SqlHandler {
|
||||||
|
|
||||||
List<Object> batchSqlArgsList = new ArrayList();
|
List<Object> batchSqlArgsList = new ArrayList();
|
||||||
|
|
||||||
|
String batchSqlName = "item";
|
||||||
|
|
||||||
private final Object batchObj = null;
|
private final Object batchObj = null;
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ public class SqlHandler {
|
||||||
if (!batchSqlArgsList.isEmpty()) {
|
if (!batchSqlArgsList.isEmpty()) {
|
||||||
for (Object o1 : batchSqlArgsList) {
|
for (Object o1 : batchSqlArgsList) {
|
||||||
Map<String, Object> map = new HashMap<>(8);
|
Map<String, Object> map = new HashMap<>(8);
|
||||||
map.put("item", o1);
|
map.put(batchSqlName, o1);
|
||||||
map.putAll((Map<String, Object>) o);
|
map.putAll((Map<String, Object>) o);
|
||||||
parse = parse(findSql, map);
|
parse = parse(findSql, map);
|
||||||
List<Object> tempArgs = new ArrayList<>();
|
List<Object> tempArgs = new ArrayList<>();
|
||||||
|
@ -142,6 +143,7 @@ public class SqlHandler {
|
||||||
if (batchSqlArgs != null) {
|
if (batchSqlArgs != null) {
|
||||||
try {
|
try {
|
||||||
this.batchSqlArgsList = (List<Object>) arg;
|
this.batchSqlArgsList = (List<Object>) arg;
|
||||||
|
batchSqlName = batchSqlArgs.value();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BindingException("can not parse batchSqlArgs for " + parameter.getName() + ", param index is " + i);
|
throw new BindingException("can not parse batchSqlArgs for " + parameter.getName() + ", param index is " + i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import youhong.ai.mymapper.command.constant.CommandConsTant;
|
||||||
import youhong.ai.mymapper.command.entity.SqlDefinition;
|
import youhong.ai.mymapper.command.entity.SqlDefinition;
|
||||||
import youhong.ai.mymapper.proxy.entity.SqlAndExecuteType;
|
import youhong.ai.mymapper.proxy.entity.SqlAndExecuteType;
|
||||||
import youhong.ai.mymapper.proxy.entity.SqlDbTypeMapping;
|
import youhong.ai.mymapper.proxy.entity.SqlDbTypeMapping;
|
||||||
|
import youhong.ai.mymapper.util.FormatSqlUtil;
|
||||||
import youhong.ai.mymapper.util.ParseSqlUtil;
|
import youhong.ai.mymapper.util.ParseSqlUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
@ -33,10 +34,10 @@ import java.util.function.Function;
|
||||||
public class MapperProxyExecute {
|
public class MapperProxyExecute {
|
||||||
|
|
||||||
private final Logger logger = Util.getLogger();
|
private final Logger logger = Util.getLogger();
|
||||||
private final List<Class<? extends Annotation>> SELECT_LIST = Arrays.asList(Select.class, SelectOracle.class);
|
private final List<Class<?>> SELECT_LIST = Arrays.asList(Select.class, SelectOracle.class);
|
||||||
private final List<Class<? extends Annotation>> UPDATE_LIST = Arrays.asList(Update.class, UpdateOracle.class);
|
private final List<Class<?>> UPDATE_LIST = Arrays.asList(Update.class, UpdateOracle.class);
|
||||||
private final List<Class<? extends Annotation>> DELETE_LIST = Arrays.asList(Delete.class, DeleteOracle.class);
|
private final List<Class<?>> DELETE_LIST = Arrays.asList(Delete.class, DeleteOracle.class);
|
||||||
private final List<Class<? extends Annotation>> INSERT_LIST = Arrays.asList(Insert.class, InsertOracle.class);
|
private final List<Class<?>> INSERT_LIST = Arrays.asList(Insert.class, InsertOracle.class);
|
||||||
|
|
||||||
private static final Map<String, SqlDbTypeMapping> INSERT_MAP = new HashMap<>();
|
private static final Map<String, SqlDbTypeMapping> INSERT_MAP = new HashMap<>();
|
||||||
private static final Map<String, SqlDbTypeMapping> SELECT_MAP = new HashMap<>();
|
private static final Map<String, SqlDbTypeMapping> SELECT_MAP = new HashMap<>();
|
||||||
|
@ -86,6 +87,9 @@ public class MapperProxyExecute {
|
||||||
sqlAndExecuteType.setArgs(parse.getArgs());
|
sqlAndExecuteType.setArgs(parse.getArgs());
|
||||||
sqlAndExecuteType.setSql(parse.getSql());
|
sqlAndExecuteType.setSql(parse.getSql());
|
||||||
sqlAndExecuteType.setRecordSet(rs);
|
sqlAndExecuteType.setRecordSet(rs);
|
||||||
|
logger.info(Util.logStr("{}.{} execute sql : \n{}\nargs:{}",
|
||||||
|
method.getDeclaringClass(), method.getName(),
|
||||||
|
FormatSqlUtil.formatSql(sqlAndExecuteType.getSql()), sqlAndExecuteType.getArgs()));
|
||||||
return SqlExecutor.execute(sqlAndExecuteType);
|
return SqlExecutor.execute(sqlAndExecuteType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,19 +101,20 @@ public class MapperProxyExecute {
|
||||||
private SqlAndExecuteType getSqlStr(String dbType, Method method, Object[] args) {
|
private SqlAndExecuteType getSqlStr(String dbType, Method method, Object[] args) {
|
||||||
Annotation[] annotations = method.getAnnotations();
|
Annotation[] annotations = method.getAnnotations();
|
||||||
for (Annotation annotation : annotations) {
|
for (Annotation annotation : annotations) {
|
||||||
if (SELECT_LIST.contains(annotation.getClass())) {
|
Class<? extends Annotation> annotationClass = annotation.annotationType();
|
||||||
|
if (SELECT_LIST.contains(annotationClass)) {
|
||||||
// select 处理
|
// select 处理
|
||||||
return selectSql(dbType, method, args);
|
return selectSql(dbType, method, args);
|
||||||
}
|
}
|
||||||
if (UPDATE_LIST.contains(annotation.getClass())) {
|
if (UPDATE_LIST.contains(annotationClass)) {
|
||||||
// update 处理
|
// update 处理
|
||||||
return updateSql(dbType, method, args);
|
return updateSql(dbType, method, args);
|
||||||
}
|
}
|
||||||
if (DELETE_LIST.contains(annotation.getClass())) {
|
if (DELETE_LIST.contains(annotationClass)) {
|
||||||
// delete 处理
|
// delete 处理
|
||||||
return deleteSql(dbType, method, args);
|
return deleteSql(dbType, method, args);
|
||||||
}
|
}
|
||||||
if (INSERT_LIST.contains(annotation.getClass())) {
|
if (INSERT_LIST.contains(annotationClass)) {
|
||||||
// insert 处理
|
// insert 处理
|
||||||
return insertSql(dbType, method, args);
|
return insertSql(dbType, method, args);
|
||||||
}
|
}
|
||||||
|
@ -127,6 +132,7 @@ public class MapperProxyExecute {
|
||||||
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
||||||
sqlAndExecuteType.setSql(sql);
|
sqlAndExecuteType.setSql(sql);
|
||||||
sqlAndExecuteType.setType(CommandConsTant.INSERT_SQL);
|
sqlAndExecuteType.setType(CommandConsTant.INSERT_SQL);
|
||||||
|
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
|
||||||
return sqlAndExecuteType;
|
return sqlAndExecuteType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +145,7 @@ public class MapperProxyExecute {
|
||||||
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
||||||
sqlAndExecuteType.setSql(sql);
|
sqlAndExecuteType.setSql(sql);
|
||||||
sqlAndExecuteType.setType(CommandConsTant.DELETE_SQL);
|
sqlAndExecuteType.setType(CommandConsTant.DELETE_SQL);
|
||||||
|
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
|
||||||
return sqlAndExecuteType;
|
return sqlAndExecuteType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +158,7 @@ public class MapperProxyExecute {
|
||||||
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
||||||
sqlAndExecuteType.setSql(sql);
|
sqlAndExecuteType.setSql(sql);
|
||||||
sqlAndExecuteType.setType(CommandConsTant.UPDATE_SQL);
|
sqlAndExecuteType.setType(CommandConsTant.UPDATE_SQL);
|
||||||
|
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
|
||||||
return sqlAndExecuteType;
|
return sqlAndExecuteType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +171,7 @@ public class MapperProxyExecute {
|
||||||
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
|
||||||
sqlAndExecuteType.setSql(sql);
|
sqlAndExecuteType.setSql(sql);
|
||||||
sqlAndExecuteType.setType(CommandConsTant.SELECT_SQL);
|
sqlAndExecuteType.setType(CommandConsTant.SELECT_SQL);
|
||||||
|
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
|
||||||
return sqlAndExecuteType;
|
return sqlAndExecuteType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,13 @@ public class MyMapperProxy implements InvocationHandler {
|
||||||
if (!"".equals(name) && null != name) {
|
if (!"".equals(name) && null != name) {
|
||||||
mapperKey += "." + name;
|
mapperKey += "." + name;
|
||||||
}
|
}
|
||||||
RecordSet rs = rsManager.getRs(mapperKey);
|
RecordSetTrans rs = rsManager.getTrans(mapperKey);
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
rsManager.setRecordSet(mapperKey);
|
rsManager.setRecordSetTrans(mapperKey);
|
||||||
rs = rsManager.getRs(mapperKey);
|
rs = rsManager.getTrans(mapperKey);
|
||||||
}
|
}
|
||||||
return mapperProxyExecute.execute(rs, method, args);
|
return mapperProxyExecute.execute(rs, method, args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,10 +77,10 @@ public class MyMapperProxy implements InvocationHandler {
|
||||||
if (!"".equals(name) && null != name) {
|
if (!"".equals(name) && null != name) {
|
||||||
mapperKey += "." + name;
|
mapperKey += "." + name;
|
||||||
}
|
}
|
||||||
RecordSetTrans rs = rsManager.getTrans(mapperKey);
|
RecordSet rs = rsManager.getRs(mapperKey);
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
rsManager.setRecordSetTrans(mapperKey);
|
rsManager.setRecordSet(mapperKey);
|
||||||
rs = rsManager.getTrans(mapperKey);
|
rs = rsManager.getRs(mapperKey);
|
||||||
}
|
}
|
||||||
return mapperProxyExecute.execute(rs, method, args);
|
return mapperProxyExecute.execute(rs, method, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,26 @@ import java.util.List;
|
||||||
@ToString
|
@ToString
|
||||||
public class SqlAndExecuteType {
|
public class SqlAndExecuteType {
|
||||||
|
|
||||||
|
/** slq */
|
||||||
private String sql;
|
private String sql;
|
||||||
|
|
||||||
|
|
||||||
|
/** sql类型 */
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
private List<Object> args;
|
private List<Object> args;
|
||||||
|
|
||||||
|
/** 执行类型 */
|
||||||
private String executeType;
|
private String executeType;
|
||||||
|
|
||||||
|
/** 方法 */
|
||||||
private Method method;
|
private Method method;
|
||||||
|
|
||||||
|
/** rs */
|
||||||
private RecordSet recordSet;
|
private RecordSet recordSet;
|
||||||
|
|
||||||
private RecordSetTrans recordSetTrans;
|
private RecordSetTrans recordSetTrans;
|
||||||
|
|
||||||
|
/** 是否是事务 */
|
||||||
private boolean trans;
|
private boolean trans;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package youhong.ai.mymapper;
|
package youhong.ai.mymapper.test;
|
||||||
|
|
||||||
import basetest.BaseTest;
|
import basetest.BaseTest;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.api.youhong.ai.taibao.fcuntionlist.mapper.FunctionListMapper;
|
||||||
|
import com.api.youhong.ai.taibao.fcuntionlist.pojo.FunctionListConfigItem;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import youhong.ai.mymapper.MyMapper;
|
||||||
import youhong.ai.mymapper.command.entity.SqlDefinition;
|
import youhong.ai.mymapper.command.entity.SqlDefinition;
|
||||||
import youhong.ai.mymapper.util.ParseSqlUtil;
|
import youhong.ai.mymapper.util.ParseSqlUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,4 +123,15 @@ public class ParseSqlTest extends BaseTest {
|
||||||
String[] strs = new String[0];
|
String[] strs = new String[0];
|
||||||
System.out.println(strs.getClass().getComponentType());
|
System.out.println(strs.getClass().getComponentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMyMapper() {
|
||||||
|
// TestMayMapper mapper = MyMapper.getMapper(TestMayMapper.class);
|
||||||
|
// System.out.println(mapper.selectTest());
|
||||||
|
|
||||||
|
FunctionListMapper mapper = MyMapper.getMapper(FunctionListMapper.class);
|
||||||
|
List<FunctionListConfigItem> functionListConfigItems = mapper.selectFunctionListAll();
|
||||||
|
System.out.println(JSON.toJSONString(functionListConfigItems));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package youhong.ai.mymapper.test;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>测试</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/3/18 19:11</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface TestMayMapper {
|
||||||
|
|
||||||
|
@Select("select COMPANYNAME,LICENSE,EXPIREDATE,CVERSION from license")
|
||||||
|
Map<String, Object> selectTest();
|
||||||
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
package youhong.ai.mymapper.util;
|
package youhong.ai.mymapper.util;
|
||||||
|
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import youhong.ai.mymapper.ParseSqlTest;
|
|
||||||
import youhong.ai.mymapper.command.ISqlCommand;
|
import youhong.ai.mymapper.command.ISqlCommand;
|
||||||
import youhong.ai.mymapper.command.annotation.SqlCommand;
|
import youhong.ai.mymapper.command.annotation.SqlCommand;
|
||||||
import youhong.ai.mymapper.command.constant.CommandConsTant;
|
import youhong.ai.mymapper.command.constant.CommandConsTant;
|
||||||
import youhong.ai.mymapper.command.entity.CommandContentDefinition;
|
import youhong.ai.mymapper.command.entity.CommandContentDefinition;
|
||||||
import youhong.ai.mymapper.command.entity.SqlCommandDefinition;
|
import youhong.ai.mymapper.command.entity.SqlCommandDefinition;
|
||||||
|
import youhong.ai.mymapper.test.ParseSqlTest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package youhong.ai.mymapper.util;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
|
||||||
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
||||||
import youhong.ai.mymapper.command.CommandExecutor;
|
import youhong.ai.mymapper.command.CommandExecutor;
|
||||||
import youhong.ai.mymapper.command.constant.CommandConsTant;
|
import youhong.ai.mymapper.command.constant.CommandConsTant;
|
||||||
|
@ -9,10 +10,7 @@ import youhong.ai.mymapper.command.entity.CommandContentDefinition;
|
||||||
import youhong.ai.mymapper.command.entity.SqlCommandDefinition;
|
import youhong.ai.mymapper.command.entity.SqlCommandDefinition;
|
||||||
import youhong.ai.mymapper.command.entity.SqlDefinition;
|
import youhong.ai.mymapper.command.entity.SqlDefinition;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>解析sql工具</h1>
|
* <h1>解析sql工具</h1>
|
||||||
|
@ -25,9 +23,11 @@ public class ParseSqlUtil {
|
||||||
|
|
||||||
|
|
||||||
public final static ThreadLocal<Map<String, Object>> PARSE_PARAM_LOCALE = new ThreadLocal<>();
|
public final static ThreadLocal<Map<String, Object>> PARSE_PARAM_LOCALE = new ThreadLocal<>();
|
||||||
public final static ThreadLocal<Map<String, Object>> PARSE_TEMP_PARAM_LOCALE = new ThreadLocal<>();
|
public final static ThreadLocal<Map<String, Object>> PARSE_TEMP_PARAM_LOCALE = ThreadLocal.withInitial(HashMap::new);
|
||||||
public final static ThreadLocal<List<Object>> SQL_PARAM_LOCALE = new ThreadLocal<>();
|
public final static ThreadLocal<List<Object>> SQL_PARAM_LOCALE = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public final static ThreadLocal<Map<String, Object>> PARAMS_ASS_LOCALE = ThreadLocal.withInitial(HashMap::new);
|
||||||
|
|
||||||
private final CommandExecutor commandExecutor = new CommandExecutor();
|
private final CommandExecutor commandExecutor = new CommandExecutor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,6 +347,7 @@ public class ParseSqlUtil {
|
||||||
if (!Objects.isNull(variable)) {
|
if (!Objects.isNull(variable)) {
|
||||||
i += CommandConsTant.VARIABLE_PREPARED_STATEMENT.length() + variable.length();
|
i += CommandConsTant.VARIABLE_PREPARED_STATEMENT.length() + variable.length();
|
||||||
Object value = getVariableValue(variable);
|
Object value = getVariableValue(variable);
|
||||||
|
|
||||||
sqlBuilder.append("?");
|
sqlBuilder.append("?");
|
||||||
ParseSqlUtil.SQL_PARAM_LOCALE.get().add(ParamValueUtil.getPreparedParam(value));
|
ParseSqlUtil.SQL_PARAM_LOCALE.get().add(ParamValueUtil.getPreparedParam(value));
|
||||||
}
|
}
|
||||||
|
@ -367,10 +368,17 @@ public class ParseSqlUtil {
|
||||||
variable = variable.trim();
|
variable = variable.trim();
|
||||||
Map<String, Object> tempMap = ParseSqlUtil.PARSE_TEMP_PARAM_LOCALE.get();
|
Map<String, Object> tempMap = ParseSqlUtil.PARSE_TEMP_PARAM_LOCALE.get();
|
||||||
Map<String, Object> paramMap = ParseSqlUtil.PARSE_PARAM_LOCALE.get();
|
Map<String, Object> paramMap = ParseSqlUtil.PARSE_PARAM_LOCALE.get();
|
||||||
|
Map<String, Object> assParam = ParseSqlUtil.PARAMS_ASS_LOCALE.get();
|
||||||
|
|
||||||
Object value = ParamValueUtil.getValueByKeyStr(variable, tempMap);
|
Object value = ParamValueUtil.getValueByKeyStr(variable, tempMap);
|
||||||
if (Objects.isNull(value)) {
|
if (Objects.isNull(value)) {
|
||||||
value = ParamValueUtil.getValueByKeyStr(variable, paramMap);
|
value = ParamValueUtil.getValueByKeyStr(variable, paramMap);
|
||||||
}
|
}
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
if (!CollectionUtil.isEmpty(assParam) && assParam.size() == 2) {
|
||||||
|
value = assParam.entrySet().stream().findFirst().get().getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,16 @@ public class ResultMapperUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (Map.class.isAssignableFrom(returnType)) {
|
if (Map.class.isAssignableFrom(returnType)) {
|
||||||
|
if (recordSet.next()) {
|
||||||
return getMap(recordSet, method, method.getGenericReturnType());
|
return getMap(recordSet, method, method.getGenericReturnType());
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (List.class.isAssignableFrom(returnType)) {
|
if (List.class.isAssignableFrom(returnType)) {
|
||||||
return getList(recordSet, method);
|
return getList(recordSet, method);
|
||||||
}
|
}
|
||||||
if (recordSet.next()) {
|
if (recordSet.next()) {
|
||||||
return getBean(recordSet, method);
|
return getBean(recordSet, method, method.getReturnType());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +95,7 @@ public class ResultMapperUtil {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (recordSet.next()) {
|
while (recordSet.next()) {
|
||||||
result.add(getBean(recordSet, method));
|
result.add(getBean(recordSet, method, componentType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result.size() > 0) {
|
if (result.size() > 0) {
|
||||||
|
@ -115,7 +118,7 @@ public class ResultMapperUtil {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
keyClass = (Class<?>) types[i];
|
keyClass = (Class<?>) types[i];
|
||||||
}
|
}
|
||||||
if (i == 2) {
|
if (i == 1) {
|
||||||
valueClass = (Class<?>) types[i];
|
valueClass = (Class<?>) types[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,13 +252,15 @@ public class ResultMapperUtil {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// java bean 类型
|
// java bean 类型
|
||||||
while (recordSet.next()) {
|
while (recordSet.next()) {
|
||||||
Object bean = getBean(recordSet, method);
|
Object bean = getBean(recordSet, method, (Class<?>) actualTypeArgument);
|
||||||
result.add(bean);
|
result.add(bean);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new CustomerException("can not get generic type!");
|
throw new CustomerException("can not get generic type!");
|
||||||
}
|
}
|
||||||
|
@ -263,8 +268,7 @@ public class ResultMapperUtil {
|
||||||
throw new CustomerException("Return value of position type, unable to obtain method return generic type.");
|
throw new CustomerException("Return value of position type, unable to obtain method return generic type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getBean(RecordSet recordSet, Method method) {
|
private Object getBean(RecordSet recordSet, Method method, Class<?> returnType) {
|
||||||
Class<?> returnType = method.getReturnType();
|
|
||||||
BeanInfo beanInfo = null;
|
BeanInfo beanInfo = null;
|
||||||
try {
|
try {
|
||||||
beanInfo = Introspector.getBeanInfo(returnType, Object.class);
|
beanInfo = Introspector.getBeanInfo(returnType, Object.class);
|
||||||
|
@ -478,10 +482,29 @@ public class ResultMapperUtil {
|
||||||
throw new CustomerException("can not set result, CollectionMappings annotation only support result of list! Do you want to use @Associations!");
|
throw new CustomerException("can not set result, CollectionMappings annotation only support result of list! Do you want to use @Associations!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Map<String, Object> assParam = ParseSqlUtil.PARAMS_ASS_LOCALE.get();
|
||||||
|
if (Objects.isNull(assParam)) {
|
||||||
|
Map<String, Object> value = new HashMap<>();
|
||||||
|
value.put("var0", parseValue);
|
||||||
|
value.put("param0", parseValue);
|
||||||
|
ParseSqlUtil.PARAMS_ASS_LOCALE.set(value);
|
||||||
|
} else {
|
||||||
|
assParam.put("var0", parseValue);
|
||||||
|
assParam.put("param0", parseValue);
|
||||||
|
}
|
||||||
|
try {
|
||||||
Object o = myMapperProxy.invokeRs(null, innerMethod, new Object[]{parseValue}, method.getName());
|
Object o = myMapperProxy.invokeRs(null, innerMethod, new Object[]{parseValue}, method.getName());
|
||||||
result.setParse(true);
|
result.setParse(true);
|
||||||
result.setValue(o);
|
result.setValue(o);
|
||||||
result.setProperty(property);
|
result.setProperty(property);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException(e);
|
||||||
|
} finally {
|
||||||
|
if (Objects.nonNull(ParseSqlUtil.PARAMS_ASS_LOCALE.get())) {
|
||||||
|
ParseSqlUtil.PARAMS_ASS_LOCALE.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -517,14 +540,37 @@ public class ResultMapperUtil {
|
||||||
throw new CustomerException("can not set result, CollectionMappings annotation only support result of list! Do you want to use @Associations!");
|
throw new CustomerException("can not set result, CollectionMappings annotation only support result of list! Do you want to use @Associations!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Map<String, Object> assParam = ParseSqlUtil.PARAMS_ASS_LOCALE.get();
|
||||||
|
if (Objects.isNull(assParam)) {
|
||||||
|
Map<String, Object> value = new HashMap<>();
|
||||||
|
value.put("var0", parseValue);
|
||||||
|
value.put("param0", parseValue);
|
||||||
|
ParseSqlUtil.PARAMS_ASS_LOCALE.set(value);
|
||||||
|
} else {
|
||||||
|
assParam.put("var0", parseValue);
|
||||||
|
assParam.put("param0", parseValue);
|
||||||
|
}
|
||||||
|
try {
|
||||||
Object o = myMapperProxy.invokeRs(null, associationMethod, new Object[]{parseValue}, method.getName());
|
Object o = myMapperProxy.invokeRs(null, associationMethod, new Object[]{parseValue}, method.getName());
|
||||||
result.setParse(true);
|
result.setParse(true);
|
||||||
result.setValue(o);
|
result.setValue(o);
|
||||||
result.setProperty(property);
|
result.setProperty(property);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException(e);
|
||||||
|
} finally {
|
||||||
|
if (Objects.nonNull(ParseSqlUtil.PARAMS_ASS_LOCALE.get())) {
|
||||||
|
ParseSqlUtil.PARAMS_ASS_LOCALE.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Object primitiveParseValue(Class<?> aclass, Object obj) {
|
private Object primitiveParseValue(Class<?> aclass, Object obj) {
|
||||||
|
|
||||||
|
if (Objects.isNull(aclass)) {
|
||||||
|
throw new CustomerException("target class type is not be null");
|
||||||
|
}
|
||||||
|
|
||||||
if (Number.class.isAssignableFrom(aclass)) {
|
if (Number.class.isAssignableFrom(aclass)) {
|
||||||
return parseNumber(aclass, obj);
|
return parseNumber(aclass, obj);
|
||||||
}
|
}
|
||||||
|
@ -534,6 +580,9 @@ public class ResultMapperUtil {
|
||||||
if (Character.class.isAssignableFrom(aclass) || char.class.isAssignableFrom(aclass)) {
|
if (Character.class.isAssignableFrom(aclass) || char.class.isAssignableFrom(aclass)) {
|
||||||
return obj == null ? null : String.valueOf(obj).charAt(0);
|
return obj == null ? null : String.valueOf(obj).charAt(0);
|
||||||
}
|
}
|
||||||
|
if (Object.class.isAssignableFrom(aclass)) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
throw new CustomerException("can not definition conversion rule of " + aclass);
|
throw new CustomerException("can not definition conversion rule of " + aclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue