feat(用例管理): 同步需求可以删除需求以及不排除回收站用例
This commit is contained in:
parent
108bc1490a
commit
790c6414f8
|
@ -21,7 +21,7 @@
|
||||||
select functional_case_demand.id, functional_case_demand.demand_id, functional_case_demand.case_id
|
select functional_case_demand.id, functional_case_demand.demand_id, functional_case_demand.case_id
|
||||||
from functional_case_demand
|
from functional_case_demand
|
||||||
left join functional_case on functional_case.id = functional_case_demand.case_id
|
left join functional_case on functional_case.id = functional_case_demand.case_id
|
||||||
where functional_case.project_id = #{projectId} and functional_case_demand.demand_platform=#{platform} and functional_case.deleted = false
|
where functional_case.project_id = #{projectId} and functional_case_demand.demand_platform=#{platform}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDemandIdsByCaseId" resultType="java.lang.String">
|
<select id="selectDemandIdsByCaseId" resultType="java.lang.String">
|
||||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.functional.service;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.functional.domain.FunctionalCaseDemand;
|
import io.metersphere.functional.domain.FunctionalCaseDemand;
|
||||||
|
import io.metersphere.functional.domain.FunctionalCaseDemandExample;
|
||||||
import io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper;
|
import io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper;
|
||||||
import io.metersphere.functional.mapper.FunctionalCaseDemandMapper;
|
import io.metersphere.functional.mapper.FunctionalCaseDemandMapper;
|
||||||
import io.metersphere.plugin.platform.dto.request.DemandRelateQueryRequest;
|
import io.metersphere.plugin.platform.dto.request.DemandRelateQueryRequest;
|
||||||
|
@ -34,6 +35,8 @@ public class DemandSyncService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtFunctionalCaseDemandMapper extFunctionalCaseDemandMapper;
|
private ExtFunctionalCaseDemandMapper extFunctionalCaseDemandMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
private FunctionalCaseDemandMapper demandMapper;
|
||||||
|
@Resource
|
||||||
private ProjectApplicationService projectApplicationService;
|
private ProjectApplicationService projectApplicationService;
|
||||||
@Resource
|
@Resource
|
||||||
private SqlSessionFactory sqlSessionFactory;
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
|
@ -50,23 +53,30 @@ public class DemandSyncService {
|
||||||
// 创建一个 List 来保存合并后的结果
|
// 创建一个 List 来保存合并后的结果
|
||||||
Platform platform = projectApplicationService.getPlatform(projectId, false);
|
Platform platform = projectApplicationService.getPlatform(projectId, false);
|
||||||
Map<String, List<FunctionalCaseDemand>> updateMap = new HashMap<>();
|
Map<String, List<FunctionalCaseDemand>> updateMap = new HashMap<>();
|
||||||
|
List<String>deleteIds = new ArrayList<>();
|
||||||
int pageNumber = 1;
|
int pageNumber = 1;
|
||||||
boolean count = true;
|
boolean count = true;
|
||||||
Page<Object> page = PageHelper.startPage(pageNumber, DEFAULT_BATCH_SIZE, count);
|
Page<Object> page = PageHelper.startPage(pageNumber, DEFAULT_BATCH_SIZE, count);
|
||||||
Pager<List<FunctionalCaseDemand>> listPager = PageUtils.setPageInfo(page, extFunctionalCaseDemandMapper.selectDemandByProjectId(projectId, platformId));
|
Pager<List<FunctionalCaseDemand>> listPager = PageUtils.setPageInfo(page, extFunctionalCaseDemandMapper.selectDemandByProjectId(projectId, platformId));
|
||||||
long total = listPager.getTotal();
|
long total = listPager.getTotal();
|
||||||
List<FunctionalCaseDemand> list = listPager.getList();
|
List<FunctionalCaseDemand> list = listPager.getList();
|
||||||
Map<String, List<FunctionalCaseDemand>> demandMap = list.stream().collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandId));
|
Map<String, List<FunctionalCaseDemand>> demandFirstMap = list.stream().collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandId));
|
||||||
Set<String> demandIds = demandMap.keySet();
|
Set<String> demandFirstIds = demandFirstMap.keySet();
|
||||||
buildUpdateMap(projectId, demandIds, platform, demandMap, platformId, updateMap);
|
buildUpdateMap(projectId, demandFirstIds, platform, demandFirstMap, platformId, updateMap, deleteIds);
|
||||||
count = false;
|
count = false;
|
||||||
for (int i = 1; i < ((int)Math.ceil((double) total/DEFAULT_BATCH_SIZE)); i ++) {
|
for (int i = 1; i < ((int)Math.ceil((double) total/DEFAULT_BATCH_SIZE)); i ++) {
|
||||||
Page<Object> pageCycle = PageHelper.startPage(i+1, DEFAULT_BATCH_SIZE, count);
|
Page<Object> pageCycle = PageHelper.startPage(i+1, DEFAULT_BATCH_SIZE, count);
|
||||||
Pager<List<FunctionalCaseDemand>> listPagerCycle = PageUtils.setPageInfo(pageCycle, extFunctionalCaseDemandMapper.selectDemandByProjectId(projectId,platformId));
|
Pager<List<FunctionalCaseDemand>> listPagerCycle = PageUtils.setPageInfo(pageCycle, extFunctionalCaseDemandMapper.selectDemandByProjectId(projectId,platformId));
|
||||||
List<FunctionalCaseDemand> pageResults = listPagerCycle.getList();
|
List<FunctionalCaseDemand> pageResults = listPagerCycle.getList();
|
||||||
Map<String, List<FunctionalCaseDemand>> demandsMap = pageResults.stream().collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandId));
|
Map<String, List<FunctionalCaseDemand>> demandsCycleMap = pageResults.stream().collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandId));
|
||||||
Set<String> demandIdSet = demandsMap.keySet();
|
Set<String> demandCycleIds = demandsCycleMap.keySet();
|
||||||
buildUpdateMap(projectId, demandIdSet, platform, demandsMap, platformId, updateMap);
|
buildUpdateMap(projectId, demandCycleIds, platform, demandsCycleMap, platformId, updateMap, deleteIds);
|
||||||
|
}
|
||||||
|
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
|
||||||
|
if (CollectionUtils.isNotEmpty(deleteIds)) {
|
||||||
|
List<String> deleteIdDistinct = deleteIds.stream().distinct().toList();
|
||||||
|
functionalCaseDemandExample.createCriteria().andDemandIdIn(deleteIdDistinct);
|
||||||
|
demandMapper.deleteByExample(functionalCaseDemandExample);
|
||||||
}
|
}
|
||||||
updateMap.forEach((k,v)->{
|
updateMap.forEach((k,v)->{
|
||||||
for (FunctionalCaseDemand functionalCaseDemand : v) {
|
for (FunctionalCaseDemand functionalCaseDemand : v) {
|
||||||
|
@ -78,18 +88,26 @@ public class DemandSyncService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LogUtils.info("End synchronizing demands");
|
LogUtils.info("End synchronizing demands");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildUpdateMap(String projectId, Set<String> demandIds, Platform platform, Map<String, List<FunctionalCaseDemand>> demandMap, String platformId, Map<String, List<FunctionalCaseDemand>> updateMap) {
|
private void buildUpdateMap(String projectId, Set<String> demandIds, Platform platform, Map<String, List<FunctionalCaseDemand>> demandMap, String platformId, Map<String, List<FunctionalCaseDemand>> updateMap, List<String>deleteIds) {
|
||||||
DemandRelateQueryRequest demandRelateQueryRequest = new DemandRelateQueryRequest();
|
DemandRelateQueryRequest demandRelateQueryRequest = new DemandRelateQueryRequest();
|
||||||
demandRelateQueryRequest.setProjectConfig(projectApplicationService.getProjectDemandThirdPartConfig(projectId));
|
demandRelateQueryRequest.setProjectConfig(projectApplicationService.getProjectDemandThirdPartConfig(projectId));
|
||||||
demandRelateQueryRequest.setRelateDemandIds(new ArrayList<>(demandIds));
|
demandRelateQueryRequest.setRelateDemandIds(new ArrayList<>(demandIds));
|
||||||
PlatformDemandDTO demands = platform.getDemands(demandRelateQueryRequest);
|
PlatformDemandDTO demands = platform.getDemands(demandRelateQueryRequest);
|
||||||
|
if (demands == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<PlatformDemandDTO.Demand> demandList = demands.getList();
|
List<PlatformDemandDTO.Demand> demandList = demands.getList();
|
||||||
|
if (CollectionUtils.isEmpty(demandList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> platformIds = demandList.stream().map(PlatformDemandDTO.Demand::getDemandId).toList();
|
||||||
|
if (demandIds.size() > platformIds.size()) {
|
||||||
|
platformIds.forEach(demandIds::remove);
|
||||||
|
deleteIds.addAll(demandIds);
|
||||||
|
}
|
||||||
for (PlatformDemandDTO.Demand demand : demandList) {
|
for (PlatformDemandDTO.Demand demand : demandList) {
|
||||||
List<FunctionalCaseDemand> functionalCaseDemands = demandMap.get(demand.getDemandId());
|
List<FunctionalCaseDemand> functionalCaseDemands = demandMap.get(demand.getDemandId());
|
||||||
List<FunctionalCaseDemand>updateList = new ArrayList<>();
|
List<FunctionalCaseDemand>updateList = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue