wulianwei 4 роки тому
коміт
8d46541ca9
58 змінених файлів з 4074 додано та 0 видалено
  1. 121 0
      pom.xml
  2. 190 0
      simple.sql
  3. 23 0
      src/main/java/com/prac/simple/App.java
  4. 39 0
      src/main/java/com/prac/simple/config/GlobalCorsConfig.java
  5. 41 0
      src/main/java/com/prac/simple/config/RedisConfig.java
  6. 65 0
      src/main/java/com/prac/simple/constant/CodeMsg.java
  7. 16 0
      src/main/java/com/prac/simple/constant/CommonConstant.java
  8. 102 0
      src/main/java/com/prac/simple/controller/DeviceController.java
  9. 153 0
      src/main/java/com/prac/simple/controller/PermissionController.java
  10. 139 0
      src/main/java/com/prac/simple/controller/RoleController.java
  11. 157 0
      src/main/java/com/prac/simple/controller/UserController.java
  12. 25 0
      src/main/java/com/prac/simple/entity/Device.java
  13. 24 0
      src/main/java/com/prac/simple/entity/Permission.java
  14. 22 0
      src/main/java/com/prac/simple/entity/Role.java
  15. 14 0
      src/main/java/com/prac/simple/entity/RolePermission.java
  16. 36 0
      src/main/java/com/prac/simple/entity/User.java
  17. 23 0
      src/main/java/com/prac/simple/entity/UserRole.java
  18. 32 0
      src/main/java/com/prac/simple/entity/req/DeviceReq.java
  19. 14 0
      src/main/java/com/prac/simple/entity/req/EditPasswordReq.java
  20. 16 0
      src/main/java/com/prac/simple/entity/req/EditRolePermissionReq.java
  21. 16 0
      src/main/java/com/prac/simple/entity/req/EditUserRoleReq.java
  22. 31 0
      src/main/java/com/prac/simple/entity/req/PermissionReq.java
  23. 24 0
      src/main/java/com/prac/simple/entity/req/RoleReq.java
  24. 32 0
      src/main/java/com/prac/simple/entity/req/UserReq.java
  25. 20 0
      src/main/java/com/prac/simple/entity/resp/LoginResp.java
  26. 25 0
      src/main/java/com/prac/simple/entity/resp/MenuResp.java
  27. 32 0
      src/main/java/com/prac/simple/entity/resp/PermissionResp.java
  28. 144 0
      src/main/java/com/prac/simple/filter/PermissionFilter.java
  29. 22 0
      src/main/java/com/prac/simple/mapper/DeviceMapper.java
  30. 46 0
      src/main/java/com/prac/simple/mapper/PermissionMapper.java
  31. 26 0
      src/main/java/com/prac/simple/mapper/RoleMapper.java
  32. 21 0
      src/main/java/com/prac/simple/mapper/RolePermissionMapper.java
  33. 27 0
      src/main/java/com/prac/simple/mapper/UserMapper.java
  34. 17 0
      src/main/java/com/prac/simple/mapper/UserRoleMapper.java
  35. 27 0
      src/main/java/com/prac/simple/service/DeviceService.java
  36. 36 0
      src/main/java/com/prac/simple/service/PermissionService.java
  37. 32 0
      src/main/java/com/prac/simple/service/RoleService.java
  38. 33 0
      src/main/java/com/prac/simple/service/UserService.java
  39. 97 0
      src/main/java/com/prac/simple/service/impl/DeviceServiceImpl.java
  40. 234 0
      src/main/java/com/prac/simple/service/impl/PermissionServiceImpl.java
  41. 130 0
      src/main/java/com/prac/simple/service/impl/RoleServiceImpl.java
  42. 202 0
      src/main/java/com/prac/simple/service/impl/UserServiceImpl.java
  43. 26 0
      src/main/java/com/prac/simple/util/AccessTokenUtil.java
  44. 46 0
      src/main/java/com/prac/simple/util/MD5Util.java
  45. 115 0
      src/main/java/com/prac/simple/util/OperationResult.java
  46. 152 0
      src/main/java/com/prac/simple/util/PageResult.java
  47. 150 0
      src/main/java/com/prac/simple/util/ServiceResult.java
  48. 34 0
      src/main/java/com/prac/simple/util/SpringUtil.java
  49. 15 0
      src/main/java/com/prac/simple/util/UUIDUtil.java
  50. 83 0
      src/main/resources/application.yml
  51. 35 0
      src/main/resources/generatorConfig.xml
  52. 175 0
      src/main/resources/log/logback.xml
  53. 135 0
      src/main/resources/mapper/DeviceMapper.xml
  54. 198 0
      src/main/resources/mapper/PermissionMapper.xml
  55. 106 0
      src/main/resources/mapper/RoleMapper.xml
  56. 67 0
      src/main/resources/mapper/RolePermissionMapper.xml
  57. 166 0
      src/main/resources/mapper/UserMapper.xml
  58. 45 0
      src/main/resources/mapper/UserRoleMapper.xml

+ 121 - 0
pom.xml

@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>com.prac</groupId>
+	<artifactId>simple</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<packaging>war</packaging>
+
+	<name>simple</name>
+	<url>http://maven.apache.org</url>
+
+	<properties>
+		<encoding>UTF-8</encoding>
+		<java-version>1.8</java-version>
+	</properties>
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.3.5.RELEASE</version>
+	</parent>
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.mybatis.spring.boot</groupId>
+			<artifactId>mybatis-spring-boot-starter</artifactId>
+			<version>1.3.2</version>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<scope>runtime</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>druid-spring-boot-starter</artifactId>
+			<version>1.1.10</version>
+		</dependency>
+		<dependency>
+			<groupId>org.projectlombok</groupId>
+			<artifactId>lombok</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.62</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-lang3</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-data-redis</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.github.pagehelper</groupId>
+			<artifactId>pagehelper-spring-boot-starter</artifactId>
+			<version>1.2.10</version>
+		</dependency>
+		<dependency>
+			<groupId>cn.hutool</groupId>
+			<artifactId>hutool-all</artifactId>
+			<version>5.4.1</version>
+		</dependency>
+		 <!--mqtt依赖-->
+        <dependency>
+            <groupId>org.eclipse.paho</groupId>
+            <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
+            <version>1.2.2</version>
+        </dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>${java-version}</source> <!-- 源代码使用的JDK版本 -->
+					<target>${java-version}</target> <!-- 需要生成的目标class文件的编译版本 -->
+					<encoding>${encoding}</encoding><!-- 字符集编码 -->
+					<skipTests>true</skipTests><!-- 跳过测试 -->
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>repackage</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.mybatis.generator</groupId>
+				<artifactId>mybatis-generator-maven-plugin</artifactId>
+				<version>1.3.6</version>
+				<configuration>
+					<!-- mybatis-generator 配置文件存放地址 -->
+					<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
+					<!-- <overwrite>true</overwrite> -->
+				</configuration>
+				<dependencies>
+					<dependency>
+						<groupId>mysql</groupId>
+						<artifactId>mysql-connector-java</artifactId>
+						<version>${mysql.version}</version>
+					</dependency>
+				</dependencies>
+			</plugin>
+		</plugins>
+	</build>
+</project>

+ 190 - 0
simple.sql

