diff --git a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java index 9cbaf90..51d33e3 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java +++ b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java @@ -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; @@ -44,15 +45,14 @@ import com.sf.common.core.page.TableDataInfo; /** * 接口管理Controller - * + * * @author zoukun * @date 2024-04-22 */ @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 list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo); Set serverIds = list.stream().map(GatewayInterfaceInfo::getServerId).collect(Collectors.toSet()); List serverList = gatewayServerService.selectGatewayServerByIds(serverIds); - Map serverIdAndNameMap = serverList.stream().collect(Collectors.toMap(GatewayServer::getId, GatewayServer::getServerName)); + Map serverMap = serverList.stream().collect(Collectors.toMap(GatewayServer::getId, Function.identity())); List 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 list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo); ExcelUtil util = new ExcelUtil(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 linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id)); GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId()); List 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 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,25 +119,22 @@ 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)); } @ApiOperation("删除接口信息") @PreAuthorize("@ss.hasPermi('gateway:interface:remove')") @Log(title = "接口管理", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { + @DeleteMapping("/{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()))); } diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java index 80c51d0..b2efc86 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java @@ -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; + } diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java index a975164..fb302c0 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java @@ -63,4 +63,10 @@ public class InsertGatewayInterfaceInfoDTO { @ApiModelProperty("策略ID集合") private List strategyIds; + + @ApiModelProperty("Mock状态(0=停用,1=启用)") + private String mockStatus; + + @ApiModelProperty("Mock响应,json格式") + private String mockResponse; } diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java index db40de3..aae57fa 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java @@ -66,4 +66,10 @@ public class UpdateGatewayInterfaceInfoDTO { @ApiModelProperty("策略ID集合") private List strategyIds; + + @ApiModelProperty("Mock状态(0=停用,1=启用)") + private String mockStatus; + + @ApiModelProperty("Mock响应,json格式") + private String mockResponse; } diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java index c7b51e9..eb13df6 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java @@ -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,10 +13,13 @@ 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; /** * 接口信息详细展示 - * + * * @author zoukun * @date 2024-04-22 */ @@ -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 strategyList; + @ApiModelProperty("Mock状态(0=停用,1=启用)") + private String mockStatus; + + @ApiModelProperty("Mock响应,json格式") + private String mockResponse; + + public static GatewayInterfaceInfoDetailedVO convert(GatewayInterfaceInfo gatewayInterfaceInfo + , GatewayServer gatewayServer + , List 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 strategyListVOList = strategyList.stream() + .map(GatewayStrategyListVO::convert) + .collect(Collectors.toList()); + vo.setStrategyList(strategyListVOList); + return vo; + } } diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java index f77d884..fb36b6b 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java @@ -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,9 +14,11 @@ import lombok.Data; import java.util.Date; import java.util.List; +import static org.apache.commons.lang3.StringUtils.EMPTY; + /** * 接口信息列表展示 - * + * * @author zoukun * @date 2024-04-22 */ @@ -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 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; + } } diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java index c72d47e..9b03830 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java @@ -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; + } } diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java index 3080167..f47816b 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java @@ -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); diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java index 746d002..26f0d2f 100644 --- a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java @@ -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 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 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())); diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml index df9b8a4..c83330d 100644 --- a/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml +++ b/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml @@ -19,13 +19,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + 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 @@ -77,6 +79,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" created, modified, server_id, + mock_status, + mock_response, #{interfaceName}, @@ -93,6 +97,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{created}, #{modified}, #{serverId}, + #{mockStatus}, + #{mockResponse}, @@ -110,6 +116,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" modified = #{modified}, update_time = #{updateTime}, server_id = #{serverId}, + mock_status = #{mockStatus}, + mock_response = #{mockResponse}, where id = #{id}