Commit 80a2efb6 authored by zhangc's avatar zhangc

修改api制作想关代码

parent d840e3f3
...@@ -6,12 +6,15 @@ CREATE TABLE `t_api_interface` ( ...@@ -6,12 +6,15 @@ CREATE TABLE `t_api_interface` (
`api_name` varchar(100) DEFAULT NULL COMMENT 'api名称', `api_name` varchar(100) DEFAULT NULL COMMENT 'api名称',
`api_desc` varchar(300) DEFAULT NULL COMMENT 'api描述', `api_desc` varchar(300) DEFAULT NULL COMMENT 'api描述',
`api_protocl` varchar(32) DEFAULT NULL COMMENT 'api请求协议:http,https', `api_protocl` varchar(32) DEFAULT NULL COMMENT 'api请求协议:http,https',
`api_path` varchar(100) DEFAULT NULL COMMENT '请求地址'
`target_url` varchar(100) DEFAULT NULL COMMENT '目标url', `target_url` varchar(100) DEFAULT NULL COMMENT '目标url',
`api_type` varchar(50) NULL DEFAULT '' COMMENT 'api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义', `api_type` varchar(50) NULL DEFAULT '' COMMENT 'api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义',
`api_function` varchar(200) DEFAULT NULL COMMENT '接口功能', `api_function` varchar(200) DEFAULT NULL COMMENT '接口功能',
`join_type` varchar(50) NULL DEFAULT NULL COMMENT '接入类型:字典表对应key值', `join_type` varchar(50) NULL DEFAULT NULL COMMENT '接入类型:字典表对应key值',
`test_example` varchar(255) NULL DEFAULT NULL COMMENT '测试实例'; `test_example` varchar(255) NULL DEFAULT NULL COMMENT '测试实例';
`status` varchar(50) NOT NULL COMMENT '状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)', `status` varchar(50) NOT NULL COMMENT '状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)',
`output_type` varchar(50) NULL DEFAULT 'JSON' COMMENT '输出类型:flow 流形式输出, json格式输出',
`page` tinyint(2) NULL DEFAULT '0' COMMENT '是否分页:0 false ,1 true',
`version` varchar(20) DEFAULT '1.0' COMMENT '版本号', `version` varchar(20) DEFAULT '1.0' COMMENT '版本号',
`sign_type` varchar(50) DEFAULT NULL COMMENT '加密方式: MD5 RSA', `sign_type` varchar(50) DEFAULT NULL COMMENT '加密方式: MD5 RSA',
`timeout` varchar(50) DEFAULT NULL COMMENT '超时时间', `timeout` varchar(50) DEFAULT NULL COMMENT '超时时间',
...@@ -39,6 +42,7 @@ CREATE TABLE `t_api_interface_custom` ( ...@@ -39,6 +42,7 @@ CREATE TABLE `t_api_interface_custom` (
`req_headers` varchar(300) DEFAULT NULL COMMENT '请求头', `req_headers` varchar(300) DEFAULT NULL COMMENT '请求头',
`resp_code` varchar(300) DEFAULT NULL COMMENT '响应状态码', `resp_code` varchar(300) DEFAULT NULL COMMENT '响应状态码',
`api_example` varchar(300) DEFAULT NULL COMMENT 'api返回样例', `api_example` varchar(300) DEFAULT NULL COMMENT 'api返回样例',
`inbox_param` varchar(300) NULL DEFAULT NULL COMMENT '固定参数',
`remark` varchar(500) DEFAULT NULL COMMENT '备注', `remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`create_user` varchar(100) DEFAULT NULL COMMENT '创建人', `create_user` varchar(100) DEFAULT NULL COMMENT '创建人',
...@@ -54,7 +58,6 @@ CREATE TABLE `t_api_interface_file` ( ...@@ -54,7 +58,6 @@ CREATE TABLE `t_api_interface_file` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'api文件表自增ID', `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'api文件表自增ID',
`project_id` bigint(20) NOT NULL COMMENT '项目编号', `project_id` bigint(20) NOT NULL COMMENT '项目编号',
`file_source` varchar(50) DEFAULT NULL COMMENT '文件来源:,1 dmp, 2 数据银行', `file_source` varchar(50) DEFAULT NULL COMMENT '文件来源:,1 dmp, 2 数据银行',
`file_type` varchar(20) DEFAULT NULL COMMENT '文件类型:1 文件夹 ,2 文件',
`file_name` varchar(50) DEFAULT NULL COMMENT '文件名称', `file_name` varchar(50) DEFAULT NULL COMMENT '文件名称',
`file_en_name` varchar(50) DEFAULT NULL COMMENT '文件英文名称', `file_en_name` varchar(50) DEFAULT NULL COMMENT '文件英文名称',
`parent_id` bigint(20) DEFAULT NULL COMMENT '父类id', `parent_id` bigint(20) DEFAULT NULL COMMENT '父类id',
......
...@@ -36,8 +36,8 @@ public class ApiDirectionController { ...@@ -36,8 +36,8 @@ public class ApiDirectionController {
*/ */
@ApiOperation("api类型列表") @ApiOperation("api类型列表")
@PostMapping(value = "/getApiTypeList") @PostMapping(value = "/getApiTypeList")
public Mono<Result> getApiTypeList(@RequestParam(name = "parentCode") String parentCode) { public Mono<Result> getApiTypeList(@RequestParam(name = "parentKey") String parentKey) {
return Mono.fromSupplier(() -> Result.of_success(apiDirectionService.getApiType(parentCode))); return Mono.fromSupplier(() -> Result.of_success(apiDirectionService.getApiType(parentKey)));
} }
/** /**
* @Description:查询某个类型的字典值 * @Description:查询某个类型的字典值
......
...@@ -36,9 +36,10 @@ public class ProducerController { ...@@ -36,9 +36,10 @@ public class ProducerController {
*/ */
@ApiOperation("Api制作(获取文件夹列表)") @ApiOperation("Api制作(获取文件夹列表)")
@GetMapping(value = "/getFileCatalog") @GetMapping(value = "/getFileCatalog")
public Mono<Result> getFileCatalog(@RequestParam(name = "pageNum",defaultValue = "1",required = false)String pageNum, public Mono<Result> getFileCatalog(@RequestParam(name = "projectId")Long projectId,
@RequestParam(name = "pageNum",defaultValue = "1",required = false)String pageNum,
@RequestParam(name = "pageSize",defaultValue = "10",required = false)String pageSize) { @RequestParam(name = "pageSize",defaultValue = "10",required = false)String pageSize) {
return Mono.fromSupplier(() -> Result.of_success(producerService.getFileCatalog(pageNum,pageSize))); return Mono.fromSupplier(() -> Result.of_success(producerService.getFileCatalog(projectId,pageNum,pageSize)));
} }
/** /**
* @Description:Api制作(自定义) * @Description:Api制作(自定义)
......
...@@ -49,10 +49,16 @@ public class ApiInterface extends BaseObject implements Serializable { ...@@ -49,10 +49,16 @@ public class ApiInterface extends BaseObject implements Serializable {
private String apiProtocl; private String apiProtocl;
/** /**
* api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义' * api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义'
*/ */
@TableField("api_type") @TableField("api_type")
private String apiType; private String apiType;
/**
* 请求地址
*/
@TableField("api_path")
private String apiPath;
/** /**
* 目标url * 目标url
*/ */
...@@ -68,6 +74,16 @@ public class ApiInterface extends BaseObject implements Serializable { ...@@ -68,6 +74,16 @@ public class ApiInterface extends BaseObject implements Serializable {
*/ */
@TableField("test_example") @TableField("test_example")
private String testExample; private String testExample;
/**
* '输出类型:flow 流形式输出, json格式输出',
*/
@TableField("output_type")
private String outputType;
/**
* 是否分页:0 false ,1 true
*/
@TableField("page")
private Boolean page;
/** /**
* 状态(1-草稿 2-发布 3-过时 4-冻结 5-失效) * 状态(1-草稿 2-发布 3-过时 4-冻结 5-失效)
......
...@@ -36,11 +36,6 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable { ...@@ -36,11 +36,6 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable {
@TableField("api_interface_id") @TableField("api_interface_id")
private Long apiInterfaceId; private Long apiInterfaceId;
/**
* api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义'
*/
@TableField("api_type")
private String apiType;
/** /**
* api请求参数 * api请求参数
...@@ -69,5 +64,10 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable { ...@@ -69,5 +64,10 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable {
*/ */
@TableField("api_example") @TableField("api_example")
private String apiExample; private String apiExample;
/**
* 固定参数
*/
@TableField("inbox_param")
private String inboxParam;
} }
...@@ -36,11 +36,11 @@ public class ApiInterfaceFile extends BaseObject implements Serializable { ...@@ -36,11 +36,11 @@ public class ApiInterfaceFile extends BaseObject implements Serializable {
@TableField("file_source") @TableField("file_source")
private String fileSource; private String fileSource;
/** ///**
* 文件类型:1 文件夹 ,2 文件 //* 文件类型:1 文件夹 ,2 文件
*/ //*/
@TableField("file_type") //@TableField("file_type")
private String fileType; //private String fileType;
/** /**
* 文件名称 * 文件名称
......
...@@ -22,10 +22,6 @@ public class ApiInterfaceReq { ...@@ -22,10 +22,6 @@ public class ApiInterfaceReq {
@NotNull(message = "api类型不能为空") @NotNull(message = "api类型不能为空")
public String apiType; public String apiType;
/* @ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空")
public String apiId;*/
@ApiModelProperty(value = "接口描述",required = false) @ApiModelProperty(value = "接口描述",required = false)
public String apiDesc; public String apiDesc;
...@@ -53,9 +49,9 @@ public class ApiInterfaceReq { ...@@ -53,9 +49,9 @@ public class ApiInterfaceReq {
@ApiModelProperty(value = "api描述",required = false) @ApiModelProperty(value = "api描述",required = false)
public String apiFunction; public String apiFunction;
@ApiModelProperty(value = "文件Id",required = true) @ApiModelProperty(value = "父类文件id,一级文件夹传入0",required = true)
@NotNull(message="文件id不能为空") @NotNull(message="父类id文件id不能为空")
public Long fileId; public Long parentId;
@ApiModelProperty(value = "项目id",required = true) @ApiModelProperty(value = "项目id",required = true)
@NotNull(message="项目id不能为空") @NotNull(message="项目id不能为空")
......
...@@ -20,9 +20,9 @@ import java.io.Serializable; ...@@ -20,9 +20,9 @@ import java.io.Serializable;
@ApiModel("数据银行api制作") @ApiModel("数据银行api制作")
public class MakeDataBankApiReq implements Serializable { public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty(value = "api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义",required = true) //@ApiModelProperty(value = "api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义",required = true)
@NotNull(message = "api类型不能为空") //@NotNull(message = "api类型不能为空")
public String apiType; //public String apiType;
@ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true) @ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true)
@NotNull(message = "传输方式不能为空") @NotNull(message = "传输方式不能为空")
...@@ -36,6 +36,17 @@ public class MakeDataBankApiReq implements Serializable { ...@@ -36,6 +36,17 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull(message = "接入类型不能为空") @NotNull(message = "接入类型不能为空")
public String joinType; public String joinType;
@ApiModelProperty(value = "输出类型:flow 流,json json形式",required = true)
@NotNull(message = "输出类型不能为空")
public String outputType;
@ApiModelProperty(value = "是否分页:",required = false)
//@NotNull(message = "是否分页不能为空")
public Boolean page;
@ApiModelProperty(value = "请求地址",required = false)
public String apiPath;
@ApiModelProperty(value = "接口描述",required = false) @ApiModelProperty(value = "接口描述",required = false)
public String apiDesc; public String apiDesc;
......
...@@ -17,10 +17,10 @@ public interface ApiDirectionService { ...@@ -17,10 +17,10 @@ public interface ApiDirectionService {
/** /**
* 根据类型获取API类型信息 * 根据类型获取API类型信息
* @param parentCode * @param parentKey
* @return * @return
*/ */
List<ApiDirection> getApiType(String parentCode); List<ApiDirection> getApiType(String parentKey);
/** /**
* 查询code值信息 * 查询code值信息
......
...@@ -93,7 +93,8 @@ public interface ProducerService { ...@@ -93,7 +93,8 @@ public interface ProducerService {
* 获取文件列表 * 获取文件列表
* @param pageNum * @param pageNum
* @param pageSize * @param pageSize
* @param projectId
* @return * @return
*/ */
IPage<ApiInterfaceFile> getFileCatalog( String pageNum, String pageSize); IPage<ApiInterfaceFile> getFileCatalog(Long projectId ,String pageNum, String pageSize);
} }
...@@ -29,25 +29,31 @@ public class ApiDirectionServiceImpl implements ApiDirectionService { ...@@ -29,25 +29,31 @@ public class ApiDirectionServiceImpl implements ApiDirectionService {
private ApiDirectionMapper apiDirectionMapper; private ApiDirectionMapper apiDirectionMapper;
@Override @Override
public List<ApiDirection> getApiType(String parentCode) { public List<ApiDirection> getApiType(String parentKey) {
QueryWrapper<ApiDirection> query = new QueryWrapper<>(); QueryWrapper<ApiDirection> query = new QueryWrapper<>();
query.eq("parent",parentCode);//父类下的所有子类 query.eq("parent",parentKey);//父类下的所有子类
query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE); query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE);
return apiDirectionMapper.selectList(query); List<ApiDirection> apiDirections = apiDirectionMapper.selectList(query);
apiDirections.forEach((x)->{
if (null == x.getParent()) {
apiDirections.remove(x.getId());
}
});
return apiDirections;
} }
@Override @Override
public List<ApiDirection> getDirectionVal(String key,String code) { public List<ApiDirection> getDirectionVal(String key,String code) {
QueryWrapper<ApiDirection> query = new QueryWrapper<>(); QueryWrapper<ApiDirection> query = new QueryWrapper<>();
if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(code)){ if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(code)){
query.eq("key",key); query.eq("`key`",key);
query.eq("code",code); query.eq("`code`",code);
query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE); query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE);
}else if (StringUtils.isNotBlank(code)){ }else if (StringUtils.isNotBlank(key)){
query.eq("key",key); query.eq("`key`",key);
query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE); query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE);
}else { }else {
query.eq("code",code); query.eq("`code`",code);
query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE); query.eq("is_enabled", GeneralStatusTypeEnum.ENABLE);
} }
return apiDirectionMapper.selectList(query); return apiDirectionMapper.selectList(query);
......
package com.jz.dm.service.request; package com.jz.dm.service.request;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jz.common.utils.HttpsUtils;
import com.jz.common.utils.RedisUtils;
import com.jz.dm.common.enums.GatewayResultCode; import com.jz.dm.common.enums.GatewayResultCode;
import com.jz.dm.common.util.OpenApiRequest; import com.jz.dm.common.util.OpenApiRequest;
import com.jz.dm.common.util.OpenApiResponse; import com.jz.dm.common.util.OpenApiResponse;
...@@ -15,6 +17,8 @@ import org.springframework.stereotype.Service; ...@@ -15,6 +17,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
/** /**
* @author ZC * @author ZC
* @PACKAGE_NAME: com.jz.dm.service.request * @PACKAGE_NAME: com.jz.dm.service.request
...@@ -39,6 +43,10 @@ public class ApiQueryService implements OpenApiService { ...@@ -39,6 +43,10 @@ public class ApiQueryService implements OpenApiService {
@Autowired @Autowired
private ApiInterfaceService apiInterfaceService; private ApiInterfaceService apiInterfaceService;
@Autowired
private RedisUtils redisUtils;
@Autowired
private HttpsUtils httpsUtils;
@Override @Override
@ApiLogAspect(description = "API请求日志") @ApiLogAspect(description = "API请求日志")
@AccessLimit(limit = 10000,sec = 1) @AccessLimit(limit = 10000,sec = 1)
...@@ -57,6 +65,22 @@ public class ApiQueryService implements OpenApiService { ...@@ -57,6 +65,22 @@ public class ApiQueryService implements OpenApiService {
break; break;
case "CUSTOM_QUERY": //自定义查询(三方查询) case "CUSTOM_QUERY": //自定义查询(三方查询)
break; break;
case "DATA_BANK_QUERY": //数据银行查询
String reqParams = parameter.getString("reqParams");
if (StringUtils.isNotBlank(reqParams)){
String apiInterface = redisUtils.get(request.getAppKey());
if (null != apiInterface){//存在
JSONObject jsonObject = JSONObject.parseObject(apiInterface);
String requestParam = jsonObject.getString("requestParam");
String targetUrl =jsonObject.getString("targetUrl");
Map param = (Map)JSONObject.parseObject(requestParam);
String respResult = httpsUtils.doGet(targetUrl, param);
response.setAttribute(respResult);
}else {//不存在查询数据库
//apiInterfaceService.getReqTargetInfo(request.getAppKey());
}
}
break;
case "DATA_BAG_QUERY": //数据包查询 case "DATA_BAG_QUERY": //数据包查询
break; break;
default : default :
......
package com.jz.dm.gateway.orther; package com.jz.dm.gateway.orther;
import com.jz.common.utils.WebUtils; import com.alibaba.fastjson.JSONObject;
import com.jz.common.utils.HttpsUtils;
import com.jz.dm.gateway.SpringTestCase; import com.jz.dm.gateway.SpringTestCase;
import com.jz.dm.service.ProducerService; import com.jz.dm.service.ProducerService;
import org.junit.Test; import org.junit.Test;
...@@ -23,19 +24,21 @@ public class TestMakeApi extends SpringTestCase { ...@@ -23,19 +24,21 @@ public class TestMakeApi extends SpringTestCase {
@Autowired @Autowired
private ProducerService producerService; private ProducerService producerService;
@Autowired
private HttpsUtils httpsUtils;
@Test @Test
public void testApiMake() { public void testApiMake() {
Map headers = new HashMap<String, String>(); Map headers = new HashMap<String, String>();
headers.put("Content-Type","application/json;charset=UTF-8"); headers.put("Content-Type","application/json;charset=UTF-8");
headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
Map params = new HashMap<String, String>(); JSONObject params = new JSONObject();
params.put("apiType","2"); params.put("apiType","2");
params.put("apiKey","www.q99sss9"); params.put("apiKey","www.q99sss9");
params.put("apiProtocl","HTTPS"); params.put("apiProtocl","HTTPS");
params.put("type","1"); params.put("type","1");
try { try {
String result = WebUtils.post(url, params,headers); String result = httpsUtils.submitPost(url, params,headers);
System.out.println("接受到的结果为:"+result); System.out.println("接受到的结果为:"+result);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -78,9 +78,9 @@ public enum ResultMsg { ...@@ -78,9 +78,9 @@ public enum ResultMsg {
*/ */
INVALID_USER("用户错误"), INVALID_USER("用户错误"),
/** /**
* 用户已报备 * 用户未登录
*/ */
USER_REPORTED("用户已报备"), USER_NOT_LOGIN("用户未登录"),
/** /**
* 用户名错误 * 用户名错误
......
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