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

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

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