|
@@ -1,16 +1,35 @@
|
|
|
package com.sd.business.service.sku.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+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.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+import com.sd.business.entity.sku.dto.SkuDto;
|
|
|
+import com.sd.business.entity.sku.dto.SkuSelectDto;
|
|
|
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.SkuSpecLinkVo;
|
|
|
+import com.sd.business.entity.sku.vo.SkuSpecVo;
|
|
|
+import com.sd.business.entity.sku.vo.SkuVo;
|
|
|
import com.sd.business.mapper.sku.SkuMapper;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.sku.SkuService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.sd.business.entity.sku.vo.SkuVo;
|
|
|
-import com.sd.business.entity.sku.dto.SkuSelectDto;
|
|
|
-import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
-import com.sd.business.entity.sku.dto.SkuDto;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -18,24 +37,99 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
* sku 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
- * @author
|
|
|
+ * @author
|
|
|
* @since 2023-07-03
|
|
|
*/
|
|
|
@Service
|
|
|
public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecService skuSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecLinkService skuSpecLinkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<SkuVo> getPage(SkuSelectDto dto) {
|
|
|
IWrapper<Sku> wrapper = getWrapper();
|
|
|
wrapper.orderByDesc("s", Sku::getId);
|
|
|
+ wrapper.like("s", Sku::getCode, dto.getCode());
|
|
|
+ wrapper.like("s", Sku::getName, dto.getName());
|
|
|
+ wrapper.like("s", Sku::getType, dto.getType());
|
|
|
Page<SkuVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<SkuVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> skuIdList = records.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<SkuSpec>> skuSpecMap = skuSpecService.mapKGroup(SkuSpec::getSkuId,
|
|
|
+ q -> q.in(SkuSpec::getSkuId, skuIdList));
|
|
|
+ records.forEach(item -> item.setSkuSpecList(skuSpecMap.getOrDefault(item.getId(), Collections.emptyList())));
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SkuVo detail(Long id) {
|
|
|
- Sku Sku = this.getById(id);
|
|
|
- SkuVo result = BeanUtil.toBean(Sku, SkuVo.class);
|
|
|
+ // sku
|
|
|
+ Sku sku = this.getById(id);
|
|
|
+ Assert.notNull(sku, "未通过skuId找到sku");
|
|
|
+ SkuVo result = BeanUtil.toBean(sku, SkuVo.class);
|
|
|
+
|
|
|
+ // sku规格
|
|
|
+ List<SkuSpec> list = skuSpecService.list(q -> q.in(SkuSpec::getSkuId, id));
|
|
|
+ List<SkuSpecVo> skuSpecList = BeanUtil.copyToList(list, SkuSpecVo.class);
|
|
|
+ result.setSkuSpecList(skuSpecList);
|
|
|
+
|
|
|
+ // sku规格关联
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = skuSpecLinkService.list(
|
|
|
+ q -> q.eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId()).eq(SkuSpecLink::getSkuId, id));
|
|
|
+
|
|
|
+ // sku规格关联map
|
|
|
+ Map<Long, Map<Integer, List<SkuSpecLink>>> map = skuSpecLinkList.stream().collect(
|
|
|
+ Collectors.groupingBy(SkuSpecLink::getSkuSpecId, Collectors.groupingBy(SkuSpecLink::getType)));
|
|
|
+
|
|
|
+ // bom规格id列表
|
|
|
+ List<Long> bomSpecIdList = new ArrayList<>();
|
|
|
+ bomSpecIdList.addAll(list.stream().map(SkuSpec::getBomSpecId).filter(ObjectUtil::isNotNull).collect(Collectors.toList()));
|
|
|
+ bomSpecIdList.addAll(skuSpecLinkList.stream().map(SkuSpecLink::getBomSpecId).collect(Collectors.toList()));
|
|
|
+ if (bomSpecIdList.size() == 0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, BomSpec> bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIdList));
|
|
|
+ for (SkuSpecVo item : skuSpecList) {
|
|
|
+
|
|
|
+ // 赋值主材bom名称
|
|
|
+ Long bomSpecId = item.getBomSpecId();
|
|
|
+ if (bomSpecId != null) {
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(bomSpecId);
|
|
|
+ if (bomSpec != null) {
|
|
|
+ item.setBomSpecName(bomSpec.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 包材,快递包装
|
|
|
+ Map<Integer, List<SkuSpecLink>> typeSkuSpecLinkMap = map.get(item.getId());
|
|
|
+ if (typeSkuSpecLinkMap == null) {
|
|
|
+ item.setPackagingMaterialList(Collections.emptyList());
|
|
|
+ item.setExpressPackingList(Collections.emptyList());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值包材
|
|
|
+ List<SkuSpecLinkVo> packagingMaterialList = createSkuSpecLinkVoList(typeSkuSpecLinkMap.get(1), bomSpecMap);
|
|
|
+ item.setPackagingMaterialList(packagingMaterialList);
|
|
|
+
|
|
|
+ // 赋值快递包装
|
|
|
+ List<SkuSpecLinkVo> expressPackingList = createSkuSpecLinkVoList(typeSkuSpecLinkMap.get(2), bomSpecMap);
|
|
|
+ item.setExpressPackingList(expressPackingList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -54,4 +148,19 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ private List<SkuSpecLinkVo> createSkuSpecLinkVoList(List<SkuSpecLink> skuSpecLinkList, Map<Long, BomSpec> bomSpecMap) {
|
|
|
+ if (ObjectUtil.isEmpty(skuSpecLinkList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return skuSpecLinkList.stream().map(item -> {
|
|
|
+ SkuSpecLinkVo skuSpecLinkVo = BeanUtil.toBean(item, SkuSpecLinkVo.class);
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(item.getBomSpecId());
|
|
|
+ if (bomSpec != null) {
|
|
|
+ skuSpecLinkVo.setName(bomSpec.getName());
|
|
|
+ }
|
|
|
+ return skuSpecLinkVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
}
|