refactor(功能用例): 优化功能用例回收删除恢复逻辑
This commit is contained in:
parent
bb3c121b8b
commit
2d85feddf5
|
@ -47,6 +47,7 @@ public class FunctionalCaseTrashService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从回收站恢复用例
|
* 从回收站恢复用例
|
||||||
|
*
|
||||||
* @param id 用例ID
|
* @param id 用例ID
|
||||||
* @param userId 当前操作人
|
* @param userId 当前操作人
|
||||||
*/
|
*/
|
||||||
|
@ -57,16 +58,14 @@ public class FunctionalCaseTrashService {
|
||||||
throw new MSException(Translator.get("case_comment.case_is_null"));
|
throw new MSException(Translator.get("case_comment.case_is_null"));
|
||||||
}
|
}
|
||||||
List<String> ids = getIdsByRefId(functionalCase.getRefId());
|
List<String> ids = getIdsByRefId(functionalCase.getRefId());
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
|
||||||
//检查自定义字段是否还存在,不存在,删除关联关系(与恢复流程没关系可异步执行)
|
//检查自定义字段是否还存在,不存在,删除关联关系(与恢复流程没关系可异步执行)
|
||||||
delCustomFields(ids);
|
delCustomFields(ids);
|
||||||
|
extFunctionalCaseMapper.recoverCase(ids, userId, System.currentTimeMillis());
|
||||||
Map<String, Object> param = new HashMap<>();
|
Map<String, Object> param = new HashMap<>();
|
||||||
param.put(CaseEvent.Param.CASE_IDS, ids);
|
param.put(CaseEvent.Param.CASE_IDS, ids);
|
||||||
param.put(CaseEvent.Param.USER_ID, userId);
|
param.put(CaseEvent.Param.USER_ID, userId);
|
||||||
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.RECOVER_FUNCTIONAL_CASE);
|
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.RECOVER_FUNCTIONAL_CASE);
|
||||||
provider.updateCaseReview(param);
|
provider.updateCaseReview(param);
|
||||||
extFunctionalCaseMapper.recoverCase(ids,userId,System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,6 +106,7 @@ public class FunctionalCaseTrashService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从回收站彻底删除用例
|
* 从回收站彻底删除用例
|
||||||
|
*
|
||||||
* @param id 用例ID
|
* @param id 用例ID
|
||||||
*/
|
*/
|
||||||
public void deleteCase(String id, String userId) {
|
public void deleteCase(String id, String userId) {
|
||||||
|
@ -115,14 +115,7 @@ public class FunctionalCaseTrashService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> ids = getIdsByRefId(functionalCase.getRefId());
|
List<String> ids = getIdsByRefId(functionalCase.getRefId());
|
||||||
if (CollectionUtils.isNotEmpty(ids)){
|
deleteByIds(functionalCase.getProjectId(), ids, userId);
|
||||||
deleteFunctionalCaseService.deleteFunctionalCaseResource(ids, functionalCase.getProjectId());
|
|
||||||
Map<String, Object> param = new HashMap<>();
|
|
||||||
param.put(CaseEvent.Param.CASE_IDS,ids);
|
|
||||||
param.put(CaseEvent.Param.USER_ID,userId);
|
|
||||||
param.put(CaseEvent.Param.EVENT_NAME,CaseEvent.Event.DELETE_TRASH_FUNCTIONAL_CASE);
|
|
||||||
provider.updateCaseReview(param);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getIdsByRefId(String refId) {
|
private List<String> getIdsByRefId(String refId) {
|
||||||
|
@ -134,6 +127,7 @@ public class FunctionalCaseTrashService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从回收站批量回复用例(恢复就是恢复所有版本)
|
* 从回收站批量回复用例(恢复就是恢复所有版本)
|
||||||
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
*/
|
*/
|
||||||
|
@ -148,100 +142,77 @@ public class FunctionalCaseTrashService {
|
||||||
if (CollectionUtils.isEmpty(request.getSelectIds())) {
|
if (CollectionUtils.isEmpty(request.getSelectIds())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
refIds = extFunctionalCaseMapper.getRefIds(request.getSelectIds(), true);
|
||||||
functionalCaseExample.createCriteria().andIdIn(request.getSelectIds());
|
}
|
||||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
if (CollectionUtils.isEmpty(refIds)) {
|
||||||
refIds = functionalCases.stream().map(FunctionalCase::getRefId).distinct().toList();
|
return;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(refIds)) {
|
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
||||||
functionalCaseExample.createCriteria().andRefIdIn(refIds);
|
functionalCaseExample.createCriteria().andRefIdIn(refIds);
|
||||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
||||||
List<String> ids = functionalCases.stream().map(FunctionalCase::getId).toList();
|
List<String> ids = functionalCases.stream().map(FunctionalCase::getId).toList();
|
||||||
|
extFunctionalCaseMapper.recoverCaseByRefIds(refIds, userId, System.currentTimeMillis());
|
||||||
|
delCustomFieldsByRefIds(refIds);
|
||||||
Map<String, Object> param = new HashMap<>();
|
Map<String, Object> param = new HashMap<>();
|
||||||
param.put(CaseEvent.Param.CASE_IDS, CollectionUtils.isNotEmpty(ids) ? ids : new ArrayList<>());
|
param.put(CaseEvent.Param.CASE_IDS, CollectionUtils.isNotEmpty(ids) ? ids : new ArrayList<>());
|
||||||
param.put(CaseEvent.Param.USER_ID, userId);
|
param.put(CaseEvent.Param.USER_ID, userId);
|
||||||
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.RECOVER_FUNCTIONAL_CASE);
|
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.RECOVER_FUNCTIONAL_CASE);
|
||||||
provider.updateCaseReview(param);
|
provider.updateCaseReview(param);
|
||||||
extFunctionalCaseMapper.recoverCaseByRefIds(refIds, userId, System.currentTimeMillis());
|
|
||||||
delCustomFieldsByRefIds(refIds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取实际的选择ID
|
* 获取实际的选择ID
|
||||||
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
* @return List<String>
|
* @return List<String>
|
||||||
*/
|
*/
|
||||||
private List<String> getIds(FunctionalCaseBatchRequest request) {
|
private List<String> getIds(FunctionalCaseBatchRequest request) {
|
||||||
List<String> ids = extFunctionalCaseMapper.getIds(request, request.getProjectId(), true);
|
List<String> ids = extFunctionalCaseMapper.getIds(request, request.getProjectId(), true);
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||||
ids.removeAll(request.getExcludeIds());
|
ids.removeAll(request.getExcludeIds());
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量彻底删除,也分当前版本和全部版本
|
* 批量彻底删除,也分当前版本和全部版本
|
||||||
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
*/
|
*/
|
||||||
public void batchDeleteCase(FunctionalCaseBatchRequest request, String userId) {
|
public void batchDeleteCase(FunctionalCaseBatchRequest request, String userId) {
|
||||||
List<String> refIds;
|
|
||||||
if (request.isSelectAll()) {
|
if (request.isSelectAll()) {
|
||||||
//判断是否全部删除
|
//判断是否全部删除
|
||||||
List<String> ids = getIds(request);
|
List<String> ids = getIds(request);
|
||||||
if (CollectionUtils.isEmpty(ids)) return;
|
if (CollectionUtils.isEmpty(ids)) return;
|
||||||
if (request.getDeleteAll()) {
|
doDeleteBatchCase(request, ids, userId);
|
||||||
//回收站全部版本全都删除
|
|
||||||
refIds = extFunctionalCaseMapper.getRefIds(ids, true);
|
|
||||||
deleteByRefIds(request, refIds, userId);
|
|
||||||
} else {
|
} else {
|
||||||
//只删除当前选择的数据
|
List<String> selectIds = request.getSelectIds();
|
||||||
deleteFunctionalCaseService.deleteFunctionalCaseResource(ids, request.getProjectId());
|
if (CollectionUtils.isEmpty(selectIds)) {
|
||||||
Map<String, Object> param = new HashMap<>();
|
|
||||||
param.put(CaseEvent.Param.CASE_IDS,ids);
|
|
||||||
param.put(CaseEvent.Param.USER_ID,userId);
|
|
||||||
param.put(CaseEvent.Param.EVENT_NAME,CaseEvent.Event.DELETE_TRASH_FUNCTIONAL_CASE);
|
|
||||||
provider.updateCaseReview(param);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (CollectionUtils.isEmpty(request.getSelectIds())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
doDeleteBatchCase(request, selectIds, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doDeleteBatchCase(FunctionalCaseBatchRequest request, List<String> ids, String userId) {
|
||||||
if (request.getDeleteAll()) {
|
if (request.getDeleteAll()) {
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
//回收站全部版本全都删除
|
||||||
functionalCaseExample.createCriteria().andIdIn(request.getSelectIds());
|
List<String> refIds = extFunctionalCaseMapper.getRefIds(ids, true);
|
||||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
|
||||||
refIds = functionalCases.stream().map(FunctionalCase::getRefId).distinct().toList();
|
|
||||||
deleteByRefIds(request, refIds, userId);
|
|
||||||
} else {
|
|
||||||
//只删除当前选择的数据
|
|
||||||
deleteFunctionalCaseService.deleteFunctionalCaseResource(request.getSelectIds(), request.getProjectId());
|
|
||||||
Map<String, Object> param = new HashMap<>();
|
|
||||||
param.put(CaseEvent.Param.CASE_IDS,request.getSelectIds());
|
|
||||||
param.put(CaseEvent.Param.USER_ID,userId);
|
|
||||||
param.put(CaseEvent.Param.EVENT_NAME,CaseEvent.Event.DELETE_TRASH_FUNCTIONAL_CASE);
|
|
||||||
provider.updateCaseReview(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteByRefIds(FunctionalCaseBatchRequest request, List<String> refIds, String userId) {
|
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
||||||
functionalCaseExample.createCriteria().andRefIdIn(refIds).andDeletedEqualTo(true);
|
functionalCaseExample.createCriteria().andRefIdIn(refIds).andDeletedEqualTo(true);
|
||||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
||||||
List<String> deleteIds = functionalCases.stream().map(FunctionalCase::getId).toList();
|
List<String> deleteIds = functionalCases.stream().map(FunctionalCase::getId).toList();
|
||||||
deleteFunctionalCaseService.deleteFunctionalCaseResource(deleteIds, request.getProjectId());
|
deleteByIds(request.getProjectId(), deleteIds, userId);
|
||||||
|
} else {
|
||||||
|
//只删除当前选择的数据
|
||||||
|
deleteByIds(request.getProjectId(), ids, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteByIds(String projectId, List<String> deleteIds, String userId) {
|
||||||
|
deleteFunctionalCaseService.deleteFunctionalCaseResource(deleteIds, projectId);
|
||||||
Map<String, Object> param = new HashMap<>();
|
Map<String, Object> param = new HashMap<>();
|
||||||
param.put(CaseEvent.Param.CASE_IDS,CollectionUtils.isNotEmpty(deleteIds) ? deleteIds : new ArrayList<>());
|
param.put(CaseEvent.Param.CASE_IDS, deleteIds);
|
||||||
param.put(CaseEvent.Param.USER_ID, userId);
|
param.put(CaseEvent.Param.USER_ID, userId);
|
||||||
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.DELETE_TRASH_FUNCTIONAL_CASE);
|
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.DELETE_TRASH_FUNCTIONAL_CASE);
|
||||||
provider.updateCaseReview(param);
|
provider.updateCaseReview(param);
|
||||||
|
|
Loading…
Reference in New Issue