查询登录用户权限信息,使用UserUtils

This commit is contained in:
2023-11-11 15:40:30 +08:00
parent 5f44c35d03
commit 7c5e55b9ee
5 changed files with 91 additions and 65 deletions

View File

@@ -21,6 +21,7 @@ import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO;
import com.jsowell.pile.service.IMemberBasicInfoService;
import com.jsowell.pile.service.IMemberPlateNumberRelationService;
import com.jsowell.pile.service.IMemberTransactionRecordService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.uniapp.MemberVO;
import com.jsowell.pile.vo.uniapp.MemberWalletLogVO;
@@ -74,7 +75,8 @@ public class MemberBasicInfoController extends BaseController {
public RestApiResponse<?> getMerchantListByAuth() {
RestApiResponse<?> response = null;
// List<MerchantInfoVO> list = memberBasicInfoService.getMerchantListByAuth(deptIds);
List<MerchantInfoVO> list = memberBasicInfoService.getMerchantListByAuth();
// List<MerchantInfoVO> list = memberBasicInfoService.getMerchantListByAuth();
List<MerchantInfoVO> list = UserUtils.getMerchantListByAuth();
if (CollectionUtils.isEmpty(list)) {
list = new ArrayList<>();
}

View File

@@ -4,7 +4,6 @@ import com.jsowell.pile.domain.MemberBasicInfo;
import com.jsowell.pile.dto.PlatformTesterDTO;
import com.jsowell.pile.dto.QueryMemberInfoDTO;
import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.uniapp.MemberBalanceVO;
import com.jsowell.pile.vo.uniapp.MemberVO;
import com.jsowell.pile.vo.uniapp.MemberWalletLogVO;
@@ -147,10 +146,4 @@ public interface IMemberBasicInfoService {
* @return
*/
List<MemberBalanceVO> getMemberRefundAmount(List<String> memberIds);
/**
* 获取当前会员中的运营商列表(带权限校验)
*/
List<MerchantInfoVO> getMerchantListByAuth();
}

View File

@@ -4,14 +4,10 @@ import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.entity.SysDept;
import com.jsowell.common.core.domain.entity.SysUser;
import com.jsowell.common.core.domain.model.LoginUser;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.PlatformTesterDTO;
@@ -23,7 +19,6 @@ import com.jsowell.pile.mapper.MemberWalletInfoMapper;
import com.jsowell.pile.mapper.MemberWalletLogMapper;
import com.jsowell.pile.service.*;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.uniapp.MemberBalanceVO;
import com.jsowell.pile.vo.uniapp.MemberVO;
import com.jsowell.pile.vo.uniapp.MemberWalletLogVO;
@@ -39,7 +34,6 @@ import org.springframework.util.StopWatch;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 会员基础信息Service业务层处理
@@ -425,54 +419,4 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
return memberWalletLogMapper.getMemberRefundAmount(memberIds);
}
/**
* 获取当前会员中的运营商列表(带权限校验)
*/
@Override
public List<MerchantInfoVO> getMerchantListByAuth() {
List<MerchantInfoVO> resultList = Lists.newArrayList();
// 获取登录用户 所有有权限运营商
LoginUser loginUser = SecurityUtils.getLoginUser();
if (Objects.isNull(loginUser)) {
return resultList;
}
// 获取登录用户对应的user对象
SysUser user = loginUser.getUser();
if (Objects.isNull(user)) {
return resultList;
}
// 获取所属部门id
SysDept dept = user.getDept();
if (Objects.isNull(dept)) {
return resultList;
}
String deptLevel = dept.getDeptLevel();
String deptId = String.valueOf(dept.getDeptId());
if (Constants.ZERO.equals(deptLevel)) {
// 平台级权限 查询所有生效的运营商
resultList = pileMerchantInfoService.selectAll();
} else if (Constants.ONE.equals(deptLevel)) {
// 一级运营商权限 查询该一级运营商下面的所有运营商
PileMerchantInfo merchantInfo = pileMerchantInfoService.queryInfoByDeptId(deptId);
resultList = pileMerchantInfoService.selectListByFirstMerchant(merchantInfo.getId() + "");
} else if (Constants.TWO.equals(deptLevel) ) {
// 二级运营商权限 返回自身运营商
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.queryMerchantInfoVOByDeptId(deptId);
if (Objects.nonNull(merchantInfoVO)) {
resultList.add(merchantInfoVO);
}
} else if (Constants.THREE.equals(deptLevel)) {
// 站点权限 返回自身运营商
PileStationInfo stationInfo = pileStationInfoService.queryInfoByDeptId(deptId);
if (Objects.nonNull(stationInfo)) {
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(stationInfo.getMerchantId() + "");
if (Objects.nonNull(merchantInfoVO)) {
resultList.add(merchantInfoVO);
}
}
}
return resultList;
}
}

