refactor(缺陷管理): 缺陷列表查询优化
This commit is contained in:
parent
163edb937f
commit
8872fe8135
|
@ -12,7 +12,9 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getIssuesByProjectId" resultType="io.metersphere.base.domain.IssuesDao">
|
<select id="getIssuesByProjectId" resultType="io.metersphere.base.domain.IssuesDao">
|
||||||
select issues.*
|
select issues.id, ifnull(issues.title, '') as title, issues.project_id, issues.create_time, issues.update_time,
|
||||||
|
ifnull(issues.description, '') as description, issues.status, issues.platform, issues.custom_fields, issues.reporter,
|
||||||
|
issues.lastmodify
|
||||||
from issues
|
from issues
|
||||||
<include refid="queryWhereCondition"/>
|
<include refid="queryWhereCondition"/>
|
||||||
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
|
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.base.domain.Issues;
|
import io.metersphere.base.domain.Issues;
|
||||||
import io.metersphere.base.domain.IssuesDao;
|
import io.metersphere.base.domain.IssuesDao;
|
||||||
|
import io.metersphere.base.domain.IssuesWithBLOBs;
|
||||||
import io.metersphere.commons.utils.PageUtils;
|
import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
import io.metersphere.track.issue.domain.PlatformUser;
|
import io.metersphere.track.issue.domain.PlatformUser;
|
||||||
|
@ -79,5 +80,10 @@ public class IssuesController {
|
||||||
return issuesService.getZentaoBuilds(request);
|
return issuesService.getZentaoBuilds(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/get/platform/issue")
|
||||||
|
public IssuesWithBLOBs getPlatformIssue(@RequestBody IssuesWithBLOBs issue) {
|
||||||
|
return issuesService.getPlatformIssue(issue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,8 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
||||||
issues.setPlatform(issuesRequest.getPlatform());
|
issues.setPlatform(issuesRequest.getPlatform());
|
||||||
issues.setProjectId(issuesRequest.getProjectId());
|
issues.setProjectId(issuesRequest.getProjectId());
|
||||||
issues.setCustomFields(issuesRequest.getCustomFields());
|
issues.setCustomFields(issuesRequest.getCustomFields());
|
||||||
|
issues.setCreateTime(System.currentTimeMillis());
|
||||||
|
issues.setUpdateTime(System.currentTimeMillis());
|
||||||
issuesMapper.insert(issues);
|
issuesMapper.insert(issues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
||||||
return project.getJiraKey();
|
return project.getJiraKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IssuesDao getJiraIssues(HttpHeaders headers, String url, String issuesId) {
|
public IssuesDao getJiraIssues(HttpHeaders headers, String url, String issuesId) {
|
||||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(headers);
|
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(headers);
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
//post
|
//post
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
||||||
return demandList;
|
return demandList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IssuesDao getTapdIssues(String projectId, String issuesId) {
|
public IssuesDao getTapdIssues(String projectId, String issuesId) {
|
||||||
String url = "https://api.tapd.cn/bugs?workspace_id=" + projectId + "&id=" + issuesId;
|
String url = "https://api.tapd.cn/bugs?workspace_id=" + projectId + "&id=" + issuesId;
|
||||||
ResultHolder call = call(url);
|
ResultHolder call = call(url);
|
||||||
String listJson = JSON.toJSONString(call.getData());
|
String listJson = JSON.toJSONString(call.getData());
|
||||||
|
@ -218,6 +218,9 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
||||||
public List<PlatformUser> getPlatformUser() {
|
public List<PlatformUser> getPlatformUser() {
|
||||||
List<PlatformUser> users = new ArrayList<>();
|
List<PlatformUser> users = new ArrayList<>();
|
||||||
String id = getProjectId(projectId);
|
String id = getProjectId(projectId);
|
||||||
|
if (StringUtils.isBlank(id)) {
|
||||||
|
MSException.throwException("未关联Tapd项目ID");
|
||||||
|
}
|
||||||
String url = "https://api.tapd.cn/workspaces/users?workspace_id=" + id;
|
String url = "https://api.tapd.cn/workspaces/users?workspace_id=" + id;
|
||||||
ResultHolder call = call(url);
|
ResultHolder call = call(url);
|
||||||
String listJson = JSON.toJSONString(call.getData());
|
String listJson = JSON.toJSONString(call.getData());
|
||||||
|
|
|
@ -51,6 +51,13 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
||||||
this.url = object.getString("url");
|
this.url = object.getString("url");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ZentaoPlatform(String account, String password, String url) {
|
||||||
|
super(new IssuesRequest());
|
||||||
|
this.account = account;
|
||||||
|
this.password = password;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String getProjectId(String projectId) {
|
String getProjectId(String projectId) {
|
||||||
if (StringUtils.isNotBlank(projectId)) {
|
if (StringUtils.isNotBlank(projectId)) {
|
||||||
|
@ -156,7 +163,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IssuesDao getZentaoIssues(String bugId) {
|
public IssuesDao getZentaoIssues(String bugId) {
|
||||||
String session = login();
|
String session = login();
|
||||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(new HttpHeaders());
|
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(new HttpHeaders());
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
@ -204,7 +211,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
||||||
String projectId = getProjectId(issuesRequest.getProjectId());
|
String projectId = getProjectId(issuesRequest.getProjectId());
|
||||||
|
|
||||||
if (StringUtils.isBlank(projectId)) {
|
if (StringUtils.isBlank(projectId)) {
|
||||||
MSException.throwException("add zentao bug fail, project zentao id is null");
|
MSException.throwException("未关联禅道项目ID.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isBlank(session)) {
|
if (StringUtils.isBlank(session)) {
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package io.metersphere.track.service;
|
package io.metersphere.track.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.IssueTemplateMapper;
|
import io.metersphere.base.mapper.IssueTemplateMapper;
|
||||||
import io.metersphere.base.mapper.IssuesMapper;
|
import io.metersphere.base.mapper.IssuesMapper;
|
||||||
import io.metersphere.base.mapper.TestCaseIssuesMapper;
|
import io.metersphere.base.mapper.TestCaseIssuesMapper;
|
||||||
|
import io.metersphere.base.mapper.WorkspaceMapper;
|
||||||
|
import io.metersphere.base.mapper.ext.ExtIssuesMapper;
|
||||||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||||
import io.metersphere.commons.constants.NoticeConstants;
|
import io.metersphere.commons.constants.NoticeConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.user.SessionUser;
|
import io.metersphere.commons.user.SessionUser;
|
||||||
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.commons.utils.ServiceUtils;
|
import io.metersphere.commons.utils.ServiceUtils;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.controller.request.IntegrationRequest;
|
import io.metersphere.controller.request.IntegrationRequest;
|
||||||
|
@ -16,9 +21,7 @@ import io.metersphere.notice.sender.NoticeModel;
|
||||||
import io.metersphere.notice.service.NoticeSendService;
|
import io.metersphere.notice.service.NoticeSendService;
|
||||||
import io.metersphere.service.IntegrationService;
|
import io.metersphere.service.IntegrationService;
|
||||||
import io.metersphere.service.ProjectService;
|
import io.metersphere.service.ProjectService;
|
||||||
import io.metersphere.track.issue.AbstractIssuePlatform;
|
import io.metersphere.track.issue.*;
|
||||||
import io.metersphere.track.issue.IssueFactory;
|
|
||||||
import io.metersphere.track.issue.ZentaoPlatform;
|
|
||||||
import io.metersphere.track.issue.domain.PlatformUser;
|
import io.metersphere.track.issue.domain.PlatformUser;
|
||||||
import io.metersphere.track.issue.domain.ZentaoBuild;
|
import io.metersphere.track.issue.domain.ZentaoBuild;
|
||||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||||
|
@ -26,6 +29,7 @@ import io.metersphere.track.request.testcase.IssuesUpdateRequest;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -51,6 +55,10 @@ public class IssuesService {
|
||||||
private TestCaseIssuesMapper testCaseIssuesMapper;
|
private TestCaseIssuesMapper testCaseIssuesMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private IssueTemplateMapper issueTemplateMapper;
|
private IssueTemplateMapper issueTemplateMapper;
|
||||||
|
@Resource
|
||||||
|
private ExtIssuesMapper extIssuesMapper;
|
||||||
|
@Resource
|
||||||
|
private WorkspaceMapper workspaceMapper;
|
||||||
|
|
||||||
public void testAuth(String platform) {
|
public void testAuth(String platform) {
|
||||||
AbstractIssuePlatform abstractPlatform = IssueFactory.createPlatform(platform, new IssuesRequest());
|
AbstractIssuePlatform abstractPlatform = IssueFactory.createPlatform(platform, new IssuesRequest());
|
||||||
|
@ -274,17 +282,17 @@ public class IssuesService {
|
||||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||||
|
|
||||||
|
|
||||||
List<IssuesDao> list = new ArrayList<>();
|
// List<IssuesDao> list = new ArrayList<>();
|
||||||
String projectId = request.getProjectId();
|
// String projectId = request.getProjectId();
|
||||||
Project project = projectService.getProjectById(projectId);
|
// Project project = projectService.getProjectById(projectId);
|
||||||
List<String> platforms = getPlatforms(project);
|
// List<String> platforms = getPlatforms(project);
|
||||||
platforms.add(IssuesManagePlatform.Local.toString());
|
// platforms.add(IssuesManagePlatform.Local.toString());
|
||||||
List<AbstractIssuePlatform> platformList = IssueFactory.createPlatforms(platforms, request);
|
// List<AbstractIssuePlatform> platformList = IssueFactory.createPlatforms(platforms, request);
|
||||||
platformList.forEach(platform -> {
|
// platformList.forEach(platform -> {
|
||||||
List<IssuesDao> issue = platform.getIssue(request);
|
// List<IssuesDao> issue = platform.getIssue(request);
|
||||||
list.addAll(issue);
|
// list.addAll(issue);
|
||||||
});
|
// });
|
||||||
// List<IssuesDao> issues = extIssuesMapper.getIssuesByProjectId(request);
|
List<IssuesDao> issues = extIssuesMapper.getIssuesByProjectId(request);
|
||||||
// Map<String, List<IssuesDao>> issueMap = getIssueMap(issues);
|
// Map<String, List<IssuesDao>> issueMap = getIssueMap(issues);
|
||||||
// Map<String, AbstractIssuePlatform> platformMap = getPlatformMap(request);
|
// Map<String, AbstractIssuePlatform> platformMap = getPlatformMap(request);
|
||||||
// issueMap.forEach((platformName, data) -> {
|
// issueMap.forEach((platformName, data) -> {
|
||||||
|
@ -293,8 +301,8 @@ public class IssuesService {
|
||||||
// platform.filter(data);
|
// platform.filter(data);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// return issues;
|
return issues;
|
||||||
return list;
|
// return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<IssuesDao>> getIssueMap(List<IssuesDao> issues) {
|
public Map<String, List<IssuesDao>> getIssueMap(List<IssuesDao> issues) {
|
||||||
|
@ -321,4 +329,59 @@ public class IssuesService {
|
||||||
platforms.add(IssuesManagePlatform.Local.toString());
|
platforms.add(IssuesManagePlatform.Local.toString());
|
||||||
return IssueFactory.createPlatformsForMap(platforms, request);
|
return IssueFactory.createPlatformsForMap(platforms, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IssuesWithBLOBs getPlatformIssue(IssuesWithBLOBs issue) {
|
||||||
|
String platform = issue.getPlatform();
|
||||||
|
if (StringUtils.isNotBlank(issue.getProjectId())) {
|
||||||
|
Project project = projectService.getProjectById(issue.getProjectId());
|
||||||
|
Workspace workspace = workspaceMapper.selectByPrimaryKey(project.getWorkspaceId());
|
||||||
|
String orgId = workspace.getOrganizationId();
|
||||||
|
try {
|
||||||
|
if (StringUtils.equals(platform, IssuesManagePlatform.Tapd.name())) {
|
||||||
|
TapdPlatform tapdPlatform = new TapdPlatform(new IssuesRequest());
|
||||||
|
String tapdId = projectService.getProjectById(issue.getProjectId()).getTapdId();
|
||||||
|
IssuesDao tapdIssues = tapdPlatform.getTapdIssues(tapdId, issue.getId());
|
||||||
|
issue.setTitle(tapdIssues.getTitle());
|
||||||
|
issue.setDescription(tapdIssues.getDescription());
|
||||||
|
issue.setStatus(tapdIssues.getStatus());
|
||||||
|
} else if (StringUtils.equals(platform, IssuesManagePlatform.Jira.name())) {
|
||||||
|
JiraPlatform jiraPlatform = new JiraPlatform(new IssuesRequest());
|
||||||
|
String config = getConfig(orgId, IssuesManagePlatform.Jira.toString());
|
||||||
|
JSONObject object = JSON.parseObject(config);
|
||||||
|
HttpHeaders headers = jiraPlatform.getAuthHeader(object);
|
||||||
|
String url = object.getString("url");
|
||||||
|
IssuesDao jiraIssues = jiraPlatform.getJiraIssues(headers, url, issue.getId());
|
||||||
|
issue.setTitle(jiraIssues.getTitle());
|
||||||
|
issue.setDescription(jiraIssues.getDescription());
|
||||||
|
issue.setStatus(jiraIssues.getStatus());
|
||||||
|
} else if (StringUtils.equals(platform, IssuesManagePlatform.Zentao.name())) {
|
||||||
|
String config = getConfig(orgId, IssuesManagePlatform.Zentao.toString());
|
||||||
|
JSONObject object = JSON.parseObject(config);
|
||||||
|
String account = object.getString("account");
|
||||||
|
String password = object.getString("password");
|
||||||
|
String url = object.getString("url");
|
||||||
|
ZentaoPlatform zentaoPlatform = new ZentaoPlatform(account, password, url);
|
||||||
|
IssuesDao zentaoIssues = zentaoPlatform.getZentaoIssues(issue.getId());
|
||||||
|
issue.setTitle(zentaoIssues.getTitle());
|
||||||
|
issue.setDescription(zentaoIssues.getDescription());
|
||||||
|
issue.setStatus(zentaoIssues.getStatus());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getConfig(String orgId, String platform) {
|
||||||
|
IntegrationRequest request = new IntegrationRequest();
|
||||||
|
if (StringUtils.isBlank(orgId)) {
|
||||||
|
MSException.throwException("organization id is null");
|
||||||
|
}
|
||||||
|
request.setOrgId(orgId);
|
||||||
|
request.setPlatform(platform);
|
||||||
|
|
||||||
|
ServiceIntegration integration = integrationService.get(request);
|
||||||
|
return integration.getConfiguration();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,24 @@ export default {
|
||||||
let data = response.data;
|
let data = response.data;
|
||||||
this.total = data.itemCount;
|
this.total = data.itemCount;
|
||||||
this.tableData = data.listObject;
|
this.tableData = data.listObject;
|
||||||
|
for (let i = 0; i < this.tableData.length; i++) {
|
||||||
|
if (this.tableData[i]) {
|
||||||
|
if (this.tableData[i].platform !== 'Local') {
|
||||||
|
this.$post("issues/get/platform/issue", this.tableData[i]).then(response => {
|
||||||
|
let issues = response.data.data;
|
||||||
|
if (issues) {
|
||||||
|
this.$set(this.tableData[i], "title", issues.title ? issues.title : "--");
|
||||||
|
this.$set(this.tableData[i], "description", issues.description ? issues.description : "--");
|
||||||
|
this.$set(this.tableData[i], "status", issues.status ? issues.status : 'delete');
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
this.$set(this.tableData[i], "title", "--");
|
||||||
|
this.$set(this.tableData[i], "description", "--");
|
||||||
|
this.$set(this.tableData[i], "status", "--");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleEdit(data) {
|
handleEdit(data) {
|
||||||
|
|
|
@ -65,5 +65,6 @@ export const ISSUE_STATUS_MAP = {
|
||||||
'new': '新建',
|
'new': '新建',
|
||||||
'closed': '已关闭',
|
'closed': '已关闭',
|
||||||
'resolved': '已解决',
|
'resolved': '已解决',
|
||||||
'active': '激活'
|
'active': '激活',
|
||||||
|
'delete': '已删除'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue