From 264f6daab21228a7143d0715c2f6fe67f14ff835 Mon Sep 17 00:00:00 2001 From: Rui Chen <44330697+coryhh@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:48:56 +0800 Subject: [PATCH] Fix/update scene info mongo (#451) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:remove the diffDetail in SubSceneInfo * feat: remove diffDetails in SceneInfo * feat: remove invalid code --- .../src/main/resources/application-dev.yaml | 2 +- .../iosummary/SceneReportService.java | 58 ++++++++++++++----- .../repository/CaseSummaryRepository.java | 2 + .../mongo/CaseSummaryRepositoryImpl.java | 18 ++++++ .../mongo/SceneInfoRepositoryImpl.java | 2 - .../iosummary/CaseSummaryCollection.java | 3 + .../mongodb/iosummary/SubSceneInfoDao.java | 6 +- pom.xml | 2 +- 8 files changed, 69 insertions(+), 24 deletions(-) diff --git a/arex-web-api/src/main/resources/application-dev.yaml b/arex-web-api/src/main/resources/application-dev.yaml index ba8adec4..95132589 100644 --- a/arex-web-api/src/main/resources/application-dev.yaml +++ b/arex-web-api/src/main/resources/application-dev.yaml @@ -11,7 +11,7 @@ arex: service: url: http://10.118.1.217:18092 mongo: - uri: mongodb://arex:password@10.118.1.217:37017/arex_storage_db + uri: mongodb://arex:iLoveArex@10.118.1.217:37017/arex_storage_db # standalone without password spring: diff --git a/arex-web-core/src/main/java/com/arextest/web/core/business/iosummary/SceneReportService.java b/arex-web-core/src/main/java/com/arextest/web/core/business/iosummary/SceneReportService.java index e6238a55..a95cef02 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/business/iosummary/SceneReportService.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/business/iosummary/SceneReportService.java @@ -13,6 +13,7 @@ import com.arextest.web.model.dto.PlanItemDto; import com.arextest.web.model.dto.ReportPlanStatisticDto; import com.arextest.web.model.dto.iosummary.CaseSummary; +import com.arextest.web.model.dto.iosummary.DiffDetail; import com.arextest.web.model.dto.iosummary.SceneInfo; import com.arextest.web.model.dto.iosummary.SubSceneInfo; import com.arextest.web.model.enums.DiffResultCode; @@ -65,9 +66,8 @@ public class SceneReportService { */ public void report(CaseSummary caseSummary) { SceneInfo sceneInfo = SceneInfo.builder().code(caseSummary.getCode()) - .categoryKey(caseSummary.categoryKey()) - .planId(caseSummary.getPlanId()).planItemId(caseSummary.getPlanItemId()) - .summary(caseSummary).build(); + .categoryKey(caseSummary.categoryKey()).planId(caseSummary.getPlanId()) + .planItemId(caseSummary.getPlanItemId()).summary(caseSummary).build(); sceneInfoRepository.save(sceneInfo); } @@ -101,11 +101,10 @@ private List checkDuplicateScene(List sceneInfos) { public QuerySceneInfoResponseType querySceneInfo(String planId, String planItemId) { QuerySceneInfoResponseType response = new QuerySceneInfoResponseType(); - List sceneInfos = sceneInfoRepository.querySceneInfo(planId, planItemId); + List sceneInfos = queryCompleteSceneInfo(planId, planItemId); sceneInfos = checkDuplicateScene(sceneInfos); - List sceneInfoTypes = - sceneInfos.stream().map(SceneInfoMapper.INSTANCE::contractFromDto) - .collect(Collectors.toList()); + List sceneInfoTypes = sceneInfos.stream() + .map(SceneInfoMapper.INSTANCE::contractFromDto).collect(Collectors.toList()); // to set recordTime and replayTime Map subSceneInfoTypeMap = new HashMap<>(); @@ -118,8 +117,7 @@ public QuerySceneInfoResponseType querySceneInfo(String planId, String planItemI if (MapUtils.isNotEmpty(subSceneInfoTypeMap)) { List dtos = replayCompareResultRepository.queryCompareResults(planId, Collections.singletonList(planItemId), new ArrayList<>(subSceneInfoTypeMap.keySet()), - null, - Arrays.asList(RECORD_ID, RECORD_TIME, REPLAY_TIME)); + null, Arrays.asList(RECORD_ID, RECORD_TIME, REPLAY_TIME)); for (CompareResultDto dto : dtos) { String recordId = dto.getRecordId(); QuerySceneInfoResponseType.SubSceneInfoType subSceneInfoType = subSceneInfoTypeMap.get( @@ -145,7 +143,7 @@ public boolean feedbackScene(FeedbackSceneRequest request) { final Integer feedbackType = request.getFeedbackType(); // update scene - List sceneInfos = sceneInfoRepository.querySceneInfo(planId, planItemId); + List sceneInfos = queryCompleteSceneInfo(planId, planItemId); sceneInfos.forEach(sceneInfo -> { if (MapUtils.isNotEmpty(sceneInfo.getSubSceneInfoMap())) { sceneInfo.getSubSceneInfoMap().forEach((groupKey, subSceneInfo) -> { @@ -176,6 +174,36 @@ public boolean feedbackScene(FeedbackSceneRequest request) { return true; } + + public List queryCompleteSceneInfo(String planId, String planItemId) { + List sceneInfos = sceneInfoRepository.querySceneInfo(planId, planItemId); + if (CollectionUtils.isEmpty(sceneInfos)) { + return sceneInfos; + } + + Map recordIdToSubSceneInfoMap = new HashMap<>(); + sceneInfos.forEach(item -> { + Map subSceneInfoMap = item.getSubSceneInfoMap(); + if (MapUtils.isEmpty(subSceneInfoMap)) { + return; + } + subSceneInfoMap.forEach( + (groupKey, subSceneInfo) -> recordIdToSubSceneInfoMap.put(subSceneInfo.getRecordId(), + subSceneInfo) + ); + }); + List recordIds = new ArrayList<>(recordIdToSubSceneInfoMap.keySet()); + List caseSummaries = caseSummaryRepository.queryCaseSummary(planId, planItemId, + recordIds); + for (CaseSummary caseSummary : caseSummaries) { + String recordId = caseSummary.getRecordId(); + List diffDetails = caseSummary.getDiffs(); + SubSceneInfo subSceneInfo = recordIdToSubSceneInfoMap.get(recordId); + subSceneInfo.setDetails(diffDetails); + } + return sceneInfos; + } + private boolean checkAllSubScenes(SceneInfo sceneInfo) { boolean result = true; for (SubSceneInfo subSceneInfo : sceneInfo.getSubSceneInfoMap().values()) { @@ -191,15 +219,13 @@ private boolean passCases(String planId, String planItemId, String groupKey) { LOGGER.info("All the scenes has been passed"); // query other cases in the same subScene List caseSummaryList = caseSummaryRepository.query(planId, planItemId); - List recordIds = - caseSummaryList.stream() - .filter(caseSummary -> String.valueOf(caseSummary.groupKey()).equals(groupKey)) - .map(CaseSummary::getRecordId).collect(Collectors.toList()); + List recordIds = caseSummaryList.stream() + .filter(caseSummary -> String.valueOf(caseSummary.groupKey()).equals(groupKey)) + .map(CaseSummary::getRecordId).collect(Collectors.toList()); // update compareResult List compareResultList = replayCompareResultRepository.queryCompareResults( - planId, - Collections.singletonList(planItemId), recordIds, null, + planId, Collections.singletonList(planItemId), recordIds, null, Arrays.asList(RECORD_ID, RECORD_TIME, REPLAY_TIME)); for (CompareResultDto compareResult : compareResultList) { compareResult.setDiffResultCode(DiffResultCode.COMPARED_WITHOUT_DIFFERENCE); diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/CaseSummaryRepository.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/CaseSummaryRepository.java index 848c1a08..72c7c50e 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/CaseSummaryRepository.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/CaseSummaryRepository.java @@ -10,4 +10,6 @@ public interface CaseSummaryRepository extends RepositoryProvider { boolean upsert(CaseSummary summary); List query(String planId, String planItemId); + + List queryCaseSummary(String planId, String planItemId, List recordIds); } diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/CaseSummaryRepositoryImpl.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/CaseSummaryRepositoryImpl.java index 4aac4921..671ca5c6 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/CaseSummaryRepositoryImpl.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/CaseSummaryRepositoryImpl.java @@ -5,8 +5,10 @@ import com.arextest.web.model.dao.mongodb.iosummary.CaseSummaryCollection; import com.arextest.web.model.dto.iosummary.CaseSummary; import com.arextest.web.model.mapper.CaseSummaryMapper; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.FindAndModifyOptions; import org.springframework.data.mongodb.core.MongoTemplate; @@ -59,4 +61,20 @@ public List query(String planId, String planItemId) { return caseSummaryCollections.stream().map(CaseSummaryMapper.INSTANCE::dtoFromDao) .collect(Collectors.toList()); } + + @Override + public List queryCaseSummary(String planId, String planItemId, + List recordIds) { + if (CollectionUtils.isEmpty(recordIds)) { + return Collections.emptyList(); + } + Query query = Query.query(Criteria.where(PLAN_ID).is(planId).and(PLAN_ITEM_ID) + .is(planItemId).and(RECORD_ID).in(recordIds)); + List caseSummaryCollections = mongoTemplate.find(query, + CaseSummaryCollection.class); + return caseSummaryCollections.stream().map(CaseSummaryMapper.INSTANCE::dtoFromDao) + .collect(Collectors.toList()); + } + + } diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/SceneInfoRepositoryImpl.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/SceneInfoRepositoryImpl.java index f8f2021f..3d896221 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/SceneInfoRepositoryImpl.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/SceneInfoRepositoryImpl.java @@ -68,8 +68,6 @@ public SceneInfo save(SceneInfo sceneInfo) { subSceneInfo.getRecordId()); update.set(toColumnName(groupKeyName, SubSceneInfoDao.Fields.replayId), subSceneInfo.getReplayId()); - update.set(toColumnName(groupKeyName, SubSceneInfoDao.Fields.details), - subSceneInfo.getDetails()); } SceneInfoCollection andModify = mongoTemplate.findAndModify(query, update, diff --git a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/CaseSummaryCollection.java b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/CaseSummaryCollection.java index 90445c29..f7ae06c5 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/CaseSummaryCollection.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/CaseSummaryCollection.java @@ -23,5 +23,8 @@ public class CaseSummaryCollection extends ModelBase { private List diffs; + private Long categoryKey; + private Long groupKey; + private Date dataCreateTime; } diff --git a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/SubSceneInfoDao.java b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/SubSceneInfoDao.java index 92bf07c5..22cc0d76 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/SubSceneInfoDao.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/iosummary/SubSceneInfoDao.java @@ -1,7 +1,6 @@ package com.arextest.web.model.dao.mongodb.iosummary; import com.arextest.web.model.enums.FeedbackTypeEnum; -import java.util.List; import lombok.Data; import lombok.experimental.FieldNameConstants; @@ -12,16 +11,15 @@ @FieldNameConstants public class SubSceneInfoDao { - private int code; private int count; + private int code; private String recordId; private String replayId; + /** * @see FeedbackTypeEnum#getCode() ; */ private Integer feedbackType; private String remark; - - private List details; } diff --git a/pom.xml b/pom.xml index f9867f0f..dfd1051b 100644 --- a/pom.xml +++ b/pom.xml @@ -495,7 +495,7 @@ - 0.6.5.7 + 0.6.5.8 0.1.28 0.0.1 1.2.24