From 8118a482e82a4bded6bead91ee2ead5e233d199d Mon Sep 17 00:00:00 2001 From: rchen9 Date: Wed, 6 Dec 2023 16:01:49 +0800 Subject: [PATCH] feat: add caseTag --- .../ReportPlanStatisticRepositoryImpl.java | 143 ++++++++---------- .../contracts/ReportInitialRequestType.java | 2 + .../ReportPlanStatisticCollection.java | 8 +- .../web/model/dto/ReportPlanStatisticDto.java | 5 +- .../arextest/web/model/mapper/PlanMapper.java | 2 +- 5 files changed, 76 insertions(+), 84 deletions(-) diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/ReportPlanStatisticRepositoryImpl.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/ReportPlanStatisticRepositoryImpl.java index 8ab31274..dcd296e9 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/ReportPlanStatisticRepositoryImpl.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/ReportPlanStatisticRepositoryImpl.java @@ -3,17 +3,17 @@ import com.arextest.web.core.repository.ReportPlanStatisticRepository; import com.arextest.web.core.repository.mongo.util.MongoHelper; import com.arextest.web.model.contract.contracts.QueryPlanStatisticsRequestType; +import com.arextest.web.model.dao.mongodb.ModelBase; import com.arextest.web.model.dao.mongodb.ReportPlanStatisticCollection; +import com.arextest.web.model.dao.mongodb.ReportPlanStatisticCollection.Fields; import com.arextest.web.model.dto.LatestDailySuccessPlanIdDto; import com.arextest.web.model.dto.ReportPlanStatisticDto; -import com.arextest.web.model.enums.ReplayStatusType; import com.arextest.web.model.mapper.PlanMapper; import com.mongodb.BasicDBObject; import com.mongodb.client.result.DeleteResult; import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -46,31 +46,7 @@ @Component public class ReportPlanStatisticRepositoryImpl implements ReportPlanStatisticRepository { - private static final String PLAN_ID = "planId"; - private static final String PLAN_NAME = "planName"; - private static final String STATUS = "status"; - private static final String APP_ID = "appId"; - private static final String APP_NAME = "appName"; - private static final String CREATOR = "creator"; - private static final String TARGET_IMAGE_ID = "targetImageId"; - private static final String TARGET_IMAGE_NAME = "targetImageName"; - private static final String CASE_SOURCE_TYPE = "caseSourceType"; - private static final String SOURCE_ENV = "sourceEnv"; - private static final String TARGET_ENV = "targetEnv"; - private static final String SOURCE_HOST = "sourceHost"; - private static final String TARGET_HOST = "targetHost"; - private static final String CORE_VERSION = "coreVersion"; - private static final String EXT_VERSION = "extVersion"; - private static final String CASE_RECORD_VERSION = "caseRecordVersion"; - private static final String REPLAY_START_TIME = "replayStartTime"; - private static final String REPLAY_END_TIME = "replayEndTime"; - private static final String CASE_START_TIME = "caseStartTime"; - private static final String CASE_END_TIME = "caseEndTime"; - private static final String DATA_CHANGE_CREATE_TIME = "dataChangeCreateTime"; - private static final String TOTAL_CASE_COUNT = "totalCaseCount"; private static final String DATE_TIME = "dateTime"; - private static final String CUSTOM_TAGS = "customTags"; - private static final String ERROR_MESSAGE = "errorMessage"; @Resource private MongoTemplate mongoTemplate; @@ -78,7 +54,8 @@ public class ReportPlanStatisticRepositoryImpl implements ReportPlanStatisticRep @Override public List findByDataCreateTimeBetween(Date startTime, Date endTime) { Query query = new Query(); - Criteria criteria = Criteria.where(DATA_CHANGE_CREATE_TIME).gte(startTime).lte(endTime); + Criteria criteria = Criteria.where(ModelBase.Fields.dataChangeCreateTime).gte(startTime) + .lte(endTime); query.addCriteria(criteria); List result = mongoTemplate.find(query, ReportPlanStatisticCollection.class); @@ -91,7 +68,7 @@ public ReportPlanStatisticDto findByPlanId(String planId) { return null; } ReportPlanStatisticCollection result = - mongoTemplate.findOne(Query.query(Criteria.where(PLAN_ID).is(planId)), + mongoTemplate.findOne(Query.query(Criteria.where(Fields.planId).is(planId)), ReportPlanStatisticCollection.class); return PlanMapper.INSTANCE.dtoFromDao(result); } @@ -103,74 +80,78 @@ public boolean findAndModifyBaseInfo(ReportPlanStatisticDto result) { } Update update = MongoHelper.getUpdate(); - update.setOnInsert(DATA_CHANGE_CREATE_TIME, System.currentTimeMillis()); + update.setOnInsert(ModelBase.Fields.dataChangeCreateTime, System.currentTimeMillis()); if (result.getCaseStartTime() != null) { - update.set(CASE_START_TIME, result.getCaseStartTime()); + update.set(Fields.caseStartTime, result.getCaseStartTime()); } if (result.getCaseEndTime() != null) { - update.set(CASE_END_TIME, result.getCaseEndTime()); + update.set(Fields.caseEndTime, result.getCaseEndTime()); } if (!StringUtils.isEmpty(result.getPlanName())) { - update.set(PLAN_NAME, result.getPlanName()); + update.set(Fields.planName, result.getPlanName()); } if (result.getStatus() != null) { - update.set(STATUS, result.getStatus()); + update.set(Fields.status, result.getStatus()); } if (!StringUtils.isEmpty(result.getAppId())) { - update.set(APP_ID, result.getAppId()); + update.set(Fields.appId, result.getAppId()); } if (!StringUtils.isEmpty(result.getAppName())) { - update.set(APP_NAME, result.getAppName()); + update.set(Fields.appName, result.getAppName()); } if (!StringUtils.isEmpty(result.getCreator())) { - update.set(CREATOR, result.getCreator()); + update.set(Fields.creator, result.getCreator()); } if (result.getTargetImageId() != null) { - update.set(TARGET_IMAGE_ID, result.getTargetImageId()); + update.set(Fields.targetImageId, result.getTargetImageId()); } if (!StringUtils.isEmpty(result.getTargetImageName())) { - update.set(TARGET_IMAGE_NAME, result.getTargetImageName()); + update.set(Fields.targetImageName, result.getTargetImageName()); } if (result.getCaseSourceType() != null) { - update.set(CASE_SOURCE_TYPE, result.getCaseSourceType()); + update.set(Fields.caseSourceType, result.getCaseSourceType()); } if (!StringUtils.isEmpty(result.getSourceEnv())) { - update.set(SOURCE_ENV, result.getSourceEnv()); + update.set(Fields.sourceEnv, result.getSourceEnv()); } if (!StringUtils.isEmpty(result.getTargetEnv())) { - update.set(TARGET_ENV, result.getTargetEnv()); + update.set(Fields.targetEnv, result.getTargetEnv()); } if (!StringUtils.isEmpty(result.getSourceHost())) { - update.set(SOURCE_HOST, result.getSourceHost()); + update.set(Fields.sourceHost, result.getSourceHost()); } if (!StringUtils.isEmpty(result.getTargetHost())) { - update.set(TARGET_HOST, result.getTargetHost()); + update.set(Fields.targetHost, result.getTargetHost()); } if (!StringUtils.isEmpty(result.getCoreVersion())) { - update.set(CORE_VERSION, result.getCoreVersion()); + update.set(Fields.coreVersion, result.getCoreVersion()); } if (!StringUtils.isEmpty(result.getExtVersion())) { - update.set(EXT_VERSION, result.getExtVersion()); + update.set(Fields.extVersion, result.getExtVersion()); } if (!StringUtils.isEmpty(result.getCaseRecordVersion())) { - update.set(CASE_RECORD_VERSION, result.getCaseRecordVersion()); + update.set(Fields.caseRecordVersion, result.getCaseRecordVersion()); } if (result.getTotalCaseCount() != null) { - update.set(TOTAL_CASE_COUNT, result.getTotalCaseCount()); + update.set(Fields.totalCaseCount, result.getTotalCaseCount()); } if (result.getReplayStartTime() != null) { - update.set(REPLAY_START_TIME, result.getReplayStartTime()); + update.set(Fields.replayStartTime, result.getReplayStartTime()); } if (result.getReplayEndTime() != null) { - update.set(REPLAY_END_TIME, result.getReplayEndTime()); + update.set(Fields.replayEndTime, result.getReplayEndTime()); } if (MapUtils.isNotEmpty(result.getCustomTags())) { - update.set(CUSTOM_TAGS, result.getCustomTags()); + update.set(Fields.customTags, result.getCustomTags()); + } + if (MapUtils.isNotEmpty(result.getCaseTags())) { + update.set(Fields.caseTags, result.getCaseTags()); } ReportPlanStatisticCollection dao = - mongoTemplate.findAndModify(Query.query(Criteria.where(PLAN_ID).is(result.getPlanId())), + mongoTemplate.findAndModify( + Query.query(Criteria.where(Fields.planId).is(result.getPlanId())), update, FindAndModifyOptions.options().returnNew(true).upsert(true), ReportPlanStatisticCollection.class); @@ -189,7 +170,7 @@ public Pair, Long> pageQueryPlanStatistic( Pageable pageable = PageRequest.of(request.getPageIndex() - 1, request.getPageSize(), - Sort.by(Sort.Direction.DESC, PLAN_ID)); + Sort.by(Sort.Direction.DESC, Fields.planId)); query.with(pageable); List daos = mongoTemplate.find(query, @@ -207,7 +188,7 @@ public Long findReplayCount() { @Override public Long findReplayCountByAppId(String appId) { - Query query = Query.query(Criteria.where(APP_ID).is(appId)); + Query query = Query.query(Criteria.where(Fields.appId).is(appId)); return mongoTemplate.count(query, ReportPlanStatisticCollection.class); } @@ -233,12 +214,14 @@ public List findLatestSuccessPlanId(String rangeField, L SortOperation sortOperation = Aggregation.sort(sort); operations.add(sortOperation); - GroupOperation groupOperation = Aggregation.group(APP_ID, APP_NAME).first(PLAN_ID).as(PLAN_ID) - .first(DATA_CHANGE_CREATE_TIME).as(DATA_CHANGE_CREATE_TIME); + GroupOperation groupOperation = Aggregation.group(Fields.appId, Fields.appName) + .first(Fields.planId).as(Fields.planId) + .first(ModelBase.Fields.dataChangeCreateTime).as(ModelBase.Fields.dataChangeCreateTime); operations.add(groupOperation); ProjectionOperation projectionOperation = - Aggregation.project(PLAN_ID, DATA_CHANGE_CREATE_TIME, APP_ID, APP_NAME); + Aggregation.project(Fields.planId, ModelBase.Fields.dataChangeCreateTime, Fields.appId, + Fields.appName); operations.add(projectionOperation); AggregationResults aggregate = mongoTemplate.aggregate( Aggregation.newAggregation(operations), @@ -275,7 +258,8 @@ public List findLatestDailySuccessPlanId(String ran SortOperation sortOperation = Aggregation.sort(sort); operations.add(sortOperation); - ProjectionOperation projectionOperation = Aggregation.project(PLAN_ID, DATA_CHANGE_CREATE_TIME, + ProjectionOperation projectionOperation = Aggregation.project(Fields.planId, + ModelBase.Fields.dataChangeCreateTime, groupField) .and(DateOperators.DateToString.dateOf(new AggregationExpression() { @Override @@ -289,7 +273,8 @@ public Document toDocument(AggregationOperationContext aggregationOperationConte GroupOperation groupOperation = Aggregation.group(DATE_TIME, groupField).first(groupField).as(groupField).first(DATE_TIME) .as(DATE_TIME) - .first(PLAN_ID).as(PLAN_ID).first(DATA_CHANGE_CREATE_TIME).as(DATA_CHANGE_CREATE_TIME); + .first(Fields.planId).as(Fields.planId).first(ModelBase.Fields.dataChangeCreateTime) + .as(ModelBase.Fields.dataChangeCreateTime); operations.add(groupOperation); AggregationResults aggregate = mongoTemplate.aggregate( @@ -308,22 +293,22 @@ public ReportPlanStatisticDto changePlanStatus(String planId, Integer status, } Update update = MongoHelper.getUpdate(); if (status != null) { - update.set(STATUS, status); + update.set(Fields.status, status); } if (totalCaseCount != null) { - update.set(TOTAL_CASE_COUNT, totalCaseCount); + update.set(Fields.totalCaseCount, totalCaseCount); } if (errorMessage != null) { - update.set(ERROR_MESSAGE, errorMessage); + update.set(Fields.errorMessage, errorMessage); } if (!rerun) { - update.set(REPLAY_END_TIME, System.currentTimeMillis()); + update.set(Fields.replayEndTime, System.currentTimeMillis()); } - if (update.getUpdateObject().keySet().size() == 0) { + if (update.getUpdateObject().keySet().isEmpty()) { return null; } ReportPlanStatisticCollection plan = - mongoTemplate.findAndModify(Query.query(Criteria.where(PLAN_ID).is(planId)), update, + mongoTemplate.findAndModify(Query.query(Criteria.where(Fields.planId).is(planId)), update, FindAndModifyOptions.options().returnNew(true).upsert(true), ReportPlanStatisticCollection.class); return PlanMapper.INSTANCE.dtoFromDao(plan); @@ -331,17 +316,18 @@ public ReportPlanStatisticDto changePlanStatus(String planId, Integer status, @Override public boolean deletePlan(String planId) { - Query query = Query.query(Criteria.where(PLAN_ID).is(planId)); + Query query = Query.query(Criteria.where(Fields.planId).is(planId)); DeleteResult deleteResult = mongoTemplate.remove(query, ReportPlanStatisticCollection.class); return deleteResult.getDeletedCount() > 0; } @Override public boolean removeErrorMsg(String planId) { - Query query = Query.query(Criteria.where(PLAN_ID).is(planId)); + Query query = Query.query(Criteria.where(Fields.planId).is(planId)); Update update = MongoHelper.getUpdate(); - update.set(ERROR_MESSAGE, null); - return mongoTemplate.updateMulti(query, update, ReportPlanStatisticCollection.class).getMatchedCount() > 0; + update.set(Fields.errorMessage, null); + return mongoTemplate.updateMulti(query, update, ReportPlanStatisticCollection.class) + .getMatchedCount() > 0; } private Query fillFilterConditions(QueryPlanStatisticsRequestType request) { @@ -350,15 +336,15 @@ private Query fillFilterConditions(QueryPlanStatisticsRequestType request) { return query; } if (request.getPlanId() != null) { - query.addCriteria(Criteria.where(PLAN_ID).is(request.getPlanId())); + query.addCriteria(Criteria.where(Fields.planId).is(request.getPlanId())); } if (!StringUtils.isEmpty(request.getAppId())) { - query.addCriteria(Criteria.where(APP_ID).is(request.getAppId())); + query.addCriteria(Criteria.where(Fields.appId).is(request.getAppId())); } if (!StringUtils.isEmpty(request.getImageId())) { - query.addCriteria(Criteria.where(TARGET_IMAGE_ID).is(request.getImageId())); + query.addCriteria(Criteria.where(Fields.targetImageId).is(request.getImageId())); } return query; @@ -371,10 +357,11 @@ private ReportPlanStatisticDto covertToReportPlanStatisticDto(BasicDBObject basi if (basicDBObject == null) { return reportPlanStatisticDto; } - reportPlanStatisticDto.setAppId(basicDBObject.getString(APP_ID)); - reportPlanStatisticDto.setAppName(basicDBObject.getString(APP_NAME)); - reportPlanStatisticDto.setPlanId(basicDBObject.getString(PLAN_ID)); - reportPlanStatisticDto.setDataChangeCreateTime(basicDBObject.getLong(DATA_CHANGE_CREATE_TIME)); + reportPlanStatisticDto.setAppId(basicDBObject.getString(Fields.appId)); + reportPlanStatisticDto.setAppName(basicDBObject.getString(Fields.appName)); + reportPlanStatisticDto.setPlanId(basicDBObject.getString(Fields.planId)); + reportPlanStatisticDto.setDataChangeCreateTime( + basicDBObject.getLong(ModelBase.Fields.dataChangeCreateTime)); return reportPlanStatisticDto; } @@ -385,10 +372,10 @@ private LatestDailySuccessPlanIdDto covertToLatestDailySuccessPlanIdDto( return latestDailySuccessPlanIdDto; } latestDailySuccessPlanIdDto.setDateTime(basicDBObject.getString(DATE_TIME)); - latestDailySuccessPlanIdDto.setAppId(basicDBObject.getString(APP_ID)); - latestDailySuccessPlanIdDto.setPlanId(basicDBObject.getString(PLAN_ID)); + latestDailySuccessPlanIdDto.setAppId(basicDBObject.getString(Fields.appId)); + latestDailySuccessPlanIdDto.setPlanId(basicDBObject.getString(Fields.planId)); latestDailySuccessPlanIdDto.setDataChangeCreateTime( - basicDBObject.getLong(DATA_CHANGE_CREATE_TIME)); + basicDBObject.getLong(ModelBase.Fields.dataChangeCreateTime)); return latestDailySuccessPlanIdDto; } diff --git a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/ReportInitialRequestType.java b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/ReportInitialRequestType.java index 8810e8ab..639b08b0 100644 --- a/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/ReportInitialRequestType.java +++ b/arex-web-model-contract/src/main/java/com/arextest/web/model/contract/contracts/ReportInitialRequestType.java @@ -44,6 +44,8 @@ public static class CaseSourceEnvironment { private Integer caseSourceType; + private Map caseTags; + private Long caseStartTime; private Long caseEndTime; diff --git a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/ReportPlanStatisticCollection.java b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/ReportPlanStatisticCollection.java index 3a29da64..c8486bc6 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/ReportPlanStatisticCollection.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/dao/mongodb/ReportPlanStatisticCollection.java @@ -25,22 +25,22 @@ public class ReportPlanStatisticCollection extends ModelBase { private String targetImageId; private String targetImageName; - private Integer caseSourceType; private String sourceEnv; private String targetEnv; private String sourceHost; private String targetHost; private String coreVersion; - private String extVersion; + private Integer caseSourceType; private String caseRecordVersion; + private Map caseTags; + private Long caseStartTime; + private Long caseEndTime; private Long replayStartTime; private Long replayEndTime; - private Long caseStartTime; - private Long caseEndTime; private Integer totalCaseCount; private String errorMessage; diff --git a/arex-web-model/src/main/java/com/arextest/web/model/dto/ReportPlanStatisticDto.java b/arex-web-model/src/main/java/com/arextest/web/model/dto/ReportPlanStatisticDto.java index 04c5a084..5e2fa066 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/dto/ReportPlanStatisticDto.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/dto/ReportPlanStatisticDto.java @@ -17,7 +17,6 @@ public class ReportPlanStatisticDto { private String targetImageId; private String targetImageName; - private Integer caseSourceType; private String sourceEnv; private String targetEnv; private String sourceHost; @@ -33,6 +32,10 @@ public class ReportPlanStatisticDto { private Long replayEndTime; + private Integer caseSourceType; + + private Map caseTags; + private Long caseStartTime; private Long caseEndTime; diff --git a/arex-web-model/src/main/java/com/arextest/web/model/mapper/PlanMapper.java b/arex-web-model/src/main/java/com/arextest/web/model/mapper/PlanMapper.java index 39258b99..2960785a 100644 --- a/arex-web-model/src/main/java/com/arextest/web/model/mapper/PlanMapper.java +++ b/arex-web-model/src/main/java/com/arextest/web/model/mapper/PlanMapper.java @@ -8,7 +8,6 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.Named; import org.mapstruct.factory.Mappers; @Mapper @@ -23,6 +22,7 @@ public interface PlanMapper { @Mapping(target = "sourceHost", source = "hostEnv.sourceHost"), @Mapping(target = "targetHost", source = "hostEnv.targetHost"), @Mapping(target = "caseSourceType", source = "caseSourceEnv.caseSourceType"), + @Mapping(target = "caseTags", source = "caseSourceEnv.caseTags"), @Mapping(target = "caseStartTime", source = "caseSourceEnv.caseStartTime"), @Mapping(target = "caseEndTime", source = "caseSourceEnv.caseEndTime"), @Mapping(target = "targetImageId", source = "targetImage.targetImageId"),