admin
2020-06-17 87b391b8a81ee2abdaa4131d245784ecc7a54e9a
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
package com.ks.tool.bkz.service.impl.user;
 
import com.ks.tool.bkz.entity.user.CardPwdInfo;
import com.ks.tool.bkz.entity.user.CardPwdTypeEnum;
import com.ks.tool.bkz.entity.user.SDLJShareOpenHistory;
import com.ks.tool.bkz.entity.user.UserInfo;
import com.ks.tool.bkz.exception.CardPwdException;
import com.ks.tool.bkz.exception.SDLJShareOpenHistoryException;
import com.ks.tool.bkz.exception.UserException;
import com.ks.tool.bkz.service.user.CardPwdService;
import com.ks.tool.bkz.service.user.SDLJShareOpenHistoryService;
import com.ks.tool.bkz.service.user.UserService;
import com.ks.tool.bkz.service.user.UserUpgradeService;
import com.ks.tool.bkz.util.CardPwdUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Date;
 
@Service
public class UserUpgradeServiceImpl implements UserUpgradeService {
    @Resource
    private CardPwdService cardPwdService;
    @Resource
    private UserService userService;
    @Resource
    private SDLJShareOpenHistoryService sdljShareOpenHistoryService;
 
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void upgradeSDLJShare(Long uid, String card, String pwd) throws UserException, CardPwdException, SDLJShareOpenHistoryException {
        UserInfo user = userService.selectValidByPrimaryKey(uid);
 
        if (user == null)
            throw new UserException(1, "用户不存在");
        cardPwdService.consumeCardPwd(uid, card, pwd);
        //查询卡密类型
        CardPwdInfo info = cardPwdService.selectByCard(card);
        CardPwdTypeEnum type = CardPwdUtil.getTypeEnumByType(info.getType());
        if (type == null)
            throw new CardPwdException(20, "未找到卡密对应的类型");
        SDLJShareOpenHistory latestHistory = sdljShareOpenHistoryService.selectLatestHistory(uid);
        Date startTime = null;
        if (latestHistory != null)
            startTime = latestHistory.getExpireTime();
        else
            startTime = new Date();
 
        Date expireTime = CardPwdUtil.getExpireTime(startTime, type);
        SDLJShareOpenHistory history = new SDLJShareOpenHistory();
        history.setExpireTime(expireTime);
        history.setCreateTime(new Date());
        history.setStartTime(startTime);
        sdljShareOpenHistoryService.addHistory(history);
    }
}