From b32e9bba9fec84d0e9ebb988f38dee871e1793d3 Mon Sep 17 00:00:00 2001 From: metersphere-bot <78466014+metersphere-bot@users.noreply.github.com> Date: Thu, 1 Jul 2021 21:45:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=8C=E6=AD=A5=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=BC=BA=E9=99=B7=20(#4303)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: chenjianxing --- .../api/service/ApiAutomationService.java | 36 ++++++----- .../listener/AppStartListener.java | 5 ++ .../service/SystemParameterService.java | 9 +++ .../track/service/IssuesService.java | 60 +++++++------------ 4 files changed, 54 insertions(+), 56 deletions(-) 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 cd49ffea18..cb66b2ed7a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -2108,25 +2108,29 @@ public class ApiAutomationService { } public void checkApiScenarioUseUrl() { - List noUrlScenarioIdList = extApiScenarioMapper.selectIdsByUseUrlIsNull(); - for (String id : noUrlScenarioIdList) { - try { - 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; + 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; } - scenario = null; - } catch (Exception e) { - e.printStackTrace(); + systemParameterService.saveInitParam(key); } - + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); } } diff --git a/backend/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/src/main/java/io/metersphere/listener/AppStartListener.java index e0900c9309..0009e14a51 100644 --- a/backend/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/src/main/java/io/metersphere/listener/AppStartListener.java @@ -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 projectIds = projectService.getProjectIds(); - projectIds.forEach(id -> { - syncThirdPartyIssues(id); - }); + try { + final String key = "init.issue"; + String value = systemParameterService.getValue(key); + if (StringUtils.isBlank(value)) { + List 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) {