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

This commit is contained in:
2023-11-11 15:21:25 +08:00
parent 6fa87d6fc2
commit 5f44c35d03
14 changed files with 109 additions and 56 deletions

View File

@@ -152,7 +152,5 @@ public interface IMemberBasicInfoService {
/**
* 获取当前会员中的运营商列表(带权限校验)
*/
List<MerchantInfoVO> getMerchantListByAuth(List<String> deptIds);
List<MerchantInfoVO> getMerchantListByAuthV2();
List<MerchantInfoVO> getMerchantListByAuth();
}

View File

@@ -22,6 +22,7 @@ import com.jsowell.pile.mapper.MemberPlateNumberRelationMapper;
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;
@@ -326,7 +327,8 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
sw.start("获取登录账号信息");
// 获取登录账号信息
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
// AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
return new ArrayList<>();
}
@@ -427,15 +429,7 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
* 获取当前会员中的运营商列表(带权限校验)
*/
@Override
public List<MerchantInfoVO> getMerchantListByAuth(List<String> deptIds) {
return memberBasicInfoMapper.getMerchantListByAuth(deptIds);
}
/**
* 获取当前会员中的运营商列表(带权限校验)
*/
@Override
public List<MerchantInfoVO> getMerchantListByAuthV2() {
public List<MerchantInfoVO> getMerchantListByAuth() {
List<MerchantInfoVO> resultList = Lists.newArrayList();
// 获取登录用户 所有有权限运营商
LoginUser loginUser = SecurityUtils.getLoginUser();

View File

@@ -47,6 +47,7 @@ import com.jsowell.pile.service.orderlogic.OrderLogicFactory;
import com.jsowell.pile.transaction.dto.ClearingBillTransactionDTO;
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.base.*;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
@@ -196,7 +197,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
@Override
public List<OrderListVO> selectOrderBasicInfoListWithAuth(QueryOrderDTO dto) {
// 权限过滤
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return Lists.newArrayList();
@@ -1948,7 +1949,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
*/
@Override
public List<IndexOrderInfoVO> getIndexOrderInfo(IndexQueryDTO dto) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
return Lists.newArrayList();
}

View File

@@ -2,8 +2,6 @@ package com.jsowell.pile.service.impl;
import com.google.common.collect.Lists;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.pile.domain.OrderInvoiceRecord;
import com.jsowell.pile.dto.GetInvoiceInfoDTO;
import com.jsowell.pile.dto.QueryInvoiceRecordDTO;
@@ -11,6 +9,7 @@ import com.jsowell.pile.mapper.OrderInvoiceRecordMapper;
import com.jsowell.pile.service.IMemberInvoiceTitleService;
import com.jsowell.pile.service.IOrderBasicInfoService;
import com.jsowell.pile.service.IOrderInvoiceRecordService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.OrderAmountDetailVO;
import com.jsowell.pile.vo.uniapp.InvoiceTitleVO;
import com.jsowell.pile.vo.web.InvoiceRecordVO;
@@ -96,7 +95,7 @@ public class OrderInvoiceRecordServiceImpl implements IOrderInvoiceRecordService
@Override
public List<OrderInvoiceRecordVO> getInvoiceListWithAuth(GetInvoiceInfoDTO dto) {
// 获取登录账号信息
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
return new ArrayList<>();
}

View File

@@ -26,6 +26,7 @@ import com.jsowell.pile.mapper.PileBasicInfoMapper;
import com.jsowell.pile.mapper.PileMerchantInfoMapper;
import com.jsowell.pile.mapper.PileSimInfoMapper;
import com.jsowell.pile.service.*;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.uniapp.GroundLockInfoVO;
@@ -326,7 +327,7 @@ public class PileBasicInfoServiceImpl implements IPileBasicInfoService {
*/
@Override
public List<PileDetailVO> queryPileInfoList(QueryPileDTO queryPileDTO) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return Lists.newArrayList();
@@ -700,7 +701,7 @@ public class PileBasicInfoServiceImpl implements IPileBasicInfoService {
*/
@Override
public IndexGeneralSituationVO getGeneralSituation(IndexQueryDTO dto) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
return new IndexGeneralSituationVO();
}

View File

@@ -1,6 +1,5 @@
package com.jsowell.pile.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -24,6 +23,7 @@ import com.jsowell.pile.service.IPileBasicInfoService;
import com.jsowell.pile.service.IPileBillingTemplateService;
import com.jsowell.pile.transaction.dto.BillingTemplateTransactionDTO;
import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails;
import com.jsowell.pile.vo.web.BillingDetailVO;
@@ -426,7 +426,7 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
if (StringUtils.isBlank(stationId)) {
return Lists.newArrayList();
}
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return Lists.newArrayList();

View File

@@ -9,13 +9,13 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.DictUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.dto.CreateMerchantDTO;
import com.jsowell.pile.dto.QueryMerchantInfoDTO;
import com.jsowell.pile.mapper.PileMerchantInfoMapper;
import com.jsowell.pile.service.IPileMerchantInfoService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.web.MerchantSettleInfoVO;
import com.jsowell.system.service.SysDeptService;
@@ -74,7 +74,7 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
*/
@Override
public List<PileMerchantInfo> selectPileMerchantInfoListWithAuth(PileMerchantInfo pileMerchantInfo) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return Lists.newArrayList();
@@ -371,7 +371,7 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
dto.setDeptIds(Lists.newArrayList());
}
// 权限过滤
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return new ArrayList<>();

View File

@@ -24,6 +24,7 @@ import com.jsowell.pile.dto.QueryStationDTO;
import com.jsowell.pile.dto.lutongyunting.BindParkingPlatformDTO;
import com.jsowell.pile.mapper.PileStationInfoMapper;
import com.jsowell.pile.service.*;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.base.StationInfoVO;
@@ -396,7 +397,7 @@ public class PileStationInfoServiceImpl implements IPileStationInfoService {
@Override
// @DataScope(deptAlias = "t3")
public List<PileStationVO> queryStationInfos(QueryStationDTO dto) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return Lists.newArrayList();
@@ -556,7 +557,7 @@ public class PileStationInfoServiceImpl implements IPileStationInfoService {
*/
@Override
public List<PileStationVO> getStationSelectList(QueryStationDTO dto) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return Lists.newArrayList();

View File

@@ -0,0 +1,75 @@
package com.jsowell.pile.util;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
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.service.IMemberBasicInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 后管登录用户工具类
*/
// 1.将工具类注入到容器中
@Slf4j
@Component
public class UserUtils {
// 2.注入想引用的对象的静态实例
private static IMemberBasicInfoService memberBasicInfoService;
// 3.初始化有参构造器
@Autowired
public UserUtils(IMemberBasicInfoService memberBasicInfoService) {
UserUtils.memberBasicInfoService = memberBasicInfoService;
}
// 4.使用
// 查询登录用户权限
public static AuthorizedDeptVO getAuthorizedMap() {
// 登录用户
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null) {
return null;
}
// 用户
SysUser user = loginUser.getUser();
if (user == null) {
return null;
}
AuthorizedDeptVO resultVO = AuthorizedDeptVO.builder().build();
// 登录用户所属部门(运营商或站点 根据父级id判断
SysDept dept = user.getDept();
if (dept == null) {
log.info("用户id:{}, 获取不到所属部门信息", user.getUserId());
return null;
}
String deptId = String.valueOf(dept.getDeptId());
resultVO.setDeptId(deptId);
log.info("用户id:{}, 所属部门信息:{}", user.getUserId(), JSONObject.toJSONString(dept));
// 登录用户角色
Long parentId = dept.getParentId();
resultVO.setParentId(String.valueOf(parentId));
List<String> merchantDeptIds = Lists.newArrayList();
List<String> stationDeptIds = Lists.newArrayList();
if (parentId == 0L) {
// 父级id是0表明是该账号挂在平台下面是系统管理员
} else if (parentId == 100L) {
// 父级id是100表明是该账号挂在运营商下面是运营商管理员
merchantDeptIds.add(deptId);
resultVO.setMerchantDeptIds(merchantDeptIds);
} else {
// 其他情况,表明是站点管理员
stationDeptIds.add(deptId);
resultVO.setStationDeptIds(stationDeptIds);
}
return resultVO;
}
}