|
@@ -1,27 +1,34 @@
|
|
|
package com.sd.business.service.sku.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
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.sd.business.entity.artwork.po.ArtworkLibrary;
|
|
|
+import com.sd.business.entity.sku.dto.SkuDto;
|
|
|
import com.sd.business.entity.sku.dto.SkuSelectDto;
|
|
|
+import com.sd.business.entity.sku.dto.SkuSpecDto;
|
|
|
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.sku.vo.SkuVo;
|
|
|
import com.sd.business.mapper.sku.SkuMapper;
|
|
|
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 com.sd.framework.util.sql.Sql;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -38,6 +45,9 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
@Autowired
|
|
|
private SkuSpecService skuSpecService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecLinkService skuSpecLinkService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<SkuVo> getPage(SkuSelectDto dto) {
|
|
|
|
|
@@ -102,22 +112,118 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
.list();
|
|
|
vo.setSkuSpecList(skuSpecList);
|
|
|
|
|
|
+ // 复制包材和快递包材
|
|
|
+ //Sql.create(SkuSpecLinkVo.class)
|
|
|
+ // .selectAll(SkuSpecLink.class)
|
|
|
+ // .selectAs()
|
|
|
+
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public void add(SkuDto dto) {
|
|
|
-// save(dto);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void edit(SkuDto dto) {
|
|
|
-// updateById(dto);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void delete(Long id) {
|
|
|
-// removeById(id);
|
|
|
-// }
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(SkuDto dto) {
|
|
|
+
|
|
|
+ // 保存sku
|
|
|
+ dto.setSource(1);
|
|
|
+ save(dto);
|
|
|
+
|
|
|
+ // 保存sku规格
|
|
|
+ List<SkuSpec> skuSpecList = dto.getSkuSpecList().stream()
|
|
|
+ .peek(item -> item.setSkuId(dto.getId()))
|
|
|
+ .map(item -> (SkuSpec) item)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ skuSpecService.saveBatch(skuSpecList);
|
|
|
+
|
|
|
+ // 保存sku规格关联快递和包材
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = createSkuSpecLink(dto.getSkuSpecList());
|
|
|
+ skuSpecLinkService.saveBatch(skuSpecLinkList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(SkuDto dto) {
|
|
|
+ Long skuId = dto.getId();
|
|
|
+ List<SkuSpecDto> skuSpecDtoList = dto.getSkuSpecList();
|
|
|
+
|
|
|
+ // 编辑sku
|
|
|
+ updateById(dto);
|
|
|
+
|
|
|
+ // 编辑sku规格
|
|
|
+ editSkuSpecList(skuId, skuSpecDtoList);
|
|
|
+
|
|
|
+ // 编辑sku规格关联快递和包材
|
|
|
+ editSkuSpecLinkList(skuId, skuSpecDtoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ removeById(id);
|
|
|
+ skuSpecService.remove(q -> q.eq(SkuSpec::getSkuId, id));
|
|
|
+ skuSpecLinkService.remove(q -> q.eq(SkuSpecLink::getSkuId, id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建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.setType(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SkuSpecLink> expressPackingList = item.getExpressPackingList();
|
|
|
+ for (SkuSpecLink skuSpecLink : expressPackingList) {
|
|
|
+ skuSpecLink.setSkuId(item.getSkuId());
|
|
|
+ skuSpecLink.setSkuSpecId(item.getId());
|
|
|
+ skuSpecLink.setType(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Stream.concat(packagingMaterialList.stream(), expressPackingList.stream());
|
|
|
+ }).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)
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(skuSpecLinkIdList), BaseIdPo::getId, skuSpecLinkIdList));
|
|
|
+
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = createSkuSpecLink(skuSpecDtoList);
|
|
|
+ skuSpecLinkService.saveOrUpdateBatch(skuSpecLinkList);
|
|
|
+ }
|
|
|
|
|
|
}
|