@@ -0,0 +1,190 @@
+-- MySQL dump 10.13  Distrib 8.0.19, for Win64 (x86_64)
+--
+-- Host: localhost    Database: simple
+-- ------------------------------------------------------
+-- Server version	8.0.19
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!50503 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `device`
+--
+
+DROP TABLE IF EXISTS `device`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!50503 SET character_set_client = utf8mb4 */;
+CREATE TABLE `device` (
+  `mac` varchar(32) COLLATE utf8_bin NOT NULL COMMENT 'MAC',
+  `name` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT '设备名称',
+  `open` char(1) COLLATE utf8_bin DEFAULT '0' COMMENT '开关:''0'' 关闭, ''1'' 打开',
+  `type` char(2) COLLATE utf8_bin NOT NULL DEFAULT '00' COMMENT '设备类型',
+  `description` varchar(100) COLLATE utf8_bin DEFAULT NULL,
+  `createtime` datetime DEFAULT NULL COMMENT '创建时间',
+  `modifytime` datetime DEFAULT NULL COMMENT '修改时间',
+  PRIMARY KEY (`mac`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='设备表';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `device`
+--
+
+LOCK TABLES `device` WRITE;
+/*!40000 ALTER TABLE `device` DISABLE KEYS */;
+INSERT INTO `device` VALUES ('20210311001','TEST1','0','00','设备1','2021-03-11 02:42:33','2021-03-11 02:42:33'),('20210311002','TEST2','0','00','设备2','2021-03-11 06:26:28','2021-03-11 06:35:16');
+/*!40000 ALTER TABLE `device` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `permission`
+--
+
+DROP TABLE IF EXISTS `permission`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!50503 SET character_set_client = utf8mb4 */;
+CREATE TABLE `permission` (
+  `id` int NOT NULL AUTO_INCREMENT COMMENT 'ID',
+  `pid` int DEFAULT NULL COMMENT '父ID',
+  `title` varchar(50) DEFAULT NULL COMMENT '标题',
+  `type` char(2) DEFAULT NULL COMMENT '类型 ''01''  菜单,''02'' 链接 ''03'' 按钮 ',
+  `url` varchar(50) DEFAULT NULL COMMENT '路径',
+  `description` varchar(50) DEFAULT NULL COMMENT '描述',
+  `orders` int DEFAULT '0' COMMENT '排序',
+  `icon` varchar(45) DEFAULT NULL COMMENT '资源bootstrap图标',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8 COMMENT='资源';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `permission`
+--
+
+LOCK TABLES `permission` WRITE;
+/*!40000 ALTER TABLE `permission` DISABLE KEYS */;
+INSERT INTO `permission` VALUES (1,0,'系统管理','01','','',1,'glyphicon glyphicon-cog'),(2,1,'人员管理','02','user/listUser','',1,''),(3,1,'角色管理','02','role/listRole','',2,NULL),(4,1,'资源管理','02','permission/listPermission','',3,NULL),(14,4,'添加资源','03','permission/addPermission','',1,NULL),(15,4,'修改资源','03','permission/editPermission','',2,NULL),(16,4,'删除资源','03','permission/deletePermission','',3,NULL),(17,2,'添加用户','03','user/addUser','',1,NULL),(19,2,'删除用户','03','user/deleteUser','',3,NULL),(20,2,'批量删除用户','03','user/batchDeleteUser','',4,NULL),(21,3,'添加角色','03','role/addRole','',1,NULL),(22,3,'修改角色','03','role/editRole','',2,NULL),(23,3,'删除角色','03','role/deleteRole','',3,NULL),(25,3,'角色赋权','03','role/authorPermission','',4,NULL),(48,2,'修改用户','03','user/editUser','',2,NULL),(49,0,'设备管理','01','','',2,NULL),(50,49,'开关设备','02','device/listDevice','',1,NULL),(51,50,'添加设备','03','device/addDevice','',1,NULL),(52,50,'修改设备','03','device/editDevice','',2,NULL),(53,50,'删除设备','03','device/deleteDevice','',3,NULL);
+/*!40000 ALTER TABLE `permission` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `role`
+--
+
+DROP TABLE IF EXISTS `role`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!50503 SET character_set_client = utf8mb4 */;
+CREATE TABLE `role` (
+  `id` varchar(50) NOT NULL COMMENT 'ID',
+  `name` varchar(50) DEFAULT NULL COMMENT '名称',
+  `description` varchar(50) DEFAULT NULL COMMENT '描述',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `role`
+--
+
+LOCK TABLES `role` WRITE;
+/*!40000 ALTER TABLE `role` DISABLE KEYS */;
+INSERT INTO `role` VALUES ('manager','管理员','管理'),('user','用户','简单查看'),('worker','员工','简单管理');
+/*!40000 ALTER TABLE `role` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `role_permission`
+--
+
+DROP TABLE IF EXISTS `role_permission`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!50503 SET character_set_client = utf8mb4 */;
+CREATE TABLE `role_permission` (
+  `role_id` varchar(50) NOT NULL COMMENT '角色ID',
+  `permission_id` int NOT NULL COMMENT '资源ID',
+  UNIQUE KEY `UK_role_permission` (`role_id`,`permission_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `role_permission`
+--
+
+LOCK TABLES `role_permission` WRITE;
+/*!40000 ALTER TABLE `role_permission` DISABLE KEYS */;
+INSERT INTO `role_permission` VALUES ('manager',1),('manager',2),('manager',3),('manager',4),('manager',14),('manager',15),('manager',16),('manager',17),('manager',19),('manager',20),('manager',21),('manager',22),('manager',23),('manager',25),('manager',48),('manager',49),('manager',50),('manager',51),('manager',52),('manager',53),('user',49),('user',50),('worker',49),('worker',50),('worker',53);
+/*!40000 ALTER TABLE `role_permission` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `user`
+--
+
+DROP TABLE IF EXISTS `user`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!50503 SET character_set_client = utf8mb4 */;
+CREATE TABLE `user` (
+  `id` varchar(40) NOT NULL COMMENT 'ID',
+  `username` varchar(50) DEFAULT NULL COMMENT '用户名',
+  `password` varchar(50) DEFAULT NULL COMMENT '密码',
+  `email` varchar(45) DEFAULT NULL COMMENT '邮箱',
+  `salt` varchar(45) DEFAULT NULL COMMENT '盐',
+  `enabled` char(1) DEFAULT '1' COMMENT '使能 ''0'' 无效 ''1'' 有效',
+  `createtime` datetime DEFAULT NULL COMMENT '创建时间',
+  `lasttime` datetime DEFAULT NULL COMMENT '最近登陆时间',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `username_UNIQUE` (`username`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `user`
+--
+
+LOCK TABLES `user` WRITE;
+/*!40000 ALTER TABLE `user` DISABLE KEYS */;
+INSERT INTO `user` VALUES ('1','admin','e10adc3949ba59abbe56e057f20f883e','18224516628@163.com',NULL,'1',NULL,'2021-03-11 08:58:26'),('e173e878c7ac4ddba03ff50a3e9adb09','wulianwei','e10adc3949ba59abbe56e057f20f883e','18224516628@163.com',NULL,'1','2021-02-06 01:14:51','2021-03-11 08:57:53'),('e21af46366e84f9688014c1c3b010726','lurenjia','e10adc3949ba59abbe56e057f20f883e','18224516628@163.com',NULL,'1','2021-03-11 06:46:52','2021-03-11 06:47:09');
+/*!40000 ALTER TABLE `user` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `user_role`
+--
+
+DROP TABLE IF EXISTS `user_role`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!50503 SET character_set_client = utf8mb4 */;
+CREATE TABLE `user_role` (
+  `user_id` varchar(50) NOT NULL COMMENT '用户ID',
+  `role_id` varchar(50) NOT NULL COMMENT '角色ID',
+  UNIQUE KEY `UK_user_role` (`user_id`,`role_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `user_role`
+--
+
+LOCK TABLES `user_role` WRITE;
+/*!40000 ALTER TABLE `user_role` DISABLE KEYS */;
+INSERT INTO `user_role` VALUES ('1','manager'),('3b97dc27ddf546a387d3d6864d17c9fd','manager'),('642a6d6e2d50441c90770027d91f42f1','manager'),('898c852ca04740b5ad334d6db3789fea','user'),('898c852ca04740b5ad334d6db3789fea','worker'),('e173e878c7ac4ddba03ff50a3e9adb09','worker'),('e21af46366e84f9688014c1c3b010726','user');
+/*!40000 ALTER TABLE `user_role` ENABLE KEYS */;
+UNLOCK TABLES;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2021-03-11 17:02:43

+ 23 - 0
src/main/java/com/prac/simple/App.java

@@ -0,0 +1,23 @@
+package com.prac.simple;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+/**
+ * 启动类
+ *
+ */
+@ServletComponentScan
+@SpringBootApplication
+@EnableTransactionManagement
+@MapperScan("com.prac.simple.mapper")
+public class App 
+{
+    public static void main( String[] args )
+    {
+        SpringApplication.run(App.class, args);
+    }
+}

+ 39 - 0
src/main/java/com/prac/simple/config/GlobalCorsConfig.java

@@ -0,0 +1,39 @@
+package com.prac.simple.config;
+
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * 
+ * @Description:  跨域配置   
+ * @author: Administrator     
+ * @date:   2020-04-29 11:43
+ */
+@Configuration
+public class GlobalCorsConfig implements WebMvcConfigurer {
+    //添加到容器中管理
+	private CorsConfiguration buildConfig() {  
+        CorsConfiguration corsConfiguration = new CorsConfiguration();  
+        corsConfiguration.addAllowedOrigin("*"); // 1允许任何域名使用
+        corsConfiguration.addAllowedHeader("*"); // 2允许任何头
+        corsConfiguration.addAllowedMethod("*"); // 3允许任何方法(post、get等) 
+        return corsConfiguration;  
+    }  
+
+    @Bean  
+    public FilterRegistrationBean<CorsFilter> corsFilter() {  
+    	
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();  
+        source.registerCorsConfiguration("/**", buildConfig()); // 4  
+        
+        FilterRegistrationBean<CorsFilter> corsBean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(source));
+        corsBean.setName("crossOriginFilter");
+        corsBean.setOrder(0);//这个顺序也有可能会有影响,尽量设置在拦截器前面
+        return corsBean;  
+    }  
+}

+ 41 - 0
src/main/java/com/prac/simple/config/RedisConfig.java

@@ -0,0 +1,41 @@
+package com.prac.simple.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+/**
+ * @Description:    配置Redis   
+ * @author: Administrator     
+ * @date:   2020年4月28日 下午4:49:01
+ */
+@Configuration
+public class RedisConfig {
+	
+	@Bean
+	@SuppressWarnings("all")
+	public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
+		RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
+		template.setConnectionFactory(factory);
+		Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
+		ObjectMapper om = new ObjectMapper(); 
+		om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+		om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+		jackson2JsonRedisSerializer.setObjectMapper(om);
+		StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
+		template.setKeySerializer(stringRedisSerializer);
+		template.setHashKeySerializer(stringRedisSerializer);
+		template.setValueSerializer(jackson2JsonRedisSerializer);
+		template.setHashValueSerializer(jackson2JsonRedisSerializer);
+		template.afterPropertiesSet();
+		return template;
+		
+	}
+
+}

+ 65 - 0
src/main/java/com/prac/simple/constant/CodeMsg.java

@@ -0,0 +1,65 @@
+package com.prac.simple.constant;
+
+/**
+ * @Description:    提示信息
+ * @author: Administrator     
+ * @date:   2020年4月29日 上午11:17:55
+ */
+public class CodeMsg {
+
+	private Integer retCode;
+	private String message;
+
+	// 成功
+	public static final Integer SUCCESS_CODE = 0;
+	public static final String SUCCESS_DESC = "SUCCESS";
+
+	// 失败
+	public static final Integer FAILED_CODE = -1;
+
+	// 按照模块定义CodeMsg
+	// 通用异常
+	public static CodeMsg SUCCESS = new CodeMsg(SUCCESS_CODE, SUCCESS_DESC);
+	public static CodeMsg FAILURE = new CodeMsg(FAILED_CODE, "系统繁忙");
+	public static CodeMsg LOGINSUCCESS = new CodeMsg(SUCCESS_CODE, "登录成功");
+	public static CodeMsg LOGINFAILED = new CodeMsg(FAILED_CODE, "登陆失败");
+	public static CodeMsg SERVER_EXCEPTION = new CodeMsg(10001, "系统繁忙,请稍后再试");
+	public static CodeMsg RELOGIN = new CodeMsg(10002, "请重新登陆");
+	public static CodeMsg REQUEST_DENY = new CodeMsg(10003, "无权访问");
+	public static CodeMsg PARAMETER_ISNULL = new CodeMsg(10004, "输入参数为空");
+	public static CodeMsg USERNAME_WRONG = new CodeMsg(10005, "用户名错误");
+	public static CodeMsg PASSWORD_WRONG = new CodeMsg(10006, "用户名错误");
+	public static CodeMsg LOGIN_PLEASE= new CodeMsg(10007, "请登陆");
+	public static CodeMsg NO_RIGHT= new CodeMsg(10008, "无权访问");
+	public static CodeMsg USER_EXIST= new CodeMsg(10009, "用户已存在");
+	public static CodeMsg USER_NO_EXIST= new CodeMsg(10010, "用户不存在");
+	public static CodeMsg PERMISSION_EXIST= new CodeMsg(10011, "资源已存在");
+	public static CodeMsg ROLE_EXIST= new CodeMsg(10012, "角色已存在");
+	public static CodeMsg CHILDREN_PERMISSION_EXIST= new CodeMsg(10013, "存在子功能");
+	public static CodeMsg OLDPASSWORD_WRONG= new CodeMsg(10014, "旧密码不正确");
+	public static CodeMsg DEVICE_EXIST= new CodeMsg(10015, "设备已存在");
+	
+	
+
+	public CodeMsg(int retCode, String message) {
+		this.retCode = retCode;
+		this.message = message;
+	}
+
+	public int getRetCode() {
+		return retCode;
+	}
+
+	public String getMessage() {
+		return message;
+	}
+
+	public void setMessage(String message) {
+		this.message = message;
+	}
+
+	@Override
+	public String toString() {
+		return "CodeMsg [retCode=" + retCode + ", message=" + message + "]";
+	}
+}

+ 16 - 0
src/main/java/com/prac/simple/constant/CommonConstant.java

@@ -0,0 +1,16 @@
+package com.prac.simple.constant;
+
+public final class CommonConstant {
+	public static final Integer ZERO = 0;
+	public static final long LOGIN_EXPIRE = 30*60L; // 登陆有效时间
+	
+	public static final String ROLE_MANAGER = "manager"; // 管理员角色
+	
+	public static final String PERMISSION_TYPE_MAINMENU = "01"; //主菜单
+	public static final String PERMISSION_TYPE_SUBMENU = "02"; //子菜单
+	public static final String PERMISSION_TYPE_BUTTON = "03"; //按钮
+	
+	public static final String DEVICE_ON= "1"; //设备开
+	public static final String DEVICE_OFF = "0";//设备关
+	
+}

+ 102 - 0
src/main/java/com/prac/simple/controller/DeviceController.java

@@ -0,0 +1,102 @@
+package com.prac.simple.controller;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.prac.simple.entity.Device;
+import com.prac.simple.entity.req.DeviceReq;
+import com.prac.simple.service.DeviceService;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+@RestController
+@RequestMapping("/device")
+public class DeviceController {
+	
+	private static Logger logger = LoggerFactory.getLogger(DeviceController.class);
+	
+	@Autowired
+	private DeviceService deviceService;
+	
+	/**
+	 * @Description 查询设备
+	 * @Author wulianwei
+	 * @Date 2021-03-11 10:22
+	 * @Return  PageResult<List<Device>>
+	 */
+	@PostMapping("/searchDevice")
+	public PageResult<List<Device>> searchDevice(@RequestBody DeviceReq req){
+		logger.info("searchDevice>>:{}",req);
+		return deviceService.searchDevice(req);
+	}
+	
+	/**
+	 * @Description 添加设备
+	 * @Author wulianwei
+	 * @Date 2021-03-11 10:22
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/addDevice")
+	public OperationResult addDevice(@RequestBody Device record){
+		logger.info("addDevice>>:{}",record);
+		return deviceService.addDevice(record);
+	}
+	
+	/**
+	 * @Description 修改设备
+	 * @Author wulianwei
+	 * @Date 2021-03-11 10:22
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/editDevice")
+	public OperationResult editDevice(@RequestBody Device record){
+		logger.info("editDevice>>:{}",record);
+		return deviceService.editDevice(record);
+	}
+	
+	
+	/**
+	 * @Description 删除设备
+	 * @Author wulianwei
+	 * @Date 2021-03-11 10:22
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/deleteDevice")
+	public OperationResult deleteDevice(@RequestBody Device record){
+		logger.info("deleteDevice>>:{}",record);
+		return deviceService.deleteDevice(record.getMac());
+	}
+	
+	/**
+	 * @Description 设备详情
+	 * @Author wulianwei
+	 * @Date 2021-03-11 10:22
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/getDevice")
+	public ServiceResult<Device> getDevice(@RequestBody Device record){
+		logger.info("getDevice>>:{}",record);
+		return deviceService.getDevice(record);
+	}
+	
+	/**
+	 * @Description 开关设备
+	 * @Author wulianwei
+	 * @Date 2021-03-11 10:22
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/switchDevice")
+	public OperationResult switchDevice(@RequestBody DeviceReq req){
+		logger.info("switchDevice>>:{}",req);
+		return deviceService.switchDevice(req);
+	}
+
+}

+ 153 - 0
src/main/java/com/prac/simple/controller/PermissionController.java

@@ -0,0 +1,153 @@
+package com.prac.simple.controller;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.prac.simple.entity.Permission;
+import com.prac.simple.entity.req.PermissionReq;
+import com.prac.simple.entity.resp.MenuResp;
+import com.prac.simple.entity.resp.PermissionResp;
+import com.prac.simple.service.PermissionService;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.ServiceResult;
+/**
+ * 
+ * @Description:  权限管理
+ * @author: wulianwei  
+ * @date: 2020-05-15 17:09
+ */
+@RestController
+@RequestMapping("/permission")
+public class PermissionController {
+	
+	private static Logger logger = LoggerFactory.getLogger(PermissionController.class);
+	
+	@Autowired
+	PermissionService permissionService;
+
+
+	/**
+	 * @Description 查询菜单
+	 * @Author wulianwei
+	 * @Date 2020-05-22
+	 */
+	@PostMapping("/listUserMenu")
+	public ServiceResult<List<MenuResp>> listUserMenu(){
+		logger.info("listUserMenu>>");
+		return permissionService.listUserMenu();
+	}
+	
+	/**
+	 * @Description 查询菜单
+	 * @Author wulianwei
+	 * @Date 2020-05-22
+	 */
+	@PostMapping("/listUserPermission")
+	public ServiceResult<List<Permission>> listUserPermission(){
+		logger.info("listUserPermission>>");
+		return permissionService.listUserPermission();
+	}
+	
+	/**
+	 * @Description 查询菜单
+	 * @Author wulianwei
+	 * @Date 2020-05-22
+	 */
+	@PostMapping("/listAllPermission")
+	public ServiceResult<List<Permission>> listAllPermission(){
+		logger.info("listAllPermission>>");
+		return permissionService.listAllPermission();
+	}
+	
+	/**
+	 * @Description 资源详情
+	 * @Author wulianwei
+	 * @Date 2020-05-22 14:18
+	 * @Return  ServiceResult<Permission>
+	 */
+	@PostMapping("/permissionDetail")
+	public ServiceResult<PermissionResp> permissionDetail(@RequestBody PermissionReq req){
+		logger.info("permissionDetail>>{}", req);
+		return permissionService.permissionDetail(req.getId());
+	}
+	
+	/**
+	 * @Description 查询角色拥有的资源
+	 * @Author wulianwei
+	 * @Date 2020-05-22 14:18
+	 * @Return  ServiceResult<Permission>
+	 */
+	@PostMapping("/listPermissionIdByRoleId")
+	public ServiceResult<List<String>> listPermissionIdByRoleId(@RequestBody PermissionReq req){
+		logger.info("listPermissionIdByRoleId>>:{}", req);
+		return permissionService.listPermissionIdByRoleId(req.getRoleId());
+	}
+	
+	/**
+	 * @Description 查看资源
+	 * @Author wulianwei
+	 * @Date 2020-05-22 14:18
+	 * @Return  ServiceResult<Permission>
+	 */
+	@PostMapping("/listAllMenu")
+	public ServiceResult<List<Permission>> listAllMenu(){
+		logger.info("listAllMenu>>");
+		return permissionService.listAllMenu();
+	}
+	/**
+	 * @Description 添加资源
+	 * @Author wulianwei
+	 * @Date 2020-05-22 11:01
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/addPermission")
+	public OperationResult addPermission(@RequestBody PermissionReq req) {
+		logger.info("addPermission>>{}", req);
+		return permissionService.addPermission(req);
+	} 
+	
+	/**
+	 * @Description 修改资源
+	 * @Author wulianwei
+	 * @Date 2020-05-22 11:01
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/editPermission")
+	public OperationResult editPermission(@RequestBody Permission permission) {
+		logger.info("editPermission>>{}", permission);
+		return permissionService.editPermission(permission);
+	} 
+	
+	/**
+	 * @Description 删除资源
+	 * @Author wulianwei
+	 * @Date 2020-05-23 10:14
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/batchDeletePermission")
+	public OperationResult batchDeletePermission(@RequestBody PermissionReq req) {
+		logger.info("batchDeletePermission>>{}",req);
+		return permissionService.batchDeletePermission(req.getId());
+	}
+	
+	/**
+	 * @Description 删除资源
+	 * @Author wulianwei
+	 * @Date 2020-05-23 10:14
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/deletePermission")
+	public OperationResult deletePermission(@RequestBody PermissionReq req) {
+		logger.info("deletePermission>>{}",req);
+		return permissionService.deletePermission(req.getId());
+	}
+	
+
+}

+ 139 - 0
src/main/java/com/prac/simple/controller/RoleController.java

@@ -0,0 +1,139 @@
+package com.prac.simple.controller;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.prac.simple.entity.Role;
+import com.prac.simple.entity.req.EditRolePermissionReq;
+import com.prac.simple.entity.req.EditUserRoleReq;
+import com.prac.simple.entity.req.RoleReq;
+import com.prac.simple.service.RoleService;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+@RestController	
+@RequestMapping("/role")
+public class RoleController {
+	
+	private static Logger logger = LoggerFactory.getLogger(RoleController.class);
+	
+	@Autowired
+	RoleService roleService;
+	
+	/**
+	 * @Description 列出所有角色
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:16
+	 * @Return  ServiceResult<List<Role>>
+	 */
+	@PostMapping("/listAllRole")
+	public ServiceResult<List<Role>> listAllRole(){
+		logger.info("listAllRole>>");
+		return roleService.listRole();
+	}
+	
+	/**
+	 * @Description 查询角色
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:16
+	 * @Return  ServiceResult<List<Role>>
+	 */
+	@PostMapping("/searchRole")
+	public PageResult<List<Role>> searchRole(@RequestBody RoleReq req){
+		logger.info("searchRole>>req:{}",req);
+		return roleService.searchRole(req);
+	}
+	
+	/**
+	 * @Description 查询用户拥有的角色
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:50
+	 * @Return  ServiceResult
+	 */
+	@PostMapping("/listRoleIdByUser")
+	public ServiceResult<List<String>> listRoleIdByUser() {
+		logger.info("listRoleIdByUser>>");
+		return roleService.listRoleIdByUser();
+	}
+	
+	/**
+	 * @Description 角色详情
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:18
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/getRole")
+	public ServiceResult<Role> getRole(@RequestBody RoleReq req) {
+		logger.info("getRole>>{}", req);
+		return roleService.getRole(req.getId());
+	}
+	
+	/**
+	 * @Description 添加角色
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:18
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/addRole")
+	public OperationResult addRole(@RequestBody Role role) {
+		logger.info("addRole>>{}", role);
+		return roleService.addRole(role);
+	}
+	
+	/**
+	 * @Description 编辑角色
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:24
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/editRole")
+	public OperationResult editRole(@RequestBody Role role) {
+		logger.info("editRole>>{}", role);
+		return roleService.editRole(role);
+	}
+	
+	/**
+	 * @Description 删除角色
+	 * @Author wulianwei
+	 * @Date 2020-05-23 15:24
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/deleteRole")
+	public OperationResult deleteRole(@RequestBody Role role) {
+		logger.info("deleteRole>>{}", role);
+		return roleService.deleteRole(role);
+	}
+	
+	/**
+	 * @Description 用户赋权
+	 * @Author wulianwei
+	 * @Date 2020-05-23 16:32
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/editUserRole")
+	public OperationResult editUserRole(@RequestBody EditUserRoleReq req) {
+		logger.info("editUserRole>>{}", req);
+		return roleService.editUserRole(req);
+	}
+	
+	/**
+	 * @Description 为角色赋权
+	 * @Author wulianwei
+	 * @Date 2020-05-23 16:55
+	 * @Return  OperationResult
+	 */
+	@PostMapping("/authorPermission")
+	public OperationResult authorPermission(@RequestBody EditRolePermissionReq req) {
+		logger.info("authorPermission>>{}",req);
+		return roleService.authorPermission(req);
+	}
+
+}

+ 157 - 0
src/main/java/com/prac/simple/controller/UserController.java

@@ -0,0 +1,157 @@
+package com.prac.simple.controller;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.prac.simple.entity.User;
+import com.prac.simple.entity.req.EditPasswordReq;
+import com.prac.simple.entity.req.UserReq;
+import com.prac.simple.entity.resp.LoginResp;
+import com.prac.simple.service.UserService;
+import com.prac.simple.util.AccessTokenUtil;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+/**
+ * 
+ * @Description:  用户管理
+ * @author: wulianwei  
+ * @date: 2020-05-15 17:09
+ */
+@RestController
+@RequestMapping("/user")
+public class UserController {
+
+	private static Logger logger = LoggerFactory.getLogger(UserController.class);
+	@Autowired
+	private UserService userService;
+	/**
+	 * @Description:    登陆   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-29 11:43  
+	 * @Return ServiceResult<LoginResp>
+	 */
+	@PostMapping("/login")
+	public ServiceResult<LoginResp> login(@RequestBody User user){
+		logger.info("login>>user:{}",user);
+		return userService.login(user.getUsername(), user.getPassword());		
+	}
+	/**
+	 * @Description:    登陆   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-29 11:43  
+	 * @Return ServiceResult<LoginResp>
+	 */
+	@PostMapping("/logout")
+	public OperationResult logout(){
+		logger.info("logout>>");
+		return userService.logout();		
+	}
+	
+	/**
+	 * @Description 查询人员 
+	 * @Author wulianwei
+	 * @Date 2020-05-23 12:32
+	 * @Return  PageResult<List<User>>
+	 */
+	@PostMapping("/searchUser")
+	public PageResult<List<User>> searchUser(@RequestBody UserReq req){
+		logger.info("searchUser>>:{}", req);
+		return userService.searchUser(req);
+	}
+	
+	/**
+	 * @Description 查询人员 
+	 * @Author wulianwei
+	 * @Date 2020-05-23 12:32
+	 * @Return  PageResult<List<User>>
+	 */
+	@PostMapping("/getUser")
+	public ServiceResult<User> getUser(@RequestBody UserReq req){
+		logger.info("getUser>>:{}", req);
+		return userService.getUser(req.getId());
+	}
+	
+	/**
+	 * 
+	 * @Description:    添加用户   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-30 15:24  
+	 * @Return OperationResult
+	 */
+	@PostMapping("/addUser")
+	public OperationResult addUser(@RequestBody UserReq userReq) {
+		logger.info("addUser>>:{}", userReq);
+		return userService.addUser(userReq);
+	}
+	
+	/**
+	 * @Description: 编辑用户   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-30 15:24  
+	 * @Return OperationResult
+	 */
+	@PostMapping("/editUser")
+	public OperationResult editUser(@RequestBody UserReq userReq) {
+		logger.info("editUser>>:{}",userReq);
+		return userService.editUser(userReq);
+	}
+	/**
+	 * @Description: 修改密码   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-30 15:24  
+	 * @Return OperationResult
+	 */
+	@PostMapping("/editPassword")
+	public OperationResult editPassword(@RequestBody EditPasswordReq req) {
+		logger.info("editPassword>>:{}",req);
+		return userService.editPassword(req);
+	}
+	
+	/**
+	 * 
+	 * @Description:    批量删除用户   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-30 15:24  
+	 * @Return OperationResult
+	 */
+	@PostMapping("/batchDeleteUser")
+	public OperationResult batchDeleteUser(@RequestBody UserReq req) {
+		logger.info("batchDeleteUser>>:{}",req);
+		return userService.bacthDeleteUser(req.getId());
+	}
+	
+	/**
+	 * 
+	 * @Description:    删除用户   
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-30 15:24  
+	 * @Return OperationResult
+	 */
+	@PostMapping("/deleteUser")
+	public OperationResult deleteUser(@RequestBody UserReq req) {
+		logger.info("deleteUser>>:{}",req);
+		return userService.deleteUser(req.getId());
+	}
+	
+	/**
+	 * 
+	 * @Description:    登录用户简介  
+	 * @Author: wulianwei     
+	 * @Date:   2020-04-30 15:24  
+	 * @Return OperationResult
+	 */
+	@PostMapping("/loginBrief")
+	public ServiceResult<User> brief() {
+		logger.info("loginBrief>>");
+		User user = AccessTokenUtil.getUser();
+		return ServiceResult.newSuccess(user);
+	}
+}

+ 25 - 0
src/main/java/com/prac/simple/entity/Device.java

@@ -0,0 +1,25 @@
+package com.prac.simple.entity;
+
+import java.util.Date;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class Device {
+    private String mac;
+
+    private String name;
+
+    private String open;
+
+    private String type;
+
+    private String description;
+
+    private Date createtime;
+
+    private Date modifytime;
+
+}

+ 24 - 0
src/main/java/com/prac/simple/entity/Permission.java

@@ -0,0 +1,24 @@
+package com.prac.simple.entity;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class Permission {
+    private String id;
+
+    private String pid;
+
+    private String title;
+
+    private String type;
+
+    private String url;
+
+    private String description;
+
+    private Integer orders;
+
+    
+}

+ 22 - 0
src/main/java/com/prac/simple/entity/Role.java

@@ -0,0 +1,22 @@
+package com.prac.simple.entity;
+
+import java.io.Serializable;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class Role implements Serializable{
+    /**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private String id;
+
+    private String name;
+
+    private String description;
+    
+}

+ 14 - 0
src/main/java/com/prac/simple/entity/RolePermission.java

@@ -0,0 +1,14 @@
+package com.prac.simple.entity;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class RolePermission {
+	
+	private String roleId;
+	private String url;
+	private String permissionId;
+
+}

+ 36 - 0
src/main/java/com/prac/simple/entity/User.java

@@ -0,0 +1,36 @@
+package com.prac.simple.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class User  implements Serializable{
+    /**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private String id;
+
+    private String username;
+
+    private String password;
+
+    private String email;
+
+    private String salt;
+
+    private String enabled;
+
+    private Date createtime;
+
+    private Date lasttime;
+    
+    private List<String> roles;
+
+}

+ 23 - 0
src/main/java/com/prac/simple/entity/UserRole.java

@@ -0,0 +1,23 @@
+package com.prac.simple.entity;
+
+public class UserRole {
+    private String userId;
+
+    private String roleId;
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId == null ? null : userId.trim();
+    }
+
+    public String getRoleId() {
+        return roleId;
+    }
+
+    public void setRoleId(String roleId) {
+        this.roleId = roleId == null ? null : roleId.trim();
+    }
+}

+ 32 - 0
src/main/java/com/prac/simple/entity/req/DeviceReq.java

@@ -0,0 +1,32 @@
+package com.prac.simple.entity.req;
+
+import java.util.Date;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class DeviceReq {
+	
+	private Integer pageSize;
+	
+	private Integer pageNum;
+	
+	private String sort;  //排序字段
+	
+	private String order; //排序,asc,desc
+	
+	private String mac;
+
+    private String name;
+
+    private String open;
+
+    private String type;
+
+    private String description;
+
+    private Date createtime;
+
+}

+ 14 - 0
src/main/java/com/prac/simple/entity/req/EditPasswordReq.java

@@ -0,0 +1,14 @@
+package com.prac.simple.entity.req;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class EditPasswordReq {
+	
+	private String oldPassword;
+	
+	private String newPassword;
+
+}

+ 16 - 0
src/main/java/com/prac/simple/entity/req/EditRolePermissionReq.java

@@ -0,0 +1,16 @@
+package com.prac.simple.entity.req;
+
+import java.util.List;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class EditRolePermissionReq {
+	
+	private String roleId;
+	
+	private List<String> permissionIds;
+
+}

+ 16 - 0
src/main/java/com/prac/simple/entity/req/EditUserRoleReq.java

@@ -0,0 +1,16 @@
+package com.prac.simple.entity.req;
+
+import java.util.List;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class EditUserRoleReq {
+	
+	private String userId;
+	
+	private List<String> roleIds;
+
+}

+ 31 - 0
src/main/java/com/prac/simple/entity/req/PermissionReq.java

@@ -0,0 +1,31 @@
+package com.prac.simple.entity.req;
+
+import java.util.List;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class PermissionReq {	
+	private String id;
+
+    private String pid;
+
+    private String title;
+
+    private String type;
+
+    private String url;
+
+    private String description;
+
+    private Integer orders;
+    
+	private String roleId;
+	
+	private String mainMenu;
+	
+	private String subMenu;
+	private List<String> ids;
+}

+ 24 - 0
src/main/java/com/prac/simple/entity/req/RoleReq.java

@@ -0,0 +1,24 @@
+package com.prac.simple.entity.req;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class RoleReq {
+	
+	private Integer pageSize;
+	
+	private Integer pageNum;
+	
+	private String sort;  //排序字段
+	
+	private String order; //排序,asc,desc
+	
+	private String id;
+
+    private String name;
+
+    private String description;
+    
+}

+ 32 - 0
src/main/java/com/prac/simple/entity/req/UserReq.java

@@ -0,0 +1,32 @@
+package com.prac.simple.entity.req;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data	
+@ToString
+public class UserReq {
+	
+	private Integer pageSize;
+	
+	private Integer pageNum;
+	
+	private String sort;  //排序字段
+	
+	private String order; //排序,asc,desc
+	
+	private String id;
+
+    private String username;
+
+    private String password;
+
+    private String email;
+
+    private String salt;
+
+    private String enabled;
+    
+    private String roleIds; //"role1,role2"
+
+}

+ 20 - 0
src/main/java/com/prac/simple/entity/resp/LoginResp.java

@@ -0,0 +1,20 @@
+package com.prac.simple.entity.resp;
+
+import java.util.List;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class LoginResp {
+	
+	private String id;
+	
+	private String username;
+	
+	private List<String> roles;
+	
+	private String token;
+
+}

+ 25 - 0
src/main/java/com/prac/simple/entity/resp/MenuResp.java

@@ -0,0 +1,25 @@
+package com.prac.simple.entity.resp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class MenuResp {
+	
+	private String id;
+	
+	private String title;
+
+    private String type;
+
+    private String url;
+    
+    private Integer orders;
+    
+    private List<MenuResp> children = new ArrayList<MenuResp>();
+
+}

+ 32 - 0
src/main/java/com/prac/simple/entity/resp/PermissionResp.java

@@ -0,0 +1,32 @@
+package com.prac.simple.entity.resp;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class PermissionResp {
+
+	private String id;
+
+    private String pid;
+
+    private String title;
+
+    private String type;
+
+    private String url;
+
+    private String description;
+
+    private Integer orders;
+    	
+	private String mainMenu;
+	
+	private String subMenu;
+	
+	private String mainMenuName;
+	
+	private String subMenuName;
+	
+}

+ 144 - 0
src/main/java/com/prac/simple/filter/PermissionFilter.java

@@ -0,0 +1,144 @@
+package com.prac.simple.filter;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.Ordered;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import com.alibaba.fastjson.JSON;
+import com.prac.simple.constant.CodeMsg;
+import com.prac.simple.constant.CommonConstant;
+import com.prac.simple.entity.User;
+import com.prac.simple.mapper.PermissionMapper;
+import com.prac.simple.mapper.RolePermissionMapper;
+import com.prac.simple.util.AccessTokenUtil;
+import com.prac.simple.util.OperationResult;
+
+@WebFilter(filterName = "permissionFilter",urlPatterns = "/*")
+public class PermissionFilter implements Filter,Ordered{
+	
+	private Logger logger = LoggerFactory.getLogger(PermissionFilter.class);
+	
+	@Autowired
+	private RolePermissionMapper rolePermissionMapper;
+	
+	@Autowired
+	private PermissionMapper permissionMapper;
+
+	@Autowired
+	private RedisTemplate<String, Object> redisTemplate;
+	
+//	@Autowired
+//	private DataInit dataInit;
+	
+	@Override
+	public void init(FilterConfig filterConfig) throws ServletException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+			throws IOException, ServletException {
+		// TODO Auto-generated method stub
+		String uri  = ((HttpServletRequest)request).getRequestURI();
+		if(uri.startsWith("/")) {
+			uri = uri.substring(1);
+		}
+		response.setCharacterEncoding("utf-8");
+        response.setContentType("application/json");
+		String accessToken = AccessTokenUtil.getAccessToken();
+		User user = null;
+		
+		if(StringUtils.isNoneEmpty(accessToken)) {// 刷新登陆有效时间
+			user = (User) redisTemplate.opsForValue().get(accessToken);
+			if(user != null) {
+				redisTemplate.expire(accessToken, CommonConstant.LOGIN_EXPIRE, TimeUnit.SECONDS);
+			}
+		}
+		//非配置路径直接放行
+		List<String> permissionUrlList = permissionMapper.selectAllPermissionUrl();
+		if(!permissionUrlList.contains(uri)) {
+			try {
+				chain.doFilter(request, response);
+			}catch (Exception e) {
+				// TODO: handle exception
+				logger.error("请求异常", e);
+				PrintWriter out = response.getWriter();
+				out.print(JSON.toJSONString(OperationResult.newFailure(CodeMsg.FAILURE)));
+				out.close();
+			}
+			return;
+		}
+		//未登录用户
+		if(StringUtils.isEmpty(accessToken)) {
+			PrintWriter out = response.getWriter();
+			out.print(JSON.toJSONString(OperationResult.newFailure(CodeMsg.LOGIN_PLEASE)));
+			out.close();
+			return;
+		}
+		//用户认证
+		if(user == null) {
+			PrintWriter out = response.getWriter();
+			out.print(JSON.toJSONString(OperationResult.newFailure(CodeMsg.RELOGIN)));
+			out.close();
+			return;
+		}
+		//权限校验
+		List<String> roles = rolePermissionMapper.selectRoleIdByUrl(uri);
+		List<String> userRoles = user.getRoles();
+		boolean rightFlag = false;
+		if(roles!=null && roles.size()>0) {
+			for(String role : roles) {
+				if(userRoles.contains(role)) {
+					rightFlag = true;
+					break;
+				}
+			}
+		}
+		if(!rightFlag) {
+			PrintWriter out = response.getWriter();
+			out.print(JSON.toJSONString(OperationResult.newFailure(CodeMsg.NO_RIGHT)));
+			out.close();
+		}else {
+			try {
+				chain.doFilter(request, response);
+			}catch (Exception e) {
+				// TODO: handle exception
+				logger.error("请求异常", e);
+				PrintWriter out = response.getWriter();
+				out.print(JSON.toJSONString(OperationResult.newFailure(CodeMsg.FAILURE)));
+				out.close();
+			}
+		}
+	}
+
+	@Override
+	public void destroy() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public int getOrder() {
+		// TODO Auto-generated method stub
+		return 1;
+	}
+
+}

+ 22 - 0
src/main/java/com/prac/simple/mapper/DeviceMapper.java

@@ -0,0 +1,22 @@
+package com.prac.simple.mapper;
+
+import java.util.List;
+
+import com.prac.simple.entity.Device;
+import com.prac.simple.entity.req.DeviceReq;
+
+public interface DeviceMapper {
+    int deleteByPrimaryKey(String mac);
+
+    int insert(Device record);
+
+    int insertSelective(Device record);
+
+    Device selectByPrimaryKey(String mac);
+    
+    List<Device> selectDevice(DeviceReq req);
+
+    int updateByPrimaryKeySelective(Device record);
+
+    int updateByPrimaryKey(Device record);
+}

+ 46 - 0
src/main/java/com/prac/simple/mapper/PermissionMapper.java

@@ -0,0 +1,46 @@
+package com.prac.simple.mapper;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
+
+import com.prac.simple.entity.Permission;
+import com.prac.simple.entity.RolePermission;
+import com.prac.simple.entity.req.PermissionReq;
+
+
+public interface PermissionMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(Permission record);
+
+    int insertSelective(Permission record);
+
+    Permission selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(Permission record);
+
+    int updateByPrimaryKey(Permission record);
+    
+    List<Permission> selectPermission(PermissionReq record);
+    
+    List<Permission> selectAllMenu();
+    
+    List<RolePermission> selectRolePermissions();
+    
+    List<Permission> selectPermissionByUserId(String userId);
+    
+    List<Permission> selectPermissionByRoleId(String roleId);
+    
+    List<String> selectAllPermissionUrl();
+    
+    Permission selectPermissionByUrl(String url);
+    
+    Permission selectPermissionByTitle(String title);
+    
+    Permission selectExistPermissionByUrl(@Param("url") String url, @Param("id") String id);
+    
+    List<Permission> selectChildrenPermission(String id);
+    
+    int batchDeletePermission(List<String> ids);
+}

+ 26 - 0
src/main/java/com/prac/simple/mapper/RoleMapper.java

@@ -0,0 +1,26 @@
+package com.prac.simple.mapper;
+
+import java.util.List;
+
+import com.prac.simple.entity.Role;
+import com.prac.simple.entity.req.RoleReq;
+
+public interface RoleMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(Role record);
+
+    int insertSelective(Role record);
+
+    Role selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(Role record);
+
+    int updateByPrimaryKey(Role record);
+    
+    List<Role> selectRoleByUserId(String userId);
+    
+    List<Role> selectAllRole();
+    
+    List<Role> selectRole(RoleReq req);
+}

+ 21 - 0
src/main/java/com/prac/simple/mapper/RolePermissionMapper.java

@@ -0,0 +1,21 @@
+package com.prac.simple.mapper;
+
+import java.util.List;
+
+import com.prac.simple.entity.RolePermission;
+
+public interface RolePermissionMapper {
+    int insert(RolePermission record);
+
+    int insertSelective(RolePermission record);
+    
+    List<String> selectPermissionIdByRoleId(String roleId);
+    
+    int batchDeleteRolePermissionByPermissionId(List<String> ids);
+    
+    int deleteRolePermissionByPermissionId(String id);
+    
+    int deleteRolePermissionByRoleId(String roleId);
+    
+    List<String> selectRoleIdByUrl(String url);
+}

+ 27 - 0
src/main/java/com/prac/simple/mapper/UserMapper.java

@@ -0,0 +1,27 @@
+package com.prac.simple.mapper;
+
+import java.util.List;
+
+import com.prac.simple.entity.User;
+import com.prac.simple.entity.req.UserReq;
+
+public interface UserMapper {
+    int deleteByPrimaryKey(String id);
+
+    int batchDelete(List<String> ids);
+    
+    int insert(User record);
+
+    int insertSelective(User record);
+
+    int updateByPrimaryKeySelective(User record);
+
+    int updateByPrimaryKey(User record);
+    
+    User selectByPrimaryKey(String id);
+    
+    
+    User selectUserByUsername(String userName);
+    
+    List<User> selectUser(UserReq req);
+}

+ 17 - 0
src/main/java/com/prac/simple/mapper/UserRoleMapper.java

@@ -0,0 +1,17 @@
+package com.prac.simple.mapper;
+
+import java.util.List;
+
+import com.prac.simple.entity.UserRole;
+
+public interface UserRoleMapper {
+    int insert(UserRole record);
+
+    int insertSelective(UserRole record);
+    
+    int deleteUserRoleByRoleId(String roleId);
+    
+    int deleteUserRoleByUserId(String userId);
+    
+    List<String> selectRoleIdByUserId(String userId);
+}

+ 27 - 0
src/main/java/com/prac/simple/service/DeviceService.java

@@ -0,0 +1,27 @@
+package com.prac.simple.service;
+
+import java.util.List;
+
+import com.prac.simple.entity.Device;
+import com.prac.simple.entity.req.DeviceReq;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+public interface DeviceService {
+	
+	PageResult<List<Device>> searchDevice(DeviceReq req);
+	
+	OperationResult addDevice(Device record);
+	
+	OperationResult editDevice(Device record);
+	
+	OperationResult deleteDevice(String mac);
+	
+	ServiceResult<Device> getDevice(Device record);
+	
+	OperationResult switchDevice(DeviceReq req);
+	
+	OperationResult changeOpen(String mac,String open);
+
+}

+ 36 - 0
src/main/java/com/prac/simple/service/PermissionService.java

@@ -0,0 +1,36 @@
+package com.prac.simple.service;
+
+import java.util.List;
+
+import com.prac.simple.entity.Permission;
+import com.prac.simple.entity.req.PermissionReq;
+import com.prac.simple.entity.resp.MenuResp;
+import com.prac.simple.entity.resp.PermissionResp;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.ServiceResult;
+
+public interface PermissionService {
+	
+	ServiceResult<List<MenuResp>> listUserMenu();
+	
+	ServiceResult<List<Permission>> listUserPermission();
+	
+	ServiceResult<List<Permission>> listAllPermission();
+	
+	ServiceResult<PermissionResp> permissionDetail(String id);
+	
+	ServiceResult<List<String>> listPermissionIdByRoleId(String roleId);
+	
+	ServiceResult<List<Permission>> listPermission(PermissionReq req);
+	
+	ServiceResult<List<Permission>> listAllMenu();
+	
+	OperationResult addPermission(PermissionReq req);
+	
+	OperationResult editPermission(Permission permission);
+	
+	OperationResult batchDeletePermission(String ids);
+	
+	OperationResult deletePermission(String id);
+	
+}

+ 32 - 0
src/main/java/com/prac/simple/service/RoleService.java

@@ -0,0 +1,32 @@
+package com.prac.simple.service;
+
+import java.util.List;
+
+import com.prac.simple.entity.Role;
+import com.prac.simple.entity.req.EditRolePermissionReq;
+import com.prac.simple.entity.req.EditUserRoleReq;
+import com.prac.simple.entity.req.RoleReq;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+public interface RoleService {
+	
+	ServiceResult<List<Role>> listRole();
+	
+	PageResult<List<Role>> searchRole(RoleReq req);
+	
+	ServiceResult<List<String>> listRoleIdByUser();
+	
+	ServiceResult<Role> getRole(String id);
+	
+	OperationResult addRole(Role role);
+	
+	OperationResult editRole(Role role);
+	
+	OperationResult deleteRole(Role role);
+	
+	OperationResult editUserRole(EditUserRoleReq req);
+	
+	OperationResult authorPermission(EditRolePermissionReq req);
+}

+ 33 - 0
src/main/java/com/prac/simple/service/UserService.java

@@ -0,0 +1,33 @@
+package com.prac.simple.service;
+
+import java.util.List;
+
+import com.prac.simple.entity.User;
+import com.prac.simple.entity.req.EditPasswordReq;
+import com.prac.simple.entity.req.UserReq;
+import com.prac.simple.entity.resp.LoginResp;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+public interface UserService {
+	
+	ServiceResult<LoginResp> login(String username,String password); 
+	
+	OperationResult logout(); 
+	
+	PageResult<List<User>> searchUser(UserReq req);
+	
+	ServiceResult<User> getUser(String id);
+	
+	OperationResult addUser(UserReq userReq);
+	
+	OperationResult editUser(UserReq userReq);
+	
+	OperationResult editPassword(EditPasswordReq req);
+	
+	OperationResult deleteUser(String id);
+	
+	OperationResult bacthDeleteUser(String ids);
+
+}

+ 97 - 0
src/main/java/com/prac/simple/service/impl/DeviceServiceImpl.java

@@ -0,0 +1,97 @@
+package com.prac.simple.service.impl;
+
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.prac.simple.constant.CodeMsg;
+import com.prac.simple.constant.CommonConstant;
+import com.prac.simple.entity.Device;
+import com.prac.simple.entity.req.DeviceReq;
+import com.prac.simple.mapper.DeviceMapper;
+import com.prac.simple.service.DeviceService;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+@Service
+public class DeviceServiceImpl implements DeviceService {
+
+	@Autowired
+	DeviceMapper deviceMapper;
+	
+	
+	@Override
+	public PageResult<List<Device>> searchDevice(DeviceReq req) {
+		// TODO Auto-generated method stub
+		Page<Object> page = PageHelper.startPage(req.getPageNum(), req.getPageSize());
+		List<Device> list = deviceMapper.selectDevice(req);
+		PageResult<List<Device>> result = PageResult.newSuccess(list);
+		result.setTotal((int) page.getTotal());
+		return result;
+	}
+
+	@Override
+	public OperationResult addDevice(Device record) {
+		// TODO Auto-generated method stub
+		Device existD = deviceMapper.selectByPrimaryKey(record.getMac());
+		if(existD != null) {
+			return OperationResult.newFailure(CodeMsg.DEVICE_EXIST);
+		}
+		record.setOpen(CommonConstant.DEVICE_OFF);
+		Date now = new Date();
+		record.setCreatetime(now);
+		record.setModifytime(now);
+		deviceMapper.insertSelective(record);
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public OperationResult editDevice(Device record) {
+		// TODO Auto-generated method stub
+		record.setModifytime(new Date());
+		deviceMapper.updateByPrimaryKeySelective(record);
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public OperationResult deleteDevice(String mac) {
+		// TODO Auto-generated method stub
+		deviceMapper.deleteByPrimaryKey(mac);
+		return OperationResult.newSuccess();
+	}
+	
+	@Override
+	public ServiceResult<Device> getDevice(Device record) {
+		// TODO Auto-generated method stub
+		Device device = deviceMapper.selectByPrimaryKey(record.getMac());
+		return ServiceResult.newSuccess(device);
+	}
+
+	@Override
+	public OperationResult switchDevice(DeviceReq req) {
+		// TODO Auto-generated method stub
+		Device device = new Device();
+		device.setMac(req.getMac());
+		device.setOpen(req.getOpen());
+		deviceMapper.updateByPrimaryKeySelective(device);
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public OperationResult changeOpen(String mac, String open) {
+		// TODO Auto-generated method stub
+		Device device = new Device();
+		device.setMac(mac);
+		device.setOpen(open);
+		deviceMapper.updateByPrimaryKeySelective(device);
+		return OperationResult.newSuccess();
+	}
+
+	
+
+}

+ 234 - 0
src/main/java/com/prac/simple/service/impl/PermissionServiceImpl.java

@@ -0,0 +1,234 @@
+package com.prac.simple.service.impl;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.prac.simple.constant.CodeMsg;
+import com.prac.simple.constant.CommonConstant;
+import com.prac.simple.entity.Permission;
+import com.prac.simple.entity.User;
+import com.prac.simple.entity.req.PermissionReq;
+import com.prac.simple.entity.resp.MenuResp;
+import com.prac.simple.entity.resp.PermissionResp;
+import com.prac.simple.mapper.PermissionMapper;
+import com.prac.simple.mapper.RolePermissionMapper;
+import com.prac.simple.service.PermissionService;
+import com.prac.simple.util.AccessTokenUtil;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.ServiceResult;
+
+@Service
+public class PermissionServiceImpl implements PermissionService{
+
+	@Autowired
+	private PermissionMapper permissionMapper;
+	
+	@Autowired
+	private RolePermissionMapper rolePermissionMapper;
+	
+		
+	@Override
+	public ServiceResult<List<MenuResp>> listUserMenu() {
+		// TODO Auto-generated method stub
+		User user = AccessTokenUtil.getUser();
+		if(user == null) {
+			return ServiceResult.newFailure(CodeMsg.LOGIN_PLEASE);
+		}
+		List<Permission> permissions=permissionMapper.selectPermissionByUserId(user.getId());
+		MenuResp topMenu = new MenuResp();
+		topMenu.setId("0");
+		topMenu.setOrders(0);
+		formatMenu(permissions,topMenu);
+		return ServiceResult.newSuccess(topMenu.getChildren());
+	}
+	
+	
+	/**
+	 * @Description 封装菜单
+	 * @author wulianwei
+	 * @Date 2020年5月15日
+	 */
+	private void formatMenu(List<Permission> permissions,MenuResp menu) {
+		for(Permission p : permissions) {
+			if(p.getPid().equals(menu.getId())) {
+				MenuResp child = new MenuResp();
+				BeanUtils.copyProperties(p, child);
+				menu.getChildren().add(child);
+			}
+		}
+		if(menu.getChildren().size() == 0) {
+			return;
+		}
+		
+		menu.setChildren(menu.getChildren().stream().sorted(Comparator.comparing(MenuResp::getOrders)).collect(Collectors.toList()));
+		for(MenuResp child : menu.getChildren()) {
+			formatMenu(permissions,child);
+		}
+	}
+	
+	@Override
+	public ServiceResult<List<Permission>> listUserPermission(){
+		User user = AccessTokenUtil.getUser();
+		if(user == null) {
+			return ServiceResult.newFailure(CodeMsg.LOGIN_PLEASE);
+		}
+		List<Permission> permissions=permissionMapper.selectPermissionByUserId(user.getId());
+		return ServiceResult.newSuccess(permissions);
+	}
+	@Override
+	public ServiceResult<PermissionResp> permissionDetail(String id) {
+		// TODO Auto-generated method stub
+		Permission permission = permissionMapper.selectByPrimaryKey(id);
+		PermissionResp resp = new PermissionResp();
+		BeanUtils.copyProperties(permission, resp);
+		if(CommonConstant.PERMISSION_TYPE_SUBMENU.equals(permission.getType())) {
+			permission = permissionMapper.selectByPrimaryKey(permission.getPid());
+			resp.setMainMenu(permission.getPid());
+			resp.setMainMenuName(permission.getTitle());
+		}else if(CommonConstant.PERMISSION_TYPE_BUTTON.equals(permission.getType())) {
+			permission = permissionMapper.selectByPrimaryKey(permission.getPid());
+			resp.setSubMenu(permission.getPid());
+			resp.setSubMenuName(permission.getTitle());
+			
+			permission = permissionMapper.selectByPrimaryKey(permission.getPid());
+			resp.setMainMenu(permission.getPid());
+			resp.setMainMenuName(permission.getTitle());
+		}
+		return ServiceResult.newSuccess(resp);
+	}
+	
+	@Override
+	public ServiceResult<List<String>> listPermissionIdByRoleId(String roleId) {
+		// TODO Auto-generated method stub
+		return ServiceResult.newSuccess(rolePermissionMapper.selectPermissionIdByRoleId(roleId));
+	}
+	
+	@Override
+	@Transactional
+	public OperationResult addPermission(PermissionReq req) {
+		// TODO Auto-generated method stub
+		if(!CommonConstant.PERMISSION_TYPE_MAINMENU.equals(req.getType())) {
+			Permission existPermission = permissionMapper.selectPermissionByUrl(req.getUrl());
+			if(existPermission != null) {
+				return OperationResult.newFailure(CodeMsg.PERMISSION_EXIST);
+			}
+		}
+		if(!StringUtils.isEmpty(req.getTitle())) {
+			Permission exist = permissionMapper.selectPermissionByTitle(req.getTitle());
+			if(exist != null &&!exist.getId().equals(req.getId()) ) {
+				return  OperationResult.newFailure(CodeMsg.PERMISSION_EXIST);
+			}
+		}
+		switch (req.getType()) {
+		case CommonConstant.PERMISSION_TYPE_MAINMENU:
+			req.setPid(CommonConstant.ZERO.toString());
+			break;
+		case CommonConstant.PERMISSION_TYPE_SUBMENU:
+			req.setPid(req.getMainMenu());
+			break;
+		case CommonConstant.PERMISSION_TYPE_BUTTON:
+			req.setPid(req.getSubMenu());
+			break;
+		}
+		Permission permission = new Permission();
+		BeanUtils.copyProperties(req, permission);
+		permissionMapper.insertSelective(permission);
+//		existPermission = permissionMapper.selectPermissionByUrl(permission.getUrl());
+//		RolePermission rolePermission = new RolePermission();
+//		rolePermission.setRoleId(CommonConstant.ROLE_MANAGER);
+//		rolePermission.setPermissionId(existPermission.getId());
+//		rolePermissionMapper.insert(rolePermission);
+		return OperationResult.newSuccess();
+	}
+
+
+	@Override
+	public OperationResult editPermission(Permission req) {
+		// TODO Auto-generated method stub
+		if(!StringUtils.isEmpty(req.getUrl())) {
+			Permission exist = permissionMapper.selectPermissionByUrl(req.getUrl());
+			if(exist != null &&!exist.getId().equals(req.getId()) ) {
+				return  OperationResult.newFailure(CodeMsg.PERMISSION_EXIST);
+			}
+		}
+		if(!StringUtils.isEmpty(req.getTitle())) {
+			Permission exist = permissionMapper.selectPermissionByTitle(req.getTitle());
+			if(exist != null &&!exist.getId().equals(req.getId()) ) {
+				return  OperationResult.newFailure(CodeMsg.PERMISSION_EXIST);
+			}
+		}
+		
+		permissionMapper.updateByPrimaryKeySelective(req);
+		return OperationResult.newSuccess();
+	}
+
+
+	@Override
+	@Transactional
+	public OperationResult batchDeletePermission(String ids) {
+		// TODO Auto-generated method stub
+//		permissionMapper.deleteByPrimaryKey(id)
+		List<String> idList =  Arrays.asList(ids.split(","));
+		for(String id : idList) {
+			List<Permission> children = permissionMapper.selectChildrenPermission(id);
+			if(children.size() > 0) {
+				Permission permission = permissionMapper.selectByPrimaryKey(id);
+				return OperationResult.newFailure(permission.getTitle()+"包含子功能,无法删除");
+			}
+		}
+		permissionMapper.batchDeletePermission(idList);
+		rolePermissionMapper.batchDeleteRolePermissionByPermissionId(idList);
+		return OperationResult.newSuccess();
+	}
+	
+	@Override
+	@Transactional
+	public OperationResult deletePermission(String id) {
+		// TODO Auto-generated method stub
+		List<Permission> children = permissionMapper.selectChildrenPermission(id);
+		if(children.size() > 0) {
+			return OperationResult.newFailure(CodeMsg.CHILDREN_PERMISSION_EXIST);
+		}
+		permissionMapper.deleteByPrimaryKey(id);
+		rolePermissionMapper.deleteRolePermissionByPermissionId(id);
+		return OperationResult.newSuccess();
+	}
+
+
+
+
+	@Override
+	public ServiceResult<List<Permission>> listAllPermission() {
+		// TODO Auto-generated method stub
+		List<Permission> permission = permissionMapper.selectPermission(null);
+		return ServiceResult.newSuccess(permission);
+	}
+
+
+	@Override
+	public ServiceResult<List<Permission>> listPermission(PermissionReq req) {
+		// TODO Auto-generated method stub
+		List<Permission> persmissons = permissionMapper.selectPermission(req);
+		return ServiceResult.newSuccess(persmissons);
+	}
+
+
+	@Override
+	public ServiceResult<List<Permission>> listAllMenu() {
+		// TODO Auto-generated method stub
+		List<Permission> persmissons = permissionMapper.selectAllMenu();
+		return ServiceResult.newSuccess(persmissons);
+	}
+
+
+	
+	
+}

+ 130 - 0
src/main/java/com/prac/simple/service/impl/RoleServiceImpl.java

@@ -0,0 +1,130 @@
+package com.prac.simple.service.impl;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.prac.simple.constant.CodeMsg;
+import com.prac.simple.entity.Role;
+import com.prac.simple.entity.RolePermission;
+import com.prac.simple.entity.User;
+import com.prac.simple.entity.UserRole;
+import com.prac.simple.entity.req.EditRolePermissionReq;
+import com.prac.simple.entity.req.EditUserRoleReq;
+import com.prac.simple.entity.req.RoleReq;
+import com.prac.simple.mapper.RoleMapper;
+import com.prac.simple.mapper.RolePermissionMapper;
+import com.prac.simple.mapper.UserRoleMapper;
+import com.prac.simple.service.RoleService;
+import com.prac.simple.util.AccessTokenUtil;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+
+@Service
+public class RoleServiceImpl implements RoleService{
+	
+	@Autowired
+	RoleMapper roleMapper;
+	
+	@Autowired
+	RolePermissionMapper rolePermissionMapper;
+	
+	@Autowired
+	UserRoleMapper userRoleMapper;
+
+	@Override
+	public ServiceResult<List<Role>> listRole() {
+		// TODO Auto-generated method stub
+		return ServiceResult.newSuccess(roleMapper.selectAllRole());
+	}
+	
+	@Override
+	public ServiceResult<List<String>> listRoleIdByUser() {
+		// TODO Auto-generated method stub
+		User user = AccessTokenUtil.getUser();
+		if(user == null) {
+			return ServiceResult.newFailure(CodeMsg.LOGIN_PLEASE);
+		}
+		List<String> roleIds = userRoleMapper.selectRoleIdByUserId(user.getId());
+		return ServiceResult.newSuccess(roleIds);
+	}
+
+	@Override
+	public OperationResult addRole(Role role) {
+		// TODO Auto-generated method stub
+		Role existRole = roleMapper.selectByPrimaryKey(role.getId());
+		if(existRole != null) {
+			return OperationResult.newFailure(CodeMsg.ROLE_EXIST);
+		}
+		roleMapper.insert(role);
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public OperationResult editRole(Role role) {
+		// TODO Auto-generated method stub
+		roleMapper.updateByPrimaryKey(role);
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	@Transactional
+	public OperationResult deleteRole(Role role) {
+		// TODO Auto-generated method stub
+		roleMapper.deleteByPrimaryKey(role.getId());
+		rolePermissionMapper.deleteRolePermissionByRoleId(role.getId());
+		userRoleMapper.deleteUserRoleByRoleId(role.getId());
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	@Transactional
+	public OperationResult editUserRole(EditUserRoleReq req) {
+		// TODO Auto-generated method stub
+		userRoleMapper.deleteUserRoleByUserId(req.getUserId());
+		for(String roleId : req.getRoleIds()) {
+			UserRole record = new UserRole();
+			record.setUserId(req.getUserId());
+			record.setRoleId(roleId);
+			userRoleMapper.insert(record);
+		}
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public PageResult<List<Role>> searchRole(RoleReq req) {
+		// TODO Auto-generated method stub
+		Page<Object> page = PageHelper.startPage(req.getPageNum(),req.getPageSize());
+		List<Role> roles = roleMapper.selectRole(req);
+		PageResult<List<Role>> result = PageResult.newSuccess(roles); 
+		result.setTotal((int) page.getTotal());
+		return result;
+	}
+
+	@Override
+	public ServiceResult<Role> getRole(String id) {
+		// TODO Auto-generated method stub
+		Role role = roleMapper.selectByPrimaryKey(id);
+		return ServiceResult.newSuccess(role);
+	}
+
+	@Override
+	@Transactional
+	public OperationResult authorPermission(EditRolePermissionReq req) {
+		// TODO Auto-generated method stub
+		rolePermissionMapper.deleteRolePermissionByRoleId(req.getRoleId());
+		for(String permissionId : req.getPermissionIds()) {
+			RolePermission record = new RolePermission();
+			record.setRoleId(req.getRoleId());
+			record.setPermissionId(permissionId);
+			rolePermissionMapper.insert(record);
+		}
+		return OperationResult.newSuccess();
+	}
+
+}

+ 202 - 0
src/main/java/com/prac/simple/service/impl/UserServiceImpl.java

@@ -0,0 +1,202 @@
+package com.prac.simple.service.impl;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.prac.simple.constant.CodeMsg;
+import com.prac.simple.constant.CommonConstant;
+import com.prac.simple.entity.Role;
+import com.prac.simple.entity.User;
+import com.prac.simple.entity.UserRole;
+import com.prac.simple.entity.req.EditPasswordReq;
+import com.prac.simple.entity.req.UserReq;
+import com.prac.simple.entity.resp.LoginResp;
+import com.prac.simple.mapper.RoleMapper;
+import com.prac.simple.mapper.UserMapper;
+import com.prac.simple.mapper.UserRoleMapper;
+import com.prac.simple.service.UserService;
+import com.prac.simple.util.AccessTokenUtil;
+import com.prac.simple.util.MD5Util;
+import com.prac.simple.util.OperationResult;
+import com.prac.simple.util.PageResult;
+import com.prac.simple.util.ServiceResult;
+import com.prac.simple.util.UUIDUtil;
+
+@Service
+public class UserServiceImpl implements UserService{
+
+	@Autowired
+	UserMapper userMapper;
+	
+	@Autowired
+	RoleMapper roleMapper;
+	
+	@Autowired
+	UserRoleMapper userRoleMapper;
+	
+	@Autowired
+	RedisTemplate<String, Object> redisTemplate;
+	
+	@Override
+	public ServiceResult<LoginResp> login(String username,String password) {
+		// TODO Auto-generated method stub
+		User loginUser = userMapper.selectUserByUsername(username);
+		if(loginUser == null) {
+			return ServiceResult.newFailure(CodeMsg.USERNAME_WRONG);
+		}
+		if(!MD5Util.encode32(password).equals(loginUser.getPassword())) {
+			return ServiceResult.newFailure(CodeMsg.PASSWORD_WRONG);
+		}
+		List<Role> roles = roleMapper.selectRoleByUserId(loginUser.getId());
+		List<String> roleIds = roles.stream().map(Role::getId).collect(Collectors.toList());
+		loginUser.setRoles(roleIds);
+		String token = UUIDUtil.getUUID();
+		redisTemplate.opsForValue().set(token, loginUser,CommonConstant.LOGIN_EXPIRE,TimeUnit.SECONDS);
+		//跟新登录时间
+		User user = new User();
+		user.setId(loginUser.getId());
+		user.setLasttime(new Date());
+		userMapper.updateByPrimaryKeySelective(user);
+		//返回登录结果
+		LoginResp resp = new LoginResp();
+		resp.setId(loginUser.getId());
+		resp.setUsername(username);
+		resp.setRoles(roleIds);
+		resp.setToken(token);
+		ServiceResult<LoginResp> result = ServiceResult.newSuccess(resp);
+		result.setMsg(CodeMsg.LOGINSUCCESS.getMessage());
+		return result;
+	}
+	
+	@Override
+	public OperationResult logout() {
+		String token = AccessTokenUtil.getAccessToken();
+		if(StringUtils.isNoneEmpty(token)) {
+			redisTemplate.delete(token);
+		}
+		return OperationResult.newSuccess();
+	}
+	
+	@Override
+	public PageResult<List<User>> searchUser(UserReq req) {
+		// TODO Auto-generated method stub
+		Page<Object> page = PageHelper.startPage(req.getPageNum(), req.getPageSize());
+		List<User> users = userMapper.selectUser(req);
+		PageResult<List<User>> userResult = PageResult.newSuccess(users);
+		userResult.setTotal((int) page.getTotal());
+		return userResult;
+	}
+
+	@Override
+	@Transactional
+	public OperationResult addUser(UserReq userReq) {
+		// TODO Auto-generated method stub
+		User existUser = userMapper.selectUserByUsername(userReq.getUsername());
+		if(existUser != null) {
+			return OperationResult.newFailure(CodeMsg.USER_EXIST);
+		}
+		User user = new User();
+		BeanUtils.copyProperties(userReq, user);
+		user.setId(UUIDUtil.get32UUID());
+		user.setPassword(MD5Util.encode32(user.getPassword()));
+		user.setCreatetime(new Date());
+		userMapper.insertSelective(user);
+		if(StringUtils.isNotEmpty(userReq.getRoleIds())) {
+			UserRole ur = new UserRole();
+			for(String roleId : userReq.getRoleIds().split(",")) {
+				ur.setUserId(user.getId());
+				ur.setRoleId(roleId);
+				userRoleMapper.insert(ur);
+			}
+		}
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public OperationResult editUser(UserReq userReq) {
+		// TODO Auto-generated method stub
+		User existUser = userMapper.selectByPrimaryKey(userReq.getId());
+		if(existUser == null) {
+			return OperationResult.newFailure(CodeMsg.USER_NO_EXIST);
+		}
+		if(!StringUtils.isEmpty(userReq.getPassword())){
+			userReq.setPassword(MD5Util.encode32(userReq.getPassword()));
+		}
+		userReq.setUsername(null);//不允许修改用户名
+		User user = new User();
+		BeanUtils.copyProperties(userReq, user);
+		userMapper.updateByPrimaryKeySelective(user);
+		if(StringUtils.isNotEmpty(userReq.getRoleIds())) {
+			userRoleMapper.deleteUserRoleByUserId(user.getId());
+			UserRole ur = new UserRole();
+			for(String roleId : userReq.getRoleIds().split(",")) {
+				ur.setUserId(user.getId());
+				ur.setRoleId(roleId);
+				userRoleMapper.insert(ur);
+			}
+		}
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public OperationResult bacthDeleteUser(String ids) {
+		// TODO Auto-generated method stub
+		if(StringUtils.isNotEmpty(ids)) {
+			List<String> idList = Arrays.asList(ids.split(","));
+			userMapper.batchDelete(idList);
+			for(String id : idList) {
+				userRoleMapper.deleteUserRoleByUserId(id);
+			}
+		}
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	@Transactional
+	public OperationResult deleteUser(String id) {
+		// TODO Auto-generated method stub
+		userMapper.deleteByPrimaryKey(id);
+		userRoleMapper.deleteUserRoleByUserId(id);
+		return OperationResult.newSuccess();
+	}
+
+	@Override
+	public ServiceResult<User> getUser(String id) {
+		// TODO Auto-generated method stub
+		User user = userMapper.selectByPrimaryKey(id);
+		List<String> roles = userRoleMapper.selectRoleIdByUserId(id);
+		user.setRoles(roles);
+		return ServiceResult.newSuccess(user);
+	}
+
+	@Override
+	public OperationResult editPassword(EditPasswordReq req) {
+		// TODO Auto-generated method stub
+		User user = AccessTokenUtil.getUser();
+		if(user == null) {
+			return OperationResult.newFailure(CodeMsg.LOGIN_PLEASE);
+		}
+		if(!user.getPassword().equals(MD5Util.encode32(req.getOldPassword()))) {
+			return OperationResult.newFailure(CodeMsg.OLDPASSWORD_WRONG);
+		}
+		User editUser = new User();
+		editUser.setId(user.getId());
+		editUser.setPassword(MD5Util.encode32(req.getNewPassword()));
+		user.setPassword(MD5Util.encode32(req.getNewPassword()));
+		userMapper.updateByPrimaryKeySelective(editUser);
+		return OperationResult.newSuccess();
+	}
+	
+}

+ 26 - 0
src/main/java/com/prac/simple/util/AccessTokenUtil.java

@@ -0,0 +1,26 @@
+package com.prac.simple.util;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import com.prac.simple.entity.User;
+
+public class AccessTokenUtil {
+	
+	public static String getAccessToken() {
+		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+		HttpServletRequest request = requestAttributes.getRequest();
+		String token = request.getHeader("accessToken");
+		return token;
+	}
+	
+	public static User getUser() {
+		@SuppressWarnings("unchecked")
+		RedisTemplate<String, Object> redisTemplate = (RedisTemplate<String, Object>) SpringUtil.getBean("redisTemplate");
+		User user = (User) redisTemplate.opsForValue().get(getAccessToken());
+		return user;
+	}
+}

+ 46 - 0
src/main/java/com/prac/simple/util/MD5Util.java

@@ -0,0 +1,46 @@
+package com.prac.simple.util;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * MD5加密工具
+ *
+ */
+public class MD5Util {
+
+	public static String encode32(String sourceStr) {
+		String result = "";
+		try {
+			MessageDigest md = MessageDigest.getInstance("MD5");
+			md.update(sourceStr.getBytes());
+			byte b[] = md.digest();
+			int i;
+			StringBuffer buf = new StringBuffer("");
+			for (int offset = 0; offset < b.length; offset++) {
+				i = b[offset];
+				if (i < 0) {
+					i += 256;
+				}
+				if (i < 16) {
+					buf.append("0");
+				}
+				buf.append(Integer.toHexString(i));
+			}
+			result = buf.toString();
+		} catch (NoSuchAlgorithmException e) {
+			System.out.println(e.getMessage());
+		}
+		return result;
+	}
+
+	public static String encode16(String sourceStr) {
+		return MD5Util.encode32(sourceStr).substring(8, 24);
+	}
+	
+	public static void main(String[] args) {
+		String code = encode32("123456");
+		System.out.println(code);
+	}
+
+}

+ 115 - 0
src/main/java/com/prac/simple/util/OperationResult.java

@@ -0,0 +1,115 @@
+package com.prac.simple.util;
+
+import java.io.Serializable;
+
+import com.prac.simple.constant.CodeMsg;
+
+/**
+ * @date 2018/07/16 操作类返回参数
+ */
+public class OperationResult  implements Serializable{
+
+    /**  */
+    private static final long serialVersionUID = 1L;
+    private Integer code;
+    private String msg;
+
+    /**
+     * 
+     */
+    public OperationResult() {
+        super();
+    }
+
+    public OperationResult(CodeMsg cm) {
+        if (cm == null) {
+            return;
+        }
+        this.code = cm.getRetCode();
+        this.msg = cm.getMessage();
+    }
+
+    /**
+     * 成功时候的调用
+     */
+    public static  OperationResult newSuccess() {
+        OperationResult rlt = new OperationResult(CodeMsg.SUCCESS);
+        return rlt;
+    }
+
+    /**
+     * 失败时候的调用
+     */
+    public static  OperationResult newFailure(CodeMsg cm) {
+        return new OperationResult(cm);
+    }
+    
+    public static  OperationResult newFailure(String msg){
+    	CodeMsg  cm=new CodeMsg(CodeMsg.FAILED_CODE, msg);
+    	return newFailure(cm);
+    }
+
+    /**
+     * 失败时候的调用,扩展消息参数
+     */
+    public static  OperationResult newFailure(CodeMsg cm, String msg) {
+        cm.setMessage(cm.getMessage() + "--" + msg);
+        return new OperationResult(cm);
+    }
+
+    /**
+     * Getter method for property <tt>code</tt>.
+     * 
+     * @return property value of code
+     */
+    public Integer getCode() {
+        return code;
+    }
+
+    /**
+     * 判断返回结果是否成功
+     */
+    public boolean success() {
+        return CodeMsg.SUCCESS_CODE == code;
+    }
+
+    /**
+     * Setter method for property <tt>code</tt>.
+     * 
+     * @param code value to be assigned to property code
+     */
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
+    /**
+     * Getter method for property <tt>msg</tt>.
+     * 
+     * @return property value of msg
+     */
+    public String getMsg() {
+        return msg;
+    }
+
+    /**
+     * Setter method for property <tt>msg</tt>.
+     * 
+     * @param msg value to be assigned to property msg
+     */
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "OperationResult [code=" + code + ", msg=" + msg + "]";
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+
+}

+ 152 - 0
src/main/java/com/prac/simple/util/PageResult.java

@@ -0,0 +1,152 @@
+package com.prac.simple.util;
+
+import java.io.Serializable;
+
+import com.prac.simple.constant.CodeMsg;
+
+public class PageResult<T> implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	private Integer code;
+	private String msg;
+	private Integer total;
+	private T data;
+
+	public PageResult() {
+		super();
+	}
+
+	public PageResult(CodeMsg cm) {
+		if (cm == null) {
+			return;
+		}
+		this.code = cm.getRetCode();
+		this.msg = cm.getMessage();
+	}
+
+	private PageResult(T data) {
+		this.code = CodeMsg.SUCCESS_CODE;
+		this.msg = CodeMsg.SUCCESS_DESC;
+		this.data = data;
+	}
+
+	/**
+	 * 成功时候的调用
+	 */
+	public static <T> PageResult<T> newSuccess(T data) {
+		return new PageResult<T>(data);
+	}
+
+	/**
+	 * 成功,传入成功提示
+	 */
+	public static <T> PageResult<T> newSuccess(CodeMsg cm) {
+		return new PageResult<T>(cm);
+	}
+	
+	/**
+	 * 成功,不需要传入参数
+	 */
+	@SuppressWarnings("unchecked")
+	public static <T> PageResult<T> newSuccess() {
+		return (PageResult<T>) newSuccess("");
+	}
+
+	/**
+	 * 失败时候的调用
+	 */
+	public static <T> PageResult<T> newFailure(CodeMsg cm) {
+		return new PageResult<T>(cm);
+	}
+
+	/**
+	 * 失败时候的调用,扩展消息参数
+	 */
+	public static <T> PageResult<T> newFailure(CodeMsg cm, String msg) {
+		cm.setMessage(cm.getMessage() + "--" + msg);
+		return new PageResult<T>(cm);
+	}
+
+	/**
+	 * 失败时候的调用,扩展消息参数
+	 */
+	public static <T> PageResult<T> newFailure(String msg) {
+		CodeMsg cm = new CodeMsg(CodeMsg.FAILED_CODE, msg);
+		return new PageResult<T>(cm);
+	}
+
+	/**
+	 * 判断返回结果是否成功
+	 */
+	public boolean success() {
+		return CodeMsg.SUCCESS_CODE == code;
+	}
+
+	/**
+	 * Getter method for property <tt>code</tt>.
+	 * 
+	 * @return property value of code
+	 */
+	public Integer getCode() {
+		return code;
+	}
+
+	/**
+	 * Setter method for property <tt>code</tt>.
+	 * 
+	 * @param code value to be assigned to property code
+	 */
+	public void setCode(Integer code) {
+		this.code = code;
+	}
+
+	/**
+	 * Getter method for property <tt>msg</tt>.
+	 * 
+	 * @return property value of msg
+	 */
+	public String getMsg() {
+		return msg;
+	}
+
+	/**
+	 * Setter method for property <tt>msg</tt>.
+	 * 
+	 * @param msg value to be assigned to property msg
+	 */
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
+
+	/**
+	 * Getter method for property <tt>data</tt>.
+	 * 
+	 * @return property value of data
+	 */
+	public T getData() {
+		return data;
+	}
+
+	/**
+	 * Setter method for property <tt>data</tt>.
+	 * 
+	 * @param data value to be assigned to property data
+	 */
+	public void setData(T data) {
+		this.data = data;
+	}
+
+	public Integer getTotal() {
+		return total;
+	}
+
+	public void setTotal(Integer total) {
+		this.total = total;
+	}
+
+	@Override
+	public String toString() {
+		return "PageResult [code=" + code + ", msg=" + msg + ", total=" + total + ", data=" + data + "]";
+	}
+
+}

+ 150 - 0
src/main/java/com/prac/simple/util/ServiceResult.java

@@ -0,0 +1,150 @@
+package com.prac.simple.util;
+
+import java.io.Serializable;
+
+import com.prac.simple.constant.CodeMsg;
+
+public class ServiceResult<T> implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	private Integer code;
+	private String msg;
+	private T data;
+
+	public ServiceResult() {
+		super();
+	}
+
+	public ServiceResult(CodeMsg cm) {
+		if (cm == null) {
+			return;
+		}
+		this.code = cm.getRetCode();
+		this.msg = cm.getMessage();
+	}
+
+	private ServiceResult(T data) {
+		this.code = CodeMsg.SUCCESS_CODE;
+		this.msg = CodeMsg.SUCCESS_DESC;
+		this.data = data;
+	}
+
+	/**
+	 * 成功时候的调用
+	 */
+	public static <T> ServiceResult<T> newSuccess(T data) {
+		return new ServiceResult<T>(data);
+	}
+
+	/**
+	 * 成功,传入成功提示
+	 */
+	public static <T> ServiceResult<T> newSuccess(CodeMsg cm) {
+		return new ServiceResult<T>(cm);
+	}
+	
+	/**
+	 * 成功,不需要传入参数
+	 */
+	@SuppressWarnings("unchecked")
+	public static <T> ServiceResult<T> newSuccess() {
+		return (ServiceResult<T>) newSuccess("");
+	}
+
+	/**
+	 * 失败时候的调用
+	 */
+	public static <T> ServiceResult<T> newFailure(CodeMsg cm) {
+		return new ServiceResult<T>(cm);
+	}
+
+	/**
+	 * 失败时候的调用,扩展消息参数
+	 */
+	public static <T> ServiceResult<T> newFailure(CodeMsg cm, String msg) {
+		cm.setMessage(cm.getMessage() + "--" + msg);
+		return new ServiceResult<T>(cm);
+	}
+
+	/**
+	 * 失败时候的调用,扩展消息参数
+	 */
+	public static <T> ServiceResult<T> newFailure(String msg) {
+		CodeMsg cm = new CodeMsg(CodeMsg.FAILED_CODE, msg);
+		return new ServiceResult<T>(cm);
+	}
+
+	/**
+	 * 判断返回结果是否成功
+	 */
+	public boolean success() {
+		return CodeMsg.SUCCESS_CODE == code;
+	}
+
+	/**
+	 * Getter method for property <tt>code</tt>.
+	 * 
+	 * @return property value of code
+	 */
+	public Integer getCode() {
+		return code;
+	}
+
+	/**
+	 * Setter method for property <tt>code</tt>.
+	 * 
+	 * @param code value to be assigned to property code
+	 */
+	public void setCode(Integer code) {
+		this.code = code;
+	}
+
+	/**
+	 * Getter method for property <tt>msg</tt>.
+	 * 
+	 * @return property value of msg
+	 */
+	public String getMsg() {
+		return msg;
+	}
+
+	/**
+	 * Setter method for property <tt>msg</tt>.
+	 * 
+	 * @param msg value to be assigned to property msg
+	 */
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
+
+	/**
+	 * Getter method for property <tt>data</tt>.
+	 * 
+	 * @return property value of data
+	 */
+	public T getData() {
+		return data;
+	}
+
+	/**
+	 * Setter method for property <tt>data</tt>.
+	 * 
+	 * @param data value to be assigned to property data
+	 */
+	public void setData(T data) {
+		this.data = data;
+	}
+
+	/**
+	 * @see java.lang.Object#toString()
+	 */
+	@Override
+	public String toString() {
+		return "ServiceResult [code=" + code + ", msg=" + msg + ", data=" + data + "]";
+	}
+
+	/**
+	 * @see java.lang.Object#toString()
+	 */
+
+}

+ 34 - 0
src/main/java/com/prac/simple/util/SpringUtil.java

@@ -0,0 +1,34 @@
+package com.prac.simple.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringUtil implements ApplicationContextAware{
+
+    private static ApplicationContext applicationContext;
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        if (SpringUtil.applicationContext == null) {
+            SpringUtil.applicationContext = applicationContext;
+        }
+    }
+
+    public static ApplicationContext getApplicationContext(){
+        return applicationContext;
+    }
+
+
+    public static Object getBean(String name) {
+        return applicationContext.getBean(name);
+    }
+
+
+    public static <T> T getBean(Class<T> clazz) {
+        return applicationContext.getBean(clazz);
+    }
+
+}

+ 15 - 0
src/main/java/com/prac/simple/util/UUIDUtil.java

@@ -0,0 +1,15 @@
+package com.prac.simple.util;
+
+import java.util.UUID;
+
+public class UUIDUtil {
+
+	public static String getUUID() {
+		return UUID.randomUUID().toString();
+	}
+	
+	public static String get32UUID() {
+		return UUID.randomUUID().toString().trim().replaceAll("-", "");
+	}
+	
+}

+ 83 - 0
src/main/resources/application.yml

@@ -0,0 +1,83 @@
+server:
+  port: 8181
+spring:
+  profiles:
+      active: dev
+  application:
+    name: simple-service
+  jackson:
+    time-zone: GMT+8
+    date-format: yyyy-MM-dd HH:mm:ss
+    
+mybatis:
+  mapper-locations: classpath:mapper/*.xml
+  type-aliases-package: com.prac.simple.entity  
+  
+#开发环境
+---
+spring:
+  profiles: dev
+  datasource:
+    url: jdbc:mysql://localhost:3306/simple?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
+    username: root
+    password: 1qaz!QAZ
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    # 连接池配置
+    druid:
+      # 初始化大小,最小,最大
+      initial-size: 5
+      min-idle: 5
+      max-active: 20
+      # 配置获取连接等待超时的时间
+      max-wait: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位毫秒
+      time-between-eviction-runs-millis: 60000
+      # 配置一个连接在池中最小生存时间
+      min-evictable-idle-time-millis: 300000
+      validation-query: SELECT 1r
+      test-while-idle: true
+      test-on-borrow: false
+      test-on-return: false
+      # 打开 PSCache,并且指定每个连接上 PSCache 的大小
+      pool-prepared-statements: true
+      max-pool-prepared-statement-per-connection-size: 20
+      # 配置监控统计拦截的 Filter,去掉后监控界面 SQL 无法统计,wall 用于防火墙
+      filters: stat,wall,slf4j
+      # 通过 connection-properties 属性打开 mergeSql 功能;慢 SQL 记录
+      connection-properties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
+      # 配置 DruidStatFilter
+      web-stat-filter:
+        enabled: true
+        url-pattern: /*
+        exclusions: .js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*
+      # 配置 DruidStatViewServlet
+      stat-view-servlet:
+        url-pattern: /druid/*
+        # IP 白名单,没有配置或者为空,则允许所有访问
+        allow: 127.0.0.1
+        # IP 黑名单,若白名单也存在,则优先使用
+        deny: 192.168.31.253
+        # 禁用 HTML 中 Reset All 按钮
+        reset-enable: false
+        # 登录用户名/密码
+        login-username: root
+        login-password: 123
+  redis:
+    database: 0
+    host: 127.0.0.1
+    port: 6379
+    timeout: 5000
+    pool:
+      max-active: 8
+      max-wait: -1ms
+      max-idle: 8
+      min-idle: 0
+#日志
+logging:
+  config: classpath:log/logback.xml
+  path: D://logs/simple-service
+  level: 
+    com.prac.simple.mapper: debug
+
+  
+

+ 35 - 0
src/main/resources/generatorConfig.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE generatorConfiguration
+  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<generatorConfiguration>
+    <!--数据库驱动
+    <classPathEntry    location="mysql-connector-java-5.1.46.jar"/>-->
+    <context id="DB2Tables"    targetRuntime="MyBatis3">
+        <commentGenerator>
+            <property name="suppressDate" value="true"/>
+            <property name="suppressAllComments" value="true"/>
+        </commentGenerator>
+        <!--数据库链接地址账号密码-->
+        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/simple?serverTimezone=UTC&amp;characterEncoding=utf8&amp;useUnicode=true&amp;useSSL=false" userId="root" password="1qaz!QAZ">
+        </jdbcConnection>
+        <javaTypeResolver>
+            <property name="forceBigDecimals" value="false"/>
+        </javaTypeResolver>
+        <!--生成Model类存放位置-->
+        <javaModelGenerator targetPackage="com.prac.simple.entity" targetProject="src/main/java">
+            <property name="enableSubPackages" value="true"/>
+            <property name="trimStrings" value="true"/>
+        </javaModelGenerator>
+        <!--生成映射文件存放位置-->
+        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
+            <property name="enableSubPackages" value="true"/>
+        </sqlMapGenerator>
+        <!--生成Dao类存放位置-->
+        <javaClientGenerator type="XMLMAPPER" targetPackage="com.prac.simple.mapper" targetProject="src/main/java">
+            <property name="enableSubPackages" value="true"/>
+        </javaClientGenerator>
+        <!--生成对应表及类名-->
+        <table tableName="device" domainObjectName="Device" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
+    </context>
+</generatorConfiguration>

+ 175 - 0
src/main/resources/log/logback.xml

@@ -0,0 +1,175 @@
+<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
+<configuration scan="true" scanPeriod="10 seconds">
+    <!--继承spring boot提供的logback配置-->
+    <!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
+
+    <!--设置系统日志目录-->
+    <springProperty name="LOG_PATH" source="logging.path"/>
+
+    <!-- 彩色日志 -->
+    <!-- 彩色日志依赖的渲染类 -->
+    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
+    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
+    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
+    <!-- 彩色日志格式 -->
+    <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
+
+    <!-- 控制台输出 -->
+    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+        <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+            <level>info</level>
+        </filter>
+    </appender>
+
+
+    <!-- 时间滚动输出 level为 DEBUG 日志 -->
+    <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${LOG_PATH}/log_debug.log</file>
+        <!--日志文件输出格式-->
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+        <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--
+                归档的日志文件的路径,例如今天是2017-04-26日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。
+                而2017-04-26的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引
+            -->
+            <fileNamePattern>${LOG_PATH}/debug/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!--
+                除按日志记录之外,还配置了日志文件不能超过500M,若超过500M,日志文件会以索引0开始,
+                命名日志文件,例如log-error-2017-04-26.0.log
+            -->
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+                <maxFileSize>500MB</maxFileSize>
+            </timeBasedFileNamingAndTriggeringPolicy>
+            <!--日志文件保留天数-->
+            <maxHistory>7</maxHistory>
+        </rollingPolicy>
+        <!-- 此日志文件只记录debug级别的 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>debug</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+
+    <!-- 时间滚动输出 level为 INFO 日志 -->
+    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${LOG_PATH}/log_info.log</file>
+        <!--日志文件输出格式-->
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+        <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--
+                归档的日志文件的路径,例如今天是2017-04-26日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。
+                而2017-04-26的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引
+            -->
+            <fileNamePattern>${LOG_PATH}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!--
+                除按日志记录之外,还配置了日志文件不能超过500M,若超过500M,日志文件会以索引0开始,
+                命名日志文件,例如log-error-2017-04-26.0.log
+            -->
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+                <maxFileSize>500MB</maxFileSize>
+            </timeBasedFileNamingAndTriggeringPolicy>
+            <!--日志文件保留天数-->
+            <maxHistory>7</maxHistory>
+        </rollingPolicy>
+        <!-- 此日志文件只记录info级别的 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>info</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+
+    <!-- 时间滚动输出 level为 WARN 日志 -->
+    <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${LOG_PATH}/log_warn.log</file>
+        <!--日志文件输出格式-->
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+        <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--
+                归档的日志文件的路径,例如今天是2017-04-26日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。
+                而2017-04-26的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引
+            -->
+            <fileNamePattern>${LOG_PATH}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!--
+                除按日志记录之外,还配置了日志文件不能超过500M,若超过500M,日志文件会以索引0开始,
+                命名日志文件,例如log-error-2017-04-26.0.log
+            -->
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+                <maxFileSize>500MB</maxFileSize>
+            </timeBasedFileNamingAndTriggeringPolicy>
+            <!--日志文件保留天数-->
+            <maxHistory>7</maxHistory>
+        </rollingPolicy>
+        <!-- 此日志文件只记录warn级别的 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>warn</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+
+    <!-- 时间滚动输出 level为 ERROR 日志 -->
+    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${LOG_PATH}/log_error.log</file>
+        <!--日志文件输出格式-->
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+        <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--
+                归档的日志文件的路径,例如今天是2017-04-26日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。
+                而2017-04-26的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引
+            -->
+            <fileNamePattern>${LOG_PATH}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!--
+                除按日志记录之外,还配置了日志文件不能超过500M,若超过500M,日志文件会以索引0开始,
+                命名日志文件,例如log-error-2017-04-26.0.log
+            -->
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+                <maxFileSize>500MB</maxFileSize>
+            </timeBasedFileNamingAndTriggeringPolicy>
+            <!--日志文件保留天数-->
+            <maxHistory>7</maxHistory>
+        </rollingPolicy>
+        <!-- 此日志文件只记录ERROR级别的 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>error</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+    <root level="info">
+            <appender-ref ref="CONSOLE" />
+            <appender-ref ref="DEBUG_FILE" />
+            <appender-ref ref="INFO_FILE" />
+            <appender-ref ref="WARN_FILE" />
+            <appender-ref ref="ERROR_FILE" />
+      </root>
+</configuration>

+ 135 - 0
src/main/resources/mapper/DeviceMapper.xml

@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.prac.simple.mapper.DeviceMapper">
+  <resultMap id="BaseResultMap" type="com.prac.simple.entity.Device">
+    <id column="mac" jdbcType="VARCHAR" property="mac" />
+    <result column="name" jdbcType="VARCHAR" property="name" />
+    <result column="open" jdbcType="CHAR" property="open" />
+    <result column="type" jdbcType="CHAR" property="type" />
+    <result column="description" jdbcType="VARCHAR" property="description" />
+    <result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
+    <result column="modifytime" jdbcType="TIMESTAMP" property="modifytime" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    mac, name, open, type, description, createtime, modifytime
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from device
+    where mac = #{mac,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+    delete from device
+    where mac = #{mac,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.prac.simple.entity.Device">
+    insert into device (mac, name, open, 
+      type, description, createtime, 
+      modifytime)
+    values (#{mac,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{open,jdbcType=CHAR}, 
+      #{type,jdbcType=CHAR}, #{description,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, 
+      #{modifytime,jdbcType=TIMESTAMP})
+  </insert>
+  <insert id="insertSelective" parameterType="com.prac.simple.entity.Device">
+    insert into device
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="mac != null">
+        mac,
+      </if>
+      <if test="name != null">
+        name,
+      </if>
+      <if test="open != null">
+        open,
+      </if>
+      <if test="type != null">
+        type,
+      </if>
+      <if test="description != null">
+        description,
+      </if>
+      <if test="createtime != null">
+        createtime,
+      </if>
+      <if test="modifytime != null">
+        modifytime,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="mac != null">
+        #{mac,jdbcType=VARCHAR},
+      </if>
+      <if test="name != null">
+        #{name,jdbcType=VARCHAR},
+      </if>
+      <if test="open != null">
+        #{open,jdbcType=CHAR},
+      </if>
+      <if test="type != null">
+        #{type,jdbcType=CHAR},
+      </if>
+      <if test="description != null">
+        #{description,jdbcType=VARCHAR},
+      </if>
+      <if test="createtime != null">
+        #{createtime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="modifytime != null">
+        #{modifytime,jdbcType=TIMESTAMP},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.prac.simple.entity.Device">
+    update device
+    <set>
+      <if test="name != null">
+        name = #{name,jdbcType=VARCHAR},
+      </if>
+      <if test="open != null">
+        open = #{open,jdbcType=CHAR},
+      </if>
+      <if test="type != null">
+        type = #{type,jdbcType=CHAR},
+      </if>
+      <if test="description != null">
+        description = #{description,jdbcType=VARCHAR},
+      </if>
+      <if test="createtime != null">
+        createtime = #{createtime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="modifytime != null">
+        modifytime = #{modifytime,jdbcType=TIMESTAMP},
+      </if>
+    </set>
+    where mac = #{mac,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.prac.simple.entity.Device">
+    update device
+    set name = #{name,jdbcType=VARCHAR},
+      open = #{open,jdbcType=CHAR},
+      type = #{type,jdbcType=CHAR},
+      description = #{description,jdbcType=VARCHAR},
+      createtime = #{createtime,jdbcType=TIMESTAMP},
+      modifytime = #{modifytime,jdbcType=TIMESTAMP}
+    where mac = #{mac,jdbcType=VARCHAR}
+  </update>
+  <select id="selectDevice"  parameterType="DeviceReq"  resultMap="BaseResultMap">
+  	select <include refid="Base_Column_List" />
+  	from device
+  	<where>
+  		<if test="mac != null and mac != ''">
+  			mac like CONCAT('%',#{mac,jdbcType=VARCHAR},'%')
+  		</if>
+  		<if test="name != null and name != ''">
+  			and name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
+  		</if>
+  	</where>
+  	<if test="sort != null and sort != ''">
+			order by ${sort}
+			<if test="order != null and order != ''">
+				${order}
+			</if>
+	</if>
+  </select>
+</mapper>

+ 198 - 0
src/main/resources/mapper/PermissionMapper.xml

@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.prac.simple.mapper.PermissionMapper">
+	<resultMap id="BaseResultMap" type="Permission">
+		<id column="id" jdbcType="VARCHAR" property="id" />
+		<result column="pid" jdbcType="VARCHAR" property="pid" />
+		<result column="title" jdbcType="VARCHAR" property="title" />
+		<result column="type" jdbcType="CHAR" property="type" />
+		<result column="url" jdbcType="VARCHAR" property="url" />
+		<result column="description" jdbcType="VARCHAR"
+			property="description" />
+		<result column="orders" jdbcType="INTEGER" property="orders" />
+	</resultMap>
+	<sql id="Base_Column_List">
+		id, pid, title, type, url, description, orders
+	</sql>
+	<select id="selectByPrimaryKey" parameterType="java.lang.String"
+		resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		where id = #{id,jdbcType=VARCHAR}
+	</select>
+	<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+		delete from permission
+		where id = #{id,jdbcType=VARCHAR}
+	</delete>
+	<insert id="insert" parameterType="Permission">
+		insert into permission (id, pid, title,
+		type, url, description,
+		orders)
+		values (#{id,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR},
+		#{title,jdbcType=VARCHAR},
+		#{type,jdbcType=CHAR}, #{url,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
+		#{orders,jdbcType=INTEGER})
+	</insert>
+	<insert id="insertSelective" parameterType="Permission">
+		insert into permission
+		<trim prefix="(" suffix=")" suffixOverrides=",">
+			<if test="id != null">
+				id,
+			</if>
+			<if test="pid != null">
+				pid,
+			</if>
+			<if test="title != null">
+				title,
+			</if>
+			<if test="type != null">
+				type,
+			</if>
+			<if test="url != null">
+				url,
+			</if>
+			<if test="description != null">
+				description,
+			</if>
+			<if test="orders != null">
+				orders,
+			</if>
+		</trim>
+		<trim prefix="values (" suffix=")" suffixOverrides=",">
+			<if test="id != null">
+				#{id,jdbcType=VARCHAR},
+			</if>
+			<if test="pid != null">
+				#{pid,jdbcType=VARCHAR},
+			</if>
+			<if test="title != null">
+				#{title,jdbcType=VARCHAR},
+			</if>
+			<if test="type != null">
+				#{type,jdbcType=CHAR},
+			</if>
+			<if test="url != null">
+				#{url,jdbcType=VARCHAR},
+			</if>
+			<if test="description != null">
+				#{description,jdbcType=VARCHAR},
+			</if>
+			<if test="orders != null">
+				#{orders,jdbcType=INTEGER},
+			</if>
+		</trim>
+	</insert>
+	<update id="updateByPrimaryKeySelective"
+		parameterType="Permission">
+		update permission
+		<set>
+			<if test="pid != null">
+				pid = #{pid,jdbcType=VARCHAR},
+			</if>
+			<if test="title != null">
+				title = #{title,jdbcType=VARCHAR},
+			</if>
+			<if test="type != null">
+				type = #{type,jdbcType=CHAR},
+			</if>
+			<if test="url != null">
+				url = #{url,jdbcType=VARCHAR},
+			</if>
+			<if test="description != null">
+				description = #{description,jdbcType=VARCHAR},
+			</if>
+			<if test="orders != null">
+				orders = #{orders,jdbcType=INTEGER},
+			</if>
+		</set>
+		where id = #{id,jdbcType=VARCHAR}
+	</update>
+	<update id="updateByPrimaryKey" parameterType="Permission">
+		update permission
+		set pid = #{pid,jdbcType=VARCHAR},
+		title = #{title,jdbcType=VARCHAR},
+		type = #{type,jdbcType=CHAR},
+		url = #{url,jdbcType=VARCHAR},
+		description = #{description,jdbcType=VARCHAR},
+		orders = #{orders,jdbcType=INTEGER}
+		where id = #{id,jdbcType=VARCHAR}
+	</update>
+	<select id="selectPermission" resultMap="BaseResultMap" parameterType="PermissionReq">
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		<where>
+			<if test="pid != null and pid != ''">
+				pid = #{pid}
+			</if>
+		</where>
+		order by pid,orders
+	</select>
+	<select id="selectAllMenu" resultMap="BaseResultMap" >
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		where type <![CDATA[<>]]> '03'
+	</select>
+	<select id="selectRolePermissions" resultType="RolePermission">
+		select p.url, r.id roleId
+		from role_permission rp
+		inner join permission p on rp.permission_id = p.id
+		inner join role r on rp.role_id=r.id
+	</select>
+	<select id="selectPermissionByUserId"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select distinct p.*
+		from permission p
+		inner join role_permission rp on rp.permission_id = p.id
+		inner join user_role ur on ur.role_id=rp.role_id
+		where ur.user_id=#{userId}
+	</select>
+	<select id="selectPermissionByRoleId"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select p.*
+		from permission p
+		inner join role_permission rp on rp.permission_id = p.id
+		where rp.role_id=#{roleId}
+	</select>
+	<select id="selectPermissionByUrl"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		where url=#{url} limit 1
+	</select>
+	<select id="selectPermissionByTitle"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		where title=#{title} limit 1
+	</select>
+	<select id="selectExistPermissionByUrl"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		where url=#{url} and id <![CDATA[<>]]>
+		#{id} limit 1
+	</select>
+	<select id="selectChildrenPermission"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from permission
+		where pid=#{id}
+	</select>
+	<select id="selectAllPermissionUrl"  parameterType="java.lang.String"  resultType="java.lang.String" >
+		select url from permission where url is not null and url <![CDATA[<>]]> ''
+	</select>
+	<delete id="batchDeletePermission" parameterType="list">
+		delete from permission where id userId
+		<foreach collection="list" item="id" open="(" close=")"
+			separator=",">
+			#{id,jdbcType=INTEGER}
+		</foreach>
+	</delete>
+</mapper>

+ 106 - 0
src/main/resources/mapper/RoleMapper.xml

@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.prac.simple.mapper.RoleMapper">
+	<resultMap id="BaseResultMap" type="Role">
+		<id column="id" jdbcType="VARCHAR" property="id" />
+		<result column="name" jdbcType="VARCHAR" property="name" />
+		<result column="description" jdbcType="VARCHAR"
+			property="description" />
+	</resultMap>
+	<sql id="Base_Column_List">
+		id, name, description
+	</sql>
+	<select id="selectByPrimaryKey" parameterType="java.lang.String"
+		resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from role
+		where id = #{id,jdbcType=VARCHAR}
+	</select>
+	<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+		delete from role
+		where id = #{id,jdbcType=VARCHAR}
+	</delete>
+	<insert id="insert" parameterType="Role">
+		insert into role (id, name,
+		description)
+		values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
+		#{description,jdbcType=VARCHAR})
+	</insert>
+	<insert id="insertSelective" parameterType="Role">
+		insert into role
+		<trim prefix="(" suffix=")" suffixOverrides=",">
+			<if test="id != null">
+				id,
+			</if>
+			<if test="name != null">
+				name,
+			</if>
+			<if test="description != null">
+				description,
+			</if>
+		</trim>
+		<trim prefix="values (" suffix=")" suffixOverrides=",">
+			<if test="id != null">
+				#{id,jdbcType=VARCHAR},
+			</if>
+			<if test="name != null">
+				#{name,jdbcType=VARCHAR},
+			</if>
+			<if test="description != null">
+				#{description,jdbcType=VARCHAR},
+			</if>
+		</trim>
+	</insert>
+	<update id="updateByPrimaryKeySelective" parameterType="Role">
+		update role
+		<set>
+			<if test="name != null">
+				name = #{name,jdbcType=VARCHAR},
+			</if>
+			<if test="description != null">
+				description = #{description,jdbcType=VARCHAR},
+			</if>
+		</set>
+		where id = #{id,jdbcType=VARCHAR}
+	</update>
+	<update id="updateByPrimaryKey" parameterType="Role">
+		update role
+		set name = #{name,jdbcType=VARCHAR},
+		description = #{description,jdbcType=VARCHAR}
+		where id = #{id,jdbcType=VARCHAR}
+	</update>
+
+	<select id="selectRoleByUserId" parameterType="java.lang.String"
+		resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from role r
+		where r.id in(
+		select ur.role_id from user_role ur where ur.user_id =
+		#{userId,jdbcType=VARCHAR}
+		)
+	</select>
+	<select id="selectAllRole" resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from role
+	</select>
+	
+	<select id="selectRole" resultMap="BaseResultMap"  parameterType="RoleReq">
+		select
+		<include refid="Base_Column_List" />
+		from role
+		<where>
+			<if test="name != null and name !=''">
+				name like CONCAT('%',#{name,jdbcType = VARCHAR},'%') 
+			</if>
+		</where>
+		<if test="sort != null and sort != ''">
+			order by ${sort}
+			<if test="order != null and order != ''">
+				${order}
+			</if>
+		</if>
+	</select>
+</mapper>

+ 67 - 0
src/main/resources/mapper/RolePermissionMapper.xml

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper
+	namespace="com.prac.simple.mapper.RolePermissionMapper">
+	<resultMap id="BaseResultMap"
+		type="com.prac.simple.entity.RolePermission">
+		<result column="role_id" jdbcType="VARCHAR" property="roleId" />
+		<result column="permission_id" jdbcType="VARCHAR"
+			property="permissionId" />
+	</resultMap>
+	<insert id="insert"
+		parameterType="com.prac.simple.entity.RolePermission">
+		insert into role_permission (role_id, permission_id)
+		values (#{roleId,jdbcType=VARCHAR}, #{permissionId,jdbcType=VARCHAR})
+	</insert>
+	<insert id="insertSelective"
+		parameterType="com.prac.simple.entity.RolePermission">
+		insert into role_permission
+		<trim prefix="(" suffix=")" suffixOverrides=",">
+			<if test="roleId != null">
+				role_id,
+			</if>
+			<if test="permissionId != null">
+				permission_id,
+			</if>
+		</trim>
+		<trim prefix="values (" suffix=")" suffixOverrides=",">
+			<if test="roleId != null">
+				#{roleId,jdbcType=VARCHAR},
+			</if>
+			<if test="permissionId != null">
+				#{permissionId,jdbcType=VARCHAR},
+			</if>
+		</trim>
+	</insert>
+	<select id="selectPermissionIdByRoleId"
+		parameterType="java.lang.String" resultType="java.lang.String">
+		select permission_id
+		from role_permission where role_id=#{roleId}
+	</select>
+	<delete id="batchDeleteRolePermissionByPermissionId"
+		parameterType="list">
+		delete from role_permission where permission_id in
+		<foreach collection="list" item="id" open="(" close=")"
+			separator=",">
+			#{id,jdbcType=INTEGER}
+		</foreach>
+	</delete>
+	<delete id="deleteRolePermissionByPermissionId"
+		parameterType="java.lang.String">
+		delete from role_permission 
+		where permission_id = #{id,jdbcType=INTEGER}
+	</delete>
+	<delete id="deleteRolePermissionByRoleId"
+		parameterType="java.lang.String">
+		delete from role_permission where role_id = #{roleId}
+	</delete>
+	
+	<select id="selectRoleIdByUrl"  parameterType="java.lang.String"  resultType="java.lang.String" >
+		select distinct rp.role_id
+		from role_permission rp
+		inner join permission p on rp.permission_id = p.id
+		<where>
+			p.url=#{url,jdbcType=VARCHAR}
+		</where>
+	</select>
+</mapper>

+ 166 - 0
src/main/resources/mapper/UserMapper.xml

@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.prac.simple.mapper.UserMapper">
+	<resultMap id="BaseResultMap" type="User">
+		<id column="id" jdbcType="VARCHAR" property="id" />
+		<result column="username" jdbcType="VARCHAR"
+			property="username" />
+		<result column="password" jdbcType="VARCHAR"
+			property="password" />
+		<result column="email" jdbcType="VARCHAR" property="email" />
+		<result column="salt" jdbcType="VARCHAR" property="salt" />
+		<result column="enabled" jdbcType="CHAR" property="enabled" />
+		<result column="createTime" jdbcType="TIMESTAMP"
+			property="createtime" />
+		<result column="lastTime" jdbcType="TIMESTAMP"
+			property="lasttime" />
+	</resultMap>
+	<sql id="Base_Column_List">
+		id, username, password, email, salt, enabled, createTime, lastTime
+	</sql>
+	<select id="selectByPrimaryKey" parameterType="java.lang.String"
+		resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from user
+		where id = #{id,jdbcType=VARCHAR}
+	</select>
+	<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+		delete from user
+		where id = #{id,jdbcType=VARCHAR}
+	</delete>
+	<insert id="insert" parameterType="User">
+		insert into user (id, username, password,
+		email, salt, enabled,
+		createTime, lastTime)
+		values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR},
+		#{password,jdbcType=VARCHAR},
+		#{email,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, #{enabled,jdbcType=CHAR},
+		#{createtime,jdbcType=TIMESTAMP}, #{lasttime,jdbcType=TIMESTAMP})
+	</insert>
+	<insert id="insertSelective" parameterType="User">
+		insert into user
+		<trim prefix="(" suffix=")" suffixOverrides=",">
+			<if test="id != null">
+				id,
+			</if>
+			<if test="username != null">
+				username,
+			</if>
+			<if test="password != null">
+				password,
+			</if>
+			<if test="email != null">
+				email,
+			</if>
+			<if test="salt != null">
+				salt,
+			</if>
+			<if test="enabled != null">
+				enabled,
+			</if>
+			<if test="createtime != null">
+				createTime,
+			</if>
+			<if test="lasttime != null">
+				lastTime,
+			</if>
+		</trim>
+		<trim prefix="values (" suffix=")" suffixOverrides=",">
+			<if test="id != null">
+				#{id,jdbcType=VARCHAR},
+			</if>
+			<if test="username != null">
+				#{username,jdbcType=VARCHAR},
+			</if>
+			<if test="password != null">
+				#{password,jdbcType=VARCHAR},
+			</if>
+			<if test="email != null">
+				#{email,jdbcType=VARCHAR},
+			</if>
+			<if test="salt != null">
+				#{salt,jdbcType=VARCHAR},
+			</if>
+			<if test="enabled != null">
+				#{enabled,jdbcType=CHAR},
+			</if>
+			<if test="createtime != null">
+				#{createtime,jdbcType=TIMESTAMP},
+			</if>
+			<if test="lasttime != null">
+				#{lasttime,jdbcType=TIMESTAMP},
+			</if>
+		</trim>
+	</insert>
+	<update id="updateByPrimaryKeySelective" parameterType="User">
+		update user
+		<set>
+			<if test="username != null">
+				username = #{username,jdbcType=VARCHAR},
+			</if>
+			<if test="password != null">
+				password = #{password,jdbcType=VARCHAR},
+			</if>
+			<if test="email != null">
+				email = #{email,jdbcType=VARCHAR},
+			</if>
+			<if test="salt != null">
+				salt = #{salt,jdbcType=VARCHAR},
+			</if>
+			<if test="enabled != null">
+				enabled = #{enabled,jdbcType=CHAR},
+			</if>
+			<if test="createtime != null">
+				createTime = #{createtime,jdbcType=TIMESTAMP},
+			</if>
+			<if test="lasttime != null">
+				lastTime = #{lasttime,jdbcType=TIMESTAMP},
+			</if>
+		</set>
+		where id = #{id,jdbcType=VARCHAR}
+	</update>
+	<update id="updateByPrimaryKey" parameterType="User">
+		update user
+		set username = #{username,jdbcType=VARCHAR},
+		password = #{password,jdbcType=VARCHAR},
+		email = #{email,jdbcType=VARCHAR},
+		salt = #{salt,jdbcType=VARCHAR},
+		enabled = #{enabled,jdbcType=CHAR},
+		createTime = #{createtime,jdbcType=TIMESTAMP},
+		lastTime = #{lasttime,jdbcType=TIMESTAMP}
+		where id = #{id,jdbcType=VARCHAR}
+	</update>
+	<select id="selectUser" parameterType="UserReq"
+		resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from user
+		<where>
+			<if test="username != null">
+				username like CONCAT('%', #{username,jdbcType=VARCHAR},'%')
+			</if>
+		</where>
+		<if test="sort != null and sort != ''">
+			order by ${sort}
+			<if test="order != null and order != ''">
+				${order}
+			</if>
+		</if>
+	</select>
+	<select id="selectUserByUsername"
+		parameterType="java.lang.String" resultMap="BaseResultMap">
+		select
+		<include refid="Base_Column_List" />
+		from user
+		where username = #{userName,jdbcType=VARCHAR} limit 1
+	</select>
+	
+	<delete id="batchDelete"  parameterType="list">
+		delete from user where id in
+		<foreach collection="list" item="id" open="(" close=")"
+			separator=",">
+			#{id,jdbcType=INTEGER}
+		</foreach>
+	</delete>
+</mapper>

+ 45 - 0
src/main/resources/mapper/UserRoleMapper.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.prac.simple.mapper.UserRoleMapper">
+	<resultMap id="BaseResultMap"
+		type="com.prac.simple.entity.UserRole">
+		<result column="user_id" jdbcType="VARCHAR" property="userId" />
+		<result column="role_id" jdbcType="VARCHAR" property="roleId" />
+	</resultMap>
+	<insert id="insert"
+		parameterType="com.prac.simple.entity.UserRole">
+		insert into user_role (user_id, role_id)
+		values (#{userId,jdbcType=VARCHAR}, #{roleId,jdbcType=VARCHAR})
+	</insert>
+	<insert id="insertSelective"
+		parameterType="com.prac.simple.entity.UserRole">
+		insert into user_role
+		<trim prefix="(" suffix=")" suffixOverrides=",">
+			<if test="userId != null">
+				user_id,
+			</if>
+			<if test="roleId != null">
+				role_id,
+			</if>
+		</trim>
+		<trim prefix="values (" suffix=")" suffixOverrides=",">
+			<if test="userId != null">
+				#{userId,jdbcType=VARCHAR},
+			</if>
+			<if test="roleId != null">
+				#{roleId,jdbcType=VARCHAR},
+			</if>
+		</trim>
+	</insert>
+	<delete id="deleteUserRoleByRoleId"
+		parameterType="java.lang.String">
+		delete from user_role where role_id=#{roleId}
+	</delete>
+	<delete id="deleteUserRoleByUserId"
+		parameterType="java.lang.String">
+		delete from user_role where user_id=#{userId}
+	</delete>
+	<select id="selectRoleIdByUserId" resultType="java.lang.String">
+		select role_id from user_role where user_id=#{userId}
+	</select>
+</mapper>