admin
2019-04-19 7da75926f4f910a0fa23ab96f2af637d0a9578a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.yeshi.fanli.service.impl.money;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.money.UserMoneyDebtMapper;
import com.yeshi.fanli.entity.money.UserMoneyDebt;
import com.yeshi.fanli.entity.money.UserMoneyDebt.UserMoneyDebtTypeEnum;
import com.yeshi.fanli.exception.money.UserMoneyDebtException;
import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
 
@Service
public class UserMoneyDebtServiceImpl implements UserMoneyDebtService {
 
    @Resource
    private UserMoneyDebtMapper userMoneyDebtMapper;
 
    @Override
    public void addUserMoneyDebt(UserMoneyDebt debt) throws UserMoneyDebtException {
        if (debt == null)
            return;
 
        if (debt.getType() == UserMoneyDebtTypeEnum.hongBao) {
            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.selectByUidAndSourceId(debt.getUid(), debt.getSourceId());
            if (old != null) {
                throw new UserMoneyDebtException(3, "对应用户的红包已经存在");
            }
            userMoneyDebtMapper.insertSelective(debt);
        }
 
    }
 
}