From b8084f6af0dac7ac1ab78f5f3aa01d144410b7d4 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Wed, 13 Sep 2023 16:24:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B8=E5=BF=83=E4=B8=9A=E5=8A=A1=20?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ningdatech/pmapi/common/constant/BizConst.java | 5 + .../pmapi/irs/controller/IrsController.java | 10 ++ .../pmapi/irs/mapper/ProjectCoreBizMapper.java | 16 +++ .../pmapi/irs/model/entity/ProjectCoreBiz.java | 52 ++++++++ .../pmapi/irs/service/IProjectCoreBizService.java | 21 +++ .../service/impl/ProjectCoreBizServiceImpl.java | 21 +++ .../model/entity/DingOrganization.java | 1 + .../organization/model/vo/OrganizationTreeVO.java | 4 +- .../model/vo/ResOrganizationListVO.java | 2 + .../contants/ProjectCodeContant.java | 1 + .../scheduler/task/SynProjectCoreBizTask.java | 144 +++++++++++++++++++++ 11 files changed, 275 insertions(+), 2 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/mapper/ProjectCoreBizMapper.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/model/entity/ProjectCoreBiz.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/service/IProjectCoreBizService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/service/impl/ProjectCoreBizServiceImpl.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCoreBizTask.java 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 59f551e..29b767c 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 @@ -87,6 +87,11 @@ public interface BizConst { int MAX_EXPORT_COUNT = 5000; String RESPONSE_KEY_DATA = "data"; + String RESPONSE_KEY_ID = "id"; + String RESPONSE_KEY_DING_CODE = "dingCode"; + String RESPONSE_KEY_MATTER_NAME = "matterName"; + String RESPONSE_KEY_ORG_NAME = "orgName"; + String RESPONSE_KEY_USER_STATE = "userState"; String ORG_NAME = "organizationName"; String ORG_CODE = "organizationCode"; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java index f5b1ed0..183869f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java @@ -5,6 +5,7 @@ import com.ningdatech.pmapi.irs.model.dto.ForwardDTO; import com.ningdatech.pmapi.projectdeclared.manage.IrsManage; import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; import com.ningdatech.pmapi.projectdeclared.model.vo.PiotTasksVO; +import com.ningdatech.pmapi.scheduler.task.SynProjectCoreBizTask; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.io.UnsupportedEncodingException; +import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import java.util.List; @@ -35,6 +37,8 @@ public class IrsController { private final IrsManage irsManage; + private final SynProjectCoreBizTask projectCoreBizTask; + @ApiOperation(value = "irs应用列表", notes = "irs应用列表") @WebLog("irs应用列表") @GetMapping("/application-list") @@ -54,4 +58,10 @@ public class IrsController { public String getCreditCode() throws NoSuchAlgorithmException, UnsupportedEncodingException { return irsManage.getCreditCode(); } + + @ApiOperation(value = "强制刷新核心业务", notes = "强制刷新核心业务") + @GetMapping("/refresh-core-biz") + public void refreshCoreBiz() throws UnknownHostException { + projectCoreBizTask.doTask(); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/mapper/ProjectCoreBizMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/mapper/ProjectCoreBizMapper.java new file mode 100644 index 0000000..dca3ec1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/mapper/ProjectCoreBizMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.irs.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.irs.model.entity.ProjectCoreBiz; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zpf + * @since 2023-09-13 + */ +public interface ProjectCoreBizMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/entity/ProjectCoreBiz.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/entity/ProjectCoreBiz.java new file mode 100644 index 0000000..e885b61 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/entity/ProjectCoreBiz.java @@ -0,0 +1,52 @@ +package com.ningdatech.pmapi.irs.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @Classname ProjectCoreBiz + * @Description + * @Date 2023/9/13 15:33 + * @Author PoffyZhang + */ +@Data +@TableName("nd_project_core_biz") +@ApiModel(value = "项目核心业务对象") +public class ProjectCoreBiz { + @TableId(type = IdType.AUTO) + @ApiModelProperty("主键") + private Long id; + + @ApiModelProperty("创建时间") + private LocalDateTime createOn; + + @ApiModelProperty("修改时间") + private LocalDateTime updateOn; + + @ApiModelProperty("irs那边的ID") + private Long irsId; + + @ApiModelProperty("生成的业务编号") + private String matterCode; + + @ApiModelProperty("业务名") + private String matterName; + + @ApiModelProperty("企业名") + private String orgName; + + @ApiModelProperty("企业钉code") + private String orgCode; + + @ApiModelProperty("区域名") + private String areaName; + + @ApiModelProperty("状态") + private String userState; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/service/IProjectCoreBizService.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/service/IProjectCoreBizService.java new file mode 100644 index 0000000..bffcdf0 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/service/IProjectCoreBizService.java @@ -0,0 +1,21 @@ +package com.ningdatech.pmapi.irs.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.gov.entity.BelongOrg; +import com.ningdatech.pmapi.irs.model.entity.ProjectCoreBiz; + +import java.util.Collection; +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author Zpf + * @since 2023-09-13 + */ +public interface IProjectCoreBizService extends IService { + + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/service/impl/ProjectCoreBizServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/service/impl/ProjectCoreBizServiceImpl.java new file mode 100644 index 0000000..7788785 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/service/impl/ProjectCoreBizServiceImpl.java @@ -0,0 +1,21 @@ +package com.ningdatech.pmapi.irs.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.pmapi.irs.mapper.ProjectCoreBizMapper; +import com.ningdatech.pmapi.irs.model.entity.ProjectCoreBiz; +import com.ningdatech.pmapi.irs.service.IProjectCoreBizService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author zpf + * @since 2023-09-13 + */ +@Service +public class ProjectCoreBizServiceImpl extends ServiceImpl + implements IProjectCoreBizService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingOrganization.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingOrganization.java index 1e268d4..3f58820 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingOrganization.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingOrganization.java @@ -55,4 +55,5 @@ public class DingOrganization implements Serializable { private String status; + private String unifiedSocialCreditCode; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/OrganizationTreeVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/OrganizationTreeVO.java index 39af940..b3457a0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/OrganizationTreeVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/OrganizationTreeVO.java @@ -36,6 +36,6 @@ public class OrganizationTreeVO { // @ApiModelProperty(value = "是否为叶子节点") // private Boolean isLeaf; // -// @ApiModelProperty(value = "联合唯一字段方便页面使用(name##organizationCode)") -// private String unionCode; + @ApiModelProperty(value = "社会同一信用代码") + private String unifiedSocialCreditCode;; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/ResOrganizationListVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/ResOrganizationListVO.java index 89007ef..1ae838e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/ResOrganizationListVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/ResOrganizationListVO.java @@ -35,4 +35,6 @@ public class ResOrganizationListVO { @ApiModelProperty("是否为上级条线主管单位") private Boolean isSuperiorLineCompetentUnit; + @ApiModelProperty("社会统一信用代码") + private String unifiedSocialCreditCode; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/contants/ProjectCodeContant.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/contants/ProjectCodeContant.java index c1b870e..098f8ba 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/contants/ProjectCodeContant.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/contants/ProjectCodeContant.java @@ -13,4 +13,5 @@ public interface ProjectCodeContant { String PROJECT_TYPE_PREFIX = "0"; String SHUZI_5 = "%05d"; + String SHUZI_4 = "%04d"; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCoreBizTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCoreBizTask.java new file mode 100644 index 0000000..556024d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/SynProjectCoreBizTask.java @@ -0,0 +1,144 @@ +package com.ningdatech.pmapi.scheduler.task; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.StopWatch; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.ningdatech.basic.model.GenericResult; +import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.ding.constants.DingOrganizationContant; +import com.ningdatech.pmapi.irs.manage.ProjectIrsManage; +import com.ningdatech.pmapi.irs.model.entity.ProjectCoreBiz; +import com.ningdatech.pmapi.irs.service.IProjectCoreBizService; +import com.ningdatech.pmapi.organization.model.entity.DingOrganization; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.ningdatech.pmapi.projectdeclared.contants.ProjectCodeContant; +import com.ningdatech.zwdd.client.ZwddClient; +import com.ningdatech.zwdd.model.dto.DingOrgInfoDTO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +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.time.LocalDateTime; +import java.util.List; +import java.util.Objects; + +/** + * @author ZPF + * @since 2023/09/13 18:16 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class SynProjectCoreBizTask { + + @Value("${hostname}") + public String HOST; + + @Value("${spring.profiles.active}") + public String active; + + @Autowired + private IProjectCoreBizService projectCoreBizService; + + @Autowired + private IDingOrganizationService organizationService; + + @Autowired + private ZwddClient zwddClient; + + @Autowired + private ProjectIrsManage projectIrsManage; + + /** + * 前置机每天晚上10点自动清空,第二天早上6点获取数据 + * 定时同步前置机数据 每天1点开始执行一次 + * + */ + @Scheduled(cron = "0 0 2 * * ?") + public void doTask() throws UnknownHostException { + if (!HOST.equals(InetAddress.getLocalHost().getHostName())) { + log.info("定时器没开启或者host不对! {}:{}", + HOST,InetAddress.getLocalHost().getHostName()); + return; + } + + log.info("同步项目核心业务开始====="); + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + + List orgs = organizationService.list(Wrappers.lambdaQuery(DingOrganization.class) + .in(DingOrganization::getTypeCode, Lists.newArrayList(DingOrganizationContant.UNIT_TYPE + , DingOrganizationContant.GOV_TEMPORARY))); + + log.info("总共需要同步 orgs size :{}",orgs.size()); + + for(DingOrganization organization : orgs){ + GenericResult dingResult = zwddClient.getOrganizationByCode(organization.getOrganizationCode()); + if(dingResult.isSuccess()){ + DingOrgInfoDTO data = dingResult.getData(); + String unifiedSocialCreditCode = data.getUnifiedSocialCreditCode(); + if(StringUtils.isNotBlank(unifiedSocialCreditCode)){ + organization.setUnifiedSocialCreditCode(unifiedSocialCreditCode); + organizationService.updateById(organization); + } + + //去请求IRS接口 + JSONObject jsonObject = projectIrsManage.searchCoreBiz(null, organization.getOrganizationCode(), 1000, 1); + JSONArray jsonArray = jsonObject.getJSONArray(BizConst.RESPONSE_KEY_DATA); + if(CollUtil.isNotEmpty(jsonArray)){ + jsonArray.forEach(j -> { + JSONObject jsonData = JSON.parseObject(JSON.toJSONString(j)); + ProjectCoreBiz coreBiz = new ProjectCoreBiz(); + // + Long irsId = jsonData.getLong(BizConst.RESPONSE_KEY_ID); + String dingCode = jsonData.getString(BizConst.RESPONSE_KEY_DING_CODE); + String matterName = jsonData.getString(BizConst.RESPONSE_KEY_MATTER_NAME); + String orgName = jsonData.getString(BizConst.RESPONSE_KEY_ORG_NAME); + String userState = jsonData.getString(BizConst.RESPONSE_KEY_USER_STATE); + + ProjectCoreBiz old = projectCoreBizService.getOne(Wrappers.lambdaQuery(ProjectCoreBiz.class) + .eq(ProjectCoreBiz::getIrsId, irsId) + .last(BizConst.LIMIT_1)); + + if(Objects.nonNull(old)){ + coreBiz.setId(old.getId()); + }else{ + coreBiz.setCreateOn(LocalDateTime.now()); + } + coreBiz.setIrsId(irsId); + coreBiz.setMatterName(matterName); + coreBiz.setOrgCode(dingCode); + coreBiz.setOrgName(orgName); + coreBiz.setUserState(userState); + projectCoreBizService.saveOrUpdate(coreBiz); + coreBiz.setMatterCode(genirate(unifiedSocialCreditCode,coreBiz.getId())); + projectCoreBizService.updateById(coreBiz); + }); + } + } + } + stopWatch.stop(); + log.info("同步项目核心业务结束====={}s",stopWatch.getTotalTimeSeconds()); + } + + /** + * 生成 编号 + * @param unifiedSocialCreditCode + * @param id + * @return + */ + private String genirate(String unifiedSocialCreditCode, Long id) { + String formatId = String.format(ProjectCodeContant.SHUZI_4, id); + return unifiedSocialCreditCode + formatId; + } + +}