提交 05393b19 authored 作者: mry's avatar mry

fix(web): 将Example修改为Environment,优化了swaggerController

上级 e8bfada3
...@@ -2,8 +2,8 @@ package org.matrix.autotest.controller; ...@@ -2,8 +2,8 @@ package org.matrix.autotest.controller;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Example; import org.matrix.autotest.entity.Environment;
import org.matrix.autotest.service.ExampleService; import org.matrix.autotest.service.EnvironmentService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,14 +17,14 @@ import java.util.List; ...@@ -17,14 +17,14 @@ import java.util.List;
* @since 2022-01-07 * @since 2022-01-07
*/ */
@RestController @RestController
@RequestMapping("/examples") @RequestMapping("/environments")
@Api(tags = "对实例表example的基本操作") @Api(tags = "对实例表example的基本操作")
public class ExampleController { public class EnvironmentController {
private final ExampleService exampleService; private final EnvironmentService environmentService;
public ExampleController(ExampleService exampleService) { public EnvironmentController(EnvironmentService environmentService) {
this.exampleService = exampleService; this.environmentService = environmentService;
} }
/** /**
...@@ -34,8 +34,8 @@ public class ExampleController { ...@@ -34,8 +34,8 @@ public class ExampleController {
*/ */
@ApiOperation(value = "查询所有实例") @ApiOperation(value = "查询所有实例")
@GetMapping @GetMapping
public List<Example> findAllExample() { public List<Environment> findAllEnvironment() {
return exampleService.findAllExample(); return environmentService.findAllEnvironment();
} }
/** /**
...@@ -46,44 +46,44 @@ public class ExampleController { ...@@ -46,44 +46,44 @@ public class ExampleController {
*/ */
@ApiOperation(value = "根据id查询实例") @ApiOperation(value = "根据id查询实例")
@GetMapping("/{id}") @GetMapping("/{id}")
public Example findByIdExample(@PathVariable Integer id) { public Environment findByIdEnvironment(@PathVariable Integer id) {
return exampleService.findByIdExample(id); return environmentService.findByIdEnvironment(id);
} }
/** /**
* 添加实例 * 添加实例
* *
* @param example 实例 * @param environment 实例
* @return 添加的实例 * @return 添加的实例
*/ */
@ApiOperation(value = "添加实例") @ApiOperation(value = "添加实例")
@PostMapping @PostMapping
public Example insertExample(@RequestBody Example example) { public Environment insertEnvironment(@RequestBody Environment environment) {
return exampleService.insertExample(example); return environmentService.insertEnvironment(environment);
} }
/** /**
* 修改实例 * 修改实例
* *
* @param example 实例 * @param environment 实例
* @return 修改后的实例 * @return 修改后的实例
*/ */
@ApiOperation(value = "根据id修改实例") @ApiOperation(value = "根据id修改实例")
@PutMapping("/{id}") @PutMapping("/{id}")
public Example updateExample(@RequestBody Example example) { public Environment updateEnvironment(@RequestBody Environment environment) {
return exampleService.updateExample(example); return environmentService.updateEnvironment(environment);
} }
/** /**
* 删除实例 * 删除实例
* *
* @param example 实例 * @param environment 实例
* @return 删除的实例 * @return 删除的实例
*/ */
@ApiOperation(value = "根据id删除实例") @ApiOperation(value = "根据id删除实例")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public Example deleteExample(@RequestBody Example example) { public Environment deleteEnvironment(@RequestBody Environment environment){
return exampleService.deleteExample(example); return environmentService.deleteEnvironment(environment);
} }
} }
...@@ -2,7 +2,7 @@ package org.matrix.autotest.dao; ...@@ -2,7 +2,7 @@ package org.matrix.autotest.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.matrix.autotest.entity.Example; import org.matrix.autotest.entity.Environment;
/** /**
* <p> * <p>
...@@ -13,6 +13,6 @@ import org.matrix.autotest.entity.Example; ...@@ -13,6 +13,6 @@ import org.matrix.autotest.entity.Example;
* @since 2022-01-07 * @since 2022-01-07
*/ */
@Mapper @Mapper
public interface ExampleMapper extends BaseMapper<Example> { public interface EnvironmentMapper extends BaseMapper<Environment> {
} }
...@@ -21,8 +21,8 @@ import java.time.LocalDateTime; ...@@ -21,8 +21,8 @@ import java.time.LocalDateTime;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@ApiModel(value = "实例表") @ApiModel(value = "实例表")
@TableName(value = "example") @TableName(value = "environment")
public class Example { public class Environment {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
package org.matrix.autotest.service; package org.matrix.autotest.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.matrix.autotest.entity.Example; import org.matrix.autotest.entity.Environment;
import java.util.List; import java.util.List;
...@@ -13,13 +13,13 @@ import java.util.List; ...@@ -13,13 +13,13 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
public interface ExampleService extends IService<Example> { public interface EnvironmentService extends IService<Environment> {
/** /**
* 查询所有实例 * 查询所有实例
* *
* @return 实例 * @return 实例
*/ */
List<Example> findAllExample(); List<Environment> findAllEnvironment();
/** /**
* 根据id查询实例 * 根据id查询实例
...@@ -27,29 +27,29 @@ public interface ExampleService extends IService<Example> { ...@@ -27,29 +27,29 @@ public interface ExampleService extends IService<Example> {
* @param id 实例id * @param id 实例id
* @return 实例 * @return 实例
*/ */
Example findByIdExample(Integer id); Environment findByIdEnvironment(Integer id);
/** /**
* 添加实例 * 添加实例
* *
* @param example 实例 * @param environment 实例
* @return 添加的实例 * @return 添加的实例
*/ */
Example insertExample(Example example); Environment insertEnvironment(Environment environment);
/** /**
* 修改实例 * 修改实例
* *
* @param example 实例 * @param environment 实例
* @return 修改后的实例 * @return 修改后的实例
*/ */
Example updateExample(Example example); Environment updateEnvironment(Environment environment);
/** /**
* 删除实例 * 删除实例
* *
* @param example 实例 * @param environment 实例
* @return 删除的实例 * @return 删除的实例
*/ */
Example deleteExample(Example example); Environment deleteEnvironment(Environment environment);
} }
package org.matrix.autotest.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.autotest.dao.EnvironmentMapper;
import org.matrix.autotest.entity.Environment;
import org.matrix.autotest.service.EnvironmentService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 实例表,项目对应的环境实例,例如:实验室环境,开发环境等 服务实现类
* </p>
*
* @author mry
* @since 2022-01-07
*/
@Service
public class EnvironmentServiceImpl extends ServiceImpl<EnvironmentMapper, Environment> implements EnvironmentService {
private final EnvironmentMapper environmentMapper;
public EnvironmentServiceImpl(EnvironmentMapper environmentMapper) {
this.environmentMapper = environmentMapper;
}
@Override
public List<Environment> findAllEnvironment() {
return environmentMapper.selectList(null);
}
@Override
public Environment findByIdEnvironment(Integer id) {
return environmentMapper.selectById(id);
}
@Override
public Environment insertEnvironment(Environment environment) {
environmentMapper.insert(environment);
return environment;
}
@Override
public Environment updateEnvironment(Environment environment) {
environmentMapper.updateById(environment);
return environment;
}
@Override
public Environment deleteEnvironment(Environment environment) {
environmentMapper.deleteById(environment.getId());
return environment;
}
}
package org.matrix.autotest.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.autotest.dao.ExampleMapper;
import org.matrix.autotest.entity.Example;
import org.matrix.autotest.service.ExampleService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 实例表,项目对应的环境实例,例如:实验室环境,开发环境等 服务实现类
* </p>
*
* @author mry
* @since 2022-01-07
*/
@Service
public class ExampleServiceImpl extends ServiceImpl<ExampleMapper, Example> implements ExampleService {
private final ExampleMapper exampleMapper;
public ExampleServiceImpl(ExampleMapper exampleMapper) {
this.exampleMapper = exampleMapper;
}
@Override
public List<Example> findAllExample() {
return exampleMapper.selectList(null);
}
@Override
public Example findByIdExample(Integer id) {
return exampleMapper.selectById(id);
}
@Override
public Example insertExample(Example example) {
exampleMapper.insert(example);
return example;
}
@Override
public Example updateExample(Example example) {
exampleMapper.updateById(example);
return example;
}
@Override
public Example deleteExample(Example example) {
exampleMapper.deleteById(example.getId());
return example;
}
}
package org.matrix.autotest.SwaggerData; package org.matrix.autotest.swaggerData;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -48,6 +48,7 @@ public class SwaggerController { ...@@ -48,6 +48,7 @@ public class SwaggerController {
@GetMapping @GetMapping
public Object parameter(String url) { public Object parameter(String url) {
@SuppressWarnings("all")
List<String> list = new ArrayList(); List<String> list = new ArrayList();
//获得json字符串 //获得json字符串
String json = loadJson(url); String json = loadJson(url);
...@@ -58,6 +59,7 @@ public class SwaggerController { ...@@ -58,6 +59,7 @@ public class SwaggerController {
Object basePath = swaggerJson.get("basePath"); Object basePath = swaggerJson.get("basePath");
Object paths = swaggerJson.get("paths"); Object paths = swaggerJson.get("paths");
//将paths转成map集合 //将paths转成map集合
@SuppressWarnings("unchecked")
Map<String, String> pathsMaps = (Map<String, String>) paths; Map<String, String> pathsMaps = (Map<String, String>) paths;
//获取key //获取key
Set<String> methodUrls = pathsMaps.keySet(); Set<String> methodUrls = pathsMaps.keySet();
...@@ -68,17 +70,21 @@ public class SwaggerController { ...@@ -68,17 +70,21 @@ public class SwaggerController {
//通过JSON获取到methodUrl,用来获取methodUrl内部的信息 //通过JSON获取到methodUrl,用来获取methodUrl内部的信息
Object objMethodUrls = objPaths.get(methodUrl); Object objMethodUrls = objPaths.get(methodUrl);
JSONObject objUrlsJson = (JSONObject) objMethodUrls; JSONObject objUrlsJson = (JSONObject) objMethodUrls;
@SuppressWarnings("unchecked")
Map<String, String> objMethodUrlsMaps = (Map<String, String>) objMethodUrls; Map<String, String> objMethodUrlsMaps = (Map<String, String>) objMethodUrls;
Set<String> requests = objMethodUrlsMaps.keySet(); Set<String> requests = objMethodUrlsMaps.keySet();
for (String request : requests) { for (String request : requests) {
//拿到请求内部的信息 //拿到请求内部的信息
Object objRequest = objUrlsJson.get(request); Object objRequest = objUrlsJson.get(request);
@SuppressWarnings("unchecked")
Map<String, String> objRequestMaps = (Map<String, String>) objRequest; Map<String, String> objRequestMaps = (Map<String, String>) objRequest;
Object parameters = objRequestMaps.get("parameters"); Object parameters = objRequestMaps.get("parameters");
List<String> parameterAllList = new ArrayList<>(); List<String> parameterAllList = new ArrayList<>();
if (parameters != null) { if (parameters != null) {
@SuppressWarnings("all")
List<String> parameterLists = (List<String>) parameters; List<String> parameterLists = (List<String>) parameters;
for (Object parameterList : parameterLists) { for (Object parameterList : parameterLists) {
@SuppressWarnings("unchecked")
Map<String, String> parameterMaps = (Map<String, String>) parameterList; Map<String, String> parameterMaps = (Map<String, String>) parameterList;
String name = parameterMaps.get("name"); String name = parameterMaps.get("name");
String type = parameterMaps.get("type"); String type = parameterMaps.get("type");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论