|
@@ -2,21 +2,20 @@ 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.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.bom.bo.BomSpecBo;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.entity.sku.dto.*;
|
|
|
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.ReplacePrincipalMaterialVo;
|
|
|
-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.entity.sku.vo.*;
|
|
|
import com.sd.business.mapper.sku.SkuMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.sku.SkuService;
|
|
@@ -27,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
@@ -60,6 +60,17 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
wrapper.like("s", Sku::getName, dto.getName());
|
|
|
wrapper.eq("s", Sku::getType, dto.getType());
|
|
|
wrapper.eq("s", Sku::getBrand, dto.getBrand());
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(dto.getSpecCode()) || StrUtil.isNotBlank(dto.getSpecName())) {
|
|
|
+ List<Long> skuIdList = skuSpecService.listObject(SkuSpec::getSkuId, q -> q
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSpecCode()), SkuSpec::getCode, dto.getSpecCode())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSpecName()), SkuSpec::getName, dto.getSpecName()));
|
|
|
+ if (skuIdList.size() == 0) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ wrapper.in("s", Sku::getId, skuIdList);
|
|
|
+ }
|
|
|
+
|
|
|
Page<SkuVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
List<SkuVo> records = page.getRecords();
|
|
|
if (records.size() == 0) {
|
|
@@ -67,8 +78,11 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
}
|
|
|
|
|
|
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));
|
|
|
+ Map<Long, List<SkuSpec>> skuSpecMap = skuSpecService.mapKGroup(SkuSpec::getSkuId, q -> q
|
|
|
+ .in(SkuSpec::getSkuId, skuIdList)
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSpecCode()), SkuSpec::getCode, dto.getSpecCode())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSpecName()), SkuSpec::getName, dto.getSpecName()));
|
|
|
+
|
|
|
records.forEach(item -> item.setSkuSpecList(skuSpecMap.getOrDefault(item.getId(), Collections.emptyList())));
|
|
|
return page;
|
|
|
}
|
|
@@ -179,13 +193,13 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<ReplacePrincipalMaterialVo> getReplacePrincipalMaterialPage(GetReplacePrincipalMaterialListDto dto) {
|
|
|
+ public Page<ReplacePrincipalMaterialVo> getReplacePrincipalMaterialPage(GetReplaceMaterialListDto dto) {
|
|
|
IWrapper<Object> wrapper = getReplaceWrapper(dto);
|
|
|
return baseMapper.getReplacePrincipalMaterialPage(dto.getPage(), wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void replacePrincipalMaterial(ReplacePrincipalMaterialDto dto) {
|
|
|
+ public void replacePrincipalMaterial(ReplaceMaterialDto dto) {
|
|
|
|
|
|
if (ObjectUtil.isAllEmpty(dto.getSkuCode(), dto.getSkuSpecCode(), dto.getBomSpecCode(),
|
|
|
dto.getWidth(), dto.getHeight(), dto.getLength())) {
|
|
@@ -207,7 +221,188 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
|
|
|
|
|
|
}
|
|
|
|
|
|
- private IWrapper<Object> getReplaceWrapper(GetReplacePrincipalMaterialListDto dto) {
|
|
|
+ @Override
|
|
|
+ public Page<ReplacePackagingMaterialVo> getReplacePackagingMaterialPage(GetReplaceMaterialListDto dto) {
|
|
|
+
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper()
|
|
|
+ .eq("sslt", SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
+ .eq("sslt", SkuSpecLink::getType, 1)
|
|
|
+ .eq("s", Sku::getCode, dto.getSkuCode())
|
|
|
+ .eq("ss", SkuSpec::getCode, dto.getSkuSpecCode())
|
|
|
+ .eq("bs", BomSpec::getCode, dto.getBomSpecCode())
|
|
|
+ .eq("ss", SkuSpec::getLength, dto.getLength())
|
|
|
+ .eq("ss", SkuSpec::getWidth, dto.getWidth())
|
|
|
+ .eq("ss", SkuSpec::getHeight, dto.getHeight());
|
|
|
+
|
|
|
+ Page<ReplacePackagingMaterialVo> page = baseMapper.getReplacePackagingMaterialPage(dto.getPage(), wrapper);
|
|
|
+ List<ReplacePackagingMaterialVo> records = page.getRecords();
|
|
|
+
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> skuSpecIdList = records.stream().map(ReplacePackagingMaterialVo::getSkuSpecId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = skuSpecLinkService.list(q -> q
|
|
|
+ .in(SkuSpecLink::getSkuSpecId, skuSpecIdList)
|
|
|
+ .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
+ .eq(SkuSpecLink::getType, 1));
|
|
|
+
|
|
|
+ Map<Long, List<SkuSpecLink>> map = skuSpecLinkList.stream().collect(Collectors.groupingBy(SkuSpecLink::getSkuSpecId));
|
|
|
+
|
|
|
+ List<Long> bomSpecIdList = skuSpecLinkList.stream().map(SkuSpecLink::getBomSpecId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ for (ReplacePackagingMaterialVo record : records) {
|
|
|
+ Long skuSpecId = record.getSkuSpecId();
|
|
|
+ List<SkuSpecLink> tempSkuSpecLinkList = map.get(skuSpecId);
|
|
|
+ if (ObjectUtil.isEmpty(tempSkuSpecLinkList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SkuSpecLink skuSpecLink : tempSkuSpecLinkList) {
|
|
|
+ Long bomSpecId = skuSpecLink.getBomSpecId();
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(bomSpecId);
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Long classifyId = bomSpecBo.getClassifyId();
|
|
|
+ String bomSpecCode = bomSpecBo.getBomSpecCode();
|
|
|
+
|
|
|
+ if (Objects.equals(classifyId, 1682221201491058690L)) {
|
|
|
+ record.setColouredPaper(record.getColouredPaper() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221249268375554L)) {
|
|
|
+ record.setOppMembrane(record.getOppMembrane() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221303530086402L)) {
|
|
|
+ record.setPeBag(record.getPeBag() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221356147630081L)) {
|
|
|
+ record.setMeshBag(record.getMeshBag() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221409847304194L)) {
|
|
|
+ record.setPaperBox(record.getPaperBox() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221453145104386L)) {
|
|
|
+ record.setBubblePack(record.getBubblePack() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221528948760578L)) {
|
|
|
+ record.setLogisticsPackagingMaterial(record.getLogisticsPackagingMaterial() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221581453058049L)) {
|
|
|
+ record.setOtherPackingMaterial(record.getOtherPackingMaterial() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1697442459841290241L)) {
|
|
|
+ record.setSelfAdhesiveSticker(record.getSelfAdhesiveSticker() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1697442971286331393L)) {
|
|
|
+ record.setDrop(record.getDrop() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221651040755714L)) {
|
|
|
+ record.setSuspenders(record.getSuspenders() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ } else if (Objects.equals(classifyId, 1682221712801882114L)) {
|
|
|
+ record.setAccessory(record.getAccessory() == null ? bomSpecCode : "," + bomSpecCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void replacePackagingMaterial(ReplacePackagingMaterialDto dto) {
|
|
|
+
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper()
|
|
|
+ .eq("sslt", SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
+ .eq("sslt", SkuSpecLink::getType, 1)
|
|
|
+ .eq("s", Sku::getCode, dto.getSkuCode())
|
|
|
+ .eq("ss", SkuSpec::getCode, dto.getSkuSpecCode())
|
|
|
+ .eq("bs", BomSpec::getCode, dto.getBomSpecCode())
|
|
|
+ .eq("ss", SkuSpec::getLength, dto.getLength())
|
|
|
+ .eq("ss", SkuSpec::getWidth, dto.getWidth())
|
|
|
+ .eq("ss", SkuSpec::getHeight, dto.getHeight());
|
|
|
+
|
|
|
+ List<ReplacePackagingMaterialVo> list = baseMapper.getReplacePackagingMaterialList(wrapper);
|
|
|
+
|
|
|
+ if (list.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> skuSpecIdList = list.stream().map(ReplacePackagingMaterialVo::getSkuSpecId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = skuSpecLinkService.list(q -> q
|
|
|
+ .in(SkuSpecLink::getSkuSpecId, skuSpecIdList)
|
|
|
+ .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
|
|
|
+ .eq(SkuSpecLink::getType, 1));
|
|
|
+
|
|
|
+ Map<Long, List<SkuSpecLink>> map = skuSpecLinkList.stream().collect(Collectors.groupingBy(SkuSpecLink::getSkuSpecId));
|
|
|
+
|
|
|
+ Long replaceBomSpecId = dto.getReplaceBomSpecId();
|
|
|
+
|
|
|
+ List<Long> bomSpecIdList = skuSpecLinkList.stream().map(SkuSpecLink::getBomSpecId).collect(Collectors.toList());
|
|
|
+ bomSpecIdList.add(replaceBomSpecId);
|
|
|
+
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ BomSpecBo replaceBomSpecBo = bomSpecBoMap.get(replaceBomSpecId);
|
|
|
+ if (replaceBomSpecBo == null) {
|
|
|
+ throw new ServiceException("没有找到替换包材bom规格");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SkuSpecLink> addOrEditSkuSpecLinkList = new ArrayList<>();
|
|
|
+ List<Long> removeSkuSpecLinkIdList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (ReplacePackagingMaterialVo record : list) {
|
|
|
+ Long skuSpecId = record.getSkuSpecId();
|
|
|
+ List<SkuSpecLink> tempSkuSpecLinkList = map.get(skuSpecId);
|
|
|
+ if (ObjectUtil.isEmpty(tempSkuSpecLinkList)) {
|
|
|
+ SkuSpecLink skuSpecLink = new SkuSpecLink();
|
|
|
+ skuSpecLink.setSkuId(record.getSkuId());
|
|
|
+ skuSpecLink.setSkuSpecId(record.getSkuSpecId());
|
|
|
+ skuSpecLink.setBomSpecId(replaceBomSpecId);
|
|
|
+ skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
+ skuSpecLink.setType(1);
|
|
|
+ skuSpecLink.setQuantity(BigDecimal.ONE);
|
|
|
+ addOrEditSkuSpecLinkList.add(skuSpecLink);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = false;
|
|
|
+ for (SkuSpecLink skuSpecLink : tempSkuSpecLinkList) {
|
|
|
+ Long bomSpecId = skuSpecLink.getBomSpecId();
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(bomSpecId);
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(bomSpecBo.getClassifyId(), replaceBomSpecBo.getClassifyId())) {
|
|
|
+ if (flag) {
|
|
|
+ removeSkuSpecLinkIdList.add(skuSpecLink.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ skuSpecLink.setBomSpecId(replaceBomSpecId);
|
|
|
+ addOrEditSkuSpecLinkList.add(skuSpecLink);
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!flag) {
|
|
|
+ SkuSpecLink skuSpecLink = new SkuSpecLink();
|
|
|
+ skuSpecLink.setSkuId(record.getSkuId());
|
|
|
+ skuSpecLink.setSkuSpecId(record.getSkuSpecId());
|
|
|
+ skuSpecLink.setBomSpecId(replaceBomSpecId);
|
|
|
+ skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
|
|
|
+ skuSpecLink.setType(1);
|
|
|
+ skuSpecLink.setQuantity(BigDecimal.ONE);
|
|
|
+ addOrEditSkuSpecLinkList.add(skuSpecLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (addOrEditSkuSpecLinkList.size() > 0) {
|
|
|
+ skuSpecLinkService.saveOrUpdateBatch(addOrEditSkuSpecLinkList);
|
|
|
+ }
|
|
|
+ if (removeSkuSpecLinkIdList.size() > 0) {
|
|
|
+ skuSpecLinkService.removeBatchByIds(removeSkuSpecLinkIdList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private IWrapper<Object> getReplaceWrapper(GetReplaceMaterialListDto dto) {
|
|
|
return IWrapper.getWrapper()
|
|
|
.eq("s", Sku::getCode, dto.getSkuCode())
|
|
|
.eq("ss", SkuSpec::getCode, dto.getSkuSpecCode())
|