admin
2020-06-19 31e20ddb1eafa5bf64a0824629fb8c7a05450318
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
package com.ks.tool.bkz.service.impl.user;
 
import com.ks.tool.bkz.dao.mybatis.user.CardPwdInfoMapper;
import com.ks.tool.bkz.entity.user.CardPwdInfo;
import com.ks.tool.bkz.exception.CardPwdException;
import com.ks.tool.bkz.service.user.CardPwdService;
import com.ks.tool.bkz.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Date;
 
@Service
public class CardPwdImpl implements CardPwdService {
    @Resource
    private CardPwdInfoMapper cardPwdInfoMapper;
 
    @Override
    public void addCardPwd(CardPwdInfo info) throws CardPwdException {
 
    }
 
    @Override
    public CardPwdInfo selectByCard(String card) {
        return cardPwdInfoMapper.selectByCard(card);
    }
 
    @Transactional
    @Override
    public void consumeCardPwd(Long uid, String card, String pwd) throws CardPwdException {
        if(uid==null)
            throw new CardPwdException(10, "用户不能为空");
 
        if(StringUtil.isNullOrEmpty(card)||StringUtil.isNullOrEmpty(pwd))
            throw new CardPwdException(10, "卡密不能为空");
 
        CardPwdInfo info = selectByCard(card);
        if (info == null)
            throw new CardPwdException(1, "卡号不存在");
        if (!info.getPwd().equalsIgnoreCase(pwd))
            throw new CardPwdException(2, "卡密不匹配");
        if (info.getConsumeState() == CardPwdInfo.STATE_CONSUMED)
            throw new CardPwdException(3, "卡密已被使用");
 
        CardPwdInfo update = new CardPwdInfo();
        update.setId(info.getId());
        update.setConsumeState(CardPwdInfo.STATE_CONSUMED);
        update.setConsumeTime(new Date());
        update.setConsumeUid(uid);
        update.setUpdateTime(new Date());
        cardPwdInfoMapper.updateByPrimaryKeySelective(update);
    }
}