Authored by chenchao

add all function 4 not entry seller

... ... @@ -3,11 +3,14 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.OrdersPrePay;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface OrdersPrePayMapper {
int insertOnDuplicateUpdate(OrdersPrePay record);
OrdersPrePay selectByUidAndOrderCode(@Param("uid") Integer uid, @Param("orderCode") Long orderCode);
List<OrdersPrePay> selectByOrderCodes(@Param("orderCodes") Collection<Long> orderCodes);
}
\ No newline at end of file
... ...
... ... @@ -14,7 +14,7 @@ public interface SellerChangePriceRecordMapper {
SellerChangePriceRecord selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SellerChangePriceRecord record);
int updateByOrderCodeNStatus(SellerChangePriceRecord record);
List<SellerChangePriceRecord> selectByPreOrderCode(Long preOrderCode);
... ...
package com.yohoufo.dal.order.model;
import lombok.Data;
@Data
public class SellerChangePriceRecord {
private Integer id;
... ... @@ -13,81 +16,12 @@ public class SellerChangePriceRecord {
private Short status;
private Short sourceStatus;
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
... ...
... ... @@ -27,4 +27,15 @@
where order_code = #{orderCode,jdbcType=BIGINT} and uid = #{uid,jdbcType=INTEGER}
</select>
<select id="selectByOrderCodes" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from orders_pre_pay
where order_code IN
<foreach collection="orderCodes" item="" open="(" close=")" separator=",">
#{orderCode,jdbcType=BIGINT}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -85,7 +85,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord">
<update id="updateByOrderCodeNStatus" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord">
update seller_change_price_record
<set>
<if test="status != null">
... ... @@ -98,7 +98,7 @@
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where order_code = #{orderCode,jdbcType=BIGINT}
where order_code = #{orderCode,jdbcType=BIGINT} and status = #{sourceStatus,jdbcType=SMALLINT}
</update>
<select id="selectByPreOrderCode" parameterType="java.lang.Long" resultMap="BaseResultMap">
... ...
... ... @@ -27,6 +27,7 @@ import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.changePrice.NotEntrySellerChangePriceService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -61,6 +62,9 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
@Autowired
private CacheCleaner cacheCleaner;
@Autowired
private NotEntrySellerChangePriceService notEntrySellerChangePriceService;
/**
* 更新订单状态
* @param orderInfo
... ... @@ -68,9 +72,11 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
public int updateOrderStatusPaid(OrderInfo orderInfo){
//
logger.info("in update seller OrderStatus after Paid, orderInfo {}",orderInfo);
Integer uid;
Long orderCode;
SellerOrder sellerOrder = new SellerOrder();
sellerOrder.setOrderCode(orderInfo.getOrderCode());
sellerOrder.setUid(orderInfo.getUid());
sellerOrder.setOrderCode(orderCode=orderInfo.getOrderCode());
sellerOrder.setUid(uid=orderInfo.getUid());
SellerOrderStatus soTargetStatus = SellerOrderStatus.HAS_PAYED;
sellerOrder.setStatus(soTargetStatus.getCode());
... ... @@ -89,9 +95,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
SellerOrderGoods tsog = new SellerOrderGoods();
tsog.setId(skup);
productProxyService.syncSkup(tsog, soTargetStatus.getSkupStatus());
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(orderInfo.getUid()).skup(skup).build();
EventBusPublisher.publishEvent(sopcEvent);
//
notEntrySellerChangePriceService.processAfterChangePriceOrderPaid(uid, orderCode);
}
return updateCnt;
}
... ... @@ -112,6 +117,12 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
productId = sellerOrderGoods.getProductId();
}
inBoxFacade.sellerPaidEarnestMoney(sellerUid=orderInfo.getUid(), prdName,sizeName,productId);
//
int skup = sellerOrder.getSkup();
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(orderInfo.getUid()).skup(skup).build();
EventBusPublisher.publishEvent(sopcEvent);
//
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
... ... @@ -42,6 +43,7 @@ import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.changePrice.NotEntrySellerChangePriceService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -116,13 +118,16 @@ public class SellerOrderCancelService {
@Autowired
MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
private NotEntrySellerChangePriceService notEntrySellerChangePriceService;
/**
* TODO 如何控制好并发,必须控制不能重复转账 退款
* 使用乐观锁,带着查询到的状态且符合条件时再去更新
* @param cancelCase
*/
public void cancel(UserCancelCase cancelCase){
logger.info("in cancel UserCancelCase {}", cancelCase);
logger.info("in seller cancel UserCancelCase {}", cancelCase);
OrderCancelEvent event = (OrderCancelEvent)cancelCase.getEvent();
int uid = event.getUid();
long orderCode = event.getOrderCode();
... ... @@ -136,72 +141,51 @@ public class SellerOrderCancelService {
//case 1: 未支付时
//case 2: 支付完成,没有买家下单
//case 3: 支付完成,有买家下单
cancel(uid, orderCode, codeType);
doCancel(uid, orderCode, codeType);
}
private final static List<Integer> relatedBuyerStatusList = Arrays.asList(OrderStatus.WAITING_PAY.getCode(),
OrderStatus.HAS_PAYED.getCode(), OrderStatus.SELLER_SEND_OUT.getCode(), OrderStatus.PLATFORM_CHECKING.getCode(),
OrderStatus.WAITING_RECEIVE.getCode(), OrderStatus.DONE.getCode());
private BuyerOrder getBuyerOrderBySkup(Integer skup, int uid, Long orderCode, OrderCodeType actor){
private List<BuyerOrder> checkCancelRelatedBuyerOrder(Integer skup, int uid, Long orderCode, OrderCodeType actor){
List<BuyerOrderGoods> pbogList = buyerOrderGoodsMapper.selectBySkups(Arrays.asList(skup));
BuyerOrder buyerOrder = null;
List<BuyerOrder> buyerOrders = null;
if (CollectionUtils.isNotEmpty(pbogList)){
List<Long> orderCodeList = pbogList.parallelStream().map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
List<BuyerOrder> pboList = buyerOrderMapper.selectByOrderCodes(orderCodeList, relatedBuyerStatusList);
if (CollectionUtils.isNotEmpty(pboList)){
if(pboList.size() > 1){
logger.warn("in seller cancel ,related buyer order size {} buyer orderCodeList {} uid {} orderCode {} actor {}",
pboList.size(), orderCodeList, uid, orderCode, actor);
throw new UfoServiceException(501, "订单不能取消");
}
buyerOrder = pboList.get(0);
buyerOrders = buyerOrderMapper.selectByOrderCodes(orderCodeList, relatedBuyerStatusList);
if (CollectionUtils.isNotEmpty(buyerOrders)){
logger.warn("in seller cancel ,related buyer order size {} buyer orderCodeList {} uid {} orderCode {} actor {}",
buyerOrders.size(), orderCodeList, uid, orderCode, actor);
throw new UfoServiceException(501, "订单不能取消");
}
}
return buyerOrder;
return buyerOrders;
}
public int cancel(int uid, long orderCode, OrderCodeType codeType){
/**
* 取消卖家订单(待支付 已上架)
* @param uid
* @param orderCode
* @return
*/
public int cancelSellerOrder(int uid, long orderCode){
int result = 0;
final OrderCodeType codeType = OrderCodeType.SELLER_TYPE;
SellerOrder sellerOrder = null;
BuyerOrder buyerOrder = null;
Integer skup=null;
//seller order code
if (OrderCodeType.SELLER_TYPE.equals(codeType)){
sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
return result;
}
skup = sellerOrder.getSkup();
buyerOrder = getBuyerOrderBySkup(skup, uid, orderCode, codeType);
}
//buyer order code
if (OrderCodeType.BUYER_TYPE.equals(codeType)){
buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), orderCode);
sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup());
if (Objects.isNull(sellerOrder)){
return result;
}
skup = sellerOrder.getSkup();
}
Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null);
logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
if (Objects.isNull(status)){
sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
return result;
}
List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanCancelStatus();
if (!sellerCanCancelStatus.contains(status)){
logger.warn("seller cancel can not execute in this status, uid {} orderCode {}, status {}", uid, orderCode, status);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
//TODO check BuyerOrder
skup = sellerOrder.getSkup();
List<BuyerOrder> buyerOrders = checkCancelRelatedBuyerOrder(skup, uid, orderCode, codeType);
//target seller Order Status
SellerOrderStatus targetSOStatus;
Integer status = checkAndAcquireStatus(sellerOrder);
//case 1: 未支付时
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
//target seller Order Status
SellerOrderStatus targetSOStatus;
logger.info("in seller cancel waiting pay, uid {} skup {} orderCode {}", uid, skup, orderCode);
targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY;
... ... @@ -209,14 +193,109 @@ public class SellerOrderCancelService {
.exceptStatus(SellerOrderStatus.WAITING_PAY).targetStatus(targetSOStatus).build();
result = cancelBeforeBuyerPayAction(uid, orderCode, skup, statusNode);
}
//case 2: 支付完成,没有买家下单
//case 3: 支付完成,有买家下单
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
logger.info("in seller cancel after paid, uid {} skup {} orderCode {}", uid, skup, orderCode);
//result = cancelAfterPayAction(sellerOrder, buyerOrder, codeType);
int buyOrderCnt = buyerOrders == null ? 0 : buyerOrders.size();
if (buyOrderCnt == 0){
/**case 2: 支付完成,没有买家下单
* actions as blow:
* 1. sellerOrder
* 2. sellerOrderGoods
* 3. 同步product skup状态
*/
result = cancelAfterPayButNotBuyAction(sellerOrder);
}
/**
* case 3: 支付完成,有买家下单
* actions as blow:
* 1. buyerOrder
* 2. sellerOrder
* 3. sellerOrderGoods
* 4. 瓜分保证金 退货款给买家
*/
//查询买家订单,状态是支付成功的
if (buyOrderCnt>0){
//result = cancelAfterPayExistBuyAction(sellerOrder, buyerOrder, codeType);
}
}
return result;
}
private int cancelBuyerOrder(int uid, long orderCode){
int result = 0;
final OrderCodeType codeType = OrderCodeType.BUYER_TYPE;
SellerOrder sellerOrder = null;
BuyerOrder buyerOrder = null;
Integer skup=null;
buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), orderCode);
sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup());
if (Objects.isNull(sellerOrder)){
return result;
}
skup = sellerOrder.getSkup();
Integer status = checkAndAcquireStatus(sellerOrder);
//TODO check BuyerOrder
//case 2: 支付完成,没有买家下单
//case 3: 支付完成,有买家下单
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
logger.info("in seller cancel after paid, uid {} skup {} orderCode {}", uid, skup, orderCode);
result = cancelAfterPayAction(sellerOrder, buyerOrder, codeType);
/**
* case 3: 支付完成,有买家下单
* actions as blow:
* 1. buyerOrder
* 2. sellerOrder
* 3. sellerOrderGoods
* 4. 瓜分保证金 退货款给买家
*/
//查询买家订单,状态是支付成功的
result = cancelAfterPayExistBuyAction(sellerOrder, buyerOrder, codeType);
}
return result;
}
private Integer checkAndAcquireStatus(SellerOrder sellerOrder){
Integer status = Optional.ofNullable(sellerOrder)
.map(SellerOrder::getStatus).orElse(null);
int uid = sellerOrder.getUid();
long orderCode = sellerOrder.getOrderCode();
logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
if (Objects.isNull(status)){
return status;
}
List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanCancelStatus();
if (!sellerCanCancelStatus.contains(status)){
logger.warn("seller cancel can not execute in this status, uid {} orderCode {}, status {}", uid, orderCode, status);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
return status;
}
/**
* 取消的中间代理
* @param uid
* @param orderCode
* @param codeType
* @return
*/
private int doCancel(int uid, long orderCode, OrderCodeType codeType){
int result = 0;
//seller order code
if (OrderCodeType.SELLER_TYPE.equals(codeType)){
//普通卖家主动取消时
notEntrySellerChangePriceService.recordSelfCancelIfPresent(uid, orderCode);
result = cancelSellerOrder(uid, orderCode);
}
//buyer order code
if (OrderCodeType.BUYER_TYPE.equals(codeType)){
result = cancelBuyerOrder(uid, orderCode);
}
return result;
}
... ... @@ -227,6 +306,7 @@ public class SellerOrderCancelService {
long orderCode = orderRequest.getOrderCode();
int result = 0;
notEntrySellerChangePriceService.recordAutoCancelIfPresent(uid, orderCode);
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
... ... @@ -587,10 +667,10 @@ public class SellerOrderCancelService {
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
}
return result;
}
@Deprecated
private int cancelAfterPayAction(SellerOrder sellerOrder, BuyerOrder buyerOrder, OrderCodeType codeType){
final int sellerUid = sellerOrder.getUid();
... ...
package com.yohoufo.order.service.seller;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SellerChangePriceRecordMapper;
import com.yohoufo.dal.order.model.SellerChangePriceRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by chao.chen on 2019/3/22.
*/
@Service
public class SellerChangePriceRecordService {
@Autowired
private SellerChangePriceRecordMapper sellerChangePriceRecordMapper;
public int add(long preOrderCode, int preSkup, long orderCode, int skup){
SellerChangePriceRecord scprDo = new SellerChangePriceRecord();
scprDo.setPreOrderCode(preOrderCode);
scprDo.setPreSkup(preSkup);
scprDo.setStatus(ChangePriceStatus.WAITING_DEAL.getCode());
scprDo.setOrderCode(orderCode);
scprDo.setSkup(skup);
int cdt = DateUtil.getCurrentTimeSecond();
scprDo.setCreateTime(cdt);
scprDo.setUpdateTime(cdt);
return sellerChangePriceRecordMapper.insertSelective(scprDo);
}
}
... ...
package com.yohoufo.order.service.seller.changePrice;
import com.google.common.collect.Lists;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.OrdersPrePayMapper;
import com.yohoufo.dal.order.SellerChangePriceRecordMapper;
import com.yohoufo.dal.order.model.OrdersPrePay;
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.event.OrderCancelEvent;
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.SellerOrderCancelService;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.seller.SellerChangePriceRecordService;
import com.yohoufo.order.service.seller.processor.NESChangePricePrepareProcessor;
import com.yohoufo.order.service.seller.processor.NESChangePricePublishPrepareProcessor;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -20,7 +33,10 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 非入驻的卖家 变价服务类
... ... @@ -52,11 +68,19 @@ public class NotEntrySellerChangePriceService {
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
@Autowired
NESChangePricePublishPrepareProcessor nesChangePricePublishPrepareProcessor;
private NESChangePricePublishPrepareProcessor nesChangePricePublishPrepareProcessor;
@Autowired
NESChangePricePublishExcutor nesChangePricePublishExcutor;
private NESChangePricePublishExcutor nesChangePricePublishExcutor;
@Autowired
private OrdersPrePayMapper ordersPrePayMapper;
@Autowired
private SellerOrderCancelService sellerOrderCancelService;
@Autowired
private SellerChangePriceRecordService sellerChangePriceRecordService;
public boolean isChangePriceOrder(int skup){
... ... @@ -65,8 +89,9 @@ public class NotEntrySellerChangePriceService {
public boolean isChangePriceOrder(long orderCode){
//todo
return false;
//
SellerChangePriceRecord scpr = sellerChangePriceRecordMapper.selectByOrderCode(orderCode);
return Objects.nonNull(scpr);
}
/**
... ... @@ -84,26 +109,22 @@ public class NotEntrySellerChangePriceService {
/**
* change Price 4 Not Entry Seller
* 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)
* @param req
* @return
*/
public OrderSubmitResp changePrice(NESChangePriceReq req){
logger.info("in NotEntrySellerChangePriceService.changePrice, req {}", req);
NESCPOrderContext ctx = nesChangePricePublishPrepareProcessor.buildPublishCtx(req);
//TODO
/*
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();
int preSkup = psog.getId();
SellerOrder sellerOrder = ctx.getSellerOrder();
Long preOrderCode = sellerOrder.getOrderCode();
List<Short> scprs = Lists.newArrayListWithCapacity(2);
... ... @@ -112,26 +133,179 @@ public class NotEntrySellerChangePriceService {
List<SellerChangePriceRecord> scprList = sellerChangePriceRecordMapper.selectByPreOrderCodeNStatus(preOrderCode, scprs);
if (CollectionUtils.isEmpty(scprList)){
logger.info("NotEntrySellerChangePriceService.changePrice there are not WAITING_DEAL or SUCCESS records, req {}", req);
//首次 或 全部失败
return nesChangePricePublishExcutor.publish(ctx);
//todo 屏蔽商品
OrderSubmitResp osResp = nesChangePricePublishExcutor.publish(ctx);
sellerChangePriceRecordService.add(preOrderCode, preSkup,osResp.getOrderCode(), osResp.getSkup() );
return osResp;
}
ChangePriceRecords cpr = splitChangePriceRecords(scprList);
//存在成功处理,有且只有一条才对(不完全正确,多终端操作同一个待变价商品)
if (CollectionUtils.isNotEmpty(cpr.successList)){
logger.warn("in NotEntrySellerChangePriceService.changePrice find ChangePriceRecords been deal successfully, req {}", req);
throw new UfoServiceException(400, "已经变价成功");
}
//没有一条成功处理,但是存在等待处理
if (CollectionUtils.isNotEmpty(cpr.waitingDealList)){
logger.info("NotEntrySellerChangePriceService.changePrice there are WAITING_DEAL records, req {}", req);
//TODO 检查待处理是否被支付(等待支付回调处理)
checkWaitingDeal(cpr.waitingDealList, preSkup);
batchCancel(req.getUid(), cpr.waitingDealList);
}
return null;
}
private void checkWaitingDeal(List<SellerChangePriceRecord> waitingDealList, int preSkup){
List<Long> orderCodes = waitingDealList.parallelStream()
.map(SellerChangePriceRecord::getOrderCode)
.collect(Collectors.toList());
//todo 到支付平台主动查询订单支付状态
//检查相关待支付订单是否存在超时内的预支付记录
List<OrdersPrePay> opps = ordersPrePayMapper.selectByOrderCodes(orderCodes);
if (CollectionUtils.isNotEmpty(opps)){
int secondsOfTimelimit = OrderInfo.SELLER_PAY_TIMEOUT;
int currentSeconds = DateUtil.getCurrentTimeSecond();
int startSeconds = currentSeconds - secondsOfTimelimit;
long prePayCnt = opps.stream().filter(opp -> opp.getCreateTime() > startSeconds).count();
if (prePayCnt > 0){
logger.warn("in checkWaitingDeal find exist prepay record, preSkup {}", preSkup);
throw new UfoServiceException(401, "请取消待支付的变价订单");
}
}
}
static class ChangePriceRecords{
List<SellerChangePriceRecord> successList;
List<SellerChangePriceRecord> waitingDealList;
}
ChangePriceRecords splitChangePriceRecords(List<SellerChangePriceRecord> scprList){
List<SellerChangePriceRecord> successList = new ArrayList<>(scprList.size());
List<SellerChangePriceRecord> waitingDealList = new ArrayList<>(scprList.size());
for(SellerChangePriceRecord scpr : scprList){
if (ChangePriceStatus.WAITING_DEAL.getCode() == scpr.getStatus()){
waitingDealList.add(scpr);
}
if (ChangePriceStatus.SUCCESS.getCode() == scpr.getStatus()){
successList.add(scpr);
}
}
ChangePriceRecords cpr = new ChangePriceRecords();
cpr.successList = successList;
cpr.waitingDealList = waitingDealList;
return cpr;
}
/**
*
*@param orderCode 支付成功的订单
*/
public void processAfterChangePriceOrderPaid(long orderCode){
//TODO
//1. 待支付订单 待上架商品
//2. 待变价skup进行下架
public void processAfterChangePriceOrderPaid(int uid, long orderCode){
logger.info("process After ChangePriceOrder Paid, uid {} orderCode {}", uid, orderCode);
//1. 已支付变价订单对应的记录状态变更
//2. 待变价skup进行下架-> 退还保证金
SellerChangePriceRecord scpr = sellerChangePriceRecordMapper.selectByOrderCode(orderCode);
if (Objects.isNull(scpr)) {
logger.warn("process After ChangePriceOrder Paid not a ChangePriceOrder, uid {} orderCode {}", uid, orderCode);
return;
}
if(recordSuccess(scpr.getOrderCode(), ChangePriceStatus.WAITING_DEAL)==0){
return;
}
long preOrderCode = scpr.getPreOrderCode();
sellerOrderCancelService.cancelSellerOrder(uid, preOrderCode);
}
public void batchCancel(int uid, List<SellerChangePriceRecord> scprList){
for(SellerChangePriceRecord scpr : scprList){
SellerOrderCancelReq req = SellerOrderCancelReq.builder().uid(uid)
.orderCode(scpr.getOrderCode()).build();
try {
cancel(req);
}catch (Exception ex){
logger.warn("in NotEntrySellerChangePriceService.batchCancel occur exception req {}", req, ex);
continue;
}
}
}
public int cancel(SellerOrderCancelReq req){
logger.info("not entry seller change price cancel order,req {}", req);
int result = 0;
int uid = req.getUid();
long orderCode = req.getOrderCode();
if ((result=recordFail(orderCode, ChangePriceStatus.FIFO, ChangePriceStatus.WAITING_DEAL))>0) {
sellerOrderCancelService.cancelSellerOrder(uid, orderCode);
}
//
return result;
}
private int recordSuccess(long orderCode,ChangePriceStatus sourceStatus){
SellerChangePriceRecord scprc = new SellerChangePriceRecord();
scprc.setOrderCode(orderCode);
scprc.setStatus(ChangePriceStatus.SUCCESS.getCode());
scprc.setUpdateTime(DateUtil.getCurrentTimeSecond());
scprc.setSourceStatus(sourceStatus.getCode());
return sellerChangePriceRecordMapper.updateByOrderCodeNStatus(scprc);
}
/**
* 卖家主动取消
* @param uid
* @param orderCode
* @return
*/
public int recordSelfCancelIfPresent(int uid, long orderCode){
ChangePriceStatus tcps = ChangePriceStatus.SELF_CANCEL,
scps = ChangePriceStatus.WAITING_DEAL;
return recordFailIfPresent(uid, orderCode, tcps, scps);
}
/**
* 卖家主动取消
* @param uid
* @param orderCode
* @return
*/
public int recordAutoCancelIfPresent(int uid, long orderCode){
ChangePriceStatus tcps = ChangePriceStatus.TIME_OUT,
scps = ChangePriceStatus.WAITING_DEAL;
return recordFailIfPresent(uid, orderCode, tcps, scps);
}
private int recordFailIfPresent(int uid, long orderCode, ChangePriceStatus tcps, ChangePriceStatus sourceStatus){
logger.info("record Fail If Present SellerChangePriceRecord,uid {} orderCode {} target status {}",
uid, orderCode, tcps);
if (isChangePriceOrder(orderCode)){
return 0;
}
SellerChangePriceRecord scprc = new SellerChangePriceRecord();
scprc.setOrderCode(orderCode);
scprc.setStatus(tcps.getCode());
scprc.setUpdateTime(DateUtil.getCurrentTimeSecond());
scprc.setRemark(tcps.getDesc());
scprc.setSourceStatus(sourceStatus.getCode());
return sellerChangePriceRecordMapper.updateByOrderCodeNStatus(scprc);
}
public int recordFail(long orderCode, ChangePriceStatus cps,ChangePriceStatus sourceStatus){
SellerChangePriceRecord scprc = new SellerChangePriceRecord();
scprc.setOrderCode(orderCode);
scprc.setStatus(cps.getCode());
scprc.setUpdateTime(DateUtil.getCurrentTimeSecond());
scprc.setRemark(cps.getDesc());
scprc.setSourceStatus(sourceStatus.getCode());
return sellerChangePriceRecordMapper.updateByOrderCodeNStatus(scprc);
}
}
... ...
... ... @@ -8,7 +8,6 @@ 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.common.Payment;
... ... @@ -20,7 +19,6 @@ import com.yohoufo.order.model.request.PrdQueryReq;
import com.yohoufo.order.service.impl.SellerAddressService;
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;
... ... @@ -58,10 +56,6 @@ public class NESChangePricePublishPrepareProcessor extends AbsPublishPrepareProc
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);
... ...