From 2925a45c1a2775c91793dbf3bef4b9303a6b4a78 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 19 Nov 2020 14:58:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E6=B7=BB=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/issue/ZentaoPlatform.java | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java index caafdc3a94..28c8c3a08e 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -87,31 +87,39 @@ public class ZentaoPlatform extends AbstractIssuePlatform { String session = login(); HttpEntity requestEntity = new HttpEntity<>(new HttpHeaders()); RestTemplate restTemplate = new RestTemplate(); - ResponseEntity responseEntity = restTemplate.exchange(url + "api-getModel-bug-getById-bugID={bugId}?zentaosid=" + session, - HttpMethod.POST, requestEntity, String.class, bugId); - String body = responseEntity.getBody(); - JSONObject obj = JSONObject.parseObject(body); - if (obj != null) { - JSONObject bug = obj.getJSONObject("data"); - String id = bug.getString("id"); - String title = bug.getString("title"); - String description = bug.getString("steps"); - Long createTime = bug.getLong("openedDate"); - String status = bug.getString("status"); - String reporter = bug.getString("openedBy"); - int deleted = bug.getInteger("deleted"); - if (deleted == 1) { - return new Issues(); + try { + ResponseEntity responseEntity = restTemplate.exchange(url + "api-getModel-bug-getById-bugID={bugId}?zentaosid=" + session, + HttpMethod.POST, requestEntity, String.class, bugId); + String body = responseEntity.getBody(); + JSONObject obj = JSONObject.parseObject(body); + + LogUtil.info("bug id is " + bugId + obj); + + if (obj != null) { + JSONObject bug = obj.getJSONObject("data"); + String id = bug.getString("id"); + String title = bug.getString("title"); + String description = bug.getString("steps"); + Long createTime = bug.getLong("openedDate"); + String status = bug.getString("status"); + String reporter = bug.getString("openedBy"); + int deleted = bug.getInteger("deleted"); + if (deleted == 1) { + return new Issues(); + } + Issues issues = new Issues(); + issues.setId(id); + issues.setTitle(title); + issues.setDescription(description); + issues.setCreateTime(createTime); + issues.setStatus(status); + issues.setReporter(reporter); + return issues; } - Issues issues = new Issues(); - issues.setId(id); - issues.setTitle(title); - issues.setDescription(description); - issues.setCreateTime(createTime); - issues.setStatus(status); - issues.setReporter(reporter); - return issues; + } catch (Exception e) { + LogUtil.error("get zentao bug fail " + e.getMessage()); } + return new Issues(); } @@ -150,6 +158,9 @@ public class ZentaoPlatform extends AbstractIssuePlatform { ResponseEntity responseEntity = restTemplate.exchange(url + "api-getModel-bug-create.json?zentaosid=" + session, HttpMethod.POST, requestEntity, String.class); String body = responseEntity.getBody(); JSONObject obj = JSONObject.parseObject(body); + + LogUtil.info("add zentao bug " + obj); + if (obj != null) { JSONObject data = obj.getJSONObject("data"); String id = data.getString("id"); @@ -235,6 +246,9 @@ public class ZentaoPlatform extends AbstractIssuePlatform { HttpMethod.GET, requestEntity, String.class); String body = responseEntity.getBody(); JSONObject obj = JSONObject.parseObject(body); + + LogUtil.info("zentao user " + obj); + JSONArray data = obj.getJSONArray("data"); List users = new ArrayList<>(); @@ -260,6 +274,9 @@ public class ZentaoPlatform extends AbstractIssuePlatform { HttpMethod.GET, requestEntity, String.class, projectId); String body = responseEntity.getBody(); JSONObject obj = JSONObject.parseObject(body); + + LogUtil.info("zentao builds" + obj); + JSONObject data = obj.getJSONObject("data"); Map maps = data.getInnerMap(); From c9bc42bacc5dfba9daf4e4b3adef77eb3a98ce14 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 19 Nov 2020 16:03:32 +0800 Subject: [PATCH 2/3] refactor: flyway --- .../src/main/resources/db/migration/V45__modify_issues.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 backend/src/main/resources/db/migration/V45__modify_issues.sql diff --git a/backend/src/main/resources/db/migration/V45__modify_issues.sql b/backend/src/main/resources/db/migration/V45__modify_issues.sql new file mode 100644 index 0000000000..0617627ced --- /dev/null +++ b/backend/src/main/resources/db/migration/V45__modify_issues.sql @@ -0,0 +1,4 @@ +alter table issues drop primary key; +alter table issues + add constraint issues_pk + primary key (id, platform); \ No newline at end of file From ad685b5a0ed6400e7c36fcd82c896e3e54be4439 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 19 Nov 2020 16:16:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E6=97=B6=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E4=B8=BB=E9=94=AE=E5=86=B2=E7=AA=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/track/issue/ZentaoPlatform.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java index 28c8c3a08e..1d0196651e 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -172,11 +172,16 @@ public class ZentaoPlatform extends AbstractIssuePlatform { testCaseIssues.setTestCaseId(testCaseId); testCaseIssuesMapper.insert(testCaseIssues); - // 插入缺陷表 - Issues issues = new Issues(); - issues.setId(id); - issues.setPlatform(IssuesManagePlatform.Zentao.toString()); - issuesMapper.insert(issues); + IssuesExample issuesExample = new IssuesExample(); + issuesExample.createCriteria().andIdEqualTo(id) + .andPlatformEqualTo(IssuesManagePlatform.Zentao.toString()); + if (issuesMapper.selectByExample(issuesExample).size() <= 0) { + // 插入缺陷表 + Issues issues = new Issues(); + issues.setId(id); + issues.setPlatform(IssuesManagePlatform.Zentao.toString()); + issuesMapper.insert(issues); + } } } }