支持批量参数传递名称

main
youHong.ai 2023-03-20 14:40:59 +08:00
parent d776524824
commit 2ea391e814
11 changed files with 169 additions and 58 deletions

View File

@ -586,25 +586,25 @@ $(() => {
}
}
let date = new Date()
let month = date.getMonth() + 1
let date = new Date();
let month = date.getMonth() + 1;
let year = date.getFullYear();
let n = window.prompt("请输入日期:", date.getDate().toString())
let workDate = year + "-" + fillNum(month) + "-" + fillNum(n)
n = fillNum(n)
WfForm.changeFieldValue("field607", {value: workDate})
let n = window.prompt("请输入日期:", date.getDate().toString());
let workDate = year + "-" + fillNum(month) + "-" + fillNum(n);
n = fillNum(n);
WfForm.changeFieldValue("field607", {value: workDate});
let workflowTitle = WfForm.getFieldValue("field-1");
WfForm.changeFieldValue("field-1", {value: workflowTitle.substring(0, workflowTitle.length - 2) + n})
WfForm.changeFieldValue("field609", {value: workDate})
WfForm.changeFieldValue("field608", {value: "00:00"})
WfForm.changeFieldValue("field610", {value: "23:59"})
WfForm.changeFieldValue("field30038", {value: 0})
WfForm.changeFieldValue("field611", {value: "出差"})
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")
WfForm.changeFieldValue("field-1", {value: workflowTitle.substring(0, workflowTitle.length - 2) + n});
WfForm.changeFieldValue("field609", {value: workDate});
WfForm.changeFieldValue("field608", {value: "00:00"});
WfForm.changeFieldValue("field610", {value: "23:59"});
WfForm.changeFieldValue("field30038", {value: 0});
WfForm.changeFieldValue("field611", {value: "出差"});
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");
WfForm.registerCheckEvent(WfForm.OPER_CLOSE, function (callback) {
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)
});
})()

View File

@ -15,4 +15,5 @@ import java.lang.annotation.*;
@Documented
public @interface BatchSqlArgs {
String value() default "";
}

View File

