From b7c0f1a9a2fd3c4be7b357123f7291743a95c369 Mon Sep 17 00:00:00 2001 From: CMM <2198256324@qq.com> Date: Mon, 19 Aug 2024 18:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E9=A1=B9=E5=9F=BA=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AFirs=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kq-vas-api/pom.xml | 18 ++- .../src/main/java/com/ningdatech/kqapi/App.java | 2 +- .../common/handler/GlobalResponseHandler.java | 3 +- .../kqapi/irs/controller/IrsController.java | 47 +++++++ .../com/ningdatech/kqapi/irs/manage/IrsManage.java | 149 +++++++++++++++++++++ kq-vas-api/src/main/resources/application-dev.yml | 12 +- kq-vas-api/src/main/resources/application-pre.yml | 12 +- kq-vas-api/src/main/resources/application-prod.yml | 10 ++ .../src/main/resources/security/auth-dev.yml | 1 + .../src/main/resources/security/auth-pre.yml | 1 + .../src/main/resources/security/auth-prod.yml | 2 + 11 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/controller/IrsController.java create mode 100644 kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/manage/IrsManage.java diff --git a/kq-vas-api/pom.xml b/kq-vas-api/pom.xml index 2289230..20b5c38 100644 --- a/kq-vas-api/pom.xml +++ b/kq-vas-api/pom.xml @@ -90,11 +90,11 @@ org.springframework.boot spring-boot-starter-aop - - com.fasterxml.jackson.core - jackson-databind - 2.16.1 - + + + + + com.github.ben-manes.caffeine @@ -157,6 +157,14 @@ com.ningdatech + nd-irs-starter + + + com.ningdatech + nd-cache-starter + + + com.ningdatech nd-file-starter diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java index 06c69d8..9808e5f 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/App.java @@ -24,7 +24,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableGlobalMethodSecurity(prePostEnabled = true) @EnableTransactionManagement @EnableAspectJAutoProxy(exposeProxy = true) -@ComponentScan(basePackages = {"com.ningdatech.kqapi", "com.ningdatech.kqapi.common"}) +@ComponentScan(basePackages = {"com.ningdatech.kqapi", "com.ningdatech.kqapi.common", "com.ningdatech.irs"}) public class App { protected static final String MAPPER_PACKAGES = "com.ningdatech.kqapi.**.mapper"; diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalResponseHandler.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalResponseHandler.java index f6745b9..5e70910 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalResponseHandler.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalResponseHandler.java @@ -23,7 +23,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; "com.ningdatech.kqapi.user.controller", "com.ningdatech.kqapi.security.controller", "com.ningdatech.kqapi.zzsfw.controller", - "com.ningdatech.kqapi.scheduler.controller" + "com.ningdatech.kqapi.scheduler.controller", + "com.ningdatech.kqapi.irs.controller" }) public class GlobalResponseHandler implements ResponseBodyAdvice { diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/controller/IrsController.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/controller/IrsController.java new file mode 100644 index 0000000..7ab939a --- /dev/null +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/controller/IrsController.java @@ -0,0 +1,47 @@ +package com.ningdatech.kqapi.irs.controller; + +import java.util.List; + +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.ningdatech.kqapi.irs.manage.IrsManage; +import com.ningdatech.log.annotation.WebLog; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * @author CMM + * @date 2024/8/19 11:11 + */ +@Slf4j +@Validated +@RestController +@RequestMapping("/api/v1/irs") +@Api(value = "irs", tags = "irs-信息查询") +@RequiredArgsConstructor +public class IrsController { + + private final IrsManage irsManage; + + @ApiOperation(value = "irs事项基本信息列表", notes = "irs事项基本信息列表") + @GetMapping("/item-basic-info-list") + public Object itemBasicInfoList(@RequestParam(required = false) String startDate, + @RequestParam(required = false) String endDate, + @RequestParam Integer pageSize, + @RequestParam Integer pageNum) { + return irsManage.itemBasicInfoList(startDate, endDate, pageSize, pageNum); + } + + @ApiOperation(value = "irs事项基本信息列表", notes = "irs事项基本信息列表") + @GetMapping("/item-basic-info-detail") + public Object itemBasicInfoDetail(@RequestParam String itemId) { + return irsManage.itemBasicInfoDetail(itemId); + } +} diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/manage/IrsManage.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/manage/IrsManage.java new file mode 100644 index 0000000..ca48fba --- /dev/null +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/irs/manage/IrsManage.java @@ -0,0 +1,149 @@ +package com.ningdatech.kqapi.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.ningdatech.irs.service.IRefreshTokenService; +import com.ningdatech.irs.utils.HttpUtil; +import com.ningdatech.kqapi.common.util.CryptUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +/** + * @author CMM + * @author CMM + * @date 2024/8/19 11:27 + * / + * /** + * @since 2024/08/19 11:27 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class IrsManage { + + @Value("${irs.item-basic-info.appKey}") + private String appKey; + + @Value("${irs.item-basic-info.appSecret}") + private String appSecret; + + @Value("${irs.item-basic-info.listUrl}") + private String itemBasicInfoListUrl; + + @Value("${irs.item-basic-info.detailUrl}") + private String itemBasicInfoDetailUrl; + + @Resource + private IRefreshTokenService refreshTokenService; + + @Value("${irs.interface-refresh.request-token-url}") + private String govRequestTokenUrl; + + @Value("${irs.interface-refresh.refresh-token-url}") + private String govRefreshTokenUrl; + + public Object itemBasicInfoList(String startDate, String endDate, Integer pageSize, Integer pageNum) { + long timestamp = System.currentTimeMillis(); + String secret = refreshTokenService.refreshToken(appKey, appSecret, govRequestTokenUrl, govRefreshTokenUrl, + HttpMethod.POST.name()); + String sign = null; + try{ + sign = CryptUtils.MD5Encode(appKey + secret + timestamp); + }catch (Exception e){ + log.error(e.getMessage()); + } + HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); + RestTemplate restTemplate; + if(Objects.nonNull(factory)){ + restTemplate = new RestTemplate(factory); + }else{ + restTemplate = new RestTemplate(); + } + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("pageSize",pageSize); + map.add("pageNum",pageNum); + map.add("startDate",startDate); + map.add("endDate",endDate); + map.add("paramStr","update_date"); + map.add("viewName","v_dsc_sx_ads_share_item_qlt_qlsx_common_i_d_v_kq_insensitive"); + map.add("appKey",appKey); + map.add("sign",sign); + map.add("requestTime",timestamp); + // 创建 HttpHeaders 对象 + HttpHeaders headers = new HttpHeaders(); + // 创建 HttpEntity 对象,并传入 HttpHeaders + HttpEntity httpEntity = new HttpEntity<>(map,headers); + log.info("请求参数 :{}", JSON.toJSONString(map)); + JSONObject jsonObject = restTemplate.postForObject(itemBasicInfoListUrl, httpEntity, JSONObject.class); + log.info("return list data :{}",jsonObject); + + JSONArray dataArray = Objects.requireNonNull(jsonObject).getJSONArray("data"); + List dataList = new ArrayList<>(dataArray); + if(CollUtil.isNotEmpty(dataList)){ + return dataList; + } else { + return jsonObject; + } + } + + public Object itemBasicInfoDetail(String itemId) { + long timestamp = System.currentTimeMillis(); + String secret = refreshTokenService.refreshToken(appKey, appSecret, govRequestTokenUrl, govRefreshTokenUrl, + HttpMethod.POST.name()); + String sign = null; + try{ + sign = CryptUtils.MD5Encode(appKey + secret + timestamp); + }catch (Exception e){ + log.error(e.getMessage()); + } + HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); + RestTemplate restTemplate; + if(Objects.nonNull(factory)){ + restTemplate = new RestTemplate(factory); + }else{ + restTemplate = new RestTemplate(); + } + + MultiValueMap map = new LinkedMultiValueMap<>(); + // 附加信息 + map.add("paramStr",itemId); + map.add("viewName","v_dsc_sx_ads_share_item_qlt_qlsx_common_i_d_v_kq_insensitive"); + map.add("appKey",appKey); + map.add("sign",sign); + map.add("requestTime",timestamp); + // 创建 HttpHeaders 对象 + HttpHeaders headers = new HttpHeaders(); + // 创建 HttpEntity 对象,并传入 HttpHeaders + HttpEntity httpEntity = new HttpEntity<>(map,headers); + log.info("请求参数 :{}", JSON.toJSONString(map)); + JSONObject jsonObject = restTemplate.postForObject(itemBasicInfoDetailUrl, httpEntity, JSONObject.class); + log.info("return detail data :{}",jsonObject); + + JSONArray dataArray = Objects.requireNonNull(jsonObject).getJSONArray("data"); + List dataList = new ArrayList<>(dataArray); + if(CollUtil.isNotEmpty(dataList)){ + return dataList; + } else { + return jsonObject; + } + } +} diff --git a/kq-vas-api/src/main/resources/application-dev.yml b/kq-vas-api/src/main/resources/application-dev.yml index 05ac7a6..c8881a3 100644 --- a/kq-vas-api/src/main/resources/application-dev.yml +++ b/kq-vas-api/src/main/resources/application-dev.yml @@ -1,5 +1,5 @@ server: - port: 33060 + port: 33061 servlet: context-path: /kq shutdown: graceful @@ -144,5 +144,15 @@ sso: user-info: internet-url: https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo zww-url: https://bcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo +irs: + interface-refresh: + method: POST + request-token-url: http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm + refresh-token-url: http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm + item-basic-info: + appSecret: oUu7hk5NnOBghTw + appKey: qlZDZwhFWx + listUrl: https://typt.kq.gov.cn:8888/datashare/rest/query/U0022S00160/V1?apiUuid=C9030E259C6C43BBAA89DDF36F2386B0 + detailUrl: https://typt.kq.gov.cn:8888/gateway/datashare/rest/query/U0022S00159/V1?apiUuid=14ED96404A834101992F00B4F6BBC7ED diff --git a/kq-vas-api/src/main/resources/application-pre.yml b/kq-vas-api/src/main/resources/application-pre.yml index c2b463b..26704c2 100644 --- a/kq-vas-api/src/main/resources/application-pre.yml +++ b/kq-vas-api/src/main/resources/application-pre.yml @@ -140,4 +140,14 @@ sso: zww-url: https://bcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000007/uc/sso/access_token user-info: internet-url: https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo - zww-url: https://bcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo \ No newline at end of file + zww-url: https://bcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo +irs: + interface-refresh: + method: POST + request-token-url: http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm + refresh-token-url: http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm + item-basic-info: + appSecret: oUu7hk5NnOBghTw + appKey: qlZDZwhFWx + listUrl: https://typt.kq.gov.cn:8888/datashare/rest/query/U0022S00160/V1?apiUuid=C9030E259C6C43BBAA89DDF36F2386B0 + detailUrl: https://typt.kq.gov.cn:8888/gateway/datashare/rest/query/U0022S00159/V1?apiUuid=14ED96404A834101992F00B4F6BBC7ED \ No newline at end of file diff --git a/kq-vas-api/src/main/resources/application-prod.yml b/kq-vas-api/src/main/resources/application-prod.yml index 1657e9a..d9b3ad5 100644 --- a/kq-vas-api/src/main/resources/application-prod.yml +++ b/kq-vas-api/src/main/resources/application-prod.yml @@ -145,5 +145,15 @@ sso: user-info: internet-url: https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo zww-url: https://bcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo +irs: + interface-refresh: + method: POST + request-token-url: http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm + refresh-token-url: http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm + item-basic-info: + appSecret: oUu7hk5NnOBghTw + appKey: qlZDZwhFWx + listUrl: https://typt.kq.gov.cn:8888/datashare/rest/query/U0022S00160/V1?apiUuid=C9030E259C6C43BBAA89DDF36F2386B0 + detailUrl: https://typt.kq.gov.cn:8888/gateway/datashare/rest/query/U0022S00159/V1?apiUuid=14ED96404A834101992F00B4F6BBC7ED diff --git a/kq-vas-api/src/main/resources/security/auth-dev.yml b/kq-vas-api/src/main/resources/security/auth-dev.yml index d14de5b..abbfdeb 100644 --- a/kq-vas-api/src/main/resources/security/auth-dev.yml +++ b/kq-vas-api/src/main/resources/security/auth-dev.yml @@ -22,6 +22,7 @@ security: - /ok.html - /open/api/** - /api/v1/wechat/** + - /api/v1/irs/** ignore-csrf-urls: - /**/anonymous/** - /api/v1/poclicy/** diff --git a/kq-vas-api/src/main/resources/security/auth-pre.yml b/kq-vas-api/src/main/resources/security/auth-pre.yml index d14de5b..abbfdeb 100644 --- a/kq-vas-api/src/main/resources/security/auth-pre.yml +++ b/kq-vas-api/src/main/resources/security/auth-pre.yml @@ -22,6 +22,7 @@ security: - /ok.html - /open/api/** - /api/v1/wechat/** + - /api/v1/irs/** ignore-csrf-urls: - /**/anonymous/** - /api/v1/poclicy/** diff --git a/kq-vas-api/src/main/resources/security/auth-prod.yml b/kq-vas-api/src/main/resources/security/auth-prod.yml index 70cc394..2874e42 100644 --- a/kq-vas-api/src/main/resources/security/auth-prod.yml +++ b/kq-vas-api/src/main/resources/security/auth-prod.yml @@ -19,6 +19,7 @@ security: - /doc.html - /ok.html - /api/v1/wechat/** + - /api/v1/irs/** ignore-csrf-urls: - /**/anonymous/** - /api/v1/user/auth/** @@ -34,6 +35,7 @@ security: - /optLog/** - /dict/** - /api/v1/wechat/** + - /api/v1/irs/** role-map: "engineer": "project_manager":