Authored by Lixiaodi

Merge branch 'dev_order' of http://git.yoho.cn/ufo/yohoufo-fore into dev_order

# Conflicts:
#	dal/src/main/java/com/yohoufo/dal/order/SellerWalletMapper.java
#	dal/src/main/resources/META-INF/mybatis/order/SellerWalletMapper.xml
Showing 21 changed files with 729 additions and 180 deletions
... ... @@ -5,7 +5,6 @@ import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.order.model.SellerWallet;
public interface SellerWalletMapper {
int deleteByPrimaryKey(Integer id);
int insert(SellerWallet record);
... ... @@ -17,10 +16,14 @@ public interface SellerWalletMapper {
int updateByPrimaryKey(SellerWallet record);
<<<<<<< HEAD
SellerWallet selectByUidAndType(@Param("uid") Integer uid, @Param("type") int type);
int addMoney(SellerWallet sw);
int returnMoney(SellerWallet sw);
=======
SellerWallet selectByUidNType(SellerWallet condition);
>>>>>>> 988aa54ed0e0d3be7e1329ab598ffaf885dfe261
}
\ 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
... ...
... ... @@ -24,6 +24,15 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWallet" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
<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,
update_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
... ...
... ... @@ -10,7 +10,6 @@ import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.impl.SellerOrderCancelService;
import com.yohoufo.order.service.impl.SellerOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -50,7 +49,8 @@ public class SellerOrderController {
@RequestParam(name = "storage_id", required = true)int storage_id,
@RequestParam(name="price", required = true)String price,
@RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException {
SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid).storageId(storage_id).price(price).build();
SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid).storageId(storage_id).price(price)
.num(num).build();
logger.info("in ufo.sellerOrder.computePublishPrd, req {}", req);
SoldPrdComputeBo computeBo = sellerOrderService.computePublishPrd(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
... ... @@ -96,11 +96,12 @@ public class SellerOrderController {
@ResponseBody
public ApiResponse batchCancel(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "batchNo", required = true)String batchNo,
@RequestParam(name="num", defaultValue = "1", required = false)int num
@RequestParam(name="num", defaultValue = "1", required = false)int num,
@RequestParam(name = "skupList", required = true)String skupList
) throws GatewayException {
SellerOrderBatchCancelReq req = SellerOrderBatchCancelReq.builder()
.uid(uid).batchNo(batchNo).storageNum(num)
.uid(uid).batchNo(batchNo).storageNum(num).skupList(skupList)
.build();
logger.info("in ufo.sellerOrder.batchCancel, req {}", req);
boolean result = sellerOrderService.batchCancel(req);
... ... @@ -196,11 +197,12 @@ public class SellerOrderController {
public ApiResponse batchChangePrice(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "price", required = true)String price,
@RequestParam(name = "batchNo", required = true)String batchNo,
@RequestParam(name="num", defaultValue = "1", required = false)int num
@RequestParam(name = "skupList", required = true)String skupList
) throws GatewayException {
BatchChangePriceReq req = BatchChangePriceReq.builder()
.uid(uid).price(price).storageNum(num)
.batchNo(batchNo)
.uid(uid).price(price)
.batchNo(batchNo).skupList(skupList)
.build();
logger.info("in ufo.sellerOrder.batchChangePrice, req {}", req);
BatchChangePriceResp result = sellerOrderService.batchChangePrice(req);
... ...
... ... @@ -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,32 +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.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.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;
... ... @@ -36,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;
... ... @@ -64,7 +63,6 @@ import java.util.stream.Collectors;
@Slf4j
public class SellerOrderService implements IOrderListService, IOrderDetailService {
@Autowired
private SellerOrderMapper sellerOrderMapper;
... ... @@ -81,9 +79,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
private SellerOrderSubmitHandler orderSubmitHandler;
@Autowired
private UserProxyService userProxyService;
@Autowired
private SellerOrderListService sellerOrderListService;
@Autowired
... ... @@ -107,16 +102,27 @@ 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);
int uid = req.getUid();
if(uid <= 0){
log.warn("in computePublishPrd uid illegal , req {}", req);
throw new GatewayException(400, "用户ID错误");
}
//
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
int num;
if ((num = req.getNum())<=0){
log.warn("in computePublishPrd num illegal , req {}", req);
throw new GatewayException(400, "非法数量值");
}
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
... ... @@ -133,42 +139,15 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
throw new GatewayException(400, "价格须为以9结尾的正整数");
}
BigDecimal prdPrice = null;
try{
prdPrice = new BigDecimal(price);
}catch (Exception e){
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
return null;
}
checkPrice(storageId, prdPrice, false);
return buildSoldPrdComputeBo(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, "别闹了,这个售价没有收入");
throw new GatewayException(400, "非法数字");
}
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
return buildSoldPrdComputeBo(uid, num, prdPrice);
}
/**
... ... @@ -179,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);
... ... @@ -240,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
... ... @@ -353,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 ){
... ... @@ -439,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;
}
... ... @@ -480,10 +380,12 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
public SoldPrdComputeBo buildSoldPrdComputeBo(BigDecimal prdPrice){
private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, BigDecimal prdPrice){
SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
/**
* 验证是否是入驻商家
*/
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, computeResult, num, prdPrice);
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
return computeBo;
}
... ... @@ -501,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;
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.request.UserAddressReqBO;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.order.convert.AddressInfoConvertor;
import com.yohoufo.order.model.AddressInfo;
import org.apache.commons.lang3.StringUtils;
... ... @@ -38,6 +39,9 @@ public class UserProxyService {
@Value("${uic.url:http://uic.yohoops.org/uic}")
private String uicUrl;
@Autowired
private UfoServiceCaller ufoServiceCaller;
/**
* 获取用户信息
* @param uid
... ... @@ -133,4 +137,18 @@ public class UserProxyService {
}
return mobile;
}
public boolean isEntryShop(int uid){
//入驻商户 method=ufo.user.isStoredSeller ,入参 uid
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);
}
logger.info("judge user is entry shop, uid {} resp {}", uid, userInfo);
return (userInfo == null || userInfo.getData() == null) ? false : (boolean) userInfo.getData();
}
}
... ...
... ... @@ -6,7 +6,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>parent</artifactId>
<version>1.4.7-SNAPSHOT</version>
<version>1.4.8-SNAPSHOT</version>
</parent>
<groupId>com.yohoufo.fore</groupId>
... ... @@ -18,7 +18,7 @@
<properties>
<qiniu.version>7.0.5</qiniu.version>
<project-name>yohoufo-fore</project-name>
<model.version>test-1.0-SNAPSHOT</model.version>
<model.version>2.0-SNAPSHOT</model.version>
</properties>
<dependencyManagement>
... ...
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);
... ...