refactor(用例评审): 去掉sessionutils在service里的使用

This commit is contained in:
guoyuqi 2023-12-06 11:58:05 +08:00 committed by 刘瑞斌
parent 8b54ddab04
commit 74f1958eff
10 changed files with 28 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -12,6 +13,8 @@ import java.util.List;
*/ */
@Data @Data
public class BaseFunctionalCaseBatchDTO extends TableBatchProcessDTO implements Serializable { public class BaseFunctionalCaseBatchDTO extends TableBatchProcessDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "模块id") @Schema(description = "模块id")
private List<String> moduleIds; private List<String> moduleIds;

View File

@ -2,6 +2,7 @@ package io.metersphere.functional.dto;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -10,6 +11,8 @@ import java.util.List;
*/ */
@Data @Data
public class CombineDTO implements Serializable { public class CombineDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String id; private String id;
private List<Object> value; private List<Object> value;

View File

@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -11,6 +12,8 @@ import java.io.Serializable;
*/ */
@Data @Data
public class DemandDTO implements Serializable { public class DemandDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "需求ID") @Schema(description = "需求ID")
private String demandId; private String demandId;

View File

@ -4,6 +4,7 @@ import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -13,6 +14,9 @@ import java.util.List;
@Data @Data
public class CaseReviewBatchRequest extends TableBatchProcessDTO implements Serializable { public class CaseReviewBatchRequest extends TableBatchProcessDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String projectId; private String projectId;

View File

@ -5,12 +5,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@Data @Data
public class CaseReviewPageRequest extends BasePageRequest implements Serializable { public class CaseReviewPageRequest extends BasePageRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.project_id.not_blank}") @NotBlank(message = "{functional_case.project_id.not_blank}")
private String projectId; private String projectId;

View File

@ -16,7 +16,7 @@ public class CaseReviewRequest implements Serializable {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Schema(description = "用例id", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "用例评审id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.id.not_blank}", groups = {Updated.class}) @NotBlank(message = "{functional_case.id.not_blank}", groups = {Updated.class})
private String id; private String id;

View File

@ -6,7 +6,6 @@ import io.metersphere.functional.mapper.CaseReviewMapper;
import io.metersphere.functional.mapper.ExtCaseReviewMapper; import io.metersphere.functional.mapper.ExtCaseReviewMapper;
import io.metersphere.functional.request.CaseReviewRequest; import io.metersphere.functional.request.CaseReviewRequest;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -37,7 +36,7 @@ public class CaseReviewNoticeService {
caseReview.setReviewPassRule(request.getReviewPassRule()); caseReview.setReviewPassRule(request.getReviewPassRule());
caseReview.setPos(getNextPos(request.getProjectId())); caseReview.setPos(getNextPos(request.getProjectId()));
caseReview.setCreateTime(System.currentTimeMillis()); caseReview.setCreateTime(System.currentTimeMillis());
caseReview.setCreateUser(SessionUtils.getUserId()); caseReview.setCreateUser(null);
} }
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
caseReview.setTags(JSON.toJSONString(request.getTags())); caseReview.setTags(JSON.toJSONString(request.getTags()));
@ -45,7 +44,7 @@ public class CaseReviewNoticeService {
caseReview.setStartTime(request.getStartTime()); caseReview.setStartTime(request.getStartTime());
caseReview.setEndTime(request.getEndTime()); caseReview.setEndTime(request.getEndTime());
caseReview.setUpdateTime(System.currentTimeMillis()); caseReview.setUpdateTime(System.currentTimeMillis());
caseReview.setUpdateUser(SessionUtils.getUserId()); caseReview.setUpdateUser(null);
return caseReview; return caseReview;
} }

View File

@ -16,7 +16,6 @@ import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.ExtOrganizationCustomFieldMapper; import io.metersphere.system.mapper.ExtOrganizationCustomFieldMapper;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
@ -129,12 +128,11 @@ public class FunctionalCaseNoticeService {
} }
public FunctionalCaseDTO getMainFunctionalCaseDTO(String name, String caseEditType, String projectId, Map<String, Object> customFields) { public FunctionalCaseDTO getMainFunctionalCaseDTO(String name, String caseEditType, String projectId, Map<String, Object> customFields) {
String userId = SessionUtils.getUserId();
FunctionalCaseDTO functionalCaseDTO = new FunctionalCaseDTO(); FunctionalCaseDTO functionalCaseDTO = new FunctionalCaseDTO();
functionalCaseDTO.setName(name); functionalCaseDTO.setName(name);
functionalCaseDTO.setProjectId(projectId); functionalCaseDTO.setProjectId(projectId);
functionalCaseDTO.setCaseEditType(caseEditType); functionalCaseDTO.setCaseEditType(caseEditType);
functionalCaseDTO.setCreateUser(userId); functionalCaseDTO.setCreateUser(null);
List<OptionDTO> fields = new ArrayList<>(); List<OptionDTO> fields = new ArrayList<>();
if (MapUtils.isNotEmpty(customFields)) { if (MapUtils.isNotEmpty(customFields)) {
customFields.keySet().forEach(key -> { customFields.keySet().forEach(key -> {
@ -179,7 +177,6 @@ public class FunctionalCaseNoticeService {
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
Map<String, FunctionalCase> functionalCaseMap = functionalCaseService.copyBaseInfo(projectId, ids); Map<String, FunctionalCase> functionalCaseMap = functionalCaseService.copyBaseInfo(projectId, ids);
Map<String, List<FunctionalCaseCustomField>> customFieldMap = functionalCaseCustomFieldService.getCustomFieldMapByCaseIds(ids); Map<String, List<FunctionalCaseCustomField>> customFieldMap = functionalCaseCustomFieldService.getCustomFieldMapByCaseIds(ids);
String userId = SessionUtils.getUserId();
AtomicReference<List<OptionDTO>> optionDTOS = new AtomicReference<>(new ArrayList<>()); AtomicReference<List<OptionDTO>> optionDTOS = new AtomicReference<>(new ArrayList<>());
ids.forEach(id -> { ids.forEach(id -> {
FunctionalCase functionalCase = functionalCaseMap.get(id); FunctionalCase functionalCase = functionalCaseMap.get(id);
@ -192,7 +189,7 @@ public class FunctionalCaseNoticeService {
functionalCaseDTO.setName(functionalCase.getName()); functionalCaseDTO.setName(functionalCase.getName());
functionalCaseDTO.setProjectId(functionalCase.getProjectId()); functionalCaseDTO.setProjectId(functionalCase.getProjectId());
functionalCaseDTO.setCaseEditType(functionalCase.getCaseEditType()); functionalCaseDTO.setCaseEditType(functionalCase.getCaseEditType());
functionalCaseDTO.setCreateUser(userId); functionalCaseDTO.setCreateUser(null);
functionalCaseDTO.setFields(optionDTOS.get()); functionalCaseDTO.setFields(optionDTOS.get());
dtoList.add(functionalCaseDTO); dtoList.add(functionalCaseDTO);
}); });

View File

@ -75,6 +75,10 @@ Insert into message_task(id, event, receiver, project_robot_id, task_type, test_
VALUES ('case-review_message0', 'CREATE', 'gyq_review_test', 'test_case_review_message_robot1', 'CASE_REVIEW_TASK', 'NONE', 'project-gyq-case-review-test', true, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.case_review_task_create'); VALUES ('case-review_message0', 'CREATE', 'gyq_review_test', 'test_case_review_message_robot1', 'CASE_REVIEW_TASK', 'NONE', 'project-gyq-case-review-test', true, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.case_review_task_create');
INSERT INTO message_task_blob(id, template) VALUES ('case-review_message0', 'message.case_review_task_create'); INSERT INTO message_task_blob(id, template) VALUES ('case-review_message0', 'message.case_review_task_create');
Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject)
VALUES ('case-review_message9', 'CREATE', 'CREATE_USER', 'test_case_review_message_robot1', 'CASE_REVIEW_TASK', 'NONE', 'project-gyq-case-review-test', true, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.case_review_task_create');
INSERT INTO message_task_blob(id, template) VALUES ('case-review_message9', 'message.case_review_task_create');
Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject)
VALUES ('case-review_message1', 'UPDATE', 'CREATE_USER', 'test_case_review_message_robot1', 'CASE_REVIEW_TASK', 'NONE', 'project-gyq-case-review-test', true, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.case_review_task_update'); VALUES ('case-review_message1', 'UPDATE', 'CREATE_USER', 'test_case_review_message_robot1', 'CASE_REVIEW_TASK', 'NONE', 'project-gyq-case-review-test', true, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.case_review_task_update');
INSERT INTO message_task_blob(id, template) VALUES ('case-review_message1', 'message.case_review_task_update'); INSERT INTO message_task_blob(id, template) VALUES ('case-review_message1', 'message.case_review_task_update');

View File

@ -110,6 +110,8 @@ public abstract class AbstractNoticeSender implements NoticeSender {
String createUser = (String) paramMap.get("createUser"); String createUser = (String) paramMap.get("createUser");
if (StringUtils.isNotBlank(createUser)) { if (StringUtils.isNotBlank(createUser)) {
toUsers.add(new Receiver(createUser, NotificationConstants.Type.SYSTEM_NOTICE.name())); toUsers.add(new Receiver(createUser, NotificationConstants.Type.SYSTEM_NOTICE.name()));
} else {
toUsers.add(new Receiver((String) paramMap.get(NoticeConstants.RelatedUser.OPERATOR), NotificationConstants.Type.SYSTEM_NOTICE.name()));
} }
} }
case NoticeConstants.RelatedUser.OPERATOR -> { case NoticeConstants.RelatedUser.OPERATOR -> {