新增在线用户管理,更新sql文件,部分代码优化

This commit is contained in:
郑杰
2018-09-21 16:48:42 +08:00
parent d1cc5b9f43
commit 73b3c94feb
16 changed files with 371 additions and 31 deletions
+23 -10
View File
@@ -11,7 +11,7 @@
Target Server Version : 50559
File Encoding : 65001
Date: 21/09/2018 11:40:53
Date: 21/09/2018 16:47:46
*/
SET NAMES utf8mb4;
@@ -34,7 +34,7 @@ CREATE TABLE `zj_menu` (
`level_number` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_cbhg0bi3f1emxkhqqtvca9btx`(`soft`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 15 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_menu
@@ -43,7 +43,7 @@ INSERT INTO `zj_menu` VALUES (1, 'layui-icon-unlink', 0, 1, '异常页', 40, '',
INSERT INTO `zj_menu` VALUES (2, 'layui-icon-tree', 1, 2, '403', 41, '/exception/403', '2018-08-29 11:40:17', '2018-09-20 11:36:24', 0);
INSERT INTO `zj_menu` VALUES (3, 'layui-icon-tree', 1, 2, '404', 42, '/exception/404', '2018-08-29 11:40:17', '2018-09-20 11:36:32', 0);
INSERT INTO `zj_menu` VALUES (4, 'layui-icon-tree', 1, 2, '500', 43, '/exception/500', '2018-08-29 11:40:17', '2018-09-20 11:36:40', 0);
INSERT INTO `zj_menu` VALUES (5, 'layui-icon-chart', 0, 1, '系统监控', 10, '', '2018-08-29 11:40:17', '2018-09-20 11:42:49', 1);
INSERT INTO `zj_menu` VALUES (5, 'layui-icon-chart', 0, 1, '系统监控', 10, '', '2018-08-29 11:40:17', '2018-09-21 16:09:38', 2);
INSERT INTO `zj_menu` VALUES (6, 'layui-icon-tree', 7, 2, '用户管理', 2, '/user/index', '2018-08-29 11:40:17', '2018-09-04 07:40:25', 0);
INSERT INTO `zj_menu` VALUES (7, 'layui-icon-util', 0, 1, '系统管理', 1, '', '2018-08-29 11:40:17', '2018-09-20 19:02:05', 4);
INSERT INTO `zj_menu` VALUES (8, 'layui-icon-tree', 7, 2, '菜单管理', 6, '/menu/index', '2018-08-29 11:40:17', '2018-09-04 07:40:25', 0);
@@ -52,6 +52,7 @@ INSERT INTO `zj_menu` VALUES (10, 'layui-icon-tree', 7, 2, '权限管理', 4, '/
INSERT INTO `zj_menu` VALUES (11, 'layui-icon-tree', 7, 2, '角色管理', 3, '/role/index', '2018-08-29 11:40:17', '2018-09-04 07:40:25', 0);
INSERT INTO `zj_menu` VALUES (12, 'layui-icon-website', 0, 1, '网络资源', 30, '', '2018-09-20 11:35:56', '2018-09-20 11:40:53', 1);
INSERT INTO `zj_menu` VALUES (13, 'layui-icon-tree', 12, 2, '图床管理', 31, '/picture/index', '2018-09-20 11:40:53', '2018-09-20 11:40:53', 0);
INSERT INTO `zj_menu` VALUES (14, 'layui-icon-tree', 5, 2, '在线用户管理', 12, '/online/index', '2018-09-21 16:09:38', '2018-09-21 16:09:38', 0);
-- ----------------------------
-- Table structure for zj_menus_roles
@@ -82,6 +83,7 @@ INSERT INTO `zj_menus_roles` VALUES (10, 1);
INSERT INTO `zj_menus_roles` VALUES (11, 1);
INSERT INTO `zj_menus_roles` VALUES (12, 1);
INSERT INTO `zj_menus_roles` VALUES (13, 1);
INSERT INTO `zj_menus_roles` VALUES (14, 1);
INSERT INTO `zj_menus_roles` VALUES (1, 2);
INSERT INTO `zj_menus_roles` VALUES (2, 2);
INSERT INTO `zj_menus_roles` VALUES (3, 2);
@@ -113,14 +115,14 @@ CREATE TABLE `zj_permission` (
`pid` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_djtxn2vldlgrkfk21d155b48i`(`perms`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 31 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_permission
-- ----------------------------
INSERT INTO `zj_permission` VALUES (1, 'admin', '超级管理员', '2018-08-29 15:15:12', '2018-08-31 00:00:00', 0);
INSERT INTO `zj_permission` VALUES (2, 'user:select', '用户查询', '2018-08-29 15:15:12', '2018-08-31 00:00:00', 4);
INSERT INTO `zj_permission` VALUES (3, 'log:select', '日志管理', '2018-08-29 15:15:12', '2018-09-02 23:11:37', 0);
INSERT INTO `zj_permission` VALUES (3, 'log:all', '日志管理', NULL, '2018-09-21 11:50:10', 0);
INSERT INTO `zj_permission` VALUES (4, 'user:all', '用户管理', '2018-08-29 15:15:12', '2018-09-02 23:11:31', 0);
INSERT INTO `zj_permission` VALUES (5, 'user:add', '新增用户', '2018-08-31 15:15:12', '2018-08-31 00:00:00', 4);
INSERT INTO `zj_permission` VALUES (6, 'user:update', '更新用户', '2018-08-31 15:15:12', '2018-08-31 00:00:00', 4);
@@ -139,6 +141,13 @@ INSERT INTO `zj_permission` VALUES (20, 'menu:add', '新增菜单', '2018-09-12
INSERT INTO `zj_permission` VALUES (21, 'menu:update', '更新菜单', '2018-09-12 13:12:21', '2018-09-12 13:12:21', 19);
INSERT INTO `zj_permission` VALUES (22, 'menu:delete', '删除菜单', '2018-09-12 13:12:43', '2018-09-12 13:12:43', 19);
INSERT INTO `zj_permission` VALUES (23, 'menu:select', '菜单搜索', '2018-09-12 13:15:02', '2018-09-12 13:15:02', 19);
INSERT INTO `zj_permission` VALUES (24, 'permission:delete', '删除权限', '2018-09-21 11:51:13', '2018-09-21 11:51:13', 8);
INSERT INTO `zj_permission` VALUES (25, 'user:delete', '删除用户', '2018-09-21 11:51:41', '2018-09-21 11:51:41', 4);
INSERT INTO `zj_permission` VALUES (26, 'picture:all', '图床管理', '2018-09-21 11:52:10', '2018-09-21 11:52:10', 0);
INSERT INTO `zj_permission` VALUES (27, 'picture:select', '图片查询', '2018-09-21 11:52:25', '2018-09-21 11:52:25', 26);
INSERT INTO `zj_permission` VALUES (28, 'picture:upload', '图片上传', NULL, '2018-09-21 11:53:30', 26);
INSERT INTO `zj_permission` VALUES (29, 'picture:delete', '图片删除', '2018-09-21 11:53:46', '2018-09-21 11:53:46', 26);
INSERT INTO `zj_permission` VALUES (30, 'user:logout', '踢出用户', '2018-09-21 16:46:59', '2018-09-21 16:46:59', 4);
-- ----------------------------
-- Table structure for zj_permissions_roles
@@ -181,7 +190,13 @@ CREATE TABLE `zj_picture` (
PRIMARY KEY (`id`) USING BTREE,
INDEX `FK5qtt7wql9517j0e2read2pdus`(`user_id`) USING BTREE,
CONSTRAINT `FK5qtt7wql9517j0e2read2pdus` FOREIGN KEY (`user_id`) REFERENCES `zj_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_picture
-- ----------------------------
INSERT INTO `zj_picture` VALUES (11, '2018-09-21 12:01:57', '1', '200', '8.49KB ', 'https://i.loli.net/2018/09/21/5ba46d305018d.jpg', '200', 1, 'avatar');
INSERT INTO `zj_picture` VALUES (12, '2018-09-21 15:15:21', 'https://sm.ms/delete/lLAmbyjGnr5W4zo', '200', '4.50KB ', 'https://i.loli.net/2018/09/21/5ba49a8975588.jpg', '200', 1, '1');
-- ----------------------------
-- Table structure for zj_role
@@ -235,13 +250,12 @@ CREATE TABLE `zj_user` (
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_kpubos9gc2cvtkb0thktkbkes`(`email`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_user
-- ----------------------------
INSERT INTO `zj_user` VALUES (1, 'https://www.zhengjie.me/images/avatar.jpg', '2018-08-23 09:11:56', 'zhengjie@tom.com', 1, '2018-09-21 08:47:20', '65a674ce6632479005ea7a9071234cfb', 'aurora');
INSERT INTO `zj_user` VALUES (6, 'https://i.loli.net/2018/08/16/5b75166b3157a.jpg', '2018-09-20 17:27:43', '11@qq.com', 0, '2018-09-21 08:45:26', '36318d4cc46eb68050b8b81ebc620f05', '测试');
INSERT INTO `zj_user` VALUES (1, 'https://www.zhengjie.me/images/avatar.jpg', '2018-08-23 09:11:56', 'zhengjie@tom.com', 1, '2018-09-21 16:26:05', '65a674ce6632479005ea7a9071234cfb', 'aurora');
-- ----------------------------
-- Table structure for zj_user_pictures
@@ -273,6 +287,5 @@ CREATE TABLE `zj_users_roles` (
-- Records of zj_users_roles
-- ----------------------------
INSERT INTO `zj_users_roles` VALUES (1, 1);
INSERT INTO `zj_users_roles` VALUES (6, 3);
SET FOREIGN_KEY_CHECKS = 1;
-1
View File
@@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.GetMapping;
@EnableScheduling
@SpringBootApplication
@EnableTransactionManagement
@EnableConfigurationProperties({AuroraProperties.class})
/**
* @author 郑杰
* @date 2018/08/21 11:54:10
@@ -0,0 +1,48 @@
package me.aurora.app.rest.system;
import lombok.extern.slf4j.Slf4j;
import me.aurora.annotation.Log;
import me.aurora.domain.ResponseEntity;
import me.aurora.service.SessionService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* @author 郑杰
* @date 2018/09/21 15:49:14
*/
@Slf4j
@RestController
@RequestMapping("/online")
public class SessionController {
@Autowired
private SessionService sessionService;
@GetMapping("/index")
public ModelAndView online() {
return new ModelAndView("/system/online/index");
}
@Log("获取在线用户")
@GetMapping(value = "/getOnlineInfo")
public Map getOnlineInfo(){
return sessionService.getOnlineInfo();
}
@Log("踢出用户")
@RequiresPermissions(value={"admin", "user:all","user:logout"}, logical= Logical.OR)
@DeleteMapping("/forceLogout")
public ResponseEntity forceLogout(String id) {
sessionService.forceLogout(id);
return ResponseEntity.ok();
}
}
@@ -16,8 +16,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.Map;
@@ -52,6 +50,7 @@ public class PictureController {
* @param limit
* @return
*/
@Log("查询全部图片")
@RequiresPermissions(value={"admin", "picture:all","picture:select"}, logical= Logical.OR)
@GetMapping(value = "/getPictureInfo")
public Map getLogInfo(@RequestParam(value = "username",required = false) String username,
@@ -83,6 +82,7 @@ public class PictureController {
* @return
* @throws Exception
*/
@Log("上传图片")
@RequiresPermissions (value={"admin", "picture:all","picture:upload"}, logical= Logical.OR)
@PostMapping(value = "/upload")
public ResponseEntity uploadAccessory(@RequestParam MultipartFile file) throws Exception {
@@ -22,9 +22,9 @@ public class GlobalExceptionHandler {
* @return
*/
@ExceptionHandler(value = AuthorizationException.class)
public String handleAuthorizationException() {
public ModelAndView handleAuthorizationException() {
log.error("没有权限访问");
return "/exception/403";
return new ModelAndView("/exception/403");
}
/**
@@ -5,7 +5,7 @@ import org.apache.shiro.session.SessionListener;
import java.util.concurrent.atomic.AtomicInteger;
/**
/**会话管理
* @author 郑杰
* @date 2018/08/22 14:42:27
*/
@@ -40,7 +40,7 @@ public class RedisConfig extends CachingConfigurerSupport {
private int port;
@Value("${spring.redis.password}")
private String password = "";
private String password;
@Value("${spring.redis.timeout}")
private String timeout;
@@ -45,7 +45,7 @@ public class ShiroConfig {
private int port;
@Value("${spring.redis.password}")
private String password = "";
private String password;
@Value("${spring.redis.timeout}")
private String timeout;
@@ -78,6 +78,7 @@ public class ShiroConfig {
return shiroFilterFactoryBean;
}
@Bean(name = "lifecycleBeanPostProcessor")
public static LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
// shiro 生命周期处理器
@@ -136,10 +137,15 @@ public class ShiroConfig {
securityManager.setRememberMeManager(rememberMeManager());
// 配置 缓存管理类 cacheManager
securityManager.setCacheManager(cacheManager());
// session管理
securityManager.setSessionManager(sessionManager());
return securityManager;
}
/**
* 会话管理
* @return
*/
@Bean
public RedisSessionDAO redisSessionDAO() {
RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
+3 -1
View File
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.annotation.Nonnull;
import javax.validation.constraints.NotBlank;
import javax.persistence.*;
import java.io.Serializable;
@@ -24,7 +26,7 @@ public class Role implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank(groups = {New.class,Update.class})
@Column(nullable = false)
private String name;
@@ -0,0 +1,70 @@
package me.aurora.domain;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* 在线用户管理
* @author 郑杰
* @date 2018/09/21 15:38:06
*/
@Getter
@Setter
public class UserOnline implements Serializable{
/**
* session id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
/**
* 用户id
*/
private String userId;
/**
* 用户名称
*/
private String username;
/**
* 用户主机地址
*/
private String host;
/**
* 用户登录时系统IP
*/
private String systemHost;
/**
* 状态
*/
private String status;
/**
* session创建时间
*/
private Date startTimestamp;
/**
* session最后访问时间
*/
private Date lastAccessTime;
/**
* 超时时间
*/
private Long timeout;
/**
* 所在地
*/
private String location;
}
@@ -0,0 +1,14 @@
package me.aurora.service;
import java.util.Map;
/**
* @author 郑杰
* @date 2018/09/21 15:42:27
*/
public interface SessionService {
Map getOnlineInfo();
boolean forceLogout(String sessionId);
}
@@ -0,0 +1,94 @@
package me.aurora.service.impl;
import cn.hutool.http.HttpStatus;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import me.aurora.config.exception.AuroraException;
import me.aurora.domain.User;
import me.aurora.domain.UserOnline;
import me.aurora.service.SessionService;
import me.aurora.util.AddressUtils;
import me.aurora.util.HttpContextUtils;
import me.aurora.util.PageUtil;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.apache.shiro.subject.SimplePrincipalCollection;
import org.apache.shiro.subject.support.DefaultSubjectContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Shiro Session 对象管理
* @author 郑杰
* @date 2018/09/21 15:43:02
*/
@Slf4j
@Service
public class SessionServiceImpl implements SessionService {
@Autowired
private SessionDAO sessionDAO;
@Autowired
ObjectMapper mapper;
@Override
public Map getOnlineInfo() {
List<UserOnline> list = new ArrayList<>();
Collection<Session> sessions = sessionDAO.getActiveSessions();
for (Session session : sessions) {
UserOnline userOnline = new UserOnline();
User user;
SimplePrincipalCollection principalCollection;
if (session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY) == null) {
continue;
} else {
principalCollection = (SimplePrincipalCollection) session
.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
user = (User) principalCollection.getPrimaryPrincipal();
userOnline.setUsername(user.getUsername());
userOnline.setUserId(user.getId().toString());
}
userOnline.setId((String) session.getId());
userOnline.setHost(session.getHost());
userOnline.setStartTimestamp(session.getStartTimestamp());
userOnline.setLastAccessTime(session.getLastAccessTime());
Long timeout = session.getTimeout();
if (timeout == 0L) {
userOnline.setStatus("0");
} else {
userOnline.setStatus("1");
}
String address = AddressUtils.getCityInfo(userOnline.getHost());
userOnline.setLocation(address);
userOnline.setTimeout(timeout);
list.add(userOnline);
}
return PageUtil.buildPage(list,Long.parseLong(list.size()+""));
}
@Override
public boolean forceLogout(String sessionId) {
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String id = request.getSession().getId();
if(id.equals(sessionId)){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"不能踢出自己!");
}
try {
Session session = sessionDAO.readSession(sessionId);
session.setTimeout(0);
session.stop();
sessionDAO.delete(session);
} catch (Exception e) {
log.error("踢出用户失败", e);
throw new AuroraException(HttpStatus.HTTP_INTERNAL_ERROR,"踢出用户失败!");
}
return true;
}
}
+1 -1
View File
@@ -70,7 +70,7 @@ spring:
# Redis服务器连接端口
port: 6379
# Redis 密码
password:
password: ""
jedis:
pool:
# 连接池中的最小空闲连接
+23 -10
View File
@@ -11,7 +11,7 @@
Target Server Version : 50559
File Encoding : 65001
Date: 21/09/2018 11:40:53
Date: 21/09/2018 16:47:46
*/
SET NAMES utf8mb4;
@@ -34,7 +34,7 @@ CREATE TABLE `zj_menu` (
`level_number` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_cbhg0bi3f1emxkhqqtvca9btx`(`soft`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 15 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_menu
@@ -43,7 +43,7 @@ INSERT INTO `zj_menu` VALUES (1, 'layui-icon-unlink', 0, 1, '异常页', 40, '',
INSERT INTO `zj_menu` VALUES (2, 'layui-icon-tree', 1, 2, '403', 41, '/exception/403', '2018-08-29 11:40:17', '2018-09-20 11:36:24', 0);
INSERT INTO `zj_menu` VALUES (3, 'layui-icon-tree', 1, 2, '404', 42, '/exception/404', '2018-08-29 11:40:17', '2018-09-20 11:36:32', 0);
INSERT INTO `zj_menu` VALUES (4, 'layui-icon-tree', 1, 2, '500', 43, '/exception/500', '2018-08-29 11:40:17', '2018-09-20 11:36:40', 0);
INSERT INTO `zj_menu` VALUES (5, 'layui-icon-chart', 0, 1, '系统监控', 10, '', '2018-08-29 11:40:17', '2018-09-20 11:42:49', 1);
INSERT INTO `zj_menu` VALUES (5, 'layui-icon-chart', 0, 1, '系统监控', 10, '', '2018-08-29 11:40:17', '2018-09-21 16:09:38', 2);
INSERT INTO `zj_menu` VALUES (6, 'layui-icon-tree', 7, 2, '用户管理', 2, '/user/index', '2018-08-29 11:40:17', '2018-09-04 07:40:25', 0);
INSERT INTO `zj_menu` VALUES (7, 'layui-icon-util', 0, 1, '系统管理', 1, '', '2018-08-29 11:40:17', '2018-09-20 19:02:05', 4);
INSERT INTO `zj_menu` VALUES (8, 'layui-icon-tree', 7, 2, '菜单管理', 6, '/menu/index', '2018-08-29 11:40:17', '2018-09-04 07:40:25', 0);
@@ -52,6 +52,7 @@ INSERT INTO `zj_menu` VALUES (10, 'layui-icon-tree', 7, 2, '权限管理', 4, '/
INSERT INTO `zj_menu` VALUES (11, 'layui-icon-tree', 7, 2, '角色管理', 3, '/role/index', '2018-08-29 11:40:17', '2018-09-04 07:40:25', 0);
INSERT INTO `zj_menu` VALUES (12, 'layui-icon-website', 0, 1, '网络资源', 30, '', '2018-09-20 11:35:56', '2018-09-20 11:40:53', 1);
INSERT INTO `zj_menu` VALUES (13, 'layui-icon-tree', 12, 2, '图床管理', 31, '/picture/index', '2018-09-20 11:40:53', '2018-09-20 11:40:53', 0);
INSERT INTO `zj_menu` VALUES (14, 'layui-icon-tree', 5, 2, '在线用户管理', 12, '/online/index', '2018-09-21 16:09:38', '2018-09-21 16:09:38', 0);
-- ----------------------------
-- Table structure for zj_menus_roles
@@ -82,6 +83,7 @@ INSERT INTO `zj_menus_roles` VALUES (10, 1);
INSERT INTO `zj_menus_roles` VALUES (11, 1);
INSERT INTO `zj_menus_roles` VALUES (12, 1);
INSERT INTO `zj_menus_roles` VALUES (13, 1);
INSERT INTO `zj_menus_roles` VALUES (14, 1);
INSERT INTO `zj_menus_roles` VALUES (1, 2);
INSERT INTO `zj_menus_roles` VALUES (2, 2);
INSERT INTO `zj_menus_roles` VALUES (3, 2);
@@ -113,14 +115,14 @@ CREATE TABLE `zj_permission` (
`pid` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_djtxn2vldlgrkfk21d155b48i`(`perms`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 31 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_permission
-- ----------------------------
INSERT INTO `zj_permission` VALUES (1, 'admin', '超级管理员', '2018-08-29 15:15:12', '2018-08-31 00:00:00', 0);
INSERT INTO `zj_permission` VALUES (2, 'user:select', '用户查询', '2018-08-29 15:15:12', '2018-08-31 00:00:00', 4);
INSERT INTO `zj_permission` VALUES (3, 'log:select', '日志管理', '2018-08-29 15:15:12', '2018-09-02 23:11:37', 0);
INSERT INTO `zj_permission` VALUES (3, 'log:all', '日志管理', NULL, '2018-09-21 11:50:10', 0);
INSERT INTO `zj_permission` VALUES (4, 'user:all', '用户管理', '2018-08-29 15:15:12', '2018-09-02 23:11:31', 0);
INSERT INTO `zj_permission` VALUES (5, 'user:add', '新增用户', '2018-08-31 15:15:12', '2018-08-31 00:00:00', 4);
INSERT INTO `zj_permission` VALUES (6, 'user:update', '更新用户', '2018-08-31 15:15:12', '2018-08-31 00:00:00', 4);
@@ -139,6 +141,13 @@ INSERT INTO `zj_permission` VALUES (20, 'menu:add', '新增菜单', '2018-09-12
INSERT INTO `zj_permission` VALUES (21, 'menu:update', '更新菜单', '2018-09-12 13:12:21', '2018-09-12 13:12:21', 19);
INSERT INTO `zj_permission` VALUES (22, 'menu:delete', '删除菜单', '2018-09-12 13:12:43', '2018-09-12 13:12:43', 19);
INSERT INTO `zj_permission` VALUES (23, 'menu:select', '菜单搜索', '2018-09-12 13:15:02', '2018-09-12 13:15:02', 19);
INSERT INTO `zj_permission` VALUES (24, 'permission:delete', '删除权限', '2018-09-21 11:51:13', '2018-09-21 11:51:13', 8);
INSERT INTO `zj_permission` VALUES (25, 'user:delete', '删除用户', '2018-09-21 11:51:41', '2018-09-21 11:51:41', 4);
INSERT INTO `zj_permission` VALUES (26, 'picture:all', '图床管理', '2018-09-21 11:52:10', '2018-09-21 11:52:10', 0);
INSERT INTO `zj_permission` VALUES (27, 'picture:select', '图片查询', '2018-09-21 11:52:25', '2018-09-21 11:52:25', 26);
INSERT INTO `zj_permission` VALUES (28, 'picture:upload', '图片上传', NULL, '2018-09-21 11:53:30', 26);
INSERT INTO `zj_permission` VALUES (29, 'picture:delete', '图片删除', '2018-09-21 11:53:46', '2018-09-21 11:53:46', 26);
INSERT INTO `zj_permission` VALUES (30, 'user:logout', '踢出用户', '2018-09-21 16:46:59', '2018-09-21 16:46:59', 4);
-- ----------------------------
-- Table structure for zj_permissions_roles
@@ -181,7 +190,13 @@ CREATE TABLE `zj_picture` (
PRIMARY KEY (`id`) USING BTREE,
INDEX `FK5qtt7wql9517j0e2read2pdus`(`user_id`) USING BTREE,
CONSTRAINT `FK5qtt7wql9517j0e2read2pdus` FOREIGN KEY (`user_id`) REFERENCES `zj_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_picture
-- ----------------------------
INSERT INTO `zj_picture` VALUES (11, '2018-09-21 12:01:57', '1', '200', '8.49KB ', 'https://i.loli.net/2018/09/21/5ba46d305018d.jpg', '200', 1, 'avatar');
INSERT INTO `zj_picture` VALUES (12, '2018-09-21 15:15:21', 'https://sm.ms/delete/lLAmbyjGnr5W4zo', '200', '4.50KB ', 'https://i.loli.net/2018/09/21/5ba49a8975588.jpg', '200', 1, '1');
-- ----------------------------
-- Table structure for zj_role
@@ -235,13 +250,12 @@ CREATE TABLE `zj_user` (
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_kpubos9gc2cvtkb0thktkbkes`(`email`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zj_user
-- ----------------------------
INSERT INTO `zj_user` VALUES (1, 'https://www.zhengjie.me/images/avatar.jpg', '2018-08-23 09:11:56', 'zhengjie@tom.com', 1, '2018-09-21 08:47:20', '65a674ce6632479005ea7a9071234cfb', 'aurora');
INSERT INTO `zj_user` VALUES (6, 'https://i.loli.net/2018/08/16/5b75166b3157a.jpg', '2018-09-20 17:27:43', '11@qq.com', 0, '2018-09-21 08:45:26', '36318d4cc46eb68050b8b81ebc620f05', '测试');
INSERT INTO `zj_user` VALUES (1, 'https://www.zhengjie.me/images/avatar.jpg', '2018-08-23 09:11:56', 'zhengjie@tom.com', 1, '2018-09-21 16:26:05', '65a674ce6632479005ea7a9071234cfb', 'aurora');
-- ----------------------------
-- Table structure for zj_user_pictures
@@ -273,6 +287,5 @@ CREATE TABLE `zj_users_roles` (
-- Records of zj_users_roles
-- ----------------------------
INSERT INTO `zj_users_roles` VALUES (1, 1);
INSERT INTO `zj_users_roles` VALUES (6, 3);
SET FOREIGN_KEY_CHECKS = 1;
@@ -0,0 +1,81 @@
<div class="layui-fluid">
<div class="layui-row">
<div class="layui-col-xs12">
<div class="layui-card">
<div class="layui-card-header">在线用户管理</div>
<div class="layui-card-body">
<table class="layui-table" id="myTable" lay-filter="tools"></table>
<script type="text/html" id="operation">
<button shiro:hasAnyPermissions="admin,user:all,user:logout" class="layui-btn layui-btn-xs layui-btn-primary" lay-event="logout">下线</button>
</script>
</div>
</div>
</div>
</div>
</div>
<script>
layui.use(['jquery', 'table', 'sidebar', 'form'], function () {
var $ = layui.jquery,
layer = layui.layer,
table = layui.table,
sidebar = layui.sidebar,
form = layui.form;
//表格渲染
table.render({
elem: '#myTable'
, url: '/online/getOnlineInfo'
, page: false
, id: "ID"
, cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
, cols: [
[
{field: 'id', align: 'center', width: 130, title: 'sessionID'}
, {field: 'username', title: '用户昵称'}
, {field: 'systemHost', title: 'IP'}
, {field: 'host', title: '主机地址'}
, {field: 'location', title: '所在地'}
, {field: 'status',width: 80, align: 'center',title: '状态'}
, {field: 'startTimestamp',width: 170, title: '登录时间'}
, {field: 'lastAccessTime',width: 170, title: '最近登录'}
, {field: 'operation', align: 'center', width: 80, toolbar: '#operation', title: '操作'}
]
]
});
//监听修改按钮
table.on('tool(tools)', function (obj) {
var data = obj.data;
if (obj.event === 'logout') {
// 强制下线
layer.confirm("你确定踢出该用户吗?", {icon: 3, btnAlign: 'c', title: '提示'},
function (index) {//确定回调
$.ajax({
url: "/online/forceLogout?id=" + data.id,
type: "DELETE",
success: function (data) {
if (data.code == 200) {
layer.close(index);
layui.layer.msg("踢出成功!", {icon: 6});
setTimeout(function () {
table.reload('ID', {
where: {}
, page: {
curr: 1
}
});
}, 1000);
} else {
layer.close(index);
layer.msg(data.msg, {icon: 5});
}
}
});
layer.close(index);
}, function (index) {//取消回调
layer.close(index);
})
}
});
})
</script>
+1 -1
View File
@@ -37,7 +37,7 @@
</div>
<div class="kit-login-row">
<div class="kit-login-col">
<input type="checkbox" name="rememberMe" id="rememberMe" checked title="记住帐号" lay-skin="primary">
<input type="checkbox" name="rememberMe" id="rememberMe" title="记住帐号" lay-skin="primary">
</div>
</div>
<div class="kit-login-row">