From 23ba41d277db8597b0b49b781fe15065da5c3a55 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 6 Nov 2023 15:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=9C=81=E7=BA=A7=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GovProjectCollectionController.java | 11 +++ .../manage/GovBusinessStripManage.java | 2 +- .../pmapi/scheduler/task/SynProvinceOrgTask.java | 93 ++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProvinceOrgTask.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/gov/controller/GovProjectCollectionController.java b/pmapi/src/main/java/com/ningdatech/pmapi/gov/controller/GovProjectCollectionController.java index 14d7e1e..8edb466 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/gov/controller/GovProjectCollectionController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/gov/controller/GovProjectCollectionController.java @@ -11,6 +11,7 @@ import com.ningdatech.pmapi.gov.model.vo.GovOperationProjectDetailVO; import com.ningdatech.pmapi.gov.model.vo.GovProjectDictionaryVO; import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq; import com.ningdatech.pmapi.scheduler.task.SynProjectCollectionTask; +import com.ningdatech.pmapi.scheduler.task.SynProvinceOrgTask; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -42,6 +43,8 @@ public class GovProjectCollectionController { private final SynProjectCollectionTask collectionTask; + private final SynProvinceOrgTask synProvinceOrgTask; + @GetMapping("/dictionary") @ApiOperation("字典") public List dictionary(@RequestParam(value = "type", required = false) String type) { @@ -186,4 +189,12 @@ public class GovProjectCollectionController { public String removeProject(@RequestBody List projectCodes){ return collectionManage.removeProject(projectCodes); } + + @GetMapping("/syn-province") + @ApiOperation("同步省级单位") + @WebLog("同步省级单位") + public String synProvince() throws UnknownHostException { + synProvinceOrgTask.doTask(); + return "同步成功"; + } } 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 8ead81d..14ea6cf 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 @@ -63,10 +63,10 @@ public class GovBusinessStripManage { } List strips = provincialGovBusinessStripService.list(Wrappers.lambdaQuery(ProvincialGovBusinessStrip.class) + .like(StringUtils.isNotBlank(businessStripName),ProvincialGovBusinessStrip::getBusinessStripName,businessStripName) .orderByAsc(ProvincialGovBusinessStrip::getBusinessStripName)); return strips.stream() - .filter(b -> StringUtils.isBlank(businessStripName) || b.getBusinessStripName().contains(businessStripName)) .map(p -> BeanUtil.copyProperties(p,ProvincialGovBusinessStripVO.class)) .collect(Collectors.toList()); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProvinceOrgTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProvinceOrgTask.java new file mode 100644 index 0000000..2f05f34 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProvinceOrgTask.java @@ -0,0 +1,93 @@ +package com.ningdatech.pmapi.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.ningdatech.pmapi.organization.model.entity.ProvincialGovBusinessStrip; +import com.ningdatech.pmapi.organization.model.vo.ProvincialGovBusinessStripVO; +import com.ningdatech.pmapi.organization.service.IProvincialGovBusinessStripService; +import com.ningdatech.pmapi.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()); + } +}