Commit e13759a1 by 墨竹

feat:bug修改

parent 6452dad1
package com.gic.haoban.manage.web.auth; package com.gic.haoban.manage.web.auth;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.manage.api.dto.LoginDTO;
import com.gic.redis.data.util.RedisUtil; import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -21,6 +23,7 @@ import java.util.concurrent.TimeUnit; ...@@ -21,6 +23,7 @@ import java.util.concurrent.TimeUnit;
* *
* @author hua * @author hua
*/ */
@Deprecated
public class AuthRequestUtil { public class AuthRequestUtil {
private static final Logger logger = LoggerFactory.getLogger(AuthRequestUtil.class); private static final Logger logger = LoggerFactory.getLogger(AuthRequestUtil.class);
...@@ -33,7 +36,7 @@ public class AuthRequestUtil { ...@@ -33,7 +36,7 @@ public class AuthRequestUtil {
String userJson = JSON.toJSONString(obj); String userJson = JSON.toJSONString(obj);
getSession().setAttribute(LOGIN_SESSION_KEY, userJson); getSession().setAttribute(LOGIN_SESSION_KEY, userJson);
} }
public static void delSessionUser() { public static void delSessionUser() {
getSession().removeAttribute(LOGIN_SESSION_KEY); getSession().removeAttribute(LOGIN_SESSION_KEY);
} }
...@@ -43,8 +46,8 @@ public class AuthRequestUtil { ...@@ -43,8 +46,8 @@ public class AuthRequestUtil {
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
return null; return null;
} }
Object cache = RedisUtil.getCache(token); //为了做兼容
return cache; return EntityUtil.changeEntityByJSON(LoginDTO.class, RedisUtil.getCache(token));
} }
private static void setLoginUserLastToken(String token, Object obj) { private static void setLoginUserLastToken(String token, Object obj) {
...@@ -104,16 +107,18 @@ public class AuthRequestUtil { ...@@ -104,16 +107,18 @@ public class AuthRequestUtil {
RedisUtil.delCache(token); RedisUtil.delCache(token);
} }
public static void setAppLoginUser(Object obj,String token) { public static void setAppLoginUser(Object obj, String token) {
RedisUtil.setCache(token, obj, 30L, TimeUnit.DAYS); RedisUtil.setCache(token, obj, 30L, TimeUnit.DAYS);
getResponse().setHeader("token", token); getResponse().setHeader("token", token);
//setLoginUserLastToken(token, obj); //setLoginUserLastToken(token, obj);
} }
public static void setAppFakeLoginUser(Object obj) { public static void setAppFakeLoginUser(Object obj) {
String token = getRequest().getHeader("token"); String token = getRequest().getHeader("token");
RedisUtil.setCache(token, obj, 30L, TimeUnit.DAYS); RedisUtil.setCache(token, obj, 30L, TimeUnit.DAYS);
getResponse().setHeader("token", token); getResponse().setHeader("token", token);
} }
public static HttpSession getSession() { public static HttpSession getSession() {
HttpSession session = null; HttpSession session = null;
try { try {
...@@ -135,16 +140,16 @@ public class AuthRequestUtil { ...@@ -135,16 +140,16 @@ public class AuthRequestUtil {
return attrs.getResponse(); return attrs.getResponse();
} }
public static Object getLoginUser() { public static Object getLoginUser() {
Cookie[] cookies = AuthRequestUtil.getRequest().getCookies(); Cookie[] cookies = AuthRequestUtil.getRequest().getCookies();
String token = ""; String token = "";
if(cookies != null){ if (cookies != null) {
for (Cookie cookie : cookies) { for (Cookie cookie : cookies) {
if(cookie.getName().equals("token")){ if (cookie.getName().equals("token")) {
token = cookie.getValue(); token = cookie.getValue();
} }
} }
} }
return getAppLoginUser(token); return getAppLoginUser(token);
} }
} }
package com.gic.haoban.manage.web.controller; package com.gic.haoban.manage.web.controller;
import com.gic.haoban.auth.api.dto.DisplayRelationShortInfoDTO; import com.gic.haoban.auth.api.dto.DisplayRelationShortInfoDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.HaobanResponse; import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.dto.LoginDTO; import com.gic.haoban.manage.api.dto.LoginDTO;
import com.gic.haoban.manage.web.auth.AuthRequestUtil;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode; import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -35,14 +36,14 @@ public class WebBaseController { ...@@ -35,14 +36,14 @@ public class WebBaseController {
public HaobanResponse resultResponse(HaoBanErrCode errCode) { public HaobanResponse resultResponse(HaoBanErrCode errCode) {
return resultResponse(errCode, null, null); return resultResponse(errCode, null, null);
} }
public HaobanResponse resultResponse(HaoBanErrCode errCode, String message,Object data,String detailError) {
public HaobanResponse resultResponse(HaoBanErrCode errCode, String message, Object data, String detailError) {
HaobanResponse response = new HaobanResponse(); HaobanResponse response = new HaobanResponse();
response.setMessage(message); response.setMessage(message);
response.setDetailError(detailError); response.setDetailError(detailError);
response.setErrorCode(errCode.getCode()); response.setErrorCode(errCode.getCode());
return response; return response;
} }
/** /**
* 获取登陆信息 * 获取登陆信息
...@@ -50,31 +51,29 @@ public class WebBaseController { ...@@ -50,31 +51,29 @@ public class WebBaseController {
* @return * @return
*/ */
protected LoginDTO getLoginUser() { protected LoginDTO getLoginUser() {
LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser(); //为了做兼容
return login; Object loginUser = AuthWebRequestUtil.getLoginUser();
return EntityUtil.changeEntityByJSON(LoginDTO.class, loginUser);
} }
public boolean haveRight(List<DisplayRelationShortInfoDTO> list){ public boolean haveRight(List<DisplayRelationShortInfoDTO> list) {
List<String> groupList = new ArrayList<String>(); List<String> groupList = new ArrayList<String>();
List<String> storeList = new ArrayList<String>(); List<String> storeList = new ArrayList<String>();
List<String> clerkList = new ArrayList<String>(); List<String> clerkList = new ArrayList<String>();
if(list==null){ if (list == null) {
return false; return false;
}
for(DisplayRelationShortInfoDTO showDto :list){
if(showDto.getGroupId()!=null){
groupList.add(showDto.getGroupId());
}
if(showDto.getStoreId()!=null){
storeList.add(showDto.getStoreId());
}
if(showDto.getClerkId()!=null){
clerkList.add(showDto.getClerkId());
}
} }
if(CollectionUtils.isEmpty(groupList) && CollectionUtils.isEmpty(storeList) && CollectionUtils.isEmpty(clerkList)){ for (DisplayRelationShortInfoDTO showDto : list) {
return false; if (showDto.getGroupId() != null) {
groupList.add(showDto.getGroupId());
}
if (showDto.getStoreId() != null) {
storeList.add(showDto.getStoreId());
}
if (showDto.getClerkId() != null) {
clerkList.add(showDto.getClerkId());
}
} }
return true; return !CollectionUtils.isEmpty(groupList) || !CollectionUtils.isEmpty(storeList) || !CollectionUtils.isEmpty(clerkList);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment