From 97addd83613c10183c883d5f63d964a5e236564d Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Thu, 27 Jul 2023 14:50:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=A4=A7=E9=A1=B9=E7=9B=AE=E8=81=94?= =?UTF-8?q?=E5=AE=A1=E5=8F=91=E9=80=81=E7=BA=BF=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/common/config/ProvincialProperties.java | 2 + .../ningdatech/pmapi/common/constant/BizConst.java | 3 + .../ding/controller/DingInfoPullController.java | 52 +----------- .../manage/GovBusinessStripManage.java | 11 +++ .../IJoinReviewProvincialBureauService.java | 10 +++ .../JoinReviewProvincialBureauServiceImpl.java | 94 ++++++++++++++++++++-- pmapi/src/main/resources/application-dev.yml | 6 ++ pmapi/src/main/resources/application-pre.yml | 6 ++ pmapi/src/main/resources/application-prod.yml | 6 ++ pmapi/src/test/resources/application-dev.yml | 1 + pmapi/src/test/resources/application-pre.yml | 1 + pmapi/src/test/resources/application-prod.yml | 1 + 12 files changed, 136 insertions(+), 57 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/config/ProvincialProperties.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/config/ProvincialProperties.java index e145d08..1fdee25 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/config/ProvincialProperties.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/config/ProvincialProperties.java @@ -21,6 +21,8 @@ public class ProvincialProperties { private String detailUrl; + private String domainUrl; + private String key; private String secret; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java index 8a3718c..2defb4b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java @@ -85,4 +85,7 @@ public interface BizConst { int MAX_EXPORT_COUNT = 5000; + String RESPONSE_KEY_DATA = "data"; + String ORG_NAME = "organizationName"; + String ORG_CODE = "organizationCode"; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java index 94fe0cc..0e3b3da 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java @@ -2,27 +2,22 @@ package com.ningdatech.pmapi.ding.controller; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; +import com.google.common.collect.Maps; import com.ningdatech.irs.service.IRefreshTokenService; -import com.ningdatech.pmapi.common.config.ProvincialProperties; import com.ningdatech.pmapi.common.util.CryptUtils; import com.ningdatech.pmapi.common.util.HttpUtil; import com.ningdatech.pmapi.ding.task.EmployeeBatchGetTask; import com.ningdatech.pmapi.ding.task.GovBusinessStripsTask; import com.ningdatech.pmapi.ding.task.OrganizationBatchGetTask; import com.ningdatech.pmapi.organization.manage.ProcDefManage; -import com.ningdatech.zwdd.ZwddIntegrationProperties; -import com.ningdatech.zwdd.client.provider.ZwddAuthClientProvider; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; - import javax.annotation.Resource; import java.security.NoSuchAlgorithmException; import java.util.Objects; @@ -55,11 +50,6 @@ public class DingInfoPullController { @Value("${irs.interface-refresh.refresh-token-url}") private String govRefreshTokenUrl; - private final ZwddIntegrationProperties zwddIntegrationProperties; - - @Autowired - private ProvincialProperties provincialProperties; - @GetMapping("/employee") public void employeeBatchGet() { employeeBatchGetTask.batchGetEmployeeTask(); @@ -117,36 +107,6 @@ public class DingInfoPullController { return procDefManage.initByArea(areaCode); } - @ApiOperation(value = "省级主管接口测试", notes = "省级主管接口测试") - @GetMapping("/test-org") - public String testOrg() throws NoSuchAlgorithmException { - Long timeStamp = System.currentTimeMillis(); - String appSecret = "496f0f2a19994f76b4fd9dae087366c7"; - String appKey = "A331101453557202109017383"; - String method = "POST"; - String secret = refreshTokenService.refreshToken(appKey,appSecret,govRequestTokenUrl,govRefreshTokenUrl,method); - String sign = CryptUtils.MD5Encode(appKey + secret + timeStamp); - HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); - RestTemplate restTemplate; - if(Objects.nonNull(factory)){ - restTemplate = new RestTemplate(factory); - }else{ - restTemplate = new RestTemplate(); - } - - String url = "https://interface.zjzwfw.gov.cn/gateway" + - "/api/proxy/001003001029/dataSharing/62vd5jAdM0b7Gr00.htm?" + - "requestTime=" + timeStamp + "&sign=" + sign + - "&appKey=" + appKey + "×tamp=" + timeStamp + - "&authSignature=" + getSha256(timeStamp/1000,provincialProperties.getPushUrl(), HttpMethod.GET.name()) + - "&authKey=" + provincialProperties.getKey(); - log.info("url :{}",url); - ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); - log.info(forEntity.getBody()); - - return forEntity.getBody(); - } - @ApiOperation(value = "测试项目归并", notes = "测试项目归并") @GetMapping("/test-guibing") public String testGuibing() throws NoSuchAlgorithmException { @@ -177,14 +137,4 @@ public class DingInfoPullController { log.info(forEntity.getBody()); return forEntity.getBody(); } - - private String getSha256(Long timeStamp,String url,String method){ - String secret = provincialProperties.getSecret(); - String key = provincialProperties.getKey(); - String bytesToSign = method + StrUtil.LF + url + StrUtil.LF + timeStamp + StrUtil.LF + key; - log.info("加密message :{}",bytesToSign); - String res = SecureUtil.hmacSha256(secret).digestBase64(bytesToSign,false); - log.info("加密结果 :{}",res); - return res; - } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java index ded0c81..3e7bb31 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java @@ -8,8 +8,10 @@ import com.ningdatech.pmapi.organization.model.vo.GovBusinessStripTreeVO; import com.ningdatech.pmapi.organization.model.vo.ProvincialGovBusinessStripVO; import com.ningdatech.pmapi.organization.service.IGovBusinessStripService; import com.ningdatech.pmapi.organization.service.IProvincialGovBusinessStripService; +import com.ningdatech.pmapi.provincial.service.IJoinReviewProvincialBureauService; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -30,6 +32,11 @@ public class GovBusinessStripManage { private final IProvincialGovBusinessStripService provincialGovBusinessStripService; + private final IJoinReviewProvincialBureauService joinReviewProvincialBureauService; + + @Value("${irs.province-gov.can-search}") + private Boolean canSearch; + public List getChildOrganizationList(String parentCode) { if (Objects.isNull(parentCode)) { parentCode = "-1"; @@ -48,6 +55,10 @@ public class GovBusinessStripManage { } public List getProvincialGovBusinessStripList(String businessStripName) { + if(Objects.nonNull(canSearch) && canSearch){ + return joinReviewProvincialBureauService.searchGovUnits(); + } + List strips = provincialGovBusinessStripService.list(Wrappers.lambdaQuery(ProvincialGovBusinessStrip.class) .orderByAsc(ProvincialGovBusinessStrip::getBusinessStripName)); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/IJoinReviewProvincialBureauService.java b/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/IJoinReviewProvincialBureauService.java index 91732b8..74f405b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/IJoinReviewProvincialBureauService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/IJoinReviewProvincialBureauService.java @@ -1,8 +1,12 @@ package com.ningdatech.pmapi.provincial.service; +import com.ningdatech.pmapi.organization.model.vo.ProvincialGovBusinessStripVO; import com.ningdatech.pmapi.provincial.model.dto.ProvincialProjectDTO; import com.ningdatech.pmapi.provincial.model.res.SjApiResponse; +import java.security.NoSuchAlgorithmException; +import java.util.List; + /** * @Classname JointReviewProvincialBureauService * @Description 省局联审接口 @@ -23,4 +27,10 @@ public interface IJoinReviewProvincialBureauService { * @return */ SjApiResponse processInfo(String projectId); + + /** + * 查询省级主管单位列表 + * @return + */ + List searchGovUnits(); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java index d5d12f9..931fc95 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java @@ -1,23 +1,38 @@ package com.ningdatech.pmapi.provincial.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; +import cn.hutool.crypto.digest.MD5; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.ningdatech.basic.model.ApiResponse; +import com.google.common.collect.Maps; +import com.ningdatech.irs.contants.IrsContant; +import com.ningdatech.irs.service.IRefreshTokenService; import com.ningdatech.pmapi.common.config.ProvincialProperties; +import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.common.util.HttpUtil; +import com.ningdatech.pmapi.organization.model.vo.ProvincialGovBusinessStripVO; import com.ningdatech.pmapi.provincial.model.dto.ProvinceApiResponse; import com.ningdatech.pmapi.provincial.model.dto.ProvincialProjectDTO; import com.ningdatech.pmapi.provincial.model.res.SjApiResponse; import com.ningdatech.pmapi.provincial.service.IJoinReviewProvincialBureauService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * @Classname JointReviewProvincialBureauService @@ -35,6 +50,23 @@ public class JoinReviewProvincialBureauServiceImpl implements IJoinReviewProvinc @Autowired private RestTemplate restTemplate; + @Resource(name = "refreshToken") + private IRefreshTokenService refreshTokenService; + + @Value("${irs.interface-refresh.request-token-url}") + private String govRequestTokenUrl; + @Value("${irs.interface-refresh.refresh-token-url}") + private String govRefreshTokenUrl; + + @Value("${irs.province-gov.url}") + private String govUrl; + + @Value("${irs.province-gov.appSecret}") + private String govAppSecret; + + @Value("${irs.province-gov.appKey}") + private String govAppKey; + /** * 推送/保存 重大接口到 省局联审 * @return @@ -48,7 +80,7 @@ public class JoinReviewProvincialBureauServiceImpl implements IJoinReviewProvinc ResponseEntity responseEntity = null; String signature = getSha256(timeStamp,provincialProperties.getPushUrl(), - HttpMethod.POST.name()); + HttpMethod.POST.name(),provincialProperties.getKey(),provincialProperties.getSecret()); //发送post请求 RequestEntity requestEntity = RequestEntity @@ -90,7 +122,7 @@ public class JoinReviewProvincialBureauServiceImpl implements IJoinReviewProvinc ResponseEntity responseEntity = null; String signature = getSha256(timeStamp,provincialProperties.getDetailUrl(), - HttpMethod.POST.name()); + HttpMethod.POST.name(),provincialProperties.getKey(),provincialProperties.getSecret()); JSONObject jsonBaby = new JSONObject(); jsonBaby.put("projectId",projectId); @@ -114,9 +146,59 @@ public class JoinReviewProvincialBureauServiceImpl implements IJoinReviewProvinc return responseEntity.getBody(); } - private String getSha256(Long timeStamp,String url,String method){ - String secret = provincialProperties.getSecret(); - String key = provincialProperties.getKey(); + @Override + public List searchGovUnits() { + Long timeStamp = System.currentTimeMillis()/1000; + String appSecret = govAppSecret; + String appKey = govAppKey; + String method = HttpMethod.POST.name(); + String secret = refreshTokenService.refreshToken(appKey,appSecret,govRequestTokenUrl,govRefreshTokenUrl,method); + String sign = MD5.create().digestHex(appKey + secret + timeStamp * 1000); + HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); + RestTemplate restTemplate; + if(Objects.nonNull(factory)){ + restTemplate = new RestTemplate(factory); + }else{ + restTemplate = new RestTemplate(); + } + + String authSignature = getSha256(timeStamp,provincialProperties.getDomainUrl(), HttpMethod.POST.name(), + provincialProperties.getKey(),provincialProperties.getSecret()); + String url = govUrl + "?appKey=" + appKey + + "×tamp=" + timeStamp + "&sign=" + sign + + "&authKey=" + provincialProperties.getKey() + "&authSignature=" + authSignature + + "&requestTime=" + timeStamp*1000; + log.info("gov search url :{}",url); + ResponseEntity forEntity = restTemplate.postForEntity(url,null, JSONObject.class, Maps.newHashMap()); + JSONObject body = forEntity.getBody(); + log.info("seach response :{}",body); + if(Objects.isNull(body)){ + return Collections.emptyList(); + } + String code = body.getString(IrsContant.RefreshToken.RESPONSE_KEY_CODE); + if(IrsContant.RefreshToken.SUCESS_CODE.equals(code)){ + JSONObject datas = body.getJSONObject(IrsContant.RefreshToken.RESPONSE_KEY_DATAS); + + if(Objects.isNull(datas)){ + return Collections.emptyList(); + } + JSONArray jsonArray = datas.getJSONArray(BizConst.RESPONSE_KEY_DATA); + if(CollUtil.isEmpty(jsonArray)){ + return Collections.emptyList(); + } + return jsonArray.stream().map(j -> { + JSONObject json = JSON.parseObject(JSON.toJSONString(j)); + ProvincialGovBusinessStripVO vo = new ProvincialGovBusinessStripVO(); + vo.setBusinessStripCode(json.getString(BizConst.ORG_CODE)); + vo.setBusinessStripName(json.getString(BizConst.ORG_NAME)); + return vo; + }).collect(Collectors.toList()); + } + + return Collections.emptyList(); + } + + private static String getSha256(Long timeStamp,String url,String method,String key,String secret){ String bytesToSign = method + StrUtil.LF + url + StrUtil.LF + timeStamp + StrUtil.LF + key; log.info("加密message :{}",bytesToSign); String res = SecureUtil.hmacSha256(secret).digestBase64(bytesToSign,false); diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index 58d3b93..8fd2e57 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -198,6 +198,7 @@ provincial: host: http://223.4.72.75/prometheus-zhejiang_foreign pushUrl: /api/v1/foreign/importantPro detailUrl: /api/v1/foreign/importantProView + domainUrl: /api/v1/foreign/dominantUnit key: 7fb48b518c6044a5a44deddd11b445e3 secret: ced8fff70018413c9516c58f95885624 @@ -223,6 +224,11 @@ irs: url: https://interface.zjzwfw.gov.cn/gateway/api/001003001029/dataSharing/XS8daav3bcemZ3Ra.htm appScret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + province-gov: + can-search: false + url: https://interface.zjzwfw.gov.cn/gateway/api/proxy/001003001029/dataSharing/62vd5jAdM0b7Gr00.htm + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/main/resources/application-pre.yml b/pmapi/src/main/resources/application-pre.yml index 13e7d71..d1ab2c5 100644 --- a/pmapi/src/main/resources/application-pre.yml +++ b/pmapi/src/main/resources/application-pre.yml @@ -196,6 +196,7 @@ provincial: host: https://pms.zj.gov.cn/prometheus-zhejiang_foreign pushUrl: /api/v1/foreign/importantPro detailUrl: /api/v1/foreign/importantProView + domainUrl: /api/v1/foreign/dominantUnit key: b5b2096953534a53991be4ea95f8cffa secret: 1bec9b77134d4962ac466fbe9696b897 # host: http://223.4.72.75/prometheus-zhejiang_foreign @@ -226,6 +227,11 @@ irs: url: https://interface.zjzwfw.gov.cn/gateway/api/001003001029/dataSharing/XS8daav3bcemZ3Ra.htm appScret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + province-gov: + can-search: true + url: https://interface.zjzwfw.gov.cn/gateway/api/proxy/001003001029/dataSharing/62vd5jAdM0b7Gr00.htm + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/main/resources/application-prod.yml b/pmapi/src/main/resources/application-prod.yml index 0a2472b..b1256f1 100644 --- a/pmapi/src/main/resources/application-prod.yml +++ b/pmapi/src/main/resources/application-prod.yml @@ -196,6 +196,7 @@ provincial: host: https://pms.zj.gov.cn/prometheus-zhejiang_foreign pushUrl: /api/v1/foreign/importantPro detailUrl: /api/v1/foreign/importantProView + domainUrl: /api/v1/foreign/dominantUnit key: b5b2096953534a53991be4ea95f8cffa secret: 1bec9b77134d4962ac466fbe9696b897 # host: http://223.4.72.75/prometheus-zhejiang_foreign @@ -226,6 +227,11 @@ irs: url: https://interface.zjzwfw.gov.cn/gateway/api/001003001029/dataSharing/XS8daav3bcemZ3Ra.htm appScret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + province-gov: + can-search: true + url: https://interface.zjzwfw.gov.cn/gateway/api/proxy/001003001029/dataSharing/62vd5jAdM0b7Gr00.htm + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/test/resources/application-dev.yml b/pmapi/src/test/resources/application-dev.yml index 803eb10..ee13bfa 100644 --- a/pmapi/src/test/resources/application-dev.yml +++ b/pmapi/src/test/resources/application-dev.yml @@ -197,6 +197,7 @@ provincial: host: http://zj.ningdatech.com/prometheus-zhejiang_foreign pushUrl: /api/v1/foreign/importantPro detailUrl: /api/v1/foreign/importantProView + domainUrl: /api/v1/foreign/dominantUnit key: 7196317343a64e67895dc0375c098fe7 secret: 75152a97f20e4c4c854dc6301cf72ad4 diff --git a/pmapi/src/test/resources/application-pre.yml b/pmapi/src/test/resources/application-pre.yml index 35637c8..079eaf9 100644 --- a/pmapi/src/test/resources/application-pre.yml +++ b/pmapi/src/test/resources/application-pre.yml @@ -201,6 +201,7 @@ provincial: host: http://223.4.72.75/prometheus-zhejiang_foreign pushUrl: /api/v1/foreign/importantPro detailUrl: /api/v1/foreign/importantProView + domainUrl: /api/v1/foreign/dominantUnit key: 7fb48b518c6044a5a44deddd11b445e3 secret: ced8fff70018413c9516c58f95885624 diff --git a/pmapi/src/test/resources/application-prod.yml b/pmapi/src/test/resources/application-prod.yml index df40152..344344a 100644 --- a/pmapi/src/test/resources/application-prod.yml +++ b/pmapi/src/test/resources/application-prod.yml @@ -196,6 +196,7 @@ provincial: host: https://pms.zj.gov.cn/prometheus-zhejiang_foreign pushUrl: /api/v1/foreign/importantPro detailUrl: /api/v1/foreign/importantProView + domainUrl: /api/v1/foreign/dominantUnit key: b5b2096953534a53991be4ea95f8cffa secret: 1bec9b77134d4962ac466fbe9696b897