Authored by LUOXC

add helo

1 package com.yohoufo.order.controller; 1 package com.yohoufo.order.controller;
2 2
3 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; 3 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
  4 +import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
4 import com.yohoufo.common.ApiResponse; 5 import com.yohoufo.common.ApiResponse;
5 import com.yohoufo.common.annotation.IgnoreSession; 6 import com.yohoufo.common.annotation.IgnoreSession;
6 import com.yohoufo.common.annotation.IgnoreSignature; 7 import com.yohoufo.common.annotation.IgnoreSignature;
@@ -9,8 +10,11 @@ import com.yohoufo.common.lock.RedisLock; @@ -9,8 +10,11 @@ import com.yohoufo.common.lock.RedisLock;
9 import com.yohoufo.common.lock.RedisLockFactory; 10 import com.yohoufo.common.lock.RedisLockFactory;
10 import com.yohoufo.common.utils.ExecutorServiceUtils; 11 import com.yohoufo.common.utils.ExecutorServiceUtils;
11 import com.yohoufo.order.model.request.TransferMoneyRequest; 12 import com.yohoufo.order.model.request.TransferMoneyRequest;
  13 +import com.yohoufo.order.service.IPaymentService;
  14 +import com.yohoufo.order.service.impl.PaymentServiceImpl;
12 import com.yohoufo.order.service.impl.TransferService; 15 import com.yohoufo.order.service.impl.TransferService;
13 import com.yohoufo.order.utils.NamedThreadFactory; 16 import com.yohoufo.order.utils.NamedThreadFactory;
  17 +import lombok.Data;
14 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
15 import org.apache.commons.lang3.RandomUtils; 19 import org.apache.commons.lang3.RandomUtils;
16 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping; @@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.bind.annotation.RequestParam; 23 import org.springframework.web.bind.annotation.RequestParam;
20 import org.springframework.web.bind.annotation.RestController; 24 import org.springframework.web.bind.annotation.RestController;
21 25
  26 +import java.math.BigDecimal;
