|
|
package com.yohoufo.product.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.BinaryOperator;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.yoho.core.common.helpers.ImagesHelper;
|
|
|
import com.yohoufo.common.utils.UfoStringUtils;
|
|
|
import com.yohoufo.dal.product.*;
|
|
|
import com.yohoufo.dal.product.model.*;
|
|
|
import com.yohoufo.product.model.*;
|
|
|
import com.yohoufo.product.response.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.yoho.core.common.helpers.ImagesHelper;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.common.utils.UfoStringUtils;
|
|
|
import com.yohoufo.dal.product.BrandMapper;
|
|
|
import com.yohoufo.dal.product.BrandSeriesMapper;
|
|
|
import com.yohoufo.dal.product.GoodsImagesMapper;
|
|
|
import com.yohoufo.dal.product.GoodsMapper;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
|
|
import com.yohoufo.dal.product.SizeMapper;
|
|
|
import com.yohoufo.dal.product.StorageMapper;
|
|
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
|
|
import com.yohoufo.dal.product.model.Brand;
|
|
|
import com.yohoufo.dal.product.model.BrandSeries;
|
|
|
import com.yohoufo.dal.product.model.Goods;
|
|
|
import com.yohoufo.dal.product.model.GoodsImages;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.dal.product.model.Size;
|
|
|
import com.yohoufo.dal.product.model.Storage;
|
|
|
import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
import com.yohoufo.product.model.GoodsBO;
|
|
|
import com.yohoufo.product.model.GoodsImageBO;
|
|
|
import com.yohoufo.product.model.GoodsSize;
|
|
|
import com.yohoufo.product.model.ProductInfo;
|
|
|
import com.yohoufo.product.model.ProductSeriesTemplate;
|
|
|
import com.yohoufo.product.model.ProductSortTemplate;
|
|
|
import com.yohoufo.product.request.StoragePriceBo;
|
|
|
import com.yohoufo.product.response.ProductDetailResp;
|
|
|
import com.yohoufo.product.response.ProductSeriesTemplateResp;
|
|
|
import com.yohoufo.product.response.ProductSortTemplateResp;
|
|
|
import com.yohoufo.product.response.StorageDataResp;
|
|
|
import com.yohoufo.product.response.StorageLeastPriceResp;
|
|
|
import com.yohoufo.product.service.ProductService;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -199,13 +227,57 @@ public class ProductServiceImpl implements ProductService{ |
|
|
@Override
|
|
|
public void createSkup(StoragePriceBo skupBo) {
|
|
|
storagePriceMapper.insert(exchangeCreateSkupBo(skupBo));
|
|
|
addStorageNum(skupBo.getSkup(), skupBo.getStorageId(), 1);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void sellerUpdateStatus(StoragePriceBo skupBo) {
|
|
|
// 卖家修改状态:*1:可售(支付保证金),2:取消支付保证金,3:超时未支付保证金,4:支付保证金后取消售卖
|
|
|
if (skupBo == null) {
|
|
|
throw new ServiceException(400, "skupBo为空!");
|
|
|
}
|
|
|
|
|
|
Integer skup = skupBo.getSkup();
|
|
|
if (skup == null || skup < 1) {
|
|
|
throw new ServiceException(400, "skup错误:" + skup);
|
|
|
}
|
|
|
|
|
|
int status;
|
|
|
if (skupBo.getStatus() == null || (status = skupBo.getStatus()) < 1 || status > 4) {
|
|
|
throw new ServiceException(400, "商品(status)错误:" + skupBo.getStatus());
|
|
|
}
|
|
|
|
|
|
StoragePrice sp = storagePriceMapper.selectBySkup(skup);
|
|
|
if (sp == null) {
|
|
|
throw new ServiceException(400, "商品(skup)不存在:" + skup);
|
|
|
}
|
|
|
|
|
|
int expectedStatus = (status == 4) ? 1 : 0;
|
|
|
if (sp.getStatus() == null || sp.getStatus() != expectedStatus) {
|
|
|
throw new ServiceException(400, "商品(skup)状态已变更:" + sp.getStatus());
|
|
|
}
|
|
|
|
|
|
// 使其可售
|
|
|
if (status == 1) {
|
|
|
if (storagePriceMapper.updateStatus(skup, 1, 0) == 0) {
|
|
|
throw new ServiceException(400, "商品(skup)状态已变更");
|
|
|
}
|
|
|
addStorageNum(skup, sp.getStorageId(), 1);
|
|
|
} else if (status == 2 || status == 3) {
|
|
|
if (storagePriceMapper.updateStatus(skup, status, 0) == 0) {
|
|
|
throw new ServiceException(400, "商品(skup)状态已变更");
|
|
|
}
|
|
|
} else {
|
|
|
if (storagePriceMapper.updateStatus(skup, status, 1) == 0) {
|
|
|
throw new ServiceException(400, "商品(skup)状态已变更");
|
|
|
}
|
|
|
addStorageNum(skup, sp.getStorageId(), -1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void saleSkup(Integer productId, Integer skup) {
|
|
|
checkParamValid(productId, skup);
|
|
|
checkProductCanSale(productId);
|
|
|
checkProductStatus(productId);
|
|
|
StoragePrice sp = checkSkupCanSale(skup);
|
|
|
if (!doSaleSkup(skup)) {
|
|
|
throw new ServiceException(400, "商品(skup)已卖出:" + skup);
|
...
|
...
|
@@ -214,32 +286,53 @@ public class ProductServiceImpl implements ProductService{ |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void cancelSaleSkup(Integer skup) {
|
|
|
StoragePrice sp = checkSkupCanCancel(skup);
|
|
|
if (!doCancelSaleSkup(skup)) {
|
|
|
public void cancelSaleSkup(Integer skup, Integer status) {
|
|
|
StoragePrice sp = checkSkupCanCancel(skup, status);
|
|
|
if (!doCancelSaleSkup(skup, status)) {
|
|
|
throw new ServiceException(400, "商品(skup)取消售卖失败:" + skup);
|
|
|
}
|
|
|
addStorageNum(skup, sp.getStorageId(), 1);
|
|
|
}
|
|
|
|
|
|
private StoragePrice checkSkupCanCancel(Integer skup) {
|
|
|
@Override
|
|
|
public void setDepotNum(Integer skup, Integer depotNum) {
|
|
|
LOGGER.info("setDepotNum skup = {}", skup);
|
|
|
StoragePrice sp = storagePriceMapper.selectBySkup(skup);
|
|
|
if (sp == null) {
|
|
|
throw new ServiceException(400, "商品(skup)不存在:" + skup);
|
|
|
}
|
|
|
if (sp.getStatus() == null || sp.getStatus() != 100) {
|
|
|
throw new ServiceException(400, "商品(skup)没有卖出:" + skup);
|
|
|
}
|
|
|
if (depotNum == null || depotNum < 1 || depotNum > 2) {
|
|
|
throw new ServiceException(400, "鉴定中心id错误:" + depotNum);
|
|
|
}
|
|
|
if (storagePriceMapper.updateDepotNum(skup, depotNum) != 1) {
|
|
|
throw new ServiceException(400, "商品(skup)没有卖出:" + skup);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private StoragePrice checkSkupCanCancel(Integer skup, Integer status) {
|
|
|
LOGGER.info("checkSkupCanCancel skup = {}", skup);
|
|
|
if (status == null || status < 101 || status > 103) {
|
|
|
throw new ServiceException(400, "status状态错误:" + skup);
|
|
|
}
|
|
|
StoragePrice sp = storagePriceMapper.selectBySkup(skup);
|
|
|
if (sp == null) {
|
|
|
throw new ServiceException(400, "商品(skup)不存在:" + skup);
|
|
|
}
|
|
|
if (sp.getStatus() == null || sp.getStatus() != 2) {
|
|
|
if (sp.getStatus() == null || sp.getStatus() != 100) {
|
|
|
throw new ServiceException(400, "商品(skup)没有卖出:" + skup);
|
|
|
}
|
|
|
return sp;
|
|
|
}
|
|
|
|
|
|
private boolean doCancelSaleSkup(Integer skup) {
|
|
|
return storagePriceMapper.cancelSaleSkup(skup) == 1;
|
|
|
private boolean doCancelSaleSkup(Integer skup, Integer status) {
|
|
|
return storagePriceMapper.updateStatus(skup, status, 100) == 1;
|
|
|
}
|
|
|
|
|
|
private boolean doSaleSkup(Integer skup) {
|
|
|
return storagePriceMapper.saleSkup(skup) == 1;
|
|
|
return storagePriceMapper.updateStatus(skup, 100, 1) == 1;
|
|
|
}
|
|
|
|
|
|
private void addStorageNum(Integer skup, Integer storageId, Integer num) {
|
...
|
...
|
@@ -272,7 +365,7 @@ public class ProductServiceImpl implements ProductService{ |
|
|
return sp;
|
|
|
}
|
|
|
|
|
|
private void checkProductCanSale(Integer productId) {
|
|
|
private void checkProductStatus(Integer productId) {
|
|
|
LOGGER.info("checkProductCanSale productId = {}", productId);
|
|
|
Product p = productMapper.selectByPrimaryKey(productId);
|
|
|
if (p == null) {
|
...
|
...
|
@@ -282,7 +375,7 @@ public class ProductServiceImpl implements ProductService{ |
|
|
throw new ServiceException(400, "商品已删除:" + productId);
|
|
|
}
|
|
|
if (p.getShelveStatus() == null || p.getShelveStatus() != 1) {
|
|
|
throw new ServiceException(400, "商品不可售:" + productId);
|
|
|
throw new ServiceException(400, "商品已下架:" + productId);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -310,6 +403,8 @@ public class ProductServiceImpl implements ProductService{ |
|
|
throw new ServiceException(400, "productId错误:" + productId);
|
|
|
}
|
|
|
|
|
|
checkProductStatus(skupBo.getProductId());
|
|
|
|
|
|
Integer goodsId = skupBo.getGoodsId();
|
|
|
if (goodsId == null || goodsId < 1) {
|
|
|
throw new ServiceException(400, "goodsId错误:" + goodsId);
|
...
|
...
|
@@ -320,11 +415,6 @@ public class ProductServiceImpl implements ProductService{ |
|
|
throw new ServiceException(400, "storageId错误:" + storageId);
|
|
|
}
|
|
|
|
|
|
Integer depotNum = skupBo.getDepotNum();
|
|
|
if (depotNum == null || depotNum < 1) {
|
|
|
throw new ServiceException(400, "depotNum错误:" + depotNum);
|
|
|
}
|
|
|
|
|
|
Integer sellerUid = skupBo.getSellerUid();
|
|
|
if (sellerUid == null || sellerUid < 1) {
|
|
|
throw new ServiceException(400, "sellerUid错误:" + sellerUid);
|
...
|
...
|
@@ -332,7 +422,7 @@ public class ProductServiceImpl implements ProductService{ |
|
|
|
|
|
BigDecimal price = skupBo.getPrice();
|
|
|
if (price == null || price.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
throw new ServiceException(400, "sellerUid错误:" + price);
|
|
|
throw new ServiceException(400, "价格不合法:" + price);
|
|
|
}
|
|
|
LOGGER.info("skupBo 校验通过:skup = {}", skupBo.getSkup());
|
|
|
|
...
|
...
|
@@ -342,11 +432,11 @@ public class ProductServiceImpl implements ProductService{ |
|
|
sp.setStorageId(storageId);
|
|
|
sp.setPrice(price);
|
|
|
sp.setSellerUid(sellerUid);
|
|
|
sp.setDepotNum(depotNum);
|
|
|
sp.setDepotNum(0); // 未设置
|
|
|
sp.setSkup(skup);
|
|
|
sp.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
sp.setUpdateTime(0);
|
|
|
sp.setStatus(1);
|
|
|
sp.setStatus(0);
|
|
|
|
|
|
LOGGER.info("StoragePrice 解析结果为: {}", sp);
|
|
|
return sp;
|
...
|
...
|
@@ -444,6 +534,7 @@ public class ProductServiceImpl implements ProductService{ |
|
|
return goodsBOs;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
private String buildImageFullUrl(String url) {
|
|
|
if (!StringUtils.startsWith(url, "http")){
|
|
|
return ImagesHelper.template2(url, ImagesHelper.SYS_BUCKET.get(ImagesHelper.SYS_GOODS_NAME)).replaceAll("extent\\/\\{width}x\\{height}\\/","");
|
...
|
...
|
|