package com.yeshi.fanli.service.impl.user.vip;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPInfoMapper;
|
import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
|
import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
|
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
|
@Service
|
public class UserVIPInfoServiceImpl implements UserVIPInfoService {
|
|
@Resource
|
private UserVIPInfoMapper userVIPInfoMapper;
|
|
@Override
|
public void addUserVIPInfo(UserVIPInfo info) throws UserVIPInfoException {
|
if (info.getId() == null) {
|
throw new UserVIPInfoException(1, "信息不完整");
|
}
|
UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(info.getId());
|
if (userInfo != null) {
|
throw new UserVIPInfoException(1, "信息已存在");
|
}
|
// 初始化状态
|
info.setState(UserVIPInfo.STATE_INVALID);
|
info.setCreateTime(new Date());
|
userVIPInfoMapper.insert(info);
|
}
|
|
@Transactional
|
@Override
|
public void passVIPApply(Long uid) throws UserVIPInfoException {
|
UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
if (userInfo == null) {
|
throw new UserVIPInfoException(1, "用户信息不存在");
|
}
|
if (userInfo.getState() != UserVIPInfo.STATE_VERIFING) {
|
throw new UserVIPInfoException(2, "申请未处于审核状态");
|
}
|
|
UserVIPInfo info = new UserVIPInfo();
|
info.setId(userInfo.getId());
|
info.setSuccessTime(new Date());
|
info.setState(UserVIPInfo.STATE_SUCCESS);
|
info.setUpdateTime(new Date());
|
userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
}
|
|
@Transactional
|
@Override
|
public void rejectVIPApply(Long uid, String reason) throws UserVIPInfoException {
|
UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
if (userInfo == null) {
|
throw new UserVIPInfoException(1, "用户信息不存在");
|
}
|
if (userInfo.getState() != UserVIPInfo.STATE_VERIFING) {
|
throw new UserVIPInfoException(2, "申请未处于审核状态");
|
}
|
|
UserVIPInfo info = new UserVIPInfo();
|
info.setId(userInfo.getId());
|
info.setState(UserVIPInfo.STATE_INVALID);
|
info.setUpdateTime(new Date());
|
userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
}
|
|
@Transactional
|
@Override
|
public void applyVIP(Long uid) throws UserVIPInfoException {
|
UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
if (userInfo == null) {
|
throw new UserVIPInfoException(1, "用户信息不存在");
|
}
|
|
if (userInfo.getState() != UserVIPInfo.STATE_INVALID) {
|
throw new UserVIPInfoException(2, "已经申请过");
|
}
|
|
UserVIPInfo info = new UserVIPInfo();
|
info.setId(userInfo.getId());
|
info.setApplyTime(new Date());
|
info.setState(UserVIPInfo.STATE_VERIFING);
|
info.setUpdateTime(new Date());
|
userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
}
|
|
@Override
|
public boolean isVIP(Long uid) {
|
UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(uid);
|
if (userInfo != null && userInfo.getState() == UserVIPInfo.STATE_SUCCESS)
|
return true;
|
else
|
return false;
|
}
|
|
@Override
|
public UserVIPInfo selectByUid(Long uid) {
|
UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(uid);
|
return userInfo;
|
}
|
|
@Override
|
public Map<Long, Boolean> listByUids(List<Long> uids) {
|
if (uids == null || uids.size() == 0)
|
return new HashMap<>();
|
List<UserVIPInfo> infoList = userVIPInfoMapper.listByUids(uids);
|
// 整理数据
|
Map<Long, Boolean> map = new HashMap<>();
|
if (infoList != null)
|
for (UserVIPInfo info : infoList)
|
if (info != null && info.getState() == UserVIPInfo.STATE_SUCCESS)
|
map.put(info.getId(), true);
|
else
|
map.put(info.getId(), false);
|
for (Long uid : uids) {
|
if (map.get(uid) == null)
|
map.put(uid, false);
|
}
|
return map;
|
}
|
|
}
|