feat(工作台): 接口变更列表格式完毕

This commit is contained in:
guoyuqi 2024-11-12 19:16:16 +08:00 committed by Craftsman
parent c87ff4cb74
commit dc58054aef
10 changed files with 273 additions and 57 deletions

View File

@ -0,0 +1,20 @@
package io.metersphere.api.dto.definition;
import io.metersphere.api.domain.ApiDefinition;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author guoyuqi
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class ApiDefinitionUpdateDTO extends ApiDefinition {
@Schema(description = "用例数")
private int caseTotal;
@Schema(description = "场景数")
private int scenarioTotal;
}

View File

@ -0,0 +1,18 @@
package io.metersphere.api.dto.definition;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiRefSourceCountDTO {
@Schema(description = "被引用的资源ID")
private String sourceId;
@Schema(description = "引用者数量")
private int count;
}

View File

@ -115,4 +115,15 @@ public interface ExtApiDefinitionMapper {
List<ProjectUserCreateCount> userCreateApiCount(@Param("projectId") String projectId, @Param("startTime") long startTime, @Param("endTime") long endTime, @Param("userIds") Set<String> userIds); List<ProjectUserCreateCount> userCreateApiCount(@Param("projectId") String projectId, @Param("startTime") long startTime, @Param("endTime") long endTime, @Param("userIds") Set<String> userIds);
/**
* 获取根据时间过滤有更新的api
*
* @param projectId xiangmuid
* @param startTime 时间过滤条件
* @param endTime 时间过滤条件
* @return List<ApiDefinitionUpdateDTO>
*/
List<ApiDefinitionUpdateDTO> getUpdateApiList(@Param("projectId") String projectId, @Param("startTime") long startTime, @Param("endTime") long endTime);
List<ApiRefSourceCountDTO> scenarioRefApiCount(@Param("projectId") String projectId, @Param("resourceIds") List<String> resourceIds);
} }

View File

@ -803,4 +803,26 @@
</if> </if>
group by api_definition.create_user; group by api_definition.create_user;
</select> </select>
<select id="getUpdateApiList" resultType="io.metersphere.api.dto.definition.ApiDefinitionUpdateDTO">
SELECT api_definition.id, api_definition.name, api_definition.update_time
FROM api_definition
WHERE api_definition.deleted = false
AND api_definition.project_id = #{projectId}
AND api_definition.update_time BETWEEN #{startTime} AND #{endTime} order by api_definition.update_time desc;
</select>
<select id="scenarioRefApiCount" resultType="io.metersphere.api.dto.definition.ApiRefSourceCountDTO">
select
ass.resource_id as sourceId, COUNT(DISTINCT ass.scenario_id) as count
from api_scenario_step ass
where ass.step_type = 'API'
and ass.project_id = #{projectId}
and ass.ref_type='REF'
and ass.resource_id in
<foreach collection="resourceIds" item="resourceId" separator="," open="(" close=")">
#{resourceId}
</foreach>
group by ass.resource_id;
</select>
</mapper> </mapper>

View File

