diff --git a/src/main/java/com/xly/tool/DynamicToolProvider.java b/src/main/java/com/xly/tool/DynamicToolProvider.java index 9a1befd..0285955 100644 --- a/src/main/java/com/xly/tool/DynamicToolProvider.java +++ b/src/main/java/com/xly/tool/DynamicToolProvider.java @@ -1006,74 +1006,76 @@ public class DynamicToolProvider implements ToolProvider { Map result = new HashMap<>(args); result = transformationArgs( result, paramDefsCheck); List paramDefs = new ArrayList<>(paramDefsCheck); + paramDefs = paramDefs.stream().filter(one-> !one.getBDynamicParam()).collect(Collectors.toList()); paramDefs.sort(Comparator.comparing(ParamRule::getIOrder)); -// for (ParamRule pd : paramDefs) { -// String name = pd.getSParam(); -// String sValue = pd.getSParamValue(); -// String sRule = pd.getSRule(); -// String sType = pd.getSType(); -// -// Boolean bCheck = result.containsKey(name); -// bCheck = bCheck && ObjectUtil.isNotEmpty(result.get(name)); -// bCheck = bCheck && RuleCode.SQL.getCode().equals(sRule); -// bCheck = bCheck && ObjectUtil.isNotEmpty(pd.getSParamConfig()); -// -// Boolean bCheck2 = result.containsKey(sValue); -// bCheck2 = bCheck2 && ObjectUtil.isNotEmpty(result.get(sValue)); -// bCheck2 = bCheck2 && RuleCode.SQL.getCode().equals(sRule); -// bCheck2 = bCheck2 && ObjectUtil.isNotEmpty(pd.getSParamConfig()); -// -// if ((bCheck || bCheck2) &&("enum".equals(sType) || "string".equals(sType))){ -// String sSql = pd.getSParamConfig(); -// String sKey = bCheck?name:sValue; -// String nameValue = result.get(sKey).toString(); -// List> dataList = dynamicExeDbService.findSql(result,sSql); -// if(ObjectUtil.isEmpty(dataList)){ -// throw new BusinessException(ErrorCode.PARAM_REQUIRED,String.format("%s 您描述的%s 不存在,请重新告诉我",name,nameValue)); -// } -// if(ObjectUtil.isNotEmpty(args.get(name)) || ObjectUtil.isNotEmpty(args.get(sValue))){ -// if(("enum".equals(sType) ||"string".equals(sType)) && (args.get(name) instanceof List || args.get(sValue) instanceof List)){ -// if(args.get(name) instanceof List){ -// args.put(name,((List) args.get(name)).get(0)); -// } -// if(args.get(sValue) instanceof List){ -// args.put(sValue,((List) args.get(sValue)).get(0)); -// } -// } -// List> dataListNew = dataList.stream().filter(one-> -// ObjectUtil.isNotEmpty(one.get(sValue)) -// &&(one.get(sValue).equals(args.get(name)) -// || one.get(sValue).equals(args.get(sValue)))).collect(Collectors.toUnmodifiableList()); -//// if("enum".equals(sType) && ObjectUtil.isEmpty(dataListNew)){ -//// args.remove(name); -//// args.remove(sValue); -//// result.remove(name); -//// result.remove(sValue); -//// continue; -//// } -// if(ObjectUtil.isNotEmpty(dataListNew)){ -// dataList = new ArrayList<>(); -// dataList.add(dataListNew.get(0)); -// } -// } -// if(ObjectUtil.isNotEmpty(dataList)){ -// String sCopyTo = pd.getSCopyTo(); -// if(ObjectUtil.isEmpty(sCopyTo)){ -// result.put(sValue, dataList.get(0).get(sValue)); -// result.put(name, dataList.get(0).get(sValue)); -// }else{ -// String[] sCopyToA = sCopyTo.split(","); -// for(String sCopyToOne:sCopyToA){ -// String[] sCopyToOneA = sCopyToOne.split(":"); -// result.put(sCopyToOneA[0], dataList.get(0).get(sCopyToOneA[1])); -// result.put(name, dataList.get(0).get(sValue)); -// } + + for (ParamRule pd : paramDefs) { + String name = pd.getSParam(); + String sValue = pd.getSParamValue(); + String sRule = pd.getSRule(); + String sType = pd.getSType(); + + Boolean bCheck = result.containsKey(name); + bCheck = bCheck && ObjectUtil.isNotEmpty(result.get(name)); + bCheck = bCheck && RuleCode.SQL.getCode().equals(sRule); + bCheck = bCheck && ObjectUtil.isNotEmpty(pd.getSParamConfig()); + + Boolean bCheck2 = result.containsKey(sValue); + bCheck2 = bCheck2 && ObjectUtil.isNotEmpty(result.get(sValue)); + bCheck2 = bCheck2 && RuleCode.SQL.getCode().equals(sRule); + bCheck2 = bCheck2 && ObjectUtil.isNotEmpty(pd.getSParamConfig()); + + if ((bCheck || bCheck2) &&("enum".equals(sType) || "string".equals(sType))){ + String sSql = pd.getSParamConfig(); + String sKey = bCheck?name:sValue; + String nameValue = result.get(sKey).toString(); + List> dataList = dynamicExeDbService.findSql(result,sSql); + if(ObjectUtil.isEmpty(dataList)){ + throw new BusinessException(ErrorCode.PARAM_REQUIRED,String.format("%s 您描述的%s 不存在,请重新告诉我",name,nameValue)); + } + if(ObjectUtil.isNotEmpty(args.get(name)) || ObjectUtil.isNotEmpty(args.get(sValue))){ + if(("enum".equals(sType) ||"string".equals(sType)) && (args.get(name) instanceof List || args.get(sValue) instanceof List)){ + if(args.get(name) instanceof List){ + args.put(name,((List) args.get(name)).get(0)); + } + if(args.get(sValue) instanceof List){ + args.put(sValue,((List) args.get(sValue)).get(0)); + } + } + List> dataListNew = dataList.stream().filter(one-> + ObjectUtil.isNotEmpty(one.get(sValue)) + &&(one.get(sValue).equals(args.get(name)) + || one.get(sValue).equals(args.get(sValue)))).collect(Collectors.toUnmodifiableList()); +// if("enum".equals(sType) && ObjectUtil.isEmpty(dataListNew)){ +// args.remove(name); +// args.remove(sValue); +// result.remove(name); +// result.remove(sValue); +// continue; // } -// } -// } -// -// -// } + if(ObjectUtil.isNotEmpty(dataListNew)){ + dataList = new ArrayList<>(); + dataList.add(dataListNew.get(0)); + } + } + if(ObjectUtil.isNotEmpty(dataList)){ + String sCopyTo = pd.getSCopyTo(); + if(ObjectUtil.isEmpty(sCopyTo)){ + result.put(sValue, dataList.get(0).get(sValue)); + result.put(name, dataList.get(0).get(sValue)); + }else{ + String[] sCopyToA = sCopyTo.split(","); + for(String sCopyToOne:sCopyToA){ + String[] sCopyToOneA = sCopyToOne.split(":"); + result.put(sCopyToOneA[0], dataList.get(0).get(sCopyToOneA[1])); + result.put(name, dataList.get(0).get(sValue)); + } + } + } + } + + + } return result; } @@ -1081,7 +1083,7 @@ public class DynamicToolProvider implements ToolProvider { Map result = new HashMap<>(args); for (ParamRule pd : paramDefs) { String name = pd.getSParam(); - if ((!result.containsKey(name)|| ObjectUtil.isEmpty(result.get(name))) + if ((!result.containsKey(name) || ObjectUtil.isEmpty(result.get(name))) && ObjectUtil.isNotEmpty(pd.getSDefaultValue()) ) { Object defaultValue = pd.getSDefaultValue();