Authored by mali

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

Showing 34 changed files with 834 additions and 181 deletions
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.SellerChangePriceRecord;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface SellerChangePriceRecordMapper {
int insert(SellerChangePriceRecord record);
int insertSelective(SellerChangePriceRecord record);
SellerChangePriceRecord selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SellerChangePriceRecord record);
List<SellerChangePriceRecord> selectByPreOrderCode(Long preOrderCode);
List<SellerChangePriceRecord> selectByPreOrderCodeNStatus(@Param("preOrderCode") Long preOrderCode,
@Param("statusList") Collection<Short> statusList);
SellerChangePriceRecord selectByOrderCode(Long orderCode);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class SellerChangePriceRecord {
private Integer id;
private Integer preSkup;
private Long preOrderCode;
private Integer skup;
private Long orderCode;
private Short status;
private String remark;
private Integer createTime;
private Integer updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPreSkup() {
return preSkup;
}
public void setPreSkup(Integer preSkup) {
this.preSkup = preSkup;
}
public Long getPreOrderCode() {
return preOrderCode;
}
public void setPreOrderCode(Long preOrderCode) {
this.preOrderCode = preOrderCode;
}
public Integer getSkup() {
return skup;
}
public void setSkup(Integer skup) {
this.skup = skup;
}
public Long getOrderCode() {
return orderCode;
}
public void setOrderCode(Long orderCode) {
this.orderCode = orderCode;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
... ...
<?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.SellerChangePriceRecordMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.SellerChangePriceRecord">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="pre_skup" jdbcType="INTEGER" property="preSkup" />
<result column="pre_order_code" jdbcType="BIGINT" property="preOrderCode" />
<result column="skup" jdbcType="INTEGER" property="skup" />
<result column="order_code" jdbcType="BIGINT" property="orderCode" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, pre_skup, pre_order_code, skup, order_code, status, remark, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where id = #{id,jdbcType=INTEGER}
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord" useGeneratedKeys="true">
insert into seller_change_price_record (pre_skup, pre_order_code, skup,
order_code, status, remark,
create_time, update_time)
values (#{preSkup,jdbcType=INTEGER}, #{preOrderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER},
#{orderCode,jdbcType=BIGINT}, #{status,jdbcType=SMALLINT}, #{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord" useGeneratedKeys="true">
insert into seller_change_price_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="preSkup != null">
pre_skup,
</if>
<if test="preOrderCode != null">
pre_order_code,
</if>
<if test="skup != null">
skup,
</if>
<if test="orderCode != null">
order_code,
</if>
<if test="status != null">
status,
</if>
<if test="remark != null">
remark,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="preSkup != null">
#{preSkup,jdbcType=INTEGER},
</if>
<if test="preOrderCode != null">
#{preOrderCode,jdbcType=BIGINT},
</if>
<if test="skup != null">
#{skup,jdbcType=INTEGER},
</if>
<if test="orderCode != null">
#{orderCode,jdbcType=BIGINT},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord">
update seller_change_price_record
<set>
<if test="status != null">
status = #{status,jdbcType=SMALLINT},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where order_code = #{orderCode,jdbcType=BIGINT}
</update>
<select id="selectByPreOrderCode" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where pre_order_code = #{preOrderCode,jdbcType=BIGINT}
</select>
<select id="selectByOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where order_code = #{orderCode,jdbcType=BIGINT}
</select>
<select id="selectByPreOrderCodeNStatus" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where pre_order_code = #{preOrderCode,jdbcType=BIGINT}
<if test="status != null">
and status in
<foreach collection="statusList" item="status" open="(" close=")" separator=",">
#{status,jdbcType=SMALLINT}
</foreach>
</if>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -16,7 +16,7 @@ import lombok.experimental.Builder;
@NoArgsConstructor
@AllArgsConstructor
public class BatchPublishTailEvent extends Event {
private int sellerUid;
private SellerOrderSubmitHandler.ForkJoinResult fjr;
private SellerWallet sellerWallet;
private boolean isSurper;
... ...
package com.yohoufo.order.model;
import com.yohoufo.dal.order.model.SellerOrder;
import lombok.Data;
/**
* Created by chao.chen on 2019/3/22.
*/
@Data
public class NESCPOrderContext extends SellerOrderContext{
private SellerOrder sellerOrder;
}
... ...
... ... @@ -14,7 +14,6 @@ import java.math.BigDecimal;
*/
@Data
public class SellerOrderContext {
private int uid;
... ...
package com.yohoufo.order.model.dto;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.dal.order.model.SellerWallet;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import java.math.BigDecimal;
/**
* Created by chao.chen on 2019/3/22.
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ImPrdNode{
Integer uid;
boolean isSuper;
SellerWallet sellerWallet;
Integer storageId;
BigDecimal salePrice;
int storageNum;
BigDecimal goodsPaymentRate;
AddressInfo hiddenBackAddress;
AddressInfo noHiddenBackAddress;
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.SellerOrderMetaMapper;
... ... @@ -18,6 +19,7 @@ import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohoufo.order.constants.MetaKey;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.order.event.SellerOrderPriceChangeEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.mq.DelayTime;
... ... @@ -78,14 +80,18 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
int updateCnt = sellerOrderMapper.updateByOrderCode(sellerOrder);
if (1 == updateCnt) {
//
int skup;
SellerOrderGoods targetSog = new SellerOrderGoods();
targetSog.setId(orderInfo.getSkup());
targetSog.setId(skup=orderInfo.getSkup());
targetSog.setStatus(soTargetStatus.getSkupStatus().getCode());
sellerOrderGoodsMapper.updateByPrimaryKeySelective(targetSog);
//sync 2 product biz model
SellerOrderGoods tsog = new SellerOrderGoods();
tsog.setId(orderInfo.getSkup());
tsog.setId(skup);
productProxyService.syncSkup(tsog, soTargetStatus.getSkupStatus());
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(orderInfo.getUid()).skup(skup).build();
EventBusPublisher.publishEvent(sopcEvent);
}
return updateCnt;
}
... ...
... ... @@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
... ... @@ -16,6 +17,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrderMeta;
import com.yohoufo.dal.order.model.SellerTaskDetail;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.SellerOrderPriceChangeEvent;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
... ... @@ -162,6 +164,10 @@ public abstract class AbstractSellerAdjustPriceTaskHandler extends AbstractSelle
//通知商品
try {
productProxyService.batchUpdatePrice(successSkups, newSalePrice);
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(uid).skup(successSkups.iterator().next()).build();
EventBusPublisher.publishEvent(sopcEvent);
log.info("[{}-{}] notify product to update price for skups:{},salePrice:{} success", uid, taskId, successSkups, newSalePrice);
} catch (Exception ex) {
log.error("[{}-{}] exception happened when notify product to update price,skups:{},salePrice:{}",
... ...
... ... @@ -2,9 +2,11 @@ package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.event.BatchPublishTailEvent;
import com.yohoufo.order.event.SellerOrderPriceChangeEvent;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -31,10 +33,12 @@ public class BatchPublishTailHandler implements IEventHandler<BatchPublishTailEv
@Subscribe
public void handle(BatchPublishTailEvent event) {
logger.info("in handle BatchPublishTailEvent event {}", event);
batchPublishTailProcess(event.getFjr(), event.getSellerWallet(), event.isSurper());
batchPublishTailProcess(event.getFjr(), event.getSellerWallet(), event.isSurper(), event.getSellerUid());
}
private void batchPublishTailProcess(SellerOrderSubmitHandler.ForkJoinResult fjr, SellerWallet sellerWallet, boolean isSurper){
private void batchPublishTailProcess(SellerOrderSubmitHandler.ForkJoinResult fjr,
SellerWallet sellerWallet, boolean isSurper,
int sellerUid){
// (异步实现)记录保证金流水
if(!isSurper) {
... ... @@ -46,7 +50,11 @@ public class BatchPublishTailHandler implements IEventHandler<BatchPublishTailEv
}
//(异步实现)同步数据到prd,记录支付,
productProxyService.batchCreateSkup(fjr.getSellerOrderGoodsList());
productProxyService.sellerBatchUpdateStatus(fjr.getSkupIds(), ProductProxyService.PrdShelvelStatus.on);
List<Integer> skups;
productProxyService.sellerBatchUpdateStatus(skups=fjr.getSkupIds(), ProductProxyService.PrdShelvelStatus.on);
//通知其他卖家价格
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(sellerUid).skup(skups.get(0)).build();
EventBusPublisher.publishEvent(sopcEvent);
}
}
... ...
... ... @@ -9,7 +9,6 @@ import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
... ... @@ -28,7 +27,7 @@ import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.service.AbsSellerOrderViewService;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.seller.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
... ...
... ... @@ -23,10 +23,7 @@ import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.common.DelStatus;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.event.BatchPublishTailEvent;
import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
import com.yohoufo.order.event.EventHandlerContainer;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.event.*;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.model.request.OrderListRequest;
... ... @@ -44,7 +41,7 @@ import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.handler.*;
import com.yohoufo.order.service.impl.processor.*;
import com.yohoufo.order.service.seller.processor.*;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.proxy.InBoxFacade;
... ... @@ -215,7 +212,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
private OrderSubmitResp publishSinglePrd(SellerOrderSubmitReq req, SellerOrderContext context) throws GatewayException {
public OrderSubmitResp publishSinglePrd(SellerOrderSubmitReq req, SellerOrderContext context){
int storageId = context.getStorageId();
int uid = context.getUid();
// step 2: create order, set status(not pay)
... ... @@ -668,6 +665,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
List<RedisKeyBuilder> skupDetailRKBs = getSkupDetailRKBs(sampleSog);
skupDetailRKBs.add(CacheKeyBuilder.orderListKey(req.getUid(), TabType.SELL.getValue()));
cacheCleaner.delete(skupDetailRKBs);
//
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(uid).skup(skupSet.iterator().next()).build();
EventBusPublisher.publishEvent(sopcEvent);
}else {
//1.2 划账失败后
failCnt = skupMap.size();
... ... @@ -794,9 +795,12 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
cacheCleaner.cleanList(uid, TabType.SELL.getValue());
// (异步实现)记录保证金流水
//(异步实现)同步数据到prd,记录支付,
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder().isSurper(isSurper)
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder()
.sellerUid(uid)
.isSurper(isSurper)
.fjr(fjr).sellerWallet(sellerWallet).build();
EventBusPublisher.publishEvent(bpte);
countDownLatch.countDown();
}catch (Exception ex){
countDownLatch.countDown();
... ... @@ -911,9 +915,4 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
}
}
... ...
... ... @@ -21,7 +21,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.dto.PrdOverPriceDTO;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.SellerGoodsListRequest;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.seller.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.utils.LoggerUtils;
... ...
package com.yohoufo.order.service.seller;
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.event.BatchPublishTailEvent;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.ImPrdNode;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.SellerService;
import com.yohoufo.order.service.impl.SkupBatchService;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.proxy.ProductProxyService;
import lombok.Data;
import lombok.experimental.Builder;
import com.yohoufo.order.service.seller.processor.ImportPublishPrepareProcessor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -28,24 +25,12 @@ import java.util.Objects;
@Service
public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, SellerOrderSubmitHandler.ForkJoinResult>{
@Builder
@Data
private static class ImPrdNode{
Integer uid;
boolean isSuper;
SellerWallet sellerWallet;
Integer storageId;
BigDecimal salePrice;
int storageNum;
BigDecimal goodsPaymentRate;
AddressInfo hiddenBackAddress;
AddressInfo noHiddenBackAddress;
}
@Autowired
private SellerOrderSubmitHandler orderSubmitHandler;
@Autowired
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
private ImportPublishPrepareProcessor importPublishPrepareProcessor;
@Autowired
private ProductProxyService productProxyService;
... ... @@ -98,29 +83,21 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S
public SellerOrderSubmitHandler.ForkJoinResult publishOne(ImPrdNode node){
Integer uid = node.uid;
boolean isSuper = node.isSuper;
Integer storageId = node.storageId;
BigDecimal salePrice = node.salePrice;
int storageNum = node.storageNum;
AddressInfo hiddenBackAddress = node.hiddenBackAddress;
AddressInfo noHiddenBackAddress = node.noHiddenBackAddress;
Integer uid = node.getUid();
//add GoodsPaymentRate
SellerOrderContext ctx = sellerOrderPrepareProcessor.buildImportPrdCxt(uid, storageId, salePrice, storageNum,
node.getGoodsPaymentRate());
ctx.setBackAddress(noHiddenBackAddress);
ctx.setBackHiddenAddress(hiddenBackAddress);
SellerOrderContext ctx = importPublishPrepareProcessor.buildPublishCtx(node);
int storageNum = node.getStorageNum();
long batchNo = skupBatchService.generateBatchNo(uid, storageNum);
ctx.getSoldProduct().setBatchNo(batchNo);
SellerOrderSubmitHandler.ForkJoinResult fjr;
fjr = orderSubmitHandler.submitMultiple(ctx, storageNum);
// (异步实现)记录保证金流水
//(异步实现)同步数据到prd,记录支付,
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder().isSurper(isSuper)
boolean isSuper = node.isSuper();
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder()
.sellerUid(uid)
.isSurper(isSuper)
.fjr(fjr).sellerWallet(null).build();
EventBusPublisher.publishEvent(bpte);
return fjr;
... ...
package com.yohoufo.order.service.seller;
/**
* Created by chao.chen on 2019/3/22.
*/
public interface PublishPrepareProcessor<I,O> {
O buildPublishCtx(I im);
}
... ...
package com.yohoufo.order.service.seller.changePrice;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.impl.SellerOrderService;
import com.yohoufo.order.service.seller.PublishExcutor;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by chao.chen on 2019/3/22.
*/
@Service
public class NESChangePricePublishExcutor implements PublishExcutor<SellerOrderContext, OrderSubmitResp> {
private Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
SellerOrderService sellerOrderService;
@Override
public OrderSubmitResp publish(SellerOrderContext ctx) {
SellerOrderSubmitReq req = SellerOrderSubmitReq.builder()
.uid(ctx.getUid())
.storageId(ctx.getStorageId()).build();
OrderSubmitResp resp = sellerOrderService.publishSinglePrd(req, ctx);
logger.info("out NESChangePricePublishExcutor.publish req {} OrderSubmitResp {}",
req, resp);
return resp;
}
}
... ...
package com.yohoufo.order.service.seller.changePrice;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
import com.yohoufo.dal.order.SellerChangePriceRecordMapper;
import com.yohoufo.dal.order.model.SellerChangePriceRecord;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.NESCPOrderContext;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.impl.processor.NESChangePricePrepareProcessor;
import com.yohoufo.order.service.seller.processor.NESChangePricePrepareProcessor;
import com.yohoufo.order.service.seller.processor.NESChangePricePublishPrepareProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 非入驻的卖家 变价服务类
* 涉及场景
* TODO case1: 变价计算
* TODO case2:变价待支付订单生成
* TODO case2.1 : 首次 ->
* TODO case2.2: 非首次 ->
* TODO case3:预支付 ->
* TODO case4:支付回调 ->
* TODO case5:主动取消 ->
* TODO case6:超时取消 ->
* TODO case7:订单列表 详情 可售商品 变价入口控制
* 功能点
* TODO F1:记录变价历史
* TODO F2: 失败时 对应变价记录 状态更新 备注原因
* TODO F3: 成功后 变价记录状态 订单状态 商品上架
* TODO F4:并发控制 :是否被并发下单 购买,
* Created by chao.chen on 2019/3/21.
*/
@Service
public class NotEntrySellerChangePriceService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private SellerChangePriceRecordMapper sellerChangePriceRecordMapper;
@Autowired
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
@Autowired
NESChangePricePublishPrepareProcessor nesChangePricePublishPrepareProcessor;
@Autowired
NESChangePricePublishExcutor nesChangePricePublishExcutor;
public boolean isChangePriceOrder(int skup){
return false;
}
public boolean isChangePriceOrder(long orderCode){
//todo
return false;
}
/**
* compute Change Price4 NES(Not Entry Seller)
* @param req
* @return
*/
public SoldPrdComputeBo computeChangePrice(NESChangePriceReq req){
logger.info("in computeChangePrice4NES, req {}", req);
logger.info("in NotEntrySellerChangePriceService.computeChangePrice, req {}", req);
ChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(cppDto.getComputeResult());
return computeBo;
... ... @@ -41,14 +88,36 @@ public class NotEntrySellerChangePriceService {
* @return
*/
public OrderSubmitResp changePrice(NESChangePriceReq req){
logger.info("in NotEntrySellerChangePriceService.changePrice, req {}", req);
NESCPOrderContext ctx = nesChangePricePublishPrepareProcessor.buildPublishCtx(req);
//TODO
/*1. 屏蔽待变价skup
* 1.1 何时恢复
*
* 生成待支付订单,将订单号返回给客户端
/*
step 1. 检查变价记录 seller_change_price_record
1.1 存在时 -> step 3
1.2 不存在时 -> step 2
step 2. 屏蔽待变价skup
2.1 何时恢复
step 3. 取消已有的待支付订单 (修改订单 商品状态 ,变价记录是否记录失败原因)
step 4. 生成待支付订单 待上架的商品,将订单号返回给客户端
step 5. 记录变价记录(新的订单号,新skup)
*/
SellerOrderGoods psog = ctx.getSellerOrderGoods();
int skup = psog.getId();
SellerOrder sellerOrder = ctx.getSellerOrder();
Long preOrderCode = sellerOrder.getOrderCode();
List<Short> scprs = Lists.newArrayListWithCapacity(2);
scprs.add(ChangePriceStatus.WAITING_DEAL.getCode());
scprs.add(ChangePriceStatus.SUCCESS.getCode());
List<SellerChangePriceRecord> scprList = sellerChangePriceRecordMapper.selectByPreOrderCodeNStatus(preOrderCode, scprs);
if (CollectionUtils.isEmpty(scprList)){
//首次 或 全部失败
return nesChangePricePublishExcutor.publish(ctx);
}
//存在成功处理,有且只有一条才对(不完全正确,多终端操作同一个待变价商品)
//没有一条成功处理,但是存在等待处理
return null;
}
... ... @@ -62,4 +131,7 @@ public class NotEntrySellerChangePriceService {
}
}
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.OrderStatus;
... ...
package com.yohoufo.order.service.seller.processor;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.PublishPrepareProcessor;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.Objects;
/**
* Created by chao.chen on 2019/3/22.
*/
public abstract class AbsPublishPrepareProcessor<I,O> extends AbsChangePricePrepareProcessor
implements PublishPrepareProcessor<I,O> {
protected abstract Logger getLogger();
@Autowired
private ProductProxyService productProxyService;
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())) {
getLogger().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());
goodsInfo.setSkupType(context.getSkupType());
return goodsInfo;
}catch (Exception ex){
getLogger().warn("in getProductDetail occur error, uid {}, storageId {}", uid, storageId);
return null;
}
}
}
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.req.SellerBatchChangeReq;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.model.dto.SkupDto;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.google.common.base.Splitter;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.req.BatchChangePriceReq;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SkupDto;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
... ...
package com.yohoufo.order.service.seller.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.bo.PrdPrice;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.ImPrdNode;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.PublishPrepareProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Objects;
/**
* Created by chao.chen on 2019/3/22.
*/
@Service
public class ImportPublishPrepareProcessor extends AbsPublishPrepareProcessor<ImPrdNode,SellerOrderContext>
implements PublishPrepareProcessor<ImPrdNode,SellerOrderContext>
{
Logger logger = LoggerUtils.getSellerOrderLogger();
@Override
protected Logger getLogger() {
return logger;
}
@Override
public SellerOrderContext buildPublishCtx(ImPrdNode node) {
Integer uid = node.getUid();
Integer storageId = node.getStorageId();
BigDecimal salePrice = node.getSalePrice();
int storageNum = node.getStorageNum();
SellerOrderContext ctx = buildImportPrdCxt(uid, storageId, salePrice, storageNum,
node.getGoodsPaymentRate());
AddressInfo hiddenBackAddress = node.getHiddenBackAddress();
AddressInfo noHiddenBackAddress = node.getNoHiddenBackAddress();
ctx.setBackAddress(noHiddenBackAddress);
ctx.setBackHiddenAddress(hiddenBackAddress);
return ctx;
}
/**
* 批量导入时 构建单个skup使用
* @param uid
* @param storageId
* @param salePrice
* @param storageNum
* @return
*/
private SellerOrderContext buildImportPrdCxt(Integer uid, Integer storageId, BigDecimal salePrice, int storageNum,
BigDecimal goodsPaymentRate){
if (uid <= 0){
logger.warn("buildImportPrdCxt uid illegal , uid {}", uid);
throw new UfoServiceException(400, "Uid 错误");
}
if (storageId <=0 ){
logger.warn("buildImportPrdCxt storageId illegal , uid {}", uid);
throw new UfoServiceException(400, "storageId 错误");
}
//
SellerOrderContext context = new SellerOrderContext();
context.setUid(uid);
context.setStorageId(storageId);
context.setSalePrice(salePrice);
SkupType skupType = SkupType.IN_STOCK;
context.setSkupType(skupType);
//TODO set noHiddenBackAddress & hiddenBackAddress
//context.setBackAddress(noHiddenBackAddress);
//context.setBackHiddenAddress(hiddenBackAddress);
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = getProductDetail(context);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
logger.warn("in buildImportPrdCxt storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
if (storageNum <=0){
logger.warn("in buildBatchSellerOrderContext storageNum illegal , uid {}, storageId {} storageNum {}",
uid, storageId, storageNum);
throw new ServiceException(ServiceError.SELLER_PUBLISH_PRD_NUM_ILLEGAL);
}
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
goodsInfo.setStorageNum(storageNum);
// compute every fee from price
PrdPrice prdPrice = new PrdPrice();
prdPrice.setCanPublish(true);
prdPrice.setGoodsPaymentRate(goodsPaymentRate);
SellerOrderComputeResult pcc = OrderAssist.buildPersonalComputeConfig(prdPrice);
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice(), pcc);
logger.info("in buildImportPrdCxt , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
return context;
}
}
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
... ... @@ -25,6 +26,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
... ... @@ -37,7 +39,7 @@ public class NESChangePricePrepareProcessor extends AbsChangePricePrepareProcess
protected final Logger logger = LoggerUtils.getSellerOrderLogger();
private void checkGoodsStatus(SellerOrderGoods psog){
public void checkGoodsStatus(SellerOrderGoods psog){
if (SkupStatus.CAN_SELL.getCode() != psog.getStatus().intValue()){
logger.warn("in NESChangePricePrepareProcessor.checkGoodsStatus not can sale, SellerOrderGoods {}", psog);
throw new UfoServiceException(400, "商品不是可售状态");
... ... @@ -105,8 +107,13 @@ public class NESChangePricePrepareProcessor extends AbsChangePricePrepareProcess
BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
//build one skup Map
Map<Integer, SkupDto> skupMap = Maps.newHashMapWithExpectedSize(1);
SkupDto skupDto = SkupDto.builder().sellerOrder(sellerOrder).sellerOrderGoods(psog).build();
skupMap.put(skup, skupDto);
return ChangePricePrepareDTO.builder()
.baseSellerOrderGoods(psog)
.skupMap(skupMap)
.prdPrice(prdPrice)
.salePrice(salePrice)
.diffEarnestMoney(diffEarnestMoney)
... ...
package com.yohoufo.order.service.seller.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.bo.PrdPrice;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.NESCPOrderContext;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SkupDto;
import com.yohoufo.order.model.request.PrdQueryReq;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.PublishPrepareProcessor;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import org.slf4j.Logger;
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 2019/3/22.
*/
@Service
public class NESChangePricePublishPrepareProcessor extends AbsPublishPrepareProcessor<NESChangePriceReq, SellerOrderContext>
implements PublishPrepareProcessor<NESChangePriceReq, SellerOrderContext> {
final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
@Override
public NESCPOrderContext buildPublishCtx(NESChangePriceReq im) {
return buildSellerOrderContext(im);
}
private NESCPOrderContext buildSellerOrderContext(NESChangePriceReq req) {
int uid = req.getUid();
if (uid <= 0){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
throw new UfoServiceException(400, "参数[uid]错误");
}
if (uid <=0){
logger.warn("in ChangePrice uid illegal, req {}", req);
throw new UfoServiceException(400, "参数uid非法");
}
int skup = req.getSkup();
if (skup<=0){
logger.warn("in ChangePrice find illegal skup code, req {}", req);
throw new UfoServiceException(400, "参数skup非法");
}
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
if (Objects.isNull(psog)){
logger.warn("in ChangePrice can not find skup in sys, req {}", req);
throw new UfoServiceException(400, "商品不存在");
}
//检查是否有买家下单
nesChangePricePrepareProcessor.checkGoodsStatus(psog);
Integer puid = psog.getUid();
if (!puid.equals(uid)){
logger.warn("in ChangePrice can not find one hacker , req {} sys-uid {}", req, puid);
throw new UfoServiceException(400, "你是猴子么");
}
//check whether exists waiting pay order of skup
SkupDto skupOfUnChange = nesChangePricePrepareProcessor.checkExistWaitingBuyerPay(psog);
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
BigDecimal preSalePrice = psog.getGoodsPrice();
//check old price vs new price
checkChangeNecessary(skup, preSalePrice, salePrice);
String tips = null;
PrdPrice prdPrice;
int storageId = psog.getStorageId();
PrdQueryReq pqr = PrdQueryReq.builder()
.uid(uid).prdPrice(salePrice).storageId(storageId).build();
prdPrice = priceComputePrepareProcessor.checkPriceRange(pqr, true);
SkupType skupType = SkupType.getSkupType(psog.getAttributes());
try {
priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
tips = ex.getErrorMessage();
}
// compute every fee from price
SellerOrderComputeResult pcc = OrderAssist.buildPersonalComputeConfig(prdPrice);
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice, pcc);
//check income
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
//calculate different of earnest Money
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(psog.getId());
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
/*
//the address of send back 2 seller
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){
logger.warn("seller submit addressId need update, uid is {}, storageId is {}, addressId is {}",
uid, storageId, addressId);
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}*/
//
NESCPOrderContext context = new NESCPOrderContext();
context.setUid(uid);
context.setStorageId(storageId);
context.setSalePrice(salePrice);
//
//context.setBackAddress(noHiddenBackAddress);
//context.setBackHiddenAddress(hiddenBackAddress);
//
context.setSkupType(skupType);
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = getProductDetail(context);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
logger.warn("in buildSellerOrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
logger.info("in build not entry Seller Order Context , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
context.setPriceOverFlowTips(tips);
return context;
}
@Override
protected Logger getLogger() {
return this.logger;
}
}
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo;
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.google.common.base.Splitter;
import com.yohobuy.ufo.model.order.common.SkupStatus;
... ... @@ -12,7 +12,6 @@ import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
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;
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.req.SellerBatchChangeReq;
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
... ... @@ -19,6 +19,7 @@ import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.service.seller.PublishPrepareProcessor;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
... ... @@ -33,23 +34,21 @@ import java.util.Objects;
* Created by chao.chen on 2018/11/19.
*/
@Service
public class SellerOrderPrepareProcessor {
public class SellerOrderPrepareProcessor extends AbsPublishPrepareProcessor<SellerOrderSubmitReq, SellerOrderContext>
implements PublishPrepareProcessor<SellerOrderSubmitReq, SellerOrderContext> {
private final Logger log = LoggerUtils.getSellerOrderLogger();
@Autowired
private UserProxyService userProxyService;
@Autowired
private ProductProxyService productProxyService;
@Autowired
private OrderComputeProvider orderComputeProvider;
//@Autowired
//private OrderComputeProvider orderComputeProvider;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
//@Autowired
//private PriceComputePrepareProcessor priceComputePrepareProcessor;
public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) throws GatewayException {
public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) {
SellerOrderContext ctx = buildSellerOrderContext(req);
int uid = ctx.getUid();
boolean isEntryShop = userProxyService.isEntryShop(uid);
... ... @@ -60,7 +59,7 @@ public class SellerOrderPrepareProcessor {
return ctx;
}
public void buildBatchSellerOrderContext(SellerOrderSubmitReq req, SellerOrderContext ctx) throws GatewayException {
private void buildBatchSellerOrderContext(SellerOrderSubmitReq req, SellerOrderContext ctx) {
int storageId = ctx.getStorageId();
int uid = ctx.getUid();
int storageNum = req.getNum();
... ... @@ -80,7 +79,7 @@ public class SellerOrderPrepareProcessor {
}
public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) {
private SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) {
int uid = req.getUid();
if (uid <= 0){
log.warn("uid illegal , uid {}", uid);
... ... @@ -152,102 +151,21 @@ public class SellerOrderPrepareProcessor {
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());
goodsInfo.setSkupType(context.getSkupType());
return goodsInfo;
}catch (Exception ex){
log.warn("in getProductDetail occur error, uid {}, storageId {}", uid, storageId);
return null;
}
}
public boolean checkIsEntry(int uid){
return userProxyService.isEntryShop(uid);
}
/**
* 批量导入时 构建单个skup使用
* @param uid
* @param storageId
* @param salePrice
* @param storageNum
* @return
*/
public SellerOrderContext buildImportPrdCxt(Integer uid, Integer storageId, BigDecimal salePrice, int storageNum,
BigDecimal goodsPaymentRate){
if (uid <= 0){
log.warn("buildImportPrdCxt uid illegal , uid {}", uid);
throw new UfoServiceException(400, "Uid 错误");
}
if (storageId <=0 ){
log.warn("buildImportPrdCxt storageId illegal , uid {}", uid);
throw new UfoServiceException(400, "storageId 错误");
}
//
SellerOrderContext context = new SellerOrderContext();
context.setUid(uid);
context.setStorageId(storageId);
context.setSalePrice(salePrice);
SkupType skupType = SkupType.IN_STOCK;
context.setSkupType(skupType);
//TODO set noHiddenBackAddress & hiddenBackAddress
//context.setBackAddress(noHiddenBackAddress);
//context.setBackHiddenAddress(hiddenBackAddress);
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = getProductDetail(context);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
log.warn("in buildImportPrdCxt storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
if (storageNum <=0){
log.warn("in buildBatchSellerOrderContext storageNum illegal , uid {}, storageId {} storageNum {}",
uid, storageId, storageNum);
throw new ServiceException(ServiceError.SELLER_PUBLISH_PRD_NUM_ILLEGAL);
}
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
goodsInfo.setStorageNum(storageNum);
// compute every fee from price
PrdPrice prdPrice = new PrdPrice();
prdPrice.setCanPublish(true);
prdPrice.setGoodsPaymentRate(goodsPaymentRate);
SellerOrderComputeResult pcc = OrderAssist.buildPersonalComputeConfig(prdPrice);
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice(), pcc);
log.info("in buildImportPrdCxt , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
return context;
@Override
public SellerOrderContext buildPublishCtx(SellerOrderSubmitReq req) {
return buildPublishPrdCtx(req);
}
@Override
protected Logger getLogger() {
return this.log;
}
}
... ...
package com.yohoufo.order.service.impl.processor;
package com.yohoufo.order.service.seller.processor;
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
import com.yohoufo.common.utils.DateUtil;
... ...
... ... @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.common.SellerFuncEnum;
import com.yohoufo.order.BaseWebTest;
import com.yohoufo.order.service.impl.processor.SellerAuthCheckService;
import com.yohoufo.order.service.seller.processor.SellerAuthCheckService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
... ...
... ... @@ -90,6 +90,7 @@ datasources:
- com.yohoufo.dal.order.OrderOverTimeMapper
- com.yohoufo.dal.order.BuyerOrderViewMapper
- com.yohoufo.dal.order.SellerJoinHistoryMapper
- com.yohoufo.dal.order.SellerChangePriceRecordMapper
ufo_promotion:
servers:
... ...
... ... @@ -89,6 +89,7 @@ datasources:
- com.yohoufo.dal.order.OrderOverTimeMapper
- com.yohoufo.dal.order.BuyerOrderViewMapper
- com.yohoufo.dal.order.SellerJoinHistoryMapper
- com.yohoufo.dal.order.SellerChangePriceRecordMapper
ufo_promotion:
servers:
... ...