|
|
package com.yoho.ufo.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.ufo.dal.BrandMapper;
|
|
|
import com.yoho.ufo.dal.GoodsImagesMapper;
|
|
|
import com.yoho.ufo.dal.GoodsMapper;
|
|
|
import com.yoho.ufo.dal.ProductMapper;
|
|
|
import com.yoho.ufo.dal.ProductSortMapper;
|
|
|
import com.yoho.ufo.dal.StorageMapper;
|
|
|
import com.yoho.ufo.dal.StoragePriceMapper;
|
|
|
import com.yoho.ufo.dal.UfoSizeMapper;
|
|
|
import com.yoho.ufo.dal.model.Goods;
|
|
|
import com.yoho.ufo.dal.model.GoodsImages;
|
|
|
import com.yoho.ufo.dal.model.Product;
|
|
|
import com.yoho.ufo.dal.model.Storage;
|
|
|
import com.yoho.ufo.dal.model.StoragePrice;
|
|
|
import com.yoho.ufo.exception.CommonException;
|
|
|
import com.yoho.ufo.model.brand.Brand;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.size.Size;
|
|
|
import com.yoho.ufo.service.IProductService;
|
|
|
import com.yoho.ufo.util.CollectionUtil;
|
|
|
import com.yohobuy.ufo.model.common.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.common.PageResponseBO;
|
|
|
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
|
|
|
import com.yohobuy.ufo.model.resp.product.ProductEditResponceBo;
|
|
|
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
|
|
|
|
|
|
@Service
|
|
|
public class ProductServiceImpl implements IProductService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProductServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ProductSortMapper productSortMapper;
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
@Autowired
|
|
|
private BrandMapper brandMapper;
|
|
|
@Autowired
|
|
|
private GoodsMapper goodsMapper;
|
|
|
@Autowired
|
|
|
private GoodsImagesMapper goodsImagesMapper;
|
|
|
@Autowired
|
|
|
private StorageMapper storageMapper;
|
|
|
@Autowired
|
|
|
private StoragePriceMapper storagePriceMapper;
|
|
|
@Autowired
|
|
|
private UfoSizeMapper sizeMapper;
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse<Void> addOrUpdate(ProductRequestBo bo) {
|
|
|
checkProductInfo(bo);
|
|
|
Product product = getProductFromBo(bo);
|
|
|
Goods goods = getGoodsFromBo(bo);
|
|
|
List<Storage> storageList = getStoragesFromBo(bo);
|
|
|
List<GoodsImages> goodsImagesList = getGoodsImagesFromBo(bo);
|
|
|
Integer productId;
|
|
|
Integer goodsId;
|
|
|
// 新增
|
|
|
if (bo.getId() == null || bo.getId() < 1) {
|
|
|
if (productMapper.insert(product) == 0) {
|
|
|
return new ApiResponse<Void>(500, "创建商品失败");
|
|
|
}
|
|
|
productId = product.getId();
|
|
|
goods.setProductId(productId);
|
|
|
goodsMapper.insert(goods);
|
|
|
if (goodsMapper.insert(goods) == 0) {
|
|
|
return new ApiResponse<Void>(500, "创建商品颜色失败");
|
|
|
}
|
|
|
goodsId = goods.getId();
|
|
|
} else {
|
|
|
productMapper.updateByPrimaryKey(product);
|
|
|
productId = product.getId();
|
|
|
goodsId = goods.getId();
|
|
|
goods.setProductId(productId);
|
|
|
goodsMapper.updateByPrimaryKey(goods);
|
|
|
if (bo.getEditImage() != null && bo.getEditImage() == 1) {
|
|
|
goodsImagesMapper.deleteByGoodsId(goodsId);
|
|
|
}
|
|
|
}
|
|
|
for (Storage s : storageList) {
|
|
|
s.setProductId(productId);
|
|
|
s.setGoodsId(goodsId);
|
|
|
storageMapper.insert(s);
|
|
|
}
|
|
|
if (bo.getEditImage() != null && bo.getEditImage() == 1) {
|
|
|
for (GoodsImages gi : goodsImagesList) {
|
|
|
gi.setProductId(productId);
|
|
|
gi.setGoodsId(goodsId);
|
|
|
goodsImagesMapper.insert(gi);
|
|
|
}
|
|
|
}
|
|
|
return new ApiResponse<Void>(null);
|
|
|
}
|
|
|
|
|
|
private List<GoodsImages> getGoodsImagesFromBo(ProductRequestBo bo) {
|
|
|
List<GoodsImages> goodsImagesList = new ArrayList<>();
|
|
|
for (int i = 0; i < bo.getImageUrlList().size(); i++) {
|
|
|
String image = bo.getImageUrlList().get(i);
|
|
|
GoodsImages gi = new GoodsImages();
|
|
|
if (i == 0) {
|
|
|
gi.setIsDefault("Y");
|
|
|
} else {
|
|
|
gi.setIsDefault("N");
|
|
|
}
|
|
|
gi.setImageUrl(image);
|
|
|
gi.setOrderBy(i + 1);
|
|
|
goodsImagesList.add(gi);
|
|
|
}
|
|
|
return goodsImagesList;
|
|
|
}
|
|
|
|
|
|
private List<Storage> getStoragesFromBo(ProductRequestBo bo) {
|
|
|
List<Storage> storageList = new ArrayList<>();
|
|
|
for(Integer id : bo.getSizeIdList()) {
|
|
|
Storage s = new Storage();
|
|
|
s.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
s.setSizeId(id);
|
|
|
s.setStorageNum(0);
|
|
|
storageList.add(s);
|
|
|
}
|
|
|
return storageList;
|
|
|
}
|
|
|
|
|
|
private Goods getGoodsFromBo(ProductRequestBo bo) {
|
|
|
Goods g = new Goods();
|
|
|
BeanUtils.copyProperties(bo, g);
|
|
|
g.setIsDefault("Y");
|
|
|
if (CollectionUtils.isNotEmpty(bo.getImageUrlList())) {
|
|
|
g.setColorImage(bo.getImageUrlList().get(0));
|
|
|
}
|
|
|
return g;
|
|
|
}
|
|
|
|
|
|
private Product getProductFromBo(ProductRequestBo bo) {
|
|
|
Product p = new Product();
|
|
|
BeanUtils.copyProperties(bo, p);
|
|
|
p.setShelveStatus(0);
|
|
|
p.setDelStatus(0);
|
|
|
p.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
p.setMinPrice(new BigDecimal(bo.getMinPrice()));
|
|
|
p.setMaxPrice(new BigDecimal(bo.getMaxPrice()));
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
try {
|
|
|
p.setSaleTime((int) (sdf.parse(bo.getSaleTime()).getTime() / 1000));
|
|
|
} catch (ParseException e) {
|
|
|
}
|
|
|
p.setGender(bo.getGender().toString());
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
private void checkProductInfo(ProductRequestBo bo) {
|
|
|
if (bo.getBrandId() == null || bo.getBrandId() < 1) {
|
|
|
throw new CommonException(400, "请选择品牌");
|
|
|
}
|
|
|
if (bo.getSeriesId() == null || bo.getSeriesId() < 1) {
|
|
|
throw new CommonException(400, "请选择系列");
|
|
|
}
|
|
|
if (StringUtils.isBlank(bo.getProductName())) {
|
|
|
throw new CommonException(400, "请输入商品名称");
|
|
|
}
|
|
|
if (StringUtils.isBlank(bo.getSaleTime())) {
|
|
|
throw new CommonException(400, "请选择发售日期");
|
|
|
}
|
|
|
if (bo.getGender() == null || bo.getGender() < 1 || bo.getGender() > 3) {
|
|
|
throw new CommonException(400, "请选择性别");
|
|
|
}
|
|
|
if (bo.getMaxSortId() == null || bo.getMaxSortId() < 1) {
|
|
|
throw new CommonException(400, "请选择大分类");
|
|
|
}
|
|
|
if (bo.getMidSortId() == null || bo.getMidSortId() < 1) {
|
|
|
throw new CommonException(400, "请选择中分类");
|
|
|
}
|
|
|
if (StringUtils.isBlank(bo.getProductCode())) {
|
|
|
throw new CommonException(400, "请输入货号");
|
|
|
}
|
|
|
BigDecimal min, max;
|
|
|
if (StringUtils.isBlank(bo.getMinPrice())) {
|
|
|
throw new CommonException(400, "请输入价格限制最低");
|
|
|
}
|
|
|
if (StringUtils.isBlank(bo.getMaxPrice())) {
|
|
|
throw new CommonException(400, "请输入价格限制最高");
|
|
|
}
|
|
|
try {
|
|
|
min = new BigDecimal(bo.getMinPrice());
|
|
|
} catch (Exception e) {
|
|
|
throw new CommonException(400, "价格限制最低输入有误");
|
|
|
}
|
|
|
try {
|
|
|
max = new BigDecimal(bo.getMaxPrice());
|
|
|
} catch (Exception e) {
|
|
|
throw new CommonException(400, "价格限制最高输入有误");
|
|
|
}
|
|
|
if (min.compareTo(max) > 0) {
|
|
|
throw new CommonException(400, "价格限制最低>最高");
|
|
|
}
|
|
|
|
|
|
if (bo.getColorId() == null || bo.getColorId() < 1) {
|
|
|
throw new CommonException(400, "请选择颜色");
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(bo.getSizeIdList())) {
|
|
|
throw new CommonException(400, "请选择至少选择一个尺寸");
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(bo.getImageUrlList())) {
|
|
|
throw new CommonException(400, "请上传至少一张图片");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse<ProductEditResponceBo> findProductDetailById(Integer id) {
|
|
|
Product product = productMapper.selectByPrimaryKey(id);
|
|
|
if (product == null) {
|
|
|
throw new CommonException(400, "商品不存在");
|
|
|
}
|
|
|
List<Goods> goodsList = goodsMapper.selectByProductId(Arrays.asList(id));
|
|
|
Goods goods = null;
|
|
|
List<GoodsImages> goodsImages = null;
|
|
|
List<Storage> storages = null;
|
|
|
if (CollectionUtils.isNotEmpty(goodsList)) {
|
|
|
goods = goodsList.get(0);
|
|
|
goodsImages = goodsImagesMapper.selectByGoodsId(goods.getId());
|
|
|
storages = storageMapper.selectByGoodsId(goods.getId());
|
|
|
}
|
|
|
return mergeProductEditResponceBo(product, goods, goodsImages, storages);
|
|
|
}
|
|
|
|
|
|
private ApiResponse<ProductEditResponceBo> mergeProductEditResponceBo(Product product, Goods goods,
|
|
|
List<GoodsImages> goodsImages, List<Storage> storages) {
|
|
|
ProductEditResponceBo bo = new ProductEditResponceBo();
|
|
|
BeanUtils.copyProperties(product, bo);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
bo.setSaleTime(sdf.format(product.getSaleTime() * 1000L));
|
|
|
bo.setGender(new Integer(product.getGender()));
|
|
|
bo.setMinPrice(product.getMinPrice().toString());
|
|
|
bo.setMaxPrice(product.getMaxPrice().toString());
|
|
|
if (goods != null) {
|
|
|
bo.setGoodsName(goods.getGoodsName());
|
|
|
bo.setGoodsId(goods.getId());
|
|
|
bo.setColorId(goods.getColorId());
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(goodsImages)) {
|
|
|
bo.setImageUrlList(CollectionUtil.map(goodsImages, GoodsImages::getImageUrl));
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(storages)) {
|
|
|
bo.setStorageIdList(CollectionUtil.map(storages, Storage::getId));
|
|
|
bo.setSizeIdList(CollectionUtil.map(storages, Storage::getSizeId));
|
|
|
}
|
|
|
return new ApiResponse<ProductEditResponceBo>(bo);
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
ProductEditResponceBo bo = new ProductEditResponceBo();
|
|
|
Product product = new Product();product.setGender("1");product.setMaxPrice(new BigDecimal("99"));
|
|
|
product.setId(99);
|
|
|
BeanUtils.copyProperties(product, bo);
|
|
|
System.out.println(JSON.toJSONString(bo));
|
|
|
}
|
|
|
@Override
|
|
|
public ApiResponse<PageResponseBO<ProductResponceBo>> list(ProductRequestBo bo) {
|
|
|
int count = productMapper.selectCount(bo.getProductCode(),
|
|
|
bo.getProductName(),
|
|
|
bo.getMaxSortId(),
|
|
|
bo.getMidSortId(),
|
|
|
bo.getBrandId(),
|
|
|
bo.getShelveStatus());
|
|
|
List<ProductResponceBo> boList = new ArrayList<>();
|
|
|
if (count > 0) {
|
|
|
List<Product> productList = productMapper.selectPage(bo.getProductCode(),
|
|
|
bo.getProductName(),
|
|
|
bo.getMaxSortId(),
|
|
|
bo.getMidSortId(),
|
|
|
bo.getBrandId(),
|
|
|
bo.getShelveStatus(),
|
|
|
bo.getStart(),
|
|
|
bo.getRows());
|
|
|
productList.forEach(p -> {
|
|
|
ProductResponceBo b = new ProductResponceBo();
|
|
|
BeanUtils.copyProperties(p, b);
|
|
|
boList.add(b);
|
|
|
});
|
|
|
List<Integer> productIdList = CollectionUtil.distinct(productList, Product::getId);
|
|
|
List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
|
|
|
Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
|
|
|
List<Brand> brandList = brandMapper.selectBrandByIdList(CollectionUtil.distinct(productList, Product::getBrandId));
|
|
|
Map<Integer, Brand> brandMap = CollectionUtil.extractMap(brandList, Brand::getId);
|
|
|
List<Integer> sortIdList = CollectionUtil.distinct(productList, Product::getMaxSortId);
|
|
|
sortIdList.addAll(CollectionUtil.distinct(productList, Product::getMidSortId));
|
|
|
List<ProductSort> productSortList = productSortMapper.selectSortByIdList(sortIdList);
|
|
|
Map<Integer, ProductSort> productSortMap = CollectionUtil.extractMap(productSortList, ProductSort::getId);
|
|
|
boList.forEach(respBo -> {
|
|
|
// 图片
|
|
|
Goods goods = goodsMap.get(respBo.getId());
|
|
|
if (goods != null) {
|
|
|
respBo.setColorImage(goods.getColorImage());
|
|
|
}
|
|
|
// 分类
|
|
|
ProductSort maxSort = productSortMap.get(respBo.getMaxSortId());
|
|
|
ProductSort midSort = productSortMap.get(respBo.getMidSortId());
|
|
|
String sort = "";
|
|
|
if (maxSort != null) {
|
|
|
sort += maxSort.getSortName();
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(sort)) {
|
|
|
sort += "/";
|
|
|
}
|
|
|
if (midSort != null) {
|
|
|
sort += midSort.getSortName();
|
|
|
}
|
|
|
respBo.setSortName(sort);
|
|
|
// 品牌
|
|
|
Brand brand = brandMap.get(respBo.getBrandId());
|
|
|
if (brand != null) {
|
|
|
respBo.setBrandName(brand.getBrandName());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
PageResponseBO<ProductResponceBo> pageBo = new PageResponseBO<>(count, boList, bo.getPage(), bo.getRows());
|
|
|
return new ApiResponse<>(pageBo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse<PageResponseBO<ProductResponceBo>> getSkuList(ProductRequestBo bo) {
|
|
|
if ((bo.getHasStock() != null && bo.getHasStock() >= 0)
|
|
|
|| (bo.getStorageId() != null && bo.getStorageId() > 0)) {
|
|
|
bo.setSkuCondition(1);
|
|
|
} else {
|
|
|
bo.setSkuCondition(0);
|
|
|
}
|
|
|
if ((bo.getSkup() != null && bo.getSkup() > 0)
|
|
|
|| (bo.getSellerUid() != null && bo.getSellerUid() > 0)) {
|
|
|
bo.setSkupCondition(1);
|
|
|
} else {
|
|
|
bo.setSkupCondition(0);
|
|
|
}
|
|
|
int count = productMapper.selectSkuCount(bo.getProductCode(),
|
|
|
bo.getProductName(),
|
|
|
bo.getMaxSortId(),
|
|
|
bo.getMidSortId(),
|
|
|
bo.getBrandId(),
|
|
|
bo.getShelveStatus(),
|
|
|
bo.getSkuCondition(),
|
|
|
bo.getSkupCondition(),
|
|
|
bo.getStorageId(),
|
|
|
bo.getSellerUid(),
|
|
|
bo.getHasStock(),
|
|
|
bo.getSkup());
|
|
|
List<ProductResponceBo> boList = new ArrayList<>();
|
|
|
if (count > 0) {
|
|
|
List<Product> productList = productMapper.selectSkuPage(bo.getProductCode(),
|
|
|
bo.getProductName(),
|
|
|
bo.getMaxSortId(),
|
|
|
bo.getMidSortId(),
|
|
|
bo.getBrandId(),
|
|
|
bo.getShelveStatus(),
|
|
|
bo.getSkuCondition(),
|
|
|
bo.getSkupCondition(),
|
|
|
bo.getStorageId(),
|
|
|
bo.getSellerUid(),
|
|
|
bo.getHasStock(),
|
|
|
bo.getSkup(),
|
|
|
bo.getStart(),
|
|
|
bo.getRows());
|
|
|
productList.forEach(p -> {
|
|
|
ProductResponceBo b = new ProductResponceBo();
|
|
|
BeanUtils.copyProperties(p, b);
|
|
|
boList.add(b);
|
|
|
});
|
|
|
List<Integer> productIdList = CollectionUtil.distinct(productList, Product::getId);
|
|
|
List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
|
|
|
Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
|
|
|
List<Brand> brandList = brandMapper.selectBrandByIdList(CollectionUtil.distinct(productList, Product::getBrandId));
|
|
|
Map<Integer, Brand> brandMap = CollectionUtil.extractMap(brandList, Brand::getId);
|
|
|
List<Storage> storageList = storageMapper.selectByGoodsIdList(CollectionUtil.distinct(goodsList, Goods::getId));
|
|
|
Map<Integer, List<Storage>> storageMap = CollectionUtil.groupingBy(storageList, Storage::getGoodsId);
|
|
|
List<StoragePrice> storagePriceList = storagePriceMapper.selectMinPriceByProductIdList(productIdList);
|
|
|
Map<Integer, StoragePrice> storagePriceMap = CollectionUtil.extractMap(storagePriceList, StoragePrice::getProductId);
|
|
|
List<Size> sizeList = sizeMapper.selectByIdList(CollectionUtil.distinct(storageList, Storage::getSizeId));
|
|
|
Map<Integer, Size> sizeMap = CollectionUtil.extractMap(sizeList, Size::getId);
|
|
|
for(ProductResponceBo respBo : boList) {
|
|
|
Integer productId = respBo.getId();
|
|
|
// 品牌
|
|
|
Brand brand = brandMap.get(respBo.getBrandId());
|
|
|
if (brand != null) {
|
|
|
respBo.setBrandName(brand.getBrandName());
|
|
|
}
|
|
|
// 最低价
|
|
|
StoragePrice sp = storagePriceMap.get(productId);
|
|
|
if (sp != null) {
|
|
|
respBo.setCurrentPrice(sp.getPrice().toString());
|
|
|
}
|
|
|
// 可售库存
|
|
|
Goods goods = goodsMap.get(productId);
|
|
|
if(goods==null) {
|
|
|
continue;
|
|
|
}
|
|
|
List<Storage> aStorageList = storageMap.get(goods.getId());
|
|
|
int countStock = 0;
|
|
|
for(Storage s : aStorageList) {
|
|
|
countStock += s.getStorageNum();
|
|
|
}
|
|
|
respBo.setStorage(countStock);
|
|
|
List<ProductResponceBo> skuList = new ArrayList<>();
|
|
|
respBo.setSkuList(skuList);
|
|
|
//respBo
|
|
|
for(Storage s : aStorageList) {
|
|
|
ProductResponceBo skuBo = new ProductResponceBo();
|
|
|
skuBo.setId(s.getId());
|
|
|
skuBo.setGoodsName(goods.getGoodsName());
|
|
|
// 尺码
|
|
|
Size size = sizeMap.get(s.getSizeId());
|
|
|
if (size != null) {
|
|
|
skuBo.setSizeName(size.getSizeName());
|
|
|
}
|
|
|
skuBo.setStorage(s.getStorageNum());
|
|
|
skuList.add(skuBo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
PageResponseBO<ProductResponceBo> pageBo = new PageResponseBO<>(count, boList, bo.getPage(), bo.getRows());
|
|
|
return new ApiResponse<>(pageBo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse<PageResponseBO<ProductResponceBo>> getSkupDetailList(ProductRequestBo bo) {
|
|
|
int count = storagePriceMapper.selectCount(
|
|
|
bo.getSellerUid(),
|
|
|
bo.getStatus(),
|
|
|
bo.getSkup(),
|
|
|
bo.getStorageId());
|
|
|
List<ProductResponceBo> boList = new ArrayList<>();
|
|
|
if (count > 0) {
|
|
|
List<StoragePrice> storagePrice = storagePriceMapper.selectPage(
|
|
|
bo.getSellerUid(),
|
|
|
bo.getStatus(),
|
|
|
bo.getSkup(),
|
|
|
bo.getStorageId(),
|
|
|
bo.getStart(),
|
|
|
bo.getRows());
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
storagePrice.forEach(sp -> {
|
|
|
ProductResponceBo b = new ProductResponceBo();
|
|
|
b.setSkup(sp.getSkup());
|
|
|
b.setSellerUid(sp.getSellerUid());
|
|
|
b.setCurrentPrice(sp.getPrice().toString());
|
|
|
b.setStatus(sp.getStatus());
|
|
|
b.setSkupCreateTime(sdf.format(sp.getCreateTime() * 1000L));
|
|
|
boList.add(b);
|
|
|
});
|
|
|
}
|
|
|
PageResponseBO<ProductResponceBo> pageBo = new PageResponseBO<>(count, boList, bo.getPage(), bo.getRows());
|
|
|
return new ApiResponse<>(pageBo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse<PageResponseBO<ProductResponceBo>> cancelSaleSkup(ProductRequestBo bo) {
|
|
|
StoragePrice sp = storagePriceMapper.selectBySkup(bo.getSkup());
|
|
|
if (sp == null) {
|
|
|
return new ApiResponse<>(400, "SKUP不存在");
|
|
|
}
|
|
|
if (sp.getStatus() == null || sp.getStatus() != 1) {
|
|
|
return new ApiResponse<>(400, "SKUP不可取消");
|
|
|
}
|
|
|
int n = storagePriceMapper.cancelSaleSkup(bo.getSkup());
|
|
|
if (n == 1) {
|
|
|
storageMapper.addStorageNum(sp.getStorageId(), -1);
|
|
|
return new ApiResponse<>(400, "操作成功");
|
|
|
}
|
|
|
return new ApiResponse<>(400, "SKUP取消失败,状态已变更!");
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|