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);
|
}
|
}
|