Commit ef20a45c authored by 朱允伟's avatar 朱允伟

<fix> 接口执行网关连接调整,sql语句格式化调整

parent 2ea0bad8
......@@ -6,8 +6,8 @@ spring:
name: @artifactId@
api-service-address:
path: /v1/dataService/**
uri: http://192.168.70.46:6725
url: http://192.168.70.46:6725/v1/dataService/api/getApiLimit
uri: http://localhost:6725
url: http://localhost:6725/v1/dataService/api/getApiLimit
......
......@@ -118,6 +118,8 @@ public class ApiServiceApplicationImpl implements ApiApplication {
public static final String ORDER_ASC = "asc";
@Value("${api-getway-address}")
private String gateWayAddress;
@Override
public InvokeResult addGroup(ApiGroupDTO apiGroupDTO, String username) {
......@@ -226,26 +228,27 @@ public class ApiServiceApplicationImpl implements ApiApplication {
return apiGroupRepository.findAll(specification, pageable);
}
@Value("${server.port}")
private String prot;
@Override
public Api addApi(ApiDTO apiDTO, String username, Integer userid) {
String name = apiDTO.getName();
String querySql = apiDTO.getQuerySql();
if(org.springframework.util.StringUtils.hasLength(querySql)){
apiDTO.setQuerySql(formatQuerySQL(querySql));
}
Integer count = 0;
try {
count = apiRepository.selectApiName(name);
//count=0代表名称不存在,可进行新增
if (count.equals(0)) {
apiDTO.setSourceWay("create");
apiDTO.setPath("http://127.0.0.1:" + prot + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiDTO.setPath("http://" +gateWayAddress + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiRepository.save(ApiAssembler.toApi(apiDTO, username, userid));
} else {
if (apiDTO.getId().equals(0)) {
throw new RuntimeException("保存Api接口失败!,名称已存在");
} else {
apiDTO.setSourceWay("create");
apiDTO.setPath("http://127.0.0.1:" + prot + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiDTO.setPath("http://" +gateWayAddress + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiRepository.save(ApiAssembler.toApi(apiDTO, username, userid));
}
}
......@@ -265,14 +268,14 @@ public class ApiServiceApplicationImpl implements ApiApplication {
//count=0代表名称不存在,可进行新增
if (count.equals(0)) {
apiDTO.setSourceWay("regist");
apiDTO.setPath("http://127.0.0.1:" + prot + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiDTO.setPath("http://" + gateWayAddress + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiRepository.save(ApiAssembler.toApi(apiDTO, username, userid));
} else {
if (apiDTO.getId().equals(0)) {
throw new RuntimeException("保存Api接口失败!,名称已存在");
} else {
apiDTO.setSourceWay("regist");
apiDTO.setPath("http://127.0.0.1:" + prot + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiDTO.setPath("http://" + gateWayAddress + "/v1/dataService/api/executeApi/" + apiDTO.getName());
apiRepository.save(ApiAssembler.toApi(apiDTO, username, userid));
}
}
......@@ -455,7 +458,7 @@ public class ApiServiceApplicationImpl implements ApiApplication {
ApiViewDTO apiViewDTO = new ApiViewDTO();
apiViewDTO.setId(item.getId());
apiViewDTO.setName(item.getName());
apiViewDTO.setPath(item.getPath());
apiViewDTO.setPath("http://" +gateWayAddress + "/v1/dataService/api/executeApi/" + item.getName());
apiViewDTO.setDescription(item.getDescription());
apiViewDTO.setApiAuthDTOList(ApiAuthAssembler.toApiAuthDTOList(item.getApiAuthList()));
String datasourceStr = item.getDatasource();
......@@ -1301,19 +1304,19 @@ public class ApiServiceApplicationImpl implements ApiApplication {
switch (requestType) {
case GET:
result = restTemplate.getForObject(uir, String.class, httpEntity);
invokeResult = InvokeResult.success("接口GET请求成功", result);
invokeResult = InvokeResult.success(result, "接口GET请求成功");
break;
case POST:
result = restTemplate.postForObject(uir, httpEntity, String.class);
invokeResult = InvokeResult.success("接口POST请求成功", result);
invokeResult = InvokeResult.success(result, "接口POST请求成功");
break;
case PUT:
restTemplate.put(uir, httpEntity);
invokeResult = InvokeResult.success("接口PUT请求成功!", "{'message':'接口PUT请求成功!'}");
invokeResult = InvokeResult.success("{'message':'接口PUT请求成功!'}", "接口PUT请求成功!");
break;
case DELETE:
restTemplate.delete(uir, httpEntity);
invokeResult = InvokeResult.success("接口DELETE请求成功!", "{'message':'接口DELETE请求成功!'}");
invokeResult = InvokeResult.success("{'message':'接口DELETE请求成功!'}", "接口DELETE请求成功!");
break;
default:
invokeResult = InvokeResult.fail();
......@@ -1443,4 +1446,8 @@ public class ApiServiceApplicationImpl implements ApiApplication {
}
return bodyParams;
}
private String formatQuerySQL(String querySql){
return querySql.replace("$ { ", "${").replace(" }", "}");
}
}
......@@ -88,12 +88,12 @@ public class ApiServicueFacadeImpl implements ApiFacade {
InvokeResult invokeResult;
try {
invokeResult = InvokeResult.success();
Api api = apiApplication.addApi(apiDTO, username, userid);
invokeResult.setData(api);
apiApplication.addApi(apiDTO, username, userid);
invokeResult.setMessage("api生成成功!");
} catch (Exception e) {
log.error("保存Api失败", e);
log.error("Api生成失败", e);
invokeResult = InvokeResult.fail();
invokeResult.setMessage("保存Api失败" + e.getMessage());
invokeResult.setMessage("Api生成失败" + e.getMessage());
}
return invokeResult;
}
......@@ -187,12 +187,12 @@ public class ApiServicueFacadeImpl implements ApiFacade {
InvokeResult invokeResult;
try {
invokeResult = InvokeResult.success();
Api api = apiApplication.registApi(apiDTO, username, userid);
invokeResult.setData(api);
apiApplication.registApi(apiDTO, username, userid);
invokeResult.setMessage("api注册成功!");
} catch (Exception e) {
log.error("保存Api失败", e);
log.error("Api注册失败", e);
invokeResult = InvokeResult.fail();
invokeResult.setMessage("保存Api失败" + e.getMessage());
invokeResult.setMessage("Api注册失败" + e.getMessage());
}
return invokeResult;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment