添加权限判断逻辑
This commit is contained in:
parent
4e4c52d063
commit
dfcf66bbe1
@ -26,6 +26,8 @@ public class BusinessApiService {
|
||||
|
||||
private String getUserUrl = "/common/getUserByToken";
|
||||
|
||||
private String getUserModuleListUrl = "/user/getUserModuleList";
|
||||
|
||||
private String authorizationDeptId = "16";
|
||||
|
||||
private String authorizationKey = "56e670eea5ff3a1aebbc02820e908ceb56e670eea5ff3a1aebbc02820e908ceb";
|
||||
@ -38,6 +40,8 @@ public class BusinessApiService {
|
||||
|
||||
private static final int SUCCESS_CODE = 200;
|
||||
|
||||
private static final int TOKEN_ERROR_CODE = 401;
|
||||
|
||||
public BusinessLoginVO loginByUserName(String userName, String password) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("username", userName);
|
||||
@ -53,12 +57,20 @@ public class BusinessApiService {
|
||||
return vo.getData();
|
||||
}
|
||||
|
||||
public List<BusinessModuleVO> getUserModuleList(String userId) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("userId", userId);
|
||||
BusinessModuleRspVO vo = post(getUserModuleListUrl, params, BusinessModuleRspVO.class);
|
||||
return vo.getData();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BusinessApiService service = new BusinessApiService();
|
||||
BusinessLoginVO loginVO = service.loginByUserName("sz545138", "Abc@123");
|
||||
String token = loginVO.getToken();
|
||||
BusinessUserVO userVO = service.getUserByToken(token);
|
||||
System.out.println(JSONUtil.toJsonStr(userVO));
|
||||
service.getUserModuleList(userVO.getUserId().toString());
|
||||
}
|
||||
|
||||
private <T extends BusinessVO> T post(String url, Map<String, Object> params, Class<T> type) {
|
||||
@ -78,7 +90,13 @@ public class BusinessApiService {
|
||||
LoggerUtil.api.info("response:" + response);
|
||||
vo = JSONUtil.toBean(response, type);
|
||||
LoggerUtil.api.info("vo:" + JSONUtil.toJsonStr(vo));
|
||||
if (vo.getCode() != null && vo.getCode() != SUCCESS_CODE) {
|
||||
if (vo.getCode() == null) {
|
||||
throw new BizException(ResponseStatus.OUTSYS_ERROR, "协议异常:" + vo.getMessage());
|
||||
} else if (vo.getCode() == SUCCESS_CODE) {
|
||||
return vo;
|
||||
} else if (vo.getCode() == TOKEN_ERROR_CODE) {
|
||||
throw new BizException(ResponseStatus.SESSION_EXPIRY);
|
||||
} else {
|
||||
throw new BizException(ResponseStatus.OUTSYS_ERROR, vo.getCode() + ":" + vo.getMessage());
|
||||
}
|
||||
} catch (BizException e) {
|
||||
@ -86,7 +104,6 @@ public class BusinessApiService {
|
||||
} catch (Exception e) {
|
||||
throw new BizException(ResponseStatus.OUTSYS_ERROR, e);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private String encodeSign(String time) {
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BusinessModuleRspVO extends BusinessVO {
|
||||
|
||||
private List<BusinessModuleVO> data;
|
||||
|
||||
public List<BusinessModuleVO> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<BusinessModuleVO> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
65
src/main/java/com/upchina/business/vo/BusinessModuleVO.java
Normal file
65
src/main/java/com/upchina/business/vo/BusinessModuleVO.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
public class BusinessModuleVO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private Integer moduleId;
|
||||
|
||||
private String endTime;
|
||||
|
||||
private String createTime;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getModuleId() {
|
||||
return moduleId;
|
||||
}
|
||||
|
||||
public void setModuleId(Integer moduleId) {
|
||||
this.moduleId = moduleId;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +1,14 @@
|
||||
package com.upchina.common.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.upchina.business.service.BusinessApiService;
|
||||
import com.upchina.business.vo.BusinessLoginVO;
|
||||
import com.upchina.business.vo.BusinessModuleVO;
|
||||
import com.upchina.business.vo.BusinessUserVO;
|
||||
import com.upchina.common.handler.BizException;
|
||||
import com.upchina.common.query.AppUserInfoQuery;
|
||||
@ -24,6 +28,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class AppUserService {
|
||||
@ -89,6 +97,19 @@ public class AppUserService {
|
||||
if (StrUtil.isBlank(auth) || frontUserVO == null) {
|
||||
return new AuthResultVO(true);
|
||||
}
|
||||
Set<String> auths = Arrays.stream(auth.split("[,,]")).collect(Collectors.toSet());
|
||||
if (CollUtil.isEmpty(auths)) {
|
||||
return new AuthResultVO(true);
|
||||
}
|
||||
List<BusinessModuleVO> moduleList = businessApiService.getUserModuleList(frontUserVO.getUserId());
|
||||
if (CollUtil.isNotEmpty(moduleList)) {
|
||||
String now = LocalDateTimeUtil.format(LocalDateTimeUtil.now(), DatePattern.NORM_DATETIME_PATTERN);
|
||||
for (BusinessModuleVO moduleVO : moduleList) {
|
||||
if (auths.contains(moduleVO.getModuleId().toString()) && moduleVO.getEndTime().compareTo(now) > 0) {
|
||||
return new AuthResultVO(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new AuthResultVO(false);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user