refactor: 启动时自动同步第三方平台缺陷 (#4303)

Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com>
This commit is contained in:
metersphere-bot 2021-07-01 21:45:47 +08:00 committed by GitHub
parent 9154a10a1c
commit b32e9bba9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 56 deletions

View File

@ -2108,9 +2108,12 @@ public class ApiAutomationService {
}
public void checkApiScenarioUseUrl() {
try {
final String key = "init.scenario.url";
String value = systemParameterService.getValue(key);
if (StringUtils.isBlank(value)) {
List<String> noUrlScenarioIdList = extApiScenarioMapper.selectIdsByUseUrlIsNull();
for (String id : noUrlScenarioIdList) {
try {
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id);
if (scenario.getUseUrl() == null) {
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenario);
@ -2123,10 +2126,11 @@ public class ApiAutomationService {
}
}
scenario = null;
} catch (Exception e) {
e.printStackTrace();
}
systemParameterService.saveInitParam(key);
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
}

View File

@ -7,6 +7,7 @@ import io.metersphere.base.domain.JarConfig;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.service.JarConfigService;
import io.metersphere.service.ScheduleService;
import io.metersphere.track.service.IssuesService;
import org.python.core.Options;
import org.python.util.PythonInterpreter;
import org.springframework.beans.factory.annotation.Value;
@ -28,6 +29,8 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
private JarConfigService jarConfigService;
@Resource
private ApiAutomationService apiAutomationService;
@Resource
private IssuesService issuesService;
@Value("${jmeter.home}")
private String jmeterHome;
@ -44,6 +47,8 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
checkApiScenarioUseUrl();
issuesService.syncThirdPartyIssues();
try {
Thread.sleep(1 * 60 * 1000);
} catch (InterruptedException e) {

View File

@ -268,6 +268,15 @@ public class SystemParameterService {
});
}
public void saveInitParam(String key) {
SystemParameter parameter = new SystemParameter();
parameter.setParamKey(key);
parameter.setParamValue("over");
parameter.setType("text");
systemParameterMapper.insert(parameter);
}
//保存表头
public void saveHeader(UserHeader userHeader) {
UserHeaderExample example = new UserHeaderExample();

View File

@ -23,6 +23,7 @@ import io.metersphere.notice.service.NoticeSendService;
import io.metersphere.service.IntegrationService;
import io.metersphere.service.IssueTemplateService;
import io.metersphere.service.ProjectService;
import io.metersphere.service.SystemParameterService;
import io.metersphere.track.issue.*;
import io.metersphere.track.issue.domain.PlatformUser;
import io.metersphere.track.issue.domain.zentao.ZentaoBuild;
@ -72,6 +73,8 @@ public class IssuesService {
private IssueTemplateService issueTemplateService;
@Resource
private TestCaseMapper testCaseMapper;
@Resource
private SystemParameterService systemParameterService;
public void testAuth(String orgId, String platform) {
IssuesRequest issuesRequest = new IssuesRequest();
@ -360,47 +363,24 @@ public class IssuesService {
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());
// jiraPlatform.getJiraIssues(issue, issue.getId());
// } 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;
// }
public void syncThirdPartyIssues() {
try {
final String key = "init.issue";
String value = systemParameterService.getValue(key);
if (StringUtils.isBlank(value)) {
List<String> projectIds = projectService.getProjectIds();
projectIds.forEach(id -> {
try {
syncThirdPartyIssues(id);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
});
systemParameterService.saveInitParam(key);
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
}
public void syncThirdPartyIssues(String projectId) {