|
@@ -13,6 +13,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.yc.ship.framework.common.pojo.CommonResult;
|
|
|
import com.yc.ship.framework.common.pojo.PageResult;
|
|
|
import com.yc.ship.framework.common.util.object.BeanUtils;
|
|
|
+import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
import com.yc.ship.framework.mybatis.core.query.MPJLambdaWrapperX;
|
|
|
import com.yc.ship.framework.mybatis.core.util.MyBatisUtils;
|
|
|
import com.yc.ship.framework.security.core.LoginUser;
|
|
@@ -44,6 +45,7 @@ import com.yc.ship.module.product.dal.dataobject.productSaleRule.ProductSaleRule
|
|
|
import com.yc.ship.module.product.dal.dataobject.productSku.ProductSkuDO;
|
|
|
import com.yc.ship.module.product.dal.dataobject.productSpu.ProductSpuDO;
|
|
|
import com.yc.ship.module.product.dal.dataobject.productTakeRule.ProductTakeRuleDO;
|
|
|
+import com.yc.ship.module.product.dal.dataobject.spuship.SpuShipDO;
|
|
|
import com.yc.ship.module.product.dal.mysql.productBase.ProductBaseMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.productBasicRule.ProductBasicRuleMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.productCheckRule.ProductCheckRuleMapper;
|
|
@@ -56,11 +58,13 @@ import com.yc.ship.module.product.dal.mysql.productSaleRule.ProductSaleRuleMappe
|
|
|
import com.yc.ship.module.product.dal.mysql.productSku.ProductSkuMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.productSpu.ProductSpuMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.productTakeRule.ProductTakeRuleMapper;
|
|
|
+import com.yc.ship.module.product.dal.mysql.spuship.SpuShipMapper;
|
|
|
import com.yc.ship.module.product.enums.SpecTypeEnum;
|
|
|
import com.yc.ship.module.product.service.productGroup.ProductGroupService;
|
|
|
import com.yc.ship.module.resource.controller.admin.category.vo.CategoryListReqVO;
|
|
|
import com.yc.ship.module.resource.controller.admin.category.vo.CategoryRespVO;
|
|
|
import com.yc.ship.module.resource.controller.admin.resource.vo.ReducedResourceRespVO;
|
|
|
+import com.yc.ship.module.resource.dal.dataobject.category.CategoryDO;
|
|
|
import com.yc.ship.module.resource.dal.dataobject.resource.ResourceDO;
|
|
|
import com.yc.ship.module.resource.dal.mysql.resource.ResourceMapper;
|
|
|
import com.yc.ship.module.resource.enums.UseStatusEnum;
|
|
@@ -104,6 +108,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
private final ProductBasicRuleMapper productBasicMapper;
|
|
|
private final ProductSaleRuleMapper productSaleMapper;
|
|
|
private final ProductTakeRuleMapper productTakeMapper;
|
|
|
+ private final SpuShipMapper spuShipMapper;
|
|
|
private final ProductCheckRuleMapper productCheckMapper;
|
|
|
private final ProductRefundRuleMapper productRefundMapper;
|
|
|
private final ProductNoticeRuleMapper productNoticeMapper;
|
|
@@ -132,6 +137,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
productSpu.setId(IdWorker.getId(productSpu));
|
|
|
productSpuMapper.insert(productSpu);
|
|
|
|
|
|
+ String[] ships = createReqVO.getShipIds().split(",");
|
|
|
+ for (String ship : ships) {
|
|
|
+ SpuShipDO spuShip = new SpuShipDO();
|
|
|
+ spuShip.setId(IdWorker.getId(spuShip));
|
|
|
+ spuShip.setShipId(ship);
|
|
|
+ spuShip.setProductId(productSpu.getId());
|
|
|
+ spuShipMapper.insert(spuShip);
|
|
|
+ }
|
|
|
if (ObjectUtil.isNotEmpty(createReqVO.getProductSaleChannels())) {
|
|
|
// 保存销售渠道
|
|
|
String[] channels = createReqVO.getProductSaleChannels().split(",");
|
|
@@ -189,7 +202,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
});
|
|
|
}
|
|
|
// 保存sku 与 group 信息
|
|
|
- saveSkuAndGroupList(createReqVO.getProductGroupList(), createReqVO.getProductSkuList(), platProductPriceList,productSpu.getId());
|
|
|
+ saveSkuAndGroupList(createReqVO.getProductGroupList(), createReqVO.getProductSkuList(),productSpu.getId());
|
|
|
// 返回
|
|
|
return productSpu.getId();
|
|
|
}
|
|
@@ -202,109 +215,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
*/
|
|
|
void saveSkuAndGroupList(List<ProductGroupSaveReqVO> specGroupList,
|
|
|
List<ProductSkuSaveReqVO> productSkuList,
|
|
|
- List<PlatProductPriceRespVO> platProductPriceList,
|
|
|
Long productId) {
|
|
|
- if (productSkuList.isEmpty()) {
|
|
|
- Set<String> specTypeSet = specGroupList.stream().map(ProductGroupSaveReqVO::getSpecType).collect(Collectors.toSet());
|
|
|
- specTypeSet.addAll(platProductPriceList.stream().map(PlatProductPriceRespVO::getSpecType).collect(Collectors.toSet()));
|
|
|
- for (String specType : specTypeSet) {
|
|
|
- ProductSkuSaveReqVO sku = new ProductSkuSaveReqVO();
|
|
|
- sku.setProductId(productId);
|
|
|
- sku.setSpecType(specType);
|
|
|
- sku.setCostPrice(BigDecimal.ZERO);
|
|
|
- sku.setSalePrice(BigDecimal.ZERO);
|
|
|
- sku.setSalePriceIsEmpty(true);
|
|
|
- productSkuList.add(sku);
|
|
|
- }
|
|
|
- } else {
|
|
|
- productSkuList.forEach(sku -> sku.setCostPrice(BigDecimal.ZERO));
|
|
|
- }
|
|
|
-
|
|
|
- // region 保存满足 必选项目&只有一个规格 的基础产品规格成本价
|
|
|
- // 筛选必选项目规格
|
|
|
- List<ProductGroupSaveReqVO> mustList = specGroupList.stream().filter(group -> group.getNeedChoose() == 1).collect(Collectors.toList());
|
|
|
- List<ProductGroupSaveReqVO> nomustList = specGroupList.stream().filter(group -> group.getNeedChoose() == 0).collect(Collectors.toList());
|
|
|
- // 过滤多个规格的基础产品
|
|
|
- List<Long> multiSizeProductBaseIds = new ArrayList<>();
|
|
|
- Map<Long, List<ProductGroupSaveReqVO>> productBaseMap = mustList.stream().collect(Collectors.groupingBy(ProductGroupSaveReqVO::getProductBaseId));
|
|
|
- productBaseMap.forEach((productBaseId, list) -> {
|
|
|
- Set<Long> collect = list.stream().map(ProductGroupSaveReqVO::getSpecificationId).collect(Collectors.toSet());
|
|
|
- if (collect.size() > 1) {
|
|
|
- multiSizeProductBaseIds.add(productBaseId);
|
|
|
- }
|
|
|
- });
|
|
|
- if (!multiSizeProductBaseIds.isEmpty()) {
|
|
|
- // 多规格基础产品标记 IsMatched = true
|
|
|
- mustList.forEach(group -> group.setIsMatched(multiSizeProductBaseIds.contains(group.getProductBaseId())));
|
|
|
- }
|
|
|
- // 根据规格类型分组
|
|
|
- Map<String, List<ProductGroupSaveReqVO>> groupMap = mustList.stream().collect(Collectors.groupingBy(ProductGroupSaveReqVO::getSpecType));
|
|
|
- // 累加同规格的成本价
|
|
|
- groupMap.forEach((specType, list) -> {
|
|
|
- ProductSkuSaveReqVO skuDO = new ProductSkuSaveReqVO();
|
|
|
- skuDO.setProductId(productId);
|
|
|
- skuDO.setSpecType(specType);
|
|
|
- skuDO.setCostPrice(BigDecimal.ZERO);
|
|
|
- skuDO.setSalePrice(BigDecimal.ZERO);
|
|
|
- list.forEach(spec -> {
|
|
|
- // 多规格基础产品不累加成本价
|
|
|
- if (!spec.getIsMatched()) {
|
|
|
- skuDO.setCostPrice(skuDO.getCostPrice().add(spec.getCostPrice()));
|
|
|
- skuDO.setSalePrice(skuDO.getSalePrice().add(spec.getSalePrice()));
|
|
|
- }
|
|
|
- spec.setIsMatched(!spec.getIsMatched());
|
|
|
- nomustList.add(spec);
|
|
|
- });
|
|
|
- productSkuList.stream().filter(sku -> ObjectUtil.equal(sku.getSpecType(), specType))
|
|
|
- .findFirst().ifPresent(sku -> {
|
|
|
- sku.setCostPrice(skuDO.getCostPrice());
|
|
|
- if (sku.getSalePriceIsEmpty()) {
|
|
|
- sku.setSalePrice(skuDO.getSalePrice());
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- // endregion
|
|
|
-
|
|
|
- if (!platProductPriceList.isEmpty()) {
|
|
|
- // 根据规格类型分组
|
|
|
- Map<String, List<PlatProductPriceRespVO>> platMap = platProductPriceList.stream().collect(Collectors.groupingBy(PlatProductPriceRespVO::getSpecType));
|
|
|
- platMap.forEach((specType, list) -> {
|
|
|
- ProductSkuSaveReqVO skuDO = new ProductSkuSaveReqVO();
|
|
|
- skuDO.setProductId(productId);
|
|
|
- skuDO.setSpecType(specType);
|
|
|
- skuDO.setCostPrice(BigDecimal.ZERO);
|
|
|
- skuDO.setSalePrice(BigDecimal.ZERO);
|
|
|
- list.forEach(spec -> {
|
|
|
- skuDO.setCostPrice(skuDO.getCostPrice().add(spec.getCostPrice()));
|
|
|
- skuDO.setSalePrice(skuDO.getSalePrice().add(spec.getSalePrice()));
|
|
|
- });
|
|
|
- productSkuList.stream().filter(sku -> ObjectUtil.equal(sku.getSpecType(), specType))
|
|
|
- .findFirst().ifPresent(sku -> {
|
|
|
- sku.setCostPrice(skuDO.getCostPrice());
|
|
|
- if (sku.getSalePriceIsEmpty()) {
|
|
|
- sku.setSalePrice(sku.getSalePrice().add(skuDO.getSalePrice()));
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- // 累加 通用规格 成本价
|
|
|
- List<ProductSkuSaveReqVO> commonTempList = productSkuList.stream()
|
|
|
- .filter(sku -> ObjectUtil.equal(sku.getSpecType(), SpecTypeEnum.COMMON.getType()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!commonTempList.isEmpty()) {
|
|
|
- ProductSkuSaveReqVO skuDO = commonTempList.get(0);
|
|
|
- if (productSkuList.size() > 1) {
|
|
|
- productSkuList.remove(skuDO);
|
|
|
- productSkuList.forEach(sku -> {
|
|
|
- sku.setCostPrice(sku.getCostPrice().add(skuDO.getCostPrice()));
|
|
|
- if (sku.getSalePriceIsEmpty()) {
|
|
|
- sku.setSalePrice(sku.getSalePrice().add(skuDO.getSalePrice()));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
// 产品sku规格信息的新增与修改
|
|
|
- productGroupService.saveSkuAndGroupList(nomustList, productSkuList, productId);
|
|
|
+ productGroupService.saveSkuAndGroupList(specGroupList, productSkuList, productId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -338,6 +251,15 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ spuShipMapper.delete(SpuShipDO::getProductId, updateObj.getId());
|
|
|
+ String[] ships = updateReqVO.getShipIds().split(",");
|
|
|
+ for (String ship : ships) {
|
|
|
+ SpuShipDO spuShip = new SpuShipDO();
|
|
|
+ spuShip.setId(IdWorker.getId(spuShip));
|
|
|
+ spuShip.setShipId(ship);
|
|
|
+ spuShip.setProductId(updateReqVO.getId());
|
|
|
+ spuShipMapper.insert(spuShip);
|
|
|
+ }
|
|
|
ProductBasicRuleDO basicRuleDO = BeanUtils.toBean(updateReqVO.getProductBasicRule(), ProductBasicRuleDO.class);
|
|
|
productBasicMapper.updateById(basicRuleDO);
|
|
|
|
|
@@ -359,37 +281,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
ProductOtherRuleDO otherRuleDO = BeanUtils.toBean(updateReqVO.getProductOtherRule(), ProductOtherRuleDO.class);
|
|
|
productOtherMapper.updateById(otherRuleDO);
|
|
|
|
|
|
- Long tenantId = TenantContextHolder.getTenantId();
|
|
|
- List<PlatProductPriceRespVO> platProductPriceList = new ArrayList<>();
|
|
|
- if (updateReqVO.getPlatProductList() != null && !updateReqVO.getPlatProductList().isEmpty()) {
|
|
|
- // 分销产品信息的新增与修改
|
|
|
- List<ProductGroupDO> groupDBList = productGroupMapper.selectList(new LambdaQueryWrapper<ProductGroupDO>()
|
|
|
- .eq(ProductGroupDO::getProductId, updateObj.getId())
|
|
|
- .eq(ProductGroupDO::getProductBaseType, 1)
|
|
|
- .eq(ProductGroupDO::getDeleted, 0));
|
|
|
- List<Long> idList = groupDBList.stream().map(ProductGroupDO::getId).collect(Collectors.toList());
|
|
|
- if (!idList.isEmpty()) {
|
|
|
- productGroupMapper.deleteBatchIds(idList);
|
|
|
- }
|
|
|
- for(PlatProductSaveReqVO item : updateReqVO.getPlatProductList()) {
|
|
|
- if (item.getPlatProductPriceList() != null && !item.getPlatProductPriceList().isEmpty()) {
|
|
|
- platProductPriceList.addAll(item.getPlatProductPriceList());
|
|
|
- }
|
|
|
- Map<String, Object> idMap = productGroupMapper.selectDistributorProductId(tenantId, item.getPlatProductId());
|
|
|
- if (idMap.isEmpty()) {
|
|
|
- throw exception(NO_PLAT_PRODUCT_AVAILABLE);
|
|
|
- }
|
|
|
- item.setProductId(updateObj.getId());
|
|
|
- item.setProductBaseId(MapUtil.getLong(idMap, "id"));
|
|
|
- item.setId(IdWorker.getId());
|
|
|
- }
|
|
|
- List<ProductGroupDO> list = BeanUtils.toBean(updateReqVO.getPlatProductList(), ProductGroupDO.class);
|
|
|
- productGroupMapper.insertBatch(list);
|
|
|
- } else {
|
|
|
- productGroupMapper.deletePlatProduct(updateObj.getId());
|
|
|
- }
|
|
|
// 保存sku信息
|
|
|
- saveSkuAndGroupList(updateReqVO.getProductGroupList(), updateReqVO.getProductSkuList(), platProductPriceList, updateReqVO.getId());
|
|
|
+ saveSkuAndGroupList(updateReqVO.getProductGroupList(), updateReqVO.getProductSkuList(), updateReqVO.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -449,6 +342,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
|
ProductBasicRuleDO basicRuleDO = productBasicMapper.selectById(id);
|
|
|
spuRespVO.setProductBasicRule(BeanUtils.toBean(basicRuleDO, ProductBasicRuleRespVO.class));
|
|
|
|
|
|
+ List<SpuShipDO> spuShipDOS = spuShipMapper.selectList(
|
|
|
+ new LambdaQueryWrapperX<SpuShipDO>()
|
|
|
+ .eqIfPresent(SpuShipDO::getProductId, id)
|
|
|
+ .eq(SpuShipDO::getDeleted, false)
|
|
|
+ );
|
|
|
+ String shipIds = spuShipDOS.stream().map(SpuShipDO::getShipId).collect(Collectors.joining(","));
|
|
|
+ spuRespVO.setShipIds(shipIds);
|
|
|
+
|
|
|
ProductSaleRuleDO saleRuleDO = productSaleMapper.selectById(id);
|
|
|
spuRespVO.setProductSaleRule(BeanUtils.toBean(saleRuleDO, ProductSaleRuleRespVO.class));
|
|
|
|