From 8c6a0fa75bb1dd1ac9cb7e962ce43d05798c4548 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 31 Aug 2021 16:08:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E9=9B=86=E6=88=90=E7=A6=85=E9=81=9311.5=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=9C=80=E6=B1=82=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/issue/ZentaoPlatform.java | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 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 8bf85c2c7a..0824152bc4 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -107,25 +107,43 @@ public class ZentaoPlatform extends AbstractIssuePlatform { String body = responseEntity.getBody(); JSONObject obj = JSONObject.parseObject(body); - LogUtil.info("project story" + key + obj); + LogUtil.info("project story: " + key + obj); if (obj != null) { - JSONObject data = obj.getJSONObject("data"); - String s = JSON.toJSONString(data); - Map map = JSONArray.parseObject(s, new TypeReference>(){}); - Collection values = map.values(); - values.forEach(v -> { - JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(v)); - DemandDTO demandDTO = new DemandDTO(); - demandDTO.setId(jsonObject.getString("id")); - demandDTO.setName(jsonObject.getString("title")); - demandDTO.setPlatform(IssuesManagePlatform.Zentao.name()); - list.add(demandDTO); - }); - + String data = obj.getString("data"); + if (StringUtils.isBlank(data)) { + return list; + } + // 兼容处理11.5版本格式 [{obj},{obj}] + if (data.charAt(0) == '[') { + JSONArray array = obj.getJSONArray("data"); + for (int i = 0; i < array.size(); i++) { + JSONObject o = array.getJSONObject(i); + DemandDTO demandDTO = new DemandDTO(); + demandDTO.setId(o.getString("id")); + demandDTO.setName(o.getString("title")); + demandDTO.setPlatform(IssuesManagePlatform.Zentao.name()); + list.add(demandDTO); + } + } + // 处理格式 {{"id": {obj}},{"id",{obj}}} + else if (data.charAt(0) == '{') { + JSONObject dataObject = obj.getJSONObject("data"); + String s = JSON.toJSONString(dataObject); + Map map = JSONArray.parseObject(s, new TypeReference>(){}); + Collection values = map.values(); + values.forEach(v -> { + JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(v)); + DemandDTO demandDTO = new DemandDTO(); + demandDTO.setId(jsonObject.getString("id")); + demandDTO.setName(jsonObject.getString("title")); + demandDTO.setPlatform(IssuesManagePlatform.Zentao.name()); + list.add(demandDTO); + }); + } } } catch (Exception e) { - LogUtil.error("get zentao bug fail " + e.getMessage()); + LogUtil.error("get zentao demand fail " + e.getMessage()); } return list; }