forked from Gitlink/microservices
Merge pull request '产品库应当区分文档与制品' (#810) from otto/microservices:product_refact into product_refact
This commit is contained in:
commit
f484b14bcd
|
|
@ -202,7 +202,7 @@ public class CacheConstants {
|
|||
/**
|
||||
* Gitlink组织开通企业是否完成 Key前缀
|
||||
*/
|
||||
public final static String GITLINK_ORG_ID_OPEN_ENTERPRISE_KEY = "gitlink_org_id_open_enterprise_key:";
|
||||
private final static String GITLINK_ORG_ID_OPEN_ENTERPRISE_KEY = "gitlink_org_id_open_enterprise_key:";
|
||||
|
||||
public static String getGitlinkOrgIdOpenEnterpriseKey(Long gitlinkOrgId) {
|
||||
return GITLINK_ORG_ID_OPEN_ENTERPRISE_KEY + gitlinkOrgId;
|
||||
|
|
@ -211,11 +211,11 @@ public class CacheConstants {
|
|||
/**
|
||||
* 专区项目Gitlink信息 Key前缀
|
||||
*/
|
||||
public final static String ZONE_PROJECT_GITLINK_INFO = "zone_project_gitlink_info:";
|
||||
private final static String ZONE_PROJECT_GITLINK_INFO = "zone_project_gitlink_info:";
|
||||
/**
|
||||
* 专区下项目分数排序 Key前缀
|
||||
*/
|
||||
public final static String ZONE_PROJECT_SORT_BY_SCORE = "zone_project_sort_by_score:";
|
||||
private final static String ZONE_PROJECT_SORT_BY_SCORE = "zone_project_sort_by_score:";
|
||||
|
||||
public static String getZoneProjectGitlinkInfo(Long gitlinkProjectId) {
|
||||
return ZONE_PROJECT_GITLINK_INFO + gitlinkProjectId;
|
||||
|
|
@ -228,4 +228,13 @@ public class CacheConstants {
|
|||
public static String getAllZoneProjectSortByScore(Long zoneId) {
|
||||
return ZONE_PROJECT_SORT_BY_SCORE + "*:" + zoneId + ":*";
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件打包是否完成(0:代表未完成;1:代表已完成;-1:代表打包失败,需要重新打包)
|
||||
*/
|
||||
private final static String PACKAGE_FILE_IS_FINISH = "packageFileIsFinish:";
|
||||
|
||||
public static String getPackageFileIsFinish(String fileIdentifier) {
|
||||
return PACKAGE_FILE_IS_FINISH + fileIdentifier;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ public class ServletUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 内容编码(排除斜杠)
|
||||
* 内容编码(排除斜杠并且不重复编码)
|
||||
*
|
||||
* @param str 内容
|
||||
* @return 编码后的内容
|
||||
|
|
@ -240,6 +240,26 @@ public class ServletUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容编码(排除斜杠并且支持重复编码)
|
||||
*
|
||||
* @param str 内容
|
||||
* @return 编码后的内容
|
||||
*/
|
||||
public static String urlEncodeExcludeSlashesApplyDuplicate(String str) {
|
||||
try {
|
||||
StringBuilder stringBuffer = new StringBuilder();
|
||||
String[] strings = str.split("/");
|
||||
for (String string : strings) {
|
||||
string = URLEncoder.encode(string, Constants.UTF8);
|
||||
stringBuffer.append("/").append(string);
|
||||
}
|
||||
return stringBuffer.toString().replaceAll("\\+", "%20");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否经过URLEncode
|
||||
* 1. 使用URLDecoder.decode对字符串进行解码。
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.microservices.file.service.impl;
|
||||
|
||||
import com.microservices.common.core.constant.CacheConstants;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
import com.microservices.common.core.utils.ServletUtils;
|
||||
import com.microservices.common.core.utils.html.EscapeUtil;
|
||||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.file.service.ISysFileInfoAsyncService;
|
||||
import com.microservices.file.service.ISysFileInfoService;
|
||||
import com.microservices.file.utils.CustomExecutorFactory;
|
||||
|
|
@ -41,6 +43,8 @@ public class SysFileInfoAsyncServiceImpl implements ISysFileInfoAsyncService {
|
|||
*/
|
||||
@Value("${file.path}")
|
||||
private String localFilePath;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public void asyncPackagedFile(String fileIdentifier, HashMap<String, String> packagedStructure, String zipFileName, String type, String hierarchy) {
|
||||
|
|
@ -70,6 +74,7 @@ public class SysFileInfoAsyncServiceImpl implements ISysFileInfoAsyncService {
|
|||
String filePath = localFilePath + fileInfo.getFilePath();
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
redisService.setCacheObject(CacheConstants.getPackageFileIsFinish(fileIdentifier), -1);
|
||||
throw new IOException("该文件不存在");
|
||||
}
|
||||
// 拷贝文件到打包目录
|
||||
|
|
@ -82,6 +87,7 @@ public class SysFileInfoAsyncServiceImpl implements ISysFileInfoAsyncService {
|
|||
org.apache.commons.io.FileUtils.copyURLToFile(new URL(fileSource), packagedFilePath.toFile());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
redisService.setCacheObject(CacheConstants.getPackageFileIsFinish(fileIdentifier), -1);
|
||||
logger.error("打包文件时出现异常,需压缩文件处理失败:{}", e.getMessage());
|
||||
throw new ServiceException("打包文件时出现异常,需压缩文件处理失败!");
|
||||
}
|
||||
|
|
@ -91,7 +97,8 @@ public class SysFileInfoAsyncServiceImpl implements ISysFileInfoAsyncService {
|
|||
ZipUtils.toZip(tempPackagedPath.toString(), Files.newOutputStream(zipFilePath), true);
|
||||
File zipFile = zipFilePath.toFile();
|
||||
if (!zipFile.exists()) {
|
||||
throw new ServiceException("打包文件时出现异常:文件压缩失败");
|
||||
redisService.setCacheObject(CacheConstants.getPackageFileIsFinish(fileIdentifier), -1);
|
||||
throw new ServiceException("打包文件时出现异常:压缩文件不存在");
|
||||
}
|
||||
String filePath = EscapeUtil.removeExtraSlashOfUrl("/" + type + "/" + hierarchy + "/" + datePath + "/" + fullZipFileName);
|
||||
SysFileInfo sysFileInfo = new SysFileInfo(fileIdentifier, zipFile, filePath);
|
||||
|
|
@ -101,9 +108,11 @@ public class SysFileInfoAsyncServiceImpl implements ISysFileInfoAsyncService {
|
|||
org.apache.commons.io.FileUtils.deleteDirectory(tempPackagedPath.toFile());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
redisService.setCacheObject(CacheConstants.getPackageFileIsFinish(fileIdentifier), -1);
|
||||
logger.error("打包文件时出现异常:{}", e.getMessage());
|
||||
throw new ServiceException("打包文件时出现异常!");
|
||||
}
|
||||
redisService.setCacheObject(CacheConstants.getPackageFileIsFinish(fileIdentifier), 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package com.microservices.file.service.impl;
|
|||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.j256.simplemagic.ContentInfo;
|
||||
import com.j256.simplemagic.ContentInfoUtil;
|
||||
import com.microservices.common.core.constant.CacheConstants;
|
||||
import com.microservices.common.core.constant.Constants;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
|
|
@ -14,6 +15,7 @@ import com.microservices.common.core.utils.html.EscapeUtil;
|
|||
import com.microservices.common.core.utils.uuid.IdUtils;
|
||||
import com.microservices.common.httpClient.domain.GitLinkRequestUrl;
|
||||
import com.microservices.common.httpClient.util.GitLinkRequestHelper;
|
||||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.file.mapper.SysFileInfoMapper;
|
||||
import com.microservices.file.service.ISysFileInfoAsyncService;
|
||||
|
|
@ -84,6 +86,8 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
*/
|
||||
@Value("${file.domain}")
|
||||
public String domain;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public SysFileInfo selectSysFileInfoByFileObjectName(String fileObjectName) {
|
||||
|
|
@ -492,6 +496,7 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
@Override
|
||||
public String packagedFile(HashMap<String, String> packagedStructure, String zipFileName, String type, String hierarchy) {
|
||||
String fileIdentifier = genFileIdentifier();
|
||||
redisService.setCacheObject(CacheConstants.getPackageFileIsFinish(fileIdentifier), 0);
|
||||
fileInfoAsyncService.asyncPackagedFile(fileIdentifier, packagedStructure, zipFileName, type, hierarchy);
|
||||
return fileIdentifier;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
package com.microservices.pms.enums;
|
||||
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.core.utils.html.EscapeUtil;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author OTTO
|
||||
*/
|
||||
@Getter
|
||||
@ApiModel("产品库制品路径前缀")
|
||||
public enum ProductLibraryComponentPathEnum {
|
||||
SOFTWARE("Software", "软件包"),
|
||||
DOC("Document", "文档");
|
||||
|
||||
private final String key;
|
||||
private final String name;
|
||||
|
||||
ProductLibraryComponentPathEnum(String key, String name) {
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public static ProductLibraryComponentPathEnum getByKey(String key) {
|
||||
for (ProductLibraryComponentPathEnum typeEnum : ProductLibraryComponentPathEnum.values()) {
|
||||
if (typeEnum.key.equals(key)) {
|
||||
return typeEnum;
|
||||
}
|
||||
}
|
||||
throw new ServiceException("该产品库制品路径前缀不存在(产品库制品路径前缀[%s])", key);
|
||||
}
|
||||
|
||||
public static String getSoftwareFixedPath(String directory) {
|
||||
return EscapeUtil.removeExtraSlashOfUrl(SOFTWARE.key + "/" + directory);
|
||||
}
|
||||
|
||||
public static String getDocFixedPath(String directory) {
|
||||
return EscapeUtil.removeExtraSlashOfUrl(DOC.key + "/" + directory);
|
||||
}
|
||||
|
||||
public static String getChineseFixedPath(String path) {
|
||||
if (path.startsWith(SOFTWARE.key)) {
|
||||
return path.replaceFirst(SOFTWARE.key, SOFTWARE.name);
|
||||
}
|
||||
if (path.startsWith(DOC.key)) {
|
||||
return path.replaceFirst(DOC.key, DOC.name);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static boolean pathIsNeedPackaged(String node, String path) {
|
||||
if (StringUtils.isNotEmpty(node)) {
|
||||
if (node.equals(SOFTWARE.key)) {
|
||||
return path.startsWith(SOFTWARE.key);
|
||||
}
|
||||
if (node.equals(DOC.key)) {
|
||||
return path.startsWith(DOC.key);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.microservices.pms.enums;
|
||||
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author OTTO
|
||||
*/
|
||||
@Getter
|
||||
@ApiModel("来源类型")
|
||||
public enum ProductLibraryRepoFromTypeEnum {
|
||||
COMMON("common", "普通类型"),
|
||||
PIPELINE("pipeline", "流水线类型"),
|
||||
DOC("doc", "文档类型");
|
||||
|
||||
private final String key;
|
||||
private final String name;
|
||||
|
||||
ProductLibraryRepoFromTypeEnum(String key, String name) {
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public static ProductLibraryRepoFromTypeEnum getByKey(String key) {
|
||||
for (ProductLibraryRepoFromTypeEnum typeEnum : ProductLibraryRepoFromTypeEnum.values()) {
|
||||
if (typeEnum.key.equals(key)) {
|
||||
return typeEnum;
|
||||
}
|
||||
}
|
||||
throw new ServiceException("该来源类型不存在(来源类型[%s])", key);
|
||||
}
|
||||
}
|
||||
|
|
@ -113,22 +113,6 @@ public class PmsProductLibraryController extends BaseController {
|
|||
return toAjax(pmsProductLibraryService.deletePmsProductLibraryByName(enterpriseIdentifier, name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传产品库制品
|
||||
*/
|
||||
// @RequiresPermissions("pms:pmsProductLibraryComponent:add")
|
||||
@Log(title = "产品库制品", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/{name}")
|
||||
@ApiOperation(value = "上传知识库文档")
|
||||
public AjaxResult uploadProductAsset(@PathVariable String enterpriseIdentifier,
|
||||
@ApiParam(value = "产品库标识", required = true) @PathVariable String name,
|
||||
@Valid @RequestBody ProductComponentInputVo productComponentInputVo) {
|
||||
productComponentInputVo.setProductRepoName(name);
|
||||
productComponentInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
|
||||
return toAjax(pmsProductLibraryService.uploadProductAsset(productComponentInputVo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品库查询制品列表
|
||||
*/
|
||||
|
|
@ -317,6 +301,21 @@ public class PmsProductLibraryController extends BaseController {
|
|||
return toAjax(pmsProductLibraryService.addDockerComponentToProductRepo(dockerComponentAddToProductRepoVo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传产品库制品
|
||||
*/
|
||||
// @RequiresPermissions("pms:pmsProductLibraryComponent:add")
|
||||
@Log(title = "产品库制品", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/{name}")
|
||||
@ApiOperation(value = "上传知识库文档")
|
||||
public AjaxResult uploadProductAsset(@PathVariable String enterpriseIdentifier,
|
||||
@ApiParam(value = "产品库标识", required = true) @PathVariable String name,
|
||||
@Valid @RequestBody ProductDocComponentInputVo productDocComponentInputVo) {
|
||||
productDocComponentInputVo.setProductRepoName(name);
|
||||
productDocComponentInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
|
||||
return toAjax(pmsProductLibraryService.uploadProductAsset(productDocComponentInputVo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品库打包
|
||||
*/
|
||||
|
|
@ -325,8 +324,9 @@ public class PmsProductLibraryController extends BaseController {
|
|||
@PostMapping("/packaged/{productRepoName}")
|
||||
@ApiOperation(value = "产品库打包")
|
||||
public AjaxResult packagedProduct(@PathVariable String enterpriseIdentifier,
|
||||
@ApiParam(value = "产品库标识", required = true) @PathVariable String productRepoName) {
|
||||
return toAjax(pmsProductLibraryService.packagedProduct(enterpriseIdentifier, productRepoName));
|
||||
@ApiParam(value = "产品库标识", required = true) @PathVariable String productRepoName,
|
||||
@ApiParam(value = "打包节点(Software:打包软件包;Document:打包文档;不传或传其他值:打包所有)") @RequestParam String node) {
|
||||
return toAjax(pmsProductLibraryService.packagedProduct(enterpriseIdentifier, productRepoName, node));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -337,6 +337,6 @@ public class PmsProductLibraryController extends BaseController {
|
|||
@ApiOperation(value = "获取产品库打包下载地址")
|
||||
public GenericsAjaxResult<ProductPackagedResultVo> getPackagedProduct(@PathVariable String enterpriseIdentifier,
|
||||
@ApiParam(value = "产品库标识", required = true) @PathVariable String productRepoName) {
|
||||
return genericsSuccess(pmsProductLibraryService.getPackagedProduct(enterpriseIdentifier, productRepoName));
|
||||
return pmsProductLibraryService.getPackagedProduct(enterpriseIdentifier, productRepoName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,12 +119,8 @@ public class PmsProductLibraryComponent extends BaseEntity {
|
|||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private String reservedField2;
|
||||
|
||||
/**
|
||||
* 预留字段3
|
||||
*/
|
||||
@ApiModelProperty(value = "预留字段3")
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private String reservedField3;
|
||||
@ApiModelProperty(value = "来源类型")
|
||||
private String fromType;
|
||||
|
||||
public void setNexusMavenAssetVo(NexusAssetVo nexusAssetVo) {
|
||||
String composeId = Base64.base64ToDecoderString(nexusAssetVo.getId());
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ public class ComponentRawInputVo {
|
|||
@ApiModelProperty(value = "目录:上传文件的目录(例如/path/to/files/)")
|
||||
@NotNull(message = "目录不能为空")
|
||||
private String directory;
|
||||
@NotNull(message = "来源类型")
|
||||
private String fromType = "common";
|
||||
|
||||
public String getNexusRepoName() {
|
||||
if (ProductLibraryRepositoriesFormatEnum.isProduct(format)) {
|
||||
|
|
@ -87,6 +89,7 @@ public class ComponentRawInputVo {
|
|||
}
|
||||
}
|
||||
pmsProductLibraryComponent.setPmsEnterpriseIdentifier(enterpriseIdentifier);
|
||||
pmsProductLibraryComponent.setFromType(fromType);
|
||||
return pmsProductLibraryComponent;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,4 +67,7 @@ public class PmsProductLibraryComponentDataVo extends BaseEntityVo {
|
|||
*/
|
||||
@ApiModelProperty(value = "制品下载地址")
|
||||
private String downloadUrl;
|
||||
|
||||
@ApiModelProperty(value = "来源类型")
|
||||
private String fromType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.microservices.pms.productLibrary.domain.vo;
|
||||
|
||||
import com.microservices.common.core.utils.bean.BeanUtils;
|
||||
import com.microservices.pms.enums.ProductLibraryRepoFromTypeEnum;
|
||||
import com.microservices.pms.productLibrary.domain.ProductLibraryRepositoriesFormatEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
|
@ -19,8 +20,8 @@ import java.util.List;
|
|||
* @date 2024-07-04
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("产品制品输入对象")
|
||||
public class ProductComponentInputVo {
|
||||
@ApiModel("文档制品输入对象")
|
||||
public class ProductDocComponentInputVo {
|
||||
@ApiModelProperty(value = "产品库标识", hidden = true)
|
||||
private String productRepoName;
|
||||
@ApiModelProperty(value = "组织标识", hidden = true)
|
||||
|
|
@ -43,6 +44,7 @@ public class ProductComponentInputVo {
|
|||
BeanUtils.copyProperties(this, target);
|
||||
target.setRepoName(productRepoName);
|
||||
target.setAssetList(assetList);
|
||||
target.setFromType(ProductLibraryRepoFromTypeEnum.DOC.getKey());
|
||||
return target;
|
||||
}
|
||||
|
||||
|
|
@ -139,4 +139,11 @@ public interface PmsProductLibraryRepositoriesMapper {
|
|||
* @return 制品库
|
||||
*/
|
||||
PmsProductLibraryRepositories selectPmsProductLibraryRepositoriesByAlias(@Param("alias") String alias, @Param("pmsEnterpriseIdentifier") String pmsEnterpriseIdentifier);
|
||||
|
||||
/**
|
||||
* 设置产品库打包文件标识为空
|
||||
*
|
||||
* @param id 产品库id
|
||||
*/
|
||||
void setProductLibraryPackagedFileIdentifierNull(Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public interface IPmsProductLibraryAsyncService {
|
|||
* 打包产品库
|
||||
*
|
||||
* @param productRepo 产品库
|
||||
* @param node
|
||||
*/
|
||||
void packagedProduct(PmsProductLibraryRepositories productRepo);
|
||||
void packagedProduct(PmsProductLibraryRepositories productRepo, String node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.microservices.pms.productLibrary.service;
|
||||
|
||||
import com.microservices.common.core.web.domain.GenericsAjaxResult;
|
||||
import com.microservices.common.core.web.page.GenericsTableDataInfo;
|
||||
import com.microservices.pms.productLibrary.domain.PmsProductLibraryRepositories;
|
||||
import com.microservices.pms.productLibrary.domain.vo.*;
|
||||
|
|
@ -78,7 +79,7 @@ public interface IPmsProductLibraryService {
|
|||
|
||||
boolean addDockerComponentToProductRepo(DockerComponentAddToProductRepoVo dockerComponentAddToProductRepoVo);
|
||||
|
||||
boolean packagedProduct(String enterpriseIdentifier, String productRepoName);
|
||||
boolean packagedProduct(String enterpriseIdentifier, String productRepoName, String node);
|
||||
|
||||
int updatePmsProductLibrary(PmsProductLibraryRepositories pmsProductLibraryRepositories);
|
||||
|
||||
|
|
@ -89,15 +90,15 @@ public interface IPmsProductLibraryService {
|
|||
* @param productRepoName 产品库名称
|
||||
* @return 产品库打包对象
|
||||
*/
|
||||
ProductPackagedResultVo getPackagedProduct(String enterpriseIdentifier, String productRepoName);
|
||||
GenericsAjaxResult<ProductPackagedResultVo> getPackagedProduct(String enterpriseIdentifier, String productRepoName);
|
||||
|
||||
/**
|
||||
* 上传产品库制品
|
||||
*
|
||||
* @param productComponentInputVo 产品库制品输入对象
|
||||
* @param productDocComponentInputVo 产品库制品输入对象
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean uploadProductAsset(ProductComponentInputVo productComponentInputVo);
|
||||
Boolean uploadProductAsset(ProductDocComponentInputVo productDocComponentInputVo);
|
||||
|
||||
GenericsTableDataInfo<DocResultVo> selectDocList(DocSearchVo docSearchVo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.microservices.common.core.utils.DateUtils;
|
|||
import com.microservices.common.core.utils.ServletUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.core.utils.html.EscapeUtil;
|
||||
import com.microservices.pms.enums.ProductLibraryComponentPathEnum;
|
||||
import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent;
|
||||
import com.microservices.pms.productLibrary.domain.PmsProductLibraryRepositories;
|
||||
import com.microservices.pms.productLibrary.domain.ProductLibraryRepositoriesFormatEnum;
|
||||
|
|
@ -200,7 +201,7 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn
|
|||
}
|
||||
|
||||
@Override
|
||||
public void packagedProduct(PmsProductLibraryRepositories productRepo) {
|
||||
public void packagedProduct(PmsProductLibraryRepositories productRepo, String node) {
|
||||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
pmsProductLibraryRepositoriesService.lockRepository(productRepo.getPmsEnterpriseIdentifier(), productRepo.getId());
|
||||
try {
|
||||
|
|
@ -208,11 +209,13 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn
|
|||
pmsProductLibraryComponentService.selectPmsProductLibraryComponentListByDatabase(productRepo.getId());
|
||||
HashMap<String, String> packagedStructure = new HashMap<>();
|
||||
for (PmsProductLibraryComponent component : componentList) {
|
||||
String fileSource = component.getFileIdentifier();
|
||||
if (StringUtils.isEmpty(fileSource)) {
|
||||
fileSource = EscapeUtil.removeExtraSlashOfUrl(productRepo.getUrl() + "/" + ServletUtils.urlEncodeExcludeSlashes(component.getPath()));
|
||||
if (ProductLibraryComponentPathEnum.pathIsNeedPackaged(node, component.getPath())) {
|
||||
String fileSource = component.getFileIdentifier();
|
||||
if (StringUtils.isEmpty(fileSource)) {
|
||||
fileSource = EscapeUtil.removeExtraSlashOfUrl(productRepo.getUrl() + "/" + ServletUtils.urlEncodeExcludeSlashesApplyDuplicate(component.getPath()));
|
||||
}
|
||||
packagedStructure.put(ProductLibraryComponentPathEnum.getChineseFixedPath(component.getPath()), fileSource);
|
||||
}
|
||||
packagedStructure.put(component.getPath(), fileSource);
|
||||
}
|
||||
String fileIdentifier = FeignUtils.getReturnData(
|
||||
remoteFileService.packagedFile(
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package com.microservices.pms.productLibrary.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.constant.CacheConstants;
|
||||
import com.microservices.common.core.constant.SecurityConstants;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
import com.microservices.common.core.utils.PageUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.core.utils.html.EscapeUtil;
|
||||
import com.microservices.common.core.web.domain.GenericsAjaxResult;
|
||||
import com.microservices.common.core.web.page.GenericsTableDataInfo;
|
||||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.pms.common.service.IPmsCommonService;
|
||||
import com.microservices.pms.document.domain.vo.PmsDocumentDetailVo;
|
||||
|
|
@ -15,6 +18,8 @@ import com.microservices.pms.document.domain.vo.PmsDocumentVo;
|
|||
import com.microservices.pms.document.service.IPmsDocumentService;
|
||||
import com.microservices.pms.enterprise.domain.PmsEnterprise;
|
||||
import com.microservices.pms.enterprise.service.IPmsEnterpriseService;
|
||||
import com.microservices.pms.enums.ProductLibraryComponentPathEnum;
|
||||
import com.microservices.pms.enums.ProductLibraryRepoFromTypeEnum;
|
||||
import com.microservices.pms.product.domain.PmsProduct;
|
||||
import com.microservices.pms.product.service.IPmsProductService;
|
||||
import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent;
|
||||
|
|
@ -81,6 +86,8 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
private IPmsCommonService pmsCommonService;
|
||||
@Autowired
|
||||
private IPmsProductService pmsProductService;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public GenericsTableDataInfo<PmsProductLibraryComponentDataVo> selectComponentList(PmsProductLibraryComponentSearchVo search) {
|
||||
|
|
@ -106,6 +113,9 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
EscapeUtil.removeExtraSlashOfUrl(
|
||||
String.format("%s/%s", repo.getUrl(), component.getPath()))));
|
||||
pmsCommonService.setBaseEntityVo(pmsProductLibraryComponentDataVo, component);
|
||||
pmsProductLibraryComponentDataVo.setFromType(
|
||||
ProductLibraryRepoFromTypeEnum.getByKey(component.getFromType()).getName()
|
||||
);
|
||||
return pmsProductLibraryComponentDataVo;
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +188,7 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProductPackagedResultVo getPackagedProduct(String enterpriseIdentifier, String productRepoName) {
|
||||
public GenericsAjaxResult<ProductPackagedResultVo> getPackagedProduct(String enterpriseIdentifier, String productRepoName) {
|
||||
ProductPackagedResultVo productPackagedResultVo = new ProductPackagedResultVo();
|
||||
PmsProductLibraryRepositories productLibraryRepositories = selectPmsProductLibraryByName(enterpriseIdentifier, productRepoName);
|
||||
String packagedFileIdentifier = productLibraryRepositories.getPackagedFileIdentifier();
|
||||
|
|
@ -186,29 +196,51 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
productPackagedResultVo.setIsPackaged(false);
|
||||
} else {
|
||||
productPackagedResultVo.setIsPackaged(true);
|
||||
try {
|
||||
SysFileInfo sysFileInfo = FeignUtils.getReturnData(
|
||||
remoteFileService.getFileByFileIdentifier(packagedFileIdentifier, SecurityConstants.INNER)
|
||||
);
|
||||
Integer isFinish = redisService.getCacheObject(CacheConstants.getPackageFileIsFinish(packagedFileIdentifier));
|
||||
if (isFinish != null) {
|
||||
redisService.deleteObject(CacheConstants.getPackageFileIsFinish(packagedFileIdentifier));
|
||||
}
|
||||
// 键值不存在或键值为1,代表打包成功,通过远程接口获取文件信息
|
||||
if (isFinish == null || isFinish == 1) {
|
||||
SysFileInfo sysFileInfo = null;
|
||||
try {
|
||||
sysFileInfo = FeignUtils.getReturnData(
|
||||
remoteFileService.getFileByFileIdentifier(packagedFileIdentifier, SecurityConstants.INNER)
|
||||
);
|
||||
} catch (ServiceException e) {
|
||||
log.error("获取打包文件失败:{}", e.getMessage());
|
||||
return packageError(productLibraryRepositories, productPackagedResultVo);
|
||||
}
|
||||
if (sysFileInfo != null) {
|
||||
productPackagedResultVo.setDownloadUrl(sysFileInfo.getDownloadUrl());
|
||||
productPackagedResultVo.setFileName(sysFileInfo.getFileOriginName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取产品库打包文件失败:{}", e.getMessage());
|
||||
} else if (isFinish == -1) {
|
||||
// 键值为-1,代表打包失败,需要重新打包
|
||||
return packageError(productLibraryRepositories, productPackagedResultVo);
|
||||
}
|
||||
}
|
||||
return productPackagedResultVo;
|
||||
return GenericsAjaxResult.success(productPackagedResultVo);
|
||||
}
|
||||
|
||||
private GenericsAjaxResult<ProductPackagedResultVo> packageError(PmsProductLibraryRepositories productLibraryRepositories, ProductPackagedResultVo productPackagedResultVo) {
|
||||
pmsProductLibraryRepositoriesMapper.setProductLibraryPackagedFileIdentifierNull(productLibraryRepositories.getId());
|
||||
productPackagedResultVo.setIsPackaged(false);
|
||||
return GenericsAjaxResult.error("打包失败,请重新打包!", productPackagedResultVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean uploadProductAsset(ProductComponentInputVo productComponentInputVo) {
|
||||
public Boolean uploadProductAsset(ProductDocComponentInputVo productDocComponentInputVo) {
|
||||
PmsProductLibraryRepositories repo =
|
||||
selectPmsProductLibraryByName(productComponentInputVo.getEnterpriseIdentifier(), productComponentInputVo.getProductRepoName());
|
||||
selectPmsProductLibraryByName(productDocComponentInputVo.getEnterpriseIdentifier(), productDocComponentInputVo.getProductRepoName());
|
||||
|
||||
// 产品库制品添加默认前缀
|
||||
productDocComponentInputVo.setDirectory(ProductLibraryComponentPathEnum.getDocFixedPath(
|
||||
productDocComponentInputVo.getDirectory()
|
||||
));
|
||||
List<AssetRawInputVo> assetList = new ArrayList<>();
|
||||
PmsEnterprise pmsEnterprise = pmsEnterpriseService.selectPmsEnterpriseByIdentifier(productComponentInputVo.getEnterpriseIdentifier());
|
||||
for (Long docId : productComponentInputVo.getDocList()) {
|
||||
PmsEnterprise pmsEnterprise = pmsEnterpriseService.selectPmsEnterpriseByIdentifier(productDocComponentInputVo.getEnterpriseIdentifier());
|
||||
for (Long docId : productDocComponentInputVo.getDocList()) {
|
||||
PmsDocumentDetailVo pmsDocument = pmsDocumentService.selectPmsDocumentDetailVoByIdAndEnterpriseId(docId, pmsEnterprise.getId());
|
||||
if (!Objects.equals(pmsDocument.getDocType(), 2) && !Objects.equals(pmsDocument.getDocType(), 3)) {
|
||||
throw new ServiceException("产品库文档类型仅允许为文档类型或附件类型(文档Id[%s])", pmsDocument.getId());
|
||||
|
|
@ -251,7 +283,7 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
|
||||
assetList.add(assetRawInputVo);
|
||||
}
|
||||
return pmsProductLibraryComponentService.insertRawComponent(productComponentInputVo.toComponentRawInputVo(assetList));
|
||||
return pmsProductLibraryComponentService.insertRawComponent(productDocComponentInputVo.toComponentRawInputVo(assetList));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -338,6 +370,10 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
if (ProductLibraryRepositoriesFormatEnum.DOCKER.getKey().equals(repo.getFormat())) {
|
||||
throw new ServiceException("Docker制品移入不能使用该接口");
|
||||
}
|
||||
// 产品库制品添加默认前缀
|
||||
commonAssetAddToProductRepoVo.setDirectory(ProductLibraryComponentPathEnum.getSoftwareFixedPath(
|
||||
commonAssetAddToProductRepoVo.getDirectory()
|
||||
));
|
||||
List<NexusAssetResultDataVo> nexusAssetResultDataVoList = new ArrayList<>();
|
||||
for (String assetId : commonAssetAddToProductRepoVo.getAssetIdList()) {
|
||||
NexusComponentResultVo<NexusAssetResultDataVo> nexusAssetResultVo = pmsProductLibraryComponentService.getAssetDetailByAssetId(commonAssetAddToProductRepoVo.getEnterpriseIdentifier(), commonAssetAddToProductRepoVo.getRepoName(), null, assetId, false);
|
||||
|
|
@ -434,6 +470,10 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
if (!ProductLibraryRepositoriesFormatEnum.DOCKER.getKey().equals(repo.getFormat())) {
|
||||
throw new ServiceException("当前接口仅允许进行Docker移入产品库操作");
|
||||
}
|
||||
// 产品库制品添加默认前缀
|
||||
dockerComponentAddToProductRepoVo.setDirectory(ProductLibraryComponentPathEnum.getSoftwareFixedPath(
|
||||
dockerComponentAddToProductRepoVo.getDirectory()
|
||||
));
|
||||
List<NexusComponentResultDataVo> nexusComponentResultDataVoList = new ArrayList<>();
|
||||
for (String componentId : dockerComponentAddToProductRepoVo.getComponentIdList()) {
|
||||
NexusComponentResultVo<NexusComponentResultDataVo> nexusAssetResultVo = pmsProductLibraryComponentService.getComponentDetailByComponentId(dockerComponentAddToProductRepoVo.getEnterpriseIdentifier(), dockerComponentAddToProductRepoVo.getRepoName(), null, componentId, false);
|
||||
|
|
@ -496,9 +536,9 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
|
||||
|
||||
@Override
|
||||
public boolean packagedProduct(String enterpriseIdentifier, String productRepoName) {
|
||||
public boolean packagedProduct(String enterpriseIdentifier, String productRepoName, String node) {
|
||||
PmsProductLibraryRepositories productRepo = selectPmsProductLibraryByName(enterpriseIdentifier, productRepoName);
|
||||
pmsProductLibraryAsyncService.packagedProduct(productRepo);
|
||||
pmsProductLibraryAsyncService.packagedProduct(productRepo, node);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
<result property="attributes" column="attributes"/>
|
||||
<result property="reservedField1" column="reserved_field_1"/>
|
||||
<result property="reservedField2" column="reserved_field_2"/>
|
||||
<result property="reservedField3" column="reserved_field_3"/>
|
||||
<result property="fromType" column="from_type"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectPmsProductLibraryComponentVo">
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
attributes,
|
||||
reserved_field_1,
|
||||
reserved_field_2,
|
||||
reserved_field_3
|
||||
from_type
|
||||
from pms_product_library_component
|
||||
</sql>
|
||||
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
pplc.attributes,
|
||||
pplc.reserved_field_1,
|
||||
pplc.reserved_field_2,
|
||||
pplc.reserved_field_3,
|
||||
pplc.from_type,
|
||||
pe.enterprise_identifier,
|
||||
pplr.format
|
||||
from pms_product_library_component as pplc
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
<if test="attributes != null and attributes != ''">and attributes = #{attributes}</if>
|
||||
<if test="reservedField1 != null and reservedField1 != ''">and reserved_field_1 = #{reservedField1}</if>
|
||||
<if test="reservedField2 != null and reservedField2 != ''">and reserved_field_2 = #{reservedField2}</if>
|
||||
<if test="reservedField3 != null and reservedField3 != ''">and reserved_field_3 = #{reservedField3}</if>
|
||||
<if test="fromType != null and fromType != ''">and from_type = #{fromType}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
|
@ -164,7 +164,7 @@
|
|||
<if test="attributes != null">attributes,</if>
|
||||
<if test="reservedField1 != null">reserved_field_1,</if>
|
||||
<if test="reservedField2 != null">reserved_field_2,</if>
|
||||
<if test="reservedField3 != null">reserved_field_3,</if>
|
||||
<if test="fromType != null">from_type,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="identifier != null and identifier != ''">#{identifier},</if>
|
||||
|
|
@ -184,7 +184,7 @@
|
|||
<if test="attributes != null">#{attributes},</if>
|
||||
<if test="reservedField1 != null">#{reservedField1},</if>
|
||||
<if test="reservedField2 != null">#{reservedField2},</if>
|
||||
<if test="reservedField3 != null">#{reservedField3},</if>
|
||||
<if test="fromType != null">#{fromType},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
|
@ -208,7 +208,7 @@
|
|||
<if test="attributes != null">attributes = #{attributes},</if>
|
||||
<if test="reservedField1 != null">reserved_field_1 = #{reservedField1},</if>
|
||||
<if test="reservedField2 != null">reserved_field_2 = #{reservedField2},</if>
|
||||
<if test="reservedField3 != null">reserved_field_3 = #{reservedField3},</if>
|
||||
<if test="fromType != null">from_type = #{fromType},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
|
|
|||
|
|
@ -239,6 +239,11 @@
|
|||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
<update id="setProductLibraryPackagedFileIdentifierNull">
|
||||
update pms_product_library_repositories
|
||||
set packaged_file_identifier = null
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deletePmsProductLibraryRepositoriesById" parameterType="Long">
|
||||
delete
|
||||
|
|
|
|||
Loading…
Reference in New Issue