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