@ -32,6 +32,7 @@ public class SqlHandler {
List<Object> batchSqlArgsList = new ArrayList();
String batchSqlName = "item";
private final Object batchObj = null;
@ -58,7 +59,7 @@ public class SqlHandler {
if (!batchSqlArgsList.isEmpty()) {
for (Object o1 : batchSqlArgsList) {
Map<String, Object> map = new HashMap<>(8);
map.put("item", o1);
map.put(batchSqlName, o1);
map.putAll((Map<String, Object>) o);
parse = parse(findSql, map);
List<Object> tempArgs = new ArrayList<>();
@ -142,6 +143,7 @@ public class SqlHandler {
if (batchSqlArgs != null) {
try {
this.batchSqlArgsList = (List<Object>) arg;
batchSqlName = batchSqlArgs.value();
} catch (Exception e) {
throw new BindingException("can not parse batchSqlArgs for " + parameter.getName() + ", param index is " + i);
}

View File

@ -12,6 +12,7 @@ import youhong.ai.mymapper.command.constant.CommandConsTant;
import youhong.ai.mymapper.command.entity.SqlDefinition;
import youhong.ai.mymapper.proxy.entity.SqlAndExecuteType;
import youhong.ai.mymapper.proxy.entity.SqlDbTypeMapping;
import youhong.ai.mymapper.util.FormatSqlUtil;
import youhong.ai.mymapper.util.ParseSqlUtil;
import java.lang.annotation.Annotation;
@ -33,10 +34,10 @@ import java.util.function.Function;
public class MapperProxyExecute {
private final Logger logger = Util.getLogger();
private final List<Class<? extends Annotation>> 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<? extends Annotation>> 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<?>> SELECT_LIST = Arrays.asList(Select.class, SelectOracle.class);
private final List<Class<?>> UPDATE_LIST = Arrays.asList(Update.class, UpdateOracle.class);
private final List<Class<?>> DELETE_LIST = Arrays.asList(Delete.class, DeleteOracle.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> SELECT_MAP = new HashMap<>();
@ -86,6 +87,9 @@ public class MapperProxyExecute {
sqlAndExecuteType.setArgs(parse.getArgs());
sqlAndExecuteType.setSql(parse.getSql());
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);
}
@ -97,19 +101,20 @@ public class MapperProxyExecute {
private SqlAndExecuteType getSqlStr(String dbType, Method method, Object[] args) {
Annotation[] annotations = method.getAnnotations();
for (Annotation annotation : annotations) {
if (SELECT_LIST.contains(annotation.getClass())) {
Class<? extends Annotation> annotationClass = annotation.annotationType();
if (SELECT_LIST.contains(annotationClass)) {
// select 处理
return selectSql(dbType, method, args);
}
if (UPDATE_LIST.contains(annotation.getClass())) {
if (UPDATE_LIST.contains(annotationClass)) {
// update 处理
return updateSql(dbType, method, args);
}
if (DELETE_LIST.contains(annotation.getClass())) {
if (DELETE_LIST.contains(annotationClass)) {
// delete 处理
return deleteSql(dbType, method, args);
}
if (INSERT_LIST.contains(annotation.getClass())) {
if (INSERT_LIST.contains(annotationClass)) {
// insert 处理
return insertSql(dbType, method, args);
}
@ -127,6 +132,7 @@ public class MapperProxyExecute {
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
sqlAndExecuteType.setSql(sql);
sqlAndExecuteType.setType(CommandConsTant.INSERT_SQL);
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
return sqlAndExecuteType;
}
@ -139,6 +145,7 @@ public class MapperProxyExecute {
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
sqlAndExecuteType.setSql(sql);
sqlAndExecuteType.setType(CommandConsTant.DELETE_SQL);
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
return sqlAndExecuteType;
}
@ -151,6 +158,7 @@ public class MapperProxyExecute {
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
sqlAndExecuteType.setSql(sql);
sqlAndExecuteType.setType(CommandConsTant.UPDATE_SQL);
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
return sqlAndExecuteType;
}
@ -163,6 +171,7 @@ public class MapperProxyExecute {
SqlAndExecuteType sqlAndExecuteType = new SqlAndExecuteType();
sqlAndExecuteType.setSql(sql);
sqlAndExecuteType.setType(CommandConsTant.SELECT_SQL);
sqlAndExecuteType.setExecuteType(CommandConsTant.SELECT_SQL);
return sqlAndExecuteType;
}

View File

@ -55,12 +55,13 @@ public class MyMapperProxy implements InvocationHandler {
if (!"".equals(name) && null != name) {
mapperKey += "." + name;
}
RecordSet rs = rsManager.getRs(mapperKey);
RecordSetTrans rs = rsManager.getTrans(mapperKey);
if (rs == null) {
rsManager.setRecordSet(mapperKey);
rs = rsManager.getRs(mapperKey);
rsManager.setRecordSetTrans(mapperKey);
rs = rsManager.getTrans(mapperKey);
}
return mapperProxyExecute.execute(rs, method, args);
}
/**
@ -76,10 +77,10 @@ public class MyMapperProxy implements InvocationHandler {
if (!"".equals(name) && null != name) {
mapperKey += "." + name;
}
RecordSetTrans rs = rsManager.getTrans(mapperKey);
RecordSet rs = rsManager.getRs(mapperKey);
if (rs == null) {
rsManager.setRecordSetTrans(mapperKey);
rs = rsManager.getTrans(mapperKey);
rsManager.setRecordSet(mapperKey);
rs = rsManager.getRs(mapperKey);
}
return mapperProxyExecute.execute(rs, method, args);
}

View File

@ -21,20 +21,26 @@ import java.util.List;
@ToString
public class SqlAndExecuteType {
/** slq */
private String sql;
/** sql类型 */
private String type;
private List<Object> args;
/** 执行类型 */
private String executeType;
/** 方法 */
private Method method;
/** rs */
private RecordSet recordSet;
private RecordSetTrans recordSetTrans;
/** 是否是事务 */
private boolean trans;
}

View File

@ -1,12 +1,16 @@
package youhong.ai.mymapper;
package youhong.ai.mymapper.test;
import basetest.BaseTest;
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 youhong.ai.mymapper.MyMapper;
import youhong.ai.mymapper.command.entity.SqlDefinition;
import youhong.ai.mymapper.util.ParseSqlUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -119,4 +123,15 @@ public class ParseSqlTest extends BaseTest {
String[] strs = new String[0];
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));
}
}

View File

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

View File

@ -1,12 +1,12 @@
package youhong.ai.mymapper.util;
import aiyh.utils.excention.CustomerException;
import youhong.ai.mymapper.ParseSqlTest;
import youhong.ai.mymapper.command.ISqlCommand;
import youhong.ai.mymapper.command.annotation.SqlCommand;
import youhong.ai.mymapper.command.constant.CommandConsTant;
import youhong.ai.mymapper.command.entity.CommandContentDefinition;
import youhong.ai.mymapper.command.entity.SqlCommandDefinition;
import youhong.ai.mymapper.test.ParseSqlTest;
import java.io.File;
import java.util.*;

View File

@ -2,6 +2,7 @@ package youhong.ai.mymapper.util;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
import youhong.ai.mymapper.command.CommandExecutor;
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.SqlDefinition;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
/**
* <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_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<Map<String, Object>> PARAMS_ASS_LOCALE = ThreadLocal.withInitial(HashMap::new);
private final CommandExecutor commandExecutor = new CommandExecutor();
/**
@ -347,6 +347,7 @@ public class ParseSqlUtil {
if (!Objects.isNull(variable)) {
i += CommandConsTant.VARIABLE_PREPARED_STATEMENT.length() + variable.length();
Object value = getVariableValue(variable);
sqlBuilder.append("?");
ParseSqlUtil.SQL_PARAM_LOCALE.get().add(ParamValueUtil.getPreparedParam(value));
}
@ -367,10 +368,17 @@ public class ParseSqlUtil {
variable = variable.trim();
Map<String, Object> tempMap = ParseSqlUtil.PARSE_TEMP_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);
if (Objects.isNull(value)) {
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;
}

View File

@ -40,13 +40,16 @@ public class ResultMapperUtil {
return null;
}
if (Map.class.isAssignableFrom(returnType)) {
return getMap(recordSet, method, method.getGenericReturnType());
if (recordSet.next()) {
return getMap(recordSet, method, method.getGenericReturnType());
}
return null;
}
if (List.class.isAssignableFrom(returnType)) {
return getList(recordSet, method);
}
if (recordSet.next()) {
return getBean(recordSet, method);
return getBean(recordSet, method, method.getReturnType());
}
return null;
}
@ -92,7 +95,7 @@ public class ResultMapperUtil {
}
} else {
while (recordSet.next()) {
result.add(getBean(recordSet, method));
result.add(getBean(recordSet, method, componentType));
}
}
if (result.size() > 0) {
@ -115,7 +118,7 @@ public class ResultMapperUtil {
if (i == 0) {
keyClass = (Class<?>) types[i];
}
if (i == 2) {
if (i == 1) {
valueClass = (Class<?>) types[i];
}
}
@ -249,13 +252,15 @@ public class ResultMapperUtil {
}
return result;
}
// java bean 类型
while (recordSet.next()) {
Object bean = getBean(recordSet, method);
result.add(bean);
}
return result;
}
// java bean 类型
while (recordSet.next()) {
Object bean = getBean(recordSet, method, (Class<?>) actualTypeArgument);
result.add(bean);
}
return result;
} else {
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.");
}
private Object getBean(RecordSet recordSet, Method method) {
Class<?> returnType = method.getReturnType();
private Object getBean(RecordSet recordSet, Method method, Class<?> returnType) {
BeanInfo beanInfo = null;
try {
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!");
}
}
Object o = myMapperProxy.invokeRs(null, innerMethod, new Object[]{parseValue}, method.getName());
result.setParse(true);
result.setValue(o);
result.setProperty(property);
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());
result.setParse(true);
result.setValue(o);
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!");
}
}
Object o = myMapperProxy.invokeRs(null, associationMethod, new Object[]{parseValue}, method.getName());
result.setParse(true);
result.setValue(o);
result.setProperty(property);
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());
result.setParse(true);
result.setValue(o);
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) {
if (Objects.isNull(aclass)) {
throw new CustomerException("target class type is not be null");
}
if (Number.class.isAssignableFrom(aclass)) {
return parseNumber(aclass, obj);
}
@ -534,6 +580,9 @@ public class ResultMapperUtil {
if (Character.class.isAssignableFrom(aclass) || char.class.isAssignableFrom(aclass)) {
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);
}