Authored by LUOXC

add helo

package com.yohoufo.order.controller;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
... ... @@ -9,8 +10,11 @@ import com.yohoufo.common.lock.RedisLock;
import com.yohoufo.common.lock.RedisLockFactory;
import com.yohoufo.common.utils.ExecutorServiceUtils;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.PaymentServiceImpl;
import com.yohoufo.order.service.impl.TransferService;
import com.yohoufo.order.utils.NamedThreadFactory;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
... ... @@ -35,6 +40,9 @@ public class OrderHelpController {
private TransferService transferService;
@Autowired
private PaymentServiceImpl paymentService;
@Autowired
private RedisLockFactory redisLockFactory;
/**
... ... @@ -57,6 +65,28 @@ public class OrderHelpController {
@IgnoreSession
@IgnoreSignature
@InnerApi
@RequestMapping(value = "/transAllEarnest")
public ApiResponse transAllEarnest(@RequestBody TransferAllEarnestRequest req) {
return new ApiResponse.ApiResponseBuilder()
.code(200)
.message(paymentService.transAllEarnest(req.getOrderCode(), req.getUid(), req.getAmount(), req.getAliPayAccount()) ? "ok" : "ko")
.build();
}
@Data
public static class TransferAllEarnestRequest {
long orderCode;
Integer uid;
BigDecimal amount;
AuthorizeResultRespVO aliPayAccount;
}
/**
* 转账
*/
@IgnoreSession
@IgnoreSignature
@InnerApi
@RequestMapping(value = "/lock")
public ApiResponse lock(String key, @RequestParam(required = false, defaultValue = "100") int taskNum) {
ExecutorService executorService = new ThreadPoolExecutor(5, 10,
... ...
... ... @@ -546,7 +546,9 @@ public class PaymentServiceImpl implements IPaymentService {
@Database(ForceMaster = true)
public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount,
AuthorizeResultRespVO aliPayAccount) {
logger.info("退还商家所有保证金,转账开始,orderCode = {}, uid={}, amount={}, alipayAccount={}", orderCode, uid, amount, aliPayAccount);
String logTag = String.format("transfer all earnest {}-{}", orderCode, uid);
logger.info("{}, amount is {} and alipay account is {}", logTag, amount, aliPayAccount);
int now = (int) (System.currentTimeMillis() / 1000);
// 查看是否已经有转账记录
... ... @@ -575,7 +577,7 @@ public class PaymentServiceImpl implements IPaymentService {
if (amount == null || amount.compareTo(new BigDecimal("0.1")) < 0) {
logger.warn("transAllEarnestErr transferMon计算费用结果为 {}, 小于0.1或为null", amount);
logger.warn("{}, amount {} less 0.1 or null", logTag, amount);
alarm("转账金额小于0.1或为null", "ufo.order.transAllEarnest", "退还商家入驻所有金额,订单号:" + orderCode + "操作类型(" + 6 + ")计算金额结果为" + amount);
record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode());
addTradeBills(record);
... ... @@ -583,20 +585,20 @@ public class PaymentServiceImpl implements IPaymentService {
}
if (StringUtils.isBlank(aliPayAccount.getAlipayAccount()) && StringUtils.isBlank(aliPayAccount.getAlipayId())) {
logger.warn("transAllEarnestErr uid {} 支付宝账号不合法", account);
logger.warn("{}, alipay account is not exist", logTag);
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALIPAY_ACCOUNT.getCode());
addTradeBills(record);
throw new ServiceException(400, "uid[" + uid + "]支付宝账号不合法");
}
logger.info("transAllEarnest参数检查成功!");
logger.info("{}, data check ok.", logTag);
tradeBillsMapper.insert(record);
// 转账
JSONObject jsonObject = null;
boolean exceedMillionAndSuccess = false;
transfer.setUpdateTime(now);
try {
logger.info("transAllEarnest开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", orderCode, account, amount);
logger.info("{}, transfer start", logTag);
shoppingRiskWatchDog.checkAlipayBlackUser(aliPayAccount.getUid(), aliPayAccount);
if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
transfer.setInterfaceType(2);
... ... @@ -616,7 +618,7 @@ public class PaymentServiceImpl implements IPaymentService {
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
jsonObject = alipayService.transferMoney(Long.toString(orderCode), aliPayAccount.getAlipayId(), aliPayAccount.getAlipayAccount(), amount);
if (jsonObject == null) {
logger.warn("transAllEarnestErr 转账失败 , orderCode is {}", orderCode);
logger.warn("{}, transfer fail.", logTag);
transfer.setStatus(3);
throw new ServiceException(500, "转账失败:阿里接口返回null");
}
... ... @@ -628,7 +630,7 @@ public class PaymentServiceImpl implements IPaymentService {
&& (code = jsonObject.getInteger("code")) == 10000
&& jsonObject.containsKey("order_id")
&& StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) {
logger.info("转账成功,targeAccount is {}, amount is {}", account, amount);
logger.info("{}, transfer success, account is {}, amount is {}", logTag, account, amount);
transfer.setAlipayTradeId(orderId);
transfer.setStatus(1);
return true;
... ... @@ -645,16 +647,15 @@ public class PaymentServiceImpl implements IPaymentService {
return true;
}
} else {
logger.warn("transAllEarnestErr 返回code或者order_id不是成功状态,code={}, orderId={}", code, orderId);
logger.warn("{}, transfer fail, return_code is {} and return_order_id is {}", logTag, code, orderId);
throw new ServiceException(500, "转账失败:code或者order_id不是成功状态");
}
} catch (Exception e) {
logger.warn("transAllEarnestErr 转账失败 , orderCode is {}, msg is {}", orderCode, e.getMessage());
logger.warn("{}, transfer fail", logTag, e);
String alarmMsg = "订单号:" + orderCode + ",操作类型(商家退出入驻退保证金),msg=" + e.getMessage();
if (jsonObject != null) {
alarmMsg += ",阿里返回DETAIL=" + jsonObject.toJSONString();
}
logger.info("transAllEarnestErr 转账失败 , alarmMsg is {}", alarmMsg);
alarm("转账失败", "ufo.order.transAllEarnest", alarmMsg);
transfer.setStatus(3);
if (e instanceof ServiceException) {
... ... @@ -664,17 +665,17 @@ public class PaymentServiceImpl implements IPaymentService {
}
} finally {
if (exceedMillionAndSuccess) {
logger.info("transferMon exceedMillion,转账结束,等待回调 orderCode is {}!", orderCode);
logger.info("{}, transfer exceed million waiting...", logTag);
return true;
}
logger.info("transAllEarnest最后更新状态 status= {}", transfer.getStatus());
logger.info("{}, transfer end update status to {}", logTag, transfer.getStatus());
transfer.setUpdateTime(now);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
// 100:成功;201:没有支付宝账号;202:金额不合法;299:转账失败
BillTradeStatus bts = transfer.getStatus() == 1 ? BillTradeStatus.SUCCESS : BillTradeStatus.TRANSFER_FAIL;
record.setTradeStatus(bts.getCode());
tradeBillsMapper.updateSelectiveByPrimaryKey(record);
logger.info("transAllEarnest最后更新状态完成,转账结束, orderCode is {}!", orderCode);
logger.info("{}, transfer end update status to {} ok", logTag, transfer.getStatus());
}
}
... ...