22 import java.util.UUID; 27 import java.util.UUID;
23 import java.util.concurrent.ArrayBlockingQueue; 28 import java.util.concurrent.ArrayBlockingQueue;
24 import java.util.concurrent.ExecutorService; 29 import java.util.concurrent.ExecutorService;
@@ -35,6 +40,9 @@ public class OrderHelpController { @@ -35,6 +40,9 @@ public class OrderHelpController {
35 private TransferService transferService; 40 private TransferService transferService;
36 41
37 @Autowired 42 @Autowired
  43 + private PaymentServiceImpl paymentService;
  44 +
  45 + @Autowired
38 private RedisLockFactory redisLockFactory; 46 private RedisLockFactory redisLockFactory;
39 47
40 /** 48 /**
@@ -57,6 +65,28 @@ public class OrderHelpController { @@ -57,6 +65,28 @@ public class OrderHelpController {
57 @IgnoreSession 65 @IgnoreSession
58 @IgnoreSignature 66 @IgnoreSignature
59 @InnerApi 67 @InnerApi
  68 + @RequestMapping(value = "/transAllEarnest")
  69 + public ApiResponse transAllEarnest(@RequestBody TransferAllEarnestRequest req) {
  70 + return new ApiResponse.ApiResponseBuilder()
  71 + .code(200)
  72 + .message(paymentService.transAllEarnest(req.getOrderCode(), req.getUid(), req.getAmount(), req.getAliPayAccount()) ? "ok" : "ko")
  73 + .build();
  74 + }
  75 +
  76 + @Data
  77 + public static class TransferAllEarnestRequest {
  78 + long orderCode;
  79 + Integer uid;
  80 + BigDecimal amount;
  81 + AuthorizeResultRespVO aliPayAccount;
  82 + }
  83 +
  84 + /**
  85 + * 转账
  86 + */
  87 + @IgnoreSession
  88 + @IgnoreSignature
  89 + @InnerApi
60 @RequestMapping(value = "/lock") 90 @RequestMapping(value = "/lock")
61 public ApiResponse lock(String key, @RequestParam(required = false, defaultValue = "100") int taskNum) { 91 public ApiResponse lock(String key, @RequestParam(required = false, defaultValue = "100") int taskNum) {
62 ExecutorService executorService = new ThreadPoolExecutor(5, 10, 92 ExecutorService executorService = new ThreadPoolExecutor(5, 10,
@@ -546,7 +546,9 @@ public class PaymentServiceImpl implements IPaymentService { @@ -546,7 +546,9 @@ public class PaymentServiceImpl implements IPaymentService {
546 @Database(ForceMaster = true) 546 @Database(ForceMaster = true)
547 public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount, 547 public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount,
548 AuthorizeResultRespVO aliPayAccount) { 548 AuthorizeResultRespVO aliPayAccount) {
549 - logger.info("退还商家所有保证金,转账开始,orderCode = {}, uid={}, amount={}, alipayAccount={}", orderCode, uid, amount, aliPayAccount); 549 +
  550 + String logTag = String.format("transfer all earnest {}-{}", orderCode, uid);
  551 + logger.info("{}, amount is {} and alipay account is {}", logTag, amount, aliPayAccount);
550 552
551 int now = (int) (System.currentTimeMillis() / 1000); 553 int now = (int) (System.currentTimeMillis() / 1000);
552 // 查看是否已经有转账记录 554 // 查看是否已经有转账记录
@@ -575,7 +577,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -575,7 +577,7 @@ public class PaymentServiceImpl implements IPaymentService {
575 577
576 578
577 if (amount == null || amount.compareTo(new BigDecimal("0.1")) < 0) { 579 if (amount == null || amount.compareTo(new BigDecimal("0.1")) < 0) {
578 - logger.warn("transAllEarnestErr transferMon计算费用结果为 {}, 小于0.1或为null", amount); 580 + logger.warn("{}, amount {} less 0.1 or null", logTag, amount);
579 alarm("转账金额小于0.1或为null", "ufo.order.transAllEarnest", "退还商家入驻所有金额,订单号:" + orderCode + "操作类型(" + 6 + ")计算金额结果为" + amount); 581 alarm("转账金额小于0.1或为null", "ufo.order.transAllEarnest", "退还商家入驻所有金额,订单号:" + orderCode + "操作类型(" + 6 + ")计算金额结果为" + amount);
580 record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode()); 582 record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode());
581 addTradeBills(record); 583 addTradeBills(record);
@@ -583,20 +585,20 @@ public class PaymentServiceImpl implements IPaymentService { @@ -583,20 +585,20 @@ public class PaymentServiceImpl implements IPaymentService {
583 } 585 }
584 586
585 if (StringUtils.isBlank(aliPayAccount.getAlipayAccount()) && StringUtils.isBlank(aliPayAccount.getAlipayId())) { 587 if (StringUtils.isBlank(aliPayAccount.getAlipayAccount()) && StringUtils.isBlank(aliPayAccount.getAlipayId())) {
586 - logger.warn("transAllEarnestErr uid {} 支付宝账号不合法", account); 588 + logger.warn("{}, alipay account is not exist", logTag);
587 record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALIPAY_ACCOUNT.getCode()); 589 record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALIPAY_ACCOUNT.getCode());
588 addTradeBills(record); 590 addTradeBills(record);
589 throw new ServiceException(400, "uid[" + uid + "]支付宝账号不合法"); 591 throw new ServiceException(400, "uid[" + uid + "]支付宝账号不合法");
590 } 592 }
591 593
592 - logger.info("transAllEarnest参数检查成功!"); 594 + logger.info("{}, data check ok.", logTag);
593 tradeBillsMapper.insert(record); 595 tradeBillsMapper.insert(record);
594 // 转账 596 // 转账
595 JSONObject jsonObject = null; 597 JSONObject jsonObject = null;
596 boolean exceedMillionAndSuccess = false; 598 boolean exceedMillionAndSuccess = false;
597 transfer.setUpdateTime(now); 599 transfer.setUpdateTime(now);
598 try { 600 try {
599 - logger.info("transAllEarnest开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", orderCode, account, amount); 601 + logger.info("{}, transfer start", logTag);
600 shoppingRiskWatchDog.checkAlipayBlackUser(aliPayAccount.getUid(), aliPayAccount); 602 shoppingRiskWatchDog.checkAlipayBlackUser(aliPayAccount.getUid(), aliPayAccount);
601 if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) { 603 if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
602 transfer.setInterfaceType(2); 604 transfer.setInterfaceType(2);
@@ -616,7 +618,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -616,7 +618,7 @@ public class PaymentServiceImpl implements IPaymentService {
616 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer); 618 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
617 jsonObject = alipayService.transferMoney(Long.toString(orderCode), aliPayAccount.getAlipayId(), aliPayAccount.getAlipayAccount(), amount); 619 jsonObject = alipayService.transferMoney(Long.toString(orderCode), aliPayAccount.getAlipayId(), aliPayAccount.getAlipayAccount(), amount);
618 if (jsonObject == null) { 620 if (jsonObject == null) {
619 - logger.warn("transAllEarnestErr 转账失败 , orderCode is {}", orderCode); 621 + logger.warn("{}, transfer fail.", logTag);
620 transfer.setStatus(3); 622 transfer.setStatus(3);
621 throw new ServiceException(500, "转账失败:阿里接口返回null"); 623 throw new ServiceException(500, "转账失败:阿里接口返回null");
622 } 624 }
@@ -628,7 +630,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -628,7 +630,7 @@ public class PaymentServiceImpl implements IPaymentService {
628 && (code = jsonObject.getInteger("code")) == 10000 630 && (code = jsonObject.getInteger("code")) == 10000
629 && jsonObject.containsKey("order_id") 631 && jsonObject.containsKey("order_id")
630 && StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) { 632 && StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) {
631 - logger.info("转账成功,targeAccount is {}, amount is {}", account, amount); 633 + logger.info("{}, transfer success, account is {}, amount is {}", logTag, account, amount);
632 transfer.setAlipayTradeId(orderId); 634 transfer.setAlipayTradeId(orderId);
633 transfer.setStatus(1); 635 transfer.setStatus(1);
634 return true; 636 return true;
@@ -645,16 +647,15 @@ public class PaymentServiceImpl implements IPaymentService { @@ -645,16 +647,15 @@ public class PaymentServiceImpl implements IPaymentService {
645 return true; 647 return true;
646 } 648 }
647 } else { 649 } else {
648 - logger.warn("transAllEarnestErr 返回code或者order_id不是成功状态,code={}, orderId={}", code, orderId); 650 + logger.warn("{}, transfer fail, return_code is {} and return_order_id is {}", logTag, code, orderId);
649 throw new ServiceException(500, "转账失败:code或者order_id不是成功状态"); 651 throw new ServiceException(500, "转账失败:code或者order_id不是成功状态");
650 } 652 }
651 } catch (Exception e) { 653 } catch (Exception e) {
652 - logger.warn("transAllEarnestErr 转账失败 , orderCode is {}, msg is {}", orderCode, e.getMessage()); 654 + logger.warn("{}, transfer fail", logTag, e);
653 String alarmMsg = "订单号:" + orderCode + ",操作类型(商家退出入驻退保证金),msg=" + e.getMessage(); 655 String alarmMsg = "订单号:" + orderCode + ",操作类型(商家退出入驻退保证金),msg=" + e.getMessage();
654 if (jsonObject != null) { 656 if (jsonObject != null) {
655 alarmMsg += ",阿里返回DETAIL=" + jsonObject.toJSONString(); 657 alarmMsg += ",阿里返回DETAIL=" + jsonObject.toJSONString();
656 } 658 }
657 - logger.info("transAllEarnestErr 转账失败 , alarmMsg is {}", alarmMsg);  
658 alarm("转账失败", "ufo.order.transAllEarnest", alarmMsg); 659 alarm("转账失败", "ufo.order.transAllEarnest", alarmMsg);
659 transfer.setStatus(3); 660 transfer.setStatus(3);
660 if (e instanceof ServiceException) { 661 if (e instanceof ServiceException) {
@@ -664,17 +665,17 @@ public class PaymentServiceImpl implements IPaymentService { @@ -664,17 +665,17 @@ public class PaymentServiceImpl implements IPaymentService {
664 } 665 }
665 } finally { 666 } finally {
666 if (exceedMillionAndSuccess) { 667 if (exceedMillionAndSuccess) {
667 - logger.info("transferMon exceedMillion,转账结束,等待回调 orderCode is {}!", orderCode); 668 + logger.info("{}, transfer exceed million waiting...", logTag);
668 return true; 669 return true;
669 } 670 }
670 - logger.info("transAllEarnest最后更新状态 status= {}", transfer.getStatus()); 671 + logger.info("{}, transfer end update status to {}", logTag, transfer.getStatus());
671 transfer.setUpdateTime(now); 672 transfer.setUpdateTime(now);
672 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer); 673 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
673 // 100:成功;201:没有支付宝账号;202:金额不合法;299:转账失败 674 // 100:成功;201:没有支付宝账号;202:金额不合法;299:转账失败
674 BillTradeStatus bts = transfer.getStatus() == 1 ? BillTradeStatus.SUCCESS : BillTradeStatus.TRANSFER_FAIL; 675 BillTradeStatus bts = transfer.getStatus() == 1 ? BillTradeStatus.SUCCESS : BillTradeStatus.TRANSFER_FAIL;
675 record.setTradeStatus(bts.getCode()); 676 record.setTradeStatus(bts.getCode());
676 tradeBillsMapper.updateSelectiveByPrimaryKey(record); 677 tradeBillsMapper.updateSelectiveByPrimaryKey(record);
677 - logger.info("transAllEarnest最后更新状态完成,转账结束, orderCode is {}!", orderCode); 678 + logger.info("{}, transfer end update status to {} ok", logTag, transfer.getStatus());
678 } 679 }
679 } 680 }
680 681