Authored by LUOXC

refactor

package com.yohoufo.order.config;
import com.yoho.core.config.ConfigReader;
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 UfoOrderPayConfigReader {
@Autowired
private ConfigReader configReader;
/**
* 申请寄存返利的单数
*
* @return
*/
public int depositRebateCnt() {
return configReader.getInt("ufo.order.pay.depositRebateCnt", 4);
}
/**
* 申请寄存返利一单返利数目
*
* @return
*/
public BigDecimal depositRebatePerAmount() {
return new BigDecimal(configReader.getDouble("ufo.order.pay.depositRebatePerAmount", 30));
}
public boolean transferWithWalletSwitch() {
return configReader.getBoolean("ufo.order.pay.transferWithWalletSwitch", true);
}
public boolean transferWithAlipayExceedMillionTransferSwitch() {
return configReader.getBoolean("ufo.order.pay.transferWithAlipayExceedMillionTransferSwitch", false);
}
public boolean isStopTransfer() {
boolean isStop = configReader.getBoolean("ufo.order.pay.isStop.transfer", false);
log.info("zk config [ufo.order.pay.isStop.transfer] value {}", isStop);
return isStop;
}
}
... ...
package com.yohoufo.order.service.handler.transfer;
import com.alibaba.fastjson.JSONObject;
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.config.UfoOrderPayConfigReader;
import com.yohoufo.order.service.proxy.WalletTransferService;
import com.yohoufo.order.service.transfer.TransferResult;
import lombok.extern.slf4j.Slf4j;
... ... @@ -22,31 +21,13 @@ public class TransferChancelSelector {
private volatile String lastTransferDate = null;
@Autowired
private ConfigReader configReader;
private UfoOrderPayConfigReader ufoOrderPayConfigReader;
@Autowired
private WalletTransferService walletTransferService;
/**
* 申请寄存返利的单数
*
* @return
*/
public int getDepositRebateOrderCnt() {
return configReader.getInt("ufo.order.pay.depositRebateCnt", 4);
}
/**
* 申请寄存返利一单返利数目
*
* @return
*/
public double getDepositRebateAmount() {
return configReader.getDouble("ufo.order.pay.depositRebatePerAmount", 30);
}
public boolean isTransferWithAlipayExceedMillionTransfer() {
boolean value = configReader.getBoolean("ufo.order.pay.exceedSwitch", false);
boolean value = ufoOrderPayConfigReader.transferWithAlipayExceedMillionTransferSwitch();
if (value) {
log.info("use exceed million ufo.order.pay.exceedSwitch={}", value);
return true;
... ... @@ -57,7 +38,7 @@ public class TransferChancelSelector {
public boolean isTransferWithWallet(TradeBills bills) {
boolean canTransfer = walletTransferService.canTransfer(bills);
boolean open = configReader.getBoolean("ufo.order.pay.transferWithWallet", false);
boolean open = ufoOrderPayConfigReader.transferWithWalletSwitch();
return canTransfer && open;
}
... ... @@ -67,9 +48,7 @@ public class TransferChancelSelector {
public boolean isStopTransferWithAlipay() {
boolean isStop = configReader.getBoolean("ufo.order.pay.isStop.transfer", false);
log.info("zk config [ufo.order.pay.isStop.transfer] value {}", isStop);
return isStop;
return ufoOrderPayConfigReader.isStopTransfer();
}
public boolean isExceedMillion(JSONObject jsonObject) {
... ...
... ... @@ -12,6 +12,7 @@ import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.config.UfoOrderPayConfigReader;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.model.request.TranseferCellNode;
import com.yohoufo.order.model.request.TransferMoneyRequest;
... ... @@ -56,6 +57,9 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
@Autowired
AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
UfoOrderPayConfigReader ufoOrderPayConfigReader;
private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(1000),
NamedThreadFactory.newThreadFactory("appraise"));
... ... @@ -89,8 +93,8 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService {
executorService.execute(() -> {
// 只返4单
int DEFAULT_REBATE_CNT = transferChancelSelector.getDepositRebateOrderCnt();
BigDecimal rebate = new BigDecimal(transferChancelSelector.getDepositRebateAmount());
int DEFAULT_REBATE_CNT = ufoOrderPayConfigReader.depositRebateCnt();
BigDecimal rebate = ufoOrderPayConfigReader.depositRebatePerAmount();
depositCodeList.stream().forEach(depositCode -> {
... ...