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

This commit is contained in:
2023-11-11 16:05:04 +08:00
parent 7c5e55b9ee
commit de5210d051
3 changed files with 73 additions and 0 deletions

View File

@@ -334,6 +334,7 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
.merchantTel(pileMerchantInfo.getServicePhone())
.organizationCode(pileMerchantInfo.getOrganizationCode())
.deptId(pileMerchantInfo.getDeptId())
.merchantLevel(pileMerchantInfo.getMerchantLevel())
.build();
return vo;
}

View File

@@ -13,6 +13,7 @@ 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.LoginUserDetailVO;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +21,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 后管登录用户工具类
@@ -134,4 +136,69 @@ public class UserUtils {
}
return resultList;
}
public static LoginUserDetailVO getLoginUserDetail() {
LoginUserDetailVO resultVO = new LoginUserDetailVO();
// 获取登录用户 所有有权限运营商
LoginUser loginUser = SecurityUtils.getLoginUser();
if (Objects.isNull(loginUser)) {
return resultVO;
}
// 获取登录用户对应的user对象
SysUser user = loginUser.getUser();
if (Objects.isNull(user)) {
return resultVO;
}
// 获取所属部门
SysDept dept = user.getDept();
if (Objects.isNull(dept)) {
return resultVO;
}
// 所属部门等级
String deptLevel = dept.getDeptLevel();
// 所属部门id
String deptId = String.valueOf(dept.getDeptId());
List<MerchantInfoVO> merchantInfoVOList = Lists.newArrayList();
List<String> firstMerchantIdList = Lists.newArrayList();
if (Constants.ZERO.equals(deptLevel)) {
// 平台级权限 查询所有生效的运营商
merchantInfoVOList = pileMerchantInfoService.selectAll();
// 获取一级运营商id
List<String> collect = merchantInfoVOList.stream()
.map(MerchantInfoVO::getMerchantLevel)
.filter("1"::equals)
.collect(Collectors.toList());
firstMerchantIdList.addAll(collect);
} else if (Constants.ONE.equals(deptLevel)) {
// 一级运营商权限 查询该一级运营商下面的所有运营商
PileMerchantInfo merchantInfo = pileMerchantInfoService.queryInfoByDeptId(deptId);
if (Objects.nonNull(merchantInfo)) {
String firstMerchantId = merchantInfo.getId().toString();
// 获取一级运营商id
firstMerchantIdList.add(firstMerchantId);
merchantInfoVOList = pileMerchantInfoService.selectListByFirstMerchant(firstMerchantId);
}
} else if (Constants.TWO.equals(deptLevel)) {
// 二级运营商权限 返回自身运营商
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.queryMerchantInfoVOByDeptId(deptId);
if (Objects.nonNull(merchantInfoVO)) {
merchantInfoVOList.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)) {
merchantInfoVOList.add(merchantInfoVO);
}
}
}
resultVO.setMerchantInfoVOList(merchantInfoVOList);
return null;
}
}

View File

@@ -20,6 +20,11 @@ public class MerchantInfoVO {
*/
private String merchantName;
/**
* 运营商等级
*/
private String merchantLevel;
/**
* 商户电话
*/