From 9c166726b6a6c14cd16489c0347cb6c9d04d68bc Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Thu, 13 Jul 2023 09:47:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=92=8C=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=20=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ningdatech/pmapi/irs/manage/AppIrsManage.java | 51 ++++++++++++++++++++++ .../irs/model/dto/PushProjectAppToIrsDTO.java | 4 ++ .../model/dto/ProjectApplicationDTO.java | 5 +++ .../model/entity/ProjectApplication.java | 2 + .../projectlib/model/vo/ProjectApplicationVO.java | 3 ++ 5 files changed, 65 insertions(+) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java index 0667095..e78f959 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/AppIrsManage.java @@ -2,7 +2,10 @@ package com.ningdatech.pmapi.irs.manage; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.basic.function.VUtils; +import com.ningdatech.pmapi.common.enumeration.CommonEnum; +import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; import com.ningdatech.pmapi.common.util.CryptUtils; import com.ningdatech.pmapi.common.util.RefreshKeyUtil; import com.ningdatech.pmapi.irs.model.dto.ApiApplyDTO; @@ -11,16 +14,22 @@ import com.ningdatech.pmapi.irs.model.dto.ApiSearchResult; import com.ningdatech.pmapi.irs.model.dto.PushProjectAppToIrsDTO; import com.ningdatech.pmapi.irs.model.res.ApiResponse; import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectApplication; +import com.ningdatech.pmapi.projectlib.service.IProjectApplicationService; import com.ningdatech.pmapi.projectlib.service.IProjectService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.security.NoSuchAlgorithmException; +import java.time.LocalDateTime; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * @Classname AppIrsManage @@ -35,6 +44,10 @@ public class AppIrsManage { private final IProjectService projectService; + private final IProjectApplicationService applicationService; + + private final StateMachineUtils stateMachineUtils; + @Value("${irs.push-app.appKey}") private String pushAppKey; @@ -61,7 +74,11 @@ public class AppIrsManage { */ public Boolean pushProjectApp(PushProjectAppToIrsDTO dto) throws NoSuchAlgorithmException { String appCode = dto.getAppCode(); + Long appId = dto.getAppId(); String projectCode = dto.getProjectCode(); + ProjectApplication app = applicationService.getById(appId); + VUtils.isTrue(Objects.isNull(app)).throwMessage("应用不存在!"); + VUtils.isTrue(CommonEnum.NO.getCode().equals(app.getIsFirst())).throwMessage("应用不是初次新建!"); Project project = projectService.getProjectByCode(projectCode); VUtils.isTrue(Objects.isNull(project)).throwMessage("项目不存在!"); @@ -90,6 +107,40 @@ public class AppIrsManage { ApiResponse body = forEntity.getBody(); + if(Objects.isNull(body)){ + return Boolean.FALSE; + } + + if(Objects.nonNull(body.getSuccess()) + && body.getSuccess()){ + //保存关系 + app.setAppCode(appCode); + if(applicationService.updateById(app)){ + /** + * 判断下 如果成功的话 那么判断下 这个项目的初次创建的app 是否都已经被注册 + * 如果都已经注册 要调用状态机 进入下一个状态 + */ + List apps = applicationService.list(Wrappers.lambdaQuery(ProjectApplication.class) + .eq(ProjectApplication::getProjectId, project.getId())); + //筛选出 初次新建的app 但是没有appCode的 + apps = apps.stream().filter(a -> { + if(CommonEnum.YES.getCode().equals(a.getIsFirst()) && + StringUtils.isBlank(app.getAppCode())){ + return Boolean.TRUE; + } + return Boolean.FALSE; + }) + .collect(Collectors.toList()); + + //如果筛选出来的 为空的话 就调用状态机 + if(CollUtil.isEmpty(apps)){ + stateMachineUtils.pass(project); + project.setUpdateOn(LocalDateTime.now()); + projectService.updateById(project); + } + } + } + return body.getSuccess(); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/PushProjectAppToIrsDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/PushProjectAppToIrsDTO.java index ecfed09..c6a0a12 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/PushProjectAppToIrsDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/model/dto/PushProjectAppToIrsDTO.java @@ -20,6 +20,10 @@ import javax.validation.constraints.NotBlank; @NoArgsConstructor public class PushProjectAppToIrsDTO { + @ApiModelProperty("我们系统的appId") + @NotBlank(message = "appId 不能为空") + private Long appId; + @ApiModelProperty("app code") @NotBlank(message = "appCode 不能为空") private String appCode; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ProjectApplicationDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ProjectApplicationDTO.java index 23fa04f..0589cc6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ProjectApplicationDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ProjectApplicationDTO.java @@ -162,4 +162,9 @@ public class ProjectApplicationDTO implements Serializable { @ApiModelProperty("申报单位编码") private String buildOrgCode; + @ApiModelProperty("项目编码") + private String projectCode; + + @ApiModelProperty("应用编码") + private String appCode; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java index cb476e9..0c46a0f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java @@ -179,4 +179,6 @@ public class ProjectApplication implements Serializable { private Long updateBy; + @ApiModelProperty("项目编码") + private String projectCode; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java index c26a88b..2e23bb9 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java @@ -171,6 +171,9 @@ public class ProjectApplicationVO implements Serializable { @ApiModelProperty("申报单位编码") private String buildOrgCode; + @ApiModelProperty("项目编码") + private String projectCode; + private Long createBy; private Long updateBy;