|
@@ -2,6 +2,7 @@ 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;
|
|
@@ -10,6 +11,7 @@ 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.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;
|
|
@@ -24,12 +26,11 @@ 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 org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
@@ -96,11 +97,11 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
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 = new HashMap<>();
|
|
|
+ if (bomSpecIdList.size() > 0) {
|
|
|
+ bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIdList));
|
|
|
}
|
|
|
|
|
|
- Map<Long, BomSpec> bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIdList));
|
|
|
for (SkuSpecVo item : skuSpecList) {
|
|
|
|
|
|
|
|
@@ -133,19 +134,123 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(SkuDto skuDto) {
|
|
|
- this.save(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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+ save(skuDto);
|
|
|
+ skuSpecService.saveBatch(skuSpecDtoList.stream().map(item -> (SkuSpec) item).collect(Collectors.toList()));
|
|
|
+ skuSpecLinkService.saveBatch(skuSpecLinkList);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ @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));
|
|
|
+
|
|
|
+ skuSpecLinkService.remove(q -> q
|
|
|
+ .eq(SkuSpecLink::getSkuId, skuId)
|
|
|
+ .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(skuSpecLinkIdList), BaseIdPo::getId, skuSpecLinkIdList));
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
this.updateById(skuDto);
|
|
|
+ skuSpecService.saveOrUpdateBatch(skuSpecDtoList.stream().map(item -> (SkuSpec) item).collect(Collectors.toList()));
|
|
|
+ skuSpecLinkService.saveOrUpdateBatch(skuSpecLinkList);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
- this.removeById(id);
|
|
|
+ removeById(id);
|
|
|
+ skuSpecService.remove(q -> q.eq(SkuSpec::getSkuId, id));
|
|
|
+ skuSpecLinkService.remove(q -> q.eq(SkuSpecLink::getSkuId, id));
|
|
|
}
|
|
|
|
|
|
private List<SkuSpecLinkVo> createSkuSpecLinkVoList(List<SkuSpecLink> skuSpecLinkList, Map<Long, BomSpec> bomSpecMap) {
|