diff --git a/springboot-saToken/README.md b/springboot-saToken/README.md new file mode 100644 index 0000000..e35eead --- /dev/null +++ b/springboot-saToken/README.md @@ -0,0 +1,43 @@ +## springBoot-demo + +springBoot-demo 是一个SpringBoot的基础框架项目,可以在此项目上进行扩展。 + +## 开发环境 + +- Java 8+ +- Maven 3.5.4+ +- SpringBoot 2.3.12.RELEASE +- mysql5.7+ +- ant1.9+ (非必须,打包可用) + + +## 快速开始 + +**使用** + +- git clone https://github.com/xuwujing/springBoot-study/springBoot-demo.git + +**使用** + +秉着开箱即用的原则,更改相应的配置(MySql、Es、Redis等地址配置),运行main方法,即可启动! + +**注意** + + EasyCode模板生成的xml若是没有逗号,则需要将全局模版velocityHasNext修改为foreach.hasNext。 + +## 项目结构 + +``` +springBoot-demo +├── pom.xml +├── README.md +├── build-dev.bat ant打包脚本启动命令 +├── build-dev.xml ant打包脚本 +├── git-info.bat git信息获取 +├── start.sh linux启动脚本 +├── stop.sh linux停止动脚本 +└── src + ├── main + │   ├── java + │   │   └── com + │   │   └── pancm \ No newline at end of file diff --git a/springboot-saToken/build-dev.bat b/springboot-saToken/build-dev.bat new file mode 100644 index 0000000..3178c7c --- /dev/null +++ b/springboot-saToken/build-dev.bat @@ -0,0 +1 @@ +ant -f build-dev.xml \ No newline at end of file diff --git a/springboot-saToken/build-dev.xml b/springboot-saToken/build-dev.xml new file mode 100644 index 0000000..abf9d50 --- /dev/null +++ b/springboot-saToken/build-dev.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/springboot-saToken/db/pcm.sql b/springboot-saToken/db/pcm.sql new file mode 100644 index 0000000..0df95f5 --- /dev/null +++ b/springboot-saToken/db/pcm.sql @@ -0,0 +1,212 @@ +/* + Navicat Premium Data Transfer + + Source Server : dev-kms + Source Server Type : MySQL + Source Server Version : 50732 + Source Host : base-dev.udb.bnqoa.com:3306 + Source Schema : base_kms + + Target Server Type : MySQL + Target Server Version : 50732 + File Encoding : 65001 + + Date: 22/11/2024 17:52:00 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + + +-- ---------------------------- +-- Table structure for log_operation +-- ---------------------------- +DROP TABLE IF EXISTS `log_operation`; +CREATE TABLE `log_operation` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `trace_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求唯一id', + `client_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '应用唯一标识', + `tenant_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '租户', + `business_no` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '业务主键', + `operation` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作', + `class_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '类名', + `method_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '方法名', + `from_ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求ip', + `result` tinyint(1) NULL DEFAULT NULL COMMENT '操作结果 1 成功, 0 失败', + `remark` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '备注', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `creator_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '创建人', + `modify_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `modifier_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_trace_id`(`trace_id`) USING BTREE, + INDEX `idx_operation`(`operation`) USING BTREE, + INDEX `idx_class_name`(`class_name`) USING BTREE, + INDEX `idx_from_ip`(`from_ip`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 74 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '操作日志表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of log_operation +-- ---------------------------- + +-- ---------------------------- +-- Table structure for log_operation_details +-- ---------------------------- +DROP TABLE IF EXISTS `log_operation_details`; +CREATE TABLE `log_operation_details` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `trace_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求唯一id', + `req_data` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '请求参数', + `rep_data` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '响应参数', + `error_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '错误信息', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `creator_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '创建人', + `modify_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `modifier_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_trace_id`(`trace_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 74 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '操作日志表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Table structure for sys_permission +-- ---------------------------- +DROP TABLE IF EXISTS `sys_permission`; +CREATE TABLE `sys_permission` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `parent_id` int(11) NOT NULL COMMENT '父ID', + `permission_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '权限编码', + `permission_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '权限名称', + `permission_route` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '权限路由', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `creator_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '创建人', + `modify_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `modifier_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 31 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '权限表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of sys_permission +-- ---------------------------- +INSERT INTO `sys_permission` VALUES (1, 0, 'UserInfoController', '用户', '/userInfo', '2024-11-21 16:37:15', '1', '2024-11-21 16:38:35', NULL, 0); +INSERT INTO `sys_permission` VALUES (2, 1, 'UserInfoController#add', '用户新增', '/userInfo/add', '2024-11-21 16:41:57', '1', '2024-11-21 16:53:28', NULL, 0); +INSERT INTO `sys_permission` VALUES (3, 1, 'UserInfoController#update', '用户修改', '/userInfo/update', '2024-11-21 16:41:57', '1', '2024-11-21 16:53:29', NULL, 0); +INSERT INTO `sys_permission` VALUES (4, 1, 'UserInfoController#enable', '用户启用/禁用', '/userInfo/enable', '2024-11-21 16:41:57', '1', '2024-11-21 16:53:32', NULL, 0); +INSERT INTO `sys_permission` VALUES (5, 1, 'UserInfoController#get', '用户详情', '/userInfo/get', '2024-11-21 16:41:57', '1', '2024-11-21 16:53:33', NULL, 0); +INSERT INTO `sys_permission` VALUES (6, 1, 'UserInfoController#queryPage', '用户分页查询', '/userInfo/queryPage', '2024-11-21 16:41:57', '1', '2024-11-21 16:53:36', NULL, 0); +INSERT INTO `sys_permission` VALUES (7, 0, 'UserRoleController', '用户角色', '/userRole', '2024-11-22 17:36:40', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (8, 7, 'UserRoleController#add', '用户角色新增', '/userRole/add', '2024-11-22 17:38:06', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (9, 7, 'UserRoleController#update', '用户角色修改', '/userRole/update', '2024-11-22 17:38:06', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (10, 7, 'UserRoleController#enable', '用户角色启用/禁用', '/userRole/enable', '2024-11-22 17:38:06', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (11, 7, 'UserRoleController#grant', '用户角色授权', '/userRole/grant', '2024-11-22 17:38:06', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (12, 7, 'UserRoleController#get', '用户角色详情', '/userRole/get', '2024-11-22 17:38:06', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (13, 7, 'UserRoleController#queryPage', '用户角色分页查询', '/userRole/queryPage', '2024-11-22 17:38:06', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (14, 0, 'PermissionController', '权限', '/permission', '2024-11-22 17:42:39', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (15, 14, 'PermissionController#add', '权限新增', '/permission/add', '2024-11-22 17:43:43', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (16, 14, 'PermissionController#update', '权限修改', '/permission/update', '2024-11-22 17:43:43', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (17, 14, 'PermissionController#get', '权限详情', '/permission/get', '2024-11-22 17:43:43', '1', NULL, NULL, 0); +INSERT INTO `sys_permission` VALUES (18, 14, 'PermissionController#queryPage', '权限分页查询', '/permission/queryPage', '2024-11-22 17:43:43', '1', NULL, NULL, 0); + +-- ---------------------------- +-- Table structure for sys_user_info +-- ---------------------------- +DROP TABLE IF EXISTS `sys_user_info`; +CREATE TABLE `sys_user_info` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `user_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户名', + `nick_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '昵称', + `password` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '密码', + `user_enable` tinyint(1) NOT NULL DEFAULT 0 COMMENT '启用状态 0 否 1是', + `role_id` tinyint(1) NOT NULL DEFAULT 2 COMMENT '角色ID 1 管理员 2 普通用户', + `job_no` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '工号', + `mobile` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '员工联系方式', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `creator_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '创建人', + `modify_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `modifier_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_user_name`(`user_name`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '系统用户表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of sys_user_info +-- ---------------------------- +INSERT INTO `sys_user_info` VALUES (1, 'admin', 'admin', '123456', 1, 1, NULL, NULL, '2024-11-21 15:48:34', '1', '2024-11-21 15:48:51', NULL, 0); + +-- ---------------------------- +-- Table structure for sys_user_role +-- ---------------------------- +DROP TABLE IF EXISTS `sys_user_role`; +CREATE TABLE `sys_user_role` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `role_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色名', + `user_enable` tinyint(1) NOT NULL DEFAULT 0 COMMENT '启用状态 0 否 1是', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `creator_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '创建人', + `modify_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `modifier_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_role_name`(`role_name`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户角色表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of sys_user_role +-- ---------------------------- +INSERT INTO `sys_user_role` VALUES (1, '管理员', 1, '2024-11-21 16:33:55', '1', NULL, NULL, 0); + +-- ---------------------------- +-- Table structure for sys_user_role_permission +-- ---------------------------- +DROP TABLE IF EXISTS `sys_user_role_permission`; +CREATE TABLE `sys_user_role_permission` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `role_id` int(11) NOT NULL COMMENT '角色ID', + `permission_id` int(11) NOT NULL COMMENT '权限ID', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `creator_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '创建人', + `modify_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `modifier_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_role_id_and_per_id`(`role_id`, `permission_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 33 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户角色权限表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of sys_user_role_permission +-- ---------------------------- +INSERT INTO `sys_user_role_permission` VALUES (2, 1, 1, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (3, 1, 2, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (4, 1, 3, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (5, 1, 4, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (6, 1, 5, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (7, 1, 6, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (8, 1, 7, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (9, 1, 8, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (10, 1, 9, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (11, 1, 10, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (12, 1, 11, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (13, 1, 12, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (14, 1, 13, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (15, 1, 14, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (16, 1, 15, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (17, 1, 16, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (18, 1, 17, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (19, 1, 18, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (20, 1, 19, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (21, 1, 20, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (22, 1, 21, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (23, 1, 22, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (24, 1, 23, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (25, 1, 24, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (26, 1, 25, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (27, 1, 26, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (28, 1, 27, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (29, 1, 28, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (30, 1, 29, '2024-11-22 17:50:54', '1', NULL, NULL, 0); +INSERT INTO `sys_user_role_permission` VALUES (31, 1, 30, '2024-11-22 17:50:54', '1', NULL, NULL, 0); + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/springboot-saToken/git-info.bat b/springboot-saToken/git-info.bat new file mode 100644 index 0000000..abc88de --- /dev/null +++ b/springboot-saToken/git-info.bat @@ -0,0 +1,13 @@ +@echo off +set time=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% +set app=springboot-demo +for /F %%i in ('git rev-parse --short HEAD') do ( set commit_id=%%i) +for /F %%i in ('git rev-parse --abbrev-ref HEAD') do ( set branch_id=%%i) +echo build_app = %app% > ./src/main/resources/build.properties +echo build_time = %time% >> ./src/main/resources/build.properties +echo git_commit = %commit_id% >> ./src/main/resources/build.properties +echo git_branch = %branch_id% >> ./src/main/resources/build.properties +echo start %app% at %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% +::echo "build_version = '${version}'" > ./src/main/resources/build.properties +::echo "upload %app%" +::echo "done %app% %time% at $(date "+%Y-%m-%d %H:%M:%S")" diff --git a/springboot-saToken/pom.xml b/springboot-saToken/pom.xml new file mode 100644 index 0000000..ba613db --- /dev/null +++ b/springboot-saToken/pom.xml @@ -0,0 +1,246 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.13.RELEASE + + + com.pancm + springboot-saToken + 0.0.1-SNAPSHOT + springboot-saToken + Demo project for Spring Boot + + + 1.8 + 1.7.25 + 1.2.3 + 3.5.0 + 2.6.2 + 2.9.2 + 1.5.21 + 1.9.6 + 1.2.62 + 5.1.41 + 1.1.12 + 4.0.3 + 1.3.1 + 1.1.4 + 2.9.2 + 1.5.21 + 1.9.6 + + + + + + local + + local + + + + true + + + + + dev + + dev + + + + + prod + + prod + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.apache.tomcat + tomcat-jdbc + + + org.springframework.boot + spring-boot-starter-logging + + + + + mysql + mysql-connector-java + ${mysql.connector.version} + + + com.alibaba + druid + ${alibaba.druid.version} + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis.spring.boot.version} + + + tk.mybatis + mapper-spring-boot-starter + ${tk.mybatis.boot.version} + + + com.baomidou + mybatis-plus-boot-starter + 3.0.5 + + + + org.mybatis.generator + mybatis-generator-core + 1.3.5 + + + com.github.pagehelper + pagehelper + ${pagehelper.version} + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + ch.qos.logback + logback-core + ${logback.version} + + + + org.springframework.boot + spring-boot-starter-websocket + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + + + com.alibaba + fastjson + ${alibaba.fastjson} + + + + + io.springfox + springfox-swagger2 + ${swagger.version} + + + io.swagger + swagger-models + + + + + + io.swagger + swagger-models + ${swagger.model.version} + + + io.springfox + springfox-swagger-ui + ${swagger.version} + + + + com.github.xiaoymin + swagger-bootstrap-ui + ${swagger.bootstrap.ui.version} + + + + + cn.dev33 + sa-token-spring-boot-starter + 1.28.0 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.8 + + + com.fasterxml.jackson.core + jackson-databind + 2.9.8 + + + + + + springboot-saToken + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/springboot-saToken/src/main/java/com/pancm/Application.java b/springboot-saToken/src/main/java/com/pancm/Application.java new file mode 100644 index 0000000..413880d --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/Application.java @@ -0,0 +1,40 @@ +package com.pancm; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.Environment; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** +* @Title: Application +* @Description: main +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @Date 2021/10/15 +**/ +@ServletComponentScan +@SpringBootApplication +@Slf4j +public class Application { + + public static void main(String[] args) throws UnknownHostException { + ConfigurableApplicationContext application = SpringApplication.run(Application.class, args); + Environment env = application.getEnvironment(); + String ip = InetAddress.getLocalHost().getHostAddress(); + String port = env.getProperty("server.port"); + String path = env.getProperty("server.servlet.context-path"); + log.info("\n----------------------------------------------------------\n\t" + + "Application springboot-demo is running! Access URLs:\n\t" + + "Local: \t\thttp://localhost:" + port + path + "/\n\t" + + "External: \thttp://" + ip + ":" + port + path + "/\n\t" + + "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" + + "----------------------------------------------------------"); + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/config/CorsFilter.java b/springboot-saToken/src/main/java/com/pancm/config/CorsFilter.java new file mode 100644 index 0000000..05e8191 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/config/CorsFilter.java @@ -0,0 +1,49 @@ +package com.pancm.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +@Configuration +public class CorsFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) { + + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; + String origin = ((HttpServletRequest) servletRequest).getHeader("Origin"); + if (StringUtils.isEmpty(origin)) { + origin = "*"; + } + String rh = ((HttpServletRequest) servletRequest).getHeader("Access-Control-Request-Headers"); + if (StringUtils.isEmpty(origin)) { + rh = "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control," + + "Content-Type,Authorization,SessionToken,Content-Disposition"; + } + httpServletResponse.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); + httpServletResponse.setHeader("Access-Control-Allow-Origin", origin); + httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true"); + httpServletResponse.setHeader("Access-Control-Allow-Headers", rh); + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/config/PancmConfiguration.java b/springboot-saToken/src/main/java/com/pancm/config/PancmConfiguration.java new file mode 100644 index 0000000..9b7e58f --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/config/PancmConfiguration.java @@ -0,0 +1,120 @@ +package com.pancm.config; + +import com.alibaba.druid.pool.DruidDataSource; +import com.github.pagehelper.PageHelper; +import org.apache.ibatis.plugin.Interceptor; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; +import java.util.Objects; +import java.util.Properties; + +import static com.pancm.config.PancmConfiguration.PACKAGE; + +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +@Configuration +@MapperScan(basePackages = {PACKAGE}, sqlSessionFactoryRef = "pancmSqlSessionFactory") +public class PancmConfiguration { + + static final String PACKAGE = "com.pancm.dao"; + static final String MAPPER_LOCATION = "classpath:pancm/mapper/*.xml"; + static final String CONFIG_LOCATION = "classpath:pancm/mybatis-config.xml"; + + + + @Value("${spring.datasource.pancm.driver-class-name}") + private String driverClassName; + + @Value("${spring.datasource.pancm.url}") + private String url; + + @Value("${spring.datasource.pancm.username}") + private String username; + + @Value("${spring.datasource.pancm.password}") + private String password; + + + @Bean(name = "pancmDataSource") + @ConfigurationProperties(prefix = "spring.datasource.pancm") + @Primary + public DataSource pancmDataSource() { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setDriverClassName(driverClassName); + dataSource.setUrl(url); + dataSource.setUsername(username); + dataSource.setPassword(password); + dataSource.setInitialSize(10); + dataSource.setMinIdle(10); + dataSource.setMaxActive(30); + dataSource.setMaxWait(30000); + dataSource.setRemoveAbandoned(true); + dataSource.setRemoveAbandonedTimeout(1800); + dataSource.setLogAbandoned(false); + dataSource.setTimeBetweenEvictionRunsMillis(60000); + dataSource.setMinEvictableIdleTimeMillis(300000); + dataSource.setValidationQuery("SELECT 1"); + dataSource.setTestWhileIdle(true); + dataSource.setTestOnBorrow(false); + dataSource.setTestOnReturn(false); + dataSource.setPoolPreparedStatements(true); + dataSource.setMaxPoolPreparedStatementPerConnectionSize(500); + dataSource.setKeepAlive(true); + dataSource.setDbType("mysql"); + return dataSource; + } + + @Bean(name = "pancmSqlSessionFactory") + @Primary + public SqlSessionFactory pancmSqlSessionFactory(@Qualifier("pancmDataSource") DataSource dataSource) throws Exception { + SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); + bean.setDataSource(dataSource); + + //分页插件 + PageHelper pageHelper = new PageHelper(); + Properties properties = new Properties(); + properties.setProperty("reasonable", "true"); + properties.setProperty("supportMethodsArguments", "true"); + properties.setProperty("returnPageInfo", "check"); + properties.setProperty("params", "count=countSql"); + pageHelper.setProperties(properties); + + //添加插件 + bean.setPlugins(new Interceptor[]{pageHelper}); + + bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION)); + bean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(CONFIG_LOCATION)); + Objects.requireNonNull(bean.getObject()).getConfiguration().setMapUnderscoreToCamelCase(true); + return bean.getObject(); + } + + @Bean(name = "pancmTransactionManager") + @Primary + public DataSourceTransactionManager testTransactionManager(@Qualifier("pancmDataSource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + + @Bean(name = "pancmSqlSessionTemplate") + @Primary + public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("pancmSqlSessionFactory") SqlSessionFactory sqlSessionFactory) + throws Exception { + return new SqlSessionTemplate(sqlSessionFactory); + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/config/SpringBeanFactory.java b/springboot-saToken/src/main/java/com/pancm/config/SpringBeanFactory.java new file mode 100644 index 0000000..9a6ed7a --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/config/SpringBeanFactory.java @@ -0,0 +1,50 @@ +package com.pancm.config; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * @Title: SpringBeanFactory + * @Description: + * @Version:1.0.0 + * @Since:jdk1.8 + * @author pancm + * @Date 2021/7/2 + **/ +@Component +public class SpringBeanFactory implements ApplicationContextAware { + + // Spring应用上下文环境 + private static ApplicationContext applicationContext; + + /** + * 实现ApplicationContextAware接口的回调方法,设置上下文环境 + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { + SpringBeanFactory.applicationContext = applicationContext; + } + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 获取对象 这里重写了bean方法,起主要作用 + */ + public static Object getBean(String beanId) throws BeansException { + if (applicationContext == null) return null; + return applicationContext.getBean(beanId); + } + + /** + * 获取当前环境 + */ + public static String getActiveProfile() { + return applicationContext.getEnvironment().getActiveProfiles()[0]; + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/config/SwaggerConfig.java b/springboot-saToken/src/main/java/com/pancm/config/SwaggerConfig.java new file mode 100644 index 0000000..1a93d99 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/config/SwaggerConfig.java @@ -0,0 +1,64 @@ +package com.pancm.config; + +import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.bind.annotation.RequestMethod; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +@Configuration +@EnableSwagger2 +@EnableSwaggerBootstrapUI +public class SwaggerConfig { + + @Bean + public Docket createRestApi() { + //添加head参数start + ParameterBuilder tokenPar = new ParameterBuilder(); + List pars = new ArrayList(); + tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); + pars.add(tokenPar.build()); + //添加head参数end + + + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.pancm.controller")) + .paths(PathSelectors.any()) + .build() + .globalOperationParameters(pars) + ; + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("pancm-swagger2") + .description("Restful-API-Doc") + .termsOfServiceUrl("https://www.cnblogs.com/xuwujing") + .contact(new Contact("虚无境的博客", "https://www.cnblogs.com/xuwujing", "xxx@qq.com")) + .version("1.0") + .build(); + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/controller/HomeController.java b/springboot-saToken/src/main/java/com/pancm/controller/HomeController.java new file mode 100644 index 0000000..527f9a6 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/controller/HomeController.java @@ -0,0 +1,53 @@ +package com.pancm.controller; + +import com.alibaba.fastjson.JSONObject; +import com.pancm.util.FileHelper; +import com.pancm.util.GetProperties; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +@RestController +@RequestMapping("/home") +@Slf4j +@Api(tags = "首页相关接口") +public class HomeController { + + + @Value("${spring.profiles.active}") + String active; + + private final static String VERSION_NAME = "version.txt"; + + @ApiOperation(value = "/version", notes = "版本信息") + @RequestMapping(value = "/version", method = {RequestMethod.GET}) + public JSONObject version(HttpServletRequest request){ + Map map = GetProperties.getAppSettings(); + JSONObject result = new JSONObject(); + result.put("git_branch", map.get("git_branch")); + result.put("build_time", map.get("build_time")); + result.put("git_commit", map.get("git_commit")); + result.put("app_name", map.get("build_app")); + result.put("profile", active); + result.put("version", FileHelper.readResourcesFile(VERSION_NAME)); + return result; + } + + + + +} diff --git a/springboot-saToken/src/main/java/com/pancm/controller/TSysUserController.java b/springboot-saToken/src/main/java/com/pancm/controller/TSysUserController.java new file mode 100644 index 0000000..8483569 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/controller/TSysUserController.java @@ -0,0 +1,103 @@ +package com.pancm.controller; + +import com.pancm.vo.TSysUserVO; +import com.pancm.service.ITSysUserService; +import org.springframework.web.bind.annotation.*; + + +import com.pancm.vo.ApiResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + + + +/** +* @Title: 用户表(TSysUser)表控制层 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:51 +*/ +@Api(tags = "用户表(TSysUser)") +@RestController +@RequestMapping("tSysUser") +public class TSysUserController { + /** + * 服务对象 + */ + @Autowired + private ITSysUserService tSysUserService; + + + /** + * 新增一条数据 + * + * @param tSysUserVO 实体类 + * @return Response对象 + */ + @ApiOperation(value = "用户表新增",notes = "用户表新增") + @RequestMapping(value = "save", method = RequestMethod.POST) + public ApiResult insert(@RequestBody TSysUserVO tSysUserVO, HttpServletRequest httpRequest) { + int result = tSysUserService.insert(tSysUserVO); + if (result > 0) { + return ApiResult.success(); + } + return ApiResult.error("新增失败"); + } + + /** + * 修改一条数据 + * + * @param tSysUserVO 实体类 + * @return Response对象 + */ + @ApiOperation(value = "用户表修改",notes = "用户表修改") + @RequestMapping(value = "edit", method = RequestMethod.POST) + public ApiResult update(@RequestBody TSysUserVO tSysUserVO, HttpServletRequest httpRequest) { + tSysUserService.update(tSysUserVO); + return ApiResult.success(); + } + + /** + * 删除一条数据 + * + * @param tSysUserVO 参数对象 + * @return Response对象 + */ + @ApiOperation(value = "用户表删除",notes = "用户表删除") + @RequestMapping(value = "del", method = RequestMethod.POST) + public ApiResult delete(@RequestBody TSysUserVO tSysUserVO, HttpServletRequest httpRequest) { + tSysUserService.deleteById(tSysUserVO.getId()); + return ApiResult.success(); + } + + + + /** + * 分页查询 + * + */ + @ApiOperation(value = "用户表查询",notes = "用户表查询") + @RequestMapping(value = "list", method = RequestMethod.POST) + public ApiResult list(@RequestBody TSysUserVO tSysUserVO) { + return tSysUserService.list(tSysUserVO); + } + + /** + * 详情查询 + * + */ + @ApiOperation(value = "用户表详情",notes = "用户表详情") + @RequestMapping(value = "view", method = RequestMethod.GET) + public ApiResult view( @RequestParam("id") String id) { + return ApiResult.success(tSysUserService.queryById(id)); + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/controller/UserController.java b/springboot-saToken/src/main/java/com/pancm/controller/UserController.java new file mode 100644 index 0000000..94fa064 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/controller/UserController.java @@ -0,0 +1,103 @@ +package com.pancm.controller; + +import com.pancm.vo.UserVO; +import com.pancm.service.IUserService; +import org.springframework.web.bind.annotation.*; + + +import com.pancm.vo.ApiResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + + + +/** +* @Title: 用户表(User)表控制层 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-01-15 15:27:02 +*/ +@Api(tags = "用户表(User)") +@RestController +@RequestMapping("user") +public class UserController { + /** + * 服务对象 + */ + @Autowired + private IUserService userService; + + + /** + * 新增一条数据 + * + * @param userVO 实体类 + * @return Response对象 + */ + @ApiOperation(value = "用户表新增",notes = "用户表新增") + @RequestMapping(value = "save", method = RequestMethod.POST) + public ApiResult insert(@RequestBody UserVO userVO, HttpServletRequest httpRequest) { + int result = userService.insert(userVO); + if (result > 0) { + return ApiResult.success(); + } + return ApiResult.error("新增失败"); + } + + /** + * 修改一条数据 + * + * @param userVO 实体类 + * @return Response对象 + */ + @ApiOperation(value = "用户表修改",notes = "用户表修改") + @RequestMapping(value = "edit", method = RequestMethod.POST) + public ApiResult update(@RequestBody UserVO userVO, HttpServletRequest httpRequest) { + userService.update(userVO); + return ApiResult.success(); + } + + /** + * 删除一条数据 + * + * @param userVO 参数对象 + * @return Response对象 + */ + @ApiOperation(value = "用户表删除",notes = "用户表删除") + @RequestMapping(value = "del", method = RequestMethod.POST) + public ApiResult delete(@RequestBody UserVO userVO, HttpServletRequest httpRequest) { + userService.deleteById(userVO.getId()); + return ApiResult.success(); + } + + + + /** + * 分页查询 + * + */ + @ApiOperation(value = "用户表查询",notes = "用户表查询") + @RequestMapping(value = "list", method = RequestMethod.POST) + public ApiResult list(@RequestBody UserVO userVO) { + return userService.list(userVO); + } + + /** + * 详情查询 + * + */ + @ApiOperation(value = "用户表详情",notes = "用户表详情") + @RequestMapping(value = "view", method = RequestMethod.GET) + public ApiResult view( @RequestParam("id") Long id) { + return ApiResult.success(userService.queryById(id)); + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/dao/TSysUserDao.java b/springboot-saToken/src/main/java/com/pancm/dao/TSysUserDao.java new file mode 100644 index 0000000..c067c6f --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/dao/TSysUserDao.java @@ -0,0 +1,87 @@ +package com.pancm.dao; + +import com.pancm.model.TSysUser; +import com.pancm.vo.TSysUserVO; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + + /** +* @Title: 用户表(TSysUser)表数据库访问层 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:54 +*/ +@Mapper +public interface TSysUserDao extends BaseMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TSysUserVO queryById(String id); + + + /** + * 通过实体查询一条数据 + * + * @param tSysUserVO 实例对象 + * @return 对象列表 + */ + TSysUserVO findOne(TSysUserVO tSysUserVO); + + /** + * 通过实体作为筛选条件查询 + * + * @param tSysUserVO 实例对象 + * @return 对象列表 + */ + List queryAll(TSysUserVO tSysUserVO); + + /** + * 新增数据 + * + * @param tSysUser 实例对象 + * @return 影响行数 + */ + int insert(TSysUser tSysUser); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tSysUser 实例对象 + * @return 影响行数 + */ + int update(TSysUser tSysUser); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(String id); + +} + diff --git a/springboot-saToken/src/main/java/com/pancm/dao/UserDao.java b/springboot-saToken/src/main/java/com/pancm/dao/UserDao.java new file mode 100644 index 0000000..4992e68 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/dao/UserDao.java @@ -0,0 +1,88 @@ +package com.pancm.dao; + +import com.pancm.model.User; +import com.pancm.vo.UserVO; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import tk.mybatis.mapper.common.BaseMapper; + +import java.util.List; + + /** +* @Title: 用户表(User)表数据库访问层 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-01-15 15:27:04 +*/ +@Mapper +public interface UserDao { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + UserVO queryById(Long id); + + + /** + * 通过实体查询一条数据 + * + * @param userVO 实例对象 + * @return 对象列表 + */ + UserVO findOne(UserVO userVO); + + /** + * 通过实体作为筛选条件查询 + * + * @param userVO 实例对象 + * @return 对象列表 + */ + List queryAll(UserVO userVO); + + /** + * 新增数据 + * + * @param user 实例对象 + * @return 影响行数 + */ + int insert(User user); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param user 实例对象 + * @return 影响行数 + */ + int update(User user); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Long id); + +} + diff --git a/springboot-saToken/src/main/java/com/pancm/model/TSysUser.java b/springboot-saToken/src/main/java/com/pancm/model/TSysUser.java new file mode 100644 index 0000000..5ded285 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/model/TSysUser.java @@ -0,0 +1,61 @@ +package com.pancm.model; + + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Table; +import java.io.Serializable; +import java.sql.Date; + + /** +* @Title: 用户表(TSysUser)实体类 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:55 +*/ +@Data +@Table(name = "t_sys_user") +public class TSysUser implements Serializable { + private static final long serialVersionUID = -56958960669065369L; + /** + * 主键 + */ + @Column(name = "id") + private String id; + /** + * 用户账号 + */ + @Column(name = "username") + private String username; + /** + * 用户密码 + */ + @Column(name = "password") + private String password; + /** + * 昵称 + */ + @Column(name = "nickname") + private String nickname; + /** + * 部门id + */ + @Column(name = "dep_id") + private Integer depId; + /** + * 岗位id + */ + @Column(name = "pos_id") + private String posId; + + + @Override + public String toString(){ + return JSONObject.toJSONString(this); + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/model/User.java b/springboot-saToken/src/main/java/com/pancm/model/User.java new file mode 100644 index 0000000..d440a6c --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/model/User.java @@ -0,0 +1,71 @@ +package com.pancm.model; + + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Table; +import java.io.Serializable; +import java.sql.Date; + + /** +* @Title: 用户表(User)实体类 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-01-15 15:27:05 +*/ +@Data +@Table(name = "user") +public class User implements Serializable { + private static final long serialVersionUID = -59671741667391987L; + /** + * ID + */ + @Column(name = "id") + private Long id; + /** + * 姓名 + */ + @Column(name = "name") + private String name; + /** + * 性别 + */ + @Column(name = "sex") + private Integer sex; + /** + * 年龄 + */ + @Column(name = "age") + private Integer age; + /** + * 创建时间 + */ + @Column(name = "create_time") + private Date createTime; + /** + * 创建人 + */ + @Column(name = "create_by") + private String createBy; + /** + * 更新时间 + */ + @Column(name = "update_time") + private Date updateTime; + /** + * 更新人 + */ + @Column(name = "update_by") + private String updateBy; + + + @Override + public String toString(){ + return JSONObject.toJSONString(this); + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/service/ITSysUserService.java b/springboot-saToken/src/main/java/com/pancm/service/ITSysUserService.java new file mode 100644 index 0000000..77d97b4 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/service/ITSysUserService.java @@ -0,0 +1,62 @@ +package com.pancm.service; + +import com.pancm.vo.TSysUserVO; +import com.pancm.model.TSysUser; +import com.pancm.vo.ApiResult; +import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + + + /** +* @Title: 用户表(TSysUser)表服务接口 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:53 +*/ +public interface ITSysUserService extends IService{ + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TSysUserVO queryById(String id); + + + /** + * 通过实体作为筛选条件查询 + * + * @param tSysUserVO 实例对象 + * @return 对象列表 + */ + ApiResult list(TSysUserVO tSysUserVO); + + + /** + * 新增数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + int insert(TSysUserVO tSysUserVO); + + /** + * 修改数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + int update(TSysUserVO tSysUserVO); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + boolean deleteById(String id); + +} diff --git a/springboot-saToken/src/main/java/com/pancm/service/IUserService.java b/springboot-saToken/src/main/java/com/pancm/service/IUserService.java new file mode 100644 index 0000000..f87a804 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/service/IUserService.java @@ -0,0 +1,60 @@ +package com.pancm.service; + +import com.pancm.vo.UserVO; +import com.pancm.vo.ApiResult; +import java.util.List; + + + /** +* @Title: 用户表(User)表服务接口 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-01-15 15:27:03 +*/ +public interface IUserService { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + UserVO queryById(Long id); + + + /** + * 通过实体作为筛选条件查询 + * + * @param userVO 实例对象 + * @return 对象列表 + */ + ApiResult list(UserVO userVO); + + + /** + * 新增数据 + * + * @param userVO 实例对象 + * @return 实例对象 + */ + int insert(UserVO userVO); + + /** + * 修改数据 + * + * @param userVO 实例对象 + * @return 实例对象 + */ + int update(UserVO userVO); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + boolean deleteById(Long id); + +} diff --git a/springboot-saToken/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java b/springboot-saToken/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java new file mode 100644 index 0000000..da98bb8 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java @@ -0,0 +1,97 @@ +package com.pancm.service.impl; + + +import com.pancm.vo.TSysUserVO; +import com.pancm.model.TSysUser; +import com.pancm.dao.TSysUserDao; +import com.pancm.service.ITSysUserService; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import com.pancm.vo.ApiResult; +import com.pancm.vo.PageResult; +import org.springframework.stereotype.Service; +import org.springframework.beans.BeanUtils; +import javax.annotation.Resource; +import java.util.List; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + + + +/** +* @Title: 用户表(TSysUser)表服务实现类 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:54 +*/ +@Service("tSysUserService") +public class TSysUserServiceImpl extends ServiceImpl implements ITSysUserService { + @Resource + private TSysUserDao tSysUserDao; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + @Override + public TSysUserVO queryById(String id) { + return this.tSysUserDao.queryById(id); + } + + + /** + * 根据条件查询 + * + * @return 实例对象的集合 + */ + @Override + public ApiResult list(TSysUserVO tSysUser) { + int pageNum = tSysUser.getPageNum(); + int pageSize = tSysUser.getPageSize(); + Page page = PageHelper.startPage(pageNum, pageSize); + List result = tSysUserDao.queryAll(tSysUser); + return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum)); + + } + + /** + * 新增数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + @Override + public int insert(TSysUserVO tSysUserVO) { + TSysUser tSysUser = new TSysUser(); + BeanUtils.copyProperties(tSysUserVO,tSysUser); + return tSysUserDao.insert(tSysUser); + } + + /** + * 修改数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + @Override + public int update(TSysUserVO tSysUserVO) { + TSysUser tSysUser = new TSysUser(); + BeanUtils.copyProperties(tSysUserVO,tSysUser); + return tSysUserDao.update(tSysUser); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + @Override + public boolean deleteById(String id) { + return this.tSysUserDao.deleteById(id) > 0; + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/service/impl/UserServiceImpl.java b/springboot-saToken/src/main/java/com/pancm/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..a7a5268 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/service/impl/UserServiceImpl.java @@ -0,0 +1,96 @@ +package com.pancm.service.impl; + + +import com.pancm.vo.UserVO; +import com.pancm.model.User; +import com.pancm.dao.UserDao; +import com.pancm.service.IUserService; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import com.pancm.vo.ApiResult; +import com.pancm.vo.PageResult; +import org.springframework.stereotype.Service; +import org.springframework.beans.BeanUtils; +import javax.annotation.Resource; +import java.util.List; + + + +/** +* @Title: 用户表(User)表服务实现类 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-01-15 15:27:04 +*/ +@Service("userService") +public class UserServiceImpl implements IUserService { + @Resource + private UserDao userDao; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + @Override + public UserVO queryById(Long id) { + return this.userDao.queryById(id); + } + + + /** + * 根据条件查询 + * + * @return 实例对象的集合 + */ + @Override + public ApiResult list(UserVO user) { + int pageNum = user.getPageNum(); + int pageSize = user.getPageSize(); + Page page = PageHelper.startPage(pageNum, pageSize); + List result = userDao.queryAll(user); + return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum)); + + } + + /** + * 新增数据 + * + * @param userVO 实例对象 + * @return 实例对象 + */ + @Override + public int insert(UserVO userVO) { + User user = new User(); + BeanUtils.copyProperties(userVO,user); + return userDao.insert(user); + } + + /** + * 修改数据 + * + * @param userVO 实例对象 + * @return 实例对象 + */ + @Override + public int update(UserVO userVO) { + User user = new User(); + BeanUtils.copyProperties(userVO,user); + return userDao.update(user); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + @Override + public boolean deleteById(Long id) { + return this.userDao.deleteById(id) > 0; + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/util/FileHelper.java b/springboot-saToken/src/main/java/com/pancm/util/FileHelper.java new file mode 100644 index 0000000..b5fa52c --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/util/FileHelper.java @@ -0,0 +1,321 @@ +package com.pancm.util; + +import com.alibaba.fastjson.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.nio.charset.StandardCharsets; + + +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +public class FileHelper { + + private final static Logger log = LoggerFactory.getLogger(FileHelper.class); + + /** + * 行为单位读取文件,常用于读面向行的格式化文件 + * + * @param folder 文件目录 + * @param fileName 文件名 + * @return 文件内容,字符串格式 + */ + public static String readFileToString(String folder, String fileName) { + return readFileToString(folder + "/" + fileName); + } + + /** + * 以行为单位读取文件,常用于读面向行的格式化文件 + * + * @param filePath 文件路径 + * @return 文件内容,字符串 + */ + public static String readFileToString(String filePath) { + File file = new File(filePath); + BufferedReader reader = null; + StringBuilder builder = new StringBuilder(); + try { + reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); + String tempString = null; + int line = 1; + // 一次读入一行,直到读入null为文件结束 + while ((tempString = reader.readLine()) != null) { + // 显示行号 + builder.append(tempString); + } + reader.close(); + } catch (IOException e) { + throw new RuntimeException("file error#" + filePath, e); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e1) { + } + } + } + return builder.toString(); + } + + /** + * 读取文件,处理成 JSON格式 + * + * @param filePath 文件绝对路径 + * @return json格式 + */ + public static Object readFileToJson(String filePath) { + String content = FileHelper.readFileToString(filePath); + return JSONObject.parse(content); + } + + /** + * 相对路径转换为绝对路径 + * + * @param folderInput 相对路径,如./ + * @return 文件目录的绝对路径 + */ + public static String convertFolder(String folderInput) { + String folder = folderInput; + if (folderInput.startsWith("./")) { + String relativeFolder = folderInput.replace("./", ""); + String dir = System.getProperty("user.dir"); + folder = dir + "/" + relativeFolder; + } + return folder; + } + + + /** + * @return boolean + * @Author pancm + * @Description 创建文件夹--多层 + * @Date 2021/2/24 + * @Param [dir] + **/ + public static boolean createMultilayerFile(String dir) { + try { + File dirPath = new File(dir); + if (!dirPath.exists()) { + dirPath.mkdirs(); + } + } catch (Exception e) { + log.error("创建多层目录操作出错: " + e.getMessage()); + return false; + } + return true; + } + + + /** + * 文件本地存储 + * + * @param file 上传文件格式 + * @param destFolder 目标目录 + * @param destFileName 目标文件名 + * @return + */ + public static boolean saveFile(MultipartFile file, String destFolder, String destFileName) { + File dest = new File(destFolder + "/" + destFileName); +// if(!dest.getParentFile().exists()){ +// dest.getParentFile().mkdir(); +// } + createMultilayerFile(destFolder); + try { + file.transferTo(dest); + return true; + } catch (Exception e) { + log.error("file save error", e); + } + return false; + } + + + public static boolean saveFile(byte[] buf, String filePath, String fileName) { + BufferedOutputStream bos = null; + FileOutputStream fos = null; + File file = null; + try { + createMultilayerFile(filePath); + file = new File(filePath + File.separator + fileName); + fos = new FileOutputStream(file); + bos = new BufferedOutputStream(fos); + bos.write(buf); + } catch (Exception e) { + log.error("file save error", e); + return false; + } finally { + if (bos != null) { + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return true; + } + + + /** + * 文件大小,单位 MB + * + * @param size 文件大小,单位byte + * @return 文件大小,MB + */ + public static long getSizeInMb(long size) { + return size / 1024 / 1024; + } + + /** + * 文件大小,单位 GB + * + * @param size 文件大小,单位byte + * @return 文件大小,GB + */ + public static long getSizeInGb(long size) { + return size / 1024 / 1024 / 1024; + } + + /** + * 获得文件扩展名 + * + * @param fileName 文件名 + * @return 扩展名,dot 后面的,如xls + */ + public static String getFileExtension(String fileName) { + if (fileName == null) { + return null; + } + int index = fileName.lastIndexOf("."); + if (index == -1) { + return null; + } + return fileName.substring(index + 1); + } + + /** + * 删除文件 + * + * @param folder 目录 + * @param fileName 文件名 + * @return 删除是否成功 + */ + public static boolean deleteFile(String folder, String fileName) { + return deleteFile(folder + "/" + fileName); + } + + /** + * 删除文件 + * + * @param filePath 文件的绝对路径 + * @return 删除是否成功 + */ + public static boolean deleteFile(String filePath) { + if (filePath == null) { + return false; + } + try { + File f = new File(filePath); + if (f.exists()) { + return f.delete(); + } + } catch (Exception ex) { + log.error("delete file error#" + filePath, ex); + } + return false; + } + + + public static String readResourcesFile(String path) { + StringBuilder sb = new StringBuilder(); + try (InputStream in = FileHelper.class.getClassLoader().getResourceAsStream(path)) { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String msg = null; + while ((msg = reader.readLine()) != null) { + sb.append(msg); +// .append("\n") + } + + } catch (IOException e) { + log.error("read file error#", e); + } + return sb.toString(); + } + + + /** + * @Author beixing + * @Description 文件夹复制 + * @Date 2021/4/27 + * @Param + * @return + **/ + public static void copyFolder(String src, String des) { + //初始化文件复制 + File file1 = new File(src); + //把文件里面内容放进数组 + File[] fs = file1.listFiles(); + //初始化文件粘贴 + File file2 = new File(des); + //判断是否有这个文件有不管没有创建 + if (!file2.exists()) { + file2.mkdirs(); + } + //遍历文件及文件夹 + for (File f : fs) { + if (f.isFile()) { + ///调用文件拷贝的方法 + fileCopy(f.getPath(), des + File.separator + f.getName()); + } else if (f.isDirectory()) { + //文件夹 + copyFolder(f.getPath(), des + File.separator + f.getName()); + } + } + + } + + /** + * 文件复制的具体方法 + */ + public static void fileCopy(String src, String des) { + //io流固定格式 + try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src)); + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(des))) { + int i = -1;//记录获取长度 + byte[] bt = new byte[2014];//缓冲区 + while ((i = bis.read(bt)) != -1) { + bos.write(bt, 0, i); + } + } catch (IOException e) { + log.error("read file error#", e); + } + } + + + public static void main(String[] args) { + String source = "D:\\video\\ceshi\\2021\\4\\26\\18\\34020000001310000001"; + String target = "D:\\video\\diagnosis\\2021\\4\\26\\18\\34020000001310000001"; +// copyFolder(source,target); + + String srcFile = "D:\\video\\ceshi\\2021\\5\\7\\10\\34020000001310000001\\34020000001310000001_20210507105454_00001.jpg"; + String desFile = "D:\\video\\34020000001310000001_20210507105454_测试.jpg"; + fileCopy(srcFile,desFile); + + } + + +} diff --git a/springboot-saToken/src/main/java/com/pancm/util/GetProperties.java b/springboot-saToken/src/main/java/com/pancm/util/GetProperties.java new file mode 100644 index 0000000..7c580e8 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/util/GetProperties.java @@ -0,0 +1,94 @@ +package com.pancm.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.*; +import java.util.Map.Entry; + +/** + * Title: getProperties + * Description: 获取配置文件 + * Version:1.0.0 + * + * @author pancm + * @date 2018年1月4日 + */ +public class GetProperties { + private static Map appSettings = new HashMap(); + private static final Logger LOG = LoggerFactory.getLogger(GetProperties.class); + private String pathName="build.properties"; + /** + * 初始化系统默认参数 + */ + private GetProperties(){ + init(); + } + + private void init(){ + InputStream in = null; + try{ + //获取resource中的配置 + in=this.getClass().getClassLoader().getResourceAsStream(pathName); + //获取项目同级的配置 +// in=new FileInputStream(new File(pathName)); + Properties prop = new Properties(); + prop.load(in); + Set> buf = prop.entrySet(); + Iterator> it = buf.iterator(); + while(it.hasNext()){ + Entry t = it.next(); + appSettings.put((String)t.getKey(), (String)t.getValue()); + } + }catch(IOException e){ + LOG.error("加载系统参数失败!",e); + }finally{ + if(null != in){ + try { + in.close(); + } catch (IOException e) { + LOG.error("加载系统参数失败!",e); + } + } + } + } + + /** + * 获取配置文件 + * + * @param + * @return app settings + */ + public synchronized static Map getAppSettings() { + if(null == appSettings || appSettings.isEmpty()){ + new GetProperties(); + } + return appSettings; + } + + /** + * Sets app settings. + * + * @param appSettings the app settings + * @param name the name + */ + public synchronized static void setAppSettings(Map appSettings,String name) { + if(null == appSettings || appSettings.isEmpty()){ + new GetProperties(); + } + GetProperties.appSettings = appSettings; + } + + /** + * 方法测试 + * + * @param args the input arguments + */ + public static void main(String[] args) { + Map conf = GetProperties.getAppSettings(); + System.out.println(conf); + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/vo/ApiResult.java b/springboot-saToken/src/main/java/com/pancm/vo/ApiResult.java new file mode 100644 index 0000000..cbd77fe --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/vo/ApiResult.java @@ -0,0 +1,92 @@ +package com.pancm.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +import static com.pancm.vo.BaseConstants.CODE_ERROR_UNKNOWN; +import static com.pancm.vo.BaseConstants.CODE_SUCCESS; +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +@Data +@ApiModel(value = "返回值", description="通用返回值") +public class ApiResult implements Serializable { + + private static final long serialVersionUID = 10000000L; + + @ApiModelProperty(value = "返回状态码;0:成功;其它,失败") + private int code; + + @ApiModelProperty(value = "补充信息,显示给前端用户") + private String message; + + @ApiModelProperty(value = "接口请求结果") + private T data; + + @ApiModelProperty(value = "异常的堆栈信息") + private Object stackTrace; + + public ApiResult message(String input) { + this.setMessage(input); + return this; + } + + public ApiResult appendMessage(String input) { + this.message += " " + input; + return this; + } + + public ApiResult data(T input) { + this.setData(input); + return this; + } + + public static ApiResult success() { + ApiResult resultMsg = new ApiResult(); + resultMsg.setCode(CODE_SUCCESS); + resultMsg.setMessage(""); + return resultMsg; + } + + public static ApiResult success(Object data) { + ApiResult resultMsg = new ApiResult(); + resultMsg.setCode(CODE_SUCCESS); + resultMsg.setData(data); + resultMsg.setMessage(""); + return resultMsg; + } + + public static ApiResult error(String message) { + return error(CODE_ERROR_UNKNOWN, message); + } + + public static ApiResult error(int code, String message) { + ApiResult resultMsg = new ApiResult(); + resultMsg.setCode(code); + resultMsg.setMessage(message); + return resultMsg; + } + + + public static ApiResult error(int code, String message, Object... data) { + ApiResult resultMsg = new ApiResult(); + resultMsg.setCode(code); + resultMsg.setMessage(message); + if (data != null) { + if (data.length >= 1) { + resultMsg.setData(data[0]); + } + if (data.length >= 2) { + resultMsg.setStackTrace(data[1]); + } + } + return resultMsg; + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/vo/BaseConstants.java b/springboot-saToken/src/main/java/com/pancm/vo/BaseConstants.java new file mode 100644 index 0000000..9a467e5 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/vo/BaseConstants.java @@ -0,0 +1,42 @@ +package com.pancm.vo; + +/** + * @Author pancm + * @Description + * @Date 2019/2/17 + * @Param + * @return + **/ +public class BaseConstants { + + public static String CONSTANT_MODULE_TYPE_STRING = "string"; + public static String CONSTANT_MODULE_TYPE_INT = "int"; + + public static String SEPARATOR_SPACE = " "; + public static String SEPARATOR_COMMA = ", "; + public static String SEPARATOR_DOT = "."; + public static String SEPARATOR_LINE = "\n"; + + public static int DATE_RANGE_ARRAY_SIZE = 2; + + /** + * excel 相关 + */ + public static final int EXCEL_MAX_EMPTY_HEADER_COUNT = 50; + public static final int EXCEL_ROW_TYPE_SKIP = 1; + public static final int EXCEL_ROW_TYPE_NORMAL = 0; + + public static final String IP_SPLIT_SEPARATOR = "\\."; + + /** + * 校验类,合法的mac地址长度 + */ + public static int VALID_MAC_LENGTH = 17; + public static int VALID_MIN_MAC_LENGTH = 12; + public static int VALID_IP_MAX_LENGTH = 15; + + public static int IP_ASSIGN_LAST = 254; + + public static int CODE_ERROR_UNKNOWN = 5000; + public static int CODE_SUCCESS = 0; +} diff --git a/springboot-saToken/src/main/java/com/pancm/vo/BasePage.java b/springboot-saToken/src/main/java/com/pancm/vo/BasePage.java new file mode 100644 index 0000000..ae705bd --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/vo/BasePage.java @@ -0,0 +1,74 @@ +package com.pancm.vo; + +import com.alibaba.fastjson.annotation.JSONField; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.util.StringUtils; + + +import java.util.List; + +@ApiModel +@Data +public class BasePage { + + /** + * 页码 + * 必须定义为 protected or public,否则子类不可见 + */ + @ApiModelProperty(name = "page_num",value = "分页 - 第几页") + protected Integer pageNum=1; + + /** + * 页大小 + */ + @ApiModelProperty(name = "page_num",value = "分页 - 每页记录数") + protected Integer pageSize=10; + + /** + * 排序字段名称 + */ + @ApiModelProperty(name = "sort_name",value = "分页 - 排序列名") + protected String sortName; + + /** + * 排序方式 + */ + @ApiModelProperty(name = "sort_order",value = "分页 - 排序方式,asc/desc") + protected String sortOrder; + + @ApiModelProperty(name = "date", value = "起止日期") + @JSONField(name = "date") + protected List dateRange; + + protected String startDate; + + protected String endDate; + + /** + * 默认排序 + */ + protected String defaultOrder; + + /** + * 排序字符串 + */ + protected String orderString; + + public String getOrderBy() { + if (!StringUtils.isEmpty(this.sortName) && !StringUtils.isEmpty(this.sortOrder)) { + String orderBy = this.sortName + " " + this.sortOrder; + if (!StringUtils.isEmpty(this.defaultOrder) && !orderBy.equals(defaultOrder)) { + orderBy += ", " + defaultOrder; + } + return orderBy.replaceAll(".*([';]+|(--)+).*", " "); + } + if (!StringUtils.isEmpty(this.defaultOrder)) { + return defaultOrder.replaceAll(".*([';]+|(--)+).*", " "); + } + return null; + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/vo/PageResult.java b/springboot-saToken/src/main/java/com/pancm/vo/PageResult.java new file mode 100644 index 0000000..63b76f6 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/vo/PageResult.java @@ -0,0 +1,30 @@ +package com.pancm.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class PageResult implements Serializable { + + private static final long serialVersionUID = 10000001L; + + @JSONField(name = "total") + private long totalNum; + + private List list; + + private int pageSize; + + @JSONField(name = "currentPage") + private int pageNum; + + public PageResult(long totalNum, List list, int pageSize, int pageNum) { + this.totalNum = totalNum; + this.list = list; + this.pageSize = pageSize; + this.pageNum = pageNum; + } +} diff --git a/springboot-saToken/src/main/java/com/pancm/vo/TSysUserVO.java b/springboot-saToken/src/main/java/com/pancm/vo/TSysUserVO.java new file mode 100644 index 0000000..5bcfc34 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/vo/TSysUserVO.java @@ -0,0 +1,61 @@ +package com.pancm.vo; + +import java.io.Serializable; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.sql.Date; +import com.pancm.vo.BasePage; + +/** +* @Title: 用户表(TSysUser)请求响应对象 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:54 +*/ +@ApiModel(value = "TSysUser", description = "用户表") +@Data +public class TSysUserVO extends BasePage implements Serializable { + private static final long serialVersionUID = 855666123415935768L; + /** + * 主键 + */ + @ApiModelProperty(value = "主键") + private String id; + /** + * 用户账号 + */ + @ApiModelProperty(value = "用户账号") + private String username; + /** + * 用户密码 + */ + @ApiModelProperty(value = "用户密码") + private String password; + /** + * 昵称 + */ + @ApiModelProperty(value = "昵称") + private String nickname; + /** + * 部门id + */ + @ApiModelProperty(value = "部门id") + private Integer depId; + /** + * 岗位id + */ + @ApiModelProperty(value = "岗位id") + private String posId; + + + + @Override + public String toString(){ + return JSONObject.toJSONString(this); + } + +} diff --git a/springboot-saToken/src/main/java/com/pancm/vo/UserVO.java b/springboot-saToken/src/main/java/com/pancm/vo/UserVO.java new file mode 100644 index 0000000..3a3e035 --- /dev/null +++ b/springboot-saToken/src/main/java/com/pancm/vo/UserVO.java @@ -0,0 +1,71 @@ +package com.pancm.vo; + +import java.io.Serializable; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.sql.Date; +import com.pancm.vo.BasePage; + +/** +* @Title: 用户表(User)请求响应对象 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-01-15 15:27:05 +*/ +@ApiModel(value = "User", description = "用户表") +@Data +public class UserVO extends BasePage implements Serializable { + private static final long serialVersionUID = 887744157417771761L; + /** + * ID + */ + @ApiModelProperty(value = "ID") + private Long id; + /** + * 姓名 + */ + @ApiModelProperty(value = "姓名") + private String name; + /** + * 性别 + */ + @ApiModelProperty(value = "性别") + private Integer sex; + /** + * 年龄 + */ + @ApiModelProperty(value = "年龄") + private Integer age; + /** + * 创建时间 + */ + @ApiModelProperty(value = "创建时间") + private Date createTime; + /** + * 创建人 + */ + @ApiModelProperty(value = "创建人") + private String createBy; + /** + * 更新时间 + */ + @ApiModelProperty(value = "更新时间") + private Date updateTime; + /** + * 更新人 + */ + @ApiModelProperty(value = "更新人") + private String updateBy; + + + + @Override + public String toString(){ + return JSONObject.toJSONString(this); + } + +} diff --git a/springboot-saToken/src/main/resources/application-dev.yml b/springboot-saToken/src/main/resources/application-dev.yml new file mode 100644 index 0000000..e1f3514 --- /dev/null +++ b/springboot-saToken/src/main/resources/application-dev.yml @@ -0,0 +1,14 @@ +server: + port: 9876 + servlet: + context-path: /api + + +spring: + datasource: + pancm: + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/pcm?autoReconnect=true&failOverReadOnly=false&characterEncoding=utf-8&useUnicode=true&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useSSL=false + username: root + password: 123456 + diff --git a/springboot-saToken/src/main/resources/application-local.yml b/springboot-saToken/src/main/resources/application-local.yml new file mode 100644 index 0000000..e1f3514 --- /dev/null +++ b/springboot-saToken/src/main/resources/application-local.yml @@ -0,0 +1,14 @@ +server: + port: 9876 + servlet: + context-path: /api + + +spring: + datasource: + pancm: + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/pcm?autoReconnect=true&failOverReadOnly=false&characterEncoding=utf-8&useUnicode=true&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useSSL=false + username: root + password: 123456 + diff --git a/springboot-saToken/src/main/resources/application.yml b/springboot-saToken/src/main/resources/application.yml new file mode 100644 index 0000000..7e3b507 --- /dev/null +++ b/springboot-saToken/src/main/resources/application.yml @@ -0,0 +1,5 @@ +spring: + profiles: + active: local + application: + name: springboot-demo diff --git a/springboot-saToken/src/main/resources/build.properties b/springboot-saToken/src/main/resources/build.properties new file mode 100644 index 0000000..0ab57c4 --- /dev/null +++ b/springboot-saToken/src/main/resources/build.properties @@ -0,0 +1,4 @@ +build_app = springboot-demo +build_time = 2024-01-15 15:48:50 +git_commit = +git_branch = diff --git a/springboot-saToken/src/main/resources/logback.xml b/springboot-saToken/src/main/resources/logback.xml new file mode 100644 index 0000000..d3a98db --- /dev/null +++ b/springboot-saToken/src/main/resources/logback.xml @@ -0,0 +1,79 @@ + + + + + + + |%d{yyyy-MM-dd HH:mm:ss.SSS}|[%thread]|%-5level|%replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''}|-%msg%n| + + + + + + + ${LOG_HOME}/msgInfo-%d{yyyy-MM-dd}.%i.log + + 10MB + 15 + 10GB + + + + |%d{yyyy-MM-dd HH:mm:ss.SSS}|[%thread]|%-5level|%logger{50}|-%msg%n + + + + + + + + + ${LOG_HOME}/msgDebug-%d{yyyy-MM-dd}.%i.log + + 10MB + 7 + 10GB + + + DEBUG + ACCEPT + DENY + + + + |%d{yyyy-MM-dd HH:mm:ss.SSS}|[%thread]|%-5level|%logger{50}|-%msg%n + + + + + + + + + ${LOG_HOME}/msgError-%d{yyyy-MM-dd}.%i.log + + 10MB + 7 + 10GB + + + ERROR + ACCEPT + DENY + + + + |%d{yyyy-MM-dd HH:mm:ss.SSS}|[%thread]|%-5level|%logger{50}|-%msg%n + + + + + + + + + + + + + diff --git a/springboot-saToken/src/main/resources/pancm/mapper/DbVersionMapper.xml b/springboot-saToken/src/main/resources/pancm/mapper/DbVersionMapper.xml new file mode 100644 index 0000000..6302933 --- /dev/null +++ b/springboot-saToken/src/main/resources/pancm/mapper/DbVersionMapper.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/springboot-saToken/src/main/resources/pancm/mapper/TSysUserMapper.xml b/springboot-saToken/src/main/resources/pancm/mapper/TSysUserMapper.xml new file mode 100644 index 0000000..5682b64 --- /dev/null +++ b/springboot-saToken/src/main/resources/pancm/mapper/TSysUserMapper.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + insert into t_sys_user(username, password, nickname, dep_id, pos_id) + values (#{username}, #{password}, #{nickname}, #{depId}, #{posId}) + + + + insert into t_sys_user(username, password, nickname, dep_id, pos_id) + values + + (#{entity.username}, #{entity.password}, #{entity.nickname}, #{entity.depId}, #{entity.posId}) + + + + + insert into t_sys_user(username, password, nickname, dep_id, pos_id) + values + + (#{entity.username}, #{entity.password}, #{entity.nickname}, #{entity.depId}, #{entity.posId}) + + on duplicate key update +username = values(username) , password = values(password) , nickname = values(nickname) , dep_id = values(dep_id) , pos_id = values(pos_id) + + + + update t_sys_user + + + username = #{username}, + + + password = #{password}, + + + nickname = #{nickname}, + + + dep_id = #{depId}, + + + pos_id = #{posId}, + + + where id = #{id} + + + + + delete from t_sys_user where id = #{id} + + + + diff --git a/springboot-saToken/src/main/resources/pancm/mapper/UserMapper.xml b/springboot-saToken/src/main/resources/pancm/mapper/UserMapper.xml new file mode 100644 index 0000000..7a9342f --- /dev/null +++ b/springboot-saToken/src/main/resources/pancm/mapper/UserMapper.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into user(name, sex, age, create_time, create_by, update_time, update_by) + values (#{name}, #{sex}, #{age}, #{createTime}, #{createBy}, #{updateTime}, #{updateBy}) + + + + insert into user(name, sex, age, create_time, create_by, update_time, update_by) + values + + (#{entity.name}, #{entity.sex}, #{entity.age}, #{entity.createTime}, #{entity.createBy}, #{entity.updateTime}, #{entity.updateBy}) + + + + + insert into user(name, sex, age, create_time, create_by, update_time, update_by) + values + + (#{entity.name}, #{entity.sex}, #{entity.age}, #{entity.createTime}, #{entity.createBy}, #{entity.updateTime}, #{entity.updateBy}) + + on duplicate key update +name = values(name) , sex = values(sex) , age = values(age) , create_time = values(create_time) , create_by = values(create_by) , update_time = values(update_time) , update_by = values(update_by) + + + + update user + + + name = #{name}, + + + sex = #{sex}, + + + age = #{age}, + + + create_time = #{createTime}, + + + create_by = #{createBy}, + + + update_time = #{updateTime}, + + + update_by = #{updateBy}, + + + where id = #{id} + + + + + delete from user where id = #{id} + + + + diff --git a/springboot-saToken/src/main/resources/pancm/mybatis-config.xml b/springboot-saToken/src/main/resources/pancm/mybatis-config.xml new file mode 100644 index 0000000..bd2d7b7 --- /dev/null +++ b/springboot-saToken/src/main/resources/pancm/mybatis-config.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/springboot-saToken/src/main/resources/version.txt b/springboot-saToken/src/main/resources/version.txt new file mode 100644 index 0000000..621cb01 --- /dev/null +++ b/springboot-saToken/src/main/resources/version.txt @@ -0,0 +1 @@ +V1.0.1 diff --git a/springboot-saToken/start.sh b/springboot-saToken/start.sh new file mode 100644 index 0000000..a9c873b --- /dev/null +++ b/springboot-saToken/start.sh @@ -0,0 +1,11 @@ +APPDIR=`pwd` +PIDFILE=$APPDIR/springboot-demo.pid +if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then +echo "springboot-demo is already running..." +exit 1 +fi +nohup java -jar $APPDIR/springboot-demo.jar >/dev/null 2>&1 & +echo $! > $PIDFILE +echo "start springboot-demo..." + + diff --git a/springboot-saToken/stop.sh b/springboot-saToken/stop.sh new file mode 100644 index 0000000..69dbc4c --- /dev/null +++ b/springboot-saToken/stop.sh @@ -0,0 +1,13 @@ +APPDIR=`pwd` +PIDFILE=$APPDIR/springboot-demo.pid +if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then +echo "springboot-demo not running..." +else +echo "stopping springboot-demo..." +PID="$(cat "$PIDFILE")" +kill -9 $PID +rm "$PIDFILE" +echo "...springboot-demo stopped" +fi + +