From 98d106e6d60f2a06275f4359fe4656520d15b1e8 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 1 Jul 2021 22:27:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B7=BB=E5=8A=A0=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=BC=BA=E9=99=B7=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 33 +++++++------------ .../commons/utils/RunInterface.java | 5 +++ .../listener/AppStartListener.java | 23 ++++++++++--- .../track/service/IssuesService.java | 23 ++++--------- .../db/migration/V89__v1.10.4_release.sql | 4 +++ 5 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/commons/utils/RunInterface.java diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index cb66b2ed7a..990dc6b203 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -2108,29 +2108,20 @@ public class ApiAutomationService { } public void checkApiScenarioUseUrl() { - try { - final String key = "init.scenario.url"; - String value = systemParameterService.getValue(key); - if (StringUtils.isBlank(value)) { - List noUrlScenarioIdList = extApiScenarioMapper.selectIdsByUseUrlIsNull(); - for (String id : noUrlScenarioIdList) { - ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id); - if (scenario.getUseUrl() == null) { - List useUrl = this.parseUrl(scenario); - if (useUrl != null) { - ApiScenarioWithBLOBs updateModel = new ApiScenarioWithBLOBs(); - updateModel.setId(scenario.getId()); - updateModel.setUseUrl(JSONArray.toJSONString(useUrl)); - apiScenarioMapper.updateByPrimaryKeySelective(updateModel); - updateModel = null; - } - } - scenario = null; + List noUrlScenarioIdList = extApiScenarioMapper.selectIdsByUseUrlIsNull(); + for (String id : noUrlScenarioIdList) { + ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id); + if (scenario.getUseUrl() == null) { + List useUrl = this.parseUrl(scenario); + if (useUrl != null) { + ApiScenarioWithBLOBs updateModel = new ApiScenarioWithBLOBs(); + updateModel.setId(scenario.getId()); + updateModel.setUseUrl(JSONArray.toJSONString(useUrl)); + apiScenarioMapper.updateByPrimaryKeySelective(updateModel); + updateModel = null; } - systemParameterService.saveInitParam(key); } - } catch (Exception e) { - LogUtil.error(e.getMessage(), e); + scenario = null; } } diff --git a/backend/src/main/java/io/metersphere/commons/utils/RunInterface.java b/backend/src/main/java/io/metersphere/commons/utils/RunInterface.java new file mode 100644 index 0000000000..4806bbd5ad --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/utils/RunInterface.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.utils; + +public interface RunInterface { + void run(); +} diff --git a/backend/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/src/main/java/io/metersphere/listener/AppStartListener.java index 0009e14a51..c2835512a6 100644 --- a/backend/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/src/main/java/io/metersphere/listener/AppStartListener.java @@ -5,9 +5,12 @@ import io.metersphere.api.jmeter.NewDriverManager; import io.metersphere.api.service.ApiAutomationService; import io.metersphere.base.domain.JarConfig; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.RunInterface; import io.metersphere.service.JarConfigService; import io.metersphere.service.ScheduleService; +import io.metersphere.service.SystemParameterService; import io.metersphere.track.service.IssuesService; +import org.apache.commons.lang3.StringUtils; import org.python.core.Options; import org.python.util.PythonInterpreter; import org.springframework.beans.factory.annotation.Value; @@ -30,6 +33,8 @@ public class AppStartListener implements ApplicationListener projectIds = projectService.getProjectIds(); - projectIds.forEach(id -> { - try { - syncThirdPartyIssues(id); - } catch (Exception e) { - LogUtil.error(e.getMessage(), e); - } - }); - systemParameterService.saveInitParam(key); + List projectIds = projectService.getProjectIds(); + projectIds.forEach(id -> { + try { + syncThirdPartyIssues(id); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); } - } catch (Exception e) { - LogUtil.error(e.getMessage(), e); - } + }); } public void syncThirdPartyIssues(String projectId) { diff --git a/backend/src/main/resources/db/migration/V89__v1.10.4_release.sql b/backend/src/main/resources/db/migration/V89__v1.10.4_release.sql index 674937ec4e..223403a598 100644 --- a/backend/src/main/resources/db/migration/V89__v1.10.4_release.sql +++ b/backend/src/main/resources/db/migration/V89__v1.10.4_release.sql @@ -17,3 +17,7 @@ ALTER TABLE `user` ADD platform_info LONGTEXT NULL COMMENT ' 其他平台对接信息'; ALTER TABLE issues ADD platform_status varchar(50) NULL COMMENT '第三方平台状态'; + +-- 定时同步缺陷 +INSERT INTO metersphere.schedule (id,`key`,`type`,value,`group`,job,enable,resource_id,user_id,workspace_id,create_time,update_time,project_id,name) +VALUES ('7a23d4db-9909-438d-9e36-58e432c8c4ae','ISSUE_SYNC','CRON','0 0 3 * * ? ','ISSUE_SYNC','io.metersphere.job.sechedule.IssueSyncJob',1,'system','admin','system',unix_timestamp() * 1000,unix_timestamp() * 1000,'system','ISSUE_SYNC');