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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.xzx.gc.user.service;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.utils.StringUtils;
import com.xzx.gc.entity.*;
import com.xzx.gc.user.dto.*;
import com.xzx.gc.user.mapper.AccountMapper;
import com.xzx.gc.user.mapper.JhyInfoMapper;
import com.xzx.gc.user.mapper.UserLoginInfoMapper;
import com.xzx.gc.user.mapper.UserMapper;
import com.xzx.gc.user.vo.GetScoreNumVo;
import com.xzx.gc.user.vo.JhyInfoListVo;
import com.xzx.gc.user.vo.ViewJhyInfoVo;
import lombok.extern.slf4j.Slf4j;
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.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Service
@Transactional
public class JhyInfoService {
 
    @Autowired
    private JhyInfoMapper jhyInfoMapper;
 
    @Autowired
    private UserMapper userMapper;
 
    @Autowired
    private UserLoginInfoMapper userLoginInfoMapper;
    @Autowired
    private AccountMapper accountMapper;
 
    public void applyJhy(JhyApplyDto applyDto) {
        JhyInfo mobileIsExist = jhyInfoMapper.selectExistJhyByIndeityOrMobile(applyDto.getMobile(), applyDto.getIdentity());
        if (mobileIsExist != null) {
            if (applyDto.getUserId().equals(mobileIsExist.getUserId())) {
                throw new RestException(-3, "审核中或审核成功, 请勿重复提交");
            }
 
            throw new RestException(-3, "手机号/身份证号已注册集物员");
        }
 
        jhyInfoMapper.deleteByUserId(applyDto.getUserId());
 
        log.info("图片地址:{}", applyDto.getCardPos());
        JhyInfo jhyInfo = new JhyInfo();
        BeanUtil.copyProperties(applyDto, jhyInfo);
        jhyInfo.setCreatedTime(new Date());
        jhyInfo.setIsJhy(JhyInfo.IS_JHY_N);
        jhyInfo.setCardPos(applyDto.getCardPos());
        jhyInfo.setStatus(JhyInfo.CHECK_WAIT);
        jhyInfoMapper.insert(jhyInfo);
    }
 
    public int applyStatus(String userId) {
        JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(userId);
        if (jhyInfo == null) {
            return 0;
        }
 
        return jhyInfo.getStatus();
    }
 
    public int isJhy(String userId) {
        JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(userId);
        if (jhyInfo == null) {
            return 0;
        }
 
        if (JhyInfo.CHECK_REFUSE.equals(jhyInfo.getStatus())) {
            return 0;
        }
 
        if (JhyInfo.CHECK_PASS.equals(jhyInfo.getStatus())) {
            return 1;
        } else {
            return 2;
        }
    }
 
    public Map<String, Object> queryList(JhyInfoListDto jhyInfoListDto) {
        PageHelper.startPage(jhyInfoListDto.getPage(), jhyInfoListDto.getLimit());
        List<JhyInfoListVo> jhyInfoListVos = jhyInfoMapper.selectJhyInfoList(jhyInfoListDto);
        if(CollUtil.isNotEmpty(jhyInfoListVos)){
            for(JhyInfoListVo jhyInfoListVo : jhyInfoListVos){
                String userId = jhyInfoListVo.getUserId();
                if(StrUtil.isNotEmpty(userId)){
                    AccountInfo accountInfo = accountMapper.selectOneByUserId(userId);
                    String collectScore = StrUtil.isEmpty(accountInfo.getCollectScore()) ? "0" : accountInfo.getCollectScore();
                    jhyInfoListVo.setScore(new BigDecimal(collectScore).setScale( 2, BigDecimal.ROUND_DOWN ));
 
                    Example example = new Example(UserLoginInfo.class);
                    Example.Criteria criteria = example.createCriteria();
                    criteria.andEqualTo("userId", userId);
                    example.setOrderByClause("login_time desc");
                    List<UserLoginInfo> userLoginInfos = userLoginInfoMapper.selectByExample(example);
                    if (CollUtil.isNotEmpty(userLoginInfos)) {
                        jhyInfoListVo.setLastLogintime(CollUtil.getFirst(userLoginInfos).getLoginTime());
                    }
                }
            }
        }
        PageInfo<JhyInfoListVo> pageInfo = new PageInfo<>(jhyInfoListVos);
 
        Map<String, Object> data = new HashMap<>();
        int count = Convert.toInt(pageInfo.getTotal());
        data.put("data", jhyInfoListVos);
        data.put("count", count);
        data.put("code", 0);
        return data;
    }
 
    public void examineJwy(ExamineJwyDto model) {
        long id = model.getId();
        JhyInfo jhyInfo = jhyInfoMapper.selectByPrimaryKey(id);
        Integer type = model.getType();
        if(1 == type){
            jhyInfo.setStatus(2);
            jhyInfo.setIsJhy(1+"");
        }else if(2 == type){
            jhyInfo.setStatus(3);
            jhyInfo.setIsJhy(2+"");
        }
        jhyInfoMapper.updateByPrimaryKey(jhyInfo);
    }
 
