Commit 4dead4da by 蔡茜

校验角色

1 parent 059625fa
package cn.com.glsx.dj.controller;
import cn.com.glsx.dj.enums.LoginRoleEnum;
import cn.com.glsx.dj.enums.RopErrorEnum;
import cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.*;
import cn.com.glsx.dj.peanalysis.remote.BusinessAnalysisRemote;
import cn.com.glsx.dj.request.output.*;
import cn.com.glsx.dj.response.LoginUserInfoResponse;
import cn.com.glsx.dj.util.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.rop.response.RopResponse;
......@@ -31,16 +28,12 @@ public class BusinessAnalysisController {
@ApiOperation("总部视角----全业务-总产值、门店总数")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.output.total", needInSession = NeedInSessionType.NO)
public RopResponse<TotalOutputResponse> totalOutput(TotalOutputRequest request) {
LoginUserInfoResponse loginUserInfo = CommonUtil.getLoginUserInfo();
if (loginUserInfo == null) {
log.info("登录失效");
return RopResponse.result(RopErrorEnum.GET_LOGIN_EXPIRE);
}
log.info("totalOutput params: {},loginRole:{}", request, loginUserInfo.getLoginRole());
if (loginUserInfo.getLoginRole() == null || loginUserInfo.getLoginRole() == LoginRoleEnum.NONE.getValue()) {
return RopResponse.error("您暂无使用权限,请确认后重新操作。");
boolean b = CommonUtil.validLeadRole();
if (!b) {
RopResponse.error("您暂无使用权限,请确认后重新操作。");
}
TotalOutputReq req = CommonUtil.convertRequest(TotalOutputReq.class);
log.info("totalOutput request: {},req:{}", request, req);
RpcResponse<TotalOutputResponse> response = businessAnalysisRemote.totalOutput(req);
return CommonUtil.convertRopResponse(response);
}
......
package cn.com.glsx.dj.util;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import cn.com.glsx.dj.enums.LoginRoleEnum;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -216,4 +213,39 @@ public class CommonUtil {
public void setLoginService(LoginService loginService) {
CommonUtil.loginService = loginService;
}
private static final Set<Integer> LEAD_ROLES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
LoginRoleEnum.OTHER.getValue(),
LoginRoleEnum.AREA_SUPERVISION_LEADER.getValue(),
LoginRoleEnum.SALE_LEADER.getValue()
)));
private static final Set<Integer> SIMPLE_ROLES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
LoginRoleEnum.AREA_SUPERVISION.getValue(),
LoginRoleEnum.SELE.getValue(),
LoginRoleEnum.FLIGHT_SUPERVISION.getValue(),
LoginRoleEnum.ONLINE_SUPERVISION.getValue()
)));
private static boolean checkRole(Set<Integer> allowedRoles) {
LoginUserInfoResponse loginUserInfo = CommonUtil.getLoginUserInfo();
if (loginUserInfo == null) {
log.info("loginUserInfo is null");
return false;
}
Integer loginRole = loginUserInfo.getLoginRole();
log.info("loginUserInfo:{}",loginUserInfo);
if (loginRole == null || loginRole == LoginRoleEnum.NONE.getValue()) {
return false;
}
return allowedRoles.contains(loginRole);
}
public static boolean validLeadRole() {
return checkRole(LEAD_ROLES);
}
public static boolean validSimpleRole() {
return checkRole(SIMPLE_ROLES);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!