From de31f1c563e753d610564992a67ded7ecb2605d3 Mon Sep 17 00:00:00 2001 From: OTTO <731554297@qq.com> Date: Mon, 8 Jul 2024 16:53:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=88=B6=E5=93=81=E5=BA=93=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91):=20=E5=88=B6=E5=93=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8F=8A=E5=88=B6=E5=93=81=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91=EF=BC=88?= =?UTF-8?q?=E5=9F=BA=E4=BA=8ENexus=E6=8E=A5=E5=8F=A3/service/extdirect?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=94=B9=E9=80=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 删除制品接口开发和删除制品文件接口开发: - 调用Nexus删除对应的制品或制品文件 - 获取Nexus删除接口返回的制品文件路径列表 - 根据制品文件路径遍历数据库中是否有对应的制品文件记录 - 若存在记录则删除数据库中的记录 --- .../PmsProductLibraryComponentController.java | 27 +++++++++ .../domain/vo/NexusComponentSearchVo.java | 28 +++++++++ .../IPmsProductLibraryComponentService.java | 14 +++++ ...PmsProductLibraryComponentServiceImpl.java | 60 +++++++++++++++++++ 4 files changed, 129 insertions(+) diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/controller/PmsProductLibraryComponentController.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/controller/PmsProductLibraryComponentController.java index e8304443a..e43c5897c 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/controller/PmsProductLibraryComponentController.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/controller/PmsProductLibraryComponentController.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.List; /** * 制品库-制品Controller @@ -106,6 +107,32 @@ public class PmsProductLibraryComponentController extends BaseController { return success(result); } + /** + * 删除制品文件 + */ + @DeleteMapping("/{repoName}/deleteAsset/{assetId}") + @ApiOperation(value = "删除制品文件") + public AjaxResult deleteAsset(@PathVariable String enterpriseIdentifier, + @PathVariable("repoName") String repoName, + @PathVariable("assetId") String assetId) { + NexusComponentResultVo> result = + pmsProductLibraryComponentService.deleteAssetByAssetId(enterpriseIdentifier, repoName, assetId); + return success(result); + } + + /** + * 删除制品 + */ + @DeleteMapping("/{repoName}/deleteComponent/{componentId}") + @ApiOperation(value = "删除制品") + public AjaxResult deleteComponent(@PathVariable String enterpriseIdentifier, + @PathVariable("repoName") String repoName, + @PathVariable("componentId") String componentId) { + NexusComponentResultVo> result = + pmsProductLibraryComponentService.deleteComponentByComponentId(enterpriseIdentifier, repoName, componentId); + return success(result); + } + /** * 上传制品-maven制品 diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/domain/vo/NexusComponentSearchVo.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/domain/vo/NexusComponentSearchVo.java index 6a0b2bff2..938ad4efc 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/domain/vo/NexusComponentSearchVo.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/domain/vo/NexusComponentSearchVo.java @@ -120,4 +120,32 @@ public class NexusComponentSearchVo { target.setData(data); return target; } + + public static NexusComponentSearchVo toDeleteAsset(String nexusRepoName, String assetId, Long tid) { + NexusComponentSearchVo target = new NexusComponentSearchVo<>(); + target.setAction("coreui_Component"); + target.setMethod("deleteAsset"); + target.setType("rpc"); + target.setTid(tid); + List data = new ArrayList<>(); + data.add(assetId); + data.add(nexusRepoName); + target.setData(data); + return target; + } + + public static NexusComponentSearchVo toDeleteComponent(String nexusRepoName, String componentId, Long tid) { + NexusComponentSearchVo target = new NexusComponentSearchVo<>(); + target.setAction("coreui_Component"); + target.setMethod("deleteComponent"); + target.setType("rpc"); + target.setTid(tid); + List data = new ArrayList<>(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", componentId); + jsonObject.put("repositoryName", nexusRepoName); + data.add(jsonObject.toJSONString()); + target.setData(data); + return target; + } } diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/IPmsProductLibraryComponentService.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/IPmsProductLibraryComponentService.java index 3fc618c7d..22cf7aed3 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/IPmsProductLibraryComponentService.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/IPmsProductLibraryComponentService.java @@ -3,6 +3,8 @@ package com.microservices.pms.productLibrary.service; import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent; import com.microservices.pms.productLibrary.domain.vo.*; +import java.util.List; + /** * 制品库-制品Service接口 * @@ -111,4 +113,16 @@ public interface IPmsProductLibraryComponentService { NexusComponentResultVo getCanDeleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId); NexusComponentResultVo getCanDeleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId); + + /** + * 删除制品 + * + * @param enterpriseIdentifier 企业标识 + * @param repoName 制品库名称 + * @param assetId 制品文件 + * @return 删除文件列表 + */ + NexusComponentResultVo> deleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId); + + NexusComponentResultVo> deleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId); } diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryComponentServiceImpl.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryComponentServiceImpl.java index d25a36f9b..7a7c6a9dc 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryComponentServiceImpl.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryComponentServiceImpl.java @@ -209,6 +209,66 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary ); } + @Override + public NexusComponentResultVo> deleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId) { + PmsProductLibraryRepositories pmsProductLibraryRepositories = + pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, repoName); + NexusComponentSearchVo nexusComponentSearchVo = + NexusComponentSearchVo.toDeleteAsset(pmsProductLibraryRepositories.getNexusRepositoriesName(), assetId, nexusRequestHelper.getNexusTid()); + NexusComponentResultVo> assetResultDataVo = + nexusRequestHelper.doRequestToJavaObjectList( + NexusRequestUrl.DO_OPERATION(), + JSONObject.from(nexusComponentSearchVo), + NexusComponentResultVo.class, + String.class + ); + deleteDatabaseAsset(pmsProductLibraryRepositories, assetResultDataVo); + return assetResultDataVo; + } + + @Override + public NexusComponentResultVo> deleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId) { + PmsProductLibraryRepositories pmsProductLibraryRepositories = + pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, repoName); + NexusComponentSearchVo nexusComponentSearchVo = + NexusComponentSearchVo.toDeleteComponent(pmsProductLibraryRepositories.getNexusRepositoriesName(), componentId, nexusRequestHelper.getNexusTid()); + NexusComponentResultVo> assetResultDataVo = + nexusRequestHelper.doRequestToJavaObjectList( + NexusRequestUrl.DO_OPERATION(), + JSONObject.from(nexusComponentSearchVo), + NexusComponentResultVo.class, + String.class + ); + deleteDatabaseAsset(pmsProductLibraryRepositories, assetResultDataVo); + return assetResultDataVo; + } + + private void deleteDatabaseAsset(PmsProductLibraryRepositories pmsProductLibraryRepositories, NexusComponentResultVo> assetResultDataVo) { + // 当制品库格式为RAW或者Maven时,需检查数据库中是否存在记录,存在记录则需要进行删除 + if (ProductLibraryRepositoriesFormatEnum.isNexusRaw(pmsProductLibraryRepositories.getFormat()) + || ProductLibraryRepositoriesFormatEnum.MAVEN.getKey().equals(pmsProductLibraryRepositories.getFormat())) { + + if (assetResultDataVo != null && assetResultDataVo.getResult() != null) { + NexusComponentResultStateVo> nexusComponentResultStateVo = assetResultDataVo.getResult(); + if (nexusComponentResultStateVo.getSuccess()) { + List deletePathList = nexusComponentResultStateVo.getData(); + for (String deletePath : deletePathList) { + // 检查数据库中是否已存在该制品文件记录 + PmsProductLibraryComponent pmsProductLibraryComponent = + pmsProductLibraryComponentMapper.selectPmsProductLibraryComponentByPath( + deletePath, + pmsProductLibraryRepositories.getName(), + pmsProductLibraryRepositories.getPmsEnterpriseId() + ); + if (pmsProductLibraryComponent != null) { + pmsProductLibraryComponentMapper.deletePmsProductLibraryComponentById(pmsProductLibraryComponent.getId()); + } + } + } + } + } + } + /** * 新增制品库-制品 *