sku库存添加

pull/1/head
sjm 2 years ago
parent 340ec95e4b
commit b87ecf6fd6

@ -27,4 +27,6 @@ public class SkuViewDTO {
private String pic; private String pic;
@ApiModelProperty(value = "售价") @ApiModelProperty(value = "售价")
private BigDecimal price; private BigDecimal price;
@ApiModelProperty(value = "库存数")
private Integer stock;
} }

@ -41,4 +41,8 @@ public class Sku extends BaseAudit {
@Excel(name = "商品销售属性json格式") @Excel(name = "商品销售属性json格式")
private String spData; private String spData;
@ApiModelProperty("库存数")
@Excel(name = "库存数")
private Integer stock;
} }

@ -28,4 +28,6 @@ public class SkuVO extends BaseAudit {
/** 商品销售属性json格式 */ /** 商品销售属性json格式 */
@Excel(name = "商品销售属性json格式") @Excel(name = "商品销售属性json格式")
private String spData; private String spData;
@Excel(name = "库存数")
private Integer stock;
} }

@ -2,7 +2,10 @@ package com.cyl.manager.pms.service;
import java.util.*; import java.util.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.h5.pojo.vo.ProductDetail; import com.cyl.h5.pojo.vo.ProductDetail;
@ -12,6 +15,8 @@ import com.cyl.manager.pms.mapper.BrandMapper;
import com.cyl.manager.pms.mapper.SkuMapper; import com.cyl.manager.pms.mapper.SkuMapper;
import com.cyl.manager.pms.pojo.vo.ProductVO; import com.cyl.manager.pms.pojo.vo.ProductVO;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -28,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author zcc * @author zcc
*/ */
@Service @Service
@Slf4j
public class ProductService { public class ProductService {
@Autowired @Autowired
private ProductMapper productMapper; private ProductMapper productMapper;
@ -123,19 +129,53 @@ public class ProductService {
*/ */
@Transactional @Transactional
public int update(ProductVO productVO) { public int update(ProductVO productVO) {
Product dbProduct = productMapper.selectById(productVO.getId());
List<Long> idList = productVO.getSkuList().stream().filter(it -> it.getId() != null).map(it -> it.getId()).collect(Collectors.toList());
if (dbProduct == null) {
return 0;
}
Long userId = SecurityUtils.getUserId();
Product product = convert.vo2do(productVO); Product product = convert.vo2do(productVO);
List<Sku> skuList = productVO.getSkuList(); List<Sku> skuList = productVO.getSkuList();
product.setUpdateBy(userId);
product.setUpdateTime(LocalDateTime.now());
productMapper.updateById(product); productMapper.updateById(product);
//查找库中所有的sku
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("product_id", product.getId()); map.put("product_id", product.getId());
skuMapper.deleteByMap(map); Map<Long, Sku> skuMap = skuMapper.selectByMap(map).stream().collect(Collectors.toMap(it -> it.getId(), it -> it));
if(skuList!=null){ //针对已有的进行编辑
skuList.forEach(sku -> { List<Sku> updateList = productVO.getSkuList().stream().filter(it -> it.getId() != null).collect(Collectors.toList());
if (!CollectionUtil.isEmpty(updateList)) {
log.info("共有{}个sku需要修改{}productId{}",updateList.size(), JSONUtil.toJsonStr(updateList),productVO.getId());
updateList.forEach(it->{
Sku sku = skuMap.get(it.getId());
sku.setUpdateBy(SecurityUtils.getUserId());
sku.setUpdateTime(LocalDateTime.now());
sku.setPrice(it.getPrice());
sku.setSpData(it.getSpData());
sku.setPic(it.getPic());
sku.setOutSkuId(it.getOutSkuId());
sku.setStock(it.getStock());
skuMapper.updateById(sku);
});
}
//针对没有的进行新增
List<Sku> addList = productVO.getSkuList().stream().filter(it -> it.getId() == null).collect(Collectors.toList());
if (!CollectionUtil.isEmpty(addList)) {
log.info("共有{}个sku需要新增{}productId{}",addList.size(), JSONUtil.toJsonStr(addList),productVO.getId());
addList.forEach(sku -> {
sku.setProductId(product.getId()); sku.setProductId(product.getId());
sku.setCreateTime(LocalDateTime.now()); sku.setCreateTime(LocalDateTime.now());
skuMapper.insert(sku); skuMapper.insert(sku);
}); });
} }
//删除
List<Long> deleteIds = skuMap.keySet().stream().filter(it -> !idList.contains(it)).collect(Collectors.toList());
if (!CollectionUtil.isEmpty(deleteIds)) {
log.info("共有{}个sku需要删除{}productId{}",deleteIds.size(), JSONUtil.toJsonStr(deleteIds),productVO.getId());
skuMapper.deleteBatchIds(deleteIds);
}
return 1; return 1;
} }

@ -16950,6 +16950,8 @@ CREATE TABLE `pms_sku` (
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 399 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'sku信息' ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 399 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'sku信息' ROW_FORMAT = Dynamic;
ALTER TABLE `pms_sku`
ADD COLUMN `stock` int(11) NULL COMMENT '库存' AFTER `pic`;
-- ---------------------------- -- ----------------------------
-- Table structure for pms_sku_snapshot -- Table structure for pms_sku_snapshot
-- ---------------------------- -- ----------------------------

Loading…
Cancel
Save