feat(REQ-2186): 查询租户产品列表增加sku返回

This commit is contained in:
李昆鹏 2024-05-15 08:36:17 +08:00
parent 6d9d02fe31
commit 9b005e6f2d
2 changed files with 59 additions and 24 deletions

View File

@ -6,6 +6,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.List;
/**
@ -69,6 +71,43 @@ public class WorkspaceProductResp {
* 最大项目数 <企业产品>
*/
private Integer maxWorkspaceCount;
/**
* SKU列表
*/
@Valid
private List<Sku> skus;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Sku {
/**
* SKU名称
*/
private String skuName;
/**
* 规格型号
*/
private String model;
/**
* 数量
*/
@Min(value = 1, message = "数量有误")
private Integer count;
/**
* 单位
*/
private String unit;
}
public static WorkspaceProductResp init() {

View File

@ -252,36 +252,16 @@ public class ProductServiceImpl implements ProductService {
.build()).collect(Collectors.toList()));
} else {
if (ProductModuleCategoryEnum.PRODUCT_VERSION.getCode().equals(k)) {
resp.getProductVersions().addAll(v.stream().map(e -> WorkspaceProductResp.Product.builder()
.productId(e.getId())
.productName(e.getProductName())
.maxPersonCount(e.getMaxPersonCount())
.maxWorkspaceCount(e.getMaxWorkspaceCount())
.build()).collect(Collectors.toList()));
resp.getProductVersions().addAll(v.stream().map(this::buildRespProduct).filter(Objects::nonNull).collect(Collectors.toList()));
}
if (ProductModuleCategoryEnum.ADD_VALUE_SERVICE.getCode().equals(k)) {
resp.getAddValueServices().addAll(v.stream().map(e -> WorkspaceProductResp.Product.builder()
.productId(e.getId())
.productName(e.getProductName())
.maxPersonCount(e.getMaxPersonCount())
.maxWorkspaceCount(e.getMaxWorkspaceCount())
.build()).collect(Collectors.toList()));
resp.getAddValueServices().addAll(v.stream().map(this::buildRespProduct).filter(Objects::nonNull).collect(Collectors.toList()));
}
if (ProductModuleCategoryEnum.GENERAL_SERVICE.getCode().equals(k)) {
resp.getGeneralServices().addAll(v.stream().map(e -> WorkspaceProductResp.Product.builder()
.productId(e.getId())
.productName(e.getProductName())
.maxPersonCount(e.getMaxPersonCount())
.maxWorkspaceCount(e.getMaxWorkspaceCount())
.build()).collect(Collectors.toList()));
resp.getGeneralServices().addAll(v.stream().map(this::buildRespProduct).filter(Objects::nonNull).collect(Collectors.toList()));
}
if (ProductModuleCategoryEnum.HARD_WARE.getCode().equals(k)) {
resp.getHardware().addAll(v.stream().map(e -> WorkspaceProductResp.Product.builder()
.productId(e.getId())
.productName(e.getProductName())
.maxPersonCount(e.getMaxPersonCount())
.maxWorkspaceCount(e.getMaxWorkspaceCount())
.build()).collect(Collectors.toList()));
resp.getHardware().addAll(v.stream().map(this::buildRespProduct).filter(Objects::nonNull).collect(Collectors.toList()));
}
}
});
@ -377,4 +357,20 @@ public class ProductServiceImpl implements ProductService {
.build());
}
}
private WorkspaceProductResp.Product buildRespProduct(ProductModule pm) {
return Optional.ofNullable(pm).map(e -> WorkspaceProductResp.Product.builder()
.productId(e.getId())
.productName(e.getProductName())
.maxPersonCount(e.getMaxPersonCount())
.maxWorkspaceCount(e.getMaxWorkspaceCount())
.skus(CollectionUtil.isNotEmpty(e.getSkus()) ? e.getSkus().stream().map(s -> WorkspaceProductResp.Sku
.builder()
.skuName(s.getSkuName())
.model(s.getModel())
.count(s.getCount())
.unit(s.getUnit())
.build()).collect(Collectors.toList()) : Collections.emptyList())
.build()).orElse(null);
}
}