refactor(用例管理): 脑图批量删除节点增加更新日志

This commit is contained in:
guoyuqi 2024-05-10 14:11:13 +08:00 committed by 刘瑞斌
parent edcd8bbbda
commit 92d441eaa8
2 changed files with 95 additions and 13 deletions

View File

@ -34,6 +34,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
@ -65,9 +66,13 @@ public class FunctionalCaseLogService {
@Resource
private BugRelationCaseMapper bugRelationCaseMapper;
@Resource
private BugMapper bugMapper;
@Resource
private ExtFunctionalCaseModuleMapper extFunctionalCaseModuleMapper;
/**
* 更新用例 日志
@ -166,10 +171,10 @@ public class FunctionalCaseLogService {
public List<LogDTO> batchDeleteFunctionalCaseLog(FunctionalCaseBatchRequest request) {
List<String> ids = functionalCaseService.doSelectIds(request, request.getProjectId());
return batchDeleteFunctionalCaseLogByIds(ids);
return batchDeleteFunctionalCaseLogByIds(ids, "/functional/case/batch/deleteToGc");
}
public List<LogDTO> batchDeleteFunctionalCaseLogByIds(List<String> ids) {
public List<LogDTO> batchDeleteFunctionalCaseLogByIds(List<String> ids, String path) {
List<LogDTO> dtoList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(ids)) {
List<FunctionalCase> functionalCases = extFunctionalCaseMapper.getLogInfo(ids, false);
@ -183,7 +188,30 @@ public class FunctionalCaseLogService {
OperationLogModule.FUNCTIONAL_CASE,
functionalCase.getName());
dto.setPath("/functional/case/batch/deleteToGc");
dto.setPath(path);
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(functionalCase));
dtoList.add(dto);
});
}
return dtoList;
}
public List<LogDTO> batchUpdateFunctionalCaseLogByIds(List<String> ids, String path) {
List<LogDTO> dtoList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(ids)) {
List<FunctionalCase> functionalCases = extFunctionalCaseMapper.getLogInfo(ids, false);
functionalCases.forEach(functionalCase -> {
LogDTO dto = new LogDTO(
functionalCase.getProjectId(),
null,
functionalCase.getId(),
null,
OperationLogType.UPDATE.name(),
OperationLogModule.FUNCTIONAL_CASE,
functionalCase.getName());
dto.setPath(path);
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(functionalCase));
dtoList.add(dto);
@ -196,13 +224,56 @@ public class FunctionalCaseLogService {
if (CollectionUtils.isEmpty(resourceList)) {
return new ArrayList<>();
}
String path = "/functional/mind/case/batch/delete/";
List<String> caseAllIds = new ArrayList<>();
Map<String, List<MinderOptionDTO>> resourceMap = resourceList.stream().collect(Collectors.groupingBy(MinderOptionDTO::getType));
List<MinderOptionDTO> caseOptionDTOS = resourceMap.get(MinderLabel.CASE.toString());
if (CollectionUtils.isEmpty(caseOptionDTOS)) {
return new ArrayList<>();
if (CollectionUtils.isNotEmpty(caseOptionDTOS)) {
List<String> caseIds = caseOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
caseAllIds.addAll(caseIds);
}
List<String> caseIds = caseOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
return batchDeleteFunctionalCaseLogByIds(caseIds);
List<MinderOptionDTO> moduleOptionDTOS = resourceMap.get(MinderLabel.MODULE.toString());
if (CollectionUtils.isNotEmpty(moduleOptionDTOS)) {
List<String> moduleIds = moduleOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
List<FunctionalCase> functionalCaseByModuleIds = getFunctionalCaseByModuleIds(moduleIds, new ArrayList<>());
List<String> list = functionalCaseByModuleIds.stream().map(FunctionalCase::getId).toList();
caseAllIds.addAll(list);
}
Set<String> strings = resourceMap.keySet();
List<LogDTO>logDTOS = new ArrayList<>();
List<String>ids = new ArrayList<>();
for (String key : strings) {
if (StringUtils.equalsIgnoreCase(key, MinderLabel.CASE.toString()) || StringUtils.equalsIgnoreCase(key, MinderLabel.MODULE.toString())) {
List<LogDTO> logDTOS1 = batchDeleteFunctionalCaseLogByIds(caseAllIds, path);
logDTOS.addAll(logDTOS1);
} else {
//更新
List<MinderOptionDTO> keyOptionDTOS = resourceMap.get(key);
if (CollectionUtils.isNotEmpty(keyOptionDTOS)) {
List<String> list = keyOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
ids.addAll(list);
}
}
}
List<LogDTO> logDTOS1 = batchUpdateFunctionalCaseLogByIds(ids, path);
logDTOS.addAll(logDTOS1);
return logDTOS;
}
public List<FunctionalCase> getFunctionalCaseByModuleIds(List<String> deleteIds, List<FunctionalCase> functionalCases) {
if (CollectionUtils.isEmpty(deleteIds)) {
return functionalCases;
}
List<FunctionalCase> functionalCaseList = extFunctionalCaseMapper.checkCaseByModuleIds(deleteIds);
if (CollectionUtils.isNotEmpty(functionalCaseList)) {
functionalCases.addAll(functionalCaseList);
}
List<String> childrenIds = extFunctionalCaseModuleMapper.selectChildrenIdsByParentIds(deleteIds);
if (CollectionUtils.isNotEmpty(childrenIds)) {
getFunctionalCaseByModuleIds(childrenIds, functionalCases);
}
return functionalCases;
}
/**

View File

@ -14,9 +14,12 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.CustomField;
import io.metersphere.system.domain.CustomFieldExample;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.sdk.enums.MoveTypeEnum;
import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.ExtCheckOwnerMapper;
import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.notice.constants.NoticeConstants;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -77,6 +80,12 @@ public class FunctionalCaseMinderService {
@Resource
private FunctionalCaseModuleService functionalCaseModuleService;
@Resource
private FunctionalCaseNoticeService functionalCaseNoticeService;
@Resource
private UserMapper userMapper;
@Resource
SqlSessionFactory sqlSessionFactory;
@ -423,6 +432,7 @@ public class FunctionalCaseMinderService {
throw new MSException(Translator.get("node.not_blank"));
}
Map<String, List<MinderOptionDTO>> resourceMap = resourceList.stream().collect(Collectors.groupingBy(MinderOptionDTO::getType));
User user = userMapper.selectByPrimaryKey(userId);
List<MinderOptionDTO> caseOptionDTOS = resourceMap.get(MinderLabel.CASE.toString());
if (CollectionUtils.isNotEmpty(caseOptionDTOS)) {
@ -442,28 +452,29 @@ public class FunctionalCaseMinderService {
functionalCaseModuleService.batchDelLog(functionalCases, projectId);
}
List<MinderOptionDTO> prerequisiteOptionDTOS = resourceMap.get(MinderLabel.PREREQUISITE.toString());
updateBlob(userId, "prerequisite", prerequisiteOptionDTOS);
updateBlob(userId, "prerequisite", prerequisiteOptionDTOS, projectId, user);
List<MinderOptionDTO> descriptionOptionDTOS = resourceMap.get(MinderLabel.DESCRIPTION.toString());
updateBlob(userId, "description", descriptionOptionDTOS);
updateBlob(userId, "description", descriptionOptionDTOS, projectId, user);
List<MinderOptionDTO> stepOptionDTOS = resourceMap.get(MinderLabel.STEPS.toString());
if (CollectionUtils.isNotEmpty(stepOptionDTOS)) {
List<MinderOptionDTO> stepResultOptionDTOS = resourceMap.get(MinderLabel.STEPS_EXPECTED_RESULT.toString());
stepOptionDTOS.addAll(stepResultOptionDTOS);
updateBlob(userId, "steps", stepOptionDTOS);
updateBlob(userId, "steps", stepOptionDTOS, projectId, user);
}
List<MinderOptionDTO> textOptionDTOS = resourceMap.get(MinderLabel.TEXT_DESCRIPTION.toString());
updateBlob(userId, "text_description", textOptionDTOS);
updateBlob(userId, "text_description", textOptionDTOS, projectId, user);
List<MinderOptionDTO> resultOptionDTOS = resourceMap.get(MinderLabel.TEXT_EXPECTED_RESULT.toString());
updateBlob(userId, "expected_result", resultOptionDTOS);
updateBlob(userId, "expected_result", resultOptionDTOS, projectId, user);
}
private void updateBlob(String userId, String column, List<MinderOptionDTO> preRequisiteOptionDTOS) {
private void updateBlob(String userId, String column, List<MinderOptionDTO> preRequisiteOptionDTOS, String projectId, User user) {
if (CollectionUtils.isNotEmpty(preRequisiteOptionDTOS)) {
List<String> caseIds = preRequisiteOptionDTOS.stream().map(MinderOptionDTO::getId).distinct().toList();
if (!extCheckOwnerMapper.checkoutOwner(FUNCTIONAL_CASE, userId, caseIds)) {
throw new MSException(Translator.get(CHECK_OWNER_CASE));
}
extFunctionalCaseBlobMapper.batchUpdateColumn(column, caseIds, null);
functionalCaseNoticeService.batchSendNotice(projectId, caseIds, user, NoticeConstants.Event.UPDATE);
}
}