refactor(消息管理): 补充消息管理接口内容

This commit is contained in:
guoyuqi 2023-09-27 14:20:13 +08:00 committed by fit2-zhao
parent fb5fec0966
commit 1a9d36534a
4 changed files with 50 additions and 19 deletions

View File

@ -21,6 +21,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
@ -42,7 +43,7 @@ public class NoticeMessageTaskController {
@GetMapping("message/task/get/{projectId}")
@Operation(summary = "项目管理-项目与权限-消息管理-消息设置-获取消息设置")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_ADD)
public List<MessageTaskDTO> getMessageList(@PathVariable String projectId) {
public List<MessageTaskDTO> getMessageList(@PathVariable String projectId) throws IOException {
return noticeMessageTaskService.getMessageList(projectId);
}

View File

@ -19,13 +19,13 @@ public class ProjectRobotDTO {
@NotBlank(message = "{project_robot.name.not_blank}", groups = {Created.class, Updated.class})
private String name;
@Schema(description = "所属平台(飞书,钉钉,企业微信,自定义)", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(description = "所属平台(飞书:LARK,钉钉:DING_TALK,企业微信:WE_COM,自定义:CUSTOM, 站内信:IN_SITE, 邮件:MAIL", requiredMode = Schema.RequiredMode.REQUIRED)
private String platform;
@Schema(description = "webhook", requiredMode = Schema.RequiredMode.REQUIRED)
private String webhook;
@Schema(description = "钉钉自定义和内部")
@Schema(description = "钉钉机器人的种类: 自定义:CUSTOM, 企业内部:ENTERPRISE")
private String type;
@Schema(description = "钉钉AppKey")

View File

@ -279,21 +279,17 @@ public class NoticeMessageTaskService {
* @param projectId 项目ID
* @return List<MessageTaskDTO>
*/
public List<MessageTaskDTO> getMessageList(String projectId) {
public List<MessageTaskDTO> getMessageList(String projectId) throws IOException {
checkProjectExist(projectId);
//获取返回数据结构
StringBuilder jsonStr = new StringBuilder();
InputStream inputStream = getClass().getResourceAsStream("/message_task.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
try {
while ((line = reader.readLine()) != null) {
jsonStr.append(line);
}
reader.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
List<MessageTaskDTO> messageTaskDTOList = JSON.parseArray(jsonStr.toString(), MessageTaskDTO.class);
//查询数据
MessageTaskExample messageTaskExample = new MessageTaskExample();

View File

@ -86,6 +86,9 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
messageTaskRequest.setRobotId("test_message_robot2");
messageTaskRequest.setEnable(true);
messageTaskRequest.setTemplate("发送消息测试");
messageTaskRequest.setUseDefaultTemplate(true);
messageTaskRequest.setSubject("发送消息测试标题");
messageTaskRequest.setUseDefaultTemplate(true);
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
@ -300,8 +303,9 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
List<String> userIds = new ArrayList<>();
userIds.add("CREATE_USER");
userIds.add("FOLLOW_PEOPLE");
userIds.add(NoticeConstants.RelatedUser.CREATE_USER);
userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE);
userIds.add(NoticeConstants.RelatedUser.OPERATOR);
messageTaskRequest.setReceiverIds(userIds);
messageTaskRequest.setRobotId("test_message_robot2");
messageTaskRequest.setEnable(true);
@ -326,8 +330,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
List<String> userIds = new ArrayList<>();
userIds.add("CREATE_USER");
userIds.add("FOLLOW_PEOPLE");
userIds.add(NoticeConstants.RelatedUser.CREATE_USER);
userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE);
userIds.add("project-message-user-5");
messageTaskRequest.setReceiverIds(userIds);
messageTaskRequest.setRobotId("test_message_robot2");
@ -353,8 +357,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
List<String> userIds = new ArrayList<>();
userIds.add("CREATE_USER");
userIds.add("FOLLOW_PEOPLE");
userIds.add(NoticeConstants.RelatedUser.CREATE_USER);
userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE);
userIds.add("project-message-user-6");
userIds.add("project-message-user-del");
messageTaskRequest.setReceiverIds(userIds);
@ -375,14 +379,44 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
@Test
@Order(14)
public void updateMessageTaskCheckSpecialUserThreeSuccess() throws Exception {
MessageTaskRequest messageTaskRequest = new MessageTaskRequest();
messageTaskRequest.setProjectId("project-message-test");
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
List<String> userIds = new ArrayList<>();
userIds.add(NoticeConstants.RelatedUser.CREATE_USER);
userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE);
userIds.add("project-message-user-6");
messageTaskRequest.setReceiverIds(userIds);
messageTaskRequest.setRobotId("test_message_robot2");
messageTaskRequest.setEnable(false);
messageTaskRequest.setTemplate("发送消息测试");
messageTaskRequest.setSubject("发送消息测试标题");
messageTaskRequest.setUseDefaultTemplate(false);
messageTaskRequest.setUseDefaultSubject(false);
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(messageTaskRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
Assertions.assertEquals(100200, resultHolder.getCode());
}
@Test
@Order(15)
public void closeMessageTaskSuccess() throws Exception {
MessageTaskRequest messageTaskRequest = new MessageTaskRequest();
messageTaskRequest.setProjectId("project-message-test");
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
List<String> userIds = new ArrayList<>();
userIds.add("CREATE_USER");
userIds.add("FOLLOW_PEOPLE");
userIds.add(NoticeConstants.RelatedUser.CREATE_USER);
userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE);
messageTaskRequest.setReceiverIds(userIds);
messageTaskRequest.setRobotId("test_message_robot2");
messageTaskRequest.setEnable(false);