Browse Source

同步省级单位状态

tags/24080901
PoffyZhang 1 year ago
parent
commit
23ba41d277
3 changed files with 105 additions and 1 deletions
  1. +11
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/gov/controller/GovProjectCollectionController.java
  2. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java
  3. +93
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProvinceOrgTask.java

+ 11
- 0
pmapi/src/main/java/com/ningdatech/pmapi/gov/controller/GovProjectCollectionController.java View File

@@ -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<GovProjectDictionaryVO> dictionary(@RequestParam(value = "type", required = false) String type) {
@@ -186,4 +189,12 @@ public class GovProjectCollectionController {
public String removeProject(@RequestBody List<String> projectCodes){
return collectionManage.removeProject(projectCodes);
}

@GetMapping("/syn-province")
@ApiOperation("同步省级单位")
@WebLog("同步省级单位")
public String synProvince() throws UnknownHostException {
synProvinceOrgTask.doTask();
return "同步成功";
}
}

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java View File

@@ -63,10 +63,10 @@ public class GovBusinessStripManage {
}

List<ProvincialGovBusinessStrip> 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());
}


+ 93
- 0
pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProvinceOrgTask.java View File

@@ -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<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());
}
}

Loading…
Cancel
Save