|
@@ -1,14 +1,20 @@
|
|
|
package com.kxs.product.biz.service.impl;
|
|
package com.kxs.product.biz.service.impl;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kxs.product.api.dto.admin.shopGood.DownShelfDTO;
|
|
import com.kxs.product.api.dto.admin.shopGood.DownShelfDTO;
|
|
|
|
|
+import com.kxs.product.api.dto.admin.shopGood.SpecSkuDetailDTO;
|
|
|
|
|
+import com.kxs.product.api.dto.admin.shopGood.SubmitSpecDTO;
|
|
|
import com.kxs.product.api.dto.admin.shopGood.SysShopGoodsAddDTO;
|
|
import com.kxs.product.api.dto.admin.shopGood.SysShopGoodsAddDTO;
|
|
|
import com.kxs.product.api.dto.admin.shopGood.SysShopGoodsPageDTO;
|
|
import com.kxs.product.api.dto.admin.shopGood.SysShopGoodsPageDTO;
|
|
|
|
|
+import com.kxs.product.api.dto.admin.shopGood.UpDownShelfDTO;
|
|
|
import com.kxs.product.api.dto.admin.shopGood.UpShelfDTO;
|
|
import com.kxs.product.api.dto.admin.shopGood.UpShelfDTO;
|
|
|
import com.kxs.product.api.model.KxsShopGoodsPic;
|
|
import com.kxs.product.api.model.KxsShopGoodsPic;
|
|
|
|
|
+import com.kxs.product.api.model.KxsShopGoodsSku;
|
|
|
|
|
+import com.kxs.product.api.model.KxsShopGoodsSpec;
|
|
|
import com.kxs.product.api.vo.admin.shopGoods.SysShopGoodsPageVO;
|
|
import com.kxs.product.api.vo.admin.shopGoods.SysShopGoodsPageVO;
|
|
|
import com.kxs.product.api.vo.kxsapp.shop.ShopGoodsDetailVO;
|
|
import com.kxs.product.api.vo.kxsapp.shop.ShopGoodsDetailVO;
|
|
|
import com.kxs.product.api.vo.kxsapp.shop.ShopGoodsListVO;
|
|
import com.kxs.product.api.vo.kxsapp.shop.ShopGoodsListVO;
|
|
@@ -21,12 +27,20 @@ import com.kxs.product.biz.mapper.KxsShopGoodsPicMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsShopGoodsSkuMapper;
|
|
import com.kxs.product.biz.mapper.KxsShopGoodsSkuMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsShopGoodsSpecMapper;
|
|
import com.kxs.product.biz.mapper.KxsShopGoodsSpecMapper;
|
|
|
import com.kxs.product.biz.service.KxsShopGoodsService;
|
|
import com.kxs.product.biz.service.KxsShopGoodsService;
|
|
|
|
|
+import com.kxs.product.biz.service.KxsShopGoodsSkuService;
|
|
|
|
|
+import com.kxs.product.biz.service.KxsShopGoodsSpecService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.checkerframework.checker.units.qual.K;
|
|
import org.checkerframework.checker.units.qual.K;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 商城商品表(KxsShopGoods)表服务实现类
|
|
* 商城商品表(KxsShopGoods)表服务实现类
|
|
@@ -44,6 +58,10 @@ public class KxsShopGoodsServiceImpl extends ServiceImpl<KxsShopGoodsMapper, Kxs
|
|
|
|
|
|
|
|
private final KxsShopGoodsSpecMapper kxsShopGoodsSpecMapper;
|
|
private final KxsShopGoodsSpecMapper kxsShopGoodsSpecMapper;
|
|
|
|
|
|
|
|
|
|
+ private final KxsShopGoodsSpecService kxsShopGoodsSpecService;
|
|
|
|
|
+
|
|
|
|
|
+ private final KxsShopGoodsSkuService kxsShopGoodsSkuService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public IPage<ShopGoodsListVO> getByPage(Page<ShopGoodsListVO> page, Integer colId) {
|
|
public IPage<ShopGoodsListVO> getByPage(Page<ShopGoodsListVO> page, Integer colId) {
|
|
|
|
|
|
|
@@ -89,6 +107,7 @@ public class KxsShopGoodsServiceImpl extends ServiceImpl<KxsShopGoodsMapper, Kxs
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
@Override
|
|
|
public void shopGoodsAdd(SysShopGoodsAddDTO param) {
|
|
public void shopGoodsAdd(SysShopGoodsAddDTO param) {
|
|
|
KxsShopGoods kxsShopGoods = new KxsShopGoods();
|
|
KxsShopGoods kxsShopGoods = new KxsShopGoods();
|
|
@@ -104,8 +123,8 @@ public class KxsShopGoodsServiceImpl extends ServiceImpl<KxsShopGoodsMapper, Kxs
|
|
|
if(shopGoods != null){
|
|
if(shopGoods != null){
|
|
|
shopGoods.setUpTime(upShelfDTO.getUpTime());
|
|
shopGoods.setUpTime(upShelfDTO.getUpTime());
|
|
|
shopGoods.setStatus(GoodsStatusEnum.UP_SHELF.getType());
|
|
shopGoods.setStatus(GoodsStatusEnum.UP_SHELF.getType());
|
|
|
|
|
+ this.updateById(shopGoods);
|
|
|
}
|
|
}
|
|
|
- this.updateById(shopGoods);
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -116,8 +135,143 @@ public class KxsShopGoodsServiceImpl extends ServiceImpl<KxsShopGoodsMapper, Kxs
|
|
|
if(shopGoods != null){
|
|
if(shopGoods != null){
|
|
|
shopGoods.setDownTime(downShelfDTO.getDownTime());
|
|
shopGoods.setDownTime(downShelfDTO.getDownTime());
|
|
|
shopGoods.setStatus(GoodsStatusEnum.DOWN_SHELF.getType());
|
|
shopGoods.setStatus(GoodsStatusEnum.DOWN_SHELF.getType());
|
|
|
|
|
+ this.updateById(shopGoods);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void upDownShelf(UpDownShelfDTO upDownShelfDTO) {
|
|
|
|
|
+ Integer id = upDownShelfDTO.getId();
|
|
|
|
|
+ KxsShopGoods shopGoods = this.getById(id);
|
|
|
|
|
+ if(shopGoods != null){
|
|
|
|
|
+ shopGoods.setStatus(upDownShelfDTO.getStatus());
|
|
|
|
|
+ this.updateById(shopGoods);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void submitSpec(SubmitSpecDTO param) {
|
|
|
|
|
+ Integer goodsId = param.getGoodsId();
|
|
|
|
|
+ List<KxsShopGoodsSpec> shopGoodsSpecList = param.getShopGoodsSpecList();
|
|
|
|
|
+ List<KxsShopGoodsSku> shopGoodsSkusList = param.getShopGoodsSkusList();
|
|
|
|
|
+ this.batchUpdateOrSaveSku(goodsId,shopGoodsSkusList);
|
|
|
|
|
+ this.batchUpdateOrSaveSpec(goodsId,shopGoodsSpecList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新或修改或删除sku
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param shopGoodsSkusList
|
|
|
|
|
+ */
|
|
|
|
|
+ public void batchUpdateOrSaveSku(Integer goodsId,List<KxsShopGoodsSku> shopGoodsSkusList) {
|
|
|
|
|
+ if(goodsId != null){
|
|
|
|
|
+ List<KxsShopGoodsSku> oldShopGoodsSkuList = kxsShopGoodsSkuService.listByGoodsId(goodsId);
|
|
|
|
|
+ Map<String,KxsShopGoodsSku> oldShopGoodsSkuMap = new HashMap<>();
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(oldShopGoodsSkuList)){
|
|
|
|
|
+ oldShopGoodsSkuMap = oldShopGoodsSkuList.stream().collect(Collectors.toMap(o -> o.getSpecifications(), o -> o, (o1, o2) -> o2));
|
|
|
|
|
+ }
|
|
|
|
|
+ if(CollectionUtils.isEmpty(shopGoodsSkusList)){
|
|
|
|
|
+ shopGoodsSkusList = new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ //新增的集合数据
|
|
|
|
|
+ List<KxsShopGoodsSku> addShopGoodsSkuList = new ArrayList<>();
|
|
|
|
|
+ //修改的集合数据
|
|
|
|
|
+ List<KxsShopGoodsSku> editShopGoodsSkuList = new ArrayList<>();
|
|
|
|
|
+ //将新增和修改的集合筛选出来
|
|
|
|
|
+ for(KxsShopGoodsSku kxsShopGoodsSku:shopGoodsSkusList){
|
|
|
|
|
+ kxsShopGoodsSku.setGoodId(goodsId);
|
|
|
|
|
+ String specifications = kxsShopGoodsSku.getSpecifications();
|
|
|
|
|
+ if(oldShopGoodsSkuMap.containsKey(specifications)){
|
|
|
|
|
+ editShopGoodsSkuList.add(kxsShopGoodsSku);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ addShopGoodsSkuList.add(kxsShopGoodsSku);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, KxsShopGoodsSku> editShopGoodsSkuMap = editShopGoodsSkuList.stream().collect(Collectors.toMap(o -> o.getSpecifications(), o -> o, (o1, o2) -> o2));
|
|
|
|
|
+
|
|
|
|
|
+ //删除数据
|
|
|
|
|
+ for(KxsShopGoodsSku kxsShopGoodsSku:oldShopGoodsSkuList){
|
|
|
|
|
+ //如果前端无对应id则删除
|
|
|
|
|
+ if(!editShopGoodsSkuMap.containsKey(kxsShopGoodsSku.getSpecifications())){
|
|
|
|
|
+ kxsShopGoodsSkuService.removeById(kxsShopGoodsSku.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //新增数据
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(addShopGoodsSkuList)){
|
|
|
|
|
+ for(KxsShopGoodsSku kxsShopGoodsSku:addShopGoodsSkuList){
|
|
|
|
|
+ kxsShopGoodsSku.setId(null);
|
|
|
|
|
+ kxsShopGoodsSkuService.save(kxsShopGoodsSku);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改数据
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(editShopGoodsSkuList)){
|
|
|
|
|
+ for(KxsShopGoodsSku kxsShopGoodsSku:editShopGoodsSkuList){
|
|
|
|
|
+ KxsShopGoodsSku byGoodsIdAndSku = kxsShopGoodsSkuService.getByGoodsIdAndSku(kxsShopGoodsSku.getGoodId(), kxsShopGoodsSku.getSpecifications());
|
|
|
|
|
+ kxsShopGoodsSkuService.updateById(byGoodsIdAndSku);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- this.updateById(shopGoods);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新或修改或删除spec
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param shopGoodsSpecList
|
|
|
|
|
+ */
|
|
|
|
|
+ public void batchUpdateOrSaveSpec(Integer goodsId,List<KxsShopGoodsSpec> shopGoodsSpecList) {
|
|
|
|
|
+ if(goodsId != null){
|
|
|
|
|
+ List<KxsShopGoodsSpec> oldShopGoodsSpecList = kxsShopGoodsSpecService.listByGoodsId(goodsId);
|
|
|
|
|
+ Map<String,KxsShopGoodsSpec> oldShopGoodsSpecMap = new HashMap<>();
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(oldShopGoodsSpecList)){
|
|
|
|
|
+ oldShopGoodsSpecMap = oldShopGoodsSpecList.stream().collect(Collectors.toMap(o -> o.getSpecification(), o -> o, (o1, o2) -> o2));
|
|
|
|
|
+ }
|
|
|
|
|
+ if(CollectionUtils.isEmpty(shopGoodsSpecList)){
|
|
|
|
|
+ shopGoodsSpecList = new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ //新增的集合数据
|
|
|
|
|
+ List<KxsShopGoodsSpec> addShopGoodsSpecList = new ArrayList<>();
|
|
|
|
|
+ //修改的集合数据
|
|
|
|
|
+ List<KxsShopGoodsSpec> editShopGoodsSpecList = new ArrayList<>();
|
|
|
|
|
+ //将新增和修改的集合筛选出来
|
|
|
|
|
+ for(KxsShopGoodsSpec kxsShopGoodsSpec:shopGoodsSpecList){
|
|
|
|
|
+ kxsShopGoodsSpec.setGoodsId(goodsId);
|
|
|
|
|
+ String specifications = kxsShopGoodsSpec.getSpecification();
|
|
|
|
|
+ if(oldShopGoodsSpecMap.containsKey(specifications)){
|
|
|
|
|
+ editShopGoodsSpecList.add(kxsShopGoodsSpec);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ addShopGoodsSpecList.add(kxsShopGoodsSpec);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, KxsShopGoodsSpec> editShopGoodsSpecMap = editShopGoodsSpecList.stream().collect(Collectors.toMap(o -> o.getSpecification(), o -> o, (o1, o2) -> o2));
|
|
|
|
|
+
|
|
|
|
|
+ //删除数据
|
|
|
|
|
+ for(KxsShopGoodsSpec kxsShopGoodsSpec:oldShopGoodsSpecList){
|
|
|
|
|
+ //如果前端无对应id则删除
|
|
|
|
|
+ if(!editShopGoodsSpecMap.containsKey(kxsShopGoodsSpec.getSpecification())){
|
|
|
|
|
+ kxsShopGoodsSpecService.removeById(kxsShopGoodsSpec.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //新增数据
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(addShopGoodsSpecList)){
|
|
|
|
|
+ for(KxsShopGoodsSpec kxsShopGoodsSpec:addShopGoodsSpecList){
|
|
|
|
|
+ kxsShopGoodsSpec.setId(null);
|
|
|
|
|
+ kxsShopGoodsSpecService.save(kxsShopGoodsSpec);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改数据
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(editShopGoodsSpecList)){
|
|
|
|
|
+ for(KxsShopGoodsSpec kxsShopGoodsSpec:editShopGoodsSpecList){
|
|
|
|
|
+ KxsShopGoodsSpec byGoodsIdAndSpec = kxsShopGoodsSpecService.getByGoodsIdAndSpec(kxsShopGoodsSpec.getGoodsId(), kxsShopGoodsSpec.getSpecification());
|
|
|
|
|
+ kxsShopGoodsSpecService.updateById(byGoodsIdAndSpec);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public SpecSkuDetailDTO specDetail(Integer goodsId) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|