|
@@ -2,30 +2,43 @@ package com.sd.business.service.sku.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.board.dto.SkuSpecQuotationDto;
|
|
|
+import com.sd.business.entity.board.vo.SkuSpecQuotationVo;
|
|
|
import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.inventory.po.Inventory;
|
|
|
+import com.sd.business.entity.price.po.PriceBillingStandard;
|
|
|
+import com.sd.business.entity.price.po.PriceBillingStandardDetail;
|
|
|
import com.sd.business.entity.sku.bo.SkuSpecBo;
|
|
|
import com.sd.business.entity.sku.dto.SkuSpecDto;
|
|
|
import com.sd.business.entity.sku.dto.SkuSpecSelectDto;
|
|
|
+import com.sd.business.entity.sku.po.Sku;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.entity.sku.po.SkuSpecLink;
|
|
|
import com.sd.business.entity.sku.vo.SkuSpecVo;
|
|
|
import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
|
import com.sd.business.mapper.sku.SkuSpecMapper;
|
|
|
+import com.sd.business.service.department.DepartmentService;
|
|
|
import com.sd.business.service.inventory.InventoryService;
|
|
|
+import com.sd.business.service.price.PriceBillingStandardDetailService;
|
|
|
+import com.sd.business.service.price.PriceBillingStandardService;
|
|
|
+import com.sd.business.service.sku.SkuService;
|
|
|
+import com.sd.business.service.sku.SkuSpecLinkService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
+import com.sd.framework.util.Assert;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -44,6 +57,21 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
|
@Autowired
|
|
|
private InventoryService inventoryService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DepartmentService departmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuService skuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecLinkService skuSpecLinkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PriceBillingStandardService priceBillingStandardService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PriceBillingStandardDetailService priceBillingStandardDetailService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<SkuSpecVo> getPage(SkuSpecSelectDto dto) {
|
|
|
IWrapper<SkuSpec> wrapper = getWrapper();
|
|
@@ -145,4 +173,132 @@ public class SkuSpecServiceImpl extends ServiceImpl<SkuSpecMapper, SkuSpec> impl
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SkuSpecQuotationVo> getSkuSpecQuotationList(SkuSpecQuotationDto dto) {
|
|
|
+ Long deptId = SecurityUtils.getDeptId();
|
|
|
+ Department department = departmentService.getById(deptId);
|
|
|
+ Assert.notNull(department, "未知事业部");
|
|
|
+ String priceBillingStandardIdStr = department.getPriceBillingStandardId();
|
|
|
+ Assert.notBlank(priceBillingStandardIdStr, "事业部未绑定加工计费标准");
|
|
|
+
|
|
|
+ // 查询事业部绑定的品牌
|
|
|
+ List<String> brandList = Arrays.asList(department.getWlnBrand().split(","));
|
|
|
+ if (ObjectUtil.isEmpty(brandList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, Sku> skuMap = skuService.mapKEntity(BaseIdPo::getId, q -> q.in(Sku::getBrand, brandList));
|
|
|
+ List<SkuSpec> skuSpecList = this.list(q -> q
|
|
|
+ .in(SkuSpec::getSkuId, skuMap.keySet())
|
|
|
+ .isNotNull(SkuSpec::getBomSpecId)
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSkuSpecCode()), SkuSpec::getCode, dto.getSkuSpecCode())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSkuSpecName()), SkuSpec::getName, dto.getSkuSpecName()));
|
|
|
+
|
|
|
+ if (skuSpecList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询加工计费标准数据
|
|
|
+ List<String> priceBillingStandardIdList = Arrays.stream(priceBillingStandardIdStr.split(",")).collect(Collectors.toList());
|
|
|
+ List<PriceBillingStandard> priceBillingStandardList = priceBillingStandardService.listByIds(priceBillingStandardIdList);
|
|
|
+ List<Long> priceBillingStandardIds = priceBillingStandardList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, List<PriceBillingStandardDetail>> priceDetailMap = priceBillingStandardDetailService.mapKGroup(
|
|
|
+ PriceBillingStandardDetail::getPriceBillingStandardId,
|
|
|
+ q -> q.in(PriceBillingStandardDetail::getPriceBillingStandardId, priceBillingStandardIds));
|
|
|
+
|
|
|
+ // 获取sku关联的所有bom数据
|
|
|
+ List<Long> skuSpecIds = skuSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<SkuSpecLink>> linkMap = skuSpecLinkService.mapKGroup(SkuSpecLink::getSkuSpecId,
|
|
|
+ q -> q.in(SkuSpecLink::getSkuSpecId, skuSpecIds)
|
|
|
+ .eq(SkuSpecLink::getDepartmentId, deptId)
|
|
|
+ .eq(SkuSpecLink::getType, 1));
|
|
|
+ Set<Long> bomSpecIds = skuSpecList.stream().map(SkuSpec::getBomSpecId).collect(Collectors.toSet());
|
|
|
+ bomSpecIds.addAll(linkMap.values().stream().flatMap(item -> item.stream().map(SkuSpecLink::getBomSpecId)).collect(Collectors.toList()));
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = this.getBomSpecBoByIdList(bomSpecIds);
|
|
|
+
|
|
|
+ List<SkuSpecQuotationVo> list = new ArrayList<>();
|
|
|
+
|
|
|
+ for (SkuSpec skuSpec : skuSpecList) {
|
|
|
+ Sku sku = skuMap.get(skuSpec.getSkuId());
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(skuSpec.getBomSpecId());
|
|
|
+
|
|
|
+ // 赋值
|
|
|
+ SkuSpecQuotationVo vo = new SkuSpecQuotationVo();
|
|
|
+ vo.setBrand(sku.getBrand());
|
|
|
+ vo.setSkuSpecCode(skuSpec.getCode());
|
|
|
+ vo.setSkuSpecName(skuSpec.getName());
|
|
|
+ vo.setBomSpecUnitPrice(bomSpecBo.getInternalSellingPrice());
|
|
|
+ vo.setPackagingMaterialCost(BigDecimal.ZERO);
|
|
|
+ vo.setLineProcessingFee(BigDecimal.ZERO);
|
|
|
+ vo.setLogoProcessingFee(BigDecimal.ZERO);
|
|
|
+ vo.setIssueFee(BigDecimal.ZERO);
|
|
|
+ vo.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
+ vo.setPackingLabor(BigDecimal.ZERO);
|
|
|
+ vo.setManagementFee(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 获取包材费
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = linkMap.get(skuSpec.getId());
|
|
|
+ if (ObjectUtil.isNotEmpty(skuSpecLinkList)) {
|
|
|
+ BigDecimal packagingMaterialCost = skuSpecLinkList.stream().map(item -> {
|
|
|
+ BomSpecBo skuSpecLinkBomSpec = bomSpecBoMap.get(item.getBomSpecId());
|
|
|
+ if (skuSpecLinkBomSpec == null) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ return skuSpecLinkBomSpec.getInternalSellingPrice().multiply(item.getQuantity());
|
|
|
+ }).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ vo.setPackagingMaterialCost(packagingMaterialCost);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取加工计费标准
|
|
|
+ List<PriceBillingStandardDetail> priceBillingStandardDetailList = new ArrayList<>();
|
|
|
+ if (StrUtil.isNotBlank(bomSpecBo.getBomSpecies())) {
|
|
|
+ priceBillingStandardList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getSpecies(), bomSpecBo.getBomSpecies()))
|
|
|
+ .findAny()
|
|
|
+ .ifPresent(item -> priceBillingStandardDetailList.addAll(priceDetailMap.getOrDefault(item.getId(), Collections.emptyList())));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PriceBillingStandardDetail priceBillingStandardDetail : priceBillingStandardDetailList) {
|
|
|
+ String chargeItem = priceBillingStandardDetail.getChargeItem();
|
|
|
+ BigDecimal chargePrice = ObjectUtil.defaultIfNull(priceBillingStandardDetail.getChargePrice(), BigDecimal.ZERO);
|
|
|
+ switch (chargeItem) {
|
|
|
+ case "10":
|
|
|
+ vo.setLineProcessingFee(chargePrice);
|
|
|
+ break;
|
|
|
+ case "20":
|
|
|
+ vo.setLogoProcessingFee(chargePrice);
|
|
|
+ break;
|
|
|
+ case "40":
|
|
|
+ vo.setPackingLabor(chargePrice);
|
|
|
+ break;
|
|
|
+ case "50":
|
|
|
+ vo.setIssueFee(chargePrice);
|
|
|
+ break;
|
|
|
+ case "60":
|
|
|
+ vo.setDeliveryMaterialsFee(chargePrice);
|
|
|
+ break;
|
|
|
+ case "70":
|
|
|
+ vo.setManagementFee(chargePrice);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算Sku单价
|
|
|
+ vo.setSkuSpecUnitPrice(
|
|
|
+ vo.getBomSpecUnitPrice()
|
|
|
+ .add(vo.getPackagingMaterialCost())
|
|
|
+ .add(vo.getIssueFee())
|
|
|
+ .add(vo.getPackingLabor())
|
|
|
+ .add(vo.getDeliveryMaterialsFee())
|
|
|
+ .add(vo.getManagementFee()));
|
|
|
+ vo.setSkuSpecUnitPriceLogo(vo.getSkuSpecUnitPrice().add(vo.getLogoProcessingFee()));
|
|
|
+ vo.setSkuSpecUnitPriceLine(vo.getSkuSpecUnitPrice().add(vo.getLineProcessingFee()));
|
|
|
+
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|