From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/money/UserMoneyDebtServiceImpl.java |  538 +++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 297 insertions(+), 241 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/UserMoneyDebtServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/UserMoneyDebtServiceImpl.java
index 3fd53c5..e65969c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/UserMoneyDebtServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/UserMoneyDebtServiceImpl.java
@@ -1,241 +1,297 @@
-package com.yeshi.fanli.service.impl.money;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.yeshi.fanli.dao.mybatis.AlipayAccountValidNormalHistoryMapper;
-import com.yeshi.fanli.dao.mybatis.money.UserMoneyDebtMapper;
-import com.yeshi.fanli.dao.mybatis.money.UserMoneyDebtReturnHistoryMapper;
-import com.yeshi.fanli.entity.bus.user.AlipayAccountValidNormalHistory;
-import com.yeshi.fanli.entity.bus.user.HongBaoV2;
-import com.yeshi.fanli.entity.money.UserMoneyDebt;
-import com.yeshi.fanli.entity.money.UserMoneyDebt.UserMoneyDebtTypeEnum;
-import com.yeshi.fanli.entity.money.UserMoneyDebtReturnHistory;
-import com.yeshi.fanli.entity.money.UserMoneyDetail;
-import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
-import com.yeshi.fanli.exception.money.UserMoneyDebtException;
-import com.yeshi.fanli.exception.money.UserMoneyDetailException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
-import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
-import com.yeshi.fanli.service.inter.money.UserMoneyService;
-import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
-import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
-import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
-import com.yeshi.fanli.service.inter.user.UserInfoService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
-
-@Service
-public class UserMoneyDebtServiceImpl implements UserMoneyDebtService {
-
-	@Resource
-	private UserMoneyDebtMapper userMoneyDebtMapper;
-
-	@Resource
-	private UserMoneyDebtReturnHistoryMapper userMoneyDebtReturnHistoryMapper;
-
-	@Resource
-	private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
-
-	@Resource
-	private TaoBaoOrderService taoBaoOrderService;
-
-	@Resource
-	private HongBaoV2Service hongBaoV2Service;
-
-	@Resource
-	private UserMoneyService userMoneyService;
-
-	@Resource
-	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
-
-	@Resource
-	private UserInfoService userInfoService;
-
-	@Resource
-	private AlipayAccountValidNormalHistoryMapper alipayAccountValidNormalHistoryMapper;
-
-	@Override
-	public void addUserMoneyDebt(UserMoneyDebt debt) throws UserMoneyDebtException {
-		if (debt == null)
-			return;
-
-		if (debt.getType() == UserMoneyDebtTypeEnum.order) {
-			if (debt.getSourceId() == null)
-				throw new UserMoneyDebtException(1, "sourceId涓虹┖");
-			if (debt.getUid() == null || debt.getOriginMoney() == null)
-				throw new UserMoneyDebtException(2, "淇℃伅涓嶅畬鏁�");
-
-			if (debt.getLeftMoney() == null)
-				debt.setLeftMoney(debt.getOriginMoney());
-
-			if (debt.getCreateTime() == null)
-				debt.setCreateTime(new Date());
-
-			UserMoneyDebt old = userMoneyDebtMapper.selectByUidAndTypeAndSourceId(debt.getUid(), debt.getType(),
-					debt.getSourceId());
-			if (old != null) {
-				throw new UserMoneyDebtException(3, "瀵瑰簲缁存潈宸茬粡瀛樺湪");
-			}
-			userMoneyDebtMapper.insertSelective(debt);
-		}
-	}
-
-	@Override
-	public UserMoneyDebt selectByTypeAndSourceId(UserMoneyDebtTypeEnum type, Long sourceId) {
-
-		return userMoneyDebtMapper.selectByTypeAndSourceId(type, sourceId);
-	}
-
-	@Transactional
-	@Override
-	public void repayDebt(UserMoneyDebt debt, BigDecimal money) throws UserMoneyDebtException {
-		if (debt == null || debt.getId() == null)
-			throw new UserMoneyDebtException(1, "鍙傛暟涓嶅畬鏁�");
-
-		if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
-			throw new UserMoneyDebtException(2, "鍋胯繕璧勯噾闇�澶т簬0");
-
-		UserMoneyDebt old = userMoneyDebtMapper.selectByPrimaryKey(debt.getId());
-		if (old == null)
-			throw new UserMoneyDebtException(3, "鍊熻捶鍏崇郴涓嶅瓨鍦�");
-
-		if (old.getUid().longValue() != debt.getUid())
-			throw new UserMoneyDebtException(4, "鍙兘鏈汉杩橀挶");
-
-		if (money.compareTo(old.getLeftMoney()) < 0)
-			throw new UserMoneyDebtException(5, "涓嶅杩�");
-
-		UserMoneyDebt update = new UserMoneyDebt();
-		update.setId(old.getId());
-		update.setUpdateTime(new Date());
-		update.setLeftMoney(old.getLeftMoney().subtract(money));
-		userMoneyDebtMapper.updateByPrimaryKeySelective(update);
-
-		UserMoneyDebtReturnHistory history = new UserMoneyDebtReturnHistory();
-		history.setBeiZhu(null);
-		history.setCreateTime(new Date());
-		history.setDebt(old);
-		history.setMoney(money);
-		history.setUid(old.getUid());
-		userMoneyDebtReturnHistoryMapper.insertSelective(history);
-
-		if (debt.getType() == UserMoneyDebtTypeEnum.order) {
-			HongBaoV2 hb = hongBaoV2Service.selectByPrimaryKey(debt.getSourceId());
-			if (hb == null) {
-				throw new UserMoneyDebtException(6, "鍋胯繕鐨勮鍗旾D涓嶅瓨鍦�");
-			}
-
-			TaoBaoWeiQuanDrawBack weiQuanDrawBack = taoBaoWeiQuanDrawBackService.selectByHongBaoId(hb.getId());
-			if (weiQuanDrawBack == null)
-				throw new UserMoneyDebtException(7, "灏氭湭鎵惧埌閫�娆句俊鎭�");
-
-			// 璧勯噾鍙樺寲锛屾坊鍔犵敤鎴疯祫閲戣褰曪紝娣诲姞鐩稿叧閫氱煡
-			Long uid = debt.getUid();
-			switch (hb.getType()) {
-			case HongBaoV2.TYPE_ZIGOU:
-				// 鏂扮増璧勯噾璁板綍
-				try {
-					UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createFanLiWeiQuan(uid, weiQuanDrawBack,
-							money);
-					userMoneyService.subUserMoney(uid, money, userMoneyDetail);
-				} catch (UserMoneyDetailException e) {
-					throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
-				}
-
-				// 鏂扮増閫氱煡
-				userMoneyMsgNotificationService.fanliOrderWeiQuan(uid, weiQuanDrawBack.getOrderId(),
-						Constant.SOURCE_TYPE_TAOBAO, money, userInfoService.getBalance(uid));
-
-				break;
-			case HongBaoV2.TYPE_SHARE_GOODS:
-
-				// 鏂扮増璧勯噾璁板綍
-				try {
-					UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShareWeiQuan(debt.getUid(),
-							weiQuanDrawBack, money);
-					userMoneyService.subUserMoney(uid, money, userMoneyDetail);
-
-					userMoneyMsgNotificationService.shareOrderWeiQuan(debt.getUid(), weiQuanDrawBack.getOrderId(),
-							Constant.SOURCE_TYPE_TAOBAO, money, userInfoService.getBalance(uid));
-
-				} catch (UserMoneyDetailException e) {
-					throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
-				}
-				break;
-			case HongBaoV2.TYPE_SHARE_ERJI:
-			case HongBaoV2.TYPE_SHARE_YIJI:
-			case HongBaoV2.TYPE_ERJI:
-			case HongBaoV2.TYPE_YIJI:
-
-				// 鏂扮増璧勯噾璁板綍
-				try {
-					UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInviteWeiQuan(uid, weiQuanDrawBack,
-							money);
-					userMoneyService.subUserMoney(uid, money, userMoneyDetail);
-				} catch (UserMoneyDetailException e) {
-					throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
-				}
-
-				// 鏂扮増閫氱煡
-				userMoneyMsgNotificationService.inviteOrderWeiQuan(uid, weiQuanDrawBack.getOrderId(),
-						Constant.SOURCE_TYPE_TAOBAO, money, userInfoService.getBalance(uid));
-				break;
-			}
-		} else if (debt.getType() == UserMoneyDebtTypeEnum.extractVerify) {// 鎻愮幇楠岃瘉
-			// 鏂扮増璧勯噾璁板綍
-			AlipayAccountValidNormalHistory aliPayAccountHistory = alipayAccountValidNormalHistoryMapper
-					.selectByPrimaryKey(debt.getSourceId());
-			if (aliPayAccountHistory == null)
-				return;
-			try {
-				UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createExtractAccountValid(aliPayAccountHistory,
-						money);
-				userMoneyService.subUserMoney(aliPayAccountHistory.getUid(), money, userMoneyDetail);
-			} catch (UserMoneyDetailException e) {
-				throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
-			}
-
-			userMoneyMsgNotificationService.alipayAccountValid(aliPayAccountHistory);
-		}
-	}
-
-	@Transactional
-	@Override
-	public void repayDebt(Long uid) {
-		// 鏌ヨ鏄惁鏈夋瑺鍊�
-		List<UserMoneyDebt> list = userMoneyDebtMapper.listByUidWithHasLeftMoney(uid, 0, 50);
-		if (list != null && list.size() > 0) {// 鏈夋瑺鍊�
-			for (UserMoneyDebt debt : list) {
-				BigDecimal leftMoney = userInfoService.getBalance(uid);
-				if (leftMoney.compareTo(debt.getLeftMoney()) >= 0) {// 鏈夎冻澶熺殑璧勯噾鍋胯繕鍊哄姟
-					try {
-						repayDebt(debt, debt.getLeftMoney());
-					} catch (UserMoneyDebtException e) {
-						try {
-							LogHelper.errorDetailInfo(e, "uid:" + uid + " debtId:" + debt.getId(), null);
-						} catch (Exception e1) {
-							e1.printStackTrace();
-						}
-					}
-				}
-			}
-		}
-	}
-
-	@Override
-	public boolean isHaveDebtToRepay(Long uid) {
-		List<UserMoneyDebt> debtList = userMoneyDebtMapper.listByUidWithHasLeftMoney(uid, 0, 1);
-		if (debtList != null && debtList.size() > 0)
-			return true;
-		return false;
-	}
-
-}
+package com.yeshi.fanli.service.impl.money;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.yeshi.fanli.dao.mybatis.AlipayAccountValidNormalHistoryMapper;
+import com.yeshi.fanli.dao.mybatis.money.UserMoneyDebtMapper;
+import com.yeshi.fanli.dao.mybatis.money.UserMoneyDebtReturnHistoryMapper;
+import com.yeshi.fanli.entity.bus.user.AlipayAccountValidNormalHistory;
+import com.yeshi.fanli.entity.bus.user.HongBaoV2;
+import com.yeshi.fanli.entity.money.UserMoneyDebt;
+import com.yeshi.fanli.entity.money.UserMoneyDebt.UserMoneyDebtTypeEnum;
+import com.yeshi.fanli.entity.money.UserMoneyDebtReturnHistory;
+import com.yeshi.fanli.entity.money.UserMoneyDetail;
+import com.yeshi.fanli.entity.order.CommonOrder;
+import com.yeshi.fanli.entity.order.HongBaoOrder;
+import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
+import com.yeshi.fanli.exception.money.UserMoneyDebtException;
+import com.yeshi.fanli.exception.money.UserMoneyDetailException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
+import com.yeshi.fanli.service.inter.money.UserMoneyService;
+import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
+import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
+import com.yeshi.fanli.service.inter.order.CommonOrderService;
+import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
+import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
+import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
+
+@Service
+public class UserMoneyDebtServiceImpl implements UserMoneyDebtService {
+
+    @Resource
+    private UserMoneyDebtMapper userMoneyDebtMapper;
+
+    @Resource
+    private UserMoneyDebtReturnHistoryMapper userMoneyDebtReturnHistoryMapper;
+
+    @Resource
+    private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
+
+    @Resource
+    private TaoBaoOrderService taoBaoOrderService;
+
+    @Resource
+    private HongBaoV2Service hongBaoV2Service;
+
+    @Resource
+    private HongBaoOrderService hongBaoOrderService;
+
+    @Resource
+    private UserMoneyService userMoneyService;
+
+    @Resource
+    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
+
+    @Resource
+    private UserInfoService userInfoService;
+
+    @Resource
+    private AlipayAccountValidNormalHistoryMapper alipayAccountValidNormalHistoryMapper;
+
+    @Resource
+    private CommonOrderService commonOrderService;
+
+    @Override
+    public void addUserMoneyDebt(UserMoneyDebt debt) throws UserMoneyDebtException {
+        if (debt == null)
+            return;
+
+        if (debt.getType() == UserMoneyDebtTypeEnum.order) {
+            if (debt.getSourceId() == null)
+                throw new UserMoneyDebtException(1, "sourceId涓虹┖");
+            if (debt.getUid() == null || debt.getOriginMoney() == null)
+                throw new UserMoneyDebtException(2, "淇℃伅涓嶅畬鏁�");
+
+            if (debt.getLeftMoney() == null)
+                debt.setLeftMoney(debt.getOriginMoney());
+
+            if (debt.getCreateTime() == null)
+                debt.setCreateTime(new Date());
+
+            UserMoneyDebt old = userMoneyDebtMapper.selectByUidAndTypeAndSourceId(debt.getUid(), debt.getType(),
+                    debt.getSourceId());
+            if (old != null) {
+                throw new UserMoneyDebtException(3, "瀵瑰簲鍞悗宸茬粡瀛樺湪");
+            }
+            userMoneyDebtMapper.insertSelective(debt);
+        }
+    }
+
+    @Override
+    public UserMoneyDebt selectByTypeAndSourceId(UserMoneyDebtTypeEnum type, Long sourceId) {
+
+        return userMoneyDebtMapper.selectByTypeAndSourceId(type, sourceId);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void repayDebt(UserMoneyDebt debt, BigDecimal money) throws UserMoneyDebtException {
+        if (debt == null || debt.getId() == null)
+            throw new UserMoneyDebtException(1, "鍙傛暟涓嶅畬鏁�");
+
+        if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
+            throw new UserMoneyDebtException(2, "鍋胯繕璧勯噾闇�澶т簬0");
+
+        UserMoneyDebt old = userMoneyDebtMapper.selectByPrimaryKey(debt.getId());
+        if (old == null)
+            throw new UserMoneyDebtException(3, "鍊熻捶鍏崇郴涓嶅瓨鍦�");
+
+        if (old.getUid().longValue() != debt.getUid())
+            throw new UserMoneyDebtException(4, "鍙兘鏈汉杩橀挶");
+
+        if (money.compareTo(old.getLeftMoney()) < 0)
+            throw new UserMoneyDebtException(5, "涓嶅杩�");
+
+        UserMoneyDebt update = new UserMoneyDebt();
+        update.setId(old.getId());
+        update.setUpdateTime(new Date());
+        update.setLeftMoney(old.getLeftMoney().subtract(money));
+        userMoneyDebtMapper.updateByPrimaryKeySelective(update);
+
+        UserMoneyDebtReturnHistory history = new UserMoneyDebtReturnHistory();
+        history.setBeiZhu(null);
+        history.setCreateTime(new Date());
+        history.setDebt(old);
+        history.setMoney(money);
+        history.setUid(old.getUid());
+        userMoneyDebtReturnHistoryMapper.insertSelective(history);
+
+        if (debt.getType() == UserMoneyDebtTypeEnum.order) {
+            HongBaoV2 hb = hongBaoV2Service.selectByPrimaryKey(debt.getSourceId());
+            if (hb == null) {
+                throw new UserMoneyDebtException(6, "鍋胯繕鐨勮鍗旾D涓嶅瓨鍦�");
+            }
+
+            TaoBaoWeiQuanDrawBack weiQuanDrawBack = taoBaoWeiQuanDrawBackService.selectByHongBaoId(hb.getId());
+            if (weiQuanDrawBack == null)
+                throw new UserMoneyDebtException(7, "灏氭湭鎵惧埌閫�娆句俊鎭�");
+
+            // 璧勯噾鍙樺寲锛屾坊鍔犵敤鎴疯祫閲戣褰曪紝娣诲姞鐩稿叧閫氱煡
+            Long uid = debt.getUid();
+            switch (hb.getType()) {
+                case HongBaoV2.TYPE_ZIGOU:
+                    // 鏂扮増璧勯噾璁板綍
+                    try {
+                        UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createFanLiWeiQuan(uid, weiQuanDrawBack,
+                                money);
+                        userMoneyService.subUserMoney(uid, money, userMoneyDetail);
+                    } catch (UserMoneyDetailException e) {
+                        throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
+                    }
+
+                    // 鏂扮増閫氱煡
+                    List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
+                            weiQuanDrawBack.getOrderId());
+                    int goodsCount = 0;
+                    for (CommonOrder co : orderList) {
+                        if (co.getState() != CommonOrder.STATE_SX)
+                            goodsCount += co.getCount();
+                    }
+
+                    BigDecimal fanliMoney = new BigDecimal(0);
+                    List<HongBaoOrder> hongBaoOrderList = hongBaoOrderService
+                            .listDetailByOrderIdAndSourceType(weiQuanDrawBack.getOrderId(), Constant.SOURCE_TYPE_TAOBAO);
+
+                    for (HongBaoOrder hongBaoOrder : hongBaoOrderList) {
+                        fanliMoney = fanliMoney.add(hongBaoOrder.getHongBaoV2().getMoney());
+                    }
+
+                    userMoneyMsgNotificationService.fanliOrderWeiQuan(uid, weiQuanDrawBack.getOrderId(),
+                            Constant.SOURCE_TYPE_TAOBAO, money, fanliMoney, goodsCount,
+                            orderList.get(0).getThirdCreateTime());
+
+                    break;
+                case HongBaoV2.TYPE_SHARE_GOODS:
+
+                    // 鏂扮増璧勯噾璁板綍
+                    try {
+                        UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShareWeiQuan(debt.getUid(),
+                                weiQuanDrawBack, money);
+                        userMoneyService.subUserMoney(uid, money, userMoneyDetail);
+
+                        // 鏂扮増閫氱煡
+                        List<CommonOrder> orderList1 = commonOrderService
+                                .listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO, weiQuanDrawBack.getOrderId());
+                        int goodsCount1 = 0;
+                        for (CommonOrder co : orderList1) {
+                            if (co.getState() != CommonOrder.STATE_SX)
+                                goodsCount1 += co.getCount();
+                        }
+
+                        BigDecimal fanliMoney1 = new BigDecimal(0);
+                        List<HongBaoOrder> hongBaoOrderList1 = hongBaoOrderService.listDetailByOrderIdAndSourceType(
+                                weiQuanDrawBack.getOrderId(), Constant.SOURCE_TYPE_TAOBAO);
+
+                        for (HongBaoOrder hongBaoOrder : hongBaoOrderList1) {
+                            fanliMoney1 = fanliMoney1.add(hongBaoOrder.getHongBaoV2().getMoney());
+                        }
+
+                        userMoneyMsgNotificationService.shareOrderWeiQuan(uid, weiQuanDrawBack.getOrderId(),
+                                Constant.SOURCE_TYPE_TAOBAO, money, fanliMoney1, goodsCount1,
+                                orderList1.get(0).getThirdCreateTime());
+
+                    } catch (UserMoneyDetailException e) {
+                        throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
+                    }
+                    break;
+                case HongBaoV2.TYPE_SHARE_ERJI:
+                case HongBaoV2.TYPE_SHARE_YIJI:
+                case HongBaoV2.TYPE_ERJI:
+                case HongBaoV2.TYPE_YIJI:
+
+                    // 鏂扮増璧勯噾璁板綍
+                    try {
+                        UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInviteWeiQuan(uid, weiQuanDrawBack,
+                                money);
+                        userMoneyService.subUserMoney(uid, money, userMoneyDetail);
+                    } catch (UserMoneyDetailException e) {
+                        throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
+                    }
+
+                    break;
+            }
+        } else if (debt.getType() == UserMoneyDebtTypeEnum.extractVerify) {// 鎻愮幇楠岃瘉
+            // 鏂扮増璧勯噾璁板綍
+            AlipayAccountValidNormalHistory aliPayAccountHistory = alipayAccountValidNormalHistoryMapper
+                    .selectByPrimaryKey(debt.getSourceId());
+
+            AlipayAccountValidNormalHistory first = alipayAccountValidNormalHistoryMapper
+                    .selectLatestByUid(aliPayAccountHistory.getUid());
+
+            if (aliPayAccountHistory == null)
+                return;
+            try {
+                UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createExtractAccountValid(aliPayAccountHistory,
+                        money);
+                userMoneyService.subUserMoney(aliPayAccountHistory.getUid(), money, userMoneyDetail);
+            } catch (UserMoneyDetailException e) {
+                throw new UserMoneyDebtException(12, "鎻掑叆璧勯噾璇︽儏鍑洪敊");
+            }
+            userMoneyMsgNotificationService.alipayAccountValid(aliPayAccountHistory, "1涓湀",
+                    first.getId().longValue() != aliPayAccountHistory.getId());
+        }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void repayDebt(Long uid) {
+        // 鏌ヨ鏄惁鏈夋瑺鍊�
+        List<UserMoneyDebt> list = userMoneyDebtMapper.listByUidWithHasLeftMoney(uid, 0, 50);
+        if (list != null && list.size() > 0) {// 鏈夋瑺鍊�
+            for (UserMoneyDebt debt : list) {
+                BigDecimal leftMoney = userInfoService.getBalance(uid);
+                if (leftMoney.compareTo(debt.getLeftMoney()) >= 0) {// 鏈夎冻澶熺殑璧勯噾鍋胯繕鍊哄姟
+                    try {
+                        repayDebt(debt, debt.getLeftMoney());
+                    } catch (UserMoneyDebtException e) {
+                        try {
+                            LogHelper.errorDetailInfo(e, "uid:" + uid + " debtId:" + debt.getId(), null);
+                        } catch (Exception e1) {
+                            e1.printStackTrace();
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public boolean isHaveDebtToRepay(Long uid) {
+        List<UserMoneyDebt> debtList = userMoneyDebtMapper.listByUidWithHasLeftMoney(uid, 0, 1);
+        if (debtList != null && debtList.size() > 0)
+            return true;
+        return false;
+    }
+
+    @Override
+    public List<Long> listNeedRepayDebtUser(int page, int pageSize) {
+        return userMoneyDebtMapper.listUidWithHasDebtToRepay((page - 1) * pageSize, pageSize);
+    }
+
+    @Override
+    public long countNeedRepayDebtUser() {
+        return userMoneyDebtMapper.countUidWithHasDebtToRepay();
+    }
+
+}

--
Gitblit v1.8.0