refactor(消息管理): 初始化消息机器人数据

This commit is contained in:
guoyuqi 2023-09-06 19:18:19 +08:00 committed by 刘瑞斌
parent 9fb065f65f
commit b4dadd8806
4 changed files with 41 additions and 8 deletions

View File

@ -122,5 +122,10 @@ VALUES (uuid(), 'functional_default', '', 1, UNIX_TIMESTAMP() * 1000, UNIX_TIMES
INSERT INTO template_custom_field(id, field_id, template_id, required, pos, api_field_id, default_value)
VALUES(uuid(), (select id from custom_field where name = 'functional_priority'), (select id from template where name = 'functional_default'), 1, 0, NULL, NULL);
-- 初始化内置消息机器人
Insert into project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES (UUID_SHORT(), 'default_project', '站内信', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null);
Insert into project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES (UUID_SHORT(), 'default_project', '邮件', 'MAIL', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null);
-- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@Tag(name = "项目机器人管理")
@Tag(name = "项目管理-项目与权限-消息管理-机器人")
@RestController
@RequestMapping("/project/robot/")
public class ProjectRobotController {
@ -32,7 +32,7 @@ public class ProjectRobotController {
@PostMapping("/list/page")
@Operation(summary = "获取机器人列表")
@Operation(summary = "项目管理-项目与权限-消息管理-获取机器人列表")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ)
public Pager<List<ProjectRobot>> listResourcePools(@Validated @RequestBody ProjectRobotRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), true);
@ -40,7 +40,7 @@ public class ProjectRobotController {
}
@PostMapping("add")
@Operation(summary = "新增机器人管理")
@Operation(summary = "项目管理-项目与权限-消息管理-新增机器人")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_ADD)
public void add(@Validated({Created.class}) @RequestBody ProjectRobotDTO projectRobotDTO) {
ProjectRobot projectRobot = new ProjectRobot();
@ -53,7 +53,7 @@ public class ProjectRobotController {
}
@PostMapping("update")
@Operation(summary = "更新机器人")
@Operation(summary = "项目管理-项目与权限-消息管理-更新机器人")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_UPDATE)
public void update(@Validated({Updated.class}) @RequestBody ProjectRobotDTO projectRobotDTO) {
ProjectRobot projectRobot = new ProjectRobot();
@ -66,21 +66,21 @@ public class ProjectRobotController {
}
@GetMapping("get/{id}")
@Operation(summary = "获取机器人详情")
@Operation(summary = "项目管理-项目与权限-消息管理-获取机器人详情")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ)
public ProjectRobotDTO getDetail(@PathVariable(value = "id") String id) {
return projectRobotService.getDetail(id);
}
@GetMapping("delete/{id}")
@Operation(summary = "删除机器人")
@Operation(summary = "项目管理-项目与权限-消息管理-删除机器人")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_DELETE)
public void delete(@PathVariable(value = "id") String id) {
projectRobotService.delete(id);
}
@GetMapping("enable/{id}")
@Operation(summary = "禁用机器人")
@Operation(summary = "项目管理-项目与权限-消息管理-禁用机器人")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_UPDATE)
public void enable(@PathVariable(value = "id") String id) {
projectRobotService.enable(id, SessionUtils.getUserId(), System.currentTimeMillis());

View File

@ -1,5 +1,5 @@
package io.metersphere.project.enums;
public enum ProjectRobotPlatform {
DING_TALK, LARK, WE_COM, CUSTOM
DING_TALK, LARK, WE_COM, CUSTOM, IN_SITE, MAIL
}

View File

@ -0,0 +1,28 @@
package io.metersphere.project.service;
import io.metersphere.project.domain.ProjectRobotExample;
import io.metersphere.project.mapper.ProjectRobotMapper;
import io.metersphere.sdk.service.CleanupProjectResourceService;
import io.metersphere.sdk.util.LogUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
@Component
public class CleanupRobotResourceService implements CleanupProjectResourceService {
@Resource
private ProjectRobotMapper robotMapper;
@Override
public void deleteResources(String projectId) {
ProjectRobotExample projectExample = new ProjectRobotExample();
projectExample.createCriteria().andProjectIdEqualTo(projectId);
robotMapper.deleteByExample(projectExample);
LogUtils.info("删除当前项目[" + projectId + "]相关接口测试资源");
}
@Override
public void cleanReportResources(String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]相关接口测试报告资源");
}
}