fix(工作台): 用户被移除项目组之后工作台面板不再统计其相关数据

--bug=1027173 --user=宋天阳 【我的工作台】我的仪表盘首页 -我创建的用例-功能用例数量无统计数据
https://www.tapd.cn/55049933/s/1383870;--bug=1027174 --user=宋天阳
【我的工作台】我的关注 tab 页面没有任何统计数据 https://www.tapd.cn/55049933/s/1383869
This commit is contained in:
song-tianyang 2023-06-20 14:27:58 +08:00 committed by 刘瑞斌
parent 50e1c1a14d
commit 529a9a732d
10 changed files with 71 additions and 15 deletions

View File

@ -88,7 +88,10 @@
select count(1) as `count`, if(i.platform = 'Local', cfi.value, i.platform_status) as statusValue, i.platform
from issues i
inner join project p
on i.project_id = p.id and p.workspace_id = #{request.workspaceId}
on i.project_id = p.id and p.workspace_id = #{request.workspaceId} and
p.id IN (SELECT source_id
FROM user_group
WHERE user_id = #{request.creator})
left join custom_field_issues cfi
on i.id = cfi.resource_id and field_id in (select cf.id
from custom_field cf

View File

@ -243,6 +243,12 @@
AND create_time >= #{request.scheduleCreateTime}
)
</if>
<if test="request.projectIdList != null and request.projectIdList.size() > 0">
AND project.id in
<foreach collection="request.projectIdList" item="itemId" separator="," open="(" close=")">
#{itemId}
</foreach>
</if>
<if test="request.ids != null and request.ids.size() > 0">
AND api_scenario.id in
<foreach collection="request.ids" item="itemId" separator="," open="(" close=")">

View File

@ -277,7 +277,6 @@
inner join project on api_test_case.project_id = project.id
inner JOIN api_definition a ON api_test_case.api_definition_id = a.id
<include refid="criCondition"/>
and a.latest = 1
</select>
<select id="getCountFollow" resultType="java.lang.Integer">
select count(*) from api_test_case ac where
@ -404,6 +403,12 @@
<if test="request.createTime >0 ">
AND api_test_case.create_time >= #{request.createTime}
</if>
<if test="request.projectIdList != null and request.projectIdList.size() > 0">
AND project.id in
<foreach collection="request.projectIdList" item="itemId" separator="," open="(" close=")">
#{itemId}
</foreach>
</if>
</where>
</sql>

View File

@ -151,6 +151,12 @@
<property name="objectKey" value="request.combine.tags"/>
</include>
</if>
<if test="request.projectIdList != null and request.projectIdList.size() > 0">
AND project.id in
<foreach collection="request.projectIdList" item="itemId" separator="," open="(" close=")">
#{itemId}
</foreach>
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId}
</if>

View File

@ -467,6 +467,12 @@
<if test="request.projectId != null">
and test_case.project_id = #{request.projectId}
</if>
<if test="request.projectIdList != null and request.projectIdList.size() > 0">
AND project.id in
<foreach collection="request.projectIdList" item="itemId" separator="," open="(" close=")">
#{itemId}
</foreach>
</if>
<include refid="filters"/>
<if test="request.caseCoverage == 'uncoverage' ">
and test_case.id not in (select distinct test_case_test.test_case_id from test_case_test)

View File

