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,25 +2108,29 @@ public class ApiAutomationService {
} }
public void checkApiScenarioUseUrl() { public void checkApiScenarioUseUrl() {
List<String> noUrlScenarioIdList = extApiScenarioMapper.selectIdsByUseUrlIsNull(); try {
for (String id : noUrlScenarioIdList) { final String key = "init.scenario.url";
try { String value = systemParameterService.getValue(key);
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id); if (StringUtils.isBlank(value)) {
if (scenario.getUseUrl() == null) { List<String> noUrlScenarioIdList = extApiScenarioMapper.selectIdsByUseUrlIsNull();
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenario); for (String id : noUrlScenarioIdList) {
if (useUrl != null) { ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id);
ApiScenarioWithBLOBs updateModel = new ApiScenarioWithBLOBs(); if (scenario.getUseUrl() == null) {
updateModel.setId(scenario.getId()); List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenario);
updateModel.setUseUrl(JSONArray.toJSONString(useUrl)); if (useUrl != null) {
apiScenarioMapper.updateByPrimaryKeySelective(updateModel); ApiScenarioWithBLOBs updateModel = new ApiScenarioWithBLOBs();
updateModel = null; updateModel.setId(scenario.getId());
updateModel.setUseUrl(JSONArray.toJSONString(useUrl));
apiScenarioMapper.updateByPrimaryKeySelective(updateModel);
updateModel = null;
}
} }
scenario = null;
} }
scenario = null; systemParameterService.saveInitParam(key);
} catch (Exception e) {
e.printStackTrace();
} }
} 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.commons.utils.LogUtil;
import io.metersphere.service.JarConfigService; import io.metersphere.service.JarConfigService;
import io.metersphere.service.ScheduleService; import io.metersphere.service.ScheduleService;
import io.metersphere.track.service.IssuesService;
import org.python.core.Options; import org.python.core.Options;
import org.python.util.PythonInterpreter; import org.python.util.PythonInterpreter;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -28,6 +29,8 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
private JarConfigService jarConfigService; private JarConfigService jarConfigService;
@Resource @Resource
private ApiAutomationService apiAutomationService; private ApiAutomationService apiAutomationService;
@Resource
private IssuesService issuesService;
@Value("${jmeter.home}") @Value("${jmeter.home}")
private String jmeterHome; private String jmeterHome;
@ -44,6 +47,8 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
checkApiScenarioUseUrl(); checkApiScenarioUseUrl();
issuesService.syncThirdPartyIssues();
try { try {
Thread.sleep(1 * 60 * 1000); Thread.sleep(1 * 60 * 1000);
} catch (InterruptedException e) { } 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) { public void saveHeader(UserHeader userHeader) {
UserHeaderExample example = new UserHeaderExample(); 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.IntegrationService;
import io.metersphere.service.IssueTemplateService; import io.metersphere.service.IssueTemplateService;
import io.metersphere.service.ProjectService; import io.metersphere.service.ProjectService;
import io.metersphere.service.SystemParameterService;
import io.metersphere.track.issue.*; import io.metersphere.track.issue.*;
import io.metersphere.track.issue.domain.PlatformUser; import io.metersphere.track.issue.domain.PlatformUser;
import io.metersphere.track.issue.domain.zentao.ZentaoBuild; import io.metersphere.track.issue.domain.zentao.ZentaoBuild;
@ -72,6 +73,8 @@ public class IssuesService {
private IssueTemplateService issueTemplateService; private IssueTemplateService issueTemplateService;
@Resource @Resource
private TestCaseMapper testCaseMapper; private TestCaseMapper testCaseMapper;
@Resource
private SystemParameterService systemParameterService;
public void testAuth(String orgId, String platform) { public void testAuth(String orgId, String platform) {
IssuesRequest issuesRequest = new IssuesRequest(); IssuesRequest issuesRequest = new IssuesRequest();
@ -360,47 +363,24 @@ public class IssuesService {
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());
// 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() { public void syncThirdPartyIssues() {
List<String> projectIds = projectService.getProjectIds(); try {
projectIds.forEach(id -> { final String key = "init.issue";
syncThirdPartyIssues(id); 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) { public void syncThirdPartyIssues(String projectId) {