@ -1,19 +1,14 @@
package io.metersphere.dashboard.controller; package io.metersphere.dashboard.controller;
import com.alibaba.excel.util.StringUtils;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.definition.ApiDefinitionUpdateDTO;
import io.metersphere.dashboard.dto.LayoutDTO; import io.metersphere.dashboard.dto.LayoutDTO;
import io.metersphere.dashboard.request.DashboardFrontPageRequest; import io.metersphere.dashboard.request.DashboardFrontPageRequest;
import io.metersphere.dashboard.response.OverViewCountDTO; import io.metersphere.dashboard.response.OverViewCountDTO;
import io.metersphere.dashboard.response.StatisticsDTO; import io.metersphere.dashboard.response.StatisticsDTO;
import io.metersphere.dashboard.service.DashboardService; import io.metersphere.dashboard.service.DashboardService;
import io.metersphere.functional.constants.CaseReviewStatus;
import io.metersphere.functional.dto.CaseReviewDTO; import io.metersphere.functional.dto.CaseReviewDTO;
import io.metersphere.functional.request.CaseReviewPageRequest;
import io.metersphere.functional.service.CaseReviewService;
import io.metersphere.sdk.dto.CombineCondition;
import io.metersphere.sdk.dto.CombineSearch;
import io.metersphere.system.security.CheckOwner; import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
@ -21,13 +16,10 @@ import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
@Tag(name = "工作台-首页") @Tag(name = "工作台-首页")
@RestController @RestController
@ -36,8 +28,6 @@ public class DashboardController {
@Resource @Resource
private DashboardService dashboardService; private DashboardService dashboardService;
@Resource
private CaseReviewService caseReviewService;
@PostMapping("/layout/edit/{organizationId}") @PostMapping("/layout/edit/{organizationId}")
@Operation(summary = "编辑用户布局") @Operation(summary = "编辑用户布局")
@ -106,49 +96,16 @@ public class DashboardController {
@Operation(summary = "待我评审") @Operation(summary = "待我评审")
@CheckOwner(resourceId = "#request.getOrganizationId()", resourceType = "organization") @CheckOwner(resourceId = "#request.getOrganizationId()", resourceType = "organization")
public Pager<List<CaseReviewDTO>> getFunctionalCasePage(@Validated @RequestBody DashboardFrontPageRequest request) { public Pager<List<CaseReviewDTO>> getFunctionalCasePage(@Validated @RequestBody DashboardFrontPageRequest request) {
CaseReviewPageRequest reviewRequest = getCaseReviewPageRequest(request); return dashboardService.getFunctionalCasePage(request);
Page<Object> page = PageHelper.startPage(reviewRequest.getCurrent(), reviewRequest.getPageSize(),
StringUtils.isNotBlank(reviewRequest.getSortString()) ? reviewRequest.getSortString() : "pos desc");
return PageUtils.setPageInfo(page, caseReviewService.getCaseReviewPage(reviewRequest));
} }
@NotNull @PostMapping("/api_change")
private static CaseReviewPageRequest getCaseReviewPageRequest(DashboardFrontPageRequest request) { @Operation(summary = "接口变更")
String projectId = request.getProjectIds().getFirst(); @CheckOwner(resourceId = "#request.getOrganizationId()", resourceType = "organization")
CaseReviewPageRequest reviewRequest = new CaseReviewPageRequest(); public Pager<List<ApiDefinitionUpdateDTO>> getApiUpdatePage(@Validated @RequestBody DashboardFrontPageRequest request) {
reviewRequest.setProjectId(projectId); Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
reviewRequest.setPageSize(request.getPageSize()); return PageUtils.setPageInfo(page, dashboardService.getApiUpdatePage(request));
reviewRequest.setCurrent(request.getCurrent());
reviewRequest.setSort(request.getSort());
CombineSearch combineSearch = getCombineSearch(request);
reviewRequest.setCombineSearch(combineSearch);
return reviewRequest;
} }
@NotNull
private static CombineSearch getCombineSearch(DashboardFrontPageRequest request) {
CombineSearch combineSearch = new CombineSearch();
combineSearch.setSearchMode(CombineSearch.SearchMode.AND.name());
List<CombineCondition> conditions = new ArrayList<>();
CombineCondition userCombineCondition = getCombineCondition(List.of(Objects.requireNonNull(SessionUtils.getUserId())), "reviewers",CombineCondition.CombineConditionOperator.IN.toString());
conditions.add(userCombineCondition);
CombineCondition statusCombineCondition = getCombineCondition(List.of(CaseReviewStatus.PREPARED.toString(), CaseReviewStatus.UNDERWAY.toString()), "status",CombineCondition.CombineConditionOperator.IN.toString());
conditions.add(statusCombineCondition);
CombineCondition createTimeCombineCondition = getCombineCondition(List.of(request.getToStartTime(), request.getToEndTime()), "createTime",CombineCondition.CombineConditionOperator.BETWEEN.toString());
conditions.add(createTimeCombineCondition);
combineSearch.setConditions(conditions);
return combineSearch;
}
@NotNull
private static CombineCondition getCombineCondition(List<Object> value, String reviewers, String operator) {
CombineCondition userCombineCondition = new CombineCondition();
userCombineCondition.setValue(value);
userCombineCondition.setName(reviewers);
userCombineCondition.setOperator(operator);
userCombineCondition.setCustomField(false);
userCombineCondition.setCustomFieldType("");
return userCombineCondition;
}
} }

View File

@ -20,4 +20,7 @@ public class StatisticsDTO {
@Schema(description = "百分比集合") @Schema(description = "百分比集合")
private List<StatusPercentDTO>statusPercentList; private List<StatusPercentDTO>statusPercentList;
@Schema(description = "错误码")
private int errorCode;
} }

View File

@ -0,0 +1,29 @@
package io.metersphere.dashboard.result;
import io.metersphere.sdk.exception.IResultCode;
/**
* @author jianxing
*/
public enum DashboardResultCode implements IResultCode {
NO_PROJECT_PERMISSION(109001, "no_project_permission");
private final int code;
private final String message;
DashboardResultCode(int code, String message) {
this.code = code;
this.message = message;
}
@Override
public int getCode() {
return code;
}
@Override
public String getMessage() {
return getTranslationMessage(this.message);
}
}

View File

@ -1,5 +1,10 @@
package io.metersphere.dashboard.service; package io.metersphere.dashboard.service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.api.dto.definition.ApiDefinitionUpdateDTO;
import io.metersphere.api.dto.definition.ApiRefSourceCountDTO;
import io.metersphere.api.mapper.ExtApiDefinitionMapper; import io.metersphere.api.mapper.ExtApiDefinitionMapper;
import io.metersphere.api.mapper.ExtApiScenarioMapper; import io.metersphere.api.mapper.ExtApiScenarioMapper;
import io.metersphere.api.mapper.ExtApiTestCaseMapper; import io.metersphere.api.mapper.ExtApiTestCaseMapper;
@ -17,9 +22,12 @@ import io.metersphere.dashboard.response.OverViewCountDTO;
import io.metersphere.dashboard.response.StatisticsDTO; import io.metersphere.dashboard.response.StatisticsDTO;
import io.metersphere.functional.constants.CaseReviewStatus; import io.metersphere.functional.constants.CaseReviewStatus;
import io.metersphere.functional.constants.FunctionalCaseReviewStatus; import io.metersphere.functional.constants.FunctionalCaseReviewStatus;
import io.metersphere.functional.dto.CaseReviewDTO;
import io.metersphere.functional.dto.FunctionalCaseStatisticDTO; import io.metersphere.functional.dto.FunctionalCaseStatisticDTO;
import io.metersphere.functional.mapper.ExtCaseReviewMapper; import io.metersphere.functional.mapper.ExtCaseReviewMapper;
import io.metersphere.functional.mapper.ExtFunctionalCaseMapper; import io.metersphere.functional.mapper.ExtFunctionalCaseMapper;
import io.metersphere.functional.request.CaseReviewPageRequest;
import io.metersphere.functional.service.CaseReviewService;
import io.metersphere.plan.mapper.ExtTestPlanMapper; import io.metersphere.plan.mapper.ExtTestPlanMapper;
import io.metersphere.plugin.platform.dto.SelectOption; import io.metersphere.plugin.platform.dto.SelectOption;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
@ -32,6 +40,9 @@ import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.project.service.ProjectService; import io.metersphere.project.service.ProjectService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.CombineCondition;
import io.metersphere.sdk.dto.CombineSearch;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.UserLayout; import io.metersphere.system.domain.UserLayout;
@ -39,6 +50,9 @@ import io.metersphere.system.domain.UserLayoutExample;
import io.metersphere.system.dto.user.ProjectUserMemberDTO; import io.metersphere.system.dto.user.ProjectUserMemberDTO;
import io.metersphere.system.mapper.UserLayoutMapper; import io.metersphere.system.mapper.UserLayoutMapper;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -51,6 +65,8 @@ import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static io.metersphere.dashboard.result.DashboardResultCode.NO_PROJECT_PERMISSION;
/** /**
* @author guoyuqi * @author guoyuqi
*/ */
@ -90,6 +106,8 @@ public class DashboardService {
private BugStatusService bugStatusService; private BugStatusService bugStatusService;
@Resource @Resource
private ProjectApplicationService projectApplicationService; private ProjectApplicationService projectApplicationService;
@Resource
private CaseReviewService caseReviewService;
public static final String FUNCTIONAL = "FUNCTIONAL"; // 功能用例 public static final String FUNCTIONAL = "FUNCTIONAL"; // 功能用例
@ -324,6 +342,9 @@ public class DashboardService {
} else { } else {
List<String> projectIds = allProjectIds.stream().distinct().toList(); List<String> projectIds = allProjectIds.stream().distinct().toList();
getUserProjectIdName = extProjectMapper.getUserProjectIdName(null, projectIds, userId); getUserProjectIdName = extProjectMapper.getUserProjectIdName(null, projectIds, userId);
if (CollectionUtils.isEmpty(getUserProjectIdName)) {
getUserProjectIdName = extProjectMapper.getUserProjectIdName(organizationId, null, userId);
}
} }
Map<String, Project> projectMap = getUserProjectIdName.stream().collect(Collectors.toMap(Project::getId, t -> t)); Map<String, Project> projectMap = getUserProjectIdName.stream().collect(Collectors.toMap(Project::getId, t -> t));
List<String> handleUsers = allHandleUsers.stream().distinct().toList(); List<String> handleUsers = allHandleUsers.stream().distinct().toList();
@ -537,7 +558,10 @@ public class DashboardService {
public StatisticsDTO projectCaseCount(DashboardFrontPageRequest request) { public StatisticsDTO projectCaseCount(DashboardFrontPageRequest request) {
String projectId = request.getProjectIds().getFirst(); String projectId = request.getProjectIds().getFirst();
StatisticsDTO statisticsDTO = new StatisticsDTO(); StatisticsDTO statisticsDTO = new StatisticsDTO();
if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) return statisticsDTO; if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) {
statisticsDTO.setErrorCode(NO_PROJECT_PERMISSION.getCode());
return statisticsDTO;
}
List<StatusPercentDTO> statusPercentList = new ArrayList<>(); List<StatusPercentDTO> statusPercentList = new ArrayList<>();
Long toStartTime = request.getToStartTime(); Long toStartTime = request.getToStartTime();
Long toEndTime = request.getToEndTime(); Long toEndTime = request.getToEndTime();
@ -637,7 +661,10 @@ public class DashboardService {
public StatisticsDTO projectAssociateCaseCount(DashboardFrontPageRequest request) { public StatisticsDTO projectAssociateCaseCount(DashboardFrontPageRequest request) {
String projectId = request.getProjectIds().getFirst(); String projectId = request.getProjectIds().getFirst();
StatisticsDTO statisticsDTO = new StatisticsDTO(); StatisticsDTO statisticsDTO = new StatisticsDTO();
if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) return statisticsDTO; if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) {
statisticsDTO.setErrorCode(NO_PROJECT_PERMISSION.getCode());
return statisticsDTO;
}
Long toStartTime = request.getToStartTime(); Long toStartTime = request.getToStartTime();
Long toEndTime = request.getToEndTime(); Long toEndTime = request.getToEndTime();
long caseTestCount = extFunctionalCaseMapper.caseTestCount(projectId, toStartTime, toEndTime); long caseTestCount = extFunctionalCaseMapper.caseTestCount(projectId, toStartTime, toEndTime);
@ -784,7 +811,10 @@ public class DashboardService {
public StatisticsDTO projectReviewCaseCount(DashboardFrontPageRequest request) { public StatisticsDTO projectReviewCaseCount(DashboardFrontPageRequest request) {
String projectId = request.getProjectIds().getFirst(); String projectId = request.getProjectIds().getFirst();
StatisticsDTO statisticsDTO = new StatisticsDTO(); StatisticsDTO statisticsDTO = new StatisticsDTO();
if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) return statisticsDTO; if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) {
statisticsDTO.setErrorCode(NO_PROJECT_PERMISSION.getCode());
return statisticsDTO;
}
Long toStartTime = request.getToStartTime(); Long toStartTime = request.getToStartTime();
Long toEndTime = request.getToEndTime(); Long toEndTime = request.getToEndTime();
List<FunctionalCaseStatisticDTO> statisticListByProjectId = extFunctionalCaseMapper.getStatisticListByProjectId(projectId, toStartTime, toEndTime); List<FunctionalCaseStatisticDTO> statisticListByProjectId = extFunctionalCaseMapper.getStatisticListByProjectId(projectId, toStartTime, toEndTime);
@ -830,7 +860,7 @@ public class DashboardService {
private static List<NameCountDTO> getCoverList(int totalCount, int coverCount, int unCoverCount) { private static List<NameCountDTO> getCoverList(int totalCount, int coverCount, int unCoverCount) {
List<NameCountDTO> coverList = new ArrayList<>(); List<NameCountDTO> coverList = new ArrayList<>();
NameCountDTO coverRate = new NameCountDTO(); NameCountDTO coverRate = new NameCountDTO();
if (totalCount>0) { if (totalCount > 0) {
BigDecimal divide = BigDecimal.valueOf(coverCount).divide(BigDecimal.valueOf(totalCount), 0, RoundingMode.HALF_UP); BigDecimal divide = BigDecimal.valueOf(coverCount).divide(BigDecimal.valueOf(totalCount), 0, RoundingMode.HALF_UP);
coverRate.setCount(Integer.valueOf(String.valueOf(divide.multiply(BigDecimal.valueOf(100))))); coverRate.setCount(Integer.valueOf(String.valueOf(divide.multiply(BigDecimal.valueOf(100)))));
} }
@ -854,6 +884,94 @@ public class DashboardService {
statusNameMap.put(CaseReviewStatus.COMPLETED.toString(), Translator.get("case_review.completed")); statusNameMap.put(CaseReviewStatus.COMPLETED.toString(), Translator.get("case_review.completed"));
return statusNameMap; return statusNameMap;
} }
public Pager<List<CaseReviewDTO>> getFunctionalCasePage(DashboardFrontPageRequest request) {
String projectId = request.getProjectIds().getFirst();
if (Boolean.FALSE.equals(checkModule(projectId, FUNCTIONAL_CASE_MODULE))) {
throw new MSException(NO_PROJECT_PERMISSION);
}
CaseReviewPageRequest reviewRequest = getCaseReviewPageRequest(request);
Page<Object> page = PageHelper.startPage(reviewRequest.getCurrent(), reviewRequest.getPageSize(),
com.alibaba.excel.util.StringUtils.isNotBlank(reviewRequest.getSortString()) ? reviewRequest.getSortString() : "pos desc");
return PageUtils.setPageInfo(page, caseReviewService.getCaseReviewPage(reviewRequest));
}
@NotNull
private static CaseReviewPageRequest getCaseReviewPageRequest(DashboardFrontPageRequest request) {
String projectId = request.getProjectIds().getFirst();
CaseReviewPageRequest reviewRequest = new CaseReviewPageRequest();
reviewRequest.setProjectId(projectId);
reviewRequest.setPageSize(request.getPageSize());
reviewRequest.setCurrent(request.getCurrent());
reviewRequest.setSort(request.getSort());
CombineSearch combineSearch = getCombineSearch(request);
reviewRequest.setCombineSearch(combineSearch);
return reviewRequest;
}
@NotNull
private static CombineSearch getCombineSearch(DashboardFrontPageRequest request) {
CombineSearch combineSearch = new CombineSearch();
combineSearch.setSearchMode(CombineSearch.SearchMode.AND.name());
List<CombineCondition> conditions = new ArrayList<>();
CombineCondition userCombineCondition = getCombineCondition(List.of(Objects.requireNonNull(SessionUtils.getUserId())), "reviewers", CombineCondition.CombineConditionOperator.IN.toString());
conditions.add(userCombineCondition);
CombineCondition statusCombineCondition = getCombineCondition(List.of(CaseReviewStatus.PREPARED.toString(), CaseReviewStatus.UNDERWAY.toString()), "status", CombineCondition.CombineConditionOperator.IN.toString());
conditions.add(statusCombineCondition);
CombineCondition createTimeCombineCondition = getCombineCondition(List.of(request.getToStartTime(), request.getToEndTime()), "createTime", CombineCondition.CombineConditionOperator.BETWEEN.toString());
conditions.add(createTimeCombineCondition);
combineSearch.setConditions(conditions);
return combineSearch;
}
@NotNull
private static CombineCondition getCombineCondition(List<Object> value, String reviewers, String operator) {
CombineCondition userCombineCondition = new CombineCondition();
userCombineCondition.setValue(value);
userCombineCondition.setName(reviewers);
userCombineCondition.setOperator(operator);
userCombineCondition.setCustomField(false);
userCombineCondition.setCustomFieldType("");
return userCombineCondition;
}
public List<ApiDefinitionUpdateDTO> getApiUpdatePage(DashboardFrontPageRequest request) {
String projectId = request.getProjectIds().getFirst();
if (Boolean.FALSE.equals(checkModule(projectId, API_TEST_MODULE))) {
throw new MSException(NO_PROJECT_PERMISSION);
}
Long toStartTime = request.getToStartTime();
Long toEndTime = request.getToEndTime();
List<ApiDefinitionUpdateDTO> list = extApiDefinitionMapper.getUpdateApiList(projectId, toStartTime, toEndTime);
processApiDefinitions(projectId, list);
return list;
}
private void processApiDefinitions(String projectId, List<ApiDefinitionUpdateDTO> list) {
List<String> apiDefinitionIds = list.stream().map(ApiDefinitionUpdateDTO::getId).toList();
if (CollectionUtils.isEmpty(apiDefinitionIds)) {
return;
}
List<ApiTestCase> apiCaseList = extApiDefinitionMapper.selectNotInTrashCaseIdsByApiIds(apiDefinitionIds);
Map<String, List<ApiTestCase>> apiCaseMap = apiCaseList.stream().
collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId));
List<ApiRefSourceCountDTO> apiRefSourceCountDTOS = extApiDefinitionMapper.scenarioRefApiCount(projectId, apiDefinitionIds);
Map<String, Integer> countMap = apiRefSourceCountDTOS.stream().collect(Collectors.toMap(ApiRefSourceCountDTO::getSourceId, ApiRefSourceCountDTO::getCount));
list.forEach(item -> {
// Calculate API Case Metrics
List<ApiTestCase> apiTestCases = apiCaseMap.get(item.getId());
if (apiTestCases != null) {
item.setCaseTotal(apiTestCases.size());
} else {
item.setCaseTotal(0);
}
Integer count = countMap.get(item.getId());
item.setScenarioTotal(Objects.requireNonNullElse(count, 0));
});
}
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.dashboard.controller; package io.metersphere.dashboard.controller;
import io.metersphere.api.dto.definition.ApiDefinitionUpdateDTO;
import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.bug.domain.Bug; import io.metersphere.bug.domain.Bug;
import io.metersphere.bug.domain.BugExample; import io.metersphere.bug.domain.BugExample;
@ -36,6 +37,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@ -67,6 +70,7 @@ public class DashboardFrontPageControllerTests extends BaseTest {
private static final String BUG_HANDLE_USER = "/dashboard/bug_handle_user"; private static final String BUG_HANDLE_USER = "/dashboard/bug_handle_user";
private static final String REVIEWING_BY_ME = "/dashboard/reviewing_by_me"; private static final String REVIEWING_BY_ME = "/dashboard/reviewing_by_me";
private static final String API_CHANGE = "/dashboard/api_change";
@Test @Test
@ -330,6 +334,13 @@ public class DashboardFrontPageControllerTests extends BaseTest {
Pager.class); Pager.class);
List<CaseReviewDTO> list = tableData.getList(); List<CaseReviewDTO> list = tableData.getList();
Assertions.assertNotNull(list); Assertions.assertNotNull(list);
MvcResult apiMvcResult = this.requestPostWithOkAndReturn(API_CHANGE, dashboardFrontPageRequest);
Pager<List<ApiDefinitionUpdateDTO>> apiTableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(apiMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
Pager.class);
List<ApiDefinitionUpdateDTO> apiList = apiTableData.getList();
Assertions.assertNotNull(apiList);
System.out.println(JSON.toJSONString(apiList));
dashboardFrontPageRequest.setStartTime(1697971947000L); dashboardFrontPageRequest.setStartTime(1697971947000L);
dashboardFrontPageRequest.setEndTime(1700650347000L); dashboardFrontPageRequest.setEndTime(1700650347000L);
mvcResult = this.requestPostWithOkAndReturn(REVIEWING_BY_ME, dashboardFrontPageRequest); mvcResult = this.requestPostWithOkAndReturn(REVIEWING_BY_ME, dashboardFrontPageRequest);
@ -338,6 +349,22 @@ public class DashboardFrontPageControllerTests extends BaseTest {
Pager.class); Pager.class);
list = tableData.getList(); list = tableData.getList();
Assertions.assertNotNull(list); Assertions.assertNotNull(list);
apiMvcResult = this.requestPostWithOkAndReturn(API_CHANGE, dashboardFrontPageRequest);
apiTableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(apiMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
Pager.class);
apiList = apiTableData.getList();
System.out.println(JSON.toJSONString(apiList));
Assertions.assertNotNull(apiList);
Project project = new Project();
project.setModuleSetting("[]");
project.setId(DEFAULT_PROJECT_ID);
projectMapper.updateByPrimaryKeySelective(project);
this.requestPost(REVIEWING_BY_ME, dashboardFrontPageRequest).andExpect(status().is5xxServerError());
this.requestPost(API_CHANGE, dashboardFrontPageRequest).andExpect(status().is5xxServerError());
project.setModuleSetting("[\"apiTest\",\"testPlan\",\"caseManagement\",\"bugManagement\"]");
project.setId(DEFAULT_PROJECT_ID);
projectMapper.updateByPrimaryKeySelective(project);
} }

