Authored by chenchao

Merge branch 'dev_order' into test6.8.2

... ... @@ -3,7 +3,6 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.SellerWallet;
public interface SellerWalletMapper {
int deleteByPrimaryKey(Integer id);
int insert(SellerWallet record);
... ... @@ -14,4 +13,6 @@ public interface SellerWalletMapper {
int updateByPrimaryKeySelective(SellerWallet record);
int updateByPrimaryKey(SellerWallet record);
SellerWallet selectByUidNType(SellerWallet condition);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.SkupBatch;
public interface SkupBatchMapper {
int deleteByPrimaryKey(Long id);
int insert(SkupBatch record);
int insertSelective(SkupBatch record);
SkupBatch selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(SkupBatch record);
int updateByPrimaryKey(SkupBatch record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class SkupBatch {
private Long id;
private Integer uid;
private Integer num;
private Integer createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
... ... @@ -24,4 +24,6 @@ public interface StorageMapper {
int addStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum);
List<Storage> selectByGoodsId(Integer goodsId);
int batchAddStorageNum(@Param("storageList")List<Storage> storageList);
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,8 @@ public interface StoragePriceMapper {
int deleteByPrimaryKey(Integer id);
int insert(StoragePrice record);
int insertBatch(@Param("storagePriceList")List<StoragePrice> storagePriceList);
StoragePrice selectByPrimaryKey(Integer id);
... ... @@ -25,9 +27,13 @@ public interface StoragePriceMapper {
int updateStatus(@Param("skup")Integer skup, @Param("status")Integer status, @Param("beforeStatus")Integer beforeStatus);
int batchUpdateStatus(@Param("skupList")List<Integer> skupList, @Param("status")Integer status);
int updateDepotNum(@Param("skup")Integer skup, @Param("depotNum")Integer depotNum);
StoragePrice selectLeastPrice(Integer storageId);
List<StoragePrice> selectByStorageIds(List<Integer> storageIds);
List<StoragePrice> selectBySkupList(@Param("skupList")List<Integer> skupList);
}
\ No newline at end of file
... ...
... ... @@ -19,10 +19,14 @@
from seller_wallet
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from seller_wallet
where id = #{id,jdbcType=INTEGER}
</delete>
<select id="selectByUidNType" resultMap="BaseResultMap" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
select
<include refid="Base_Column_List" />
from seller_wallet
where uid = #{uid,jdbcType=INTEGER} and `type` = #{type,jdbcType=TINYINT} limit 1
</select>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
insert into seller_wallet (id, uid, amount,
status, type, create_time,
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yohoufo.dal.order.SkupBatchMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.SkupBatch">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="num" jdbcType="INTEGER" property="num" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
id, uid, num, create_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from skup_batch
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from skup_batch
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SkupBatch" useGeneratedKeys="true">
insert into skup_batch (uid, num, create_time
)
values (#{uid,jdbcType=INTEGER}, #{num,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SkupBatch" useGeneratedKeys="true">
insert into skup_batch
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">
uid,
</if>
<if test="num != null">
num,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="uid != null">
#{uid,jdbcType=INTEGER},
</if>
<if test="num != null">
#{num,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SkupBatch">
update skup_batch
<set>
<if test="uid != null">
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="num != null">
num = #{num,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.SkupBatch">
update skup_batch
set uid = #{uid,jdbcType=INTEGER},
num = #{num,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -62,5 +62,25 @@
update_time = unix_timestamp()
where id = #{storageId,jdbcType=INTEGER}
</update>
<update id="batchAddStorageNum" parameterType="java.util.List">
update storage
<trim prefix="set" suffixOverrides=",">
<trim prefix="storage_num =case" suffix="end,">
<foreach collection="storageList" item="item" index="index">
<if test="item.storageNum!=null">
when id=#{item.id,jdbcType=INTEGER} then storage_num + #{item.storageNum,jdbcType=INTEGER}
</if>
</foreach>
</trim>
<trim prefix="update_time =case" suffix="end,">
<foreach collection="storageList" item="item" index="index">
when id=#{item.id,jdbcType=INTEGER} then unix_timestamp()
</foreach>
</trim>
</trim>
where
<foreach collection="storageList" separator="or" item="item" index="index" >
id= #{item.id,jdbcType=INTEGER}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -28,6 +28,21 @@
#{price,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertBatch">
insert into storage_price (skup, product_id, goods_id,
storage_id, depot_num, seller_uid,
price, status, update_time,
create_time)
values
<foreach collection="storagePriceList" item="item" index="index" separator="," >
(#{item.skup,jdbcType=INTEGER}, #{item.productId,jdbcType=INTEGER},
#{item.goodsId,jdbcType=INTEGER},#{item.storageId,jdbcType=INTEGER}, #{item.depotNum,jdbcType=INTEGER}, #{item.sellerUid,jdbcType=INTEGER},
#{item.price,jdbcType=DECIMAL}, #{item.status,jdbcType=INTEGER}, #{item.updateTime,jdbcType=INTEGER},
#{item.createTime,jdbcType=INTEGER})
</foreach>
</insert>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.product.model.StoragePrice">
update storage_price
set skup = #{skup,jdbcType=INTEGER},
... ... @@ -81,6 +96,16 @@
#{item}
</foreach>
</select>
<select id="selectBySkupList" resultMap="BaseResultMap">
select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
update_time, create_time
from storage_price
where skup in
<foreach item="item" index="index" collection="skupList"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<update id="updateStatus">
update storage_price set status = #{status,jdbcType=INTEGER},
update_time = unix_timestamp()
... ... @@ -95,5 +120,12 @@
where skup = #{skup,jdbcType=INTEGER}
and status = 100
</update>
<update id="batchUpdateStatus">
update storage_price set status = #{status,jdbcType=INTEGER},
update_time = unix_timestamp()
where skup in
<foreach item="skup" index="index" collection="skupList" open="(" separator="," close=")">
#{skup}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo;
import com.yohoufo.common.constant.ExpressInfoConstant;
... ... @@ -26,6 +23,7 @@ import com.yohoufo.order.model.response.GoodsInfo;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
... ... @@ -73,6 +71,9 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
@Autowired
private OrderCacheService orderCacheService;
@Autowired
private UserProxyService userProxyService;
private static List<SkupStatus> noNeedShowOrderCode = Arrays.asList(SkupStatus.CAN_NOT_SELL,SkupStatus.CAN_SELL,
SkupStatus.SELF_CANCEL_PAY, SkupStatus.TIMEOUT_CANCEL,
SkupStatus.SELLER_CANCEL_SELL, SkupStatus.YOHO_CANCEL_SELL);
... ... @@ -103,12 +104,14 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
logger.warn("can not find seller order, req {}", orderRequest);
return null;
}
boolean isEntry = userProxyService.isEntryShop(uid);
SellerType sellerType = isEntry ? SellerType.ENTRY : SellerType.COMMON;
Integer skup = sellerOrder.getSkup();
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
Integer skupStatusCode = sellerOrderGoods.getStatus();
SkupStatus skupStatus = SkupStatus.getSkupStatus(skupStatusCode);
AddressInfo addressInfo = sellerAddressService.getHiddenAddressInfo(uid, skup);
orderDetailInfo = buildOrderDetail(sellerOrder, skupStatus, sellerOrderGoods, addressInfo);
orderDetailInfo = buildOrderDetail(sellerOrder, skupStatus, sellerOrderGoods, addressInfo, sellerType);
}else{
orderDetailInfo = super.getOrderDetail(orderRequest);
}
... ... @@ -273,12 +276,13 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
}
private OrderDetailInfo buildOrderDetail(SellerOrder order, SkupStatus skupStatus,
SellerOrderGoods sellerOrderGoods, AddressInfo addressInfo
SellerOrderGoods sellerOrderGoods, AddressInfo addressInfo,
SellerType sellerType
) {
OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
orderDetailInfo.setUid(order.getUid());
orderDetailInfo.setOrderCode(getOrderCode(skupStatus, order));
orderDetailInfo.setButtons(skupStatus.getDetailButtons());
orderDetailInfo.setButtons(skupStatus.getDetailButtons(sellerType));
orderDetailInfo.setSubmitOrderTimeStr(DateUtil.formatDate(order.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
orderDetailInfo.setUserAddress(addressInfo);
//卖家
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SellerType;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
... ... @@ -22,6 +23,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.proxy.UserProxyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -54,6 +56,9 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
@Autowired
private OrderCacheService orderCacheService;
@Autowired
private UserProxyService userProxyService;
@Override
public PageResp<OrderListInfo> getOrderList(OrderListRequest request){
... ... @@ -73,7 +78,8 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
int type;
if ((type=request.getType()) == SellerOrderListType.IN_SALE.getType()){
List<Integer> statusList = initOrderListRequest(request);
boolean isEntry = userProxyService.isEntryShop(request.getUid());
final SellerType sellerType = isEntry ? SellerType.ENTRY : SellerType.COMMON;
int total = sellerOrderGoodsMapper.selectCntByUidStatusList(request.getUid(), statusList);
int limit = request.getLimit();
respBuilder = PageResp.builder()
... ... @@ -98,7 +104,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
List<SellerOrder> sellerOrders = sellerOrderMapper.selectBySkups(skupList);
List<OrderListInfo> data ;
data = sellerOrders.parallelStream()
.map(sellerOrder -> buildOrderListInfo(skupSellerOrderGoodsMap.get(sellerOrder.getSkup()), sellerOrder))
.map(sellerOrder -> buildOrderListInfo(skupSellerOrderGoodsMap.get(sellerOrder.getSkup()), sellerOrder, sellerType))
.filter(oli -> Objects.nonNull(oli))
.collect(Collectors.toList());
... ... @@ -132,7 +138,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
}
OrderListInfo buildOrderListInfo(SellerOrderGoods sellerOrderGoods,
SellerOrder sellerOrder) {
SellerOrder sellerOrder, SellerType sellerType) {
OrderListInfo orderListInfo = new OrderListInfo();
orderListInfo.setUid(sellerOrder.getUid());
... ... @@ -152,7 +158,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
orderListInfo.setStatuStr(skupStatus.getDesc());
// 按钮显示
orderListInfo.setButtons(skupStatus.getListButtons());
orderListInfo.setButtons(skupStatus.getListButtons(sellerType));
// 当订单状态是待付款, 显示leftTime
if (sellerOrderGoods.getStatus() == SkupStatus.CAN_NOT_SELL.getCode()){
... ...
... ... @@ -2,35 +2,35 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.BatchChangePriceResp;
import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.*;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.common.DelStatus;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
import com.yohoufo.order.event.EventHandlerContainer;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.model.AddressInfo;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.EarnestMoney;
import com.yohoufo.order.model.dto.PlatformFeeDto;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.model.response.OrderSummaryResp;
import com.yohoufo.order.service.IOrderDetailService;
... ... @@ -39,16 +39,12 @@ import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
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.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.model.ProductInfo;
import com.yohoufo.product.response.StorageDataResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -67,7 +63,6 @@ import java.util.stream.Collectors;
@Slf4j
public class SellerOrderService implements IOrderListService, IOrderDetailService {
@Autowired
private SellerOrderMapper sellerOrderMapper;
... ... @@ -84,9 +79,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
private SellerOrderSubmitHandler orderSubmitHandler;
@Autowired
private UserProxyService userProxyService;
@Autowired
private SellerOrderListService sellerOrderListService;
@Autowired
... ... @@ -110,6 +102,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private CacheCleaner cacheCleaner;
@Autowired
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
log.info("in computePublishPrd, req {}", req);
... ... @@ -152,33 +146,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
throw new GatewayException(400, "非法数字");
}
checkPrice(storageId, prdPrice, false);
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
return buildSoldPrdComputeBo(uid, num, prdPrice);
}
void checkPrice(int storageId, BigDecimal prdPrice, boolean validateMaxPrice) throws GatewayException {
ProductInfo productInfo = productProxyService.getPrdPriceRange(storageId);
BigDecimal minPrice = productInfo.getMinPrice();
BigDecimal maxPrice = productInfo.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
throw new GatewayException(501, "您的出价过低");
}
if (validateMaxPrice && prdPrice.subtract(maxPrice).doubleValue() > 0D){
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
throw new GatewayException(501, "您的出价过高");
}
}
void checkIncome(int storageId, BigDecimal income) throws GatewayException {
if (income == null || income.compareTo(BigDecimal.ZERO) <= 0){
log.warn("in checkIncome,storageId {}, income {}", income);
throw new GatewayException(501, "别闹了,这个售价没有收入");
}
}
/**
* 发布商品 + 生成订单
* @param req
... ... @@ -187,22 +158,22 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
*/
public OrderSubmitResp publishPrd(SellerOrderSubmitReq req) throws GatewayException {
SellerOrderContext context = buildSellerOrderContext(req);
SellerOrderContext context = sellerOrderPrepareProcessor.buildSellerOrderContext(req);
int storageId = context.getStorageId();
int uid = context.getUid();
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = getProductDetail(context);
GoodsInfo goodsInfo = sellerOrderPrepareProcessor.getProductDetail(context);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
log.warn("in computePublishPrd storageId not exist in prd , uid {}, storageId {}", uid, storageId);
log.warn("in publishPrd storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
checkPrice(storageId, goodsInfo.getPrice(), true);
sellerOrderPrepareProcessor.checkPrice(storageId, goodsInfo.getPrice(), true);
// compute every fee from price
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice());
checkIncome(storageId, computeResult.getIncome());
sellerOrderPrepareProcessor.checkIncome(storageId, computeResult.getIncome());
log.info("in publishPrd , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
... ... @@ -248,98 +219,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
private GoodsInfo getProductDetail(SellerOrderContext context){
int uid = context.getUid();
int storageId = context.getStorageId();
BigDecimal salePrice = context.getSalePrice();
try {
StorageDataResp prdResp = productProxyService.getStorageData(storageId);
if (!Integer.valueOf(1).equals(prdResp.getStatus())) {
log.info("in getProductDetail occur product out shelve, uid {}, storageId {}", uid, storageId);
return null;
}
GoodsInfo goodsInfo = new GoodsInfo();
goodsInfo.setUid(uid);
goodsInfo.setProductId(prdResp.getProductId());
goodsInfo.setProductName(prdResp.getProductName());
goodsInfo.setColorId(Objects.isNull(prdResp.getColorId()) ? null : Integer.valueOf(prdResp.getColorId()));
goodsInfo.setColorName(prdResp.getColorName());
GoodsSize size;
if (Objects.nonNull(size =prdResp.getSize())){
goodsInfo.setSizeName(size.getSizeName());
goodsInfo.setSizeId(size.getSizeId());
}
goodsInfo.setImageUrl(prdResp.getImageUrl());
goodsInfo.setPrice(salePrice);
goodsInfo.setStorageId(context.getStorageId());
return goodsInfo;
}catch (Exception ex){
log.warn("in getProductDetail occur error, uid {}, storageId {}", uid, storageId);
return null;
}
}
private SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) throws GatewayException {
int uid = req.getUid();
if (uid <= 0){
log.warn("uid illegal , uid {}", uid);
throw new GatewayException(400, "Uid 错误");
}
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "storageId 错误");
}
String price = req.getPrice();
if (StringUtils.isBlank(price)){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
if(!price.endsWith("9")){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}
BigDecimal salePrice;
try{
salePrice = new BigDecimal(req.getPrice());
}catch (Exception ex){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "售价格式错误");
}
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
if (addressId < 0){
log.warn("seller submit order addressId invalidate, uid {}, storageId {}, addressId is {}",
uid, storageId, req.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
//the address of send back 2 seller
//
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){
log.warn("seller submit addressId need update, uid is {}, storageId is {}, addressId is {}",
uid, storageId, addressId);
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}
//
SellerOrderContext context = new SellerOrderContext();
context.setUid(uid);
context.setStorageId(storageId);
context.setSalePrice(salePrice);
//
context.setBackAddress(noHiddenBackAddress);
context.setBackHiddenAddress(hiddenBackAddress);
return context;
}
/**
* 卖家支付完成后调用
* @param uid
... ... @@ -361,6 +240,21 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
@Autowired
private SkupBatchService skupBatchService;
public void batchPublishPrds(SellerOrderSubmitReq req) throws GatewayException {
// 一串校验
SellerOrderContext ctx = sellerOrderPrepareProcessor.buildBatchSellerOrderContext(req);
//TODO 扣减保证金
//TODO (异步实现)记录保证金流水
//TODO 生成批次号
skupBatchService.generateBatchNo(req.getUid(), req.getNum());
//TODO 批量生成订单(订单表,meta 地址,算费)--> 需要用到多线程并行处理
//TODO(异步实现)同步数据到prd,记录支付,
}
public boolean offShelveByErp(int skup){
if (skup <= 0 ){
... ... @@ -447,16 +341,14 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
if(OrderCodeType.BUYER_TYPE.getType() == codeMeta.getType()){
BuyerOrder buyerOrder = buyerOrderMapper.selectAllByOrderCode(orderCode);
//todo 判断状态后更新
//判断状态后更新
checkBuyCanDelStatus(buyerOrder.getStatus());
BuyerOrder target = new BuyerOrder();
target.setId(buyerOrder.getId());
target.setSellerOrderStatus(DelStatus.IS_DEL.getCode());
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
buyerOrderMapper.updateByPrimaryKeySelective(target);
}
cacheCleaner.cleanList(uid, TabType.SELL.getValue());
return true;
}
... ... @@ -488,29 +380,12 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
private boolean isEnough(int uid, BigDecimal mEarestMoney){
//todo 取出入驻商家的钱包余额,判断保证金总额是否足够扣减
return false;
}
private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, BigDecimal prdPrice){
SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
/**
* 验证是否是入驻商家
*/
boolean isEntryShop = userProxyService.isEntryShop(uid);
if(isEntryShop){
BigDecimal singleEarestMoney = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
boolean isEnough = isEnough(uid, mEarestMoney);
if (!isEnough){
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
}
}
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, computeResult, num, prdPrice);
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
return computeBo;
}
... ... @@ -528,8 +403,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
return sellerOrderDetailService.getOrderDetail(orderRequest);
}
/**
* 根据用户id查询卖的单数
* 出售栏目显示的数量=出售tab下商品“出售中”状态的数量+待发货tab下所有的订单数+已发货tab下所有订单数
... ...
package com.yohoufo.order.service.impl;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SkupBatchMapper;
import com.yohoufo.dal.order.model.SkupBatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
* Created by chao.chen on 2018/11/19.
*/
@Service
public class SkupBatchService {
private final Logger logger = LoggerFactory.getLogger(getClass());
private SkupBatchMapper skupBatchMapper;
public Long generateBatchNo(int uid, int num){
SkupBatch record = new SkupBatch();
record.setUid(uid);
record.setNum(num);
record.setCreateTime(DateUtil.getCurrentTimeSecond());
skupBatchMapper.insertSelective(record);
return record.getId();
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SkupBatchMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
... ... @@ -24,6 +26,9 @@ public class SkupService {
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private SkupBatchMapper skupBatchMapper;
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public SellerOrderGoods addSkup(GoodsInfo goodsInfo){
... ... @@ -58,6 +63,10 @@ public class SkupService {
return sellerOrderGoods;
}
public void batchPublishPrds(SellerOrderSubmitReq req){
}
}
... ...
package com.yohoufo.order.service.impl.processor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SellerWalletType;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.model.AddressInfo;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.model.ProductInfo;
import com.yohoufo.product.response.StorageDataResp;
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 java.math.BigDecimal;
import java.util.Objects;
/**
* Created by chao.chen on 2018/11/19.
*/
@Service
public class SellerOrderPrepareProcessor {
private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private UserProxyService userProxyService;
@Autowired
private ProductProxyService productProxyService;
@Autowired
private SellerOrderComputeHandler computeHandler;
@Autowired
private SellerWalletMapper sellerWalletMapper;
public SellerOrderContext buildBatchSellerOrderContext(SellerOrderSubmitReq req) throws GatewayException {
SellerOrderContext ctx = buildSellerOrderContext(req);
int storageId = ctx.getStorageId();
int uid = ctx.getUid();
int storageNum = req.getNum();
if (storageNum <=0){
log.warn("in buildBatchSellerOrderContext storageNum illegal , uid {}, storageId {} storageNum {}",
uid, storageId, storageNum);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = getProductDetail(ctx);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
log.warn("in buildBatchSellerOrderContext storageId not exist in prd , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
goodsInfo.setStorageNum(storageNum);
ctx.setSoldProduct(goodsInfo);
checkPrice(storageId, goodsInfo.getPrice(), true);
// compute every fee from price
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice());
checkIncome(storageId, computeResult.getIncome());
checkNGetMergeEarnestMoney(uid, computeResult, storageNum, goodsInfo.getPrice());
return ctx;
}
public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) throws GatewayException {
int uid = req.getUid();
if (uid <= 0){
log.warn("uid illegal , uid {}", uid);
throw new GatewayException(400, "Uid 错误");
}
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "storageId 错误");
}
String price = req.getPrice();
if (StringUtils.isBlank(price)){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
if(!price.endsWith("9")){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}
BigDecimal salePrice;
try{
salePrice = new BigDecimal(req.getPrice());
}catch (Exception ex){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "售价格式错误");
}
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
if (addressId < 0){
log.warn("seller submit order addressId invalidate, uid {}, storageId {}, addressId is {}",
uid, storageId, req.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
//the address of send back 2 seller
//
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){
log.warn("seller submit addressId need update, uid is {}, storageId is {}, addressId is {}",
uid, storageId, addressId);
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}
//
SellerOrderContext context = new SellerOrderContext();
context.setUid(uid);
context.setStorageId(storageId);
context.setSalePrice(salePrice);
//
context.setBackAddress(noHiddenBackAddress);
context.setBackHiddenAddress(hiddenBackAddress);
return context;
}
public GoodsInfo getProductDetail(SellerOrderContext context){
int uid = context.getUid();
int storageId = context.getStorageId();
BigDecimal salePrice = context.getSalePrice();
try {
StorageDataResp prdResp = productProxyService.getStorageData(storageId);
if (!Integer.valueOf(1).equals(prdResp.getStatus())) {
log.info("in getProductDetail occur product out shelve, uid {}, storageId {}", uid, storageId);
return null;
}
GoodsInfo goodsInfo = new GoodsInfo();
goodsInfo.setUid(uid);
goodsInfo.setProductId(prdResp.getProductId());
goodsInfo.setProductName(prdResp.getProductName());
goodsInfo.setColorId(Objects.isNull(prdResp.getColorId()) ? null : Integer.valueOf(prdResp.getColorId()));
goodsInfo.setColorName(prdResp.getColorName());
GoodsSize size;
if (Objects.nonNull(size = prdResp.getSize())){
goodsInfo.setSizeName(size.getSizeName());
goodsInfo.setSizeId(size.getSizeId());
}
goodsInfo.setImageUrl(prdResp.getImageUrl());
goodsInfo.setPrice(salePrice);
goodsInfo.setStorageId(context.getStorageId());
return goodsInfo;
}catch (Exception ex){
log.warn("in getProductDetail occur error, uid {}, storageId {}", uid, storageId);
return null;
}
}
public void checkPrice(int storageId, BigDecimal prdPrice, boolean validateMaxPrice) throws GatewayException {
ProductInfo productInfo = productProxyService.getPrdPriceRange(storageId);
BigDecimal minPrice = productInfo.getMinPrice();
BigDecimal maxPrice = productInfo.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
throw new GatewayException(501, "您的出价过低");
}
if (validateMaxPrice && prdPrice.subtract(maxPrice).doubleValue() > 0D){
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
throw new GatewayException(501, "您的出价过高");
}
}
public void checkIncome(int storageId, BigDecimal income) throws GatewayException {
if (income == null || income.compareTo(BigDecimal.ZERO) <= 0){
log.warn("in checkIncome,storageId {}, income {}", storageId, income);
throw new GatewayException(501, "别闹了,这个售价没有收入");
}
}
public BigDecimal checkNGetMergeEarnestMoney(int uid, SellerOrderComputeResult computeResult, int num, BigDecimal prdPrice){
boolean isEntryShop = userProxyService.isEntryShop(uid);
BigDecimal mEarestMoney = null;
if(isEntryShop){
BigDecimal singleEarestMoney = computeResult.getEarnestMoney().getEarnestMoney();
mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
boolean isEnough = isEnough(uid, mEarestMoney);
if (!isEnough){
log.warn("in buildSoldPrdComputeBo,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",
uid, num, prdPrice, singleEarestMoney);
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
}
}
return mEarestMoney;
}
/**
*
* @param uid
* @param mEarestMoney
* @return
*/
private boolean isEnough(int uid, BigDecimal mEarestMoney){
//取出入驻商家的钱包余额,判断保证金总额是否足够扣减
SellerWallet condition = new SellerWallet();
condition.setUid(uid);
condition.setType(SellerWalletType.EARNEAST_MONEY.getCode());
SellerWallet psw = sellerWalletMapper.selectByUidNType(condition);
log.info("in compare price, uid {}, mEarestMoney {}, SellerWallet {}", uid, mEarestMoney, psw);
if (psw !=null && psw.getAmount().compareTo(mEarestMoney) >= 0){
return true;
}
return false;
}
}
... ...
... ... @@ -144,8 +144,6 @@ public class UserProxyService {
ApiResponse userInfo ;
try {
userInfo = ufoServiceCaller.call("ufo.user.isStoredSeller", uid);
}catch (Exception ex){
logger.warn("in getMobile fail, uid {}", uid, ex);
throw new ServiceException(ServiceError.USER_IS_NOT_EXIST);
... ...
package com.yohoufo.product.controller;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -171,6 +174,24 @@ public class ProductController {
}
}
/**
* 批量创建skup
* @param skupBo
* @return
*/
@RequestMapping(params = "method=ufo.product.batchCreateSkup")
public ApiResponse batchCreateSkup(@RequestBody List<StoragePriceBo> skupBoList) {
LOG.info("in method=ufo.product.batchCreateSkup skupBoList = {}", skupBoList);
try {
productService.batchCreateSkup(skupBoList);
return new ApiResponse(200, "创建成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("创建SKUP失败!", e);
int code = (e instanceof ServiceException) ? ((ServiceException) e).getCode() : 500;
return new ApiResponse(code, e.getMessage(), Boolean.FALSE);
}
}
// 卖家修改状态:*1:可售(支付保证金),2:取消支付保证金,3:超时未支付保证金,4:支付保证金后取消售卖
@RequestMapping(params = "method=ufo.product.sellerUpdateStatus")
public ApiResponse sellerUpdateStatus(@RequestBody StoragePriceBo skupBo) {
... ... @@ -189,6 +210,34 @@ public class ProductController {
}
}
// 商家修改状态:1:上架 2:下架
@RequestMapping(params = "method=ufo.product.sellerBatchUpdateStatus")
public ApiResponse sellerBatchUpdateStatus(@RequestParam(value = "skupList", required = true) List<Integer> skupList,
@RequestParam(value = "status", required = true) Integer status){
LOG.info("in method=ufo.product.sellerBatchUpdateStatus skupList is {}, status is {}", skupList, status);
int dbStatus = 1;//上架
if(1 != status.intValue() && 2 != status.intValue()) {
throw new ServiceException(400, "status值不对,只能传1或2!");
}
//下架
if(2 == status.intValue()) {
dbStatus = 104;
}
try {
productService.sellerBatchUpdateStatus(skupList, dbStatus);
//清缓存
LOG.info("sellerUpdateStatus success and async clearProductCache skupList = {}", skupList);
clearBatchProductCache(skupList);
return new ApiResponse(200, "更新成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("sellerBatchUpdateStatus失败!", 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(
... ... @@ -257,4 +306,35 @@ public class ProductController {
}
});
}
private void clearBatchProductCache(List<Integer> skupList) {
executors.execute(() -> {
try {
LOG.info("in clearBatchProductCache skupList = {}", skupList);
List<StoragePrice> spList = productService.getStoragePriceBySkupList(skupList);
List<Integer> productIdList = spList.stream().map(StoragePrice::getProductId).collect(Collectors.toList());
List<Integer> storageIdList = spList.stream().map(StoragePrice::getStorageId).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(productIdList)) {
for(Integer productId : productIdList) {
LOG.info("clearCache queryProductDetailById productId = {}, ", productId);
//商品详情
cacheAop.clearCache(
ProductController.class.getMethod("queryProductDetailById", new Class[] { Integer.class }),
new Object[] { productId });
}
}
if(CollectionUtils.isNotEmpty(storageIdList)) {
for(Integer storageId : storageIdList) {
// sku最低价
LOG.info("clearCache queryStorageLeastprice storageId = {}, ", storageId);
cacheAop.clearCache(
ProductController.class.getMethod("queryStorageLeastprice", new Class[] { Integer.class }),
new Object[] { storageId });
}
}
} catch (Exception e) {
LOG.error("删除商品缓存失败!", e);
}
});
}
}
\ No newline at end of file
... ...
package com.yohoufo.product.service;
import com.yoho.core.dal.datasource.annotation.Database;
import java.util.List;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.*;
import org.springframework.transaction.annotation.Transactional;
import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.response.ProductSeriesTemplateResp;
import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
public interface ProductService {
... ... @@ -34,4 +39,15 @@ public interface ProductService {
// 查询商品的基本信息
ProductDetailResp queryProductBaseInfo(Integer productId);
void batchCreateSkup(List<StoragePriceBo> skupBoList);
/**
* 卖家上架或下架商品
* @param skupList
* @param status
*/
void sellerBatchUpdateStatus(List<Integer> skupList, int status);
List<StoragePrice> getStoragePriceBySkupList(List<Integer> skupList);
}
... ...
... ... @@ -6,20 +6,20 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.yoho.core.dal.datasource.annotation.Database;
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.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import com.google.common.collect.Lists;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -169,6 +169,11 @@ public class ProductServiceImpl implements ProductService{
public StoragePrice getStoragePriceBySkup(Integer skup) {
return storagePriceMapper.selectBySkup(skup);
}
@Override
public List<StoragePrice> getStoragePriceBySkupList(List<Integer> skupList) {
return storagePriceMapper.selectBySkupList(skupList);
}
@Override
public ProductSortTemplateResp querySortTemplateData(String productIds) {
... ... @@ -235,6 +240,22 @@ public class ProductServiceImpl implements ProductService{
}
@Override
public void batchCreateSkup(List<StoragePriceBo> skupBoList) {
if(CollectionUtils.isEmpty(skupBoList)) {
throw new ServiceException(400, "skupBoList为空!");
}
List<StoragePrice> spList = Lists.newArrayList();
//校验
for(int i=0; i<skupBoList.size(); i++) {
StoragePrice sp = exchangeCreateSkupBo(skupBoList.get(i));
spList.add(sp);
}
//批量插入数据库
storagePriceMapper.insertBatch(spList);
}
@Override
public void sellerUpdateStatus(StoragePriceBo skupBo) {
// 卖家修改状态:*1:可售(支付保证金),2:取消支付保证金,3:超时未支付保证金,4:支付保证金后取消售卖
if (skupBo == null) {
... ... @@ -280,6 +301,37 @@ public class ProductServiceImpl implements ProductService{
}
@Override
public void sellerBatchUpdateStatus(List<Integer> skupList, int status) {
LOGGER.info("sellerBatchUpdateStatus in, skupList is {}, status is {}", skupList, status);
// 卖家修改上下架状态:*1:可售(支付保证金),商家上架,104:商家下架
int updateNum = storagePriceMapper.batchUpdateStatus(skupList, status);
if(updateNum == 0) {
throw new ServiceException(400, "更新上架状态失败!");
}
//获取storageId
List<StoragePrice> storagePriceList = storagePriceMapper.selectBySkupList(skupList);
Map<Integer, List<StoragePrice>> storagePriceMap = storagePriceList.stream().collect(Collectors.groupingBy(StoragePrice::getStorageId));
List<Storage> storageReqList = Lists.newArrayList();
for(Entry<Integer, List<StoragePrice>> entry : storagePriceMap.entrySet()) {
Storage storage = new Storage();
storage.setId(entry.getKey());
if(status == 1) {
storage.setStorageNum(entry.getValue().size());
}else if(status == 104) {
storage.setStorageNum(-entry.getValue().size());
}
storageReqList.add(storage);
}
updateNum = storageMapper.batchAddStorageNum(storageReqList);
if(updateNum != storageReqList.size()) {
throw new ServiceException(400, "更新库存数量失败!");
}
}
@Override
public void saleSkup(Integer productId, Integer skup) {
checkParamValid(productId, skup);
checkProductStatus(productId);
... ...