@ -4,6 +4,9 @@ import io.metersphere.request.BaseQueryRequest;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public class ApiScenarioRequest extends BaseQueryRequest {
@ -35,4 +38,5 @@ public class ApiScenarioRequest extends BaseQueryRequest {
//测试计划关联场景过滤掉步骤为0的场景
private String stepTotal;
private List<String> projectIdList = new ArrayList<>();
}

View File

@ -5,6 +5,7 @@ import io.metersphere.request.OrderRequest;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -73,4 +74,6 @@ public class ApiTestCaseRequest extends BaseQueryRequest {
//全选
private boolean selectAll;
private List<String> projectIdList = new ArrayList<>();
}

View File

@ -4,6 +4,7 @@ import io.metersphere.request.BaseQueryRequest;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
@Getter
@ -63,4 +64,6 @@ public class QueryTestCaseRequest extends BaseQueryRequest {
private Boolean toBeUpdated;
private String apiCoverage;
private String scenarioCoverage;
private List<String> projectIdList = new ArrayList<>();
}

View File

@ -4,6 +4,7 @@ import io.metersphere.request.OrderRequest;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -15,4 +16,5 @@ public class QueryTestPlanRequest extends TestPlanRequest {
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
private Map<String, Object> combine;
private List<String> projectIdList = new ArrayList<>();
}

View File

@ -12,25 +12,21 @@ import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.request.ApiSyncCaseRequest;
import io.metersphere.request.ProjectRequest;
import io.metersphere.request.api.ApiScenarioRequest;
import io.metersphere.request.api.ApiTestCaseRequest;
import io.metersphere.request.track.QueryTestCaseRequest;
import io.metersphere.request.track.QueryTestPlanRequest;
import io.metersphere.request.api.ApiTestCaseRequest;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jakarta.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.metersphere.workstation.util.ShareUtil.getTimeMills;
@ -77,7 +73,7 @@ public class WorkstationService {
createTime = startDayOfWeek.getTime();
}
String userId = SessionUtils.getUserId();
//build query condition object
QueryTestPlanRequest testPlanRequest = new QueryTestPlanRequest();
testPlanRequest.setUserId(userId);
testPlanRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
@ -89,7 +85,7 @@ public class WorkstationService {
if (isWeek) {
apiTestCaseRequest.setCreateTime(createTime);
}
//@see io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml:103
Map<String, Object> combine = new HashMap<>(2);
Map<String, String> operatorValue = new HashMap<>(2);
operatorValue.put("operator", "current user");
@ -109,6 +105,19 @@ public class WorkstationService {
if (isWeek) {
testCaseRequest.setCreateTime(createTime);
}
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
projectRequest.setUserId(userId);
List<Project> projects = baseProjectMapper.getUserProject(projectRequest);
if (CollectionUtils.isNotEmpty(projects)) {
List<String> projectIds = projects.stream().map(Project::getId).toList();
apiScenarioRequest.setProjectIdList(projectIds);
apiTestCaseRequest.setProjectIdList(projectIds);
testCaseRequest.setProjectIdList(projectIds);
testPlanRequest.setProjectIdList(projectIds);
}
//query db
int apiScenarioCaseCount = extApiScenarioMapper.listModule(apiScenarioRequest);
int apiTestCaseCount = extApiTestCaseMapper.moduleCount(apiTestCaseRequest);
@ -124,12 +133,17 @@ public class WorkstationService {
}
public Map<String, Integer> getFollowTotalCount(String workstationId){
public Map<String, Integer> getFollowTotalCount(String workstationId) {
String userId = SessionUtils.getUserId();
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(workstationId);
if (CollectionUtils.isEmpty(projectIds)) {
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setWorkspaceId(workstationId);
projectRequest.setUserId(userId);
List<Project> projects = baseProjectMapper.getUserProject(projectRequest);
if (CollectionUtils.isEmpty(projects)) {
return null;
}
List<String> projectIds = projects.stream().map(Project::getId).toList();
int caseFollowCount = extTestCaseMapper.getCountFollow(projectIds, userId);
int planFollowCount = extTestPlanMapper.getCountFollow(projectIds, userId);
int reviewFollowCount = extTestCaseReviewMapper.getCountFollow(projectIds, userId);
@ -246,10 +260,14 @@ public class WorkstationService {
public Integer getIssueWeekCount(String workstationId) {
String userId = SessionUtils.getUserId();
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(workstationId);
if (CollectionUtils.isEmpty(projectIds)) {
ProjectRequest projectRequest = new ProjectRequest();
projectRequest.setWorkspaceId(workstationId);
projectRequest.setUserId(userId);
List<Project> projects = baseProjectMapper.getUserProject(projectRequest);
if (CollectionUtils.isEmpty(projects)) {
return null;
}
List<String> projectIds = projects.stream().map(Project::getId).toList();
Date startDayOfWeek = getStartDayOfWeek();
Long createTime = startDayOfWeek.getTime();
return extIssuesMapper.getCountCreat(projectIds, userId, createTime);