refactor(接口测试): 优化接口涉及的通知
This commit is contained in:
parent
7b5b1bcca8
commit
c68f66f9e5
|
@ -435,3 +435,13 @@ no_permission_to_resource=无操作资源的权限
|
|||
api_scenario_circular_reference_error=场景存在循环引用
|
||||
|
||||
api_import_url_is_exist=导入的URL已存在
|
||||
report.status.success=成功
|
||||
report.status.error=失败
|
||||
report.status.pending=未执行
|
||||
report.status.fake_error=误报
|
||||
|
||||
api_definition.status.ongoing=进行中
|
||||
api_definition.status.completed=已完成
|
||||
api_definition.status.abandoned=已废弃
|
||||
api_definition.status.continuous=连调中
|
||||
|
||||
|
|
|
@ -441,3 +441,12 @@ tags_size_large_than=The number of tags cannot exceed 10
|
|||
no_permission_to_resource=No permission to access the resource
|
||||
api_scenario_circular_reference_error=There are circular references to the scenario
|
||||
api_import_url_is_exist=The imported URL already exists
|
||||
report.status.success=Success
|
||||
report.status.error=Error
|
||||
report.status.pending=Pending
|
||||
report.status.fake_error=Fake error
|
||||
|
||||
api_definition.status.ongoing=Underway
|
||||
api_definition.status.completed=Completed
|
||||
api_definition.status.abandoned=Abandoned
|
||||
api_definition.status.continuous=Continuous
|
|
@ -410,3 +410,11 @@ no_permission_to_resource=没有权限访问该资源
|
|||
api_scenario_circular_reference_error=场景存在循环引用
|
||||
|
||||
api_import_url_is_exist=导入的URL已存在
|
||||
report.status.success=成功
|
||||
report.status.error=失败
|
||||
report.status.pending=未执行
|
||||
report.status.fake_error=误报
|
||||
api_definition.status.ongoing=进行中
|
||||
api_definition.status.completed=已完成
|
||||
api_definition.status.abandoned=已废弃
|
||||
api_definition.status.continuous=连调中
|
|
@ -409,3 +409,12 @@ no_permission_to_resource=無權限訪問資源
|
|||
api_scenario_circular_reference_error=場景存在循環引用
|
||||
|
||||
api_import_url_is_exist=导入URL已存在
|
||||
report.status.success=成功
|
||||
report.status.error=失败
|
||||
report.status.pending=未执行
|
||||
report.status.fake_error=誤報
|
||||
|
||||
api_definition.status.ongoing=進行中
|
||||
api_definition.status.completed=已完成
|
||||
api_definition.status.abandoned=已作廢
|
||||
api_definition.status.continuous=持續中
|
|
@ -331,6 +331,7 @@ message.domain.createTime=创建时间
|
|||
message.domain.updateTime=更新时间
|
||||
message.domain.deleteTime=删除时间
|
||||
#接口定义和用例
|
||||
message.domain.id=ID
|
||||
message.domain.protocol=接口协议
|
||||
message.domain.method=http协议类型
|
||||
message.domain.path=http协议路径/其它协议则为空
|
||||
|
@ -540,3 +541,5 @@ env_info_all=环境信息(总).json
|
|||
custom_function_already_exist= 脚本名称已存在
|
||||
permission.project_custom_function.name=公共脚本
|
||||
permission.project_custom_function.execute=测试
|
||||
|
||||
message.domain.report.name=报告名称
|
|
@ -368,6 +368,7 @@ message.domain.update_time=Update time
|
|||
message.domain.delete_time=Delete time
|
||||
message.domain.triggerMode=Trigger mode
|
||||
#接口定义和case
|
||||
message.domain.id=ID
|
||||
message.domain.protocol=Interface Protocol
|
||||
message.domain.method=Http protocol type
|
||||
message.domain.path=Http protocol path/other protocols are empty
|
||||
|
@ -579,3 +580,5 @@ env_info_all=All environment info.json
|
|||
custom_function_already_exist= custom function name already exist
|
||||
permission.project_custom_function.name=Common script
|
||||
permission.project_custom_function.execute=Test
|
||||
|
||||
message.domain.report.name=Report name
|
|
@ -367,6 +367,7 @@ message.domain.updateTime=更新时间
|
|||
message.domain.deleteTime=删除时间
|
||||
message.domain.triggerMode=触发方式
|
||||
#接口定义和用例
|
||||
message.domain.id=ID
|
||||
message.domain.protocol=接口协议
|
||||
message.domain.method=http协议类型
|
||||
message.domain.path=http协议路径/其它协议则为空
|
||||
|
@ -578,3 +579,5 @@ env_info_all=环境信息(总).json
|
|||
custom_function_already_exist= 脚本名称已存在
|
||||
permission.project_custom_function.name=公共脚本
|
||||
permission.project_custom_function.execute=测试
|
||||
|
||||
message.domain.report.name=报告名称
|
|
@ -368,6 +368,7 @@ message.domain.updateTime=更新時間
|
|||
message.domain.deleteTime=刪除時間
|
||||
message.domain.triggerMode=觸發方式
|
||||
#接口定義和用例
|
||||
message.domain.id=ID
|
||||
message.domain.protocol=介面協定
|
||||
message.domain.method=http協定類型
|
||||
message.domain.path=http協定路徑/其它協定則為空
|
||||
|
@ -578,3 +579,5 @@ env_info_all=環境信息(总).json
|
|||
custom_function_already_exist= 腳本名稱已存在
|
||||
permission.project_custom_function.name=公共腳本
|
||||
permission.project_custom_function.execute=測試
|
||||
|
||||
message.domain.report.name=報告名稱
|
|
@ -79,7 +79,6 @@ public class ApiDefinitionController {
|
|||
@Operation(summary = "接口测试-接口管理-批量更新接口定义")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_definition")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getBatchEditApiDTO(#request)", targetClass = ApiDefinitionNoticeService.class)
|
||||
public void batchUpdate(@Validated @RequestBody ApiDefinitionBatchUpdateRequest request) {
|
||||
apiDefinitionService.batchUpdate(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -141,7 +140,7 @@ public class ApiDefinitionController {
|
|||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.moveToGcLog(#id)", msClass = ApiDefinitionLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_definition")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getEditApiDTO(#id)", targetClass = ApiDefinitionNoticeService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getDeleteApiDTO(#id)", targetClass = ApiDefinitionNoticeService.class)
|
||||
public void deleteToGc(@PathVariable String id, @RequestParam(required = false) boolean deleteAllVersion) {
|
||||
apiDefinitionService.deleteToGc(id, deleteAllVersion, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -150,7 +149,6 @@ public class ApiDefinitionController {
|
|||
@Operation(summary = "接口测试-接口管理-批量删除接口定义到回收站")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_definition")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchEditApiDTO(#request)", targetClass = ApiDefinitionNoticeService.class)
|
||||
public void batchDeleteToGc(@Validated @RequestBody ApiDefinitionBatchDeleteRequest request) {
|
||||
apiDefinitionService.batchDeleteToGc(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.api.dto.definition.ApiReportDTO;
|
|||
import io.metersphere.api.dto.definition.ApiReportDetailDTO;
|
||||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||
import io.metersphere.api.dto.report.ApiReportListDTO;
|
||||
import io.metersphere.api.service.definition.ApiReportNoticeService;
|
||||
import io.metersphere.api.service.ApiReportShareService;
|
||||
import io.metersphere.api.service.definition.ApiReportLogService;
|
||||
import io.metersphere.api.service.definition.ApiReportService;
|
||||
|
@ -15,6 +16,8 @@ import io.metersphere.sdk.constants.PermissionConstants;
|
|||
import io.metersphere.sdk.domain.ShareInfo;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.notice.annotation.SendNotice;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
|
@ -63,6 +66,7 @@ public class ApiReportController {
|
|||
@CheckOwner(resourceId = "#id", resourceType = "api_report")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_DELETE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.deleteLog(#id)", msClass = ApiReportLogService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_REPORT_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getDto(#id)", targetClass = ApiReportNoticeService.class)
|
||||
public void delete(@PathVariable String id) {
|
||||
apiReportService.delete(id, SessionUtils.getUserId());
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "接口测试-接口管理-接口用例-新增")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD)
|
||||
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = ApiTestCaseLogService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_CREATE, target = "#targetClass.getCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_CREATE, target = "#targetClass.addCaseDto(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
public ApiTestCase add(@Validated @RequestBody ApiTestCaseAddRequest request) {
|
||||
return apiTestCaseService.addCase(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -171,7 +171,6 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "接口测试-接口管理-接口用例-批量移动到回收站")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_DELETE, target = "#targetClass.getBatchEditApiCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
public void deleteToGcByParam(@RequestBody ApiTestCaseBatchRequest request) {
|
||||
apiTestCaseService.batchMoveGc(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -180,7 +179,6 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "接口测试-接口管理-接口用例-批量编辑")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_DELETE, target = "#targetClass.getBatchEditApiCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
public void batchUpdate(@Validated @RequestBody ApiCaseBatchEditRequest request) {
|
||||
apiTestCaseService.batchEdit(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ public class ApiScenarioBatchOperationController {
|
|||
@Operation(summary = "接口测试-接口场景批量操作-批量编辑")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_SCENARIO_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getBatchOptionScenarios(#request)", targetClass = ApiScenarioNoticeService.class)
|
||||
public void batchUpdate(@Validated @RequestBody ApiScenarioBatchEditRequest request) {
|
||||
apiValidateService.validateApiMenuInProject(request.getProjectId(), ApiResource.PROJECT.name());
|
||||
apiScenarioService.batchEdit(request, SessionUtils.getUserId());
|
||||
|
@ -52,7 +51,6 @@ public class ApiScenarioBatchOperationController {
|
|||
@Operation(summary = "接口测试-接口场景批量操作-回收站列表-批量删除")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_DELETE)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_SCENARIO_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchOptionScenarios(#request)", targetClass = ApiScenarioNoticeService.class)
|
||||
public ApiScenarioBatchOperationResponse deleteFromGc(@Validated @RequestBody ApiScenarioBatchRequest request) {
|
||||
apiValidateService.validateApiMenuInProject(request.getProjectId(), ApiResource.PROJECT.name());
|
||||
return apiScenarioService.batchGCOperation(request, true, new LogInsertModule(SessionUtils.getUserId(), "/api/scenario/batch-operation/delete-gc", HttpMethodConstants.POST.name()));
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ApiScenarioController {
|
|||
@Operation(summary = "接口测试-接口场景管理-创建场景")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_ADD)
|
||||
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = ApiScenarioLogService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_SCENARIO_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getScenarioDTO(#request)", targetClass = ApiScenarioNoticeService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_SCENARIO_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.addScenarioDTO(#request)", targetClass = ApiScenarioNoticeService.class)
|
||||
public ApiScenario add(@Validated @RequestBody ApiScenarioAddRequest request) {
|
||||
return apiScenarioService.add(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -149,7 +149,6 @@ public class ApiScenarioController {
|
|||
return apiScenarioService.getStepResourceInfo(resourceId, resourceType);
|
||||
}
|
||||
|
||||
//需求补充:回收站里的相关操作都不需要发通知
|
||||
@GetMapping("/recover/{id}")
|
||||
@Operation(summary = "接口测试-接口场景管理-恢复场景")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_DELETE)
|
||||
|
@ -217,7 +216,6 @@ public class ApiScenarioController {
|
|||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.scheduleLog(#request.getScenarioId())", msClass = ApiScenarioLogService.class)
|
||||
@CheckOwner(resourceId = "#scenarioId", resourceType = "api_scenario")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.SCHEDULE_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getScheduleNotice(#request)", targetClass = ApiScenarioNoticeService.class)
|
||||
public void deleteScheduleConfig(@PathVariable String scenarioId) {
|
||||
apiValidateService.validateApiMenuInProject(scenarioId, ApiResource.API_SCENARIO.name());
|
||||
apiScenarioService.deleteScheduleConfig(scenarioId);
|
||||
|
|
|
@ -9,11 +9,14 @@ import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
|||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
|
||||
import io.metersphere.api.service.ApiReportShareService;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioReportLogService;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioReportNoticeService;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioReportService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.domain.ShareInfo;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.notice.annotation.SendNotice;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
|
@ -62,6 +65,7 @@ public class ApiScenarioReportController {
|
|||
@CheckOwner(resourceId = "#id", resourceType = "api_scenario_report")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_DELETE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.deleteLog(#id)", msClass = ApiScenarioReportLogService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_REPORT_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getDto(#id)", targetClass = ApiScenarioReportNoticeService.class)
|
||||
public void delete(@PathVariable String id) {
|
||||
apiScenarioReportService.delete(id, SessionUtils.getUserId());
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
|||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||
import io.metersphere.api.dto.definition.ApiReportStepDTO;
|
||||
import io.metersphere.api.dto.report.ReportDTO;
|
||||
import io.metersphere.system.dto.sdk.ApiReportMessageDTO;
|
||||
import io.metersphere.system.dto.taskcenter.TaskCenterDTO;
|
||||
import io.metersphere.system.dto.taskcenter.request.TaskCenterBatchRequest;
|
||||
import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest;
|
||||
|
@ -38,4 +39,6 @@ public interface ExtApiReportMapper {
|
|||
List<ReportDTO> selectByIds(@Param("ids") List<String> ids);
|
||||
|
||||
void updateApiCaseStatus(@Param("ids") List<String> ids);
|
||||
|
||||
List<ApiReportMessageDTO> getNoticeList(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
|
|
@ -254,5 +254,16 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getNoticeList" resultType="io.metersphere.system.dto.sdk.ApiReportMessageDTO">
|
||||
select id , name
|
||||
from api_report
|
||||
<if test="ids != null and ids.size() > 0">
|
||||
where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
|||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||
import io.metersphere.api.dto.report.ReportDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO;
|
||||
import io.metersphere.system.dto.sdk.ApiReportMessageDTO;
|
||||
import io.metersphere.system.dto.taskcenter.TaskCenterDTO;
|
||||
import io.metersphere.system.dto.taskcenter.request.TaskCenterBatchRequest;
|
||||
import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest;
|
||||
|
@ -51,4 +52,6 @@ public interface ExtApiScenarioReportMapper {
|
|||
void updateApiScenario(List<String> ids);
|
||||
|
||||
List<ApiScenarioReportStepDTO> selectStepDeatilByReportId(String id);
|
||||
|
||||
List<ApiReportMessageDTO> getNoticeList(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
|
|
@ -236,6 +236,15 @@
|
|||
from api_scenario_report_detail
|
||||
where api_scenario_report_detail.report_id = #{reportId}
|
||||
</select>
|
||||
<select id="getNoticeList" resultType="io.metersphere.system.dto.sdk.ApiReportMessageDTO">
|
||||
select id ,name from api_scenario_report
|
||||
<if test="ids != null and ids.size() > 0">
|
||||
where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<sql id="filters">
|
||||
<if test="${filter} != null and ${filter}.size() > 0">
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
import io.metersphere.api.constants.ApiDefinitionStatus;
|
||||
import io.metersphere.api.constants.ApiScenarioStatus;
|
||||
import io.metersphere.api.domain.ApiReport;
|
||||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
|
@ -18,6 +20,7 @@ import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
|
|||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.BaseSystemConfigDTO;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
|
@ -32,6 +35,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
|
@ -62,7 +66,7 @@ public class ApiReportSendNoticeService {
|
|||
assert systemParameterService != null;
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
BeanMap beanMap;
|
||||
String event;
|
||||
String event = null;
|
||||
ApiReportShareService shareService = CommonBeanFactory.getBean(ApiReportShareService.class);
|
||||
ApiReportShareRequest shareRequest = new ApiReportShareRequest();
|
||||
shareRequest.setReportId(noticeDTO.getReportId());
|
||||
|
@ -83,7 +87,7 @@ public class ApiReportSendNoticeService {
|
|||
event = NoticeConstants.Event.SCENARIO_EXECUTE_SUCCESSFUL;
|
||||
} else if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ApiReportStatus.FAKE_ERROR.name())) {
|
||||
event = NoticeConstants.Event.SCENARIO_EXECUTE_FAKE_ERROR;
|
||||
} else {
|
||||
} else if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ApiReportStatus.ERROR.name())) {
|
||||
event = NoticeConstants.Event.SCENARIO_EXECUTE_FAILED;
|
||||
}
|
||||
shareUrl = String.format(shareUrl, "shareReportScenario");
|
||||
|
@ -101,7 +105,7 @@ public class ApiReportSendNoticeService {
|
|||
event = NoticeConstants.Event.CASE_EXECUTE_SUCCESSFUL;
|
||||
} else if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ApiReportStatus.FAKE_ERROR.name())) {
|
||||
event = NoticeConstants.Event.CASE_EXECUTE_FAKE_ERROR;
|
||||
} else {
|
||||
} else if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ApiReportStatus.ERROR.name())){
|
||||
event = NoticeConstants.Event.CASE_EXECUTE_FAILED;
|
||||
}
|
||||
shareUrl = String.format(shareUrl, "shareReportCase");
|
||||
|
@ -112,13 +116,36 @@ public class ApiReportSendNoticeService {
|
|||
|
||||
Map paramMap = new HashMap<>(beanMap);
|
||||
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user != null ? user.getName() : "");
|
||||
paramMap.put("status", noticeDTO.getReportStatus());
|
||||
// TODO 是否需要国际化 根据状态判断给不同的key
|
||||
String status = paramMap.containsKey("status") ? paramMap.get("status").toString() : null;
|
||||
if (StringUtils.isNotBlank(status)) {
|
||||
if (List.of(ApiScenarioStatus.UNDERWAY.name(), ApiDefinitionStatus.PROCESSING.name()).contains(status)) {
|
||||
status = Translator.get("api_definition.status.ongoing");
|
||||
} else if (List.of(ApiScenarioStatus.COMPLETED.name(), ApiDefinitionStatus.DONE.name()).contains(status)){
|
||||
status = Translator.get("api_definition.status.completed");
|
||||
} else if (StringUtils.equals(ApiScenarioStatus.DEPRECATED.name(), status)){
|
||||
status = Translator.get("api_definition.status.abandoned");
|
||||
} else if (StringUtils.equals(ApiDefinitionStatus.DEBUGGING.name(), status)){
|
||||
status = Translator.get("api_definition.status.continuous");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String reportStatus = report.getStatus();
|
||||
if (StringUtils.endsWithIgnoreCase(reportStatus, ApiReportStatus.SUCCESS.name())) {
|
||||
reportStatus = Translator.get("report.status.success");
|
||||
} else if (StringUtils.endsWithIgnoreCase(reportStatus, ApiReportStatus.FAKE_ERROR.name())) {
|
||||
reportStatus = Translator.get("report.status.fake_error");
|
||||
} else {
|
||||
reportStatus = Translator.get("report.status.error");
|
||||
}
|
||||
|
||||
paramMap.put("status", status);
|
||||
paramMap.put("reportName", report.getName());
|
||||
paramMap.put("startTime", report.getStartTime());
|
||||
paramMap.put("endTime", report.getEndTime());
|
||||
paramMap.put("requestDuration", report.getRequestDuration());
|
||||
paramMap.put("reportStatus", report.getStatus());
|
||||
paramMap.put("reportStatus", reportStatus);
|
||||
paramMap.put("errorCount", report.getErrorCount());
|
||||
paramMap.put("fakeErrorCount", report.getFakeErrorCount());
|
||||
paramMap.put("pendingCount", report.getPendingCount());
|
||||
|
|
|
@ -360,7 +360,7 @@ public class ApiDefinitionImportUtilService {
|
|||
operationLogs.add(dto);
|
||||
|
||||
ApiDefinitionCaseDTO apiDefinitionCaseDTO = new ApiDefinitionCaseDTO();
|
||||
BeanUtils.copyBean(apiDefinitionCaseDTO, t);
|
||||
BeanUtils.copyBean(apiDefinitionCaseDTO, apiDefinitionDTO);
|
||||
createLists.add(apiDefinitionCaseDTO);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,14 +3,16 @@ package io.metersphere.api.service.definition;
|
|||
import io.metersphere.api.domain.ApiDefinition;
|
||||
import io.metersphere.api.domain.ApiDefinitionExample;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionAddRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionBatchRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionUpdateRequest;
|
||||
import io.metersphere.api.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.api.mapper.ExtApiDefinitionMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.ApiDefinitionCaseDTO;
|
||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -18,15 +20,16 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ApiDefinitionNoticeService {
|
||||
|
||||
@Resource
|
||||
private ExtApiDefinitionMapper extApiDefinitionMapper;
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
|
||||
public ApiDefinitionCaseDTO getApiDTO(ApiDefinitionAddRequest request) {
|
||||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
|
@ -38,58 +41,33 @@ public class ApiDefinitionNoticeService {
|
|||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(request.getId());
|
||||
BeanUtils.copyBean(caseDTO, apiDefinition);
|
||||
BeanUtils.copyBean(caseDTO, request);
|
||||
return caseDTO;
|
||||
}
|
||||
|
||||
public List<ApiDefinitionCaseDTO> getBatchEditApiDTO(ApiDefinitionBatchRequest request) {
|
||||
List<String> ids = this.doSelectIds(request, request.getProjectId(), request.getProtocol(), false);
|
||||
return handleBatchNotice(ids);
|
||||
public ApiDefinitionCaseDTO getDeleteApiDTO(String id) {
|
||||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||
BeanUtils.copyBean(caseDTO, apiDefinition);
|
||||
return caseDTO;
|
||||
}
|
||||
|
||||
public List<ApiDefinitionCaseDTO> getEditApiDTO(String id) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(id);
|
||||
return handleBatchNotice(ids);
|
||||
}
|
||||
|
||||
private List<ApiDefinitionCaseDTO> handleBatchNotice(List<String> ids) {
|
||||
List<ApiDefinitionCaseDTO> dtoList = new ArrayList<>();
|
||||
public void batchSendNotice(List<String> ids, String userId, String projectId, String event) {
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
SubListUtils.dealForSubList(ids, 100, (subList) -> {
|
||||
detailApiData(subList, dtoList);
|
||||
});
|
||||
}
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
private void detailApiData(List<String> ids, List<ApiDefinitionCaseDTO> dtoList) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
example.createCriteria().andIdIn(subList);
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||
Map<String, ApiDefinition> apiDefinitionMap = apiDefinitions.stream().collect(Collectors.toMap(ApiDefinition::getId, a -> a));
|
||||
ids.forEach(id -> {
|
||||
ApiDefinition api = apiDefinitionMap.get(id);
|
||||
List<ApiDefinitionCaseDTO> noticeLists = apiDefinitions.stream()
|
||||
.map(apiDefinition -> {
|
||||
ApiDefinitionCaseDTO apiDefinitionCaseDTO = new ApiDefinitionCaseDTO();
|
||||
BeanUtils.copyBean(apiDefinitionCaseDTO, api);
|
||||
dtoList.add(apiDefinitionCaseDTO);
|
||||
BeanUtils.copyBean(apiDefinitionCaseDTO, apiDefinition);
|
||||
return apiDefinitionCaseDTO;
|
||||
})
|
||||
.toList();
|
||||
List<Map> resources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(noticeLists), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, event, resources, user, projectId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public <T> List<String> doSelectIds(T dto, String projectId, String protocol, boolean deleted) {
|
||||
TableBatchProcessDTO request = (TableBatchProcessDTO) dto;
|
||||
if (request.isSelectAll()) {
|
||||
List<String> ids = extApiDefinitionMapper.getIds(request, projectId, protocol, deleted);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
ids.removeAll(request.getExcludeIds());
|
||||
}
|
||||
ids.addAll(request.getSelectIds());
|
||||
return ids.stream().distinct().toList();
|
||||
} else {
|
||||
request.getSelectIds().removeAll(request.getExcludeIds());
|
||||
return request.getSelectIds();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
|
|||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.OperationHistoryService;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
|
@ -134,7 +135,8 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
private OperationLogBlobMapper operationLogBlobMapper;
|
||||
@Resource
|
||||
private ApiExecuteService apiExecuteService;
|
||||
private static final int MAX_TAG_SIZE = 10;
|
||||
@Resource
|
||||
private ApiDefinitionNoticeService apiDefinitionNoticeService;
|
||||
|
||||
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, String userId) {
|
||||
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request, userId);
|
||||
|
@ -324,6 +326,8 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
apiDefinitionExample.createCriteria().andIdIn(ids);
|
||||
apiDefinitionMapper.updateByExampleSelective(apiDefinition, apiDefinitionExample);
|
||||
}
|
||||
//发送通知
|
||||
apiDefinitionNoticeService.batchSendNotice(ids, userId, request.getProjectId(), NoticeConstants.Event.UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -649,6 +653,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
// 记录删除到回收站的日志, 单条注解记录
|
||||
if (isBatch) {
|
||||
apiDefinitionLogService.batchDelLog(delApiIds, userId, projectId);
|
||||
apiDefinitionNoticeService.batchSendNotice(delApiIds, userId, projectId, NoticeConstants.Event.DELETE);
|
||||
}
|
||||
extApiDefinitionMapper.batchDeleteByRefId(subRefIds, userId, projectId);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package io.metersphere.api.service.definition;
|
||||
|
||||
import io.metersphere.api.domain.ApiReport;
|
||||
import io.metersphere.api.mapper.ApiReportMapper;
|
||||
import io.metersphere.api.mapper.ExtApiReportMapper;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.ApiReportMessageDTO;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ApiReportNoticeService {
|
||||
|
||||
@Resource
|
||||
private ApiReportMapper apiReportMapper;
|
||||
@Resource
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
@Resource
|
||||
private ExtApiReportMapper extApiReportMapper;
|
||||
|
||||
public ApiReportMessageDTO getDto(String id) {
|
||||
ApiReport apiReport = apiReportMapper.selectByPrimaryKey(id);
|
||||
ApiReportMessageDTO reportMessageDTO = new ApiReportMessageDTO();
|
||||
reportMessageDTO.setId(apiReport.getId());
|
||||
reportMessageDTO.setName(apiReport.getName());
|
||||
return reportMessageDTO;
|
||||
}
|
||||
|
||||
public void batchSendNotice(List<String> ids, User user, String projectId, String event) {
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
SubListUtils.dealForSubList(ids, 100, (subList) -> {
|
||||
List<ApiReportMessageDTO> noticeLists = extApiReportMapper.getNoticeList(subList);
|
||||
List<Map> resources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(noticeLists), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_REPORT_TASK, event, resources, user, projectId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,8 +16,10 @@ import io.metersphere.sdk.mapper.EnvironmentMapper;
|
|||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -64,6 +66,8 @@ public class ApiReportService {
|
|||
private EnvironmentMapper environmentMapper;
|
||||
@Resource
|
||||
private EnvironmentGroupMapper environmentGroupMapper;
|
||||
@Resource
|
||||
private ApiReportNoticeService apiReportNoticeService;
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
|
@ -151,6 +155,7 @@ public class ApiReportService {
|
|||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
SubListUtils.dealForSubList(ids, 500, subList -> {
|
||||
ApiReportExample example = new ApiReportExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
|
@ -161,6 +166,7 @@ public class ApiReportService {
|
|||
apiReportMapper.updateByExampleSelective(apiReport, example);
|
||||
//TODO 记录日志
|
||||
apiReportLogService.batchDeleteLog(subList, userId, request.getProjectId());
|
||||
apiReportNoticeService.batchSendNotice(subList, user, request.getProjectId(), NoticeConstants.Event.DELETE);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,34 +3,37 @@ package io.metersphere.api.service.definition;
|
|||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.domain.ApiTestCaseExample;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseBatchRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseUpdateRequest;
|
||||
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.ApiDefinitionCaseDTO;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ApiTestCaseNoticeService {
|
||||
|
||||
@Resource
|
||||
private ApiTestCaseService apiTestCaseService;
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
|
||||
public ApiDefinitionCaseDTO getCaseDTO(ApiTestCaseAddRequest request) {
|
||||
public ApiDefinitionCaseDTO addCaseDto(ApiTestCaseAddRequest request) {
|
||||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
BeanUtils.copyBean(caseDTO, request);
|
||||
caseDTO.setCaseName(request.getName());
|
||||
caseDTO.setCaseStatus(request.getStatus());
|
||||
caseDTO.setCaseCreateUser(null);
|
||||
caseDTO.setCaseUpdateUser(null);
|
||||
return caseDTO;
|
||||
}
|
||||
|
||||
|
@ -38,7 +41,6 @@ public class ApiTestCaseNoticeService {
|
|||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(request.getId());
|
||||
BeanUtils.copyBean(caseDTO, testCase);
|
||||
BeanUtils.copyBean(caseDTO, request);
|
||||
return caseDTO;
|
||||
}
|
||||
|
||||
|
@ -46,40 +48,26 @@ public class ApiTestCaseNoticeService {
|
|||
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(id);
|
||||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
BeanUtils.copyBean(caseDTO, testCase);
|
||||
caseDTO.setName(null);
|
||||
caseDTO.setStatus(null);
|
||||
caseDTO.setCaseCreateTime(testCase.getCreateTime());
|
||||
caseDTO.setCaseUpdateTime(testCase.getUpdateTime());
|
||||
caseDTO.setCaseCreateUser(testCase.getCreateUser());
|
||||
caseDTO.setCaseUpdateUser(testCase.getUpdateUser());
|
||||
caseDTO.setCaseName(testCase.getName());
|
||||
caseDTO.setCaseStatus(testCase.getStatus());
|
||||
return caseDTO;
|
||||
}
|
||||
|
||||
|
||||
private List<ApiDefinitionCaseDTO> handleBatchNotice(List<String> ids) {
|
||||
List<ApiDefinitionCaseDTO> dtoList = new ArrayList<>();
|
||||
public void batchSendNotice(List<String> ids, String userId, String projectId, String event) {
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
SubListUtils.dealForSubList(ids, 500, subList -> {
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
SubListUtils.dealForSubList(ids, 100, (subList) -> {
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
List<ApiTestCase> caseList = apiTestCaseMapper.selectByExample(example);
|
||||
caseList.forEach(apiTestCase -> {
|
||||
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||
List<ApiDefinitionCaseDTO> noticeLists = apiTestCases.stream()
|
||||
.map(apiTestCase -> {
|
||||
ApiDefinitionCaseDTO apiDefinitionCaseDTO = new ApiDefinitionCaseDTO();
|
||||
apiDefinitionCaseDTO.setCaseName(apiTestCase.getName());
|
||||
apiDefinitionCaseDTO.setProjectId(apiTestCase.getProjectId());
|
||||
apiDefinitionCaseDTO.setCaseStatus(apiTestCase.getStatus());
|
||||
apiDefinitionCaseDTO.setCreateUser(null);
|
||||
dtoList.add(apiDefinitionCaseDTO);
|
||||
});
|
||||
BeanUtils.copyBean(apiDefinitionCaseDTO, apiTestCase);
|
||||
return apiDefinitionCaseDTO;
|
||||
})
|
||||
.toList();
|
||||
List<Map> resources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(noticeLists), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, event, resources, user, projectId);
|
||||
});
|
||||
}
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
public List<ApiDefinitionCaseDTO> getBatchEditApiCaseDTO(ApiTestCaseBatchRequest request) {
|
||||
List<String> ids = apiTestCaseService.doSelectIds(request, false);
|
||||
return handleBatchNotice(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.metersphere.system.dto.request.OperationHistoryRequest;
|
|||
import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.OperationHistoryService;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
|
@ -99,6 +100,8 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
private ApiReportService apiReportService;
|
||||
@Resource
|
||||
private EnvironmentService environmentService;
|
||||
@Resource
|
||||
private ApiTestCaseNoticeService apiTestCaseNoticeService;
|
||||
|
||||
private static final String CASE_TABLE = "api_test_case";
|
||||
private static final int MAX_TAG_SIZE = 10;
|
||||
|
@ -437,6 +440,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
List<ApiTestCase> apiTestCases = extApiTestCaseMapper.getCaseInfoByIds(ids, true);
|
||||
apiTestCaseLogService.batchToGcLog(apiTestCases, userId, projectId);
|
||||
}
|
||||
apiTestCaseNoticeService.batchSendNotice(ids, userId, projectId, NoticeConstants.Event.CASE_DELETE);
|
||||
}
|
||||
|
||||
public void batchEdit(ApiCaseBatchEditRequest request, String userId) {
|
||||
|
@ -466,6 +470,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
List<ApiTestCase> caseInfoByIds = extApiTestCaseMapper.getCaseInfoByIds(ids, false);
|
||||
apiTestCaseLogService.batchEditLog(caseInfoByIds, userId, projectId);
|
||||
apiTestCaseNoticeService.batchSendNotice(ids, userId, projectId, NoticeConstants.Event.CASE_UPDATE);
|
||||
}
|
||||
|
||||
private void batchUpdateEnvironment(ApiTestCaseExample example, ApiTestCase updateCase, String envId, ApiTestCaseMapper mapper) {
|
||||
|
|
|
@ -3,28 +3,21 @@ package io.metersphere.api.service.scenario;
|
|||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiScenarioExample;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioAddRequest;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioScheduleConfigRequest;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioUpdateRequest;
|
||||
import io.metersphere.api.job.ApiScenarioScheduleJob;
|
||||
import io.metersphere.api.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
import io.metersphere.system.domain.ScheduleExample;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.ApiScenarioMessageDTO;
|
||||
import io.metersphere.system.mapper.ScheduleMapper;
|
||||
import io.metersphere.system.notice.NoticeModel;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.notice.utils.MessageTemplateUtils;
|
||||
import io.metersphere.system.service.NoticeSendService;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.beanutils.BeanMap;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -35,51 +28,12 @@ public class ApiScenarioNoticeService {
|
|||
private ApiScenarioMapper apiScenarioMapper;
|
||||
|
||||
@Resource
|
||||
private ScheduleMapper scheduleMapper;
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private NoticeSendService noticeSendService;
|
||||
|
||||
public void sendScheduleNotice(ApiScenarioScheduleConfigRequest request, String userId) {
|
||||
ScheduleExample example = new ScheduleExample();
|
||||
example.createCriteria().andResourceIdEqualTo(request.getScenarioId()).andJobEqualTo(ApiScenarioScheduleJob.class.getName());
|
||||
List<Schedule> schedules = scheduleMapper.selectByExample(example);
|
||||
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
||||
String event = NoticeConstants.Event.OPEN;
|
||||
if (BooleanUtils.isFalse(request.isEnable())) {
|
||||
event = NoticeConstants.Event.CLOSE;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(schedules)) {
|
||||
BeanMap beanMap = new BeanMap(schedules.getFirst());
|
||||
Map paramMap = new HashMap<>(beanMap);
|
||||
String template = defaultTemplateMap.get(NoticeConstants.TaskType.SCHEDULE_TASK + "_" + event);
|
||||
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
||||
String subject = defaultSubjectMap.get(NoticeConstants.TaskType.SCHEDULE_TASK + "_" + event);
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(userId)
|
||||
.context(template)
|
||||
.subject(subject)
|
||||
.paramMap(paramMap)
|
||||
.event(event)
|
||||
.excludeSelf(true)
|
||||
.build();
|
||||
noticeSendService.send(NoticeConstants.TaskType.SCHEDULE_TASK, noticeModel);
|
||||
}
|
||||
}
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
|
||||
|
||||
private List<ApiScenario> handleBatchNotice(List<String> ids) {
|
||||
List<ApiScenario> dtoList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
SubListUtils.dealForSubList(ids, 100, (subList) -> {
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
dtoList.addAll(apiScenarioMapper.selectByExample(example));
|
||||
});
|
||||
}
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
public ApiScenarioMessageDTO getScenarioDTO(ApiScenarioAddRequest request) {
|
||||
public ApiScenarioMessageDTO addScenarioDTO(ApiScenarioAddRequest request) {
|
||||
ApiScenarioMessageDTO scenarioDTO = new ApiScenarioMessageDTO();
|
||||
BeanUtils.copyBean(scenarioDTO, request);
|
||||
return scenarioDTO;
|
||||
|
@ -89,7 +43,6 @@ public class ApiScenarioNoticeService {
|
|||
ApiScenarioMessageDTO scenarioDTO = new ApiScenarioMessageDTO();
|
||||
ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(request.getId());
|
||||
BeanUtils.copyBean(scenarioDTO, apiScenario);
|
||||
BeanUtils.copyBean(scenarioDTO, request);
|
||||
return scenarioDTO;
|
||||
}
|
||||
|
||||
|
@ -100,5 +53,24 @@ public class ApiScenarioNoticeService {
|
|||
return scenarioDTO;
|
||||
}
|
||||
|
||||
public void batchSendNotice(List<String> ids, String userId, String projectId, String event) {
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
SubListUtils.dealForSubList(ids, 100, (subList) -> {
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(example);
|
||||
List<ApiScenarioMessageDTO> noticeLists = apiScenarios.stream()
|
||||
.map(apiScenario -> {
|
||||
ApiScenarioMessageDTO scenarioMessageDTO = new ApiScenarioMessageDTO();
|
||||
BeanUtils.copyBean(scenarioMessageDTO, apiScenario);
|
||||
return scenarioMessageDTO;
|
||||
})
|
||||
.toList();
|
||||
List<Map> resources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(noticeLists), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_SCENARIO_TASK, event, resources, user, projectId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package io.metersphere.api.service.scenario;
|
||||
|
||||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportMapper;
|
||||
import io.metersphere.api.mapper.ExtApiScenarioReportMapper;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.ApiReportMessageDTO;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ApiScenarioReportNoticeService {
|
||||
|
||||
@Resource
|
||||
private ApiScenarioReportMapper apiScenarioReportMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
@Resource
|
||||
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
|
||||
|
||||
public ApiReportMessageDTO getDto(String id) {
|
||||
ApiScenarioReport scenarioReport = apiScenarioReportMapper.selectByPrimaryKey(id);
|
||||
ApiReportMessageDTO reportMessageDTO = new ApiReportMessageDTO();
|
||||
reportMessageDTO.setId(scenarioReport.getId());
|
||||
reportMessageDTO.setName(scenarioReport.getName());
|
||||
return reportMessageDTO;
|
||||
}
|
||||
|
||||
public void batchSendNotice(List<String> ids, User user, String projectId, String event) {
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
SubListUtils.dealForSubList(ids, 100, (subList) -> {
|
||||
List<ApiReportMessageDTO> noticeLists = extApiScenarioReportMapper.getNoticeList(subList);
|
||||
List<Map> resources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(noticeLists), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_REPORT_TASK, event, resources, user, projectId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,8 +19,10 @@ import io.metersphere.sdk.mapper.EnvironmentMapper;
|
|||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -64,6 +66,8 @@ public class ApiScenarioReportService {
|
|||
private EnvironmentGroupMapper environmentGroupMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ApiScenarioReportNoticeService apiScenarioReportNoticeService;
|
||||
private static final String SPLITTER = "_";
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
|
@ -151,6 +155,7 @@ public class ApiScenarioReportService {
|
|||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
SubListUtils.dealForSubList(ids, 500, subList -> {
|
||||
ApiScenarioReportExample example = new ApiScenarioReportExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
|
@ -161,6 +166,7 @@ public class ApiScenarioReportService {
|
|||
apiScenarioReportMapper.updateByExampleSelective(scenarioReport, example);
|
||||
//TODO 记录日志
|
||||
apiScenarioReportLogService.batchDeleteLog(subList, userId, request.getProjectId());
|
||||
apiScenarioReportNoticeService.batchSendNotice(subList, user, request.getProjectId(), NoticeConstants.Event.DELETE);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ import io.metersphere.api.parser.step.StepParserFactory;
|
|||
import io.metersphere.api.service.ApiCommonService;
|
||||
import io.metersphere.api.service.ApiExecuteService;
|
||||
import io.metersphere.api.service.ApiFileResourceService;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.schedule.ApiScheduleNoticeService;
|
||||
import io.metersphere.api.service.definition.ApiDefinitionModuleService;
|
||||
import io.metersphere.api.service.definition.ApiDefinitionService;
|
||||
import io.metersphere.api.service.definition.ApiTestCaseService;
|
||||
|
@ -320,6 +322,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
List<ApiScenario> scenarioInfoByIds = extApiScenarioMapper.getInfoByIds(ids, false);
|
||||
apiScenarioLogService.batchEditLog(scenarioInfoByIds, userId, projectId);
|
||||
apiScenarioNoticeService.batchSendNotice(ids, userId, projectId, NoticeConstants.Event.UPDATE);
|
||||
}
|
||||
|
||||
private void batchUpdateEnvironment(ApiScenarioExample example, ApiScenario updateScenario,
|
||||
|
@ -2614,6 +2617,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
sublist -> operationGC(sublist, isDeleteOperation, deleteTime, logInsertModule.getOperator()));
|
||||
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(),
|
||||
isDeleteOperation ? OperationLogType.DELETE.name() : OperationLogType.RECOVER.name(), logInsertModule, OperationLogModule.API_TEST_SCENARIO_RECYCLE, false);
|
||||
apiScenarioNoticeService.batchSendNotice(scenarioIds, logInsertModule.getOperator(), request.getProjectId(), NoticeConstants.Event.DELETE);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -2669,7 +2673,6 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
.resourceType(ScheduleResourceType.API_SCENARIO.name())
|
||||
.config(JSON.toJSONString(scheduleRequest.getConfig()))
|
||||
.build();
|
||||
apiScenarioNoticeService.sendScheduleNotice(scheduleRequest, operator);
|
||||
|
||||
return scheduleService.scheduleConfig(
|
||||
scheduleConfig,
|
||||
|
|
|
@ -14,10 +14,7 @@ import io.metersphere.system.dto.BugMessageDTO;
|
|||
import io.metersphere.system.dto.BugSyncNoticeDTO;
|
||||
import io.metersphere.system.dto.request.DefaultBugCustomField;
|
||||
import io.metersphere.system.dto.request.DefaultFunctionalCustomField;
|
||||
import io.metersphere.system.dto.sdk.ApiDefinitionCaseDTO;
|
||||
import io.metersphere.system.dto.sdk.ApiScenarioMessageDTO;
|
||||
import io.metersphere.system.dto.sdk.FunctionalCaseMessageDTO;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.sdk.*;
|
||||
import io.metersphere.system.mapper.CustomFieldMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.notice.utils.MessageTemplateUtils;
|
||||
|
@ -56,6 +53,11 @@ public class NoticeTemplateService {
|
|||
addOptionDto(messageTemplateFieldDTOList, allFields, null);
|
||||
//TODO:获取报告
|
||||
}
|
||||
case NoticeConstants.TaskType.API_REPORT_TASK -> {
|
||||
Field[] allFields = FieldUtils.getAllFields(ApiReportMessageDTO.class);
|
||||
addOptionDto(messageTemplateFieldDTOList, allFields, null);
|
||||
//TODO:获取报告
|
||||
}
|
||||
case NoticeConstants.TaskType.TEST_PLAN_TASK -> {
|
||||
Field[] allFields = FieldUtils.getAllFields(TestPlan.class);
|
||||
addOptionDto(messageTemplateFieldDTOList, allFields, "test_plan_");
|
||||
|
|
|
@ -138,14 +138,14 @@ public class TaskCenterController {
|
|||
@Operation(summary = "系统-任务中心-定时任务批量开启")
|
||||
public void batchEnable(@Validated @RequestBody TaskCenterScheduleBatchRequest request) {
|
||||
hasPermission(SYSTEM, request.getScheduleTagType());
|
||||
taskCenterService.batchEnable(request, SessionUtils.getUserId(), "/task/center/system/schedule/batch-enable", OperationLogModule.SETTING_SYSTEM_TASK_CENTER, true);
|
||||
taskCenterService.batchEnable(request, SessionUtils.getUserId(), "/task/center/system/schedule/batch-enable", OperationLogModule.SETTING_SYSTEM_TASK_CENTER, true, SessionUtils.getCurrentProjectId());
|
||||
}
|
||||
|
||||
@PostMapping("/org/schedule/batch-enable")
|
||||
@Operation(summary = "组织-任务中心-定时任务批量开启")
|
||||
public void batchOrgEnable(@Validated @RequestBody TaskCenterScheduleBatchRequest request) {
|
||||
hasPermission(ORG, request.getScheduleTagType());
|
||||
taskCenterService.batchEnableOrg(request, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), "/task/center/org/schedule/batch-enable", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER, true);
|
||||
taskCenterService.batchEnableOrg(request, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), "/task/center/org/schedule/batch-enable", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER, true, SessionUtils.getCurrentProjectId());
|
||||
}
|
||||
|
||||
@PostMapping("/project/schedule/batch-enable")
|
||||
|
@ -159,14 +159,14 @@ public class TaskCenterController {
|
|||
@Operation(summary = "系统-任务中心-定时任务批量关闭")
|
||||
public void batchDisable(@Validated @RequestBody TaskCenterScheduleBatchRequest request) {
|
||||
hasPermission(SYSTEM, request.getScheduleTagType());
|
||||
taskCenterService.batchEnable(request, SessionUtils.getUserId(), "/task/center/system/schedule/batch-disable", OperationLogModule.SETTING_SYSTEM_TASK_CENTER, false);
|
||||
taskCenterService.batchEnable(request, SessionUtils.getUserId(), "/task/center/system/schedule/batch-disable", OperationLogModule.SETTING_SYSTEM_TASK_CENTER, false, SessionUtils.getCurrentProjectId());
|
||||
}
|
||||
|
||||
@PostMapping("/org/schedule/batch-disable")
|
||||
@Operation(summary = "组织-任务中心-定时任务批量关闭")
|
||||
public void batchOrgDisable(@Validated @RequestBody TaskCenterScheduleBatchRequest request) {
|
||||
hasPermission(ORG, request.getScheduleTagType());
|
||||
taskCenterService.batchEnableOrg(request, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), "/task/center/org/schedule/batch-disable", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER, false);
|
||||
taskCenterService.batchEnableOrg(request, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), "/task/center/org/schedule/batch-disable", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER, false, SessionUtils.getCurrentProjectId());
|
||||
}
|
||||
|
||||
@PostMapping("/project/schedule/batch-disable")
|
||||
|
|
|
@ -7,6 +7,8 @@ import lombok.NoArgsConstructor;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ApiDefinitionCaseDTO {
|
||||
@Schema(description = "message.domain.id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "message.domain.name")
|
||||
private String name;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.system.dto.sdk;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ApiReportMessageDTO {
|
||||
@Schema(description = "message.domain.id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "message.domain.report.name")
|
||||
private String name;
|
||||
|
||||
}
|
|
@ -7,6 +7,8 @@ import lombok.NoArgsConstructor;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ApiScenarioMessageDTO {
|
||||
@Schema(description = "message.domain.id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "message.domain.api_scenario_name")
|
||||
private String name;
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package io.metersphere.system.schedule;
|
||||
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.notice.NoticeModel;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.notice.utils.MessageTemplateUtils;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import io.metersphere.system.service.NoticeSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.beanutils.BeanMap;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ApiScheduleNoticeService {
|
||||
@Resource
|
||||
private NoticeSendService noticeSendService;
|
||||
@Resource
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
|
||||
public void sendScheduleNotice(Schedule schedule, String userId) {
|
||||
if (ObjectUtils.isNotEmpty(schedule)) {
|
||||
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
||||
String event = NoticeConstants.Event.OPEN;
|
||||
if (BooleanUtils.isFalse(schedule.getEnable())) {
|
||||
event = NoticeConstants.Event.CLOSE;
|
||||
}
|
||||
BeanMap beanMap = new BeanMap(schedule);
|
||||
Map paramMap = new HashMap<>(beanMap);
|
||||
String template = defaultTemplateMap.get(NoticeConstants.TaskType.SCHEDULE_TASK + "_" + event);
|
||||
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
||||
String subject = defaultSubjectMap.get(NoticeConstants.TaskType.SCHEDULE_TASK + "_" + event);
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(userId)
|
||||
.context(template)
|
||||
.subject(subject)
|
||||
.paramMap(paramMap)
|
||||
.event(event)
|
||||
.excludeSelf(true)
|
||||
.build();
|
||||
noticeSendService.send(NoticeConstants.TaskType.SCHEDULE_TASK, noticeModel);
|
||||
}
|
||||
}
|
||||
|
||||
public void batchSendNotice(String projectId, List<Schedule> scheduleList, User user, String event) {
|
||||
SubListUtils.dealForSubList(scheduleList, 100, list -> {
|
||||
List<Map> resources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(list), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.SCHEDULE_TASK, event, resources, user, projectId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -25,6 +25,8 @@ public class ScheduleService {
|
|||
private ScheduleMapper scheduleMapper;
|
||||
@Resource
|
||||
private ScheduleManager scheduleManager;
|
||||
@Resource
|
||||
private ApiScheduleNoticeService apiScheduleNoticeService;
|
||||
|
||||
public void addSchedule(Schedule schedule) {
|
||||
schedule.setId(IDGenerator.nextStr());
|
||||
|
@ -121,6 +123,7 @@ public class ScheduleService {
|
|||
schedule.setUpdateTime(System.currentTimeMillis());
|
||||
schedule.setJob(clazz.getName());
|
||||
scheduleMapper.updateByExampleSelective(schedule, example);
|
||||
apiScheduleNoticeService.sendScheduleNotice(schedule, operator);
|
||||
} else {
|
||||
schedule = scheduleConfig.genCronSchedule(null);
|
||||
schedule.setJob(clazz.getName());
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.project.domain.Project;
|
|||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.Organization;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
|
@ -21,11 +22,14 @@ import io.metersphere.system.log.constants.OperationLogType;
|
|||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.log.service.OperationLogService;
|
||||
import io.metersphere.system.mapper.*;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.schedule.ApiScheduleNoticeService;
|
||||
import io.metersphere.system.schedule.BaseScheduleJob;
|
||||
import io.metersphere.system.schedule.ScheduleService;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -36,10 +40,7 @@ import org.quartz.TriggerKey;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -82,6 +83,10 @@ public class TaskCenterService {
|
|||
OperationLogService operationLogService;
|
||||
@Resource
|
||||
SqlSessionFactory sqlSessionFactory;
|
||||
@Resource
|
||||
ApiScheduleNoticeService apiScheduleNoticeService;
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
|
||||
|
||||
private static final String CREATE_TIME_SORT = "create_time desc";
|
||||
|
@ -207,6 +212,7 @@ public class TaskCenterService {
|
|||
scheduleService.editSchedule(schedule);
|
||||
scheduleService.addOrUpdateCronJob(schedule, new JobKey(schedule.getKey(), schedule.getJob()),
|
||||
new TriggerKey(schedule.getKey(), schedule.getJob()), BaseScheduleJob.class);
|
||||
apiScheduleNoticeService.sendScheduleNotice(schedule, userId);
|
||||
saveLog(List.of(schedule), userId, path, HttpMethodConstants.GET.name(), module, OperationLogType.UPDATE.name());
|
||||
}
|
||||
|
||||
|
@ -247,18 +253,18 @@ public class TaskCenterService {
|
|||
operationLogService.batchAdd(logs);
|
||||
}
|
||||
|
||||
public void batchEnable(TaskCenterScheduleBatchRequest request, String userId, String path, String module, boolean enable) {
|
||||
public void batchEnable(TaskCenterScheduleBatchRequest request, String userId, String path, String module, boolean enable, String projectId) {
|
||||
List<OptionDTO> projectList = getSystemProjectList();
|
||||
batchOperation(request, userId, path, module, projectList, enable);
|
||||
batchOperation(request, userId, path, module, projectList, enable, projectId);
|
||||
}
|
||||
|
||||
public void batchEnableOrg(TaskCenterScheduleBatchRequest request, String userId, String orgId, String path, String module, boolean enable) {
|
||||
public void batchEnableOrg(TaskCenterScheduleBatchRequest request, String userId, String orgId, String path, String module, boolean enable, String projectId) {
|
||||
List<OptionDTO> projectList = getOrgProjectList(orgId);
|
||||
batchOperation(request, userId, path, module, projectList, enable);
|
||||
batchOperation(request, userId, path, module, projectList, enable, projectId);
|
||||
|
||||
}
|
||||
|
||||
private void batchOperation(TaskCenterScheduleBatchRequest request, String userId, String path, String module, List<OptionDTO> projectList, boolean enable) {
|
||||
private void batchOperation(TaskCenterScheduleBatchRequest request, String userId, String path, String module, List<OptionDTO> projectList, boolean enable, String projectId) {
|
||||
List<Schedule> scheduleList = new ArrayList<>();
|
||||
if (request.isSelectAll()) {
|
||||
List<String> projectIds = projectList.stream().map(OptionDTO::getId).toList();
|
||||
|
@ -269,23 +275,29 @@ public class TaskCenterService {
|
|||
scheduleList = scheduleMapper.selectByExample(example);
|
||||
}
|
||||
//过滤掉不需要的 和已经开启过的
|
||||
scheduleList = scheduleList.stream().filter(s -> s.getEnable() != enable || !request.getExcludeIds().contains(s.getId())).collect(Collectors.toList());
|
||||
scheduleList = scheduleList.stream().filter(s -> s.getEnable() != enable).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
scheduleList.removeAll(request.getExcludeIds());
|
||||
}
|
||||
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ScheduleMapper batchMapper = sqlSession.getMapper(ScheduleMapper.class);
|
||||
scheduleList.forEach(s -> {
|
||||
SubListUtils.dealForSubList(scheduleList, 100, list -> {
|
||||
list.forEach(s -> {
|
||||
s.setEnable(enable);
|
||||
batchMapper.updateByPrimaryKeySelective(s);
|
||||
scheduleService.addOrUpdateCronJob(s, new JobKey(s.getKey(), s.getJob()),
|
||||
new TriggerKey(s.getKey(), s.getJob()), BaseScheduleJob.class);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
});
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
apiScheduleNoticeService.batchSendNotice(projectId, scheduleList, userMapper.selectByPrimaryKey(userId), enable ? NoticeConstants.Event.OPEN : NoticeConstants.Event.CLOSE);
|
||||
saveLog(scheduleList, userId, path, HttpMethodConstants.POST.name(), module, OperationLogType.UPDATE.name());
|
||||
}
|
||||
|
||||
public void batchEnableProject(TaskCenterScheduleBatchRequest request, String userId, String projectId, String path, String module, boolean enable) {
|
||||
List<OptionDTO> projectList = getProjectOption(projectId);
|
||||
batchOperation(request, userId, path, module, projectList, enable);
|
||||
batchOperation(request, userId, path, module, projectList, enable, projectId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue