Commit d6c5f6e1 authored by 赵啸非's avatar 赵啸非

添加角色菜单权限新实现

parent fc77a492
package com.mortals.xhx.base.login.web;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ITokenService;
import com.mortals.framework.service.IUser;
......@@ -21,7 +23,9 @@ import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.user.LoginPdu;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.common.utils.MenuEncodeUtil;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,97 +38,32 @@ import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Set;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
@RestController
@Slf4j
@RequestMapping("login")
public class LoginController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> {
@Autowired
private UserService userService;
@Autowired
private ValidCodeService validCodeService;
@Autowired
private ResourceService resourceService;
@Autowired
private MenuService menuService;
@Autowired
private ITokenService tokenService;
@Autowired
private ICacheService cacheService;
@Autowired
private IUserFeign userFeign;
private static Log logger = LogFactory.getLog(LoginController.class);
@RequestMapping("login")
public String login( @RequestBody LoginForm loginForm) throws Exception {
String loginName = loginForm.getLoginName();
String password = loginForm.getPassword();
LoginPdu loginPdu = new LoginPdu();
loginPdu.setLoginName(loginName);
loginPdu.setPassword(password);
loginPdu.setSecurityCode("admin");
String resp = userFeign.portalLogin(loginPdu);
return resp;
/*JSONObject ret = new JSONObject();
String loginName = loginForm.getLoginName();
String password = loginForm.getPassword();
//String securityCode = loginForm.getSecurityCode();
String ip = super.getRequestIP(request);
if (StringUtils.isEmpty(loginName) || StringUtils.isEmpty(password)) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "未获取到用户信息,请重新登录");
return ret.toJSONString();
}
UserEntity userEntity = null;
try {
loginForm.validate();
userEntity = userService.doLogin(loginName, password, ip);
userEntity.setLastLoginAddress(ip);
//saveCurrUser(request, response, userEntity);
recordSysLog(request, userEntity, "用户登录系统成功!");
// 返回拥有的菜单数据
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
List<MenuEntity> outlookBarList = menuService.findTreeMenu(userEntity, urls);
String currUserName = userEntity.getRealName();
if (currUserName == null || currUserName.trim().length() == 0) {
currUserName = "管理员";
}
userEntity.setLoginTime(System.currentTimeMillis());
userEntity.setToken(IdUtil.fastSimpleUUID());
userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
String token = authTokenService.createToken(userEntity);
JSONObject data = new JSONObject();
data.put("token", token);
data.put("currUserName", currUserName);
data.put("barList", outlookBarList);
data.put("id", userEntity.getId());
data.put("userType", userEntity.getUserType());
//this.generateBlackCookie(request, response, loginName, urls);
ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls);
return ret.toJSONString();
} catch (Exception e) {
log.error("login error ", e);
if (userEntity == null) {
userEntity = new UserEntity();
userEntity.setLoginName(loginName);
}
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}*/
}
@RequestMapping("logout")
......@@ -138,21 +77,28 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
JSONObject ret = new JSONObject();
IUser user = this.getCurUser();
if (user == null) {
return "";
return JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT));
}
Set<String> urls = resourceService.findUrlSetByUserId(user.getId());
List<MenuEntity> outlookBarList = menuService.findTreeMenu(user, urls);
log.info("userId:{},urls:{}", user.getId(), JSON.toJSONString(urls));
// List<MenuEntity> outlookBarList = menuService.findTreeMenu(user, urls);
List<MenuEntity> treeMenuList = menuService.findTreeMenu(user);
String currUserName = user.getRealName();
if (currUserName == null || currUserName.trim().length() == 0) {
currUserName = "管理员";
}
JSONObject data = new JSONObject();
String token = authTokenService.getToken(request);
data.put("token", token);
data.put("currUserName", currUserName);
data.put("barList", outlookBarList);
data.put("menuList", treeMenuList);
data.put("id", user.getId());
data.put("userType", user.getUserType());
ret.put(KEY_RESULT_DATA, data);
//this.generateBlackCookie(request, response, user.getLoginName(), urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, user.getId().toString(), MenuEncodeUtil.generateMenuUrlCode(urls));
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls);
......
......@@ -10,7 +10,7 @@ import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.model.MenuQuery;
import com.mortals.xhx.base.system.menu.model.MenuTreeSelect;
import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.common.code.DataSatus;
import com.mortals.xhx.common.code.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
......
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 权限类型 (0.无限制,1.无需登录查看,2.需要登录查看,3.需要角色权限查看)枚举类
*
* @author zxfei
*/
public enum AuthTypeEnum {
无限制(0, "无限制"),
无需登录查看(1, "无需登录查看"),
需要登录查看(2, "需要登录查看"),
需要角色权限查看(3, "需要角色权限查看");
private Integer value;
private String desc;
AuthTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static AuthTypeEnum getByValue(Integer value) {
for (AuthTypeEnum authTypeEnum : AuthTypeEnum.values()) {
if (authTypeEnum.getValue() == value) {
return authTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (AuthTypeEnum item : AuthTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 是否常用菜单 (0.非常用,1.常用)枚举类
*
* @author zxfei
*/
public enum CommMenuEnum {
非常用(0, "非常用"),
常用(1, "常用");
private Integer value;
private String desc;
CommMenuEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static CommMenuEnum getByValue(Integer value) {
for (CommMenuEnum commMenuEnum : CommMenuEnum.values()) {
if (commMenuEnum.getValue() == value) {
return commMenuEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (CommMenuEnum item : CommMenuEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 链接方式 (0.普通,1.弹出,2.脚本)枚举类
*
* @author zxfei
*/
public enum LinkTypeEnum {
普通(0, "普通"),
弹出(1, "弹出"),
脚本(2, "脚本");
private Integer value;
private String desc;
LinkTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static LinkTypeEnum getByValue(Integer value) {
for (LinkTypeEnum linkTypeEnum : LinkTypeEnum.values()) {
if (linkTypeEnum.getValue() == value) {
return linkTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (LinkTypeEnum item : LinkTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 菜单类型 (0.目录,1.菜单,2.按钮)枚举类
*
* @author zxfei
*/
public enum MenuTypeEnum {
目录(0, "目录"),
菜单(1, "菜单"),
按钮(2, "按钮");
private Integer value;
private String desc;
MenuTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static MenuTypeEnum getByValue(Integer value) {
for (MenuTypeEnum menuTypeEnum : MenuTypeEnum.values()) {
if (menuTypeEnum.getValue() == value) {
return menuTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (MenuTypeEnum item : MenuTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 菜单状态 (0.停用,1.启用)枚举类
*
* @author zxfei
*/
public enum StatusEnum {
停用(0, "停用"),
启用(1, "启用");
private Integer value;
private String desc;
StatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static StatusEnum getByValue(Integer value) {
for (StatusEnum statusEnum : StatusEnum.values()) {
if (statusEnum.getValue() == value) {
return statusEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (StatusEnum item : StatusEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 菜单显示状态 (0.显示,1.隐藏)枚举类
*
* @author zxfei
*/
public enum VisibleEnum {
显示(0, "显示"),
隐藏(1, "隐藏");
private Integer value;
private String desc;
VisibleEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static VisibleEnum getByValue(Integer value) {
for (VisibleEnum visibleEnum : VisibleEnum.values()) {
if (visibleEnum.getValue() == value) {
return visibleEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (VisibleEnum item : VisibleEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
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