From 43b1447c5ba51e1f4e18c4eaf5095c7bd261010d Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 18 Jul 2023 11:48:43 +0800 Subject: [PATCH] =?UTF-8?q?api=20=E5=AE=9E=E4=BD=93=20irs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../irs/controller/ApplicationController.java | 7 ++- .../pmapi/irs/controller/IrsController.java | 4 +- .../ningdatech/pmapi/irs/manage/AppIrsManage.java | 58 +++++++++++++++++----- .../com/ningdatech/pmapi/irs/model/dto/ApiDTO.java | 3 +- .../pmapi/projectdeclared/manage/IrsManage.java | 20 +++++--- 5 files changed, 66 insertions(+), 26 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/ApplicationController.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/ApplicationController.java index 8aac63b..ee4a7dc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/ApplicationController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/ApplicationController.java @@ -1,5 +1,8 @@ package com.ningdatech.pmapi.irs.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.ningdatech.log.annotation.WebLog; import com.ningdatech.pmapi.irs.manage.AppIrsManage; import com.ningdatech.pmapi.irs.model.dto.ApiApplyDTO; @@ -34,12 +37,12 @@ public class ApplicationController { } @GetMapping("/sreach-app") - public ApiApplySearchResult searchApp(ApiApplyDTO apply) throws NoSuchAlgorithmException { + public JSONObject searchApp(ApiApplyDTO apply) throws NoSuchAlgorithmException { return appIrsManage.searchApp(apply); } @GetMapping("/sreach-apps") - public List searchApps(ApiApplyDTO apply) throws NoSuchAlgorithmException { + public JSONArray searchApps(ApiApplyDTO apply) throws NoSuchAlgorithmException { return appIrsManage.searchApps(apply); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java index d783bcd..5ea1c8c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java @@ -31,8 +31,8 @@ public class IrsController { @ApiOperation(value = "irs应用列表", notes = "irs应用列表") @WebLog("irs应用列表") @GetMapping("/application-list") - public List applicationList() { - return irsManage.applicationList(); + public List applicationList(@RequestParam(required = false) String areaCode) { + return irsManage.applicationList(areaCode); } @ApiOperation(value = "试点任务列表", notes = "试点任务列表") diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java index c805dcf..0396c58 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java @@ -2,6 +2,8 @@ package com.ningdatech.pmapi.irs.manage; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.basic.function.VUtils; import com.ningdatech.pmapi.common.enumeration.CommonEnum; @@ -83,8 +85,11 @@ public class AppIrsManage { ApiApplyDTO apiApply = new ApiApplyDTO(); apiApply.setAppId(appCode); - ApiApplySearchResult apiApplySearchResult = this.searchApp(apiApply); - + JSONObject jsonObject = this.searchApp(apiApply); + VUtils.isTrue(Objects.isNull(jsonObject)).throwMessage("应用在IRS不存在!"); + JSONArray data = jsonObject.getJSONArray("data"); + VUtils.isTrue(CollUtil.isNotEmpty(data)).throwMessage("应用在IRS不存在!"); + ApiApplySearchResult apiApplySearchResult = JSON.parseObject(JSON.toJSONString(data.get(0)),ApiApplySearchResult.class); VUtils.isTrue(Objects.isNull(apiApplySearchResult)).throwMessage("应用在IRS不存在!"); long timestamp = System.currentTimeMillis(); @@ -149,7 +154,7 @@ public class AppIrsManage { * @return * @throws NoSuchAlgorithmException */ - public ApiApplySearchResult searchApp(ApiApplyDTO apply) throws NoSuchAlgorithmException { + public JSONObject searchApp(ApiApplyDTO apply) throws NoSuchAlgorithmException { long timestamp = System.currentTimeMillis(); String appCode = apply.getAppId(); String requestSecret = RefreshKeyUtil.getRequestSecret(searchAppKey, searchAppScret); @@ -160,18 +165,33 @@ public class AppIrsManage { "&areaCode=&deptCode=&name="; log.info("url : {}",url); RestTemplate restTemplate = new RestTemplate(); - ResponseEntity forEntity = restTemplate.getForEntity(url, ApiDTO.class); + ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); log.info("查询应用目录 : {}",JSON.toJSONString(forEntity)); - if(Objects.nonNull(forEntity.getBody()) && Objects.nonNull(forEntity.getBody().getDatas()) - && CollUtil.isNotEmpty(forEntity.getBody().getDatas().getApiApplySearchResult())){ - return forEntity.getBody().getDatas().getApiApplySearchResult().get(0); + if(Objects.nonNull(forEntity.getBody()) && Objects.nonNull(forEntity.getBody())){ + JSONObject body = JSON.parseObject(forEntity.getBody()); + if(Objects.isNull(body)){ + return null; + } + JSONObject datas = body.getJSONObject("datas"); + if(Objects.isNull(datas)){ + return null; + } + JSONObject data = datas.getJSONObject("data"); + if(Objects.isNull(data)){ + return null; + } + JSONArray apiApplySearchResult = data.getJSONArray("apiApplySearchResult"); + if(CollUtil.isEmpty(apiApplySearchResult)){ + return null; + } + return apiApplySearchResult.getJSONObject(0); } return null; } - public List searchApps(ApiApplyDTO apply) throws NoSuchAlgorithmException { + public JSONArray searchApps(ApiApplyDTO apply) throws NoSuchAlgorithmException { long timestamp = System.currentTimeMillis(); String areaCode = StringUtils.isNotBlank(apply.getAreaCode()) ? apply.getAreaCode() : null; @@ -182,14 +202,26 @@ public class AppIrsManage { "pageNum=1&areaCode=" + areaCode + "&deptCode=&name="; RestTemplate restTemplate = new RestTemplate(); - ResponseEntity forEntity = restTemplate.getForEntity(url, ApiDTO.class); + ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); log.info("查询应用目录 : {}",JSON.toJSONString(forEntity)); - if(Objects.nonNull(forEntity.getBody()) && Objects.nonNull(forEntity.getBody().getDatas()) - && CollUtil.isNotEmpty(forEntity.getBody().getDatas().getApiApplySearchResult())){ - return forEntity.getBody().getDatas().getApiApplySearchResult(); + if(Objects.nonNull(forEntity.getBody())){ + JSONObject body = JSON.parseObject(forEntity.getBody()); + if(Objects.isNull(body)){ + return null; + } + JSONObject datas = body.getJSONObject("datas"); + if(Objects.isNull(datas)){ + return null; + } + JSONObject data = datas.getJSONObject("data"); + if(Objects.isNull(data)){ + return null; + } + JSONArray apiApplySearchResult = data.getJSONArray("apiApplySearchResult"); + return apiApplySearchResult; } - return Collections.emptyList(); + return null; } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/ApiDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/ApiDTO.java index 0127367..6a65546 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/ApiDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/ApiDTO.java @@ -22,6 +22,5 @@ public class ApiDTO implements Serializable { private String code; private String msg; - private String data; - private ApiSearchResult datas; + private ApiSearchResult data; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java index 6180d22..c8dfcd8 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java @@ -2,10 +2,12 @@ package com.ningdatech.pmapi.projectdeclared.manage; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.pmapi.irs.manage.AppIrsManage; import com.ningdatech.pmapi.irs.model.dto.ApiApplyDTO; -import com.ningdatech.pmapi.irs.model.dto.ApiApplySearchResult; import com.ningdatech.pmapi.projectdeclared.model.entity.IrsApplication; import com.ningdatech.pmapi.projectdeclared.model.entity.NdPiotTasks; import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; @@ -20,6 +22,7 @@ import org.springframework.stereotype.Component; import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -43,7 +46,7 @@ public class IrsManage { private final AppIrsManage appIrsManage; - public List applicationList() { + public List applicationList(String areaCode) { //不请求IRS if(!isSearchApp) { List list = irsApplicationService.list(); @@ -54,12 +57,15 @@ public class IrsManage { } try { - List apiApplySearchResults = appIrsManage.searchApps(new ApiApplyDTO()); - if(CollUtil.isNotEmpty(apiApplySearchResults)){ - return apiApplySearchResults.stream().map(apply -> { + ApiApplyDTO apiApplay = new ApiApplyDTO(); + apiApplay.setAreaCode(areaCode); + JSONArray jsonArray = appIrsManage.searchApps(apiApplay); + if(CollUtil.isNotEmpty(jsonArray)){ + return jsonArray.stream().map(apply -> { + JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(apply)); IrsApplicationVO vo = new IrsApplicationVO(); - vo.setApplicationCode(apply.getAppId()); - vo.setApplicationName(apply.getName()); + vo.setApplicationCode(jsonObject.getString("appId")); + vo.setApplicationName(jsonObject.getString("name")); return vo; }).collect(Collectors.toList()); }