mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-26 05:55:03 +08:00
75 lines
2.7 KiB
Java
75 lines
2.7 KiB
Java
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|