Authored by LUOXC

refactor

... ... @@ -5,6 +5,7 @@ import com.yoho.core.config.ConfigReader;
import com.yohoufo.dal.order.model.OrdersPayTransfer;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.common.TradeType;
import com.yohoufo.order.service.proxy.WalletTransferService;
import com.yohoufo.order.service.transfer.TransferResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
... ... @@ -16,13 +17,16 @@ import java.util.Date;
@Slf4j
@Service
public class AlipayTransferChancelSelector {
public class TransferChancelSelector {
private volatile String lastTransferDate = null;
@Autowired
private ConfigReader configReader;
@Autowired
private WalletTransferService walletTransferService;
/**
* 申请寄存返利的单数
*
... ... @@ -52,11 +56,9 @@ public class AlipayTransferChancelSelector {
}
public boolean isTransferWithWallet(TradeBills bills) {
TradeType tradeType = TradeType.getTradeTypeByCode(bills.getTradeType());
if (tradeType == TradeType.deposit_rebate) {
return false;
}
return configReader.getBoolean("ufo.order.pay.transferWithWallet", false);
boolean canTransfer = walletTransferService.canTransfer(bills);
boolean open = configReader.getBoolean("ufo.order.pay.transferWithWallet", false);
return canTransfer && open;
}
public boolean isTransferWithWallet(Integer interfaceType) {
... ...
... ... @@ -16,7 +16,7 @@ import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.model.request.TranseferCellNode;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
import com.yohoufo.order.service.handler.transfer.TransferChancelSelector;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -45,7 +45,7 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
OrderCodeGenerator orderCodeGenerator;
@Autowired
private AlipayTransferChancelSelector alipayTransferChancelSelector;
private TransferChancelSelector alipayTransferChancelSelector;
@Autowired
TransferService transferService;
... ...
... ... @@ -22,28 +22,21 @@ import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.OrdersPayTransferMapper;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ClientType;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.convert.AppraiseOrderGoodsConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.AppraiseOrderContext;
import com.yohoufo.order.model.request.TranseferCellNode;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.handler.GoodsServiceRefundHandler;
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
import com.yohoufo.order.service.handler.transfer.TransferChancelSelector;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.NamedThreadFactory;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -54,10 +47,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
... ... @@ -99,7 +88,7 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
OrderCodeGenerator orderCodeGenerator;
@Autowired
private AlipayTransferChancelSelector alipayTransferChancelSelector;
private TransferChancelSelector alipayTransferChancelSelector;
@Autowired
TransferService transferService;
... ...
... ... @@ -38,7 +38,7 @@ import com.yohoufo.order.service.*;
import com.yohoufo.order.service.handler.BuyerOrderPayDiffTimeHandler;
import com.yohoufo.order.service.handler.payment.PayServiceFactory;
import com.yohoufo.order.service.handler.payment.RefundManager;
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
import com.yohoufo.order.service.handler.transfer.TransferChancelSelector;
import com.yohoufo.order.service.handler.payment.OrderPaymentServiceFactory;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
... ... @@ -152,7 +152,7 @@ public class PaymentServiceImpl implements IPaymentService {
BuyerOrderPayDiffTimeHandler buyerOrderPayDiffTimeHandler;
@Autowired
private AlipayTransferChancelSelector alipayTransferChancelSelector;
private TransferChancelSelector alipayTransferChancelSelector;
@Autowired
private TradeBillsService tradeBillsService;
... ...
... ... @@ -12,7 +12,7 @@ import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.order.constants.ClientSpecialSemanticCode;
import com.yohoufo.order.convert.builder.AlarmEventBuilder;
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
import com.yohoufo.order.service.handler.transfer.TransferChancelSelector;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
... ... @@ -45,7 +45,7 @@ public class ShoppingRiskWatchDog {
private AlipayBlackUserMapper alipayBlackUserMapper;
@Autowired
AlipayTransferChancelSelector alipayTransferChancelSelector;
TransferChancelSelector alipayTransferChancelSelector;
public void checkWaitingPayCnt(int uid){
logger.info("in ShoppingRiskWatchDog.checkWaitingPayCnt uid {}", uid);
... ...
... ... @@ -11,8 +11,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@Slf4j
@Service
public class DefaultWalletTransferService implements WalletTransferService {
... ... @@ -22,68 +20,62 @@ public class DefaultWalletTransferService implements WalletTransferService {
@Override
public TransferResult transfer(String logTag, TradeBills tradeBills) {
return transfer(logTag,
tradeBills.getUid(),
tradeBills.getOrderCode(),
tradeBills.getUserType(),
TradeType.getTradeTypeByCode(tradeBills.getTradeType()),
tradeBills.getAmount());
public boolean canTransfer(TradeBills tradeBills) {
return transformTradeType(tradeBills) > 0;
}
private TransferResult transfer(String logTag,
Integer uid,
Long orderCode,
int useType,
TradeType tradeType,
BigDecimal transferAmount) {
@Override
public TransferResult transfer(String logTag, TradeBills tradeBills) {
// 0:未知、1:订单货款、2:买家补偿金、3:卖家补偿金、4:保证金
Integer trgTradeType;
if (tradeType == TradeType.guarantee_cash) {
trgTradeType = 4;
} else if (tradeType == TradeType.goods_income) {
trgTradeType = 1;
} else if (tradeType == TradeType.compensateIncome) {
trgTradeType = useType == PaymentServiceImpl.TargetUserType.buyer.getCode() ? 2
: useType == PaymentServiceImpl.TargetUserType.seller.getCode() ? 3
: 0;
} else {
trgTradeType = 0;
}
JSONObject request = new JSONObject();
request.fluentPut("uid", uid)
.fluentPut("amount", transferAmount)
.fluentPut("orderCode", orderCode)
.fluentPut("tradeType", trgTradeType)
request.fluentPut("uid", tradeBills.getUid())
.fluentPut("amount", tradeBills.getAmount())
.fluentPut("orderCode", tradeBills.getOrderCode())
.fluentPut("tradeType", transformTradeType(tradeBills))
// source 1:UFO
.fluentPut("source", 1);
try {
JSONObject result = serviceCaller.asyncCall("wallet.addWalletBalance", request, JSONObject.class).get(1);
log.info("{}, transfer success uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
log.info("{}, transfer success", logTag);
return TransferResult.builder()
.transferOrderCode(orderCode.toString())
.transferOrderCode(tradeBills.getOrderCode().toString())
.code(result.getIntValue("code"))
.msg(result.getString("message"))
.build();
} catch (ServiceException e) {
log.info("{}, transfer fail uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
log.info("{}, transfer fail", logTag);
return TransferResult.builder()
.transferOrderCode(orderCode.toString())
.transferOrderCode(tradeBills.getOrderCode().toString())
.code(e.getCode())
.msg(e.getErrorMessage())
.build();
} catch (Exception e) {
log.info("{}, transfer fail uid is {} orderCode is {} tradeType is {} transferAmount is {}",
logTag, uid, orderCode, tradeType, transferAmount);
log.info("{}, transfer fail", logTag, e);
return TransferResult.builder()
.transferOrderCode(orderCode.toString())
.transferOrderCode(tradeBills.getOrderCode().toString())
.code(599)
.msg(e.getMessage())
.build();
}
}
/**
* @param tradeBills
* @return 0:无效、1:订单货款、2:买家补偿金、3:卖家补偿金、4:保证金
*/
private int transformTradeType(TradeBills tradeBills) {
int useType = tradeBills.getUserType();
TradeType tradeType = TradeType.getTradeTypeByCode(tradeBills.getTradeType());
if (tradeType == TradeType.guarantee_cash) {
return 4;
} else if (tradeType == TradeType.goods_income) {
return 1;
} else if (tradeType == TradeType.compensateIncome) {
return useType == PaymentServiceImpl.TargetUserType.buyer.getCode() ? 2
: useType == PaymentServiceImpl.TargetUserType.seller.getCode() ? 3
: 0;
} else {
return 0;
}
}
}
... ...
... ... @@ -5,6 +5,8 @@ import com.yohoufo.order.service.transfer.TransferResult;
public interface WalletTransferService {
boolean canTransfer(TradeBills tradeBills);
TransferResult transfer(String logTag, TradeBills tradeBills);
}
... ...