xiaoyong931011
2021-08-04 ea868a98b776b9e89db429a195704a1412ca8905
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.xzx.gc.user.service;
 
import cn.hutool.core.date.DateUtil;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.utils.BusinessUtil;
import com.xzx.gc.common.utils.IdUtils;
import com.xzx.gc.entity.AccountInfo;
import com.xzx.gc.user.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
 
import java.math.BigDecimal;
import java.util.List;
 
@Service
@Transactional
public class AccountService {
 
    @Autowired
    private AccountMapper accountMapper;
 
    @Autowired
    private IdUtils idUtils;
 
    @Autowired
    private BusinessUtil businessUtil;
 
    public List<AccountInfo> findAll(){
        Example example = new Example(AccountInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("delFlag", 0);
        criteria.andEqualTo("isProhibit", 0);
        List<AccountInfo> accountInfos = accountMapper.selectByExample(example);
        return accountInfos;
    }
 
 
    public AccountInfo findById(String accountId){
        return accountMapper.selectByPrimaryKey(accountId);
    }
 
    public AccountInfo findByUserId(String userId){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setDelFlag(Constants.DEL_NOT_FLAG);
        accountInfo.setUserId(userId);
        accountInfo.setIsProhibit("0");
        AccountInfo accountInfo1 = accountMapper.selectOne(accountInfo);
        return accountInfo1;
    }
 
    public AccountInfo findByUserIdForbidden(String userId){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setDelFlag(Constants.DEL_NOT_FLAG);
        accountInfo.setUserId(userId);
        AccountInfo accountInfo1 = accountMapper.selectOne(accountInfo);
        return accountInfo1;
    }
 
    public List<AccountInfo> findByMobile(String mobile){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setAccountName(mobile);
        accountInfo.setDelFlag(Constants.DEL_NOT_FLAG);
        List<AccountInfo> select = accountMapper.select(accountInfo);
        return select;
    }
 
    public void deleteByUserId(String userId){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setDelFlag(Constants.DEL_FLAG);
        accountInfo.setUpdateTime(DateUtil.now());
        Example example=new Example(AccountInfo.class);
        example.createCriteria().andEqualTo("userId",userId);
         accountMapper.updateByExampleSelective(accountInfo,example);
    }
 
    public void deleteByAccountId(String accountId){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setDelFlag(Constants.DEL_FLAG);
        accountInfo.setAccountId(accountId);
        accountMapper.updateByPrimaryKeySelective(accountInfo);
    }
 
    /**
     * 添加默认账户
     * @param mobile
     * @param userId
     */
    public int addDefault(String mobile,String userId){
        AccountInfo accountInfo =init(mobile,userId);
        return accountMapper.insertSelective(accountInfo);
    }
 
    public void add(AccountInfo accountInfo){
        accountMapper.insertSelective(accountInfo);
    }
 
    public AccountInfo init(String mobile,String userId){
        AccountInfo accountInfo =new AccountInfo();
        accountInfo.setAccountId(idUtils.generate("ZH",4));
        accountInfo.setAccountName(mobile);
        accountInfo.setUserId(userId);
        accountInfo.setFreezeMoney("0");
        accountInfo.setWithdrawMoney("0");
        accountInfo.setMoney("0");
        accountInfo.setDelFlag(0);
        accountInfo.setErrorTimes(0);
        accountInfo.setIsProhibit("0");
        accountInfo.setCreateTime(DateUtil.now());
        accountInfo.setUpdateTime(DateUtil.now());
        accountInfo.setCollectScore("0");
        return accountInfo;
    }
 
    public void updateOverLimitByAccountId(String accountId,BigDecimal overdraftLimit){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setAccountId(accountId);
        accountInfo.setOverdraftLimit(businessUtil.changeMoney(overdraftLimit));
        accountMapper.updateByPrimaryKeySelective(accountInfo);
    }
 
    public void updateFixLimitByAccountId(String accountId,BigDecimal overdraftLimit){
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setAccountId(accountId);
        accountInfo.setFixedLimit(businessUtil.changeMoney(overdraftLimit));
        accountMapper.updateByPrimaryKeySelective(accountInfo);
    }
}