View File

@ -68,5 +68,16 @@ INSERT INTO bug (id, num, title, handle_users, handle_user, create_user, create_
VALUES ('dashboard_bug2', 100002, 'oasis2', 'PROJECT', 'PROJECT', 'admin', 1716185577387, 'admin', UNIX_TIMESTAMP() * 1000, 'admin', UNIX_TIMESTAMP() * 1000, '100001100001', 'bug-template-id', 'Local', 'open', '["default-tag"]', null, 0, 5000); VALUES ('dashboard_bug2', 100002, 'oasis2', 'PROJECT', 'PROJECT', 'admin', 1716185577387, 'admin', UNIX_TIMESTAMP() * 1000, 'admin', UNIX_TIMESTAMP() * 1000, '100001100001', 'bug-template-id', 'Local', 'open', '["default-tag"]', null, 0, 5000);
INSERT INTO bug (id, num, title, handle_users, handle_user, create_user, create_time,update_user, update_time, delete_user, delete_time, project_id, template_id, platform, status, tags, platform_bug_id, deleted, pos) INSERT INTO bug (id, num, title, handle_users, handle_user, create_user, create_time,update_user, update_time, delete_user, delete_time, project_id, template_id, platform, status, tags, platform_bug_id, deleted, pos)
VALUES ('dashboard_bug3', 100003, 'oasis3', 'admin', 'admin', 'admin', 1716185577387, 'admin', UNIX_TIMESTAMP() * 1000, 'admin', UNIX_TIMESTAMP() * 1000, '100001100001', 'bug-template-id', 'Local', 'open', '["default-tag"]', null, 0, 5000) VALUES ('dashboard_bug3', 100003, 'oasis3', 'admin', 'admin', 'admin', 1716185577387, 'admin', UNIX_TIMESTAMP() * 1000, 'admin', UNIX_TIMESTAMP() * 1000, '100001100001', 'bug-template-id', 'Local', 'open', '["default-tag"]', null, 0, 5000);
INSERT INTO api_definition(id, name, protocol, method, path, status, num, tags, pos, project_id, module_id, latest, version_id, ref_id, description, create_time, create_user, update_time, update_user, delete_user, delete_time, deleted)
VALUES ('dashboard_api_definition_id_1', 'gyq_associate_api_definition_id_1', 'HTTP', 'POST','api/test','test-api-status', 1000001, null, 1, '100001100001' , 'gyq_associate_test_module', true, 'v1.10','gyq_associate_api_definition_id_1', null, 1697971947000,'admin', 1697971947000,'admin', null,null,false);
INSERT INTO api_definition(id, name, protocol, method, path, status, num, tags, pos, project_id, module_id, latest, version_id, ref_id, description, create_time, create_user, update_time, update_user, delete_user, delete_time, deleted)
VALUES ('dashboard_api_definition_id_2', 'gyq_associate_api_definition_id_2', 'HTTP', 'POST','api/test','test-api-status', 1000001, null, 1, '100001100001' , 'gyq_associate_test_module', true, 'v1.10','gyq_associate_api_definition_id_1', null, 1697971947000,'admin', 1697971947000,'admin', null,null,false);
INSERT INTO api_test_case(id, name, priority, num, tags, status, last_report_status, last_report_id, pos, project_id, api_definition_id, version_id, environment_id, create_time, create_user, update_time, update_user, delete_time, delete_user, deleted) VALUES
('dashboard_ac_1', 'oasis_ac', 'P0', 1001, null, 'Underway', 'PENDING', null, 100, '100001100001', 'dashboard_api_definition_id_1', 'oasis_ac_version_id', 'oasis_ac_env_id', 1698058347559, 'admin', 1698058347559, 'admin', null, null, false);
INSERT INTO api_scenario_step(id, scenario_id, name, sort, enable, resource_id, resource_num, step_type, project_id, parent_id, version_id, ref_type, origin_project_id, config)
VALUE ('dashboard_act_1', 'dashboard_sc_1', 'dd', 1, true, 'dashboard_api_definition_id_1', '1000', 'API', '100001100001', null, 'oasis_ac_version_id', 'REF', '100001100001', null)