Authored by mali

Merge branch 'dev_20190403_代码优化'

package com.yohoufo.common.constant;
/**
* 平台发货的标识
*/
public enum EnumPlatformDeliveryStatus {
delivery_to_seller(1,"鉴定中心发货到卖家"),
delivery_to_buyer (2,"鉴定中心发货到买家"),
;
private Integer code;
private String name;
EnumPlatformDeliveryStatus(Integer code, String name){
this.code = code;
this.name = name;
}
public int getCode() {
return code;
}
}
... ...
... ... @@ -51,10 +51,8 @@ public interface BuyerOrderMapper {
// 修改订单状态
int updateStatusByOrderCode(@Param("orderCode")long orderCode, @Param("uid")int uid, @Param("status")int status, @Param("targetStatus")int targetStatus, @Param("currentTime")int currentTime);
//修改订单状态 , 6.8.7版本以后去掉 ,不要引用该方法
//拆分出瑕疵确认状态,系统上线之初存在多种状态的情况
//@Deprecated
//int updateStatusByOrderCodeMoreExpectStatus(@Param("orderCode")long orderCode, @Param("uid")int uid, @Param("expectStatusList")List<Integer> expectStatusList, @Param("targetStatus")int targetStatus, @Param("currentTime")int currentTime);
// 修改订单的平台发货状态
int updatePlatformDeliveryStatusByOrderCode(@Param("orderCode")long orderCode, @Param("uid")int uid, @Param("targetPlatformDeliveryStatus")int targetPlatformDeliveryStatus,@Param("currentTime")int currentTime);
// 根据uid查询订单总数
Integer selectOrderNumByUid(@Param("uid")int uid);
... ...
... ... @@ -41,6 +41,9 @@ public class BuyerOrder {
private Integer sellerOrderStatus;
@Getter@Setter
private Integer platformDeliveryStatus;//1 平台发货给卖家, 2 平台发货给买家
@Getter@Setter
private Integer attributes;
public Integer getId() {
... ...
... ... @@ -19,10 +19,11 @@
<result column="seller_order_status" jdbcType="INTEGER" property="sellerOrderStatus" />
<result column="channel_no" jdbcType="VARCHAR" property="channelNo" />
<result column="attributes" jdbcType="INTEGER" property="attributes" />
<result column="platform_delivery_status" jdbcType="INTEGER" property="platformDeliveryStatus" />
</resultMap>
<sql id="Base_Column_List">
id, uid, order_code, seller_uid, client_type, payment, payment_type, is_cancel, amount,
ship_fee, status, create_time, update_time, buyer_order_status, seller_order_status, channel_no, attributes
ship_fee, status, create_time, update_time, buyer_order_status, seller_order_status, channel_no, attributes,platform_delivery_status
</sql>
... ... @@ -137,13 +138,13 @@
client_type, payment, payment_type,
is_cancel, amount, ship_fee,
status, create_time, update_time,
buyer_order_status, seller_order_status, channel_no, attributes)
buyer_order_status, seller_order_status, channel_no, attributes,platform_delivery_status)
values (#{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT}, #{sellerUid,jdbcType=INTEGER},
#{clientType,jdbcType=INTEGER}, #{payment,jdbcType=INTEGER}, #{paymentType,jdbcType=TINYINT},
#{isCancel,jdbcType=TINYINT}, #{amount,jdbcType=DECIMAL}, #{shipFee,jdbcType=DECIMAL},
#{status,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
#{buyerOrderStatus,jdbcType=INTEGER}, #{sellerOrderStatus,jdbcType=INTEGER}, #{channelNo,jdbcType=VARCHAR},
#{attributes,jdbcType=INTEGER})
#{attributes,jdbcType=INTEGER},#{platformDeliveryStatus,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.BuyerOrder" useGeneratedKeys="true">
insert into buyer_order
... ... @@ -197,6 +198,9 @@
<if test="attributes != null">
attributes,
</if>
<if test="platformDeliveryStatus != null">
platform_delivery_status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="uid != null">
... ... @@ -247,6 +251,9 @@
<if test="attributes != null">
#{attributes,jdbcType=INTEGER},
</if>
<if test="platformDeliveryStatus != null">
#{platformDeliveryStatus,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.BuyerOrder">
... ... @@ -387,18 +394,11 @@
where uid = #{uid,jdbcType=INTEGER} and order_code = #{orderCode,jdbcType=BIGINT} and status = #{status, jdbcType=INTEGER}
</update>
<!--
<update id="updateStatusByOrderCodeMoreExpectStatus">
<update id="updatePlatformDeliveryStatusByOrderCode">
update buyer_order set
status = #{targetStatus,jdbcType=INTEGER},
update_time = #{currentTime,jdbcType=INTEGER}
platform_delivery_status = #{targetPlatformDeliveryStatus,jdbcType=INTEGER}, update_time = #{currentTime,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER} and order_code = #{orderCode,jdbcType=BIGINT}
and status in
<foreach item="item" index="index" collection="expectStatusList" open="(" separator="," close=")">
#{item}
</foreach>
</update>
-->
<select id="selectOrderNumByUid" resultType="java.lang.Integer">
select count(*) from buyer_order where uid = #{uid,jdbcType=INTEGER} and buyer_order_status = 1
... ...
... ... @@ -13,6 +13,7 @@ import com.yohobuy.ufo.model.promotion.request.CouponSendMqBean;
import com.yohobuy.ufo.model.promotion.request.CouponSendType;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.constant.EnumPlatformDeliveryStatus;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
... ... @@ -68,7 +69,7 @@ public class AppraiseService {
private static final Logger LOGGER = LoggerFactory.getLogger(AppraiseService.class);
private ExecutorService executorService = new ThreadPoolExecutor(3, 5, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new PubThreadFactory("appraise-processor"));
private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new PubThreadFactory("appraise-processor"));
@Autowired
private IExpressInfoService expressInfoService;
... ... @@ -214,10 +215,15 @@ public class AppraiseService {
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
executorService.execute(() -> {
//记录物流信息
//发物流
expressInfoService.deliverGoods(buyerUid, appraiseExpressInfoBo.getExpressCompanyId(), orderCode, appraiseExpressInfoBo.getWayBillCode(), appraiseExpressInfoBo.getDepotNum(), appraiseExpressInfoBo.getMobile());
//更新平台物流状态为已发货
buyerOrderMapper.updatePlatformDeliveryStatusByOrderCode(orderCode, buyerOrder.getUid(),
EnumPlatformDeliveryStatus.delivery_to_buyer.getCode(), DateUtil.getCurrentTimeSecond());
});
//记录订单的状态变更信息
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetOrderStatus.getCode());
... ... @@ -291,11 +297,16 @@ public class AppraiseService {
LOGGER.info("returnBackOrderCauseOfJudgeFailure check status ok expectStatus {}, actual status {}, orderCode {}", expectStatus,
buyerOrder.getStatus(), orderCode);
executorService.execute(() -> {
//更新物流信息
int sellerUid = buyerOrder.getSellerUid();
expressInfoService.returnBackOrderCauseOfJudgeFailure(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum, mobile);
//更新平台物流状态为已发货
buyerOrderMapper.updatePlatformDeliveryStatusByOrderCode(orderCode, buyerOrder.getUid(),
EnumPlatformDeliveryStatus.delivery_to_seller.getCode(), DateUtil.getCurrentTimeSecond());
});
//清缓存
SellerOrderGoods sellerOrderGoods = cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid());
... ... @@ -342,10 +353,15 @@ public class AppraiseService {
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
//记录物流信息
int sellerUid = buyerOrder.getSellerUid();
executorService.execute(() -> {
//记录物流信息
expressInfoService.returnBackCauseOfBuyerCancelAfterSellerSendOut(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum, mobile, false);
//更新平台物流状态为已发货
buyerOrderMapper.updatePlatformDeliveryStatusByOrderCode(orderCode, buyerOrder.getUid(),
EnumPlatformDeliveryStatus.delivery_to_seller.getCode(), DateUtil.getCurrentTimeSecond());
});
//发送消息
inBoxFacade.sendCancelledProductToSellerByCenter(sellerUid, wayBillCode);
... ... @@ -384,8 +400,14 @@ public class AppraiseService {
//记录物流信息
int sellerUid = buyerOrder.getSellerUid();
executorService.execute(() -> {
expressInfoService.returnBackCauseOfBuyerCancelAfterSellerSendOut(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum, mobile, true);
//更新平台物流状态为已发货
buyerOrderMapper.updatePlatformDeliveryStatusByOrderCode(orderCode, buyerOrder.getUid(),
EnumPlatformDeliveryStatus.delivery_to_seller.getCode(), DateUtil.getCurrentTimeSecond());
});
//发送消息
//清缓存
SellerOrderGoods sellerOrderGoods = cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid());
... ... @@ -403,9 +425,6 @@ public class AppraiseService {
LOGGER.info("Buyer Order miniFaultAccept (OrderRequest) {}", orderRequest);
//订单状态变更为鉴定中 ,记录调拨的物流信息 ,发消息 ,
OrderStatus expectStatus = OrderStatus.MINI_FAULT_WAITING;
//拆分状态,版本升级之后存在的特殊订单
//OrderStatus expectStatusAnother = OrderStatus.PLATFORM_RECEIVE;
//List<Integer> expectStatusList= Lists.newArrayList(expectStatus.getCode(),expectStatusAnother.getCode());
OrderStatus targetStatus = OrderStatus.MINI_FAULT_ACCEPT;
// 参数检查
... ... @@ -426,8 +445,6 @@ public class AppraiseService {
buyerOrder.getStatus(), buyerOrder.getOrderCode());
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
//checkStatusWithMoreExpectStatus(buyerOrder,orderRequest, expectStatusList);
int buyerUid = orderRequest.getUid();
long orderCode = orderRequest.getOrderCode();
int sellerUid = buyerOrder.getSellerUid();
... ... @@ -497,9 +514,7 @@ public class AppraiseService {
LOGGER.info("Buyer Order miniFaultNotAccept (OrderRequest) {}", orderRequest);
//订单状态变更为 鉴定不通过 ,记录调拨的物流信息 ,发消息 ,
OrderStatus expectStatus = OrderStatus.MINI_FAULT_WAITING;
//拆分状态,版本升级之后存在的特殊订单
//OrderStatus expectStatusAnother = OrderStatus.PLATFORM_RECEIVE;
//List<Integer> expectStatusList= Lists.newArrayList(expectStatusNew.getCode(),expectStatusAnother.getCode());
OrderStatus targetStatus = OrderStatus.MINI_FAULT_REJECT;
// 参数检查
if (orderRequest.getUid() < 0
... ... @@ -521,8 +536,6 @@ public class AppraiseService {
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
//checkStatusWithMoreExpectStatus(buyerOrder,orderRequest, expectStatusList);
long orderCode = orderRequest.getOrderCode();
ApiResponse result = this.miniFaultReject(orderCode, targetStatus, false);
... ... @@ -536,21 +549,6 @@ public class AppraiseService {
}
/*
* 该方法再6.8.6.5版本中使用,拆分订单的时候,存在多种情况expectStatus
* 瑕疵接受
* 瑕疵不接受 这两种情形使用
@Deprecated
private void checkStatusWithMoreExpectStatus(BuyerOrder buyerOrder, OrderRequest orderRequest, List<Integer> expectStatusList ) {
// 检查 订单状态
int status = buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus().intValue();
OrderStatus orderStatus = OrderStatus.getOrderStatus(status);
if (orderStatus == null || !expectStatusList.contains(orderStatus.getCode())){
LOGGER.warn("check status invalidate, uid is {}, orderCode is {}, status is {}",
orderRequest.getUid(), orderRequest.getOrderCode(), buyerOrder.getStatus());
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
}*/
/**
* 瑕疵不通过: 买家不接受或者超时确认
... ... @@ -561,9 +559,6 @@ public class AppraiseService {
public ApiResponse miniFaultReject(Long orderCode, OrderStatus targetStatus, boolean outTimeFlag) {
LOGGER.info("miniFaultReject enter , orderCode {} ,targetStatus {},outTimeFlag {}", orderCode, targetStatus, outTimeFlag);
OrderStatus expectStatus = OrderStatus.MINI_FAULT_WAITING;
//拆分状态,版本升级之后存在的特殊订单
//OrderStatus expectStatusAnother = OrderStatus.PLATFORM_RECEIVE;
//List<Integer> expectStatusList= Lists.newArrayList(expectStatusNew.getCode(),expectStatusAnother.getCode());
ApiResponse apiResponse = new ApiResponse();
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
... ... @@ -741,70 +736,6 @@ public class AppraiseService {
DateUtil.getCurrentTimeSecond());
if (rows > 0) {
/*
//refund coupons of buyer
BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.APPRAISE_FAIL)
.uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(brce);
//
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
long sellerOrderCode = sellerOrder.getOrderCode();
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.APPRAISAL_FAIL_COMPENSATE;
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
skup, orderCode, buyerUid);
//将卖家的保证金分账给平台和买家
PenaltyResult penaltyResult = SellerEarnestMoney2BuyerPenaltyCalculator.from(sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee"))
.calculate()
.orElse(null);
if(Objects.nonNull(penaltyResult)){
TransferCase transferCase = TransferCase.EARNEST_MONEY_TO_BUYER;
TranseferCellNode transeferCellNode = new TranseferCellNode();
transeferCellNode.setUid(buyerUid);
transeferCellNode.setAmount(penaltyResult.getPenaltyAmountWithoutYhServiceAmount());
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.sellerUid(sellerUid)
.buyerOrderCode(orderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.transeferCellNode(transeferCellNode)
.swdType(SellerWalletDetail.Type.APPRAISE_FAIL)
.alarmConfig(AlarmConfig.APPRAISE_FAIL)
.build();
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
//再分账
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in appraiseFail,begin transfer async");
transferService.transfer(tmReq);
});
}
//退钱给买家
BigDecimal goodsAmount = buyerOrder.getAmount();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsAmount)
.skup(skup);
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid,orderCode,goodsAmount)
.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
.refund();
*/
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, orderCode, targetStatus);
boolean refundGoodsMoneyFlag = refundMoneyResultModel.isRefundGoodsMoneyFlag();
SellerOrderGoods sellerOrderGoods = refundMoneyResultModel.getSellerOrderGoods();
... ... @@ -838,6 +769,10 @@ public class AppraiseService {
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judge_reject;
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
//更新平台物流状态为已发货
buyerOrderMapper.updatePlatformDeliveryStatusByOrderCode(orderCode, buyerOrder.getUid(),
EnumPlatformDeliveryStatus.delivery_to_seller.getCode(), DateUtil.getCurrentTimeSecond());
//发货物流(平台已发货)
expressInfoService.returnBackOrderCauseOfJudgeFailure(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum, mobile);
... ... @@ -1331,59 +1266,21 @@ public class AppraiseService {
* 退款给卖家(仅退一次)
*
*/
/*
SellerOrder tso = new SellerOrder();
tso.setUid(sellerUid);
tso.setOrderCode(sellerOrderCode);
tso.setStatus(targetSoStatus.getCode());
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
*/
//更新卖家订单状态
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
skup, orderCode, buyerUid);
//退款给卖家(仅退一次)
PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid, orderCode, skup, sellerOrder, targetSoStatus);
/*
BigDecimal saleIncome = getSaleIncome(sellerUid, skup);
TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER;
TranseferCellNode transeferCellNode = new TranseferCellNode();
transeferCellNode.setUid(sellerUid);
transeferCellNode.setAmount(saleIncome);
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.buyerOrderCode(orderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.transeferCellNode(transeferCellNode)
.alarmConfig(AlarmConfig.APPRAISE_SUCCESS)
.build();
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in appraiseSuccess,begin transfer async");
transferService.transfer(tmReq);
});
//退保证金给卖家
//refund earnestMoney
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.APPRAISE_OK,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue());
LOGGER.info("in appraiseSuccess,refund ok, refundReqOfSeller {}", refundReqOfSeller);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
*/
try {
//鉴定通过后自动发货,这个时候产生:买家确认收货的mq
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
//更新平台物流状态为已发货
buyerOrderMapper.updatePlatformDeliveryStatusByOrderCode(orderCode, buyerOrder.getUid(),
EnumPlatformDeliveryStatus.delivery_to_buyer.getCode(), DateUtil.getCurrentTimeSecond());
//记录物流信息
//发物流
expressInfoService.deliverGoods(buyerUid, expressCompanyId, orderCode, wayBillCode, depotNum, mobile);
... ... @@ -1409,18 +1306,6 @@ public class AppraiseService {
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
}
/*
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
*/
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, sellerOrder.getEarnestMoney());
... ...
... ... @@ -795,6 +795,10 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
Product product = Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null);
//消息
inBoxFacade.buyerMiniFaultCreate(uid,orderCode,sellerOrderGoods,product);
//记录订单的状态变更信息
logger.info("in miniFaultCreate record status change, orderCode {},uid {} ,sellerUid {}", orderCode, uid, sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
}
}
... ...
... ... @@ -222,6 +222,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
buyerOrder.setBuyerOrderStatus(DelStatus.NOT_DEL.getCode());
buyerOrder.setSellerOrderStatus(DelStatus.NOT_DEL.getCode());
buyerOrder.setAttributes(orderBuilder.getAttributes());
buyerOrder.setPlatformDeliveryStatus(0);//平台发货状态给默认值
buyerOrderMapper.insert(buyerOrder);
}
... ...