Authored by mali

Merge branch 'dev'

Showing 20 changed files with 372 additions and 84 deletions
... ... @@ -58,13 +58,13 @@ public class GlobalDefaultExceptionHandler {
}
//如果是业务异常,则返回http 200,并且构造json消息体中错误码&错误内容
if (e instanceof GatewayException || e instanceof ServiceException) {
if (e instanceof GatewayException || e instanceof ServiceException || e instanceof Exception) {
int code;
String desc;
if (e instanceof GatewayException) {
code = ((GatewayException) e).getErrorCode();
desc = ((GatewayException) e).getDesc();
} else { //服务异常,不能直接返回给客户端,必须映射一下
} else if(e instanceof ServiceException) { //服务异常,不能直接返回给客户端,必须映射一下
ServiceException serviceException = (ServiceException) e;
ServiceError serviceError = serviceException.getServiceError();
code = serviceError.getMappingGatewayError().getLeft();
... ... @@ -72,6 +72,9 @@ public class GlobalDefaultExceptionHandler {
if (serviceException.getParams() != null) {
desc = MessageFormat.format(desc, serviceException.getParams());
}
}else {
code = 500;
desc = "服务暂时异常,请稍等";
}
log.warn("service exception happened at:{}, code:{}, desc:{}, uri:{}, request: {}, params is: {}", serviceName, code, desc, request.getRequestURI(), serviceName, params);
... ...
... ... @@ -51,7 +51,6 @@ public class SignatureVerifyInterceptor implements HandlerInterceptor, Applicati
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
//(1) 验签开关, 控制是否需要验签. 默认需要验证
boolean isSignatureVerifyEnable = configReader.getBoolean("gateway.security.isSignatureVerifyEnable", true);
logger.info("isDebugEnable is {},request param debug is {}",isDebugEnable,httpServletRequest.getParameter("debug"));//TODO test
if(!isSignatureVerifyEnable){
logger.debug("gateway.security.isSignatureVerifyEnable is false");
return true;
... ...
... ... @@ -4,6 +4,8 @@ import com.yohoufo.dal.product.model.StoragePrice;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface StoragePriceMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -20,6 +22,10 @@ public interface StoragePriceMapper {
int saleSkup(Integer skup);
int cancelSaleSkup(Integer skup);
int updateStatus(@Param("skup")Integer skup, @Param("status")Integer status, @Param("beforeStatus")Integer beforeStatus);
int updateDepotNum(@Param("skup")Integer skup, @Param("depotNum")Integer depotNum);
StoragePrice selectLeastPrice(Integer storageId);
... ...
... ... @@ -20,7 +20,17 @@ public class StoragePrice {
private BigDecimal price;
/** 1:可售,2卖出,3鉴定失败,4卖家取消, 5客服取消. */
/**
* <pre>
* 卖家操作
* 0:初始(未支付保证金),*1:可售(已经支付保证金),2:卖家取消支付保证金,3:卖家超时未支付保证金,4:卖家支付保证金后取消售卖
* 买家操作
* 100:购买使得商品卖出(可能下单未支付,且未超时,或者已支付),101:取消卖出(买家手动),102:取消卖出(超时未支付),103:下单失败
* 平台操作
* 200:客服取消,201:鉴定失败
* </pre>
*
*/
private Integer status;
private Integer updateTime;
... ...
... ... @@ -60,7 +60,7 @@
where skup = #{skup,jdbcType=INTEGER}
</select>
<update id="saleSkup" parameterType="java.lang.Integer">
update storage_price set status = 2,
update storage_price set status = 100,
update_time = unix_timestamp()
where skup = #{skup,jdbcType=INTEGER} and status = 1
</update>
... ... @@ -81,5 +81,19 @@
#{item}
</foreach>
</select>
<update id="updateStatus">
update storage_price set status = #{status,jdbcType=INTEGER},
update_time = unix_timestamp()
where skup = #{skup,jdbcType=INTEGER}
<if test="beforeStatus != null ">
and status = #{beforeStatus}
</if>
</update>
<update id="updateDepotNum">
update storage_price set depot_num = #{depotNum,jdbcType=INTEGER},
update_time = unix_timestamp()
where skup = #{skup,jdbcType=INTEGER}
and status = 100
</update>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.model;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import lombok.Data;
... ... @@ -38,5 +39,5 @@ public class SellerOrderContext {
private AddressInfo backAddress;
private transient SellerOrderGoods sellerOrderGoods;
}
... ...
... ... @@ -51,6 +51,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
orderInfo.setStatus(SellerOrderStatus.HAS_PAYED.getCode());
sellerOrderMapper.updateByOrderCode(sellerOrder);
//
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.service.handler;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.GoodsInfo;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.service.impl.SkupService;
... ... @@ -35,17 +36,19 @@ public class SellerOrderSubmitHandler {
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Database(ForceMaster=true, DataSource="ufo_order")
public Long submit(SellerOrderContext context) throws GatewayException {
public void submit(SellerOrderContext context) throws GatewayException {
int uid = context.getUid();
int storageId = context.getStorageId();
log.info("in seller order submit uid {}, storageId {}", uid, storageId);
GoodsInfo goodsInfo = context.getSoldProduct();
//
int skup = skupService.addSkup(goodsInfo);
SellerOrderGoods sellerOrderGoods = skupService.addSkup(goodsInfo);
int skup = sellerOrderGoods.getId();
if (skup <= 0){
log.warn("in computePublishPrd storageId not exist in prd , uid {}, storageId {}", uid, storageId);
throw new GatewayException(501, "商品发布失败");
}
context.setSellerOrderGoods(sellerOrderGoods);
context.getSoldProduct().setSkup(skup);
//step 2: create order, set status(not pay)
//generate a new real code
... ... @@ -54,7 +57,6 @@ public class SellerOrderSubmitHandler {
sellerAddressService.saveSendBackAddress(context);
//record every fee items
sellerFeeService.saveFee(context);
return 0L;
}
... ...
... ... @@ -3,6 +3,8 @@ package com.yohoufo.order.service.impl;
import com.yohoufo.order.service.impl.visitor.AutoCancelCase;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
... ... @@ -11,9 +13,10 @@ import org.springframework.stereotype.Service;
@Service
public class SellerOrderCancelService {
private final Logger logger = LoggerFactory.getLogger(getClass());
public void cancel(UserCancelCase cancelCase){
logger.info("in cancel UserCancelCase {}", cancelCase);
//未支付时
//支付完成,没有买家下单
... ... @@ -23,13 +26,13 @@ public class SellerOrderCancelService {
public void cancel(AutoCancelCase autoCancelCase){
logger.info("in cancel autoCancelCase {}", autoCancelCase);
}
public void cancel(OffShelveCancelCase offShelveCancelCase){
logger.info("in cancel offShelveCancelCase {}", offShelveCancelCase);
}
}
... ...
... ... @@ -5,10 +5,10 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.SkupStatus;
import com.yohoufo.order.convert.AddressInfoConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.AddressInfo;
... ... @@ -23,11 +23,11 @@ import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -46,8 +46,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private UfoServiceCaller ufoServiceCaller;
@Autowired
private SellerOrderComputeHandler computeHandler;
... ... @@ -67,6 +66,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private SellerOrderDetailService sellerOrderDetailService;
@Autowired
private ProductProxyService productProxyService;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
log.info("in computePublishPrd, req {}", req);
... ... @@ -77,11 +79,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
StorageLeastPriceResp resp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId);
BigDecimal leastPrice;
if (Objects.isNull(resp) || Objects.isNull(leastPrice = resp.getLeastPrice()) || leastPrice.doubleValue() == 0D){
throw new GatewayException(501, "暂无商品");
}
BigDecimal leastPrice = productProxyService.getLeastprice(storageId);
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
平台服务费(5%,优惠期间0%) ¥0.00
... ... @@ -129,11 +129,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
throw new GatewayException(400, "商品不存在");
}
context.setSoldProduct(goodsInfo);
StorageLeastPriceResp leastPriceResp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId);
BigDecimal leastPrice;
if (Objects.isNull(leastPriceResp) || Objects.isNull(leastPrice = leastPriceResp.getLeastPrice()) || leastPrice.doubleValue() == 0D){
throw new GatewayException(501, "无法比对商品最低价");
}
BigDecimal leastPrice = productProxyService.getLeastprice(storageId);
if (goodsInfo.getPrice().subtract(leastPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,leastPrice {}, req {}", leastPrice, req);
throw new GatewayException(501, "设定的价格低于商品最低价");
... ... @@ -154,6 +150,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
//submit all as atomic operation, use transaction of DB
//all include : 1. skup, 2. order , 3. 寄回地址
orderSubmitHandler.submit(context);
boolean syncPrdFlag = productProxyService.syncSkup(context.getSellerOrderGoods(), SkupStatus.CAN_NOT_SELL);
log.info("publish finish, syncPrdFlag {}, req {}, orderCode {}", syncPrdFlag, req, orderCode);
//TODO 发消息
return orderCode;
}
... ... @@ -164,7 +164,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
int storageId = context.getStorageId();
BigDecimal salePrice = context.getSalePrice();
try {
StorageDataResp prdResp = ufoServiceCaller.call("ufo.product.storage.data", storageId);
StorageDataResp prdResp = productProxyService.getStorageData(storageId);
GoodsInfo goodsInfo = new GoodsInfo();
goodsInfo.setUid(uid);
goodsInfo.setProductId(prdResp.getProductId());
... ...
... ... @@ -21,12 +21,12 @@ public class SkupService {
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public int addSkup(GoodsInfo goodsInfo){
public SellerOrderGoods addSkup(GoodsInfo goodsInfo){
//validate data legal
SellerOrderGoods sellerOrderGoods = resp2Do4AddNew(goodsInfo);
//
sellerOrderGoodsMapper.insertSelective(sellerOrderGoods);
return sellerOrderGoods.getId();
return sellerOrderGoods;
}
... ...
... ... @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService;
/**
* Created by chenchao on 2018/9/17.
*/
public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{
public abstract class AbsSellerOrderCancelCase<T extends SellerOrderCancelService> implements SellerOrderCancelCase<T>{
private int uid;
... ... @@ -17,7 +17,7 @@ public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{
this.orderCode = orderCode;
}
public abstract void accept(SellerOrderCancelService visitor);
public abstract void accept(T visitor);
public int getUid() {
... ... @@ -27,4 +27,12 @@ public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{
public long getOrderCode() {
return orderCode;
}
@Override
public String toString() {
return "{" +
"uid=" + uid +
", orderCode=" + orderCode +
'}';
}
}
... ...
... ... @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService;
/**未支付 超时取消
* Created by chenchao on 2018/9/17.
*/
public class AutoCancelCase extends AbsSellerOrderCancelCase {
public class AutoCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> {
... ... @@ -14,10 +14,16 @@ public class AutoCancelCase extends AbsSellerOrderCancelCase {
}
@Override
public void accept(SellerOrderCancelService visitor) {
public void accept(T visitor) {
visitor.cancel(this);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AutoCancelCase{");
sb.append(super.toString());
sb.append('}');
return sb.toString();
}
}
... ...
... ... @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService;
/**skup下架取消
* Created by chenchao on 2018/9/17.
*/
public class OffShelveCancelCase extends AbsSellerOrderCancelCase {
public class OffShelveCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> {
public OffShelveCancelCase(int uid, long orderCode) {
... ... @@ -14,7 +14,15 @@ public class OffShelveCancelCase extends AbsSellerOrderCancelCase {
@Override
public void accept(SellerOrderCancelService visitor) {
public void accept(T visitor) {
visitor.cancel(this);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("OffShelveCancelCase{");
sb.append(super.toString());
sb.append('}');
return sb.toString();
}
}
... ...
... ... @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService;
/**
* Created by chenchao on 2018/9/17.
*/
public interface SellerOrderCancelCase {
public interface SellerOrderCancelCase<T extends SellerOrderCancelService> {
void accept(SellerOrderCancelService visitor);
void accept(T visitor);
}
... ...
... ... @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService;
/**
* Created by chenchao on 2018/9/17.
*/
public class UserCancelCase extends AbsSellerOrderCancelCase {
public class UserCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> {
... ... @@ -14,7 +14,16 @@ public class UserCancelCase extends AbsSellerOrderCancelCase {
}
@Override
public void accept(SellerOrderCancelService visitor) {
public void accept(T visitor) {
visitor.cancel(this);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("UserCancelCase{");
sb.append(super.toString());
sb.append('}');
return sb.toString();
}
}
... ...
package com.yohoufo.order.service.proxy;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.SkupStatus;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Objects;
/**
* Created by chenchao on 2018/9/21.
*/
@Service
public class ProductProxyService {
final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private UfoServiceCaller ufoServiceCaller;
private final static String syncSkup = "method=ufo.product.createSkup";
@Autowired
private SellerOrderGoodsMapper sogMapper;
public BigDecimal getLeastprice(int storageId) throws GatewayException {
StorageLeastPriceResp resp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId);
BigDecimal leastPrice;
if (Objects.isNull(resp) || Objects.isNull(leastPrice = resp.getLeastPrice()) || leastPrice.doubleValue() == 0D){
throw new GatewayException(501, "无法比对商品最低价");
}
return leastPrice;
}
public StorageDataResp getStorageData(int storageId){
StorageDataResp prdResp = ufoServiceCaller.call("ufo.product.storage.data", storageId);
return prdResp;
}
public boolean syncSkup(SellerOrderGoods goods, SkupStatus skupStatus){
boolean result = false;
switch (skupStatus){
//一开始未支付时调用
case CAN_NOT_SELL:
result = doSyncSkup(goods, skupStatus);
break;
case SELF_CANCEL_PAY:
break;
case TIMEOUT_CANCEL:
break;
case SELLER_CANCEL_SELL:
break;
case YOHO_CANCEL_SELL:
break;
default:
break;
}
return result;
}
public boolean doSyncSkup(SellerOrderGoods goods, SkupStatus skupStatus){
StoragePriceBo skupReq = new StoragePriceBo();
skupReq.setSkup(goods.getId());
skupReq.setStatus(skupStatus.getCode());
skupReq.setProductId(goods.getProductId());
skupReq.setGoodsId(goods.getColorId());
skupReq.setStorageId(goods.getStorageId());
skupReq.setPrice(goods.getGoodsPrice());
skupReq.setSellerUid(goods.getUid());
ApiResponse resp = ufoServiceCaller.call(syncSkup, skupReq);
return (null == resp || null == resp.getData())? false : (boolean)resp.getData();
}
}
... ...
... ... @@ -116,14 +116,12 @@ public class ProductController {
return productService.queryStorageInfo(storageId);
}
// 增加库存
// 创建skup
@RequestMapping(params = "method=ufo.product.createSkup")
public ApiResponse createSkup(@RequestBody StoragePriceBo skupBo) {
LOG.info("in method=ufo.product.createSkup skupBo = {}", skupBo);
try {
productService.createSkup(skupBo);
LOG.info("createSkup success and async clearProductCache skup = {}", skupBo.getSkup());
clearProductCache(skupBo.getSkup());
return new ApiResponse(200, "创建成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("创建SKUP失败!", e);
... ... @@ -132,6 +130,40 @@ public class ProductController {
}
}
// 卖家修改状态:*1:可售(支付保证金),2:取消支付保证金,3:超时未支付保证金,4:支付保证金后取消售卖
@RequestMapping(params = "method=ufo.product.sellerUpdateStatus")
public ApiResponse sellerUpdateStatus(@RequestBody StoragePriceBo skupBo) {
LOG.info("in method=ufo.product.sellerUpdateStatus skupBo = {}", skupBo);
try {
productService.sellerUpdateStatus(skupBo);
if (skupBo.getStatus() == 1 || skupBo.getStatus() == 4) {
LOG.info("sellerUpdateStatus success and async clearProductCache skup = {}", skupBo.getSkup());
clearProductCache(skupBo.getSkup());
}
return new ApiResponse(200, "创建成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("sellerUpdateStatus失败!", e);
int code = (e instanceof ServiceException) ? ((ServiceException) e).getCode() : 500;
return new ApiResponse(code, e.getMessage(), Boolean.FALSE);
}
}
// 设置鉴定中心
@RequestMapping(params = "method=ufo.product.setDepotNum")
public ApiResponse setDepotNum(
@RequestParam(value = "skup", required = true) Integer skup,
@RequestParam(value = "depotNum", required = true) Integer depotNum) {
LOG.info("in method=ufo.product.cancelSaleSkup skup={}, depotNum={}", skup, depotNum);
try {
productService.setDepotNum(skup, depotNum);
return new ApiResponse(200, "设置成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("设置鉴定中心失败!", e);
int code = (e instanceof ServiceException) ? ((ServiceException) e).getCode() : 500;
return new ApiResponse(code, e.getMessage(), Boolean.FALSE);
}
}
// 售卖
@RequestMapping(params = "method=ufo.product.saleSkup")
public ApiResponse saleSkup(
... ... @@ -149,21 +181,15 @@ public class ProductController {
return new ApiResponse(code, e.getMessage(), Boolean.FALSE);
}
}
/**
*
* @param skup
* @return
*/
@IgnoreSignature
@IgnoreSession
// 取消售卖
@RequestMapping(params = "method=ufo.product.cancelSaleSkup")
public ApiResponse cancelSaleSkup(
@RequestParam(value = "skup", required = true) Integer skup) {
LOG.info("in method=ufo.product.cancelSaleSkup skup={}", skup);
@RequestParam(value = "skup", required = true) Integer skup,
@RequestParam(value = "status", required = true) Integer status) {
LOG.info("in method=ufo.product.cancelSaleSkup skup={}, status={}", skup, status);
try {
productService.cancelSaleSkup(skup);
productService.cancelSaleSkup(skup, status);
LOG.info("saleSkup success and async clearProductCache skup = {}", skup);
clearProductCache(skup);
return new ApiResponse(200, "取消卖出成功!", Boolean.TRUE);
... ...
... ... @@ -16,7 +16,7 @@ public interface ProductService {
void saleSkup(Integer productId, Integer skup);
void cancelSaleSkup(Integer skup);
void cancelSaleSkup(Integer skup, Integer status);
StoragePrice getStoragePriceBySkup(Integer skup);
... ... @@ -24,5 +24,8 @@ public interface ProductService {
ProductSortTemplateResp querySortTemplateData(String productIds);
void sellerUpdateStatus(StoragePriceBo skupBo);
void setDepotNum(Integer skup, Integer depotNum);
}
... ...
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}\\/","");
... ...