fix(测试计划): 执行通知问题
--bug=1044741 --user=宋昌昌 【Jenkins插件】MS消息管理中配置了Jenkins执行成功/执行失败,给接收人是创建人发送通知失败 https://www.tapd.cn/55049933/s/1558376
This commit is contained in:
parent
fc46239b5b
commit
209c5a9e44
|
@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -43,6 +44,7 @@ public class BugLogService {
|
||||||
* @param files 文件
|
* @param files 文件
|
||||||
* @return 日志
|
* @return 日志
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public LogDTO addLog(BugEditRequest request, List<MultipartFile> files) {
|
public LogDTO addLog(BugEditRequest request, List<MultipartFile> files) {
|
||||||
LogDTO dto = new LogDTO(request.getProjectId(), null, null, null, OperationLogType.ADD.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, getPlatformTitle(request));
|
LogDTO dto = new LogDTO(request.getProjectId(), null, null, null, OperationLogType.ADD.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, getPlatformTitle(request));
|
||||||
dto.setHistory(true);
|
dto.setHistory(true);
|
||||||
|
@ -59,6 +61,7 @@ public class BugLogService {
|
||||||
* @param files 文件
|
* @param files 文件
|
||||||
* @return 日志
|
* @return 日志
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public LogDTO updateLog(BugEditRequest request, List<MultipartFile> files) {
|
public LogDTO updateLog(BugEditRequest request, List<MultipartFile> files) {
|
||||||
BugDTO history = getOriginalValue(request.getId());
|
BugDTO history = getOriginalValue(request.getId());
|
||||||
LogDTO dto = new LogDTO(request.getProjectId(), null, request.getId(), null, OperationLogType.UPDATE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, getPlatformTitle(request));
|
LogDTO dto = new LogDTO(request.getProjectId(), null, request.getId(), null, OperationLogType.UPDATE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, getPlatformTitle(request));
|
||||||
|
@ -76,6 +79,7 @@ public class BugLogService {
|
||||||
* @param id 缺陷ID
|
* @param id 缺陷ID
|
||||||
* @return 日志
|
* @return 日志
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public LogDTO deleteLog(String id) {
|
public LogDTO deleteLog(String id) {
|
||||||
Bug bug = bugMapper.selectByPrimaryKey(id);
|
Bug bug = bugMapper.selectByPrimaryKey(id);
|
||||||
if (bug != null) {
|
if (bug != null) {
|
||||||
|
@ -95,6 +99,7 @@ public class BugLogService {
|
||||||
* @param id 缺陷ID
|
* @param id 缺陷ID
|
||||||
* @return 日志
|
* @return 日志
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public LogDTO recoverLog(String id) {
|
public LogDTO recoverLog(String id) {
|
||||||
Bug bug = bugMapper.selectByPrimaryKey(id);
|
Bug bug = bugMapper.selectByPrimaryKey(id);
|
||||||
if (bug != null) {
|
if (bug != null) {
|
||||||
|
@ -146,10 +151,7 @@ public class BugLogService {
|
||||||
bugs.forEach(bug -> {
|
bugs.forEach(bug -> {
|
||||||
BugDTO originalBug = new BugDTO();
|
BugDTO originalBug = new BugDTO();
|
||||||
BeanUtils.copyBean(originalBug, bug);
|
BeanUtils.copyBean(originalBug, bug);
|
||||||
BugContent bugContent = bugContents.stream().filter(content -> StringUtils.equals(content.getBugId(), bug.getId())).findFirst().orElse(null);
|
bugContents.stream().filter(content -> StringUtils.equals(content.getBugId(), bug.getId())).findFirst().ifPresent(bugContent -> originalBug.setDescription(bugContent.getDescription()));
|
||||||
if (bugContent != null) {
|
|
||||||
originalBug.setDescription(bugContent.getDescription());
|
|
||||||
}
|
|
||||||
bugOriginalList.add(originalBug);
|
bugOriginalList.add(originalBug);
|
||||||
});
|
});
|
||||||
// 缺陷自定义字段
|
// 缺陷自定义字段
|
||||||
|
@ -162,7 +164,8 @@ public class BugLogService {
|
||||||
* @return 缺陷标题
|
* @return 缺陷标题
|
||||||
*/
|
*/
|
||||||
private String getPlatformTitle(BugEditRequest request) {
|
private String getPlatformTitle(BugEditRequest request) {
|
||||||
BugCustomFieldDTO platformTitle = request.getCustomFields().stream().filter(field -> StringUtils.equalsAny(field.getId(), "summary")).findFirst().get();
|
Optional<BugCustomFieldDTO> find = request.getCustomFields().stream().filter(field -> StringUtils.equalsAny(field.getId(), "summary", "title")).findFirst();
|
||||||
return StringUtils.isNotBlank(request.getTitle()) ? request.getTitle() : platformTitle.getValue();
|
BugCustomFieldDTO titleField = find.orElseGet(BugCustomFieldDTO::new);
|
||||||
|
return StringUtils.isNotBlank(request.getTitle()) ? request.getTitle() : titleField.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class BugNoticeService {
|
||||||
* @param request 请求参数
|
* @param request 请求参数
|
||||||
* @return 缺陷通知
|
* @return 缺陷通知
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public BugNoticeDTO getNoticeByRequest(BugEditRequest request) {
|
public BugNoticeDTO getNoticeByRequest(BugEditRequest request) {
|
||||||
// 获取状态选项, 处理人选项
|
// 获取状态选项, 处理人选项
|
||||||
Map<String, String> statusMap = getStatusMap(request.getProjectId());
|
Map<String, String> statusMap = getStatusMap(request.getProjectId());
|
||||||
|
@ -88,22 +89,7 @@ public class BugNoticeService {
|
||||||
if (bugDTO == null) {
|
if (bugDTO == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 构建通知对象
|
return buildNotice(bugDTO);
|
||||||
BugNoticeDTO notice = new BugNoticeDTO();
|
|
||||||
BeanUtils.copyBean(notice, bugDTO);
|
|
||||||
// 自定义字段解析{name: value}
|
|
||||||
if (CollectionUtils.isNotEmpty(bugDTO.getCustomFields())) {
|
|
||||||
List<OptionDTO> fields = new ArrayList<>();
|
|
||||||
bugDTO.getCustomFields().forEach(field -> {
|
|
||||||
// 其他自定义字段
|
|
||||||
OptionDTO fieldDTO = new OptionDTO();
|
|
||||||
fieldDTO.setId(field.getName());
|
|
||||||
fieldDTO.setName(field.getValue());
|
|
||||||
fields.add(fieldDTO);
|
|
||||||
});
|
|
||||||
notice.setFields(fields);
|
|
||||||
}
|
|
||||||
return notice;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,22 +102,7 @@ public class BugNoticeService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<BugNoticeDTO> notices = new ArrayList<>();
|
List<BugNoticeDTO> notices = new ArrayList<>();
|
||||||
bugs.forEach(bug -> {
|
bugs.forEach(bug -> notices.add(buildNotice(bug)));
|
||||||
BugNoticeDTO notice = new BugNoticeDTO();
|
|
||||||
BeanUtils.copyBean(notice, bug);
|
|
||||||
if (CollectionUtils.isNotEmpty(bug.getCustomFields())) {
|
|
||||||
List<OptionDTO> fields = new ArrayList<>();
|
|
||||||
bug.getCustomFields().forEach(field -> {
|
|
||||||
// 其他自定义字段
|
|
||||||
OptionDTO fieldDTO = new OptionDTO();
|
|
||||||
fieldDTO.setId(field.getName());
|
|
||||||
fieldDTO.setName(field.getValue());
|
|
||||||
fields.add(fieldDTO);
|
|
||||||
});
|
|
||||||
notice.setFields(fields);
|
|
||||||
}
|
|
||||||
notices.add(notice);
|
|
||||||
});
|
|
||||||
return notices;
|
return notices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +111,7 @@ public class BugNoticeService {
|
||||||
* @param request 批量请求参数
|
* @param request 批量请求参数
|
||||||
* @return 缺陷通知集合
|
* @return 缺陷通知集合
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public List<BugNoticeDTO> getBatchNoticeByRequest(BugBatchRequest request) {
|
public List<BugNoticeDTO> getBatchNoticeByRequest(BugBatchRequest request) {
|
||||||
List<String> batchIds = bugService.getBatchIdsByRequest(request);
|
List<String> batchIds = bugService.getBatchIdsByRequest(request);
|
||||||
return getNoticeByIds(batchIds);
|
return getNoticeByIds(batchIds);
|
||||||
|
@ -164,4 +136,28 @@ public class BugNoticeService {
|
||||||
List<SelectOption> handlerOption = bugCommonService.getHeaderHandlerOption(projectId);
|
List<SelectOption> handlerOption = bugCommonService.getHeaderHandlerOption(projectId);
|
||||||
return handlerOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
return handlerOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建通知对象
|
||||||
|
* @param bugDTO 缺陷DTO
|
||||||
|
* @return 通知对象
|
||||||
|
*/
|
||||||
|
private BugNoticeDTO buildNotice(BugDTO bugDTO) {
|
||||||
|
// 构建通知对象
|
||||||
|
BugNoticeDTO notice = new BugNoticeDTO();
|
||||||
|
BeanUtils.copyBean(notice, bugDTO);
|
||||||
|
// 自定义字段解析{name: value}
|
||||||
|
if (CollectionUtils.isNotEmpty(bugDTO.getCustomFields())) {
|
||||||
|
List<OptionDTO> fields = new ArrayList<>();
|
||||||
|
bugDTO.getCustomFields().forEach(field -> {
|
||||||
|
// 其他自定义字段
|
||||||
|
OptionDTO fieldDTO = new OptionDTO();
|
||||||
|
fieldDTO.setId(field.getName());
|
||||||
|
fieldDTO.setName(field.getValue());
|
||||||
|
fields.add(fieldDTO);
|
||||||
|
});
|
||||||
|
notice.setFields(fields);
|
||||||
|
}
|
||||||
|
return notice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package io.metersphere.system.dto.sdk;
|
package io.metersphere.system.dto.sdk;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class TestPlanMessageDTO {
|
public class TestPlanMessageDTO {
|
||||||
@Schema(description = "message.domain.test_plan_num")
|
@Schema(description = "message.domain.test_plan_num")
|
||||||
private String num;
|
private String num;
|
||||||
|
|
|
@ -280,6 +280,7 @@ public class TestPlanReportService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动生成报告 (计划 或者 组)
|
* 自动生成报告 (计划 或者 组)
|
||||||
|
*
|
||||||
* @param request 请求参数
|
* @param request 请求参数
|
||||||
* @param currentUser 当前用户
|
* @param currentUser 当前用户
|
||||||
*/
|
*/
|
||||||
|
@ -320,11 +321,11 @@ public class TestPlanReportService {
|
||||||
request.setTestPlanId(plan.getId());
|
request.setTestPlanId(plan.getId());
|
||||||
TestPlanReportGenPreParam genPreParam = buildReportGenParam(request, plan, prepareReportId);
|
TestPlanReportGenPreParam genPreParam = buildReportGenParam(request, plan, prepareReportId);
|
||||||
if (!manual) {
|
if (!manual) {
|
||||||
//不是手动保存的测试计划报告,不存储startTime
|
// 不是手动保存的测试计划报告,不存储startTime
|
||||||
genPreParam.setStartTime(null);
|
genPreParam.setStartTime(null);
|
||||||
}
|
}
|
||||||
genPreParam.setUseManual(manual);
|
genPreParam.setUseManual(manual);
|
||||||
//如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id
|
// 如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id
|
||||||
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
|
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
|
||||||
TestPlanReport preReport = preGenReport(prepareItemReportId, genPreParam, currentUser, childPlanIds, reportManualParam);
|
TestPlanReport preReport = preGenReport(prepareItemReportId, genPreParam, currentUser, childPlanIds, reportManualParam);
|
||||||
if (manual) {
|
if (manual) {
|
||||||
|
@ -469,7 +470,7 @@ public class TestPlanReportService {
|
||||||
reportApiCase.setTestPlanReportId(report.getId());
|
reportApiCase.setTestPlanReportId(report.getId());
|
||||||
reportApiCase.setTestPlanName(genParam.getTestPlanName());
|
reportApiCase.setTestPlanName(genParam.getTestPlanName());
|
||||||
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
|
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
|
||||||
//根据不超过数据库字段最大长度压缩模块名
|
// 根据不超过数据库字段最大长度压缩模块名
|
||||||
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
|
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
|
||||||
if (!genParam.getUseManual()) {
|
if (!genParam.getUseManual()) {
|
||||||
// 接口执行时才更新结果
|
// 接口执行时才更新结果
|
||||||
|
@ -499,7 +500,7 @@ public class TestPlanReportService {
|
||||||
reportApiScenario.setTestPlanReportId(report.getId());
|
reportApiScenario.setTestPlanReportId(report.getId());
|
||||||
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
|
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
|
||||||
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
|
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
|
||||||
//根据不超过数据库字段最大长度压缩模块名
|
// 根据不超过数据库字段最大长度压缩模块名
|
||||||
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
|
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
|
||||||
if (!genParam.getUseManual()) {
|
if (!genParam.getUseManual()) {
|
||||||
// 接口执行时才更新结果
|
// 接口执行时才更新结果
|
||||||
|
@ -578,7 +579,7 @@ public class TestPlanReportService {
|
||||||
|
|
||||||
// 发送计划执行通知
|
// 发送计划执行通知
|
||||||
if (!useManual) {
|
if (!useManual) {
|
||||||
testPlanSendNoticeService.sendExecuteNotice(planReport.getCreateUser(), planReport.getTestPlanId(), planReport.getProjectId(), planReport.getResultStatus(), planReport.getTriggerMode());
|
testPlanSendNoticeService.sendExecuteNotice(planReport.getCreateUser(), planReport.getTestPlanId(), planReport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,6 +702,7 @@ public class TestPlanReportService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回功能用例执行结果
|
* 返回功能用例执行结果
|
||||||
|
*
|
||||||
* @param executeHisId 执行历史ID
|
* @param executeHisId 执行历史ID
|
||||||
* @return 执行结果
|
* @return 执行结果
|
||||||
*/
|
*/
|
||||||
|
@ -925,7 +927,7 @@ public class TestPlanReportService {
|
||||||
if (CollectionUtils.isEmpty(uploadFileIds)) {
|
if (CollectionUtils.isEmpty(uploadFileIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//过滤已上传过的
|
// 过滤已上传过的
|
||||||
TestPlanReportAttachmentExample example = new TestPlanReportAttachmentExample();
|
TestPlanReportAttachmentExample example = new TestPlanReportAttachmentExample();
|
||||||
example.createCriteria().andTestPlanReportIdEqualTo(reportId).andFileIdIn(uploadFileIds).andSourceEqualTo(source);
|
example.createCriteria().andTestPlanReportIdEqualTo(reportId).andFileIdIn(uploadFileIds).andSourceEqualTo(source);
|
||||||
List<TestPlanReportAttachment> existReportMdFiles = testPlanReportAttachmentMapper.selectByExample(example);
|
List<TestPlanReportAttachment> existReportMdFiles = testPlanReportAttachmentMapper.selectByExample(example);
|
||||||
|
@ -1106,11 +1108,11 @@ public class TestPlanReportService {
|
||||||
example.createCriteria().andFileIdEqualTo(fileId);
|
example.createCriteria().andFileIdEqualTo(fileId);
|
||||||
List<TestPlanReportAttachment> reportAttachments = testPlanReportAttachmentMapper.selectByExample(example);
|
List<TestPlanReportAttachment> reportAttachments = testPlanReportAttachmentMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isEmpty(reportAttachments)) {
|
if (CollectionUtils.isEmpty(reportAttachments)) {
|
||||||
//在临时文件获取
|
// 在临时文件获取
|
||||||
fileName = getTempFileNameByFileId(fileId);
|
fileName = getTempFileNameByFileId(fileId);
|
||||||
bytes = commonFileService.downloadTempImg(fileId, fileName, compressed);
|
bytes = commonFileService.downloadTempImg(fileId, fileName, compressed);
|
||||||
} else {
|
} else {
|
||||||
//在正式目录获取
|
// 在正式目录获取
|
||||||
TestPlanReportAttachment attachment = reportAttachments.getFirst();
|
TestPlanReportAttachment attachment = reportAttachments.getFirst();
|
||||||
fileName = attachment.getFileName();
|
fileName = attachment.getFileName();
|
||||||
FileRequest fileRequest = buildPlanFileRequest(projectId, attachment.getTestPlanReportId(), attachment.getFileId(), attachment.getFileName());
|
FileRequest fileRequest = buildPlanFileRequest(projectId, attachment.getTestPlanReportId(), attachment.getFileId(), attachment.getFileName());
|
||||||
|
|
|
@ -4,27 +4,36 @@ import io.metersphere.functional.domain.FunctionalCase;
|
||||||
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
||||||
import io.metersphere.plan.domain.*;
|
import io.metersphere.plan.domain.*;
|
||||||
import io.metersphere.plan.dto.TestPlanDTO;
|
import io.metersphere.plan.dto.TestPlanDTO;
|
||||||
|
import io.metersphere.plan.dto.TestPlanShareInfo;
|
||||||
import io.metersphere.plan.dto.request.TestPlanCreateRequest;
|
import io.metersphere.plan.dto.request.TestPlanCreateRequest;
|
||||||
|
import io.metersphere.plan.dto.request.TestPlanReportShareRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanUpdateRequest;
|
import io.metersphere.plan.dto.request.TestPlanUpdateRequest;
|
||||||
import io.metersphere.plan.mapper.TestPlanConfigMapper;
|
import io.metersphere.plan.mapper.TestPlanConfigMapper;
|
||||||
import io.metersphere.plan.mapper.TestPlanFollowerMapper;
|
import io.metersphere.plan.mapper.TestPlanFollowerMapper;
|
||||||
import io.metersphere.plan.mapper.TestPlanMapper;
|
import io.metersphere.plan.mapper.TestPlanMapper;
|
||||||
|
import io.metersphere.project.domain.Project;
|
||||||
|
import io.metersphere.project.mapper.ProjectMapper;
|
||||||
import io.metersphere.sdk.constants.ResultStatus;
|
import io.metersphere.sdk.constants.ResultStatus;
|
||||||
import io.metersphere.sdk.constants.TaskTriggerMode;
|
import io.metersphere.sdk.constants.TaskTriggerMode;
|
||||||
import io.metersphere.sdk.constants.TestPlanConstants;
|
import io.metersphere.sdk.constants.TestPlanConstants;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
|
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
||||||
|
import io.metersphere.system.dto.sdk.BaseSystemConfigDTO;
|
||||||
|
import io.metersphere.system.dto.sdk.TestPlanMessageDTO;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
import io.metersphere.system.notice.NoticeModel;
|
import io.metersphere.system.notice.NoticeModel;
|
||||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||||
import io.metersphere.system.notice.utils.MessageTemplateUtils;
|
import io.metersphere.system.notice.utils.MessageTemplateUtils;
|
||||||
import io.metersphere.system.service.CommonNoticeSendService;
|
import io.metersphere.system.service.CommonNoticeSendService;
|
||||||
import io.metersphere.system.service.NoticeSendService;
|
import io.metersphere.system.service.NoticeSendService;
|
||||||
|
import io.metersphere.system.service.SystemParameterService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.beanutils.BeanMap;
|
import org.apache.commons.beanutils.BeanMap;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -51,6 +60,10 @@ public class TestPlanSendNoticeService {
|
||||||
private TestPlanConfigMapper testPlanConfigMapper;
|
private TestPlanConfigMapper testPlanConfigMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanFollowerMapper testPlanFollowerMapper;
|
private TestPlanFollowerMapper testPlanFollowerMapper;
|
||||||
|
@Autowired
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
@Resource
|
||||||
|
private TestPlanReportShareService testPlanReportShareService;
|
||||||
|
|
||||||
public void sendNoticeCase(List<String> relatedUsers, String userId, String caseId, String task, String event, String testPlanId) {
|
public void sendNoticeCase(List<String> relatedUsers, String userId, String caseId, String task, String event, String testPlanId) {
|
||||||
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey(caseId);
|
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey(caseId);
|
||||||
|
@ -91,12 +104,12 @@ public class TestPlanSendNoticeService {
|
||||||
|
|
||||||
|
|
||||||
public void batchSendNotice(String projectId, List<String> ids, User user, String event) {
|
public void batchSendNotice(String projectId, List<String> ids, User user, String event) {
|
||||||
int amount = 100;//每次读取的条数
|
int amount = 100;// 每次读取的条数
|
||||||
long roundTimes = Double.valueOf(Math.ceil((double) ids.size() / amount)).longValue();//循环的次数
|
long roundTimes = Double.valueOf(Math.ceil((double) ids.size() / amount)).longValue();// 循环的次数
|
||||||
for (int i = 0; i < (int) roundTimes; i++) {
|
for (int i = 0; i < (int) roundTimes; i++) {
|
||||||
int fromIndex = (i * amount);
|
int fromIndex = (i * amount);
|
||||||
int toIndex = ((i + 1) * amount);
|
int toIndex = ((i + 1) * amount);
|
||||||
if (i == roundTimes - 1 || toIndex > ids.size()) {//最后一次遍历
|
if (i == roundTimes - 1 || toIndex > ids.size()) {// 最后一次遍历
|
||||||
toIndex = ids.size();
|
toIndex = ids.size();
|
||||||
}
|
}
|
||||||
List<String> subList = ids.subList(fromIndex, toIndex);
|
List<String> subList = ids.subList(fromIndex, toIndex);
|
||||||
|
@ -130,7 +143,7 @@ public class TestPlanSendNoticeService {
|
||||||
return testPlans.stream().collect(Collectors.toMap(TestPlan::getId, testPlan -> testPlan));
|
return testPlans.stream().collect(Collectors.toMap(TestPlan::getId, testPlan -> testPlan));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public TestPlanDTO sendAddNotice(TestPlanCreateRequest request) {
|
public TestPlanDTO sendAddNotice(TestPlanCreateRequest request) {
|
||||||
TestPlanDTO dto = new TestPlanDTO();
|
TestPlanDTO dto = new TestPlanDTO();
|
||||||
BeanUtils.copyBean(dto, request);
|
BeanUtils.copyBean(dto, request);
|
||||||
|
@ -138,6 +151,7 @@ public class TestPlanSendNoticeService {
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public TestPlanDTO sendUpdateNotice(TestPlanUpdateRequest request) {
|
public TestPlanDTO sendUpdateNotice(TestPlanUpdateRequest request) {
|
||||||
TestPlanDTO dto = new TestPlanDTO();
|
TestPlanDTO dto = new TestPlanDTO();
|
||||||
BeanUtils.copyBean(dto, request);
|
BeanUtils.copyBean(dto, request);
|
||||||
|
@ -154,6 +168,7 @@ public class TestPlanSendNoticeService {
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public TestPlanDTO sendDeleteNotice(String id) {
|
public TestPlanDTO sendDeleteNotice(String id) {
|
||||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(id);
|
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(id);
|
||||||
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(id);
|
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(id);
|
||||||
|
@ -173,34 +188,74 @@ public class TestPlanSendNoticeService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报告汇总-计划执行结束通知
|
* 报告汇总-计划执行结束通知
|
||||||
|
*
|
||||||
* @param currentUser 当前用户
|
* @param currentUser 当前用户
|
||||||
* @param planId 计划ID
|
* @param planId 计划ID
|
||||||
* @param projectId 项目ID
|
* @param report 报告
|
||||||
* @param executeResult 执行结果
|
|
||||||
*/
|
*/
|
||||||
@Async
|
@Async
|
||||||
public void sendExecuteNotice(String currentUser, String planId, String projectId, String executeResult, String triggerMode) {
|
public void sendExecuteNotice(String currentUser, String planId, TestPlanReport report) {
|
||||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
||||||
if (testPlan != null) {
|
if (testPlan != null) {
|
||||||
User user = userMapper.selectByPrimaryKey(currentUser);
|
User user = userMapper.selectByPrimaryKey(currentUser);
|
||||||
setLanguage(user.getLanguage());
|
setLanguage(user.getLanguage());
|
||||||
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
||||||
String template = defaultTemplateMap.get(StringUtils.equals(executeResult, ResultStatus.SUCCESS.name()) ?
|
String template = defaultTemplateMap.get(StringUtils.equals(report.getResultStatus(), ResultStatus.SUCCESS.name()) ?
|
||||||
NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED);
|
NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED);
|
||||||
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
||||||
String subject = defaultSubjectMap.get(StringUtils.equals(executeResult, ResultStatus.SUCCESS.name()) ?
|
String subject = defaultSubjectMap.get(StringUtils.equals(report.getResultStatus(), ResultStatus.SUCCESS.name()) ?
|
||||||
NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED);
|
NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED);
|
||||||
Map<String, Object> paramMap = new HashMap<>(4);
|
TestPlanMessageDTO messageDTO = buildMessageNotice(planId, report, currentUser);
|
||||||
|
BeanMap beanMap = new BeanMap(messageDTO);
|
||||||
|
Map paramMap = new HashMap<>(beanMap);
|
||||||
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName());
|
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName());
|
||||||
paramMap.put("name", testPlan.getName());
|
paramMap.put("name", testPlan.getName());
|
||||||
paramMap.put("projectId", projectId);
|
paramMap.put("projectId", report.getProjectId());
|
||||||
paramMap.put("id", planId);
|
paramMap.put("id", planId);
|
||||||
paramMap.put("Language", user.getLanguage());
|
paramMap.put("Language", user.getLanguage());
|
||||||
|
paramMap.put("createUser", testPlan.getCreateUser());
|
||||||
NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false)
|
NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false)
|
||||||
.context(template).subject(subject).paramMap(paramMap).event(StringUtils.equals(executeResult, ResultStatus.SUCCESS.name()) ?
|
.context(template).subject(subject).paramMap(paramMap).event(StringUtils.equals(report.getResultStatus(), ResultStatus.SUCCESS.name()) ?
|
||||||
NoticeConstants.Event.EXECUTE_SUCCESSFUL : NoticeConstants.Event.EXECUTE_FAILED).build();
|
NoticeConstants.Event.EXECUTE_SUCCESSFUL : NoticeConstants.Event.EXECUTE_FAILED).build();
|
||||||
noticeSendService.send(StringUtils.equals(TaskTriggerMode.API.name(), triggerMode) ?
|
noticeSendService.send(StringUtils.equals(TaskTriggerMode.API.name(), report.getTriggerMode()) ?
|
||||||
NoticeConstants.TaskType.JENKINS_TASK : NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel);
|
NoticeConstants.TaskType.JENKINS_TASK : NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建计划消息通知对象
|
||||||
|
*
|
||||||
|
* @param planId 计划ID
|
||||||
|
* @param report 报告
|
||||||
|
* @param currentUser 当前用户
|
||||||
|
* @return 计划消息通知对象
|
||||||
|
*/
|
||||||
|
private TestPlanMessageDTO buildMessageNotice(String planId, TestPlanReport report, String currentUser) {
|
||||||
|
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
||||||
|
// 报告URL
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(testPlan.getProjectId());
|
||||||
|
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||||
|
assert systemParameterService != null;
|
||||||
|
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||||
|
String reportUrl = baseSystemConfigDTO.getUrl() + "/#/test-plan/testPlanReportDetail?id=%s&type=%s&orgId=%s&pId=%s";
|
||||||
|
reportUrl = String.format(reportUrl, report.getId(), report.getIntegrated() ? TestPlanConstants.TEST_PLAN_TYPE_GROUP : TestPlanConstants.TEST_PLAN_TYPE_PLAN,
|
||||||
|
project.getOrganizationId(), project.getId());
|
||||||
|
// 报告分享URL
|
||||||
|
TestPlanReportShareRequest shareRequest = new TestPlanReportShareRequest();
|
||||||
|
shareRequest.setReportId(report.getId());
|
||||||
|
shareRequest.setProjectId(project.getId());
|
||||||
|
shareRequest.setShareType("TEST_PLAN_SHARE_REPORT");
|
||||||
|
TestPlanShareInfo shareInfo = testPlanReportShareService.gen(shareRequest, currentUser);
|
||||||
|
String reportShareUrl = baseSystemConfigDTO.getUrl() + "/#/share/shareReportTestPlan?type=" +
|
||||||
|
(report.getIntegrated() ? TestPlanConstants.TEST_PLAN_TYPE_GROUP : TestPlanConstants.TEST_PLAN_TYPE_PLAN) + "shareId=" + shareInfo.getId();
|
||||||
|
return TestPlanMessageDTO.builder()
|
||||||
|
.num(testPlan.getNum().toString()).name(testPlan.getName()).status(testPlan.getStatus()).type(testPlan.getType()).tags(testPlan.getTags())
|
||||||
|
.createUser(testPlan.getCreateUser()).createTime(testPlan.getCreateTime()).updateUser(testPlan.getUpdateUser()).updateTime(testPlan.getUpdateTime())
|
||||||
|
.plannedStartTime(testPlan.getPlannedStartTime()).plannedEndTime(testPlan.getPlannedEndTime())
|
||||||
|
.actualStartTime(testPlan.getActualStartTime()).actualEndTime(testPlan.getActualEndTime())
|
||||||
|
.description(testPlan.getDescription()).reportName(report.getName()).reportUrl(reportUrl).reportShareUrl(reportShareUrl)
|
||||||
|
.startTime(report.getStartTime()).endTime(report.getEndTime()).execStatus(report.getExecStatus()).resultStatus(report.getResultStatus())
|
||||||
|
.passRate(report.getPassRate()).passThreshold(report.getPassThreshold()).executeRate(report.getExecuteRate())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue