Commit 7cbbdd2f authored by 黎博's avatar 黎博

新增模块相关接口

parent 57f0575a
package cn.qg.holmes.controller.auto; package cn.qg.holmes.controller.auto;
import cn.qg.holmes.common.JsonResult; import cn.qg.holmes.common.JsonResult;
import cn.qg.holmes.entity.auto.AutoModule;
import cn.qg.holmes.service.auto.AutoModuleService; import cn.qg.holmes.service.auto.AutoModuleService;
import cn.qg.holmes.service.auto.ProjectService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.HashMap;
import org.springframework.web.bind.annotation.RestController; import java.util.Map;
/** /**
* 接口自动化模块controller * 接口自动化模块controller
...@@ -20,8 +25,72 @@ public class AutoModuleController { ...@@ -20,8 +25,72 @@ public class AutoModuleController {
@Autowired @Autowired
AutoModuleService autoModuleService; AutoModuleService autoModuleService;
@Autowired
ProjectService projectService;
/**
* 获取接口自动化模块列表
* @param pageNum 第几页
* @param pageSize 每页第几个
* @return
*/
@GetMapping("/list") @GetMapping("/list")
public JsonResult getAutoModuleList(Integer pageNum, Integer pageSize) { public JsonResult getAutoModuleList(Integer pageNum, Integer pageSize) {
return null; IPage<AutoModule> autoModuleIPage = new Page<>(pageNum, pageSize);
IPage<AutoModule> autoModuleEntity = autoModuleService.page(autoModuleIPage);
Map<String, Object> map = new HashMap<>();
map.put("total", autoModuleEntity.getTotal());
map.put("list", autoModuleEntity.getRecords());
return JsonResult.buildSuccessResult(map);
}
/**
* 新增模块
* @param autoModule AutoModule实体类
* @return
*/
@PostMapping("/add")
public JsonResult addAutoModule(@RequestBody AutoModule autoModule) {
QueryWrapper<AutoModule> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", autoModule.getName());
if (projectService.getById(autoModule.getProjectId()) == null) {
return JsonResult.buildErrorStateResult("所选项目不存在!", false);
} else if (autoModuleService.getOne(queryWrapper) != null) {
return JsonResult.buildErrorStateResult("模块已存在!", false);
} else {
return JsonResult.buildSuccessResult(autoModuleService.save(autoModule));
}
}
/**
* 修改模块
* @param autoModule AutoModule实体类
* @return
*/
@PostMapping("/modify")
public JsonResult editAutoModule(@RequestBody AutoModule autoModule) {
QueryWrapper<AutoModule> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", autoModule.getName());
queryWrapper.ne("id", autoModule.getId());
if (autoModuleService.getById(autoModule.getId()) == null) {
return JsonResult.buildErrorStateResult("模块不存在!", false);
} else if (autoModuleService.getOne(queryWrapper) != null) {
return JsonResult.buildErrorStateResult("该模块名已存在!", false);
} else {
return JsonResult.buildSuccessResult(autoModuleService.updateById(autoModule));
}
}
/**
* 删除模块
* @param moduleId 模块id
*/
@GetMapping("/delete")
public JsonResult deleteAutoModule(@RequestParam Integer moduleId) {
if (autoModuleService.getById(moduleId) == null) {
return JsonResult.buildErrorStateResult("模块不存在", false);
} else {
return JsonResult.buildSuccessResult(autoModuleService.removeById(moduleId));
}
} }
} }
...@@ -20,6 +20,7 @@ public class AutoModule { ...@@ -20,6 +20,7 @@ public class AutoModule {
private String name; private String name;
private String description; private String description;
private String domain; private String domain;
private Integer projectId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime; private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment