@Slf4j
public class SameFeignCallUtil {
public static ResourceCountVo countStorageRackResourceByUserCode(String userCode, String uriStr, Function<String, String> function) {
String result = null;
try {
log.info("call countStorageRackResourceByUserCode param is {}", userCode);
// result = dgdpsCloudClient.countStorageRackResourceByUserCode(userCode);
result = function.apply(userCode);
} catch (Exception e) {
if (e instanceof BusinessException) {
throw e;
} else {
log.error(DgdpsportalLogHelper.message("dgdpsiot:call countStorageRackResourceByUserCode method failed"), e);
AssemblyErrorUtil.assemblyFeignCallError(uriStr);
}
}
log.info("call countStorageRackResourceByUserCode param is {}",result);
CommonResponse response = JSON.parseObject(result, CommonResponse.class);
if (ErrorCode.SUCCESS.equals(response.getCode()) && null != response.getData()) {
ResourceCountVo dto = JSONObject.parseObject(response.getData().toString(), ResourceCountVo.class);
return dto;
} else {
throw new BusinessException(response.getCode(), response.getMsg());
}
}
public static ResourceCountVo dealStorageRackResourceCountException(String userCode, String uriStr, Function<String, String> function) {
ResourceCountVo vo = null;
try {
vo = SameFeignCallUtil.countStorageRackResourceByUserCode(userCode, uriStr, function);
} catch (Exception e) {
// 抛异常
log.error("countStorageRackResourceByUserCode error",e);
}
return vo;
}
}
@Value("${dgdpsdata.server.countStorageRackResourceByUserCode}")
private String countStorageRackResourceByUserCode;
@Override
public ResourceCountVo countStorageRackResourceByUserCode(String userCode) {
Function<String, String> function = x -> {
return dgdpsDataClient.countStorageRackResourceByUserCode(x);
};
return SameFeignCallUtil.dealStorageRackResourceCountException(userCode, countStorageRackResourceByUserCode, function);
}