From 83f921a099ec8172a35a8e904f418048f0894c3e Mon Sep 17 00:00:00 2001 From: WendyYang Date: Fri, 12 Apr 2024 16:40:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hz-pm-api/pom.xml | 4 - .../controller/GovProjectCollectionController.java | 10 --- .../IJoinReviewProvincialBureauService.java | 14 +--- .../JoinReviewProvincialBureauServiceImpl.java | 74 ----------------- .../pm/api/scheduler/task/SynProvinceOrgTask.java | 93 ---------------------- pom.xml | 5 -- 6 files changed, 4 insertions(+), 196 deletions(-) delete mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/SynProvinceOrgTask.java diff --git a/hz-pm-api/pom.xml b/hz-pm-api/pom.xml index cac0e83..c5869be 100644 --- a/hz-pm-api/pom.xml +++ b/hz-pm-api/pom.xml @@ -164,10 +164,6 @@ com.ningdatech - nd-irs-starter - - - com.ningdatech nd-yxt-starter 1.0.0 diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/gov/controller/GovProjectCollectionController.java b/hz-pm-api/src/main/java/com/hz/pm/api/gov/controller/GovProjectCollectionController.java index c75b47c..8c2776e 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/gov/controller/GovProjectCollectionController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/gov/controller/GovProjectCollectionController.java @@ -8,7 +8,6 @@ import com.hz.pm.api.gov.model.vo.GovBizProjectListVO; import com.hz.pm.api.gov.model.vo.GovOperationProjectDetailVO; import com.hz.pm.api.gov.model.vo.GovProjectDictionaryVO; import com.hz.pm.api.projectlib.model.req.ProjectListReq; -import com.hz.pm.api.scheduler.task.SynProvinceOrgTask; import com.ningdatech.basic.model.PageVo; import com.ningdatech.log.annotation.WebLog; import io.swagger.annotations.Api; @@ -19,7 +18,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; -import java.net.UnknownHostException; import java.util.List; /** @@ -39,7 +37,6 @@ import java.util.List; public class GovProjectCollectionController { private final GovProjectCollectionManage collectionManage; - private final SynProvinceOrgTask synProvinceOrgTask; @GetMapping("/dictionary") @ApiOperation("字典") @@ -165,11 +162,4 @@ public class GovProjectCollectionController { return collectionManage.removeProject(projectCodes); } - @GetMapping("/syn-province") - @ApiOperation("同步省级单位") - @WebLog("同步省级单位") - public String synProvince() throws UnknownHostException { - synProvinceOrgTask.doTask(); - return "同步成功"; - } } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/IJoinReviewProvincialBureauService.java b/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/IJoinReviewProvincialBureauService.java index c5701cb..4f9595d 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/IJoinReviewProvincialBureauService.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/IJoinReviewProvincialBureauService.java @@ -1,11 +1,8 @@ package com.hz.pm.api.provincial.service; -import com.hz.pm.api.organization.model.vo.ProvincialGovBusinessStripVO; import com.hz.pm.api.provincial.model.dto.ProvincialProjectDTO; import com.hz.pm.api.provincial.model.res.SjApiResponse; -import java.util.List; - /** * @Classname JointReviewProvincialBureauService * @Description 省局联审接口 @@ -16,20 +13,17 @@ public interface IJoinReviewProvincialBureauService { /** * 推送/保存 重大接口到 省局联审 - * @return + * + * @return \ */ Boolean pushImportProject(ProvincialProjectDTO project); /** * 查看 本区域 省局联审 的项目审核详情 - * @return + * + * @return \ */ SjApiResponse processInfo(String projectId); - /** - * 查询省级主管单位列表 - * @return - */ - List searchGovUnits(); } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java b/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java index 9feb273..79f974f 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/provincial/service/impl/JoinReviewProvincialBureauServiceImpl.java @@ -1,19 +1,10 @@ package com.hz.pm.api.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.google.common.collect.Maps; -import com.ningdatech.irs.contants.IrsContant; -import com.ningdatech.irs.service.IRefreshTokenService; import com.hz.pm.api.common.config.ProvincialProperties; -import com.hz.pm.api.common.model.constant.BizConst; -import com.hz.pm.api.common.util.HttpUtil; -import com.hz.pm.api.organization.model.vo.ProvincialGovBusinessStripVO; import com.hz.pm.api.provincial.model.dto.ProvinceApiResponse; import com.hz.pm.api.provincial.model.dto.ProvincialProjectDTO; import com.hz.pm.api.provincial.model.res.SjApiResponse; @@ -25,16 +16,9 @@ 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 * @Description 省局联审接口 @@ -47,13 +31,8 @@ public class JoinReviewProvincialBureauServiceImpl implements IJoinReviewProvinc @Autowired private ProvincialProperties provincialProperties; - @Autowired private RestTemplate restTemplate; - - @Resource - private IRefreshTokenService refreshTokenService; - @Value("${irs.interface-refresh.request-token-url:}") private String govRequestTokenUrl; @Value("${irs.interface-refresh.refresh-token-url:}") @@ -152,59 +131,6 @@ public class JoinReviewProvincialBureauServiceImpl implements IJoinReviewProvinc return responseEntity.getBody(); } - @Override - public List searchGovUnits() { - long timeStamp = System.currentTimeMillis(); - Long timeSeconds = 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); - HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); - RestTemplate restTemplate; - if (Objects.nonNull(factory)) { - restTemplate = new RestTemplate(factory); - } else { - restTemplate = new RestTemplate(); - } - - String authSignature = getSha256(timeSeconds, provincialProperties.getDomainUrl(), HttpMethod.POST.name(), - provincialProperties.getKey(), provincialProperties.getSecret()); - String url = govUrl + "?appKey=" + appKey + - "×tamp=" + timeSeconds + "&sign=" + sign + - "&authKey=" + provincialProperties.getKey() + "&authSignature=" + authSignature + - "&requestTime=" + timeStamp; - 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); diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/SynProvinceOrgTask.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/SynProvinceOrgTask.java deleted file mode 100644 index 4965ca5..0000000 --- a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/SynProvinceOrgTask.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.hz.pm.api.scheduler.task; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.StopWatch; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.collect.Lists; -import com.hz.pm.api.organization.model.entity.ProvincialGovBusinessStrip; -import com.hz.pm.api.organization.model.vo.ProvincialGovBusinessStripVO; -import com.hz.pm.api.organization.service.IProvincialGovBusinessStripService; -import com.hz.pm.api.provincial.service.IJoinReviewProvincialBureauService; -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.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ZPF - * @since 2023/08/31 18:16 - */ -@Component -@Slf4j -@RequiredArgsConstructor -public class SynProvinceOrgTask { - - @Value("${hostname:}") - public String HOST; - - @Value("${spring.profiles.active}") - public String active; - - @Autowired - private IProvincialGovBusinessStripService provincialGovBusinessStripService; - - @Autowired - private IJoinReviewProvincialBureauService joinReviewProvincialBureauService; - - /** - * - */ - @Scheduled(cron = "0 0 3 * * ?") - public void doTask() throws UnknownHostException { - if (!HOST.equals(InetAddress.getLocalHost().getHostName())) { - log.info("定时器没开启或者host不对! {}:{}", - HOST,InetAddress.getLocalHost().getHostName()); - return; - } - - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - - log.info("同步省局升级单位数据任务开始====={}s",stopWatch.getTotalTimeSeconds()); - - List res = Lists.newArrayList(); - for(int i = 0;i < 10;i++){ - res = joinReviewProvincialBureauService.searchGovUnits(); - if(CollUtil.isNotEmpty(res)){ - log.info("请求到了数据 :{}",res.size()); - break; - } - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - if(CollUtil.isEmpty(res)){ - log.info("一直都没请求到数据 任务结束"); - return; - } - - - log.info("数据同步任务开始之前 先删除前置机上的所有数据"); - provincialGovBusinessStripService.remove(Wrappers.lambdaQuery(ProvincialGovBusinessStrip.class)); - - List saves = res.stream().map(r -> { - ProvincialGovBusinessStrip strip = new ProvincialGovBusinessStrip(); - strip.setBusinessStripCode(r.getBusinessStripCode()); - strip.setBusinessStripName(r.getBusinessStripName()); - return strip; - }).collect(Collectors.toList()); - provincialGovBusinessStripService.saveBatch(saves); - - stopWatch.stop(); - log.info("同步省局升级单位数据任务结束====={}s",stopWatch.getTotalTimeSeconds()); - } -} diff --git a/pom.xml b/pom.xml index c61a100..e1bfa25 100644 --- a/pom.xml +++ b/pom.xml @@ -105,11 +105,6 @@ 1.0.0 - com.ningdatech - nd-irs-starter - 1.0.0 - - joda-time joda-time 2.10.6