feat : 添加外部接口必要参数
This commit is contained in:
@@ -33,6 +33,16 @@ public class Portal extends BaseEntity {
|
||||
*/
|
||||
private Long queryId;
|
||||
|
||||
/**
|
||||
* 菜单id
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 接口id
|
||||
*/
|
||||
private Long interfaceId;
|
||||
|
||||
/**
|
||||
* 数据适配器id
|
||||
*/
|
||||
@@ -73,11 +83,6 @@ public class Portal extends BaseEntity {
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 第三方接口地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.fateverse.query.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 第三方接口信息
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2024/4/26 11:17
|
||||
*/
|
||||
@Data
|
||||
public class PortalInterface {
|
||||
|
||||
/**
|
||||
* 接口id
|
||||
*/
|
||||
private Long interfaceId;
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*/
|
||||
private String requestMethod;
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
public class PortalBo implements Serializable {
|
||||
private Long portalId;
|
||||
private Long queryId;
|
||||
private Long interfaceId;
|
||||
private Long adapterId;
|
||||
private PortalEnum type;
|
||||
private String requestMethod;
|
||||
@@ -36,13 +37,13 @@ public class PortalBo implements Serializable {
|
||||
return PortalBo.builder()
|
||||
.portalId(portal.getPortalId())
|
||||
.queryId(portal.getQueryId())
|
||||
.interfaceId(portal.getInterfaceId())
|
||||
.adapterId(portal.getAdapterId())
|
||||
.type(portal.getType())
|
||||
.requestMethod(portal.getRequestMethod())
|
||||
.createDataAdapter(portal.getCreateDataAdapter())
|
||||
.page(portal.getPage())
|
||||
.path(portal.getPath())
|
||||
.url(portal.getUrl())
|
||||
.state(portal.getState())
|
||||
.mappings(mappings)
|
||||
.build();
|
||||
|
||||
@@ -72,6 +72,16 @@ public class PortalDto {
|
||||
@NotNull(message = "是否创建数据适配器不能为空!")
|
||||
private Boolean createDataAdapter;
|
||||
|
||||
@ApiModelProperty("请求地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty("请求类型")
|
||||
private String contentType;
|
||||
|
||||
|
||||
@ApiModelProperty("接口请求方法类型")
|
||||
private String interfaceRequestMethod;
|
||||
|
||||
/**
|
||||
* 是否分页
|
||||
*/
|
||||
@@ -84,13 +94,6 @@ public class PortalDto {
|
||||
@NotBlank(message = "系统暴露地址不能为空")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 第三方接口地址
|
||||
*/
|
||||
@ApiModelProperty("第三方接口地址")
|
||||
private String url;
|
||||
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@@ -121,7 +124,6 @@ public class PortalDto {
|
||||
.page(page)
|
||||
.type(type)
|
||||
.path(path)
|
||||
.url(url)
|
||||
.state(state)
|
||||
.build();
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.fateverse.query.mapper;
|
||||
|
||||
import cn.fateverse.query.entity.PortalInterface;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2024/4/26 11:23
|
||||
*/
|
||||
public interface PortalInterfaceMapper {
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param interfaceId 接口id
|
||||
* @return 接口信息
|
||||
*/
|
||||
PortalInterface selectById(Long interfaceId);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param portalInterface 接口信息
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer insert(PortalInterface portalInterface);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param portalInterface 接口信息
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer update(PortalInterface portalInterface);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param interfaceId 接口id
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer deleteById(Long interfaceId);
|
||||
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import cn.fateverse.query.entity.vo.PortalIdWrapper;
|
||||
import cn.fateverse.query.enums.DataAdapterType;
|
||||
import cn.fateverse.query.enums.PortalPremEnum;
|
||||
import cn.fateverse.query.handler.reader.DataAdapterHandlerReader;
|
||||
import cn.fateverse.query.mapper.*;
|
||||
import cn.fateverse.query.portal.service.HandlerMethodService;
|
||||
import cn.fateverse.query.constant.QueryConstant;
|
||||
import cn.fateverse.query.entity.dto.PortalDto;
|
||||
@@ -19,10 +20,6 @@ import cn.fateverse.query.entity.query.PortalQuery;
|
||||
import cn.fateverse.query.entity.vo.PortalVo;
|
||||
import cn.fateverse.query.entity.vo.SimplePortalVo;
|
||||
import cn.fateverse.query.enums.PortalEnum;
|
||||
import cn.fateverse.query.mapper.DataAdapterMapper;
|
||||
import cn.fateverse.query.mapper.PortalMapper;
|
||||
import cn.fateverse.query.mapper.PortalMappingMapper;
|
||||
import cn.fateverse.query.mapper.UniQueryMapper;
|
||||
import cn.fateverse.query.service.PortalService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -58,6 +55,8 @@ public class PortalServiceImpl implements PortalService {
|
||||
|
||||
private final PortalMappingMapper portalMappingMapper;
|
||||
|
||||
private final PortalInterfaceMapper portalInterfaceMapper;
|
||||
|
||||
|
||||
private final DataAdapterHandlerReader handlerReader;
|
||||
|
||||
@@ -67,12 +66,14 @@ public class PortalServiceImpl implements PortalService {
|
||||
PortalMappingMapper portalMappingMapper,
|
||||
ThreadPoolTaskExecutor taskExecuteExecutor,
|
||||
HandlerMethodService methodService,
|
||||
PortalInterfaceMapper portalInterfaceMapper,
|
||||
DataAdapterHandlerReader handlerReader) {
|
||||
this.portalMapper = portalMapper;
|
||||
this.queryMapper = queryMapper;
|
||||
this.adapterMapper = adapterMapper;
|
||||
this.portalMappingMapper = portalMappingMapper;
|
||||
this.methodService = methodService;
|
||||
this.portalInterfaceMapper = portalInterfaceMapper;
|
||||
this.handlerReader = handlerReader;
|
||||
taskExecuteExecutor.execute(() -> {
|
||||
PortalQuery query = new PortalQuery();
|
||||
@@ -240,8 +241,8 @@ public class PortalServiceImpl implements PortalService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PortalIdWrapper save(PortalDto portalDto) {
|
||||
checkPortalType(portalDto);
|
||||
Portal portal = portalDto.toPortal();
|
||||
checkPortalType(portal);
|
||||
Portal old = portalMapper.selectByPath(portal.getPath(), portal.getRequestMethod());
|
||||
if (!ObjectUtils.isEmpty(old)) {
|
||||
throw new CustomException("系统中存在当前请求路径");
|
||||
@@ -260,6 +261,9 @@ public class PortalServiceImpl implements PortalService {
|
||||
throw new CustomException("未找到对应的数据适配器!");
|
||||
}
|
||||
}
|
||||
if (PortalEnum.EXTERNAL.equals(portal.getType())) {
|
||||
createPortalInterface(portalDto, portal);
|
||||
}
|
||||
portalMapper.insert(portal);
|
||||
List<PortalMapping> mappings = portalDto.getMappings();
|
||||
if (!ObjectUtils.isEmpty(mappings)) {
|
||||
@@ -279,8 +283,8 @@ public class PortalServiceImpl implements PortalService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PortalIdWrapper edit(PortalDto portalDto) {
|
||||
checkPortalType(portalDto);
|
||||
Portal portal = portalDto.toPortal();
|
||||
checkPortalType(portal);
|
||||
Portal old = portalMapper.selectByPath(portal.getPath(), portal.getRequestMethod());
|
||||
if (!QueryConstant.PORTAL_DEV.equals(old.getState())) {
|
||||
throw new CustomException("当前状态不允许修改");
|
||||
@@ -295,6 +299,22 @@ public class PortalServiceImpl implements PortalService {
|
||||
adapterMapper.deleteById(old.getAdapterId());
|
||||
}
|
||||
}
|
||||
if (!old.getType().equals(portal.getType())) {
|
||||
if (PortalEnum.LOCAL.equals(portal.getType())) {
|
||||
portalInterfaceMapper.deleteById(old.getInterfaceId());
|
||||
} else {
|
||||
createPortalInterface(portalDto, portal);
|
||||
}
|
||||
} else {
|
||||
if (PortalEnum.EXTERNAL.equals(portal.getType())) {
|
||||
PortalInterface portalInterface = new PortalInterface();
|
||||
portalInterface.setInterfaceId(old.getInterfaceId());
|
||||
portalInterface.setContentType(portalDto.getContentType());
|
||||
portalInterface.setRequestMethod(portalDto.getInterfaceRequestMethod());
|
||||
portalInterface.setUrl(portalDto.getUrl());
|
||||
portalInterfaceMapper.update(portalInterface);
|
||||
}
|
||||
}
|
||||
portalMappingMapper.deleteByPortalId(portal.getPortalId());
|
||||
portalMapper.update(portal);
|
||||
if (!ObjectUtils.isEmpty(portalDto.getMappings())) {
|
||||
@@ -340,6 +360,9 @@ public class PortalServiceImpl implements PortalService {
|
||||
adapterMapper.deleteById(portal.getAdapterId());
|
||||
}
|
||||
portalMappingMapper.deleteByPortalId(portalId);
|
||||
if (PortalEnum.EXTERNAL.equals(portal.getType())) {
|
||||
portalInterfaceMapper.deleteById(portal.getInterfaceId());
|
||||
}
|
||||
portalMapper.deleteById(portalId);
|
||||
}
|
||||
|
||||
@@ -393,19 +416,40 @@ public class PortalServiceImpl implements PortalService {
|
||||
portal.setAdapterId(dataAdapter.getAdapterId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建第三方接口
|
||||
*
|
||||
* @param portalDto 接口dto对象
|
||||
* @param portal 接口对象
|
||||
*/
|
||||
private void createPortalInterface(PortalDto portalDto, Portal portal) {
|
||||
PortalInterface portalInterface = new PortalInterface();
|
||||
portalInterface.setContentType(portalDto.getContentType());
|
||||
portalInterface.setRequestMethod(portalDto.getInterfaceRequestMethod());
|
||||
portalInterface.setUrl(portalDto.getUrl());
|
||||
portalInterfaceMapper.insert(portalInterface);
|
||||
portal.setInterfaceId(portalInterface.getInterfaceId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查接口类型是否正确
|
||||
*
|
||||
* @param portal 接口信息
|
||||
* @param portalDto 接口信息
|
||||
*/
|
||||
private void checkPortalType(Portal portal) {
|
||||
if (PortalEnum.LOCAL.equals(portal.getType())) {
|
||||
if (ObjectUtils.isEmpty(portal.getQueryId())) {
|
||||
private void checkPortalType(PortalDto portalDto) {
|
||||
if (PortalEnum.LOCAL.equals(portalDto.getType())) {
|
||||
if (ObjectUtils.isEmpty(portalDto.getQueryId())) {
|
||||
throw new CustomException("请选择查询接口!");
|
||||
}
|
||||
portal.setUrl(null);
|
||||
} else if (PortalEnum.EXTERNAL.equals(portal.getType())) {
|
||||
if (ObjectUtils.isEmpty(portal.getUrl())) {
|
||||
} else if (PortalEnum.EXTERNAL.equals(portalDto.getType())) {
|
||||
if (ObjectUtils.isEmpty(portalDto.getContentType())) {
|
||||
throw new CustomException("外部接口请求类型不能为空");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(portalDto.getInterfaceRequestMethod())) {
|
||||
throw new CustomException("外部接口请求方法不能为空");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(portalDto.getUrl())) {
|
||||
throw new CustomException("第三方接口地址不能为空!");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.fateverse.query.mapper.PortalInterfaceMapper">
|
||||
|
||||
<select id="selectById" resultType="cn.fateverse.query.entity.PortalInterface">
|
||||
select interface_id, content_type, request_method
|
||||
from portal_interface
|
||||
where interface_id = #{interfaceId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyColumn="interface_id" keyProperty="interfaceId">
|
||||
insert into portal_interface (interface_id, content_type, request_method)
|
||||
values (#{interfaceId}, #{contentType}, #{requestMethod})
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update portal_interface
|
||||
set content_type = #{contentType},
|
||||
request_method = #{requestMethod}
|
||||
where interface_id = #{interfaceId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
from portal_interface
|
||||
where interface_id = #{interfaceId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -7,6 +7,8 @@
|
||||
<sql id="selectVo">
|
||||
select portal_id,
|
||||
query_id,
|
||||
menu_id,
|
||||
interface_id,
|
||||
adapter_id,
|
||||
portal_name,
|
||||
permission_type,
|
||||
@@ -15,7 +17,6 @@
|
||||
create_data_adapter,
|
||||
page,
|
||||
path,
|
||||
url,
|
||||
state,
|
||||
create_by,
|
||||
create_time,
|
||||
@@ -32,7 +33,8 @@
|
||||
<select id="selectList" resultType="cn.fateverse.query.entity.Portal">
|
||||
<include refid="selectVo"/>
|
||||
<where>
|
||||
<if test="portalName != null and portalName != ''">and portal_name like concat('%', #{portalName}, '%')</if>
|
||||
<if test="portalName != null and portalName != ''">and portal_name like concat('%', #{portalName}, '%')
|
||||
</if>
|
||||
<if test="permissionType != null ">and permission_type = #{permissionType}</if>
|
||||
<if test="type != null">and type = #{type}</if>
|
||||
<if test="state != null">and state = #{state}</if>
|
||||
@@ -50,6 +52,7 @@
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="queryId != null">query_id,</if>
|
||||
<if test="adapterId != null">adapter_id,</if>
|
||||
<if test="interfaceId != null">interface_id,</if>
|
||||
<if test="portalName != null">portal_name,</if>
|
||||
<if test="permissionType != null">permission_type,</if>
|
||||
<if test="type != null">type,</if>
|
||||
@@ -57,7 +60,6 @@
|
||||
<if test="requestMethod != null">request_method,</if>
|
||||
<if test="createDataAdapter != null">create_data_adapter,</if>
|
||||
<if test="path != null">path,</if>
|
||||
<if test="url != null">url,</if>
|
||||
<if test="state != null">state,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null ">create_time,</if>
|
||||
@@ -65,6 +67,7 @@
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="queryId != null">#{queryId},</if>
|
||||
<if test="adapterId != null">#{adapterId},</if>
|
||||
<if test="interfaceId != null">#{interfaceId},</if>
|
||||
<if test="portalName != null">#{portalName},</if>
|
||||
<if test="permissionType != null">#{permissionType},</if>
|
||||
<if test="type != null">#{type},</if>
|
||||
@@ -72,7 +75,6 @@
|
||||
<if test="requestMethod != null">#{requestMethod},</if>
|
||||
<if test="createDataAdapter != null">#{createDataAdapter},</if>
|
||||
<if test="path != null">#{path},</if>
|
||||
<if test="url != null">#{url},</if>
|
||||
<if test="state != null">#{state},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null ">#{createTime},</if>
|
||||
@@ -84,6 +86,7 @@
|
||||
<set>
|
||||
<if test="queryId != null">query_id = #{queryId},</if>
|
||||
<if test="adapterId != null">adapter_id = #{adapterId},</if>
|
||||
<if test="interfaceId != null">interface_id = #{interfaceId},</if>
|
||||
<if test="portalName != null">portal_name = #{portalName},</if>
|
||||
<if test="permissionType != null">permission_type = #{permissionType},</if>
|
||||
<if test="type != null">type = #{type},</if>
|
||||
@@ -91,7 +94,6 @@
|
||||
<if test="requestMethod != null">request_method = #{requestMethod},</if>
|
||||
<if test="createDataAdapter != null">create_data_adapter = #{createDataAdapter},</if>
|
||||
<if test="path != null">path = #{path},</if>
|
||||
<if test="url != null">url = #{url},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
|
||||
Reference in New Issue
Block a user