    public void addScoreNum(AddScoreNumDto model) {
        Example exampleAccount = new Example(AccountInfo.class);
        Example.Criteria criteriaAccount = exampleAccount.createCriteria();
        criteriaAccount.andEqualTo("userId",model.getUserId());
        List<AccountInfo> accountInfos = accountMapper.selectByExample(exampleAccount);
        if(CollUtil.isNotEmpty(accountInfos)){
            AccountInfo accountInfo = accountInfos.get(0);
            String collectScore = StrUtil.isEmpty(accountInfo.getCollectScore())?"0":accountInfo.getCollectScore();
//            collectScore = collectScore + model.getScore();
            accountInfo.setCollectScore(model.getScore().toString());
            accountMapper.updateByPrimaryKey(accountInfo);
 
            ScoreDetails scoreDetailsRet = new ScoreDetails();
            scoreDetailsRet.setUserId(model.getUserId());
            scoreDetailsRet.setType(ScoreDetails.SCORE_TYPE_ADMIN_RECHARGE);
            scoreDetailsRet.setOriginalScore(new BigDecimal(collectScore).setScale( 0, BigDecimal.ROUND_DOWN ));
            scoreDetailsRet.setCurrentScore(new BigDecimal(model.getScore()).setScale( 0, BigDecimal.ROUND_DOWN ));
            scoreDetailsRet.setChangeScore(new BigDecimal(model.getScore()).setScale( 0, BigDecimal.ROUND_DOWN ));
            scoreDetailsRet.setCreatedTime(new Date());
            accountMapper.insertScoreDetailsRet(scoreDetailsRet);
        }
    }
 
    public GetScoreNumVo getScoreNum(GetScoreNumDto model) {
        GetScoreNumVo getScoreNumVo = new GetScoreNumVo();
        Example exampleAccount = new Example(AccountInfo.class);
        Example.Criteria criteriaAccount = exampleAccount.createCriteria();
        criteriaAccount.andEqualTo("userId",model.getUserId());
        List<AccountInfo> accountInfos = accountMapper.selectByExample(exampleAccount);
        if(CollUtil.isNotEmpty(accountInfos)){
            AccountInfo accountInfo = accountInfos.get(0);
            getScoreNumVo.setScore(new BigDecimal(StrUtil.isEmpty(accountInfo.getCollectScore())?"0":accountInfo.getCollectScore()).setScale( 0, BigDecimal.ROUND_DOWN ));
        }
        return getScoreNumVo;
    }
 
    public ViewJhyInfoVo viewJhyInfo(Long id) {
        JhyInfo jhyInfo = jhyInfoMapper.selectByPrimaryKey(id);
        ViewJhyInfoVo viewJhyInfoVo = new ViewJhyInfoVo();
        viewJhyInfoVo.setIsJhy(jhyInfo.getIsJhy());
        viewJhyInfoVo.setUsername(jhyInfo.getUsername());
        viewJhyInfoVo.setMobile(jhyInfo.getMobile());
        viewJhyInfoVo.setIdCard(jhyInfo.getIdentity());
        viewJhyInfoVo.setIdCardImg(jhyInfo.getCardPos());
        viewJhyInfoVo.setAddress(jhyInfo.getAddress());
        String userId = jhyInfo.getUserId();
        AccountInfo accountInfo = accountMapper.selectOneByUserId(userId);
        String collectScore = accountInfo.getCollectScore();
        BigDecimal bigDecimal = new BigDecimal(StrUtil.isEmpty(collectScore) ? "0" : collectScore).setScale( 2, BigDecimal.ROUND_DOWN );
        viewJhyInfoVo.setScore(bigDecimal);
        viewJhyInfoVo.setCreateTime(jhyInfo.getCreatedTime().toString());
 
        UserInfo userInfo = userMapper.selectByPrimaryKey(userId);
        String nickName = userInfo.getNickName();
        if(StrUtil.isNotEmpty(nickName)){
            String decode = StringUtils.decode(nickName);
            viewJhyInfoVo.setNickname(decode);
        }
 
        List<UserLoginInfo> userLoginInfos = userLoginInfoMapper.selectOneByUserId(userId);
        if(CollUtil.isNotEmpty(userLoginInfos)){
            String loginTime = userLoginInfos.get(0).getLoginTime();
            viewJhyInfoVo.setLoginTime(loginTime);
        }
        return viewJhyInfoVo;
    }
 
    public void updateJhyInfo(UpdateJhyInfoDto model) {
        JhyInfo jhyInfo = jhyInfoMapper.selectByPrimaryKey(model.getId());
        String mobile = model.getMobile();
        String isJhy = model.getIsJhy();
        jhyInfo.setIsJhy(isJhy);
        jhyInfo.setMobile(mobile);
        jhyInfoMapper.updateByPrimaryKey(jhyInfo);
    }
}