| | |
| | | package com.yeshi.fanli.service.manger.user;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
| | |
|
| | | @Component
|
| | | public class UserLevelManager {
|
| | | @Resource
|
| | | private UserVIPInfoService userVIPInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserVIPPreInfoService userVIPPreInfoService;
|
| | |
|
| | | /**
|
| | | * 获取用户等级
|
| | | * @Title: getUserLevel
|
| | | * @Description: |
| | | * @param uid
|
| | | * @return |
| | | * UserLevelEnum 返回类型
|
| | | * @throws
|
| | | */
|
| | | public UserLevelEnum getUserLevel(Long uid) {
|
| | | UserVIPPreInfo info = userVIPPreInfoService.getLatestProcessInfo(uid);
|
| | | if (info != null)
|
| | | for (UserLevelEnum level : UserLevelEnum.values())
|
| | | if (level.getLevel() == info.getProcess())
|
| | | return level;
|
| | | return UserLevelEnum.daRen;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取当时的用户等级
|
| | | * @Title: getUserLevel
|
| | | * @Description: |
| | | * @param uid
|
| | | * @param date
|
| | | * @return |
| | | * UserLevelEnum 返回类型
|
| | | * @throws
|
| | | */
|
| | | public UserLevelEnum getUserLevel(Long uid, Date date) {
|
| | | UserVIPPreInfo info = userVIPPreInfoService.getProcessInfo(uid, date);
|
| | | if (info != null)
|
| | | for (UserLevelEnum level : UserLevelEnum.values())
|
| | | if (level.getLevel() == info.getProcess())
|
| | | return level;
|
| | | return UserLevelEnum.daRen;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void setUserLevel(Long uid, UserLevelEnum level, Date date) {
|
| | |
|
| | | // 删除原有等级
|
| | |
|
| | | for (UserLevelEnum le : UserLevelEnum.values()) {
|
| | | UserVIPPreInfo info = userVIPPreInfoService.getVipByProcess(uid, le.getLevel());
|
| | | if (info != null)
|
| | | userVIPPreInfoService.deleteByPrimaryKey(info.getId());
|
| | | }
|
| | |
|
| | | // 添加新的等级
|
| | | if (level == UserLevelEnum.daRen)
|
| | | return;
|
| | |
|
| | | UserVIPPreInfo info = new UserVIPPreInfo();
|
| | | info.setCreateTime(date);
|
| | | info.setProcess(level.getLevel());
|
| | | info.setUid(uid);
|
| | | try {
|
| | | userVIPPreInfoService.addUserVIPPreInfo(info);
|
| | | } catch (UserVIPPreInfoException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.manger.user; |
| | | |
| | | import java.util.Date; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo; |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService; |
| | | |
| | | @Component |
| | | public class UserLevelManager { |
| | | @Resource |
| | | private UserVIPInfoService userVIPInfoService; |
| | | |
| | | @Resource |
| | | private UserVIPPreInfoService userVIPPreInfoService; |
| | | |
| | | /** |
| | | * 获取用户等级 |
| | | * @Title: getUserLevel |
| | | * @Description: |
| | | * @param uid |
| | | * @return |
| | | * UserLevelEnum 返回类型 |
| | | * @throws |
| | | */ |
| | | public UserLevelEnum getUserLevel(Long uid) { |
| | | UserVIPPreInfo info = userVIPPreInfoService.getLatestProcessInfo(uid); |
| | | if (info != null) |
| | | for (UserLevelEnum level : UserLevelEnum.values()) |
| | | if (level.getLevel() == info.getProcess()) |
| | | return level; |
| | | return UserLevelEnum.daRen; |
| | | } |
| | | |
| | | /** |
| | | * 获取当时的用户等级 |
| | | * @Title: getUserLevel |
| | | * @Description: |
| | | * @param uid |
| | | * @param date |
| | | * @return |
| | | * UserLevelEnum 返回类型 |
| | | * @throws |
| | | */ |
| | | public UserLevelEnum getUserLevel(Long uid, Date date) { |
| | | UserVIPPreInfo info = userVIPPreInfoService.getProcessInfo(uid, date); |
| | | if (info != null) |
| | | for (UserLevelEnum level : UserLevelEnum.values()) |
| | | if (level.getLevel() == info.getProcess()) |
| | | return level; |
| | | return UserLevelEnum.daRen; |
| | | } |
| | | |
| | | @Transactional |
| | | public void setUserLevel(Long uid, UserLevelEnum level, Date date) { |
| | | |
| | | // 删除原有等级 |
| | | |
| | | for (UserLevelEnum le : UserLevelEnum.values()) { |
| | | UserVIPPreInfo info = userVIPPreInfoService.getVipByProcess(uid, le.getLevel()); |
| | | if (info != null) |
| | | userVIPPreInfoService.deleteByPrimaryKey(info.getId()); |
| | | } |
| | | |
| | | // 添加新的等级 |
| | | if (level == UserLevelEnum.daRen) |
| | | return; |
| | | |
| | | UserVIPPreInfo info = new UserVIPPreInfo(); |
| | | info.setCreateTime(date); |
| | | info.setProcess(level.getLevel()); |
| | | info.setUid(uid); |
| | | //默认为订单型 |
| | | info.setSourceType(UserVIPPreInfo.SOURCE_TYPE_ORDER); |
| | | try { |
| | | userVIPPreInfoService.addUserVIPPreInfo(info); |
| | | } catch (UserVIPPreInfoException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |