@@ -164,10 +164,6 @@ | |||
</dependency> | |||
<dependency> | |||
<groupId>com.ningdatech</groupId> | |||
<artifactId>nd-irs-starter</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.ningdatech</groupId> | |||
<artifactId>nd-yxt-starter</artifactId> | |||
<version>1.0.0</version> | |||
</dependency> | |||
@@ -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 "同步成功"; | |||
} | |||
} |
@@ -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<ProvincialGovBusinessStripVO> searchGovUnits(); | |||
} |
@@ -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<ProvincialGovBusinessStripVO> 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<JSONObject> 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); | |||
@@ -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<ProvincialGovBusinessStripVO> 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<ProvincialGovBusinessStrip> 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()); | |||
} | |||
} |
@@ -105,11 +105,6 @@ | |||
<version>1.0.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.ningdatech</groupId> | |||
<artifactId>nd-irs-starter</artifactId> | |||
<version>1.0.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>joda-time</groupId> | |||
<artifactId>joda-time</artifactId> | |||
<version>2.10.6</version> | |||