refactor(功能用例): 优化功能用例回收删除恢复逻辑
This commit is contained in:
parent
bb3c121b8b
commit
2d85feddf5
|
@ -47,7 +47,8 @@ public class FunctionalCaseTrashService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从回收站恢复用例
|
* 从回收站恢复用例
|
||||||
* @param id 用例ID
|
*
|
||||||
|
* @param id 用例ID
|
||||||
* @param userId 当前操作人
|
* @param userId 当前操作人
|
||||||
*/
|
*/
|
||||||
public void recoverCase(String id, String userId) {
|
public void recoverCase(String id, String 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,22 +106,16 @@ public class FunctionalCaseTrashService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从回收站彻底删除用例
|
* 从回收站彻底删除用例
|
||||||
|
*
|
||||||
* @param id 用例ID
|
* @param id 用例ID
|
||||||
*/
|
*/
|
||||||
public void deleteCase(String id, String userId) {
|
public void deleteCase(String id, String userId) {
|
||||||
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey(id);
|
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey(id);
|
||||||
if (functionalCase == null) {
|
if (functionalCase == null) {
|
||||||
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,8 +127,9 @@ public class FunctionalCaseTrashService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从回收站批量回复用例(恢复就是恢复所有版本)
|
* 从回收站批量回复用例(恢复就是恢复所有版本)
|
||||||
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
*/
|
*/
|
||||||
public void batchRecoverCase(FunctionalCaseBatchRequest request, String userId) {
|
public void batchRecoverCase(FunctionalCaseBatchRequest request, String userId) {
|
||||||
List<String> refIds;
|
List<String> refIds;
|
||||||
|
@ -148,102 +142,79 @@ 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);
|
|
||||||
refIds = functionalCases.stream().map(FunctionalCase::getRefId).distinct().toList();
|
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(refIds)) {
|
if (CollectionUtils.isEmpty(refIds)) {
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
return;
|
||||||
functionalCaseExample.createCriteria().andRefIdIn(refIds);
|
|
||||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
|
||||||
List<String> ids = functionalCases.stream().map(FunctionalCase::getId).toList();
|
|
||||||
Map<String, Object> param = new HashMap<>();
|
|
||||||
param.put(CaseEvent.Param.CASE_IDS,CollectionUtils.isNotEmpty(ids) ? ids : new ArrayList<>());
|
|
||||||
param.put(CaseEvent.Param.USER_ID,userId);
|
|
||||||
param.put(CaseEvent.Param.EVENT_NAME,CaseEvent.Event.RECOVER_FUNCTIONAL_CASE);
|
|
||||||
provider.updateCaseReview(param);
|
|
||||||
extFunctionalCaseMapper.recoverCaseByRefIds(refIds, userId, System.currentTimeMillis());
|
|
||||||
delCustomFieldsByRefIds(refIds);
|
|
||||||
}
|
}
|
||||||
|
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
||||||
|
functionalCaseExample.createCriteria().andRefIdIn(refIds);
|
||||||
|
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
||||||
|
List<String> ids = functionalCases.stream().map(FunctionalCase::getId).toList();
|
||||||
|
extFunctionalCaseMapper.recoverCaseByRefIds(refIds, userId, System.currentTimeMillis());
|
||||||
|
delCustomFieldsByRefIds(refIds);
|
||||||
|
Map<String, Object> param = new HashMap<>();
|
||||||
|
param.put(CaseEvent.Param.CASE_IDS, CollectionUtils.isNotEmpty(ids) ? ids : new ArrayList<>());
|
||||||
|
param.put(CaseEvent.Param.USER_ID, userId);
|
||||||
|
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.RECOVER_FUNCTIONAL_CASE);
|
||||||
|
provider.updateCaseReview(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取实际的选择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)) {
|
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
//只删除当前选择的数据
|
|
||||||
deleteFunctionalCaseService.deleteFunctionalCaseResource(ids, request.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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (CollectionUtils.isEmpty(request.getSelectIds())) {
|
List<String> selectIds = request.getSelectIds();
|
||||||
|
if (CollectionUtils.isEmpty(selectIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request.getDeleteAll()) {
|
doDeleteBatchCase(request, selectIds, userId);
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
|
||||||
functionalCaseExample.createCriteria().andIdIn(request.getSelectIds());
|
|
||||||
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) {
|
private void doDeleteBatchCase(FunctionalCaseBatchRequest request, List<String> ids, String userId) {
|
||||||
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
if (request.getDeleteAll()) {
|
||||||
functionalCaseExample.createCriteria().andRefIdIn(refIds).andDeletedEqualTo(true);
|
//回收站全部版本全都删除
|
||||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
List<String> refIds = extFunctionalCaseMapper.getRefIds(ids, true);
|
||||||
List<String> deleteIds = functionalCases.stream().map(FunctionalCase::getId).toList();
|
FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample();
|
||||||
deleteFunctionalCaseService.deleteFunctionalCaseResource(deleteIds, request.getProjectId());
|
functionalCaseExample.createCriteria().andRefIdIn(refIds).andDeletedEqualTo(true);
|
||||||
|
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
|
||||||
|
List<String> deleteIds = functionalCases.stream().map(FunctionalCase::getId).toList();
|
||||||
|
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