1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| final InfoMethodDetail methodDetail = infoComponent.getMethodDetail(handle, checkGroup, invokeName, invokeLength) .orElseThrow(() -> new PassedException(PlatformExceptionEnum.NOT_FOUND)); log.info("[GATEWAY] 查询的方法 {} ({}) | [{}] | [{}]", invokeName, invokeLength, system, checkGroup);
if ((null == useCache || useCache) && null != methodDetail.getMethodData()) { final String methodData = methodDetail.getMethodData(); Map<String, Object> map = Jackson.json2Map(methodData); if (CollectionUtil.isEmpty(map)) { log.warn("[GATEWAY] 查询的方法 {} ({}) | [{}] | [{}], 解析缓存数据失败", invokeName, invokeLength, system, checkGroup); infoComponent.clearMethodCache(handle, group, system, invokeName); return Collections.emptyMap(); }
boolean update = false; String paramMock = methodDetail.getParamMock(); if (null == paramMock) { update = true; Object paramInfo = map.get(PARAMETER_INFO); if (null == paramInfo) { paramMock = "[]"; } else { paramMock = Jackson.toJson(mock.paramMock(Jackson.objCopyList(paramInfo, FieldDetailInfo.class))); } } String returnMock = methodDetail.getReturnMock(); if (null == returnMock) { update = true; Object returnInfo = map.get(RETURN_INFO); if (null == returnInfo) { returnMock = "{}"; } else { returnMock = Jackson.toJson(mock.returnMock(Jackson.objCopyBean(returnInfo, FieldDetailInfo.class))); } } map.remove("methodData");
if (update) { infoComponent.updateMethodCache(handle, checkGroup, invokeName, invokeLength, methodData, paramMock, returnMock); } map.put("paramMock", paramMock); map.put("returnMock", returnMock); return map; } else { Map<String, Object> map = Jackson.bean2Map(methodDetail); assert map != null; if (null != methodDetail.getCommentInfo()) { map.put("commentInfo", Jackson.fromJson(methodDetail.getCommentInfo())); } else { map.put("commentInfo", Collections.emptyMap()); } if (null != methodDetail.getInjectionInfo()) { map.put("injectionInfo", Jackson.fromJson(methodDetail.getInjectionInfo())); } else { map.put("injectionInfo", Collections.emptyMap()); }
final String thisClazzName = methodDetail.getClazzName(); Set<String> clazzNames = Sets.newHashSet(thisClazzName); final String parameterJson = methodDetail.getParameterInfo(); List<FieldDetailInfo> parameterInfo = null; if (StringUtil.notBlank(parameterJson)) { parameterInfo = Jackson.json2List(parameterJson, FieldDetailInfo.class); clazzNames.addAll(parameterInfo.stream().map(FieldDetailInfo::getFullTypeName).collect(Collectors.toSet())); } else { map.put("parameterInfo", Collections.emptyList()); }
final String returnJson = methodDetail.getReturnInfo(); FieldDetailInfo returnInfo = null; if (StringUtil.notBlank(returnJson)) { returnInfo = Jackson.fromJson(returnJson, FieldDetailInfo.class); clazzNames.add(returnInfo.getFullTypeName()); } else { map.put("returnInfo", Collections.emptyMap()); }
if (!clazzNames.isEmpty()) { clazzNames.removeAll(InnerType.innerClass.values()); if (!clazzNames.isEmpty()) { final Map<String, Optional<InfoClazzField>> refClazzField = getField(checkGroup, clazzNames); final Set<String> refClazzNames = Sets.newHashSet(); checkClazzName(group, refClazzNames, refClazzField, parameterInfo, returnInfo); if (!refClazzNames.isEmpty()) { refClazzField.putAll(getField(checkGroup, refClazzNames)); }
if (null != parameterInfo) { final Map<String, String> injectionNames = Maps.newHashMap(); if (null != methodDetail.getInjectionInfo()) { final Map<String, InjectionInfo> injectionInfo = Jackson.json2Map(methodDetail.getInjectionInfo(), InjectionInfo.class); injectionInfo.forEach((key, info) -> { if (null != info && null != info.getInjectType()) { injectionNames.put(key, StringUtil.splitLastByDot(info.getInjectType())); } }); } if (injectionNames.isEmpty()) { parameterInfo.forEach(parameterOne -> clazzType(thisClazzName, parameterOne, refClazzField)); } else { parameterInfo = parameterInfo.stream().filter(one -> { if (null != one.getEnquire() && one.getEnquire()) { return false; } final String fieldName = one.getFieldName(); final String injectionType = injectionNames.get(fieldName); final boolean enquire = injectionNames.containsKey(fieldName) && (!injectionType.equalsIgnoreCase(InjectEnum.MEMBER_ID.toString()) || InnerType.isLongType(one.getFullTypeName())); one.setEnquire(enquire); return !enquire; }).collect(Collectors.toList()); parameterInfo.forEach(parameterOne -> clazzType(thisClazzName, parameterOne, refClazzField)); } map.put("parameterInfo", parameterInfo); } if (null != returnInfo) { clazzType(thisClazzName, returnInfo, refClazzField); map.put("returnInfo", returnInfo); } } else { if (null != parameterInfo) { map.put("parameterInfo", parameterInfo); } if (null != returnInfo) { map.put("returnInfo", returnInfo); } } }
String paramMock = Jackson.toJson(mock.paramMock(parameterInfo)); String returnMock = Jackson.toJson(mock.returnMock(returnInfo)); map.remove("methodData");
final int result = infoComponent.updateMethodCache(handle, checkGroup, invokeName, invokeLength, Jackson.toJson(map), paramMock, returnMock); log.info("[GATEWAY] 方法缓存更新结果: {}", result);
map.put("paramMock", paramMock); map.put("returnMock", returnMock); return map; }
|