feat(制品库优化): 获取制品列表时若制品来源于流水线需展示相关信息

获取制品列表时若制品来源于流水线则设置制品的来源标签

Signed-off-by: OTTO <731554297@qq.com>
This commit is contained in:
OTTO 2025-02-10 15:53:19 +08:00
parent c271179b43
commit 1000c7fed5
5 changed files with 66 additions and 4 deletions

View File

@ -129,7 +129,7 @@ public class PmsProductLibraryComponent extends BaseEntity {
this.setIdentifier(composeIds[1]);
}
this.setAttributes(JSONObject.toJSONString(nexusAssetVo));
// this.setAttributes(JSONObject.toJSONString(nexusAssetVo));
}
public ComponentMavenInputVo toComponentMavenInputVo(PmsProductLibraryRepositories snapshotRepo) {

View File

@ -58,4 +58,7 @@ public class NexusResultDataVo {
*/
@ApiModelProperty(value = "默认文件夹")
private String defaultDir;
@ApiModelProperty(value = "制品来源标签")
private String fromTag;
}

View File

@ -107,4 +107,12 @@ public interface PmsProductLibraryComponentMapper {
* @return 制品
*/
PmsProductLibraryComponent selectPmsProductLibraryComponentByIdentifier(@Param("repoId") Long repoId, @Param("identifier") String identifier);
/**
* 通过assetId列表查询来自流水线的制品
*
* @param assetIdList assetId列表
* @return 来自流水线的制品
*/
List<PmsProductLibraryComponent> selectComponentListFromPipelineByAssetIdList(@Param("assetIdList") List<String> assetIdList);
}

View File

@ -1,5 +1,6 @@
package com.microservices.pms.productLibrary.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.constant.CacheConstants;
@ -28,6 +29,7 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -37,6 +39,8 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 制品库-制品Service业务层处理
@ -66,6 +70,8 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
private IPmsProductLibraryAsyncService pmsProductLibraryAsyncService;
@Autowired
private RedisService redisService;
@Autowired
private DefaultErrorAttributes errorAttributes;
/**
* 查询制品库-制品
@ -83,7 +89,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
*
* @param enterpriseIdentifier 组织标识
* @param componentSearchVo 制品库-制品
* @param isProduct 是否产品
* @param isProduct 是否产品
* @return 制品库-制品
*/
@Override
@ -93,12 +99,49 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
componentSearchVo.setRepositoryName(pmsProductLibraryRepositories.getNexusRepositoriesName());
NexusComponentSearchVo<ComponentSearchVo> nexusComponentSearchVo = NexusComponentSearchVo.toRead(componentSearchVo, nexusRequestHelper.getNexusTid());
return nexusRequestHelper.doRequestToJavaObjectList(
NexusComponentResultVo<List<NexusResultDataVo>> resultVo = nexusRequestHelper.doRequestToJavaObjectList(
NexusRequestUrl.DO_OPERATION(),
JSONObject.from(nexusComponentSearchVo),
NexusComponentResultVo.class,
NexusResultDataVo.class
);
if (resultVo.getResult() != null) {
List<NexusResultDataVo> dataList = resultVo.getResult().getData();
// 提取assetId列表从数据库中查询来源于流水线的制品
List<String> assetIdList = dataList.stream().map(NexusResultDataVo::getAssetId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (!assetIdList.isEmpty()) {
List<PmsProductLibraryComponent> pmsProductLibraryComponentList = pmsProductLibraryComponentMapper.selectComponentListFromPipelineByAssetIdList(assetIdList);
if (!pmsProductLibraryComponentList.isEmpty()) {
dataList.forEach(x -> {
if (x.getAssetId() != null) {
PmsProductLibraryComponent pipelineComponent =
pmsProductLibraryComponentList.stream().filter(component -> x.getAssetId().equals(component.getIdentifier())).findFirst().orElse(null);
if (pipelineComponent != null) {
String attributes = pipelineComponent.getAttributes();
if (JSON.isValid(attributes)) {
JSONObject attributesJson = JSONObject.parseObject(attributes);
String repository = attributesJson.getString("repository");
String repositoryDes = null;
if (StringUtils.isNotEmpty(repository)) {
repositoryDes = String.format("【%s】仓库的", repository);
}
String pipelineName = attributesJson.getString("pipelineName");
String pipelineNameDes = null;
if (StringUtils.isNotEmpty(pipelineName)) {
pipelineNameDes = String.format("【%s】", pipelineName);
}
String fromTag = String.format("由%s%s流水线生成", repositoryDes, pipelineNameDes);
x.setFromTag(fromTag);
}
}
}
});
}
}
}
return resultVo;
}
@Override
@ -533,7 +576,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
public Boolean insertPypiComponent(ComponentInputVo componentInputVo) {
PmsProductLibraryRepositories repo = pmsProductLibraryRepositoriesService.getPmsProductLibraryRepositories(
false,
componentInputVo.getEnterpriseIdentifier(),
componentInputVo.getEnterpriseIdentifier(),
componentInputVo.getRepoName(),
componentInputVo.getSnapshotName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getId());

View File

@ -142,6 +142,14 @@
where repo_id = #{repoId}
and identifier = #{identifier}
</select>
<select id="selectComponentListFromPipelineByAssetIdList" resultMap="PmsProductLibraryComponentResult">
<include refid="selectPmsProductLibraryComponentVo"/>
where identifier in
<foreach item="assetId" collection="assetIdList" open="(" separator="," close=")">
#{assetId}
</foreach>
and from_type='pipeline'
</select>
<insert id="insertPmsProductLibraryComponent" parameterType="PmsProductLibraryComponent" useGeneratedKeys="true"
keyProperty="id">