接口管理增加Mock配置
This commit is contained in:
parent
5a8ecdce48
commit
7704dd58ad
@ -4,6 +4,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@ -44,15 +45,14 @@ import com.sf.common.core.page.TableDataInfo;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口管理Controller
|
* 接口管理Controller
|
||||||
*
|
*
|
||||||
* @author zoukun
|
* @author zoukun
|
||||||
* @date 2024-04-22
|
* @date 2024-04-22
|
||||||
*/
|
*/
|
||||||
@Api("网关服务-接口管理")
|
@Api("网关服务-接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/gateway/interface")
|
@RequestMapping("/gateway/interface")
|
||||||
public class GatewayInterfaceInfoController extends BaseController
|
public class GatewayInterfaceInfoController extends BaseController {
|
||||||
{
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IGatewayInterfaceInfoService gatewayInterfaceInfoService;
|
private IGatewayInterfaceInfoService gatewayInterfaceInfoService;
|
||||||
|
|
||||||
@ -65,31 +65,18 @@ public class GatewayInterfaceInfoController extends BaseController
|
|||||||
@ApiOperation("查询接口信息列表")
|
@ApiOperation("查询接口信息列表")
|
||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:list')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(GatewayInterfaceInfo gatewayInterfaceInfo)
|
public TableDataInfo list(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||||
{
|
|
||||||
gatewayInterfaceInfo.setAppCode(AppUtils.getAppCodeFromRequestHeader());
|
gatewayInterfaceInfo.setAppCode(AppUtils.getAppCodeFromRequestHeader());
|
||||||
startPage();
|
startPage();
|
||||||
List<GatewayInterfaceInfo> list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
|
List<GatewayInterfaceInfo> list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
|
||||||
Set<Long> serverIds = list.stream().map(GatewayInterfaceInfo::getServerId).collect(Collectors.toSet());
|
Set<Long> serverIds = list.stream().map(GatewayInterfaceInfo::getServerId).collect(Collectors.toSet());
|
||||||
List<GatewayServer> serverList = gatewayServerService.selectGatewayServerByIds(serverIds);
|
List<GatewayServer> serverList = gatewayServerService.selectGatewayServerByIds(serverIds);
|
||||||
Map<Long, String> serverIdAndNameMap = serverList.stream().collect(Collectors.toMap(GatewayServer::getId, GatewayServer::getServerName));
|
Map<Long, GatewayServer> serverMap = serverList.stream().collect(Collectors.toMap(GatewayServer::getId, Function.identity()));
|
||||||
List<GatewayInterfaceInfoListVO> voList = list.stream().map(info -> {
|
List<GatewayInterfaceInfoListVO> voList = list.stream().map(info -> {
|
||||||
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
|
GatewayInterfaceInfoListVO vo = GatewayInterfaceInfoListVO.convert(info, serverMap.get(info.getServerId()));
|
||||||
vo.setId(info.getId());
|
|
||||||
vo.setInterfaceName(info.getInterfaceName());
|
|
||||||
vo.setApiCode(info.getApiCode());
|
|
||||||
vo.setInterfacePath(info.getInterfacePath());
|
|
||||||
vo.setRequestMethod(info.getRequestMethod());
|
|
||||||
vo.setDescription(info.getDescription());
|
|
||||||
vo.setVersion(info.getVersion());
|
|
||||||
vo.setStatus(info.getStatus());
|
|
||||||
vo.setDocument(info.getDocument());
|
|
||||||
// TODO 调用次数和平均时间暂时没有来源
|
// TODO 调用次数和平均时间暂时没有来源
|
||||||
vo.setNumberOfCalls(0L);
|
vo.setNumberOfCalls(0L);
|
||||||
vo.setAverageResponseTime(0L);
|
vo.setAverageResponseTime(0L);
|
||||||
vo.setCreateTime(info.getCreateTime());
|
|
||||||
vo.setServerId(info.getServerId());
|
|
||||||
vo.setServerName(serverIdAndNameMap.get(info.getServerId()));
|
|
||||||
return vo;
|
return vo;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
return getDataTable(voList);
|
return getDataTable(voList);
|
||||||
@ -99,8 +86,7 @@ public class GatewayInterfaceInfoController extends BaseController
|
|||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:export')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:export')")
|
||||||
@Log(title = "接口管理", businessType = BusinessType.EXPORT)
|
@Log(title = "接口管理", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, GatewayInterfaceInfo gatewayInterfaceInfo)
|
public void export(HttpServletResponse response, GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||||
{
|
|
||||||
List<GatewayInterfaceInfo> list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
|
List<GatewayInterfaceInfo> list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
|
||||||
ExcelUtil<GatewayInterfaceInfo> util = new ExcelUtil<GatewayInterfaceInfo>(GatewayInterfaceInfo.class);
|
ExcelUtil<GatewayInterfaceInfo> util = new ExcelUtil<GatewayInterfaceInfo>(GatewayInterfaceInfo.class);
|
||||||
util.exportExcel(response, list, "接口管理数据");
|
util.exportExcel(response, list, "接口管理数据");
|
||||||
@ -109,43 +95,15 @@ public class GatewayInterfaceInfoController extends BaseController
|
|||||||
@ApiOperation("获取接口详细信息")
|
@ApiOperation("获取接口详细信息")
|
||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:query')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:query')")
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||||
{
|
|
||||||
GatewayInterfaceInfoDetailedVO vo = new GatewayInterfaceInfoDetailedVO();
|
|
||||||
|
|
||||||
GatewayInterfaceInfo gatewayInterfaceInfo = gatewayInterfaceInfoService.selectGatewayInterfaceInfoById(id);
|
GatewayInterfaceInfo gatewayInterfaceInfo = gatewayInterfaceInfoService.selectGatewayInterfaceInfoById(id);
|
||||||
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id));
|
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id));
|
||||||
GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId());
|
GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId());
|
||||||
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet()));
|
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet()));
|
||||||
|
GatewayInterfaceInfoDetailedVO vo = GatewayInterfaceInfoDetailedVO.convert(gatewayInterfaceInfo,gatewayServer,strategyList);
|
||||||
vo.setId(gatewayInterfaceInfo.getId());
|
|
||||||
vo.setInterfaceName(gatewayInterfaceInfo.getInterfaceName());
|
|
||||||
vo.setApiCode(gatewayInterfaceInfo.getApiCode());
|
|
||||||
vo.setInterfacePath(gatewayInterfaceInfo.getInterfacePath());
|
|
||||||
vo.setRequestMethod(gatewayInterfaceInfo.getRequestMethod());
|
|
||||||
vo.setDescription(gatewayInterfaceInfo.getDescription());
|
|
||||||
vo.setVersion(gatewayInterfaceInfo.getVersion());
|
|
||||||
vo.setStatus(gatewayInterfaceInfo.getStatus());
|
|
||||||
vo.setDocument(gatewayInterfaceInfo.getDocument());
|
|
||||||
// TODO 调用次数和平均时间暂时没有来源
|
// TODO 调用次数和平均时间暂时没有来源
|
||||||
vo.setNumberOfCalls(0L);
|
vo.setNumberOfCalls(0L);
|
||||||
vo.setAverageResponseTime(0L);
|
vo.setAverageResponseTime(0L);
|
||||||
vo.setCreateTime(gatewayInterfaceInfo.getCreateTime());
|
|
||||||
vo.setUpdateTime(gatewayInterfaceInfo.getUpdateTime());
|
|
||||||
vo.setServerId(gatewayInterfaceInfo.getServerId());
|
|
||||||
vo.setServerName(gatewayServer.getServerName());
|
|
||||||
// 策略信息
|
|
||||||
List<GatewayStrategyListVO> strategyListVOList = strategyList.stream().map(strategy -> {
|
|
||||||
GatewayStrategyListVO strategyListVO = new GatewayStrategyListVO();
|
|
||||||
strategyListVO.setId(strategy.getId());
|
|
||||||
strategyListVO.setStrategyName(strategy.getStrategyName());
|
|
||||||
strategyListVO.setStrategyType(strategy.getStrategyType());
|
|
||||||
strategyListVO.setDescription(strategy.getDescription());
|
|
||||||
strategyListVO.setStatus(strategy.getStatus());
|
|
||||||
return strategyListVO;
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
vo.setStrategyList(strategyListVOList);
|
|
||||||
return success(vo);
|
return success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +111,7 @@ public class GatewayInterfaceInfoController extends BaseController
|
|||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:add')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:add')")
|
||||||
@Log(title = "接口管理", businessType = BusinessType.INSERT)
|
@Log(title = "接口管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody InsertGatewayInterfaceInfoDTO dto)
|
public AjaxResult add(@Validated @RequestBody InsertGatewayInterfaceInfoDTO dto) {
|
||||||
{
|
|
||||||
return success(gatewayInterfaceInfoService.insertGatewayInterfaceInfoAndBindStrategy(dto));
|
return success(gatewayInterfaceInfoService.insertGatewayInterfaceInfoAndBindStrategy(dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,25 +119,22 @@ public class GatewayInterfaceInfoController extends BaseController
|
|||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:edit')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:edit')")
|
||||||
@Log(title = "接口管理", businessType = BusinessType.UPDATE)
|
@Log(title = "接口管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody UpdateGatewayInterfaceInfoDTO dto)
|
public AjaxResult edit(@Validated @RequestBody UpdateGatewayInterfaceInfoDTO dto) {
|
||||||
{
|
|
||||||
return success(gatewayInterfaceInfoService.updateGatewayInterfaceInfoAndBindStrategy(dto));
|
return success(gatewayInterfaceInfoService.updateGatewayInterfaceInfoAndBindStrategy(dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("删除接口信息")
|
@ApiOperation("删除接口信息")
|
||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:remove')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:remove')")
|
||||||
@Log(title = "接口管理", businessType = BusinessType.DELETE)
|
@Log(title = "接口管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids)
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||||
{
|
|
||||||
return toAjax(gatewayInterfaceInfoService.deleteGatewayInterfaceInfoByIds(ids));
|
return toAjax(gatewayInterfaceInfoService.deleteGatewayInterfaceInfoByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("启用/停用接口信息")
|
@ApiOperation("启用/停用接口信息")
|
||||||
@Log(title = "启用/停用接口信息", businessType = BusinessType.UPDATE)
|
@Log(title = "启用/停用接口信息", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/status")
|
@PutMapping("/status")
|
||||||
public AjaxResult updateStatus(@Validated @RequestBody UpdateDataStatusDTO dto)
|
public AjaxResult updateStatus(@Validated @RequestBody UpdateDataStatusDTO dto) {
|
||||||
{
|
|
||||||
return toAjax(gatewayInterfaceInfoService.updateGatewayInterfaceInfoStatusByIds(dto.getIds(), GatewayDataStatus.getByCode(dto.getStatus())));
|
return toAjax(gatewayInterfaceInfoService.updateGatewayInterfaceInfoStatusByIds(dto.getIds(), GatewayDataStatus.getByCode(dto.getStatus())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,4 +79,10 @@ public class GatewayInterfaceInfo extends BaseEntity
|
|||||||
@ApiModelProperty("网关服务id")
|
@ApiModelProperty("网关服务id")
|
||||||
private Long serverId;
|
private Long serverId;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
|
private String mockStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock响应,json格式")
|
||||||
|
private String mockResponse;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,10 @@ public class InsertGatewayInterfaceInfoDTO {
|
|||||||
|
|
||||||
@ApiModelProperty("策略ID集合")
|
@ApiModelProperty("策略ID集合")
|
||||||
private List<Long> strategyIds;
|
private List<Long> strategyIds;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
|
private String mockStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock响应,json格式")
|
||||||
|
private String mockResponse;
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,10 @@ public class UpdateGatewayInterfaceInfoDTO {
|
|||||||
|
|
||||||
@ApiModelProperty("策略ID集合")
|
@ApiModelProperty("策略ID集合")
|
||||||
private List<Long> strategyIds;
|
private List<Long> strategyIds;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
|
private String mockStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock响应,json格式")
|
||||||
|
private String mockResponse;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ package com.sf.service.gateway.domain.vo;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.sf.common.annotation.Excel;
|
import com.sf.common.annotation.Excel;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
|
import com.sf.service.gateway.domain.GatewayServer;
|
||||||
|
import com.sf.service.gateway.domain.GatewayStrategy;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -10,10 +13,13 @@ import javax.validation.constraints.NotBlank;
|
|||||||
import javax.validation.constraints.Pattern;
|
import javax.validation.constraints.Pattern;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口信息详细展示
|
* 接口信息详细展示
|
||||||
*
|
*
|
||||||
* @author zoukun
|
* @author zoukun
|
||||||
* @date 2024-04-22
|
* @date 2024-04-22
|
||||||
*/
|
*/
|
||||||
@ -22,46 +28,64 @@ import java.util.List;
|
|||||||
public class GatewayInterfaceInfoDetailedVO {
|
public class GatewayInterfaceInfoDetailedVO {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** ID */
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
@ApiModelProperty("ID")
|
@ApiModelProperty("ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/** 接口名称 */
|
/**
|
||||||
|
* 接口名称
|
||||||
|
*/
|
||||||
@Excel(name = "接口名称")
|
@Excel(name = "接口名称")
|
||||||
@ApiModelProperty("接口名称")
|
@ApiModelProperty("接口名称")
|
||||||
private String interfaceName;
|
private String interfaceName;
|
||||||
|
|
||||||
/** api编码 */
|
/**
|
||||||
|
* api编码
|
||||||
|
*/
|
||||||
@Excel(name = "接口编码")
|
@Excel(name = "接口编码")
|
||||||
@ApiModelProperty("接口编码")
|
@ApiModelProperty("接口编码")
|
||||||
private String apiCode;
|
private String apiCode;
|
||||||
|
|
||||||
/** 接口路径 */
|
/**
|
||||||
|
* 接口路径
|
||||||
|
*/
|
||||||
@Excel(name = "接口路径")
|
@Excel(name = "接口路径")
|
||||||
@ApiModelProperty("接口名称")
|
@ApiModelProperty("接口名称")
|
||||||
private String interfacePath;
|
private String interfacePath;
|
||||||
|
|
||||||
/** 请求方式 */
|
/**
|
||||||
|
* 请求方式
|
||||||
|
*/
|
||||||
@Excel(name = "请求方式")
|
@Excel(name = "请求方式")
|
||||||
@ApiModelProperty("请求方式")
|
@ApiModelProperty("请求方式")
|
||||||
private String requestMethod;
|
private String requestMethod;
|
||||||
|
|
||||||
/** 接口描述 */
|
/**
|
||||||
|
* 接口描述
|
||||||
|
*/
|
||||||
@Excel(name = "接口描述")
|
@Excel(name = "接口描述")
|
||||||
@ApiModelProperty("接口描述")
|
@ApiModelProperty("接口描述")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
/** 接口版本 */
|
/**
|
||||||
|
* 接口版本
|
||||||
|
*/
|
||||||
@Excel(name = "接口版本")
|
@Excel(name = "接口版本")
|
||||||
@ApiModelProperty("接口版本")
|
@ApiModelProperty("接口版本")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
/** 接口状态(0停用 1启用) */
|
/**
|
||||||
|
* 接口状态(0停用 1启用)
|
||||||
|
*/
|
||||||
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
|
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
|
||||||
@ApiModelProperty("接口状态(0=停用,1=启用)")
|
@ApiModelProperty("接口状态(0=停用,1=启用)")
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 接口文档(文档地址) */
|
/**
|
||||||
|
* 接口文档(文档地址)
|
||||||
|
*/
|
||||||
@Excel(name = "接口文档", readConverterExp = "文档地址")
|
@Excel(name = "接口文档", readConverterExp = "文档地址")
|
||||||
@ApiModelProperty("接口文档(文档地址)")
|
@ApiModelProperty("接口文档(文档地址)")
|
||||||
private String document;
|
private String document;
|
||||||
@ -87,4 +111,36 @@ public class GatewayInterfaceInfoDetailedVO {
|
|||||||
@ApiModelProperty
|
@ApiModelProperty
|
||||||
private List<GatewayStrategyListVO> strategyList;
|
private List<GatewayStrategyListVO> strategyList;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
|
private String mockStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock响应,json格式")
|
||||||
|
private String mockResponse;
|
||||||
|
|
||||||
|
public static GatewayInterfaceInfoDetailedVO convert(GatewayInterfaceInfo gatewayInterfaceInfo
|
||||||
|
, GatewayServer gatewayServer
|
||||||
|
, List<GatewayStrategy> strategyList) {
|
||||||
|
GatewayInterfaceInfoDetailedVO vo = new GatewayInterfaceInfoDetailedVO();
|
||||||
|
vo.setId(gatewayInterfaceInfo.getId());
|
||||||
|
vo.setInterfaceName(gatewayInterfaceInfo.getInterfaceName());
|
||||||
|
vo.setApiCode(gatewayInterfaceInfo.getApiCode());
|
||||||
|
vo.setInterfacePath(gatewayInterfaceInfo.getInterfacePath());
|
||||||
|
vo.setRequestMethod(gatewayInterfaceInfo.getRequestMethod());
|
||||||
|
vo.setDescription(gatewayInterfaceInfo.getDescription());
|
||||||
|
vo.setVersion(gatewayInterfaceInfo.getVersion());
|
||||||
|
vo.setStatus(gatewayInterfaceInfo.getStatus());
|
||||||
|
vo.setDocument(gatewayInterfaceInfo.getDocument());
|
||||||
|
vo.setCreateTime(gatewayInterfaceInfo.getCreateTime());
|
||||||
|
vo.setUpdateTime(gatewayInterfaceInfo.getUpdateTime());
|
||||||
|
vo.setServerId(gatewayInterfaceInfo.getServerId());
|
||||||
|
vo.setServerName(gatewayServer.getServerName());
|
||||||
|
vo.setMockStatus(gatewayInterfaceInfo.getMockStatus());
|
||||||
|
vo.setMockResponse(gatewayInterfaceInfo.getMockResponse());
|
||||||
|
// 策略信息
|
||||||
|
List<GatewayStrategyListVO> strategyListVOList = strategyList.stream()
|
||||||
|
.map(GatewayStrategyListVO::convert)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
vo.setStrategyList(strategyListVOList);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,10 @@ package com.sf.service.gateway.domain.vo;
|
|||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.sf.common.annotation.Excel;
|
import com.sf.common.annotation.Excel;
|
||||||
import com.sf.common.core.domain.BaseEntity;
|
import com.sf.common.core.domain.BaseEntity;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
|
import com.sf.service.gateway.domain.GatewayRoute;
|
||||||
|
import com.sf.service.gateway.domain.GatewayServer;
|
||||||
|
import com.sf.service.gateway.enums.GatewayServiceModel;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -10,9 +14,11 @@ import lombok.Data;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口信息列表展示
|
* 接口信息列表展示
|
||||||
*
|
*
|
||||||
* @author zoukun
|
* @author zoukun
|
||||||
* @date 2024-04-22
|
* @date 2024-04-22
|
||||||
*/
|
*/
|
||||||
@ -21,46 +27,64 @@ import java.util.List;
|
|||||||
public class GatewayInterfaceInfoListVO {
|
public class GatewayInterfaceInfoListVO {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** ID */
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
@ApiModelProperty("ID")
|
@ApiModelProperty("ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/** 接口名称 */
|
/**
|
||||||
|
* 接口名称
|
||||||
|
*/
|
||||||
@Excel(name = "接口名称")
|
@Excel(name = "接口名称")
|
||||||
@ApiModelProperty("接口名称")
|
@ApiModelProperty("接口名称")
|
||||||
private String interfaceName;
|
private String interfaceName;
|
||||||
|
|
||||||
/** api编码 */
|
/**
|
||||||
|
* api编码
|
||||||
|
*/
|
||||||
@Excel(name = "接口编码")
|
@Excel(name = "接口编码")
|
||||||
@ApiModelProperty("接口编码")
|
@ApiModelProperty("接口编码")
|
||||||
private String apiCode;
|
private String apiCode;
|
||||||
|
|
||||||
/** 接口路径 */
|
/**
|
||||||
|
* 接口路径
|
||||||
|
*/
|
||||||
@Excel(name = "接口路径")
|
@Excel(name = "接口路径")
|
||||||
@ApiModelProperty("接口名称")
|
@ApiModelProperty("接口名称")
|
||||||
private String interfacePath;
|
private String interfacePath;
|
||||||
|
|
||||||
/** 请求方式 */
|
/**
|
||||||
|
* 请求方式
|
||||||
|
*/
|
||||||
@Excel(name = "请求方式")
|
@Excel(name = "请求方式")
|
||||||
@ApiModelProperty("请求方式")
|
@ApiModelProperty("请求方式")
|
||||||
private String requestMethod;
|
private String requestMethod;
|
||||||
|
|
||||||
/** 接口描述 */
|
/**
|
||||||
|
* 接口描述
|
||||||
|
*/
|
||||||
@Excel(name = "接口描述")
|
@Excel(name = "接口描述")
|
||||||
@ApiModelProperty("接口描述")
|
@ApiModelProperty("接口描述")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
/** 接口版本 */
|
/**
|
||||||
|
* 接口版本
|
||||||
|
*/
|
||||||
@Excel(name = "接口版本")
|
@Excel(name = "接口版本")
|
||||||
@ApiModelProperty("接口版本")
|
@ApiModelProperty("接口版本")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
/** 接口状态(0停用 1启用) */
|
/**
|
||||||
|
* 接口状态(0停用 1启用)
|
||||||
|
*/
|
||||||
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
|
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
|
||||||
@ApiModelProperty("接口状态(0=停用,1=启用)")
|
@ApiModelProperty("接口状态(0=停用,1=启用)")
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 接口文档(文档地址) */
|
/**
|
||||||
|
* 接口文档(文档地址)
|
||||||
|
*/
|
||||||
@Excel(name = "接口文档", readConverterExp = "文档地址")
|
@Excel(name = "接口文档", readConverterExp = "文档地址")
|
||||||
@ApiModelProperty("接口文档(文档地址)")
|
@ApiModelProperty("接口文档(文档地址)")
|
||||||
private String document;
|
private String document;
|
||||||
@ -71,7 +95,9 @@ public class GatewayInterfaceInfoListVO {
|
|||||||
@ApiModelProperty("响应时间(平均 ms)")
|
@ApiModelProperty("响应时间(平均 ms)")
|
||||||
private Long averageResponseTime;
|
private Long averageResponseTime;
|
||||||
|
|
||||||
/** 创建时间 */
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
@ -84,4 +110,28 @@ public class GatewayInterfaceInfoListVO {
|
|||||||
@ApiModelProperty
|
@ApiModelProperty
|
||||||
private List<GatewayStrategyListVO> strategyList;
|
private List<GatewayStrategyListVO> strategyList;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
|
private String mockStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock响应,json格式")
|
||||||
|
private String mockResponse;
|
||||||
|
|
||||||
|
public static GatewayInterfaceInfoListVO convert(GatewayInterfaceInfo info, GatewayServer gatewayServer) {
|
||||||
|
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
|
||||||
|
vo.setId(info.getId());
|
||||||
|
vo.setInterfaceName(info.getInterfaceName());
|
||||||
|
vo.setApiCode(info.getApiCode());
|
||||||
|
vo.setInterfacePath(info.getInterfacePath());
|
||||||
|
vo.setRequestMethod(info.getRequestMethod());
|
||||||
|
vo.setDescription(info.getDescription());
|
||||||
|
vo.setVersion(info.getVersion());
|
||||||
|
vo.setStatus(info.getStatus());
|
||||||
|
vo.setDocument(info.getDocument());
|
||||||
|
vo.setCreateTime(info.getCreateTime());
|
||||||
|
vo.setServerId(info.getServerId());
|
||||||
|
vo.setServerName(gatewayServer != null ? gatewayServer.getServerName() : EMPTY);
|
||||||
|
vo.setMockStatus(info.getMockStatus());
|
||||||
|
vo.setMockResponse(info.getMockResponse());
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,15 @@ package com.sf.service.gateway.domain.vo;
|
|||||||
|
|
||||||
import com.sf.common.annotation.Excel;
|
import com.sf.common.annotation.Excel;
|
||||||
import com.sf.common.core.domain.BaseEntity;
|
import com.sf.common.core.domain.BaseEntity;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
|
import com.sf.service.gateway.domain.GatewayServer;
|
||||||
|
import com.sf.service.gateway.domain.GatewayStrategy;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 策略管理对象 Gateway_strategy
|
* 策略管理对象 Gateway_strategy
|
||||||
@ -32,5 +37,13 @@ public class GatewayStrategyListVO {
|
|||||||
/** 策略状态(0停用 1启用) */
|
/** 策略状态(0停用 1启用) */
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
public static GatewayStrategyListVO convert(GatewayStrategy strategy) {
|
||||||
|
GatewayStrategyListVO vo = new GatewayStrategyListVO();
|
||||||
|
vo.setId(strategy.getId());
|
||||||
|
vo.setStrategyName(strategy.getStrategyName());
|
||||||
|
vo.setStrategyType(strategy.getStrategyType());
|
||||||
|
vo.setDescription(strategy.getDescription());
|
||||||
|
vo.setStatus(strategy.getStatus());
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,9 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
|
|||||||
apiConfig.setUri(api.getInterfacePath());
|
apiConfig.setUri(api.getInterfacePath());
|
||||||
apiConfig.setMethod(api.getRequestMethod());
|
apiConfig.setMethod(api.getRequestMethod());
|
||||||
apiConfig.setStrategy(currentApiStrategyList);
|
apiConfig.setStrategy(currentApiStrategyList);
|
||||||
|
if (GatewayDataStatus.ENABLE.getCode().equals(api.getMockStatus())){
|
||||||
|
apiConfig.setMockResponse(api.getMockResponse());
|
||||||
|
}
|
||||||
return apiConfig;
|
return apiConfig;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
sacService.setApiConfig(apiConfigList);
|
sacService.setApiConfig(apiConfigList);
|
||||||
|
@ -3,6 +3,7 @@ package com.sf.service.gateway.service.impl;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import apijson.JSON;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.sf.common.utils.*;
|
import com.sf.common.utils.*;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
@ -74,6 +75,7 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long insertGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
public Long insertGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||||
|
checkGatewayInterfaceInfoCanInsertOrUpdate(gatewayInterfaceInfo);
|
||||||
String appCode = AppUtils.getAppCodeFromRequestHeader();
|
String appCode = AppUtils.getAppCodeFromRequestHeader();
|
||||||
gatewayInterfaceInfo.setAppCode(appCode);
|
gatewayInterfaceInfo.setAppCode(appCode);
|
||||||
String username = SecurityUtils.getUsername();
|
String username = SecurityUtils.getUsername();
|
||||||
@ -91,18 +93,13 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkGatewayInterfaceInfoCanEnable(GatewayInterfaceInfo current) {
|
private void checkGatewayInterfaceInfoCanInsertOrUpdate(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||||
GatewayInterfaceInfo query = new GatewayInterfaceInfo();
|
if (GatewayDataStatus.ENABLE.getCode().equals(gatewayInterfaceInfo.getMockStatus())){
|
||||||
query.setStatus(GatewayDataStatus.ENABLE.getCode());
|
Assert.isTrue(JSON.isJSONObject(gatewayInterfaceInfo.getMockResponse()),"请输入正确格式的响应信息");
|
||||||
query.setAppCode(current.getAppCode());
|
|
||||||
query.setInterfacePath(current.getInterfacePath());
|
|
||||||
List<GatewayInterfaceInfo> infoList = gatewayInterfaceInfoMapper.selectGatewayInterfaceInfoList(query);
|
|
||||||
if (CollUtil.isNotEmpty(infoList)) {
|
|
||||||
Assert.isTrue(infoList.size() == 1,"该请求路径已存在启用的记录");
|
|
||||||
Assert.isTrue(infoList.get(0).getId().equals(current.getId()),"该请求路径已存在启用的记录");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改接口管理
|
* 修改接口管理
|
||||||
*
|
*
|
||||||
@ -111,6 +108,7 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||||
|
checkGatewayInterfaceInfoCanInsertOrUpdate(gatewayInterfaceInfo);
|
||||||
gatewayInterfaceInfo.setModified(SecurityUtils.getUsername());
|
gatewayInterfaceInfo.setModified(SecurityUtils.getUsername());
|
||||||
gatewayInterfaceInfo.setUpdateTime(DateUtils.getNowDate());
|
gatewayInterfaceInfo.setUpdateTime(DateUtils.getNowDate());
|
||||||
try {
|
try {
|
||||||
@ -158,10 +156,6 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
log.warn("Insufficient update conditions");
|
log.warn("Insufficient update conditions");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (GatewayDataStatus.ENABLE.equals(status)) {
|
|
||||||
List<GatewayInterfaceInfo> infoList = selectGatewayInterfaceInfoByIds(ids);
|
|
||||||
infoList.forEach(this::checkGatewayInterfaceInfoCanEnable);
|
|
||||||
}
|
|
||||||
return gatewayInterfaceInfoMapper.updateGatewayInterfaceInfoStatusByIds(ids, status.getCode());
|
return gatewayInterfaceInfoMapper.updateGatewayInterfaceInfoStatusByIds(ids, status.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +188,8 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
gatewayInterfaceInfo.setStatus(GatewayDataStatus.DISABLE.getCode());
|
gatewayInterfaceInfo.setStatus(GatewayDataStatus.DISABLE.getCode());
|
||||||
gatewayInterfaceInfo.setDocument(dto.getDocument());
|
gatewayInterfaceInfo.setDocument(dto.getDocument());
|
||||||
gatewayInterfaceInfo.setServerId(dto.getServerId());
|
gatewayInterfaceInfo.setServerId(dto.getServerId());
|
||||||
|
gatewayInterfaceInfo.setMockStatus(dto.getMockStatus());
|
||||||
|
gatewayInterfaceInfo.setMockResponse(dto.getMockResponse());
|
||||||
Long interfaceInfoId = insertGatewayInterfaceInfo(gatewayInterfaceInfo);
|
Long interfaceInfoId = insertGatewayInterfaceInfo(gatewayInterfaceInfo);
|
||||||
if (CollUtil.isNotEmpty(dto.getStrategyIds())) {
|
if (CollUtil.isNotEmpty(dto.getStrategyIds())) {
|
||||||
checkGatewayStrategyTypeCannotBeRepeated(dto.getStrategyIds());
|
checkGatewayStrategyTypeCannotBeRepeated(dto.getStrategyIds());
|
||||||
@ -218,6 +214,8 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
gatewayInterfaceInfo.setVersion(dto.getVersion());
|
gatewayInterfaceInfo.setVersion(dto.getVersion());
|
||||||
gatewayInterfaceInfo.setDocument(dto.getDocument());
|
gatewayInterfaceInfo.setDocument(dto.getDocument());
|
||||||
gatewayInterfaceInfo.setServerId(dto.getServerId());
|
gatewayInterfaceInfo.setServerId(dto.getServerId());
|
||||||
|
gatewayInterfaceInfo.setMockStatus(dto.getMockStatus());
|
||||||
|
gatewayInterfaceInfo.setMockResponse(dto.getMockResponse());
|
||||||
updateGatewayInterfaceInfo(gatewayInterfaceInfo);
|
updateGatewayInterfaceInfo(gatewayInterfaceInfo);
|
||||||
// 先删除
|
// 先删除
|
||||||
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(Collections.singleton(dto.getId()));
|
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(Collections.singleton(dto.getId()));
|
||||||
|
@ -19,13 +19,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="modified" column="modified" />
|
<result property="modified" column="modified" />
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
<result property="serverId" column="server_id" />
|
<result property="serverId" column="server_id" />
|
||||||
|
<result property="mockStatus" column="mock_status" />
|
||||||
|
<result property="mockResponse" column="mock_response" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectGatewayInterfaceInfoVo">
|
<sql id="selectGatewayInterfaceInfoVo">
|
||||||
select id, interface_name,api_code, interface_path, request_method,
|
select id, interface_name,api_code, interface_path, request_method,
|
||||||
description, version, status, document, created,
|
description, version, status, document, created,
|
||||||
create_time, modified, update_time ,
|
create_time, modified, update_time ,
|
||||||
server_id
|
server_id,mock_status,mock_response
|
||||||
from Gateway_interface_info
|
from Gateway_interface_info
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
@ -77,6 +79,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="created != null">created,</if>
|
<if test="created != null">created,</if>
|
||||||
<if test="modified != null">modified,</if>
|
<if test="modified != null">modified,</if>
|
||||||
<if test="serverId != null">server_id,</if>
|
<if test="serverId != null">server_id,</if>
|
||||||
|
<if test="mockStatus != null">mock_status,</if>
|
||||||
|
<if test="mockResponse != null">mock_response,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
|
<if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
|
||||||
@ -93,6 +97,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="created != null">#{created},</if>
|
<if test="created != null">#{created},</if>
|
||||||
<if test="modified != null">#{modified},</if>
|
<if test="modified != null">#{modified},</if>
|
||||||
<if test="serverId != null">#{serverId},</if>
|
<if test="serverId != null">#{serverId},</if>
|
||||||
|
<if test="mockStatus != null">#{mockStatus},</if>
|
||||||
|
<if test="mockResponse != null">#{mockResponse},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -110,6 +116,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="modified != null">modified = #{modified},</if>
|
<if test="modified != null">modified = #{modified},</if>
|
||||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
<if test="serverId != null">server_id = #{serverId},</if>
|
<if test="serverId != null">server_id = #{serverId},</if>
|
||||||
|
<if test="mockStatus != null">mock_status = #{mockStatus},</if>
|
||||||
|
<if test="mockResponse != null">mock_response = #{mockResponse},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user