View File

@@ -2,17 +2,24 @@ package com.jsowell.pile.util;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.entity.SysDept;
import com.jsowell.common.core.domain.entity.SysUser;
import com.jsowell.common.core.domain.model.LoginUser;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.domain.PileStationInfo;
import com.jsowell.pile.service.IMemberBasicInfoService;
import com.jsowell.pile.service.IPileMerchantInfoService;
import com.jsowell.pile.service.IPileStationInfoService;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
/**
* 后管登录用户工具类
@@ -25,10 +32,17 @@ public class UserUtils {
// 2.注入想引用的对象的静态实例
private static IMemberBasicInfoService memberBasicInfoService;
private static IPileMerchantInfoService pileMerchantInfoService;
private static IPileStationInfoService pileStationInfoService;
// 3.初始化有参构造器
@Autowired
public UserUtils(IMemberBasicInfoService memberBasicInfoService) {
public UserUtils(IMemberBasicInfoService memberBasicInfoService, IPileMerchantInfoService pileMerchantInfoService,
IPileStationInfoService pileStationInfoService) {
UserUtils.memberBasicInfoService = memberBasicInfoService;
UserUtils.pileMerchantInfoService = pileMerchantInfoService;
UserUtils.pileStationInfoService = pileStationInfoService;
}
// 4.使用
@@ -72,4 +86,52 @@ public class UserUtils {
}
return resultVO;
}
/**
* 获取当前会员中的运营商列表(带权限校验)
*/
public static List<MerchantInfoVO> getMerchantListByAuth() {
List<MerchantInfoVO> resultList = Lists.newArrayList();
// 获取登录用户 所有有权限运营商
LoginUser loginUser = SecurityUtils.getLoginUser();
if (Objects.isNull(loginUser)) {
return resultList;
}
// 获取登录用户对应的user对象
SysUser user = loginUser.getUser();
if (Objects.isNull(user)) {
return resultList;
}
// 获取所属部门id
SysDept dept = user.getDept();
if (Objects.isNull(dept)) {
return resultList;
}
String deptLevel = dept.getDeptLevel();
String deptId = String.valueOf(dept.getDeptId());
if (Constants.ZERO.equals(deptLevel)) {
// 平台级权限 查询所有生效的运营商
resultList = pileMerchantInfoService.selectAll();
} else if (Constants.ONE.equals(deptLevel)) {
// 一级运营商权限 查询该一级运营商下面的所有运营商
PileMerchantInfo merchantInfo = pileMerchantInfoService.queryInfoByDeptId(deptId);
resultList = pileMerchantInfoService.selectListByFirstMerchant(merchantInfo.getId() + "");
} else if (Constants.TWO.equals(deptLevel) ) {
// 二级运营商权限 返回自身运营商
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.queryMerchantInfoVOByDeptId(deptId);
if (Objects.nonNull(merchantInfoVO)) {
resultList.add(merchantInfoVO);
}
} else if (Constants.THREE.equals(deptLevel)) {
// 站点权限 返回自身运营商
PileStationInfo stationInfo = pileStationInfoService.queryInfoByDeptId(deptId);
if (Objects.nonNull(stationInfo)) {
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(stationInfo.getMerchantId() + "");
if (Objects.nonNull(merchantInfoVO)) {
resultList.add(merchantInfoVO);
}
}
}
return resultList;
}
}

View File

@@ -0,0 +1,25 @@
package com.jsowell.pile.vo.base;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* 登录用户详情VO
*/
@Getter
@Setter
public class LoginUserDetailVO {
/**
* 有权限的一级运营商idList
* 平台级账号有多个一级运营商权限
* 其他账号只有一个
*/
private List<String> firstMerchantIdList;
/**
* 获取当前会员中的运营商列表
*/
private List<MerchantInfoVO> merchantInfoVOList;
}