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