Commit d85b43d7 authored by ysongq's avatar ysongq

Merge branch 'dm_dev' of http://gitlab.ioubuy.cn/yaobenzhang/dm_project into dm_dev

parents 8a3abdeb c050d053
package com.jz.dm.common.enums.apiInterface;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.apiInterface
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiInfoOutTypeEnum
* @DATE: 2021-1-6/11:14
* @DAY_NAME_SHORT: 周三
* @Description: 输出类型
**/
public enum ApiInfoOutTypeEnum {
JSON,
XML,
FLOW;
}
...@@ -81,8 +81,8 @@ public class AuthController { ...@@ -81,8 +81,8 @@ public class AuthController {
* @Author: Mr.zhang * @Author: Mr.zhang
* @Date: 2020-12-26 * @Date: 2020-12-26
*/ */
// @ApiOperation("认证信息修改") @ApiOperation("取消授权")
//@PostMapping(value = "/update-auth-info") @PostMapping(value = "/update-auth-info")
public Mono<Result> updateAuthListInfo(@RequestBody @Valid AuthInfoUpdateReq req) { public Mono<Result> updateAuthListInfo(@RequestBody @Valid AuthInfoUpdateReq req) {
return Mono.fromSupplier(() -> authService.updateAuthInfo(req)); return Mono.fromSupplier(() -> authService.updateAuthInfo(req));
} }
......
...@@ -104,7 +104,7 @@ public class ProducerController { ...@@ -104,7 +104,7 @@ public class ProducerController {
*/ */
@ApiOperation("保存修改的api信息") @ApiOperation("保存修改的api信息")
@PostMapping(value = "/保存修改的api信息") @PostMapping(value = "/保存修改的api信息")
public Mono<Result> saveUpdateAPiInfo(@RequestBody @Valid MakeApiSaveInfoReq req) { public Mono<Result> saveUpdateAPiInfo(@RequestBody @Valid ApiInterfaceReq req) {
return Mono.fromSupplier(() -> producerService.saveUpdateAPiInfo(req)); return Mono.fromSupplier(() -> producerService.saveUpdateAPiInfo(req));
} }
......
...@@ -24,9 +24,6 @@ public class AuthInfoDto implements Serializable { ...@@ -24,9 +24,6 @@ public class AuthInfoDto implements Serializable {
@ApiModelProperty(value = "授权组织id") @ApiModelProperty(value = "授权组织id")
private Long apiOrgId; private Long apiOrgId;
/* @ApiModelProperty(value = "api应用id")
private Long apiInterfaceId;*/
@ApiModelProperty(value = "授权组织名称") @ApiModelProperty(value = "授权组织名称")
private String orgName; private String orgName;
......
...@@ -2,6 +2,7 @@ package com.jz.dm.models.req.auth; ...@@ -2,6 +2,7 @@ package com.jz.dm.models.req.auth;
import com.jz.common.bean.BasePageBean; import com.jz.common.bean.BasePageBean;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -18,4 +19,12 @@ import java.io.Serializable; ...@@ -18,4 +19,12 @@ import java.io.Serializable;
@Data @Data
@ApiModel("认证信息列表请求体") @ApiModel("认证信息列表请求体")
public class AuthListInfoReq extends BasePageBean implements Serializable { public class AuthListInfoReq extends BasePageBean implements Serializable {
@ApiModelProperty(value = "apiKey api唯一标识",required = false)
private String apiKey;
@ApiModelProperty(value = "授权码",required = false)
private String authCode;
} }
...@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable;
/** /**
* @author ZC * @author ZC
...@@ -17,7 +18,7 @@ import javax.validation.constraints.NotNull; ...@@ -17,7 +18,7 @@ import javax.validation.constraints.NotNull;
**/ **/
@Data @Data
@ApiModel(value = "api基本信息") @ApiModel(value = "api基本信息")
public class ApiInterfaceReq { public class ApiInterfaceReq implements Serializable {
@ApiModelProperty(value = "api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义",required = true) @ApiModelProperty(value = "api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义",required = true)
@NotNull(message = "api类型不能为空") @NotNull(message = "api类型不能为空")
public String apiType; public String apiType;
...@@ -25,8 +26,7 @@ public class ApiInterfaceReq { ...@@ -25,8 +26,7 @@ public class ApiInterfaceReq {
@ApiModelProperty(value = "接口描述",required = false) @ApiModelProperty(value = "接口描述",required = false)
public String apiDesc; public String apiDesc;
@ApiModelProperty(value = "传输方式:http https",required = true)
@ApiModelProperty(value = "传输方式",required = true)
@NotNull(message = "传输方式不能为空") @NotNull(message = "传输方式不能为空")
public String transMode; public String transMode;
...@@ -58,14 +58,10 @@ public class ApiInterfaceReq { ...@@ -58,14 +58,10 @@ public class ApiInterfaceReq {
public Long projectId; public Long projectId;
@ApiModelProperty(value = "状态",required = false)
public String status;
/*@ApiModelProperty(value = "api名称",required = false) @ApiModelProperty(value = "更新时传入api自增id",required = false)
public String apiName; public Long id;
*/
/* @ApiModelProperty(value = "状态",required = false)
public String status;*/
//@ApiModelProperty(value = "更新时传入api自增id",required = false)
//public Long id;
} }
package com.jz.dm.models.req.make;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.req.make
* @PROJECT_NAME: jz-dm-parent
* @NAME: MakeApiSaveInfoReq
* @DATE: 2020-12-29/10:00
* @DAY_NAME_SHORT: 周二
* @Description:
**/
@Data
@ApiModel("保存API基本信息请求体")
public class MakeApiSaveInfoReq implements Serializable {
@ApiModelProperty(value = "id",required = true)
@NotNull(message = "id不能为空")
public Long id;
@ApiModelProperty(value = "api类型",required = true)
@NotNull(message = "api类型不能为空")
public String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空")
public String apiId;
@ApiModelProperty(value = "接口描述",required = false)
public String apiDesc;
@ApiModelProperty(value = "api版本",required = false)
public String version;
@ApiModelProperty(value = "加密方式",required = true)
@NotNull(message = "加密方式不能为空")
public String transMode;
@ApiModelProperty(value = "传输方式",required = true)
@NotNull(message="传输方式不能为空")
public String type;
@ApiModelProperty(value = "目标地址",required = true)
@NotNull(message="目标地址不能为空")
public String targetUrl;
@ApiModelProperty(value = "超时时间",required = true)
@NotNull(message="超时时间不能为空")
public String timeout;
@ApiModelProperty(value = "api描述",required = false)
public String apiFunction;
@ApiModelProperty(value = "项目编号",required = true)
@NotNull(message="项目编号不能为空")
public String projectId;
@ApiModelProperty(value = "列",required = false)
public String columnCode;
@ApiModelProperty(value = "状态",required = false)
public String status;
}
...@@ -23,13 +23,16 @@ public class MakeBigDataApiReq implements Serializable { ...@@ -23,13 +23,16 @@ public class MakeBigDataApiReq implements Serializable {
@ApiModelProperty(value = "id--更新时id不能为空",required = false) @ApiModelProperty(value = "id--更新时id不能为空",required = false)
private Long id; private Long id;
@ApiModelProperty(value = "数据类型:api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 8 查询hive数据源 9自定义",required = true) /* @ApiModelProperty(value = "数据类型:api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 8 查询hive数据源 9自定义",required = true)
@NotNull(message = "apiType不能为空") @NotNull(message = "apiType不能为空")
private String apiType; private String apiType;*/
//@ApiModelProperty(value = "apiId 等价于apiKey",required = true) @ApiModelProperty(value = "接入类型:对应字典表key",required = true)
//@NotNull(message = "apiId不能为空") @NotNull(message = "接入类型不能为空")
//public String apiId; public String joinType;
@ApiModelProperty(value = "是否分页",required = false)
public Integer page;
@ApiModelProperty(value = "数据源Id",required = true) @ApiModelProperty(value = "数据源Id",required = true)
@NotNull(message = "数据源Id不能为空") @NotNull(message = "数据源Id不能为空")
...@@ -47,8 +50,6 @@ public class MakeBigDataApiReq implements Serializable { ...@@ -47,8 +50,6 @@ public class MakeBigDataApiReq implements Serializable {
@NotNull(message = "处理类型不能为空") @NotNull(message = "处理类型不能为空")
private String handleType; private String handleType;
@ApiModelProperty(value = "是否分页",required = false)
private long page;
@ApiModelProperty(value = "请求参数",required = true) @ApiModelProperty(value = "请求参数",required = true)
@NotNull(message = "请求参数不能为空") @NotNull(message = "请求参数不能为空")
......
...@@ -73,7 +73,7 @@ public interface ProducerService { ...@@ -73,7 +73,7 @@ public interface ProducerService {
* @param req * @param req
* @return * @return
*/ */
Result saveUpdateAPiInfo(MakeApiSaveInfoReq req); Result saveUpdateAPiInfo(ApiInterfaceReq req);
/** /**
* 数据银行制作API/数据包 * 数据银行制作API/数据包
......
...@@ -64,6 +64,12 @@ public class AuthServiceImpl implements AuthService { ...@@ -64,6 +64,12 @@ public class AuthServiceImpl implements AuthService {
public Result getAuthListInfo(AuthListInfoReq req) { public Result getAuthListInfo(AuthListInfoReq req) {
IPage<AuthInfoDto> page = new Page<>(req.getPageNum(), req.getPageSize()); IPage<AuthInfoDto> page = new Page<>(req.getPageNum(), req.getPageSize());
QueryWrapper<AuthInfoDto> query = new QueryWrapper<>(); QueryWrapper<AuthInfoDto> query = new QueryWrapper<>();
if (StringUtils.isNotBlank(req.getApiKey())){
query.eq("ai.api_key",req.getApiKey());
}
if (StringUtils.isNotBlank(req.getAuthCode())){
query.eq("au.auth_code",req.getAuthCode());
}
query.eq("au.is_deleted",0); query.eq("au.is_deleted",0);
query.orderByDesc("au.create_date"); query.orderByDesc("au.create_date");
IPage<AuthInfoDto> listSelectApiAuth = apiAuthMapper.listSelectApiAuth(page, query); IPage<AuthInfoDto> listSelectApiAuth = apiAuthMapper.listSelectApiAuth(page, query);
...@@ -234,8 +240,18 @@ public class AuthServiceImpl implements AuthService { ...@@ -234,8 +240,18 @@ public class AuthServiceImpl implements AuthService {
*/ */
@Override @Override
public Result updateAuthInfo(AuthInfoUpdateReq req) { public Result updateAuthInfo(AuthInfoUpdateReq req) {
//TODO 认证后是否可以修改 ApiAuth apiAuth = apiAuthMapper.selectById(req.getId());
return null; if (null == apiAuth){
return Result.of_error(ResultMsg.DATA_NOT_EXIST);
}
UpdateWrapper<ApiAuth> updateWra = new UpdateWrapper<>();
updateWra.set("is_deleted",1);
updateWra.set("status",GeneralStatusTypeEnum.UN_VALID.name());
updateWra.eq("id",req.getId());
if (apiAuthMapper.update(null,updateWra) == 0){
return Result.of_error(ResultMsg.UPDATE_FAIL);
}
return Result.of_success(ResultMsg.UPDATE_SUCCESS);
} }
/** /**
...@@ -274,6 +290,7 @@ public class AuthServiceImpl implements AuthService { ...@@ -274,6 +290,7 @@ public class AuthServiceImpl implements AuthService {
public ApiAuth getAuthUser(String authCode,Long apiId) { public ApiAuth getAuthUser(String authCode,Long apiId) {
QueryWrapper<ApiAuth> query = new QueryWrapper<>(); QueryWrapper<ApiAuth> query = new QueryWrapper<>();
query.eq("auth_code",authCode); query.eq("auth_code",authCode);
query.eq("status",GeneralStatusTypeEnum.VALID.name());
query.eq("api_interface_id",apiId); query.eq("api_interface_id",apiId);
query.eq("is_deleted",0); query.eq("is_deleted",0);
return apiAuthMapper.selectOne(query); return apiAuthMapper.selectOne(query);
......
...@@ -193,6 +193,7 @@ public class OrganizationManageImpl implements OrganizationManageService { ...@@ -193,6 +193,7 @@ public class OrganizationManageImpl implements OrganizationManageService {
public ApiOrg getAuthOrganization(Long apiOrgId) { public ApiOrg getAuthOrganization(Long apiOrgId) {
QueryWrapper<ApiOrg> query = new QueryWrapper<>(); QueryWrapper<ApiOrg> query = new QueryWrapper<>();
query.eq("id",apiOrgId); query.eq("id",apiOrgId);
query.eq("status", OrgStatusEnum.NORMAL.name());
query.eq("is_deleted",0); query.eq("is_deleted",0);
return apiOrgMapper.selectOne(query); return apiOrgMapper.selectOne(query);
} }
......
...@@ -15,6 +15,7 @@ import com.jz.common.utils.RedisUtils; ...@@ -15,6 +15,7 @@ import com.jz.common.utils.RedisUtils;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.common.constant.TagConstants; import com.jz.dm.common.constant.TagConstants;
import com.jz.dm.common.enums.GeneralStatusTypeEnum; import com.jz.dm.common.enums.GeneralStatusTypeEnum;
import com.jz.dm.common.enums.apiInterface.ApiInfoOutTypeEnum;
import com.jz.dm.common.enums.apiInterface.ApiStatusEnum; import com.jz.dm.common.enums.apiInterface.ApiStatusEnum;
import com.jz.dm.common.enums.produce.ProducerStatusTypeEnum; import com.jz.dm.common.enums.produce.ProducerStatusTypeEnum;
import com.jz.dm.common.util.RandomUtil; import com.jz.dm.common.util.RandomUtil;
...@@ -99,7 +100,7 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -99,7 +100,7 @@ public class ProducerServiceImpl implements ProducerService {
} }
/** /**
* 制作自定义Api * DMP制作自定义Api
* *
* @param req * @param req
* @return * @return
...@@ -118,29 +119,33 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -118,29 +119,33 @@ public class ProducerServiceImpl implements ProducerService {
@Override @Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public Result addDataBankApiInfo(MakeDataBankApiReq req) { public Result addDataBankApiInfo(MakeDataBankApiReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS); //SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) { //if (null == currentUser) {
return Result.of_error(ResultMsg.USER_NOT_LOGIN); // return Result.of_error(ResultMsg.USER_NOT_LOGIN);
} //}
List<ApiInterfaceFile> fileSource = List<ApiInterfaceFile> fileSource =
apiInterfaceFileMapper.selectList(new QueryWrapper<ApiInterfaceFile>().eq("file_source", "2")); apiInterfaceFileMapper.selectList(new QueryWrapper<ApiInterfaceFile>().eq("file_source", "2"));
if (fileSource.size() == 0 || fileSource.size() >= 2) { if (fileSource.size() == 0 || fileSource.size() >= 2) {
return Result.of_error("文件夹信息异常!"); return Result.of_error("文件夹信息异常!");
} }
if (StringUtils.isNotBlank(req.getOutputType()) &&
(!req.getOutputType().contains(ApiInfoOutTypeEnum.JSON.name()) ||
!req.getOutputType().contains(ApiInfoOutTypeEnum.FLOW.name()) )){
return Result.of_error("输出类型不存在!");
}
String apiKey =""; String apiKey ="";
if (StringUtils.isNotBlank(req.getJoinType()) if (StringUtils.isNotBlank(req.getJoinType())
&& "10006".equals(req.getJoinType())) {//数据银行制作API && "10006".equals(req.getJoinType())) {//数据银行制作API
apiKey = RandomUtil.getStringRandom(16); apiKey = RandomUtil.getStringRandom(16);
ApiInterface anInterface = new ApiInterface(); ApiInterface anInterface = new ApiInterface();
anInterface.setCreateUser(""); //anInterface.setCreateUser(currentUser.getUserName());
anInterface.setApiType("2");//数据银行制作api anInterface.setApiType("2");//数据银行制作api
anInterface.setStatus(ProducerStatusTypeEnum.ISSUE.name());//发布 anInterface.setStatus(ProducerStatusTypeEnum.ISSUE.name());//发布
anInterface.setApiKey(apiKey);//apiKey anInterface.setApiKey(apiKey);//apiKey
anInterface.setFileId(req.getFileId());
BeanUtils.copyProperties(req, anInterface); BeanUtils.copyProperties(req, anInterface);
int resIn = apiInterfaceMapper.insert(anInterface); int resIn = apiInterfaceMapper.insert(anInterface);
ApiInterfaceCustom interfaceCustom = new ApiInterfaceCustom(); ApiInterfaceCustom interfaceCustom = new ApiInterfaceCustom();
interfaceCustom.setCreateUser(""); //interfaceCustom.setCreateUser(currentUser.getUserName());
interfaceCustom.setApiKey(apiKey); interfaceCustom.setApiKey(apiKey);
interfaceCustom.setApiInterfaceId(anInterface.getId()); interfaceCustom.setApiInterfaceId(anInterface.getId());
BeanUtils.copyProperties(req, interfaceCustom); BeanUtils.copyProperties(req, interfaceCustom);
...@@ -188,7 +193,7 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -188,7 +193,7 @@ public class ProducerServiceImpl implements ProducerService {
public Result addBigDataMakeApi(MakeBigDataApiReq req) { public Result addBigDataMakeApi(MakeBigDataApiReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS); SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) { if (null == currentUser) {
return Result.of_error(ResultMsg.USER_NOT_LOGIN); return Result.of_error("用户信息不存在");
} }
QueryWrapper<ApiOpenApiEsFields> queryOpenApi = new QueryWrapper<>(); QueryWrapper<ApiOpenApiEsFields> queryOpenApi = new QueryWrapper<>();
queryOpenApi.eq("es_database", req.getEsDatabase()); queryOpenApi.eq("es_database", req.getEsDatabase());
...@@ -222,9 +227,6 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -222,9 +227,6 @@ public class ProducerServiceImpl implements ProducerService {
//api信息在redis中的key //api信息在redis中的key
String redisValueOfKey = RandomUtil.getStringRandom(16); String redisValueOfKey = RandomUtil.getStringRandom(16);
if (null != dataSource) { if (null != dataSource) {
redisTemplate.opsForValue().set(TagConstants.OPEN_API_HANDLER_INFO_NAMESPACE + redisValueOfKey, req.getHandleType());
//es相关信息
//redisTemplate.opsForValue().set(TagConstants.OPEN_API_ESTAG_INFO_NAMESPACE + redisValueOfKey, req);
//存入调用的基本ApiKey信息 //存入调用的基本ApiKey信息
redisTemplate.opsForValue().set( redisValueOfKey, req); redisTemplate.opsForValue().set( redisValueOfKey, req);
//esjdbc 连接地址 用于接口中调用获取es数据 //esjdbc 连接地址 用于接口中调用获取es数据
...@@ -232,7 +234,7 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -232,7 +234,7 @@ public class ProducerServiceImpl implements ProducerService {
} }
int result = 0; int result = 0;
ApiOpenApiEsTagconfig apiEsTagconfig = new ApiOpenApiEsTagconfig(); ApiOpenApiEsTagconfig apiEsTagconfig = new ApiOpenApiEsTagconfig();
if (null != req.getId() && "".equals(req.getId())) {//更新 if (null != req.getId() && !"".equals(req.getId())) {//更新
apiEsTagconfig.setUpdateDate(new Date()); apiEsTagconfig.setUpdateDate(new Date());
apiEsTagconfig.setUpdateUser(currentUser.getUserName()); apiEsTagconfig.setUpdateUser(currentUser.getUserName());
BeanUtils.copyProperties(req, apiEsTagconfig); BeanUtils.copyProperties(req, apiEsTagconfig);
...@@ -259,7 +261,7 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -259,7 +261,7 @@ public class ProducerServiceImpl implements ProducerService {
public Result saveInterfaceAPi(ApiInterfaceReq req) { public Result saveInterfaceAPi(ApiInterfaceReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS); SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) { if (null == currentUser) {
return Result.of_error(ResultMsg.USER_NOT_LOGIN); return Result.of_error("用户信息不存在");
} }
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>(); QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("project_id", req.getProjectId()); query.eq("project_id", req.getProjectId());
...@@ -303,6 +305,8 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -303,6 +305,8 @@ public class ProducerServiceImpl implements ProducerService {
if (apiInterfaceMapper.insert(apiInterface) == 0) { if (apiInterfaceMapper.insert(apiInterface) == 0) {
throw ResponseException.of_error("保存Api信息失败!"); throw ResponseException.of_error("保存Api信息失败!");
} }
//缓存到redis中
redisUtils.set(apiKey,req);
return Result.of_success(ResultMsg.INSERT_SUCCESS,apiKey); return Result.of_success(ResultMsg.INSERT_SUCCESS,apiKey);
} }
...@@ -313,22 +317,23 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -313,22 +317,23 @@ public class ProducerServiceImpl implements ProducerService {
* @return * @return
*/ */
@Override @Override
public Result saveUpdateAPiInfo(MakeApiSaveInfoReq req) { public Result saveUpdateAPiInfo(ApiInterfaceReq req) {
SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS); SysUserDto currentUser = getLoginUser(RedisMessageConstant.SENDTYPE_LOGIN_SYS);
if (null == currentUser) { if (null == currentUser) {
return Result.of_error(ResultMsg.USER_NOT_LOGIN); return Result.of_error("用户信息不存在");
} }
ApiInterface apiInterface = apiInterfaceMapper.selectById(req.getId()); ApiInterface apiInterface = apiInterfaceMapper.selectById(req.getId());
if (null == apiInterface) { if (null == apiInterface) {
return Result.of_error(ResultMsg.DATA_NOT_FOUND); return Result.of_error(ResultMsg.DATA_NOT_FOUND);
} }
if (StringUtils.isBlank(req.getType()) || "0".equals(req.getType())) { if (StringUtils.isBlank(req.getSignType()) || "0".equals(req.getSignType())) {
return Result.of_error("加密类型错误!"); return Result.of_error("加密类型错误!");
} }
apiInterface.setApiType(req.getApiType()); apiInterface.setApiType(req.getApiType());
apiInterface.setApiDesc(req.getApiDesc()); apiInterface.setApiDesc(req.getApiDesc());
apiInterface.setJoinType(req.getJoinType());
apiInterface.setVersion(RandomUtil.generateVersion(apiInterface.getVersion()));//版本自动累加 apiInterface.setVersion(RandomUtil.generateVersion(apiInterface.getVersion()));//版本自动累加
apiInterface.setSignType(req.getType()); apiInterface.setSignType(req.getSignType());
apiInterface.setApiProtocl(req.getTransMode());//传输方式 https http apiInterface.setApiProtocl(req.getTransMode());//传输方式 https http
if (StringUtils.isNotBlank(req.getTargetUrl())) { if (StringUtils.isNotBlank(req.getTargetUrl())) {
apiInterface.setTargetUrl(req.getTargetUrl()); apiInterface.setTargetUrl(req.getTargetUrl());
......
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.jz.common.utils.HttpsUtils; import com.jz.common.utils.HttpsUtils;
import com.jz.common.utils.RedisUtils; 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.enums.apiInterface.ApiInfoOutTypeEnum;
import com.jz.dm.common.exception.GatewayException; import com.jz.dm.common.exception.GatewayException;
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;
...@@ -66,26 +67,39 @@ public class ApiQueryService implements OpenApiService { ...@@ -66,26 +67,39 @@ public class ApiQueryService implements OpenApiService {
if (StringUtils.isNotBlank(selectType)) { if (StringUtils.isNotBlank(selectType)) {
try { try {
switch (selectType) { switch (selectType) {
case "QUERY_TAG": //标签查询 case "10001": //实时接入查询
break; break;
case "BIG_DATA_QUERY"://大数据查询 case "10003": //标签查询
break; break;
case "CUSTOM_QUERY": //自定义查询(三方查询) case "10002"://大数据查询
if (StringUtils.isNotBlank(apiInterface)){//redis中存在
JSONObject jsonBigData = JSONObject.parseObject(apiInterface);
String targetUrl = jsonBigData.getString("targetUrl");
rangRequestTarget(ApiInfoOutTypeEnum.JSON.name(),targetUrl,paramMap,response);
}else { //缓存中不存在 查询数据库
ApiInterface apiInfo= apiInterfaceService.getApiInfo(request.getAppKey());
if (apiInfo == null){
throw new GatewayException(GatewayResultCode.REQUEST_INFO_UNEXIST);
}
rangRequestTarget(ApiInfoOutTypeEnum.JSON.name(),apiInfo.getTargetUrl(),paramMap,response);
}
break;
case "10004": //自定义查询(三方查询)
if (StringUtils.isNotBlank(apiInterface)){//redis中存在 if (StringUtils.isNotBlank(apiInterface)){//redis中存在
JSONObject jsonCustom = JSONObject.parseObject(apiInterface); JSONObject jsonCustom = JSONObject.parseObject(apiInterface);
String targetUrl = jsonCustom.getString("targetUrl"); String targetUrl = jsonCustom.getString("targetUrl");
rangRequestTarget("json",targetUrl,null,response); rangRequestTarget(ApiInfoOutTypeEnum.JSON.name(),targetUrl,null,response);
}else {//redis中不存在,查询数据库 }else {//redis中不存在,查询数据库
ApiInterface apiReqDto = ApiInterface apiReqDto =
apiInterfaceService.getReqTargetInfo(request.getAppKey()); apiInterfaceService.getReqTargetInfo(request.getAppKey());
if (null == apiReqDto) { if (null == apiReqDto) {
throw new GatewayException(GatewayResultCode.REQUEST_INFO_UNEXIST); throw new GatewayException(GatewayResultCode.REQUEST_INFO_UNEXIST);
} }
rangRequestTarget("json",apiReqDto.getTargetUrl(),null,response); rangRequestTarget(ApiInfoOutTypeEnum.JSON.name(),apiReqDto.getTargetUrl(),null,response);
} }
break; break;
case "DATA_BANK_QUERY": //数据银行查询 case "10006": //数据银行查询
if (null != apiInterface) {//redis中存在 if (StringUtils.isNotBlank(apiInterface)) {//redis中存在
JSONObject jsonObject = JSONObject.parseObject(apiInterface); JSONObject jsonObject = JSONObject.parseObject(apiInterface);
String targetUrl = jsonObject.getString("targetUrl"); String targetUrl = jsonObject.getString("targetUrl");
String outputType = jsonObject.getString("outputType"); String outputType = jsonObject.getString("outputType");
...@@ -99,7 +113,21 @@ public class ApiQueryService implements OpenApiService { ...@@ -99,7 +113,21 @@ public class ApiQueryService implements OpenApiService {
rangRequestTarget(apiReqDto.getOutputType(), apiReqDto.getTargetUrl(),paramMap,response); rangRequestTarget(apiReqDto.getOutputType(), apiReqDto.getTargetUrl(),paramMap,response);
} }
break; break;
case "DATA_BAG_QUERY": //数据银行数据包查询 case "10007": //数据银行数据包查询
if (StringUtils.isNotBlank(apiInterface)){//从redis中获取数据
JSONObject jsonObject = JSONObject.parseObject(apiInterface);
String targetUrl = jsonObject.getString("targetUrl");
String outputType = jsonObject.getString("outputType");
rangRequestTarget(outputType, targetUrl, paramMap, response);
}else {//不存在查询数据库
ApiInterface apiReqDto =
apiInterfaceService.getReqTargetInfo(request.getAppKey());
if (null == apiReqDto) {
throw new GatewayException(GatewayResultCode.REQUEST_INFO_UNEXIST);
}
rangRequestTarget(apiReqDto.getOutputType(), apiReqDto.getTargetUrl(),paramMap,response);
}
break; break;
default: default:
response.setCode(GatewayResultCode.ILLEGAL_REQUEST.getCode()); response.setCode(GatewayResultCode.ILLEGAL_REQUEST.getCode());
...@@ -116,9 +144,9 @@ public class ApiQueryService implements OpenApiService { ...@@ -116,9 +144,9 @@ public class ApiQueryService implements OpenApiService {
} }
private void rangRequestTarget(String outputType, String targetUrl, Map<String, String> param, OpenApiResponse response) { private void rangRequestTarget(String outputType, String targetUrl, Map<String, String> param, OpenApiResponse response) {
if ("flow".equals(outputType)) {//文件流形式请求 if (ApiInfoOutTypeEnum.FLOW.name().equals(outputType)) {//文件流形式请求
// httpsUtils.doGetImg()TODO 流形式未实现 // httpsUtils.doGetImg()TODO 流形式未实现
} else if ("json".equals(outputType)) { } else if (ApiInfoOutTypeEnum.JSON.name().equals(outputType)) {
String respResult = httpsUtils.doGet(targetUrl, param); String respResult = httpsUtils.doGet(targetUrl, param);
response.setAttribute(respResult); response.setAttribute(respResult);
} else { } else {
......
package com.jz.common.utils; package com.jz.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -44,7 +45,7 @@ public class HttpsUtils { ...@@ -44,7 +45,7 @@ public class HttpsUtils {
* @param headers 请求头 * @param headers 请求头
* @return * @return
*/ */
public String submitPost(String url, String params, Map<String, String> headers) { public String submitPost(String url, JSONObject params, Map<String, String> headers) {
CloseableHttpClient httpClient = getHttpClient(); CloseableHttpClient httpClient = getHttpClient();
String body = null; String body = null;
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
...@@ -56,8 +57,8 @@ public class HttpsUtils { ...@@ -56,8 +57,8 @@ public class HttpsUtils {
httpPost.addHeader(e.getKey(), e.getValue()); httpPost.addHeader(e.getKey(), e.getValue());
} }
} }
if (StringUtils.isNotBlank(params)) { if (StringUtils.isNotBlank(params.toString())) {
httpPost.setEntity(new StringEntity(params, Consts.UTF_8)); httpPost.setEntity(new StringEntity(params.toString(), Consts.UTF_8));
} }
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
body = getBody(response.getEntity()); body = getBody(response.getEntity());
......
...@@ -143,7 +143,7 @@ public class Result<T> implements Serializable { ...@@ -143,7 +143,7 @@ public class Result<T> implements Serializable {
Result resultJson = new Result(ResultCode.FAILURE.getCode(),data); Result resultJson = new Result(ResultCode.FAILURE.getCode(),data);
return resultJson; return resultJson;
} }
@Deprecated //@Deprecated
public static Result of_error(String msg) { public static Result of_error(String msg) {
Result resultJson = new Result(ResultCode.FAILURE.getCode(),null,msg); Result resultJson = new Result(ResultCode.FAILURE.getCode(),null,msg);
return resultJson; return resultJson;
......
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