|
@@ -25,84 +25,109 @@ import java.util.Map;
|
|
|
|
|
|
@DubboService
|
|
@DubboService
|
|
public class OperatingInterfacesDubboServiceImpl implements OperatingInterfacesDubboService {
|
|
public class OperatingInterfacesDubboServiceImpl implements OperatingInterfacesDubboService {
|
|
-
|
|
|
|
|
|
+
|
|
private static Logger log = LoggerFactory.getLogger(OperatingInterfacesDubboServiceImpl.class);
|
|
private static Logger log = LoggerFactory.getLogger(OperatingInterfacesDubboServiceImpl.class);
|
|
-
|
|
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private InterfacesService interfacesService;
|
|
private InterfacesService interfacesService;
|
|
-
|
|
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private ErrorCodeService errorCodeService;
|
|
private ErrorCodeService errorCodeService;
|
|
-
|
|
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
-
|
|
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private RedisTemplate redisTemplate;
|
|
private RedisTemplate redisTemplate;
|
|
-
|
|
|
|
|
|
+
|
|
private Map<String, InterfacesDTO> map = new HashMap<>();
|
|
private Map<String, InterfacesDTO> map = new HashMap<>();
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Result<InterfacesDTO> detailForGateway(String servicePath) {
|
|
public Result<InterfacesDTO> detailForGateway(String servicePath) {
|
|
|
|
+ servicePath = servicePath.replaceAll("/\\d+$", "");
|
|
InterfacesDTO interfaces = map.get(servicePath);
|
|
InterfacesDTO interfaces = map.get(servicePath);
|
|
if (null != interfaces) {
|
|
if (null != interfaces) {
|
|
return Result.success(interfaces);
|
|
return Result.success(interfaces);
|
|
} else {
|
|
} else {
|
|
- //处理 通配符 * 部分
|
|
|
|
- for (String key:map.keySet()) {
|
|
|
|
|
|
+ // 处理 通配符 * 部分
|
|
|
|
+ for (String key : map.keySet()) {
|
|
InterfacesDTO temp = map.get(key);
|
|
InterfacesDTO temp = map.get(key);
|
|
- if (key.contains("*") && servicePath.startsWith(key.substring(0,key.indexOf("*")))){
|
|
|
|
|
|
+ if (key.contains("*") && servicePath.startsWith(key.substring(0, key.indexOf("*")))) {
|
|
return Result.success(temp);
|
|
return Result.success(temp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //查询数据库
|
|
|
|
|
|
+ // 查询数据库
|
|
InterfacesDTO dto = null;
|
|
InterfacesDTO dto = null;
|
|
List<Interfaces> all = interfacesService.findAll();
|
|
List<Interfaces> all = interfacesService.findAll();
|
|
for (Interfaces interfacez : all) {
|
|
for (Interfaces interfacez : all) {
|
|
String key = interfacez.getServicePath();
|
|
String key = interfacez.getServicePath();
|
|
if (key.equals(servicePath)) {
|
|
if (key.equals(servicePath)) {
|
|
dto = InterfacesDTO.generator(interfacez);
|
|
dto = InterfacesDTO.generator(interfacez);
|
|
- map.put(key,dto);
|
|
|
|
|
|
+ map.put(key, dto);
|
|
return Result.success(dto);
|
|
return Result.success(dto);
|
|
- } else if (key.contains("*") && servicePath.startsWith(key.substring(0,key.indexOf("*")))){
|
|
|
|
|
|
+ } else if (key.contains("*") && servicePath.startsWith(key.substring(0, key.indexOf("*")))) {
|
|
dto = InterfacesDTO.generator(interfacez);
|
|
dto = InterfacesDTO.generator(interfacez);
|
|
- map.put(key,dto);
|
|
|
|
|
|
+ map.put(key, dto);
|
|
return Result.success(dto);
|
|
return Result.success(dto);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return Result.fail("未找到接口");
|
|
|
|
|
|
+ // fixme 自增兜底接口,后续删除
|
|
|
|
+ Interfaces build = Interfaces.builder()
|
|
|
|
+ .apiName("兜底接口自增")
|
|
|
|
+ .returnCodeTranslate(0)
|
|
|
|
+ .apiRemark("兜底接口自增")
|
|
|
|
+ .apiMemo("兜底接口自增")
|
|
|
|
+ .serviceName("兜底接口自增")
|
|
|
|
+ .servicePath(servicePath)
|
|
|
|
+ .serviceType("1")
|
|
|
|
+ .moduleId("1")
|
|
|
|
+ .moduleName(servicePath.replaceAll("^/([^/]+).*", "$1"))
|
|
|
|
+ .authorizeType(0)
|
|
|
|
+ .merchantAuthorizeType(0)
|
|
|
|
+ .status(1)
|
|
|
|
+ .requestJson("{}")
|
|
|
|
+ .requestJsonDemo("{}")
|
|
|
|
+ .responseJson("{}")
|
|
|
|
+ .responseJsonDemo("{}")
|
|
|
|
+ .createName("兜底接口自增")
|
|
|
|
+ .build();
|
|
|
|
+ interfacesService.save(build);
|
|
|
|
+ dto = InterfacesDTO.generator(build);
|
|
|
|
+ map.put(servicePath, dto);
|
|
|
|
+ return Result.success(dto);
|
|
|
|
+ // return Result.fail("未找到接口");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-// @Override
|
|
|
|
-// public Result<InterfacesDTO> detailForGateway(String servicePath) {
|
|
|
|
-//// log.info(String.format("servicePath = %s", servicePath));
|
|
|
|
-// InterfacesDTO interfaces = (InterfacesDTO) redisTemplate.opsForHash().get(RedisConstants.INTERFACES_MAP, servicePath);
|
|
|
|
-// if (null != interfaces) {
|
|
|
|
-//// log.info("接口名:" + interfaces.getApiName());
|
|
|
|
-// return Result.success(interfaces);
|
|
|
|
-// } else {
|
|
|
|
-// // 刷新接口
|
|
|
|
-// InterfacesDTO dto = reloadInterfaces(servicePath);
|
|
|
|
-// if (null != dto) {
|
|
|
|
-// return Result.success(dto);
|
|
|
|
-// } else {
|
|
|
|
-// Map<String,Object> entries = redisTemplate.opsForHash().entries(RedisConstants.INTERFACES_MAP);
|
|
|
|
-// Set<String> keys = entries.keySet();
|
|
|
|
-// for (String key:keys ) {
|
|
|
|
-// if (key.contains("*")){
|
|
|
|
-// if (servicePath.startsWith(key.substring(0,key.indexOf("*")))){
|
|
|
|
-//// log.info("接口名:" + interfaces.getApiName()+",接口url:"+servicePath);
|
|
|
|
-// return Result.success((InterfacesDTO)entries.get(key));
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// return Result.fail("未找到接口");
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // @Override
|
|
|
|
+ // public Result<InterfacesDTO> detailForGateway(String servicePath) {
|
|
|
|
+ //// log.info(String.format("servicePath = %s", servicePath));
|
|
|
|
+ // InterfacesDTO interfaces = (InterfacesDTO) redisTemplate.opsForHash().get(RedisConstants.INTERFACES_MAP, servicePath);
|
|
|
|
+ // if (null != interfaces) {
|
|
|
|
+ //// log.info("接口名:" + interfaces.getApiName());
|
|
|
|
+ // return Result.success(interfaces);
|
|
|
|
+ // } else {
|
|
|
|
+ // // 刷新接口
|
|
|
|
+ // InterfacesDTO dto = reloadInterfaces(servicePath);
|
|
|
|
+ // if (null != dto) {
|
|
|
|
+ // return Result.success(dto);
|
|
|
|
+ // } else {
|
|
|
|
+ // Map<String,Object> entries = redisTemplate.opsForHash().entries(RedisConstants.INTERFACES_MAP);
|
|
|
|
+ // Set<String> keys = entries.keySet();
|
|
|
|
+ // for (String key:keys ) {
|
|
|
|
+ // if (key.contains("*")){
|
|
|
|
+ // if (servicePath.startsWith(key.substring(0,key.indexOf("*")))){
|
|
|
|
+ //// log.info("接口名:" + interfaces.getApiName()+",接口url:"+servicePath);
|
|
|
|
+ // return Result.success((InterfacesDTO)entries.get(key));
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // return Result.fail("未找到接口");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 刷新redis中的接口信息并返回当前这个接口的信息
|
|
* 刷新redis中的接口信息并返回当前这个接口的信息
|
|
*
|
|
*
|
|
@@ -117,13 +142,13 @@ public class OperatingInterfacesDubboServiceImpl implements OperatingInterfacesD
|
|
String key = interfaces.getServicePath();
|
|
String key = interfaces.getServicePath();
|
|
if (key.equals(servicePath)) {
|
|
if (key.equals(servicePath)) {
|
|
dto = InterfacesDTO.generator(interfaces);
|
|
dto = InterfacesDTO.generator(interfaces);
|
|
- } else if (key.contains("*") && servicePath.startsWith(key.substring(0,key.indexOf("*")))){
|
|
|
|
|
|
+ } else if (key.contains("*") && servicePath.startsWith(key.substring(0, key.indexOf("*")))) {
|
|
dto = InterfacesDTO.generator(interfaces);
|
|
dto = InterfacesDTO.generator(interfaces);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return dto;
|
|
return dto;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Result<ErrorCodeDTO> getErrorCode(String servicePath, String retCode) {
|
|
public Result<ErrorCodeDTO> getErrorCode(String servicePath, String retCode) {
|
|
String key = ProjectConstant.ERROR_CODE + servicePath + retCode;
|
|
String key = ProjectConstant.ERROR_CODE + servicePath + retCode;
|