|
@@ -2,7 +2,6 @@ package com.sd.business.service.sku.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
@@ -59,7 +58,8 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
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());
|
|
|
+ wrapper.eq("s", Sku::getType, dto.getType());
|
|
|
+ wrapper.eq("s", Sku::getBrand, dto.getBrand());
|
|
|
Page<SkuVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
List<SkuVo> records = page.getRecords();
|
|
|
if (records.size() == 0) {
|
|
@@ -137,47 +137,17 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(SkuDto skuDto) {
|
|
|
- skuDto.setId(IdWorker.getId());
|
|
|
- skuDto.setSource(1);
|
|
|
-
|
|
|
- List<SkuSpecDto> skuSpecDtoList = skuDto.getSkuSpecDtoList();
|
|
|
|
|
|
- for (SkuSpecDto skuSpecDto : skuSpecDtoList) {
|
|
|
- skuSpecDto.setId(IdWorker.getId());
|
|
|
- skuSpecDto.setSkuId(skuDto.getId());
|
|
|
- }
|
|
|
-
|
|
|
- List<SkuSpecLink> skuSpecLinkList = skuSpecDtoList.stream().flatMap(item -> {
|
|
|
- List<SkuSpecLink> principalMaterialSkuSpecLinkList = item.getPrincipalMaterialSkuSpecLinkList();
|
|
|
- if (principalMaterialSkuSpecLinkList == null) {
|
|
|
- principalMaterialSkuSpecLinkList = Collections.emptyList();
|
|
|
- } else {
|
|
|
- for (SkuSpecLink skuSpecLink : principalMaterialSkuSpecLinkList) {
|
|
|
- skuSpecLink.setId(IdWorker.getId());
|
|
|
- skuSpecLink.setSkuId(item.getSkuId());
|
|
|
- skuSpecLink.setSkuSpecId(item.getId());
|
|
|
- skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
- skuSpecLink.setType(1);
|
|
|
- }
|
|
|
- }
|
|
|
+ skuDto.setSource(1);
|
|
|
+ save(skuDto);
|
|
|
|
|
|
- List<SkuSpecLink> expressPackingSkuSpecLinkList = item.getExpressPackingSkuSpecLinkList();
|
|
|
- if (expressPackingSkuSpecLinkList == null) {
|
|
|
- expressPackingSkuSpecLinkList = Collections.emptyList();
|
|
|
- } else {
|
|
|
- for (SkuSpecLink skuSpecLink : expressPackingSkuSpecLinkList) {
|
|
|
- skuSpecLink.setId(IdWorker.getId());
|
|
|
- skuSpecLink.setSkuId(item.getSkuId());
|
|
|
- skuSpecLink.setSkuSpecId(item.getId());
|
|
|
- skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
- skuSpecLink.setType(2);
|
|
|
- }
|
|
|
- }
|
|
|
- return Stream.concat(principalMaterialSkuSpecLinkList.stream(), expressPackingSkuSpecLinkList.stream());
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ List<SkuSpec> skuSpecList = skuDto.getSkuSpecList().stream()
|
|
|
+ .peek(item -> item.setSkuId(skuDto.getId()))
|
|
|
+ .map(item -> (SkuSpec) item)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ skuSpecService.saveBatch(skuSpecList);
|
|
|
|
|
|
- save(skuDto);
|
|
|
- skuSpecService.saveBatch(skuSpecDtoList.stream().map(item -> (SkuSpec) item).collect(Collectors.toList()));
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = createSkuSpecLink(skuDto.getSkuSpecList());
|
|
|
skuSpecLinkService.saveBatch(skuSpecLinkList);
|
|
|
|
|
|
}
|
|
@@ -185,64 +155,19 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void edit(SkuDto skuDto) {
|
|
|
- Long skuId = skuDto.getId();
|
|
|
-
|
|
|
- List<SkuSpecDto> skuSpecDtoList = skuDto.getSkuSpecDtoList();
|
|
|
-
|
|
|
- List<Long> skuSpecIdList = skuSpecDtoList.stream().map(SkuSpec::getId)
|
|
|
- .filter(ObjectUtil::isNotNull).collect(Collectors.toList());
|
|
|
-
|
|
|
- List<Long> skuSpecLinkIdList = skuSpecDtoList.stream().flatMap(item -> Stream.concat(
|
|
|
- item.getPrincipalMaterialSkuSpecLinkList().stream(),
|
|
|
- item.getExpressPackingSkuSpecLinkList().stream()
|
|
|
- )).map(BaseIdPo::getId).filter(ObjectUtil::isNotNull).collect(Collectors.toList());
|
|
|
|
|
|
- skuSpecService.remove(q -> q
|
|
|
- .eq(SkuSpec::getSkuId, skuId)
|
|
|
- .notIn(ObjectUtil.isNotEmpty(skuSpecIdList), BaseIdPo::getId, skuSpecIdList));
|
|
|
+ Long skuId = skuDto.getId();
|
|
|
+ List<SkuSpecDto> skuSpecDtoList = skuDto.getSkuSpecList();
|
|
|
|
|
|
- skuSpecLinkService.remove(q -> q
|
|
|
- .eq(SkuSpecLink::getSkuId, skuId)
|
|
|
- .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
- .notIn(ObjectUtil.isNotEmpty(skuSpecLinkIdList), BaseIdPo::getId, skuSpecLinkIdList));
|
|
|
+ // 编辑sku
|
|
|
+ updateById(skuDto);
|
|
|
|
|
|
- for (SkuSpecDto skuSpecDto : skuSpecDtoList) {
|
|
|
- skuSpecDto.setId(IdWorker.getId());
|
|
|
- skuSpecDto.setSkuId(skuDto.getId());
|
|
|
- }
|
|
|
+ // 编辑sku规格
|
|
|
+ editSkuSpecList(skuId, skuSpecDtoList);
|
|
|
|
|
|
- List<SkuSpecLink> skuSpecLinkList = skuSpecDtoList.stream().flatMap(item -> {
|
|
|
- List<SkuSpecLink> principalMaterialSkuSpecLinkList = item.getPrincipalMaterialSkuSpecLinkList();
|
|
|
- if (principalMaterialSkuSpecLinkList == null) {
|
|
|
- principalMaterialSkuSpecLinkList = Collections.emptyList();
|
|
|
- } else {
|
|
|
- for (SkuSpecLink skuSpecLink : principalMaterialSkuSpecLinkList) {
|
|
|
- skuSpecLink.setId(IdWorker.getId());
|
|
|
- skuSpecLink.setSkuId(item.getSkuId());
|
|
|
- skuSpecLink.setSkuSpecId(item.getId());
|
|
|
- skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
- skuSpecLink.setType(1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- List<SkuSpecLink> expressPackingSkuSpecLinkList = item.getExpressPackingSkuSpecLinkList();
|
|
|
- if (expressPackingSkuSpecLinkList == null) {
|
|
|
- expressPackingSkuSpecLinkList = Collections.emptyList();
|
|
|
- } else {
|
|
|
- for (SkuSpecLink skuSpecLink : expressPackingSkuSpecLinkList) {
|
|
|
- skuSpecLink.setId(IdWorker.getId());
|
|
|
- skuSpecLink.setSkuId(item.getSkuId());
|
|
|
- skuSpecLink.setSkuSpecId(item.getId());
|
|
|
- skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
- skuSpecLink.setType(2);
|
|
|
- }
|
|
|
- }
|
|
|
- return Stream.concat(principalMaterialSkuSpecLinkList.stream(), expressPackingSkuSpecLinkList.stream());
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ // 编辑sku规格关联快递和包材
|
|
|
+ editSkuSpecLinkList(skuId, skuSpecDtoList);
|
|
|
|
|
|
- this.updateById(skuDto);
|
|
|
- skuSpecService.saveOrUpdateBatch(skuSpecDtoList.stream().map(item -> (SkuSpec) item).collect(Collectors.toList()));
|
|
|
- skuSpecLinkService.saveOrUpdateBatch(skuSpecLinkList);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -253,7 +178,11 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
skuSpecLinkService.remove(q -> q.eq(SkuSpecLink::getSkuId, id));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建sku规格关联
|
|
|
+ */
|
|
|
private List<SkuSpecLinkVo> createSkuSpecLinkVoList(List<SkuSpecLink> skuSpecLinkList, Map<Long, BomSpec> bomSpecMap) {
|
|
|
+
|
|
|
if (ObjectUtil.isEmpty(skuSpecLinkList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
@@ -266,6 +195,79 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
}
|
|
|
return skuSpecLinkVo;
|
|
|
}).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑sku规格
|
|
|
+ */
|
|
|
+ private void editSkuSpecList(Long skuId, List<SkuSpecDto> skuSpecDtoList) {
|
|
|
+
|
|
|
+ List<Long> skuSpecIdList = skuSpecDtoList.stream().map(SkuSpec::getId)
|
|
|
+ .filter(ObjectUtil::isNotNull).collect(Collectors.toList());
|
|
|
+
|
|
|
+ skuSpecService.remove(q -> q
|
|
|
+ .eq(SkuSpec::getSkuId, skuId)
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(skuSpecIdList), BaseIdPo::getId, skuSpecIdList));
|
|
|
+
|
|
|
+ List<SkuSpec> skuSpecList = skuSpecDtoList.stream()
|
|
|
+ .peek(item -> item.setSkuId(skuId))
|
|
|
+ .map(item -> (SkuSpec) item)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ skuSpecService.saveOrUpdateBatch(skuSpecList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑sku规格关联快递和包材
|
|
|
+ */
|
|
|
+ private void editSkuSpecLinkList(Long skuId, List<SkuSpecDto> skuSpecDtoList) {
|
|
|
+
|
|
|
+ List<Long> skuSpecLinkIdList = skuSpecDtoList.stream()
|
|
|
+ .flatMap(item -> Stream.concat(
|
|
|
+ item.getPackagingMaterialList().stream(),
|
|
|
+ item.getExpressPackingList().stream()))
|
|
|
+ .map(BaseIdPo::getId)
|
|
|
+ .filter(ObjectUtil::isNotNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ skuSpecLinkService.remove(q -> q
|
|
|
+ .eq(SkuSpecLink::getSkuId, skuId)
|
|
|
+ .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(skuSpecLinkIdList), BaseIdPo::getId, skuSpecLinkIdList));
|
|
|
+
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = createSkuSpecLink(skuSpecDtoList);
|
|
|
+ skuSpecLinkService.saveOrUpdateBatch(skuSpecLinkList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建sku规格关联快递和包材
|
|
|
+ */
|
|
|
+ private List<SkuSpecLink> createSkuSpecLink(List<SkuSpecDto> skuSpecDtoList) {
|
|
|
+
|
|
|
+ return skuSpecDtoList.stream().flatMap(item -> {
|
|
|
+
|
|
|
+ List<SkuSpecLink> packagingMaterialList = item.getPackagingMaterialList();
|
|
|
+ for (SkuSpecLink skuSpecLink : packagingMaterialList) {
|
|
|
+ skuSpecLink.setSkuId(item.getSkuId());
|
|
|
+ skuSpecLink.setSkuSpecId(item.getId());
|
|
|
+ skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
+ skuSpecLink.setType(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SkuSpecLink> expressPackingList = item.getExpressPackingList();
|
|
|
+ for (SkuSpecLink skuSpecLink : expressPackingList) {
|
|
|
+ skuSpecLink.setSkuId(item.getSkuId());
|
|
|
+ skuSpecLink.setSkuSpecId(item.getId());
|
|
|
+ skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
+ skuSpecLink.setType(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Stream.concat(packagingMaterialList.stream(), expressPackingList.stream());
|
|
|
+
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|