From fde1eb082b0de793b36574c311ee8f3d6410feeb Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期四, 02 四月 2020 11:22:10 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div
---
fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java | 57 +++++++++++++++++++++++++++++++++++----------------------
1 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java
index 04176c2..e8cc4a8 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java
@@ -2,6 +2,7 @@
import java.math.BigDecimal;
import java.util.Date;
+import java.util.List;
import javax.annotation.Resource;
@@ -14,6 +15,7 @@
import com.yeshi.fanli.exception.redpack.RedPackBalanceException;
import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
+import com.yeshi.fanli.vo.redpack.RedPackBalanceVO;
@Service
public class RedPackBalanceServiceImpl implements RedPackBalanceService {
@@ -29,26 +31,14 @@
return redPackBalanceMapper.selectByPrimaryKey(uid);
}
- private void verify(RedPackBalance redPackBalance) throws RedPackBalanceException{
- if (redPackBalance == null)
- return;
-
- if (redPackBalance.getState() != null && redPackBalance.getState() == RedPackBalance.STATE_LOCKED)
- throw new RedPackBalanceException(1, "绾㈠寘宸插皝绂侊紝鎰熻阿浣跨敤");
- }
-
@Override
- public BigDecimal getBalance(Long uid) throws RedPackBalanceException{
+ public BigDecimal getBalance(Long uid){
if (uid == null || uid == 0)
return new BigDecimal(0);
RedPackBalance redPackBalance = redPackBalanceMapper.selectByPrimaryKey(uid);
- if (redPackBalance != null) {
- // 楠岃瘉
- verify(redPackBalance);
-
- return redPackBalance.getMoney();
- }
+ if (redPackBalance != null && redPackBalance.getMoney() != null)
+ return redPackBalance.getMoney();
return new BigDecimal(0);
}
@@ -66,13 +56,10 @@
redPackBalance = new RedPackBalance();
redPackBalance.setId(uid);
redPackBalance.setMoney(money);
- redPackBalance.setState(RedPackBalance.STATE_INIT);
redPackBalance.setCreateTime(new Date());
redPackBalance.setUpdateTime(new Date());
redPackBalanceMapper.insertSelective(redPackBalance);
} else {
- // 楠岃瘉
- verify(redPackBalance);
redPackBalanceMapper.addRedPack(uid, money);
}
}
@@ -91,11 +78,37 @@
if (balance.getMoney().compareTo(money) < 0)
throw new RedPackBalanceException(2, "绾㈠寘浣欓涓嶈冻");
-
- // 楠岃瘉
- verify(balance);
-
+
// 鍑忓皯绾㈠寘
redPackBalanceMapper.subRedPack(uid, money);
}
+
+
+ @Override
+ public RedPackBalance selectForUpdate(Long uid) {
+ return redPackBalanceMapper.selectForUpdate(uid);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void resetRedPack(Long uid, RedPackDetail detail) throws RedPackBalanceException {
+ if (uid == null || uid == 0 || detail == null)
+ throw new RedPackBalanceException(1, "鍙傛暟浼犻�掍笉瀹屾暣");
+ // 鍔犲叆鏄庣粏
+ redPackDetailService.insertSelective(detail);
+ // 閲嶇疆
+ redPackBalanceMapper.resetRedPack(uid);
+ }
+
+
+ @Override
+ public List<RedPackBalanceVO> query(Integer start, Integer count, String key, Integer state,Integer order){
+ return redPackBalanceMapper.query(start, count, key, state,order);
+ }
+
+ @Override
+ public long count(String key, Integer state){
+ return redPackBalanceMapper.count(key, state);
+ }
+
}
--
Gitblit v1.8.0