Authored by sailing-PC\sailing

add sms alarm

package com.yohoufo.order.common;
/**
* 1:鉴定通过(货款-->卖家);
* 2:鉴定不通过(保证金 --> 买家);
* 3:有买家时卖家不卖了(保证金 --> 买家)
* 1:鉴定通过(货款-->卖家 + 平台);
* 2:鉴定不通过(保证金 --> 买家 + 平台);
* 3:有买家时卖家不卖了(保证金 --> 买家+ 平台)
* 4:超时发货(保证金 --> 买家 + 平台)
* Created by chenchao on 2018/10/9.
*/
public enum TransferCase {
... ... @@ -11,13 +12,11 @@ public enum TransferCase {
APPRAISE_SUCCESS(1),
APPRAISE_FAIL(2),
SELLER_PLAY_BUYER(3);
SELLER_PLAY_BUYER(3),
DELIVER_TIME_OUT(4);
private int code;
TransferCase(int code) {
this.code = code;
}
... ...
package com.yohoufo.order.constants;
/**
* Created by chenchao on 2018/10/16.
*/
public enum AlarmConfig {
APPRAISE_SUCCESS("buyerOrder.transferGoodsMoney","buyerOrder.refundEarnestMoney"),
APPRAISE_FAIL("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney"),
SELLER_PLAY_BUYER("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney"),
DELIVER_TIME_OUT("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney");
private String transferName;
private String refundName;
AlarmConfig(String transferName, String refundName) {
this.transferName = transferName;
this.refundName = refundName;
}
public String getTransferName() {
return transferName;
}
public String getRefundName() {
return refundName;
}
}
... ...
package com.yohoufo.order.model.request;
import com.yohoufo.order.common.TransferCase;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
... ... @@ -25,4 +26,13 @@ public class TransferMoneyRequest {
* </pre>
*/
private int type;
private TransferCase transferCase;
public TransferMoneyRequest(long buyerOrderCode, long sellerOrderCode, int type) {
this.buyerOrderCode = buyerOrderCode;
this.sellerOrderCode = sellerOrderCode;
this.type = type;
}
}
... ...
... ... @@ -3,18 +3,21 @@ package com.yohoufo.order.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.SellerCancelDeliverEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.TransferService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -41,6 +44,9 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
@Autowired
private IPaymentService paymentService;
@Autowired
private TransferService transferService;
public String getMessageTopic() {
... ... @@ -64,8 +70,10 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
if (expectStatus.getCode() == buyerOrder.getStatus()){
//将卖家的保证金分账给平台和买家
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).build();
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).transferCase(TransferCase.DELIVER_TIME_OUT)
.build();
transferService.transfer(tmReq);
//
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
... ... @@ -76,7 +84,6 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
.amount(goodsMoney)
.skup(skup);
try{
paymentService.transferMon(tmReq);
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
... ... @@ -89,6 +96,11 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "发货超时后,订单"+ orderCode + "退货款失败";
AlarmConfig alarmConfig = AlarmConfig.DELIVER_TIME_OUT;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally {
OrderStatus targetStatus = OrderStatus.SEND_OUT_TIMEOUT;
... ...
... ... @@ -17,6 +17,7 @@ import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.common.SellerOrderStatus;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.BuyerConfirmEvent;
import com.yohoufo.order.model.request.PaymentRequest;
... ... @@ -62,6 +63,10 @@ public class AppraiseService {
private InBoxFacade inBoxFacade;
@Autowired
TransferService transferService;
public boolean appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum){
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
... ... @@ -83,6 +88,11 @@ public class AppraiseService {
final Integer sellerUid = sellerOrder.getUid();
final Long sellerOrderCode = sellerOrder.getOrderCode();
TransferCase transferCase = TransferCase.APPRAISE_SUCCESS;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
transferService.transfer(tmReq);
/**
* 退保证金给卖家
*/
... ... @@ -99,10 +109,7 @@ public class AppraiseService {
.skup(skup);
try {
paymentService.refund(req);
//分账
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.APPRAISE_SUCCESS.getCode()).build();
paymentService.transferMon(tmReq);
//通知卖家退还保证金
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
... ... @@ -118,10 +125,14 @@ public class AppraiseService {
inBoxFacade.depotDeliver2Buyer(buyerUid, orderCode);
}catch (Exception ex){
LOGGER.warn("in appraiseSuccess,transferMon or refund fail, req {}", req, ex);
LOGGER.warn("in appraiseSuccess,refund fail, req {}", req, ex);
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally {
// 更新买家订单状态
LOGGER.info("appraiseSuccess update buyer order {} ", buyerOrder);
... ... @@ -158,6 +169,7 @@ public class AppraiseService {
return true;
}
/**
* 更新发到卖家的物流信息
* 将卖家的保证金分账给平台和买家
... ... @@ -188,16 +200,10 @@ public class AppraiseService {
int skup = bog.getSkup();
//将卖家的保证金分账给平台和买家
TransferCase transferCase = TransferCase.APPRAISE_FAIL;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.APPRAISE_FAIL.getCode()).build();
try{
paymentService.transferMon(tmReq);
}catch (Exception ex){
LOGGER.warn("in appraiseFail ,Transfer fail,req {}", tmReq, ex);
String content = "鉴定不通过时,订单"+ orderCode + "保证金分账失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerOrder.appraiseFail", "cancel", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
.type(transferCase.getCode()).transferCase(transferCase).build();
transferService.transfer(tmReq);
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
... ... @@ -224,7 +230,9 @@ public class AppraiseService {
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "鉴定不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerOrder.appraiseFail", "cancel", content);
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_FAIL;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally {
... ...
... ... @@ -14,6 +14,7 @@ import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.*;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
import com.yohoufo.order.event.OrderCancelEvent;
... ... @@ -77,6 +78,9 @@ public class SellerOrderCancelService {
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private TransferService transferService;
/**
* TODO 如何控制好并发,必须控制不能重复转账 退款
* 使用乐观锁,带着查询到的状态且符合条件时再去更新
... ... @@ -303,10 +307,11 @@ public class SellerOrderCancelService {
.amount(goodsMoney)
.skup(sellerOrder.getSkup());
try{
//TODO 分赃(分账) 有待考虑使用2比对
//分赃(分账) 有待考虑使用2比对
TransferCase transferCase = TransferCase.SELLER_PLAY_BUYER;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(buyerOrderCode)
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).build();
paymentService.transferMon(tmReq);
.type(transferCase.getCode()).transferCase(transferCase).build();
transferService.transfer(tmReq);
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
... ... @@ -323,6 +328,10 @@ public class SellerOrderCancelService {
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "订单"+ buyerOrderCode + "退货款失败";
AlarmConfig alarmConfig = AlarmConfig.SELLER_PLAY_BUYER;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally{
int result = 0;
//actions of buyer order and related
... ...
package com.yohoufo.order.service.impl;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by chenchao on 2018/10/16.
*/
@Service
public class TransferService {
private final Logger closeLogger = LoggerUtils.getOrderCloseLogger();
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private IPaymentService paymentService;
public void transfer(TransferMoneyRequest req){
TransferCase transferCase = req.getTransferCase();
if (transferCase == null){
return;
}
try{
paymentService.transferMon(req);
}catch (Exception ex){
logger.warn("in transfer, transfer fail,req {}", req, ex);
SmsAlarmEvent smsAlarmEvent = getSmsAlarmEvent(req, transferCase);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
}
SmsAlarmEvent getSmsAlarmEvent(TransferMoneyRequest req, TransferCase transferCase){
String content;
SmsAlarmEvent smsAlarmEvent;
AlarmConfig alarmConfig ;
switch (transferCase){
case APPRAISE_SUCCESS:
content = "鉴定通过时,订单"+ req.getBuyerOrderCode() + "货款分账失败";
alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
break;
case APPRAISE_FAIL:
content = "鉴定不通过时,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.APPRAISE_FAIL;
break;
case SELLER_PLAY_BUYER:
closeLogger.warn("in cancelAfterPayExistBuyAction , transfer fail,req {}", req);
content = "卖家取消,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.SELLER_PLAY_BUYER;
break;
case DELIVER_TIME_OUT:
closeLogger.warn("in deliver timeout , transfer fail,req {}", req);
content = "卖家发货超时,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.DELIVER_TIME_OUT;
break;
default:
return null;
}
smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getTransferName(), alarmConfig.name(), content);
return smsAlarmEvent;
}
}
... ...