commit f185add54695a14f3f1ff197c469d6efde02d377 Author: 冷冷 Date: Mon Jul 23 15:25:22 2018 +0800 :bookmark: v1.2.3 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..afff4db4b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +root = true + +# 对所有文件生效 +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{java,xml}] +indent_style = tab +indent_size = 4 + +[*.{yml,json}] +indent_style = space +indent_size = 2 + +# 对后缀名为 md 的文件生效 +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..956f4e305 --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +### gradle ### +.gradle +/build/ +!gradle/wrapper/gradle-wrapper.jar + +### STS ### +.settings/ +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +rebel.xml + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +### maven ### +target/ +*.war +*.ear +*.zip +*.tar +*.tar.gz + +### logs #### +logs + +### temp ignore ### +*.log +*.cache +*.diff +*.patch +*.tmp +*.java~ +*.properties~ +*.xml~ + +### system ignore ### +.DS_Store +Thumbs.db +Servers +.metadata +upload +gen_code diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..b1bc6888b --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ + Copyright (c) 2018-2025, lengleng All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + Neither the name of the pig4cloud.com developer nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + Author: lengleng (wangiegie@gmail.com) diff --git a/README.md b/README.md new file mode 100644 index 000000000..16504adaa --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +

+ Build Status + Coverage Status + Downloads +

+ +

Supporting Pig Developer Team

+ +## 项目官网 +https://pig4cloud.com + +### 配套代码 +pigx-ui + +### pigx 和 pig 区别 + +- 基于最新的Spring Cloud Finchley.RELEASE 版本 +- 完整的oAuth 流程,资源服务器控制权限 +- 去除了部分对于开发不友好的中间件 + +### 部署说明 +[部署说明](doc/deploy.md) + +## 协议和授权 + +pigX并非一个开源软件,作者保留全部的权利。 + +### 🌹权益 + +1. 个人使用 +2. 允许用于学习、毕设等。 + +### 🚫禁止 + +1. 将本项目的部分或全部代码和资源进行任何形式的再发行(尤其上传GitHub、Gitee ) +2. 利用本项目的部分或全部代码和资源进行`任何商业行为` +3. 举报有奖,抢先体验`pigx 2.0`。 + +## 贡献代码 + +pigX并非一个开源项目,也不是社区共同创造,其全部功能由作者独立完成。 + +如果你愿意放弃所有权利,并将权利无条件转让给pigX作者,欢迎您贡献代码,当然会给予不等金额奖励。 + +## 提交反馈 + +1. 欢迎提交 issue,请写清楚遇到问题的原因,浏览器和操作系统环境,重现的流程。 +如果有开发能力,建议在本地调试出出错的代码。 + +2. 不接受`功能请求`的 issue,功能请求可能会被直接关闭,请谅解(正确的方式是打赏并附言)。 + diff --git a/doc/PIGX.png b/doc/PIGX.png new file mode 100644 index 000000000..5f7a010cf Binary files /dev/null and b/doc/PIGX.png differ diff --git a/doc/deploy.md b/doc/deploy.md new file mode 100644 index 000000000..bdf9330a1 --- /dev/null +++ b/doc/deploy.md @@ -0,0 +1,58 @@ +### 写在最前 +**如果想快速部署pigX,请完全参考本篇文档,如果有个性化的修改(例如:oauth2配置、token 个性化需求),请参考本篇运行起来以后,自行修改。循序渐进** + +### 架构图 +![image](http://p0hpm86wj.bkt.clouddn.com/PIGX.png) +### 一、项目下载 + +``` +git https://www.gitee.wang/pig/pigx.git +``` + +### 二、配置数据库 + +``` +版本: mysql5.7+ + +``` +基本参数如下: +![image](https://gitee.com/uploads/images/2018/0610/142651_72fad599_410595.png) + + +### 三、pig配置修改 +pigx/pigx-config/src/main/resources/config/application-dev.yml + +``` +# redis 相关 +spring: + redis: + password: + host: localhost +``` +pigx/pigx-config/src/main/resources/config/pigx-auth-dev.yml +pigx/pigx-config/src/main/resources/config/pigx-upms-dev.yml + +``` +# 数据源 +spring: + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.jdbc.Driver + username: root + password: lengleng + url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false +``` + + +### 四、pigx-ui: + +``` +git clone https://www.gitee.wang/pig/pigx-ui.git +npm run dev +``` +请确保启动顺序 +1.eureka +2.config +3.gateway +4.auth +5.upms diff --git a/doc/pigx.sql b/doc/pigx.sql new file mode 100644 index 000000000..f11c17c43 --- /dev/null +++ b/doc/pigx.sql @@ -0,0 +1,270 @@ +/* + Navicat Premium Data Transfer + + Source Server : 139.224.200.249 + Source Server Type : MySQL + Source Server Version : 50721 + Source Host : 139.224.200.249 + Source Database : pigx + + Target Server Type : MySQL + Target Server Version : 50721 + File Encoding : utf-8 + + Date: 06/26/2018 21:52:22 PM +*/ + +SET NAMES utf8; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for `sys_dept` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_dept`; +CREATE TABLE `sys_dept` ( + `dept_id` int(20) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL COMMENT '部门名称', + `order_num` int(11) DEFAULT NULL COMMENT '排序', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + `del_flag` char(1) DEFAULT '0' COMMENT '是否删除 -1:已删除 0:正常', + `parent_id` int(11) DEFAULT NULL, + PRIMARY KEY (`dept_id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='部门管理'; + +-- ---------------------------- +-- Records of `sys_dept` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_dept` VALUES ('1', '山东农信', null, '2018-01-22 19:00:23', '2018-01-23 12:40:46', '0', '0'), ('2', '沙县国际', null, '2018-01-22 19:00:38', '2018-01-23 12:42:04', '0', '0'), ('3', '潍坊农信', null, '2018-01-22 19:00:44', '2018-01-23 12:40:56', '0', '1'), ('4', '高新农信', null, '2018-01-22 19:00:52', '2018-01-23 12:41:11', '0', '3'), ('5', '院校农信', null, '2018-01-22 19:00:57', '2018-01-23 12:41:22', '0', '4'), ('6', '潍坊学院农信', '115', '2018-01-22 19:01:06', '2018-03-07 16:22:04', '0', '5'), ('7', '山东沙县', null, '2018-01-22 19:01:57', '2018-01-23 12:42:15', '0', '2'), ('8', '潍坊沙县', null, '2018-01-22 19:02:03', '2018-01-23 12:42:23', '0', '7'), ('9', '高新沙县', null, '2018-01-22 19:02:14', '2018-03-07 16:28:14', '0', '8'), ('10', '测试', '110', '2018-06-26 21:26:59', '2018-06-26 21:27:14', '1', '5'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_dept_relation` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_dept_relation`; +CREATE TABLE `sys_dept_relation` ( + `ancestor` int(11) NOT NULL COMMENT '祖先节点', + `descendant` int(11) NOT NULL COMMENT '后代节点', + PRIMARY KEY (`ancestor`,`descendant`), + KEY `idx1` (`ancestor`), + KEY `idx2` (`descendant`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Records of `sys_dept_relation` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_dept_relation` VALUES ('1', '1'), ('1', '3'), ('1', '4'), ('1', '5'), ('1', '6'), ('2', '2'), ('2', '7'), ('2', '8'), ('2', '9'), ('3', '3'), ('3', '4'), ('3', '5'), ('3', '6'), ('4', '4'), ('4', '5'), ('4', '6'), ('5', '5'), ('5', '6'), ('6', '6'), ('7', '7'), ('7', '8'), ('7', '9'), ('8', '8'), ('8', '9'), ('9', '9'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_dict` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_dict`; +CREATE TABLE `sys_dict` ( + `id` int(64) NOT NULL AUTO_INCREMENT COMMENT '编号', + `value` varchar(100) NOT NULL COMMENT '数据值', + `label` varchar(100) NOT NULL COMMENT '标签名', + `type` varchar(100) NOT NULL COMMENT '类型', + `description` varchar(100) NOT NULL COMMENT '描述', + `sort` decimal(10,0) NOT NULL COMMENT '排序(升序)', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `remarks` varchar(255) DEFAULT NULL COMMENT '备注信息', + `del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标记', + PRIMARY KEY (`id`), + KEY `sys_dict_value` (`value`), + KEY `sys_dict_label` (`label`), + KEY `sys_dict_del_flag` (`del_flag`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='字典表'; + +-- ---------------------------- +-- Records of `sys_dict` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_dict` VALUES ('2', '9', '异常', 'log_type', '日志异常', '1', '2017-12-28 13:06:39', '2018-01-06 10:54:41', null, '0'), ('3', '0', '正常', 'log_type', '正常', '1', '2018-05-11 23:52:57', '2018-05-11 23:52:57', '123', '0'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_log` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_log`; +CREATE TABLE `sys_log` ( + `id` bigint(64) NOT NULL AUTO_INCREMENT COMMENT '编号', + `type` char(1) DEFAULT '1' COMMENT '日志类型', + `title` varchar(255) DEFAULT '' COMMENT '日志标题', + `service_id` varchar(32) DEFAULT NULL COMMENT '服务ID', + `create_by` varchar(64) DEFAULT NULL COMMENT '创建者', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `remote_addr` varchar(255) DEFAULT NULL COMMENT '操作IP地址', + `user_agent` varchar(1000) DEFAULT NULL COMMENT '用户代理', + `request_uri` varchar(255) DEFAULT NULL COMMENT '请求URI', + `method` varchar(10) DEFAULT NULL COMMENT '操作方式', + `params` text COMMENT '操作提交的数据', + `time` mediumtext COMMENT '执行时间', + `del_flag` char(1) DEFAULT '0' COMMENT '删除标记', + `exception` text COMMENT '异常信息', + PRIMARY KEY (`id`), + KEY `sys_log_create_by` (`create_by`), + KEY `sys_log_request_uri` (`request_uri`), + KEY `sys_log_type` (`type`), + KEY `sys_log_create_date` (`create_time`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='日志表'; + +-- ---------------------------- +-- Table structure for `sys_menu` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_menu`; +CREATE TABLE `sys_menu` ( + `menu_id` int(11) NOT NULL COMMENT '菜单ID', + `name` varchar(32) NOT NULL COMMENT '菜单名称', + `permission` varchar(32) DEFAULT NULL COMMENT '菜单权限标识', + `path` varchar(128) DEFAULT NULL COMMENT '前端URL', + `parent_id` int(11) DEFAULT NULL COMMENT '父菜单ID', + `icon` varchar(32) DEFAULT NULL COMMENT '图标', + `component` varchar(64) DEFAULT NULL COMMENT 'VUE页面', + `sort` int(11) DEFAULT '1' COMMENT '排序值', + `type` char(1) DEFAULT NULL COMMENT '菜单类型 (0菜单 1按钮)', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `del_flag` char(1) DEFAULT '0' COMMENT '0--正常 1--删除', + PRIMARY KEY (`menu_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='菜单权限表'; + +-- ---------------------------- +-- Records of `sys_menu` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_menu` VALUES ('1', '系统管理', null, '/admin', '-1', 'icon-xitongguanli', 'Layout', '1', '0', '2017-11-07 20:56:00', '2018-05-14 21:53:22', '0'), ('2', '用户管理', null, 'user', '1', 'icon-yonghuguanli', 'views/admin/user/index', '2', '0', '2017-11-02 22:24:37', '2018-05-14 22:11:35', '0'), ('3', '菜单管理', null, 'menu', '1', 'icon-caidanguanli', 'views/admin/menu/index', '3', '0', '2017-11-08 09:57:27', '2018-05-14 22:11:21', '0'), ('4', '角色管理', null, 'role', '1', 'icon-jiaoseguanli', 'views/admin/role/index', '4', '0', '2017-11-08 10:13:37', '2018-05-14 22:11:19', '0'), ('5', '日志管理', null, 'log', '1', 'icon-rizhiguanli', 'views/admin/log/index', '5', '0', '2017-11-20 14:06:22', '2018-05-14 22:11:18', '0'), ('6', '字典管理', null, 'dict', '1', 'icon-zygl', 'views/admin/dict/index', '6', '0', '2017-11-29 11:30:52', '2018-05-14 22:12:48', '0'), ('7', '部门管理', null, 'dept', '1', 'icon-iconbmgl', 'views/admin/dept/index', '7', '0', '2018-01-20 13:17:19', '2018-05-14 22:11:16', '0'), ('8', '系统监控', null, '', '-1', 'icon-iconbmgl', null, '8', '0', '2018-01-22 12:30:41', '2018-06-24 17:10:11', '1'), ('9', '服务监控', null, 'http://139.224.200.249:5001', '8', 'icon-jiankong', null, '9', '0', '2018-01-23 10:53:33', '2018-06-24 17:10:12', '1'), ('10', 'zipkin监控', null, 'http://139.224.200.249:5002', '8', 'icon-jiankong', null, '11', '0', '2018-01-23 10:55:18', '2018-06-24 17:10:12', '1'), ('11', 'pinpoint监控', null, 'https://pinpoint.pig4cloud.com', '8', 'icon-xiazaihuancun', null, '10', '0', '2018-01-25 11:08:52', '2018-06-24 17:10:12', '1'), ('12', '缓存状态', null, 'http://139.224.200.249:8585', '8', 'icon-ecs-status', null, '12', '0', '2018-01-23 10:56:11', '2018-06-24 17:10:12', '1'), ('13', 'ELK状态', null, 'http://139.224.200.249:5601', '8', 'icon-ecs-status', null, '13', '0', '2018-01-23 10:55:47', '2018-06-24 17:10:12', '1'), ('14', '接口文档', null, 'http://139.224.200.249:9999/swagger-ui.html', '8', 'icon-wendangdocument72', null, '14', '0', '2018-01-23 10:56:43', '2018-06-24 17:10:12', '1'), ('15', '任务监控', null, 'http://139.224.200.249:8899', '8', 'icon-jiankong', null, '15', '0', '2018-01-23 10:55:18', '2018-06-24 17:10:12', '1'), ('22', '用户新增', 'sys_user_add', null, '2', null, null, null, '1', '2017-11-08 09:52:09', '2017-12-04 16:31:10', '0'), ('23', '用户修改', 'sys_user_edit', null, '2', null, null, null, '1', '2017-11-08 09:52:48', '2018-06-26 21:16:57', '0'), ('24', '用户删除', 'sys_user_del', null, '2', null, null, null, '1', '2017-11-08 09:54:01', '2017-12-04 16:31:18', '0'), ('32', '菜单新增', 'sys_menu_add', null, '3', null, null, null, '1', '2017-11-08 10:15:53', '2018-01-20 14:37:50', '0'), ('33', '菜单修改', 'sys_menu_edit', null, '3', null, null, null, '1', '2017-11-08 10:16:23', '2018-01-20 14:37:56', '0'), ('34', '菜单删除', 'sys_menu_del', null, '3', null, null, null, '1', '2017-11-08 10:16:43', '2018-01-20 14:38:03', '0'), ('42', '角色新增', 'sys_role_add', null, '4', null, null, null, '1', '2017-11-08 10:14:18', '2018-04-20 07:21:38', '0'), ('43', '角色修改', 'sys_role_edit', null, '4', null, null, null, '1', '2017-11-08 10:14:41', '2018-04-20 07:21:50', '0'), ('44', '角色删除', 'sys_role_del', null, '4', null, null, null, '1', '2017-11-08 10:14:59', '2018-04-20 07:22:00', '0'), ('45', '分配权限', 'sys_role_perm', null, '4', null, null, null, '1', '2018-04-20 07:22:55', '2018-04-20 07:24:40', '0'), ('52', '日志删除', 'sys_log_del', null, '5', null, null, null, '1', '2017-11-20 20:37:37', '2017-11-28 17:36:52', '0'), ('62', '字典删除', 'sys_dict_del', null, '6', null, null, null, '1', '2017-11-29 11:30:11', '2018-01-07 15:40:51', '0'), ('63', '字典新增', 'sys_dict_add', null, '6', null, null, null, '1', '2018-05-11 22:34:55', null, '0'), ('64', '字典修改', 'sys_dict_edit', null, '6', null, null, null, '1', '2018-05-11 22:36:03', '2018-06-26 21:17:36', '0'), ('72', '部门新增', 'sys_dept_add', null, '7', null, null, null, '1', '2018-01-20 14:56:16', '2018-01-20 21:17:57', '0'), ('73', '部门修改', 'sys_dept_edit', null, '7', null, null, null, '1', '2018-01-20 14:56:59', '2018-01-20 21:17:59', '0'), ('74', '部门删除', 'sys_dept_del', null, '7', null, null, null, '1', '2018-01-20 14:57:28', '2018-01-20 21:18:05', '0'), ('100', '客户端管理', '', 'client', '1', 'icon-bangzhushouji', 'views/admin/client/index', '10', '0', '2018-01-20 13:17:19', '2018-05-15 21:28:10', '0'), ('101', '客户端新增', 'sys_client_add', null, '100', '1', null, null, '1', '2018-05-15 21:35:18', '2018-05-16 10:35:26', '0'), ('102', '客户端修改', 'sys_client_edit', null, '100', null, null, null, '1', '2018-05-15 21:37:06', '2018-06-26 21:17:17', '0'), ('103', '客户端删除', 'sys_client_del', null, '100', null, null, null, '1', '2018-05-15 21:39:16', '2018-05-15 21:52:34', '0'), ('200', '服务监控', null, 'http://127.0.0.1:5001', '1', 'icon-msnui-supervise', null, '9', '0', '2018-06-26 10:50:32', '2018-06-26 11:04:42', '0'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_oauth_client_details` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_oauth_client_details`; +CREATE TABLE `sys_oauth_client_details` ( + `client_id` varchar(32) NOT NULL, + `resource_ids` varchar(256) DEFAULT NULL, + `client_secret` varchar(256) DEFAULT NULL, + `scope` varchar(256) DEFAULT NULL, + `authorized_grant_types` varchar(256) DEFAULT NULL, + `web_server_redirect_uri` varchar(256) DEFAULT NULL, + `authorities` varchar(256) DEFAULT NULL, + `access_token_validity` int(11) DEFAULT NULL, + `refresh_token_validity` int(11) DEFAULT NULL, + `additional_information` varchar(4096) DEFAULT NULL, + `autoapprove` varchar(256) DEFAULT NULL, + PRIMARY KEY (`client_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Records of `sys_oauth_client_details` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_oauth_client_details` VALUES ('app', null, 'app', 'server', 'password,refresh_token', null, null, null, null, null, 'true'), ('pig', null, 'pig', 'server', 'password,refresh_token', null, null, null, null, null, 'false'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_role` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_role`; +CREATE TABLE `sys_role` ( + `role_id` int(11) NOT NULL AUTO_INCREMENT, + `role_name` varchar(64) COLLATE utf8mb4_bin NOT NULL, + `role_code` varchar(64) COLLATE utf8mb4_bin NOT NULL, + `role_desc` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL, + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `del_flag` char(1) COLLATE utf8mb4_bin DEFAULT '0' COMMENT '删除标识(0-正常,1-删除)', + PRIMARY KEY (`role_id`), + UNIQUE KEY `role_idx1_role_code` (`role_code`) +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Records of `sys_role` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_role` VALUES ('1', 'admin', 'ROLE_ADMIN', '超级管理员', '2017-10-29 15:45:51', '2018-04-22 11:40:29', '0'), ('14', 'demo', 'demo', 'demo用户', '2018-04-20 07:14:32', '2018-06-12 18:43:22', '0'), ('15', 'demo2', 'demo2', 'demo2', '2018-06-12 18:59:38', null, '0'), ('16', 'demo3', 'demo3', 'demo', '2018-06-13 07:07:25', '2018-06-24 17:16:47', '1'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_role_dept` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_role_dept`; +CREATE TABLE `sys_role_dept` ( + `id` int(20) NOT NULL AUTO_INCREMENT, + `role_id` int(20) DEFAULT NULL COMMENT '角色ID', + `dept_id` int(20) DEFAULT NULL COMMENT '部门ID', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='角色与部门对应关系'; + +-- ---------------------------- +-- Records of `sys_role_dept` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_role_dept` VALUES ('11', '1', '1'), ('16', '14', '6'), ('17', '15', '5'), ('18', '16', '8'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_role_menu` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_role_menu`; +CREATE TABLE `sys_role_menu` ( + `role_id` int(11) NOT NULL COMMENT '角色ID', + `menu_id` int(11) NOT NULL COMMENT '菜单ID', + PRIMARY KEY (`role_id`,`menu_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='角色菜单表'; + +-- ---------------------------- +-- Records of `sys_role_menu` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_role_menu` VALUES ('1', '1'), ('1', '2'), ('1', '3'), ('1', '4'), ('1', '5'), ('1', '6'), ('1', '7'), ('1', '22'), ('1', '23'), ('1', '24'), ('1', '32'), ('1', '33'), ('1', '34'), ('1', '42'), ('1', '43'), ('1', '44'), ('1', '45'), ('1', '52'), ('1', '62'), ('1', '63'), ('1', '64'), ('1', '72'), ('1', '73'), ('1', '74'), ('1', '100'), ('1', '101'), ('1', '102'), ('1', '103'), ('1', '200'), ('14', '1'), ('14', '2'), ('14', '3'), ('14', '4'), ('14', '5'), ('14', '6'), ('14', '7'), ('14', '21'), ('14', '22'), ('14', '23'), ('14', '24'), ('14', '31'), ('14', '32'), ('14', '33'), ('14', '34'), ('14', '41'), ('14', '42'), ('14', '43'), ('14', '44'), ('14', '45'), ('14', '51'), ('14', '52'), ('14', '61'), ('14', '62'), ('14', '63'), ('14', '64'), ('14', '71'), ('14', '72'), ('14', '73'), ('14', '74'), ('14', '100'), ('14', '101'), ('14', '102'), ('14', '103'), ('14', '104'), ('14', '110'), ('14', '111'), ('14', '112'), ('14', '113'), ('15', '1'), ('15', '2'), ('15', '3'), ('15', '5'), ('15', '21'), ('15', '22'), ('15', '23'), ('15', '24'), ('15', '31'), ('15', '32'), ('15', '33'), ('15', '34'), ('15', '51'), ('15', '52'), ('16', '1'), ('16', '2'), ('16', '21'), ('16', '22'), ('16', '23'), ('16', '24'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_user` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_user`; +CREATE TABLE `sys_user` ( + `user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `username` varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '用户名', + `password` varchar(255) COLLATE utf8mb4_bin NOT NULL, + `salt` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '随机盐', + `phone` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '简介', + `avatar` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '头像', + `dept_id` int(11) DEFAULT NULL COMMENT '部门ID', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + `del_flag` char(1) COLLATE utf8mb4_bin DEFAULT '0' COMMENT '0-正常,1-删除', + PRIMARY KEY (`user_id`), + UNIQUE KEY `user_idx1_username` (`username`) +) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='用户表'; + +-- ---------------------------- +-- Records of `sys_user` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_user` VALUES ('1', 'admin', '$2a$10$vg5QNHhCknAqevx9vM2s5esllJEzF/pa8VZXtFYHhhOhUcCw/GWyS', null, '17034642888', null, '1', '2018-04-20 07:15:18', '2018-06-26 11:43:22', '0'), ('4', 'pig', '$2a$10$vg5QNHhCknAqevx9vM2s5esllJEzF/pa8VZXtFYHhhOhUcCw/GWyS', null, '17034642118', null, '1', '2018-04-22 11:39:07', '2018-05-10 18:01:11', '0'), ('5', '0098', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642117', null, '1', '2018-05-29 21:35:03', null, '0'), ('7', '0097', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642001', null, '1', '2018-05-29 21:35:03', null, '0'), ('8', '17034642002', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642002', null, '1', '2018-05-29 21:35:03', null, '0'), ('9', '17034642003', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642003', null, '1', '2018-05-29 21:35:03', null, '0'), ('10', '17034642004', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642004', null, '1', '2018-05-29 21:35:03', null, '0'), ('11', '17034642005', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642005', null, '1', '2018-05-29 21:35:03', null, '0'), ('14', '17034642006', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642006', null, '1', '2018-05-29 21:35:03', null, '0'), ('15', '17034642007', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642007', null, '1', '2018-05-29 21:35:03', null, '0'), ('16', '17034642008', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642008', null, '1', '2018-05-29 21:35:03', null, '0'), ('17', '17034642009', '$2a$10$Rm.6OnUqDoiPGMd60/JzlOPErBeHJzOs39uUanCR.RP7u3uW6s5Mq', null, '17034642009', null, '1', '2018-05-29 21:35:03', null, '0'), ('18', '123456', '$2a$10$P1cRSPAJqfPpKPmQIo/GiuSfrdvRnU0nNWBywqK/lBkrL/K1TOXy6', null, '17034642115', null, '6', '2018-06-12 18:28:42', null, '0'), ('19', 'demo2', '$2a$10$qaNZ/KVvq65.wRo20dDuYOR1Qocuvnj3h9CtrXTimFI3.d1PHJMhi', null, '12345678902', null, '5', '2018-06-12 19:00:02', '2018-06-26 21:36:45', '0'), ('20', 'demo3', '$2a$10$vg5QNHhCknAqevx9vM2s5esllJEzF/pa8VZXtFYHhhOhUcCw/GWyS', null, '11122233344', null, '8', '2018-06-13 07:07:56', '2018-06-13 07:09:00', '0'); +COMMIT; + +-- ---------------------------- +-- Table structure for `sys_user_role` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_user_role`; +CREATE TABLE `sys_user_role` ( + `user_id` int(11) NOT NULL COMMENT '用户ID', + `role_id` int(11) NOT NULL COMMENT '角色ID', + PRIMARY KEY (`user_id`,`role_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='用户角色表'; + +-- ---------------------------- +-- Records of `sys_user_role` +-- ---------------------------- +BEGIN; +INSERT INTO `sys_user_role` VALUES ('1', '1'), ('4', '14'), ('5', '1'), ('7', '1'), ('8', '1'), ('9', '1'), ('10', '1'), ('11', '1'), ('12', '1'), ('13', '1'), ('14', '1'), ('15', '1'), ('16', '1'), ('17', '1'), ('18', '14'), ('19', '15'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..cc71f0064 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,64 @@ +version: '2' +services: + pigx-redis: + image: redis:4.0.10 + ports: + - 6379:6379 + restart: always + + pigx-eureka: + build: + context: ./ + dockerfile: ./pigx-eureka/Dockerfile + restart: always + ports: + - 1025:1025 + + pigx-config: + links: + - pigx-eureka + build: + context: ./ + dockerfile: ./pigx-config/Dockerfile + restart: always + + pigx-gateway: + links: + - pigx-eureka + build: + context: ./ + dockerfile: ./pigx-gateway/Dockerfile + restart: always + ports: + - 9999:9999 + + pigx-auth: + links: + - pigx-eureka + - pigx-redis + build: + context: ./ + dockerfile: ./pigx-auth/Dockerfile + restart: always + ports: + - 3000:3000 + + pig-upms: + links: + - pigx-eureka + - pigx-redis + - pigx-gateway + build: + context: ./ + dockerfile: ./pigx-upms/pigx-upms-biz/Dockerfile + restart: always + + pig-monitor: + links: + - pigx-eureka + build: + context: ./ + dockerfile: ./pigx-monitor/Dockerfile + restart: always + ports: + - 5001:5001 diff --git a/pigx-auth/Dockerfile b/pigx-auth/Dockerfile new file mode 100644 index 000000000..69d3f7b14 --- /dev/null +++ b/pigx-auth/Dockerfile @@ -0,0 +1,13 @@ +FROM anapsix/alpine-java:8_server-jre_unlimited + +MAINTAINER wangiegie@gmail.com + +RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-auth + +WORKDIR /pigx/bin/com.pig4cloud/pigx-auth + +EXPOSE 1025 + +ADD ./pigx-auth/target/pigx-auth.jar ./ + +CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-auth.jar diff --git a/pigx-auth/pom.xml b/pigx-auth/pom.xml new file mode 100644 index 000000000..c70900d14 --- /dev/null +++ b/pigx-auth/pom.xml @@ -0,0 +1,102 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + pigx-auth + ${pigx.version} + jar + + pigx-auth + pigx 认证授权中心,基于 spring security oAuth2 + + + + + org.springframework.cloud + spring-cloud-starter-config + + + + com.pig4cloud + pigx-upms-api + ${pigx.version} + + + + org.springframework.cloud + spring-cloud-starter-security + + + + spring-security-oauth2 + org.springframework.security.oauth + + + + + org.springframework.security.oauth + spring-security-oauth2 + ${security.oauth.version} + + + + mysql + mysql-connector-java + + + + org.springframework.boot + spring-boot-starter-web + + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${project.name} + + + + + + diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/PigxAuthApplication.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/PigxAuthApplication.java new file mode 100644 index 000000000..223a53505 --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/PigxAuthApplication.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.auth; + + +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * @author lengleng + * @date 2018年06月21日 + * 认证授权中心 + */ +@SpringCloudApplication +@EnableFeignClients({"com.pig4cloud.pigx.admin.api.feign"}) +public class PigxAuthApplication { + + public static void main(String[] args) { + SpringApplication.run(PigxAuthApplication.class, args); + } +} diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java new file mode 100644 index 000000000..c13da06a6 --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java @@ -0,0 +1,102 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.auth.config; + +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.security.compoent.PigxWebResponseExceptionTranslator; +import lombok.AllArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; +import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; +import org.springframework.security.oauth2.provider.token.TokenEnhancer; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; + +/** + * @author lengleng + * @date 2018/6/22 + * 认证服务器配置 + */ +@Configuration +@AllArgsConstructor +@EnableAuthorizationServer +public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { + private final DataSource dataSource; + private final AuthenticationManager authenticationManager; + private final RedisConnectionFactory redisConnectionFactory; + + @Override + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { + JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource); + clientDetailsService.setSelectClientDetailsSql(SecurityConstants.DEFAULT_SELECT_STATEMENT); + clientDetailsService.setFindClientDetailsSql(SecurityConstants.DEFAULT_FIND_STATEMENT); + clients.withClientDetails(clientDetailsService); + } + + @Override + public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { + oauthServer + .allowFormAuthenticationForClients() + .checkTokenAccess("permitAll()"); + } + + @Override + public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { + endpoints + .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST) + .tokenStore(tokenStore()) + .tokenEnhancer(tokenEnhancer()) + .authenticationManager(authenticationManager) + .reuseRefreshTokens(false) + .exceptionTranslator(new PigxWebResponseExceptionTranslator()); + } + + + + @Bean + public TokenStore tokenStore() { + RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory); + tokenStore.setPrefix(SecurityConstants.PIGX_PREFIX + SecurityConstants.OAUTH_PREFIX); + return tokenStore; + } + + @Bean + public TokenEnhancer tokenEnhancer() { + return (accessToken, authentication) -> { + final Map additionalInfo = new HashMap<>(1); + additionalInfo.put("license", SecurityConstants.PIGX_LICENSE); + ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo); + return accessToken; + }; + } +} diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java new file mode 100644 index 000000000..837c086aa --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java @@ -0,0 +1,68 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.auth.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.annotation.Order; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.factory.PasswordEncoderFactories; +import org.springframework.security.crypto.password.PasswordEncoder; + +/** + * @author lengleng + * @date 2018/6/22 + * 认证相关配置 + */ +@Primary +@Order(90) +@Configuration +public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/actuator/**", "/oauth/removeToken").permitAll() + .anyRequest().authenticated() + .and().csrf().disable(); + } + + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + /** + * https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-updated + * Encoded password does not look like BCrypt + * + * @return PasswordEncoder + */ + @Bean + public PasswordEncoder passwordEncoder() { + return PasswordEncoderFactories.createDelegatingPasswordEncoder(); + } + +} diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/RevokeTokenEndpoint.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/RevokeTokenEndpoint.java new file mode 100644 index 000000000..811978edd --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/RevokeTokenEndpoint.java @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.auth.endpoint; + +import cn.hutool.core.util.StrUtil; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author lengleng + * @date 2018/6/24 + * 删除token端点 + */ +@RestController +@AllArgsConstructor +public class RevokeTokenEndpoint { + private final TokenStore tokenStore; + + /** + * 删除token + * + * @param authHeader Authorization + */ + @RequestMapping("/oauth/removeToken") + public R logout(@RequestHeader(value = "Authorization", required = false) String authHeader) { + if (StringUtils.hasText(authHeader)) { + String tokenValue = authHeader.replace("Bearer", "").trim(); + OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue); + if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) { + return new R<>(false, "退出失败,token 为空"); + } + tokenStore.removeAccessToken(accessToken); + } + return new R<>(Boolean.TRUE); + } +} diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java new file mode 100644 index 000000000..f709b31aa --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java @@ -0,0 +1,81 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.auth.service; + +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.api.feign.RemoteUserService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * 用户详细信息 + * + * @author lengleng + */ +@Slf4j +@Service +@AllArgsConstructor +public class PigxUserDetailsServiceImpl implements UserDetailsService { + private final RemoteUserService remoteUserService; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + R result = remoteUserService.info(username, SecurityConstants.FROM_IN); + + if (result == null || result.getData() == null) { + throw new UsernameNotFoundException("用户不存在"); + } + + UserInfo info = result.getData(); + Set dbAuthsSet = new HashSet<>(); + if (ArrayUtil.isNotEmpty(info.getRoles())) { + // 获取角色 + Arrays.stream(info.getRoles()).forEach(role -> dbAuthsSet.add(SecurityConstants.ROLE + role)); + // 获取资源 + dbAuthsSet.addAll(Arrays.asList(info.getPermissions())); + + } + Collection authorities + = AuthorityUtils.createAuthorityList(dbAuthsSet.toArray(new String[0])); + SysUser user = info.getSysUser(); + boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstant.STATUS_NORMAL); + // 构造security用户 + return new User(username, SecurityConstants.BCRYPT + user.getPassword(), enabled, + true, true, true, authorities); + } +} diff --git a/pigx-auth/src/main/resources/bootstrap.yml b/pigx-auth/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..73d9d7df3 --- /dev/null +++ b/pigx-auth/src/main/resources/bootstrap.yml @@ -0,0 +1,26 @@ +server: + port: 3000 + +spring: + application: + name: pigx-auth + # 配置中心 + cloud: + config: + fail-fast: true + name: ${spring.application.name} + profile: dev + discovery: + enabled: true + service-id: pigx-config + +# 注册中心配置 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://pig:pig@localhost:1025/eureka/ +logging: + level: + root: debug diff --git a/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/config/KaptchaConfiguration.java b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/config/KaptchaConfiguration.java new file mode 100644 index 000000000..aae34dbfc --- /dev/null +++ b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/config/KaptchaConfiguration.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.config; + +import com.google.code.kaptcha.impl.DefaultKaptcha; +import com.google.code.kaptcha.util.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Properties; + +/** + * @author lengleng + * @date 2017-12-21 21:12:18 + */ +@Configuration +public class KaptchaConfiguration { + + private static final String KAPTCHA_BORDER = "kaptcha.border"; + private static final String KAPTCHA_TEXTPRODUCER_FONT_COLOR = "kaptcha.textproducer.font.color"; + private static final String KAPTCHA_TEXTPRODUCER_CHAR_SPACE = "kaptcha.textproducer.char.space"; + private static final String KAPTCHA_IMAGE_WIDTH = "kaptcha.image.width"; + private static final String KAPTCHA_IMAGE_HEIGHT = "kaptcha.image.height"; + private static final String KAPTCHA_TEXTPRODUCER_CHAR_LENGTH = "kaptcha.textproducer.char.length"; + private static final Object KAPTCHA_IMAGE_FONT_SIZE = "kaptcha.textproducer.font.size"; + + /** + * 默认生成图形验证码宽度 + */ + String DEFAULT_IMAGE_WIDTH = "100"; + + /** + * 默认生成图像验证码高度 + */ + String DEFAULT_IMAGE_HEIGHT = "40"; + + /** + * 默认生成图形验证码长度 + */ + String DEFAULT_IMAGE_LENGTH = "4"; + + /** + * 默认生成图形验证码过期时间 + */ + int DEFAULT_IMAGE_EXPIRE = 60; + /** + * 边框颜色,合法值: r,g,b (and optional alpha) 或者 white,black,blue. + */ + String DEFAULT_COLOR_FONT = "black"; + + /** + * 图片边框 + */ + String DEFAULT_IMAGE_BORDER = "no"; + /** + * 默认图片间隔 + */ + String DEFAULT_CHAR_SPACE = "5"; + + /** + * 默认保存code的前缀 + */ + String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY"; + /** + * 验证码文字大小 + */ + String DEFAULT_IMAGE_FONT_SIZE = "30"; + + @Bean + public DefaultKaptcha producer() { + Properties properties = new Properties(); + properties.put(KAPTCHA_BORDER, DEFAULT_IMAGE_BORDER); + properties.put(KAPTCHA_TEXTPRODUCER_FONT_COLOR, DEFAULT_COLOR_FONT); + properties.put(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, DEFAULT_CHAR_SPACE); + properties.put(KAPTCHA_IMAGE_WIDTH, DEFAULT_IMAGE_WIDTH); + properties.put(KAPTCHA_IMAGE_HEIGHT, DEFAULT_IMAGE_HEIGHT); + properties.put(KAPTCHA_IMAGE_FONT_SIZE, DEFAULT_IMAGE_FONT_SIZE); + properties.put(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, DEFAULT_IMAGE_LENGTH); + Config config = new Config(properties); + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } +} diff --git a/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/exception/ValidateCodeException.java b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/exception/ValidateCodeException.java new file mode 100644 index 000000000..a86375ac3 --- /dev/null +++ b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/exception/ValidateCodeException.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.exception; + +/** + * @author lengleng + */ +public class ValidateCodeException extends Exception { + +} diff --git a/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/filter/ImageCodeGatewayFilter.java b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/filter/ImageCodeGatewayFilter.java new file mode 100644 index 000000000..99fe66cff --- /dev/null +++ b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/filter/ImageCodeGatewayFilter.java @@ -0,0 +1,93 @@ +package com.pig4cloud.pigx.gateway.filter; + +import cn.hutool.core.util.StrUtil; +import com.pig4cloud.pigx.gateway.exception.ValidateCodeException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/7/4 + * 验证码处理 + */ +@Slf4j +@Component +public class ImageCodeGatewayFilter extends AbstractGatewayFilterFactory { + private static final String OAUTH_TOKEN_URL = "/oauth/token"; + public static final String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY"; + + @Autowired + private RedisTemplate redisTemplate; + + @Override + public GatewayFilter apply(Object config) { + return (exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + + // 不是登录请求,直接向下执行 + if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath(), OAUTH_TOKEN_URL)) { + return chain.filter(exchange); + } + try { + checkCode(request); + } catch (ValidateCodeException e) { + ServerHttpResponse response = exchange.getResponse(); + response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED); + return response.setComplete(); + } + + return chain.filter(exchange); + }; + } + + + /** + * 检查code + * + * @param request + * @throws ValidateCodeException 校验异常 + */ + private void checkCode(ServerHttpRequest request) throws ValidateCodeException { + String code = request.getQueryParams().getFirst("code"); + + if (StrUtil.isBlank(code)) { + throw new ValidateCodeException(); + } + + String randomStr = request.getQueryParams().getFirst("randomStr"); + if (StrUtil.isBlank(randomStr)) { + throw new ValidateCodeException(); + } + + String key = DEFAULT_CODE_KEY + randomStr; + if (!redisTemplate.hasKey(key)) { + throw new ValidateCodeException(); + } + + Object codeObj = redisTemplate.opsForValue().get(key); + + if (codeObj == null) { + throw new ValidateCodeException(); + } + + String saveCode = codeObj.toString(); + if (StrUtil.isBlank(saveCode)) { + redisTemplate.delete(key); + throw new ValidateCodeException(); + } + + if (!StrUtil.equals(saveCode, code)) { + redisTemplate.delete(key); + throw new ValidateCodeException(); + } + + redisTemplate.delete(key); + } +} diff --git a/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/handle/ImageCodeHandler.java b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/handle/ImageCodeHandler.java new file mode 100644 index 000000000..ccdb6d45f --- /dev/null +++ b/pigx-common/pigx-common-code/src/main/java/com/pig4cloud/pigx/common/code/handle/ImageCodeHandler.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.handle; + +import com.google.code.kaptcha.Producer; +import com.pig4cloud.pigx.gateway.filter.ImageCodeGatewayFilter; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.util.FastByteArrayOutputStream; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * @author lengleng + * @date 2018/7/5 + * 验证码生成逻辑处理类 + */ +@Slf4j +@Component +@AllArgsConstructor +public class ImageCodeHandler implements HandlerFunction { + private final Producer producer; + private final RedisTemplate redisTemplate; + + @Override + public Mono handle(ServerRequest serverRequest) { + //生成验证码 + String text = producer.createText(); + BufferedImage image = producer.createImage(text); + + //保存验证码信息 + String randomStr = serverRequest.queryParam("randomStr").get(); + redisTemplate.opsForValue().set(ImageCodeGatewayFilter.DEFAULT_CODE_KEY + randomStr, text, 60, TimeUnit.SECONDS); + + // 转换流信息写出 + FastByteArrayOutputStream os = new FastByteArrayOutputStream(); + try { + ImageIO.write(image, "jpeg", os); + } catch (IOException e) { + log.error("ImageIO write err", e); + return Mono.error(e); + } + + return ServerResponse + .status(HttpStatus.OK) + .contentType(MediaType.IMAGE_JPEG) + .body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray()))); + } +} diff --git a/pigx-common/pigx-common-core/pom.xml b/pigx-common/pigx-common-core/pom.xml new file mode 100644 index 000000000..afe5c6b8c --- /dev/null +++ b/pigx-common/pigx-common-core/pom.xml @@ -0,0 +1,63 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx-common + ${pigx.version} + + + pigx-common-core + ${pigx.version} + jar + pigx-common-core + pigx 公共工具类核心包 + + + + + + cn.hutool + hutool-all + ${hutool.version} + + + + com.alibaba + fastjson + ${fastjson.version} + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + javax.servlet + javax.servlet-api + ${servlet-api.version} + provided + + + diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/RedisConfig.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/RedisConfig.java new file mode 100644 index 000000000..2890d8c28 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/RedisConfig.java @@ -0,0 +1,77 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.config; + +import lombok.AllArgsConstructor; +import org.springframework.cache.annotation.EnableCaching; +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.*; +import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * @author lengleng + * @date 2018/6/23 + * Redis 配置类 + */ +@EnableCaching +@Configuration +@AllArgsConstructor +public class RedisConfig { + private final RedisConnectionFactory factory; + + @Bean + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); + redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); + redisTemplate.setConnectionFactory(factory); + return redisTemplate; + } + + @Bean + public HashOperations hashOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForHash(); + } + + @Bean + public ValueOperations valueOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForValue(); + } + + @Bean + public ListOperations listOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForList(); + } + + @Bean + public SetOperations setOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForSet(); + } + + @Bean + public ZSetOperations zSetOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForZSet(); + } +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java new file mode 100644 index 000000000..5b0e0c472 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.constant; + +/** + * @author lengleng + * @date 2017/10/29 + */ +public interface CommonConstant { + /** + * token请求头名称 + */ + String REQ_HEADER = "Authorization"; + + /** + * token分割符 + */ + String TOKEN_SPLIT = "Bearer "; + + /** + * jwt签名 + */ + String SIGN_KEY = "PIG"; + /** + * 删除 + */ + String STATUS_DEL = "1"; + /** + * 正常 + */ + String STATUS_NORMAL = "0"; + + /** + * 锁定 + */ + String STATUS_LOCK = "9"; + + /** + * 菜单 + */ + String MENU = "0"; + + /** + * 按钮 + */ + String BUTTON = "1"; + + /** + * 删除标记 + */ + String DEL_FLAG = "del_flag"; + + /** + * 编码 + */ + String UTF8 = "UTF-8"; + + /** + * JSON 资源 + */ + String CONTENT_TYPE = "application/json; charset=utf-8"; + + /** + * 阿里大鱼 + */ + String ALIYUN_SMS = "aliyun_sms"; + + /** + * 路由信息Redis保存的key + */ + String ROUTE_KEY = "_ROUTE_KEY"; +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/MqQueueConstant.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/MqQueueConstant.java new file mode 100644 index 000000000..901b497ad --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/MqQueueConstant.java @@ -0,0 +1,57 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.constant; + +/** + * @author lengleng + * @date 2018/1/15 + * MQ 消息队列 + */ +public interface MqQueueConstant { + /** + * log rabbit队列名称 + */ + String LOG_QUEUE = "log"; + + /** + * 发送短信验证码队列 + */ + String MOBILE_CODE_QUEUE = "mobile_code_queue"; + + /** + * 短信服务状态队列 + */ + String MOBILE_SERVICE_STATUS_CHANGE = "mobile_service_status_change"; + + /** + * 钉钉服务状态队列 + */ + String DINGTALK_SERVICE_STATUS_CHANGE = "dingtalk_service_status_change"; + + /** + * zipkin 队列 + */ + String ZIPKIN_NAME_QUEUE = "zipkin"; + + /** + * 路由配置状态队列 + */ + String ROUTE_CONFIG_CHANGE = "route_config_change"; +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java new file mode 100644 index 000000000..e3120b138 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java @@ -0,0 +1,77 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.constant; + +/** + * @author lengleng + * @date 2017-12-18 + */ +public interface SecurityConstants { + /** + * 角色前缀 + */ + String ROLE = "ROLE_"; + /** + * 前缀 + */ + String PIGX_PREFIX = "pigx_"; + + /** + * oauth 相关前缀 + */ + String OAUTH_PREFIX = "oauth:"; + /** + * 项目的license + */ + String PIGX_LICENSE = "made by pigx"; + + /** + * 内部 + */ + String FROM_IN = "Y"; + + /** + * {bcrypt} 加密的特征码 + */ + String BCRYPT = "{bcrypt}"; + /** + * sys_oauth_client_details 表的字段,不包括client_id、client_secret + */ + String CLIENT_FIELDS = "client_id, CONCAT('{noop}',client_secret) as client_secret, resource_ids, scope, " + + "authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, " + + "refresh_token_validity, additional_information, autoapprove"; + + /** + * JdbcClientDetailsService 查询语句 + */ + String BASE_FIND_STATEMENT = "select " + CLIENT_FIELDS + + " from sys_oauth_client_details"; + + /** + * 默认的查询语句 + */ + String DEFAULT_FIND_STATEMENT = BASE_FIND_STATEMENT + " order by client_id"; + + /** + * 按条件client_id 查询 + */ + String DEFAULT_SELECT_STATEMENT = BASE_FIND_STATEMENT + " where client_id = ?"; + +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/ServiceNameConstant.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/ServiceNameConstant.java new file mode 100644 index 000000000..da11cb17e --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/ServiceNameConstant.java @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.constant; + +/** + * @author lengleng + * @date 2018年06月22日16:41:01 + * 服务名称 + */ +public interface ServiceNameConstant { + /** + * 认证服务的SERVICEID(zuul 配置的对应) + */ + String AUTH_SERVICE = "pigx-auth"; + + /** + * UMPS模块 + */ + String UMPS_SERVICE = "pigx-upms"; +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumSmsChannel.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumSmsChannel.java new file mode 100644 index 000000000..a77c77b4a --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumSmsChannel.java @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.constant.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author lengleng + * @date 2018/1/16 + * 短信通道枚举 + */ +@Getter +@AllArgsConstructor +public enum EnumSmsChannel { + /** + * 阿里大鱼短信通道 + */ + ALIYUN("ALIYUN_SMS", "阿里大鱼"); + /** + * 通道名称 + */ + private final String name; + /** + * 通道描述 + */ + private final String description; +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumSmsChannelTemplate.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumSmsChannelTemplate.java new file mode 100644 index 000000000..cd767d9ed --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumSmsChannelTemplate.java @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.constant.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author LiXunHuan + * @date 2018/1/16 + * 短信通道模板 + */ +@Getter +@AllArgsConstructor +public enum EnumSmsChannelTemplate { + /** + * 登录验证 + */ + LOGIN_NAME_LOGIN("loginCodeChannel", "登录验证"), + /** + * 服务异常提醒 + */ + SERVICE_STATUS_CHANGE("serviceStatusChange", "Pig4Cloud"); + + /** + * 模板名称 + */ + private final String template; + /** + * 模板签名 + */ + private final String signName; +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/CheckedException.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/CheckedException.java new file mode 100644 index 000000000..36201eb47 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/CheckedException.java @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.exception; + +import lombok.NoArgsConstructor; + +/** + * @author lengleng + * @date 😴2018年06月22日16:21:57 + */ +@NoArgsConstructor +public class CheckedException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public CheckedException(String message) { + super(message); + } + + public CheckedException(Throwable cause) { + super(cause); + } + + public CheckedException(String message, Throwable cause) { + super(message, cause); + } + + public CheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/PigDeniedException.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/PigDeniedException.java new file mode 100644 index 000000000..f21cdc37a --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/PigDeniedException.java @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.exception; + +import lombok.NoArgsConstructor; + +/** + * @author lengleng + * @date 2018年06月22日16:22:03 + * 403 授权拒绝 + */ +@NoArgsConstructor +public class PigDeniedException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public PigDeniedException(String message) { + super(message); + } + + public PigDeniedException(Throwable cause) { + super(cause); + } + + public PigDeniedException(String message, Throwable cause) { + super(message, cause); + } + + public PigDeniedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/UnloginException.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/UnloginException.java new file mode 100644 index 000000000..4518b3231 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/UnloginException.java @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.exception; + +import lombok.NoArgsConstructor; + +/** + * @author lengleng + * @date 2018年06月22日16:22:10 + */ +@NoArgsConstructor +public class UnloginException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public UnloginException(String message) { + super(message); + } + + public UnloginException(Throwable cause) { + super(cause); + } + + public UnloginException(String message, Throwable cause) { + super(message, cause); + } + + public UnloginException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/ValidateCodeException.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/ValidateCodeException.java new file mode 100644 index 000000000..db5bb10da --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/exception/ValidateCodeException.java @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.exception; + +/** + * @author lengleng + * @date 2018年06月22日16:22:15 + */ +public class ValidateCodeException extends Exception { + private static final long serialVersionUID = -7285211528095468156L; + + public ValidateCodeException(String msg) { + super(msg); + } +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/ClassUtils.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/ClassUtils.java new file mode 100644 index 000000000..61125d4aa --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/ClassUtils.java @@ -0,0 +1,112 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.util; + +import org.springframework.core.BridgeMethodResolver; +import org.springframework.core.DefaultParameterNameDiscoverer; +import org.springframework.core.MethodParameter; +import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.core.annotation.SynthesizingMethodParameter; +import org.springframework.web.method.HandlerMethod; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** + * 类工具类 + * + * @author L.cm + */ +public class ClassUtils extends org.springframework.util.ClassUtils { + private static final ParameterNameDiscoverer PARAMETERNAMEDISCOVERER = new DefaultParameterNameDiscoverer(); + + /** + * 获取方法参数信息 + * + * @param constructor 构造器 + * @param parameterIndex 参数序号 + * @return {MethodParameter} + */ + public static MethodParameter getMethodParameter(Constructor constructor, int parameterIndex) { + MethodParameter methodParameter = new SynthesizingMethodParameter(constructor, parameterIndex); + methodParameter.initParameterNameDiscovery(PARAMETERNAMEDISCOVERER); + return methodParameter; + } + + /** + * 获取方法参数信息 + * + * @param method 方法 + * @param parameterIndex 参数序号 + * @return {MethodParameter} + */ + public static MethodParameter getMethodParameter(Method method, int parameterIndex) { + MethodParameter methodParameter = new SynthesizingMethodParameter(method, parameterIndex); + methodParameter.initParameterNameDiscovery(PARAMETERNAMEDISCOVERER); + return methodParameter; + } + + /** + * 获取Annotation + * + * @param method Method + * @param annotationType 注解类 + * @param 泛型标记 + * @return {Annotation} + */ + public static A getAnnotation(Method method, Class annotationType) { + Class targetClass = method.getDeclaringClass(); + // The method may be on an interface, but we need attributes from the target class. + // If the target class is null, the method will be unchanged. + Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass); + // If we are dealing with method with generic parameters, find the original method. + specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); + // 先找方法,再找方法上的类 + A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType); + ; + if (null != annotation) { + return annotation; + } + // 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类 + return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType); + } + + /** + * 获取Annotation + * + * @param handlerMethod HandlerMethod + * @param annotationType 注解类 + * @param 泛型标记 + * @return {Annotation} + */ + public static A getAnnotation(HandlerMethod handlerMethod, Class annotationType) { + // 先找方法,再找方法上的类 + A annotation = handlerMethod.getMethodAnnotation(annotationType); + if (null != annotation) { + return annotation; + } + // 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类 + Class beanType = handlerMethod.getBeanType(); + return AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType); + } + +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java new file mode 100644 index 000000000..e9a14ff3c --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java @@ -0,0 +1,71 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.util; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; + +/** + * 响应信息主体 + * + * @param + * @author lengleng + */ +@ToString +public class R implements Serializable { + private static final int SUCCESS = 0; + private static final int FAIL = 1; + private static final long serialVersionUID = 1L; + @Getter + @Setter + private String msg = "success"; + + @Getter + @Setter + private int code = SUCCESS; + + @Getter + @Setter + private T data; + + public R() { + super(); + } + + public R(T data) { + super(); + this.data = data; + } + + public R(T data, String msg) { + super(); + this.data = data; + this.msg = msg; + } + + public R(Throwable e) { + super(); + this.msg = e.getMessage(); + this.code = FAIL; + } +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/SpringContextHolder.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/SpringContextHolder.java new file mode 100644 index 000000000..0eacf108d --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/SpringContextHolder.java @@ -0,0 +1,102 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.util; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; + +/** + * @author lengleng + * @date 2018/6/27 + * Spring 工具类 + */ +@Slf4j +@Service +@Lazy(false) +public class SpringContextHolder implements ApplicationContextAware, DisposableBean { + + private static ApplicationContext applicationContext = null; + + /** + * 取得存储在静态变量中的ApplicationContext. + */ + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 实现ApplicationContextAware接口, 注入Context到静态变量中. + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + SpringContextHolder.applicationContext = applicationContext; + } + + /** + * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) { + return (T) applicationContext.getBean(name); + } + + /** + * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + public static T getBean(Class requiredType) { + return applicationContext.getBean(requiredType); + } + + /** + * 清除SpringContextHolder中的ApplicationContext为Null. + */ + public static void clearHolder() { + if (log.isDebugEnabled()) { + log.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext); + } + applicationContext = null; + } + + /** + * 发布事件 + * + * @param event + */ + public static void publishEvent(ApplicationEvent event) { + if (applicationContext == null) { + return; + } + applicationContext.publishEvent(event); + } + + /** + * 实现DisposableBean接口, 在Context关闭时清理静态变量. + */ + @Override + public void destroy() throws Exception { + SpringContextHolder.clearHolder(); + } + +} diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/WebUtils.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/WebUtils.java new file mode 100644 index 000000000..8609e791e --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/WebUtils.java @@ -0,0 +1,195 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.core.util; + +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.http.MediaType; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.method.HandlerMethod; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + + +/** + * Miscellaneous utilities for web applications. + * + * @author L.cm + */ +@Slf4j +public class WebUtils extends org.springframework.web.util.WebUtils { + + public static final String UNKNOWN = "unknown"; + + /** + * 判断是否ajax请求 + * spring ajax 返回含有 ResponseBody 或者 RestController注解 + * + * @param handlerMethod HandlerMethod + * @return 是否ajax请求 + */ + public static boolean isBody(HandlerMethod handlerMethod) { + ResponseBody responseBody = ClassUtils.getAnnotation(handlerMethod, ResponseBody.class); + return responseBody != null; + } + + /** + * 读取cookie + * + * @param name cookie name + * @return cookie value + */ + public static String getCookieVal(String name) { + HttpServletRequest request = WebUtils.getRequest(); + Assert.notNull(request, "request from RequestContextHolder is null"); + return getCookieVal(request, name); + } + + /** + * 读取cookie + * + * @param request HttpServletRequest + * @param name cookie name + * @return cookie value + */ + public static String getCookieVal(HttpServletRequest request, String name) { + Cookie cookie = getCookie(request, name); + return cookie != null ? cookie.getValue() : null; + } + + /** + * 清除 某个指定的cookie + * + * @param response HttpServletResponse + * @param key cookie key + */ + public static void removeCookie(HttpServletResponse response, String key) { + setCookie(response, key, null, 0); + } + + /** + * 设置cookie + * + * @param response HttpServletResponse + * @param name cookie name + * @param value cookie value + * @param maxAgeInSeconds maxage + */ + public static void setCookie(HttpServletResponse response, String name, String value, int maxAgeInSeconds) { + Cookie cookie = new Cookie(name, value); + cookie.setPath("/"); + cookie.setMaxAge(maxAgeInSeconds); + cookie.setHttpOnly(true); + response.addCookie(cookie); + } + + /** + * 获取 HttpServletRequest + * + * @return {HttpServletRequest} + */ + public static HttpServletRequest getRequest() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + } + + /** + * 获取 HttpServletResponse + * + * @return {HttpServletResponse} + */ + public static HttpServletResponse getResponse() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + } + + /** + * 返回json + * + * @param response HttpServletResponse + * @param result 结果对象 + */ + public static void renderJson(HttpServletResponse response, Object result) { + renderJson(response, result, MediaType.APPLICATION_JSON_UTF8_VALUE); + } + + /** + * 返回json + * + * @param response HttpServletResponse + * @param result 结果对象 + * @param contentType contentType + */ + public static void renderJson(HttpServletResponse response, Object result, String contentType) { + response.setCharacterEncoding("UTF-8"); + response.setContentType(contentType); + try (PrintWriter out = response.getWriter()) { + out.append(JSONUtil.toJsonStr(result)); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + + /** + * 获取ip + * + * @return {String} + */ + public static String getIP() { + return getIP(WebUtils.getRequest()); + } + + /** + * 获取ip + * + * @param request HttpServletRequest + * @return {String} + */ + public static String getIP(HttpServletRequest request) { + Assert.notNull(request, "HttpServletRequest is null"); + String ip = request.getHeader("X-Requested-For"); + if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { + ip = request.getHeader("X-Forwarded-For"); + } + if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return StringUtils.isBlank(ip) ? null : ip.split(",")[0]; + } +} + diff --git a/pigx-common/pigx-common-core/src/main/resources/META-INF/spring-devtools.properties b/pigx-common/pigx-common-core/src/main/resources/META-INF/spring-devtools.properties new file mode 100644 index 000000000..f6eed4bb5 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/resources/META-INF/spring-devtools.properties @@ -0,0 +1 @@ +restart.include.pigx-common-core=/pigx-common-core[\\w-]+\.jar diff --git a/pigx-common/pigx-common-core/src/main/resources/META-INF/spring.factories b/pigx-common/pigx-common-core/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..9046e742b --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.pig4cloud.pigx.common.core.config.RedisConfig,\ + com.pig4cloud.pigx.common.core.util.SpringContextHolder diff --git a/pigx-common/pigx-common-core/src/main/resources/META-INF/spring.provides b/pigx-common/pigx-common-core/src/main/resources/META-INF/spring.provides new file mode 100644 index 000000000..61afcd7b2 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: hutool-all, spring-cloud-starter-openfeign, feign-okhttp, fastjson, spring-boot-starter-data-redis diff --git a/pigx-common/pigx-common-log/pom.xml b/pigx-common/pigx-common-log/pom.xml new file mode 100644 index 000000000..eb8310a0f --- /dev/null +++ b/pigx-common/pigx-common-log/pom.xml @@ -0,0 +1,51 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx-common + ${pigx.version} + + + pigx-common-log + ${pigx.version} + jar + pigx-common-log + pigx 日志服务 + + + + + + com.pig4cloud + pigx-common-core + ${pigx.version} + + + + com.pig4cloud + pigx-upms-api + ${pigx.version} + + + diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/LogAutoConfiguration.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/LogAutoConfiguration.java new file mode 100644 index 000000000..eaa365b79 --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/LogAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.log; + +import com.pig4cloud.pigx.admin.api.feign.RemoteLogService; +import com.pig4cloud.pigx.common.log.aspect.SysLogAspect; +import com.pig4cloud.pigx.common.log.event.SysLogListener; +import lombok.AllArgsConstructor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author lengleng + * @date 2018/6/28 + * 日志自动配置 + */ +@Configuration +@AllArgsConstructor +@ConditionalOnWebApplication +@EnableFeignClients({"com.pig4cloud.pigx.admin.api.feign"}) +public class LogAutoConfiguration { + private final RemoteLogService remoteLogService; + + @Bean + public SysLogListener sysLogListener() { + return new SysLogListener(remoteLogService); + } + + @Bean + public SysLogAspect sysLogAspect() { + return new SysLogAspect(); + } +} diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/annotation/SysLog.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/annotation/SysLog.java new file mode 100644 index 000000000..8fcd4bf1a --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/annotation/SysLog.java @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.log.annotation; + +import java.lang.annotation.*; + +/** + * @author lengleng + * @date 2018/6/28 + * 操作日志注解 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface SysLog { + + /** + * 描述 + * + * @return {String} + */ + String value(); +} diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/aspect/SysLogAspect.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/aspect/SysLogAspect.java new file mode 100644 index 000000000..0b55b399b --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/aspect/SysLogAspect.java @@ -0,0 +1,57 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.log.aspect; + +import com.pig4cloud.pigx.common.log.annotation.SysLog; +import com.pig4cloud.pigx.common.log.event.SysLogEvent; +import com.pig4cloud.pigx.common.log.util.SysLogUtils; +import com.pig4cloud.pigx.common.core.util.SpringContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; + +/** + * 操作日志使用spring event异步入库 + * + * @author L.cm + */ +@Aspect +@Slf4j +public class SysLogAspect { + + @Around("@annotation(sysLog)") + public Object aroundWxApi(ProceedingJoinPoint point, SysLog sysLog) throws Throwable { + String strClassName = point.getTarget().getClass().getName(); + String strMethodName = point.getSignature().getName(); + log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName); + + com.pig4cloud.pigx.admin.api.entity.SysLog logVo = SysLogUtils.getSysLog(); + logVo.setTitle(sysLog.value()); + // 发送异步日志事件 + Long startTime = System.currentTimeMillis(); + Object obj = point.proceed(); + Long endTime = System.currentTimeMillis(); + logVo.setTime(endTime - startTime); + SpringContextHolder.publishEvent(new SysLogEvent(logVo)); + return obj; + } + +} diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/event/SysLogEvent.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/event/SysLogEvent.java new file mode 100644 index 000000000..17b7674be --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/event/SysLogEvent.java @@ -0,0 +1,34 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.log.event; + +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import org.springframework.context.ApplicationEvent; + +/** + * @author lengleng + * 系统日志事件 + */ +public class SysLogEvent extends ApplicationEvent { + + public SysLogEvent(SysLog source) { + super(source); + } +} diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/event/SysLogListener.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/event/SysLogListener.java new file mode 100644 index 000000000..74d8801c5 --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/event/SysLogListener.java @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.log.event; + +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.api.feign.RemoteLogService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.core.annotation.Order; +import org.springframework.scheduling.annotation.Async; + + +/** + * @author lengleng + * 异步监听日志事件 + */ +@Slf4j +@AllArgsConstructor +public class SysLogListener { + private final RemoteLogService remoteLogService; + + @Async + @Order + @EventListener(SysLogEvent.class) + public void saveSysLog(SysLogEvent event) { + SysLog sysLog = (SysLog) event.getSource(); + remoteLogService.saveLog(sysLog); + } +} diff --git a/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java new file mode 100644 index 000000000..21cd3d7fb --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/java/com/pig4cloud/pigx/common/log/util/SysLogUtils.java @@ -0,0 +1,66 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.log.util; + +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.URLUtil; +import cn.hutool.http.HttpUtil; +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.security.util.SecurityUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +/** + * 系统日志工具类 + * + * @author L.cm + */ +public class SysLogUtils { + + private static final String PASSWORD = "password"; + + public static SysLog getSysLog() { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + StringBuilder params = new StringBuilder(); + request.getParameterMap().forEach((key, values) -> { + params.append(key).append("="); + if (PASSWORD.equalsIgnoreCase(key)) { + params.append("******"); + } else { + params.append(ArrayUtil.toString(values)); + } + params.append("&"); + }); + + SysLog sysLog = new SysLog(); + sysLog.setCreateBy(SecurityUtils.getUser()); + sysLog.setType(CommonConstant.STATUS_NORMAL); + sysLog.setRemoteAddr(HttpUtil.getClientIP(request)); + sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI())); + sysLog.setMethod(request.getMethod()); + sysLog.setUserAgent(request.getHeader("user-agent")); + sysLog.setParams(HttpUtil.toParams(request.getParameterMap())); + sysLog.setServiceId(SecurityUtils.getClientId()); + return sysLog; + } +} diff --git a/pigx-common/pigx-common-log/src/main/resources/META-INF/spring-devtools.properties b/pigx-common/pigx-common-log/src/main/resources/META-INF/spring-devtools.properties new file mode 100644 index 000000000..76296deab --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/resources/META-INF/spring-devtools.properties @@ -0,0 +1 @@ +restart.include.pigx-common-security=/pigx-common-log[\\w-]+\.jar diff --git a/pigx-common/pigx-common-log/src/main/resources/META-INF/spring.factories b/pigx-common/pigx-common-log/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..0fa28a4dd --- /dev/null +++ b/pigx-common/pigx-common-log/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.pig4cloud.pigx.common.log.LogAutoConfiguration diff --git a/pigx-common/pigx-common-security/pom.xml b/pigx-common/pigx-common-security/pom.xml new file mode 100644 index 000000000..93b02bbd6 --- /dev/null +++ b/pigx-common/pigx-common-security/pom.xml @@ -0,0 +1,59 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx-common + ${pigx.version} + + + pigx-common-security + ${pigx.version} + jar + pigx-common-security + pigx 安全工具类 + + + + + + com.pig4cloud + pigx-common-core + ${pigx.version} + + + + org.springframework.cloud + spring-cloud-starter-security + + + + io.github.openfeign + feign-okhttp + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PermissionService.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PermissionService.java new file mode 100644 index 000000000..1c42a2812 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PermissionService.java @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.security.compoent; + +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.util.PatternMatchUtils; +import org.springframework.util.StringUtils; + +import java.util.Collection; + +/** + * @author lengleng + * @date 2018/6/22 + * 接口权限判断工具 + */ +@Slf4j +@Component("pms") +public class PermissionService { + /** + * 判断接口是否有xxx:xxx权限 + * + * @param permission 权限 + * @return {boolean} + */ + public boolean hasPermission(String permission) { + if (StrUtil.isBlank(permission)) { + return false; + } + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) { + return false; + } + Collection authorities = authentication.getAuthorities(); + return authorities.stream() + .map(GrantedAuthority::getAuthority) + .filter(StringUtils::hasText) + .anyMatch(x -> PatternMatchUtils.simpleMatch(permission, x)); + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PigAccessDeniedHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PigAccessDeniedHandler.java new file mode 100644 index 000000000..406021199 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PigAccessDeniedHandler.java @@ -0,0 +1,74 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.security.compoent; + +/** + * @author lengleng + * @date 2018/6/22 + */ + +import cn.hutool.http.HttpStatus; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.exception.PigDeniedException; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * @author lengleng + * 授权拒绝处理器,覆盖默认的OAuth2AccessDeniedHandler + * 包装失败信息到PigDeniedException + */ +@Slf4j +@Component +@AllArgsConstructor +public class PigAccessDeniedHandler extends OAuth2AccessDeniedHandler { + private final ObjectMapper objectMapper; + + /** + * 授权拒绝处理,使用R包装 + * + * @param request request + * @param response response + * @param authException authException + * @throws IOException IOException + * @throws ServletException ServletException + */ + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException { + log.info("授权失败,禁止访问 {}", request.getRequestURI()); + response.setCharacterEncoding(CommonConstant.UTF8); + response.setContentType(CommonConstant.CONTENT_TYPE); + R result = new R<>(new PigDeniedException("授权失败,禁止访问")); + response.setStatus(HttpStatus.HTTP_FORBIDDEN); + PrintWriter printWriter = response.getWriter(); + printWriter.append(objectMapper.writeValueAsString(result)); + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PigxWebResponseExceptionTranslator.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PigxWebResponseExceptionTranslator.java new file mode 100644 index 000000000..0aa33d6f2 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/PigxWebResponseExceptionTranslator.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.compoent; + +import com.pig4cloud.pigx.common.security.exception.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.oauth2.common.DefaultThrowableAnalyzer; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.common.exceptions.InsufficientScopeException; +import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; +import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; +import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator; +import org.springframework.security.web.util.ThrowableAnalyzer; +import org.springframework.web.HttpRequestMethodNotSupportedException; + +import java.io.IOException; + +/** + * @author lengleng + * @date 2018/7/8 + * 异常处理,重写oauth 默认实现 + */ +@Slf4j +public class PigxWebResponseExceptionTranslator implements WebResponseExceptionTranslator { + + private ThrowableAnalyzer throwableAnalyzer = new DefaultThrowableAnalyzer(); + + @Override + public ResponseEntity translate(Exception e) throws Exception { + + // Try to extract a SpringSecurityException from the stacktrace + Throwable[] causeChain = throwableAnalyzer.determineCauseChain(e); + + Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class, + causeChain); + if (ase != null) { + return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e)); + } + + ase = (AccessDeniedException) throwableAnalyzer + .getFirstThrowableOfType(AccessDeniedException.class, causeChain); + if (ase != null) { + return handleOAuth2Exception(new ForbiddenException(ase.getMessage(), ase)); + } + + ase = (InvalidGrantException) throwableAnalyzer + .getFirstThrowableOfType(InvalidGrantException.class, causeChain); + if (ase != null) { + return handleOAuth2Exception(new InvalidException(ase.getMessage(), ase)); + } + + ase = (HttpRequestMethodNotSupportedException) throwableAnalyzer + .getFirstThrowableOfType(HttpRequestMethodNotSupportedException.class, causeChain); + if (ase != null) { + return handleOAuth2Exception(new MethodNotAllowed(ase.getMessage(), ase)); + } + + ase = (OAuth2Exception) throwableAnalyzer.getFirstThrowableOfType( + OAuth2Exception.class, causeChain); + + if (ase != null) { + return handleOAuth2Exception((OAuth2Exception) ase); + } + + return handleOAuth2Exception(new ServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), e)); + + } + + private ResponseEntity handleOAuth2Exception(OAuth2Exception e) throws IOException { + + int status = e.getHttpErrorCode(); + HttpHeaders headers = new HttpHeaders(); + headers.set("Cache-Control", "no-store"); + headers.set("Pragma", "no-cache"); + if (status == HttpStatus.UNAUTHORIZED.value() || (e instanceof InsufficientScopeException)) { + headers.set("WWW-Authenticate", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary())); + } + + ResponseEntity response = new ResponseEntity<>(new PigxAuth2Exception(e.getMessage()), headers, + HttpStatus.valueOf(status)); + + return response; + + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/ResourceAuthExceptionEntryPoint.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/ResourceAuthExceptionEntryPoint.java new file mode 100644 index 000000000..33d2252bf --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/compoent/ResourceAuthExceptionEntryPoint.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.compoent; + +import cn.hutool.http.HttpStatus; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * @author lengleng + * @date 2018/7/8 + * 客户端异常处理 + * 1. 可以根据 AuthenticationException 不同细化异常处理 + */ +@Slf4j +@Component +@AllArgsConstructor +public class ResourceAuthExceptionEntryPoint implements AuthenticationEntryPoint { + private final ObjectMapper objectMapper; + + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, + AuthenticationException authException) throws IOException { + response.setCharacterEncoding(CommonConstant.UTF8); + response.setContentType(CommonConstant.CONTENT_TYPE); + R result = new R<>(); + result.setCode(HttpStatus.HTTP_UNAUTHORIZED); + if (authException != null) { + result.setMsg("error"); + result.setData(authException.getMessage()); + } + response.setStatus(HttpStatus.HTTP_UNAUTHORIZED); + PrintWriter printWriter = response.getWriter(); + printWriter.append(objectMapper.writeValueAsString(result)); + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/ForbiddenException.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/ForbiddenException.java new file mode 100644 index 000000000..6b8236d0b --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/ForbiddenException.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +import org.springframework.http.HttpStatus; + +/** + * @author lengleng + * @date 2018/7/8 + */ +public class ForbiddenException extends PigxAuth2Exception { + + public ForbiddenException(String msg, Throwable t) { + super(msg); + } + + @Override + public String getOAuth2ErrorCode() { + return "access_denied"; + } + + @Override + public int getHttpErrorCode() { + return HttpStatus.FORBIDDEN.value(); + } + +} + diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/InvalidException.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/InvalidException.java new file mode 100644 index 000000000..487dc0b74 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/InvalidException.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +/** + * @author lengleng + * @date 2018/7/8 + */ +public class InvalidException extends PigxAuth2Exception { + + public InvalidException(String msg, Throwable t) { + super(msg); + } + + @Override + public String getOAuth2ErrorCode() { + return "invalid_exception"; + } + + @Override + public int getHttpErrorCode() { + return 426; + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/MethodNotAllowed.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/MethodNotAllowed.java new file mode 100644 index 000000000..e1274c2ec --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/MethodNotAllowed.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +import org.springframework.http.HttpStatus; + +/** + * @author lengleng + * @date 2018/7/8 + */ +public class MethodNotAllowed extends PigxAuth2Exception { + + public MethodNotAllowed(String msg, Throwable t) { + super(msg); + } + + @Override + public String getOAuth2ErrorCode() { + return "method_not_allowed"; + } + + @Override + public int getHttpErrorCode() { + return HttpStatus.METHOD_NOT_ALLOWED.value(); + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/PigxAuth2Exception.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/PigxAuth2Exception.java new file mode 100644 index 000000000..e50e2299d --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/PigxAuth2Exception.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; + +import java.util.Map; + +/** + * @author lengleng + * @date 2018/7/8 + * 自定义OAuth2Exception + */ +public class PigxAuth2Exception extends OAuth2Exception { + + public PigxAuth2Exception(String msg) { + super(msg); + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/ServerErrorException.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/ServerErrorException.java new file mode 100644 index 000000000..53e723b28 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/ServerErrorException.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +import org.springframework.http.HttpStatus; + +/** + * @author lengleng + * @date 2018/7/8 + */ +public class ServerErrorException extends PigxAuth2Exception { + + public ServerErrorException(String msg, Throwable t) { + super(msg); + } + + @Override + public String getOAuth2ErrorCode() { + return "server_error"; + } + + @Override + public int getHttpErrorCode() { + return HttpStatus.INTERNAL_SERVER_ERROR.value(); + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/UnauthorizedException.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/UnauthorizedException.java new file mode 100644 index 000000000..0d01007c6 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/UnauthorizedException.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +import org.springframework.http.HttpStatus; + +/** + * @author lengleng + * @date 2018/7/8 + */ +public class UnauthorizedException extends PigxAuth2Exception { + + public UnauthorizedException(String msg, Throwable t) { + super(msg); + } + + @Override + public String getOAuth2ErrorCode() { + return "unauthorized"; + } + + @Override + public int getHttpErrorCode() { + return HttpStatus.UNAUTHORIZED.value(); + } + +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/interceptor/PigxFeignClientIntercept.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/interceptor/PigxFeignClientIntercept.java new file mode 100644 index 000000000..141c99a36 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/interceptor/PigxFeignClientIntercept.java @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.security.interceptor; + +import feign.RequestInterceptor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.oauth2.client.OAuth2ClientContext; +import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; + +/** + * @author lengleng + * @date 2018/6/22 + * feign 拦截器传递 header 中oauth token, + * 使用hystrix 的信号量模式 + */ +@Configuration +@ConditionalOnProperty("security.oauth2.client.client-id") +public class PigxFeignClientIntercept { + @Bean + public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext, + OAuth2ProtectedResourceDetails resource) { + return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, resource); + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java new file mode 100644 index 000000000..ae1c8190e --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java @@ -0,0 +1,94 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.common.security.util; + + +import cn.hutool.core.util.StrUtil; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.oauth2.provider.OAuth2Authentication; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * 安全工具类 + * + * @author L.cm + */ +public class SecurityUtils { + + /** + * 获取Authentication + */ + public static Authentication getAuthentication() { + return SecurityContextHolder.getContext().getAuthentication(); + } + + /** + * 获取用户 + */ + public static String getUser(Authentication authentication) { + Object principal = authentication.getPrincipal(); + if (principal == null) { + return null; + } + return (String) principal; + } + + public static String getClientId() { + Authentication authentication = getAuthentication(); + if (authentication instanceof OAuth2Authentication) { + OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication; + return auth2Authentication.getOAuth2Request().getClientId(); + } + return null; + } + + /** + * 获取用户 + */ + public static String getUser() { + Authentication authentication = getAuthentication(); + if (authentication == null) { + return null; + } + return getUser(authentication); + } + + /** + * 获取用户角色信息 + * + * @return 角色集合 + */ + public static List getRoles() { + Authentication authentication = getAuthentication(); + Collection authorities = authentication.getAuthorities(); + + List roles = new ArrayList<>(); + authorities.stream() + .filter(granted -> StrUtil.startWith(granted.getAuthority(), SecurityConstants.ROLE)) + .forEach(granted -> roles.add(StrUtil.removePrefix(granted.getAuthority(), SecurityConstants.ROLE))); + return roles; + } +} diff --git a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring-devtools.properties b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring-devtools.properties new file mode 100644 index 000000000..0a52a6fde --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring-devtools.properties @@ -0,0 +1 @@ +restart.include.pigx-common-security=/pigx-common-security[\\w-]+\.jar diff --git a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..caa397bbd --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories @@ -0,0 +1,5 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.pig4cloud.pigx.common.security.compoent.PermissionService,\ + com.pig4cloud.pigx.common.security.compoent.PigAccessDeniedHandler,\ + com.pig4cloud.pigx.common.security.compoent.ResourceAuthExceptionEntryPoint,\ + com.pig4cloud.pigx.common.security.interceptor.PigxFeignClientIntercept diff --git a/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.provides b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.provides new file mode 100644 index 000000000..c3a54e58e --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: pigx-common-core, spring-cloud-starter-security diff --git a/pigx-common/pigx-common-security/src/main/resources/org/springframework/security/messages_zh_CN.properties b/pigx-common/pigx-common-security/src/main/resources/org/springframework/security/messages_zh_CN.properties new file mode 100644 index 000000000..8a6bf9187 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/resources/org/springframework/security/messages_zh_CN.properties @@ -0,0 +1,64 @@ +# +# +# Copyright (c) 2018-2025, lengleng All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# Neither the name of the pig4cloud.com developer nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# Author: lengleng (wangiegie@gmail.com) +# +# +AbstractAccessDecisionManager.accessDenied=\u4E0D\u5141\u8BB8\u8BBF\u95EE +AbstractLdapAuthenticationProvider.emptyPassword=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A +AbstractSecurityInterceptor.authenticationNotFound=\u672A\u5728SecurityContext\u4E2D\u67E5\u627E\u5230\u8BA4\u8BC1\u5BF9\u8C61 +AbstractUserDetailsAuthenticationProvider.badCredentials=\u7528\u6237\u540D\u4E0D\u5B58\u5728\u6216\u8005\u5BC6\u7801\u9519\u8BEF +AbstractUserDetailsAuthenticationProvider.credentialsExpired=\u7528\u6237\u51ED\u8BC1\u5DF2\u8FC7\u671F +AbstractUserDetailsAuthenticationProvider.disabled=\u7528\u6237\u672A\u6FC0\u6D3B +AbstractUserDetailsAuthenticationProvider.expired=\u7528\u6237\u5E10\u53F7\u5DF2\u8FC7\u671F +AbstractUserDetailsAuthenticationProvider.locked=\u7528\u6237\u5E10\u53F7\u5DF2\u88AB\u9501\u5B9A +AbstractUserDetailsAuthenticationProvider.onlySupports=\u4EC5\u4EC5\u652F\u6301UsernamePasswordAuthenticationToken +AccountStatusUserDetailsChecker.credentialsExpired=\u7528\u6237\u51ED\u8BC1\u5DF2\u8FC7\u671F +AccountStatusUserDetailsChecker.disabled=\u7528\u6237\u672A\u6FC0\u6D3B +AccountStatusUserDetailsChecker.expired=\u7528\u6237\u5E10\u53F7\u5DF2\u8FC7\u671F +AccountStatusUserDetailsChecker.locked=\u7528\u6237\u5E10\u53F7\u5DF2\u88AB\u9501\u5B9A +AclEntryAfterInvocationProvider.noPermission=\u7ED9\u5B9A\u7684Authentication\u5BF9\u8C61({0})\u6839\u672C\u65E0\u6743\u64CD\u63A7\u9886\u57DF\u5BF9\u8C61({1}) +AnonymousAuthenticationProvider.incorrectKey=\u5C55\u793A\u7684AnonymousAuthenticationToken\u4E0D\u542B\u6709\u9884\u671F\u7684key +BindAuthenticator.badCredentials=\u5BC6\u7801\u9519\u8BEF +BindAuthenticator.emptyPassword=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A +CasAuthenticationProvider.incorrectKey=\u5C55\u793A\u7684CasAuthenticationToken\u4E0D\u542B\u6709\u9884\u671F\u7684key +CasAuthenticationProvider.noServiceTicket=\u672A\u80FD\u591F\u6B63\u786E\u63D0\u4F9B\u5F85\u9A8C\u8BC1\u7684CAS\u670D\u52A1\u7968\u6839 +ConcurrentSessionControlAuthenticationStrategy.exceededAllowed=\u5DF2\u7ECF\u8D85\u8FC7\u4E86\u5F53\u524D\u4E3B\u4F53({0})\u88AB\u5141\u8BB8\u7684\u6700\u5927\u4F1A\u8BDD\u6570\u91CF +DigestAuthenticationFilter.incorrectRealm=\u54CD\u5E94\u7ED3\u679C\u4E2D\u7684Realm\u540D\u5B57({0})\u540C\u7CFB\u7EDF\u6307\u5B9A\u7684Realm\u540D\u5B57({1})\u4E0D\u543B\u5408 +DigestAuthenticationFilter.incorrectResponse=\u9519\u8BEF\u7684\u54CD\u5E94\u7ED3\u679C +DigestAuthenticationFilter.missingAuth=\u9057\u6F0F\u4E86\u9488\u5BF9'auth' QOP\u7684\u3001\u5FC5\u987B\u7ED9\u5B9A\u7684\u6458\u8981\u53D6\u503C; \u63A5\u6536\u5230\u7684\u5934\u4FE1\u606F\u4E3A{0} +DigestAuthenticationFilter.missingMandatory=\u9057\u6F0F\u4E86\u5FC5\u987B\u7ED9\u5B9A\u7684\u6458\u8981\u53D6\u503C; \u63A5\u6536\u5230\u7684\u5934\u4FE1\u606F\u4E3A{0} +DigestAuthenticationFilter.nonceCompromised=Nonce\u4EE4\u724C\u5DF2\u7ECF\u5B58\u5728\u95EE\u9898\u4E86\uFF0C{0} +DigestAuthenticationFilter.nonceEncoding=Nonce\u672A\u7ECF\u8FC7Base64\u7F16\u7801; \u76F8\u5E94\u7684nonce\u53D6\u503C\u4E3A {0} +DigestAuthenticationFilter.nonceExpired=Nonce\u5DF2\u7ECF\u8FC7\u671F/\u8D85\u65F6 +DigestAuthenticationFilter.nonceNotNumeric=Nonce\u4EE4\u724C\u7684\u7B2C1\u90E8\u5206\u5E94\u8BE5\u662F\u6570\u5B57\uFF0C\u4F46\u7ED3\u679C\u5374\u662F{0} +DigestAuthenticationFilter.nonceNotTwoTokens=Nonce\u5E94\u8BE5\u7531\u4E24\u90E8\u5206\u53D6\u503C\u6784\u6210\uFF0C\u4F46\u7ED3\u679C\u5374\u662F{0} +DigestAuthenticationFilter.usernameNotFound=\u7528\u6237\u540D{0}\u672A\u627E\u5230 +JdbcDaoImpl.noAuthority=\u6CA1\u6709\u4E3A\u7528\u6237{0}\u6307\u5B9A\u89D2\u8272 +JdbcDaoImpl.notFound=\u672A\u627E\u5230\u7528\u6237{0} +LdapAuthenticationProvider.badCredentials=\u574F\u7684\u51ED\u8BC1 +LdapAuthenticationProvider.credentialsExpired=\u7528\u6237\u51ED\u8BC1\u5DF2\u8FC7\u671F +LdapAuthenticationProvider.disabled=\u7528\u6237\u672A\u6FC0\u6D3B +LdapAuthenticationProvider.expired=\u7528\u6237\u5E10\u53F7\u5DF2\u8FC7\u671F +LdapAuthenticationProvider.locked=\u7528\u6237\u5E10\u53F7\u5DF2\u88AB\u9501\u5B9A +LdapAuthenticationProvider.emptyUsername=\u7528\u6237\u540D\u4E0D\u5141\u8BB8\u4E3A\u7A7A +LdapAuthenticationProvider.onlySupports=\u4EC5\u4EC5\u652F\u6301UsernamePasswordAuthenticationToken +PasswordComparisonAuthenticator.badCredentials=\u574F\u7684\u51ED\u8BC1 +ProviderManager.providerNotFound=\u672A\u67E5\u627E\u5230\u9488\u5BF9{0}\u7684AuthenticationProvider +RememberMeAuthenticationProvider.incorrectKey=\u5C55\u793ARememberMeAuthenticationToken\u4E0D\u542B\u6709\u9884\u671F\u7684key +RunAsImplAuthenticationProvider.incorrectKey=\u5C55\u793A\u7684RunAsUserToken\u4E0D\u542B\u6709\u9884\u671F\u7684key +SubjectDnX509PrincipalExtractor.noMatching=\u672A\u5728subjectDN\: {0}\u4E2D\u627E\u5230\u5339\u914D\u7684\u6A21\u5F0F +SwitchUserFilter.noCurrentUser=\u4E0D\u5B58\u5728\u5F53\u524D\u7528\u6237 +SwitchUserFilter.noOriginalAuthentication=\u4E0D\u80FD\u591F\u67E5\u627E\u5230\u539F\u5148\u7684\u5DF2\u8BA4\u8BC1\u5BF9\u8C61 diff --git a/pigx-common/pigx-common-swagger/pom.xml b/pigx-common/pigx-common-swagger/pom.xml new file mode 100644 index 000000000..898226da2 --- /dev/null +++ b/pigx-common/pigx-common-swagger/pom.xml @@ -0,0 +1,58 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx-common + ${pigx.version} + + + pigx-common-swagger + ${pigx.version} + jar + pigx-common-log + pigx 接口文档 + + + + + + com.pig4cloud + pigx-common-security + ${pigx.version} + + + + javax.servlet + javax.servlet-api + ${servlet-api.version} + provided + + + + io.springfox + springfox-swagger2 + ${swagger.version} + + + diff --git a/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/annotation/EnablePigxSwagger2.java b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/annotation/EnablePigxSwagger2.java new file mode 100644 index 000000000..9285ad651 --- /dev/null +++ b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/annotation/EnablePigxSwagger2.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.swagger.annotation; + +import com.pig4cloud.pigx.common.swagger.config.SwaggerAutoConfiguration; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +/** + * @author lengleng + * @date 2018/7/21 + * 开启pigx swagger + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@Import({SwaggerAutoConfiguration.class}) +public @interface EnablePigxSwagger2 { +} diff --git a/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java new file mode 100644 index 000000000..023318331 --- /dev/null +++ b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ +package com.pig4cloud.pigx.common.swagger.config; + + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author Sywd + * swagger配置 + */ +@Configuration +@EnableSwagger2 +@EnableAutoConfiguration +public class SwaggerAutoConfiguration { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() + .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()) + .build().securitySchemes(Collections.singletonList(securitySchema())) + .securityContexts(Collections.singletonList(securityContext())).pathMapping("/"); + } + + private SecurityContext securityContext() { + return SecurityContext.builder().securityReferences(defaultAuth()) + .forPaths(PathSelectors.ant("/**")) + .build(); + } + + private List defaultAuth() { + + final AuthorizationScope[] authorizationScopes = new AuthorizationScope[3]; + authorizationScopes[0] = new AuthorizationScope("read", "read all"); + authorizationScopes[1] = new AuthorizationScope("trust", "trust all"); + authorizationScopes[2] = new AuthorizationScope("write", "write all"); + + return Collections.singletonList(new SecurityReference("pigX OAuth", authorizationScopes)); + } + + + private OAuth securitySchema() { + ArrayList authorizationScopeList = new ArrayList(); + authorizationScopeList.add(new AuthorizationScope("server", "server all")); + authorizationScopeList.add(new AuthorizationScope("read", "read all")); + authorizationScopeList.add(new AuthorizationScope("write", "access all")); + + ArrayList grantTypes = new ArrayList(); + GrantType creGrant = new ResourceOwnerPasswordCredentialsGrant("http://localhost:9999/auth/oauth/token"); + + grantTypes.add(creGrant); + return new OAuth("pigX OAuth", authorizationScopeList, grantTypes); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("PigX Swagger API ") + .description("https://gitee.com/log4j/pig/wikis") + .termsOfServiceUrl("https://gitee.wang/pig/pigx") + .contact(new Contact("冷冷", "https://gitee.wang/pig/pigx", "wangiegie@gmail.com")) + .version("2.0") + .build(); + } + +} diff --git a/pigx-common/pom.xml b/pigx-common/pom.xml new file mode 100644 index 000000000..441f743c3 --- /dev/null +++ b/pigx-common/pom.xml @@ -0,0 +1,42 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + pigx-common + ${pigx.version} + pom + pigx-common + pigx 公共聚合模块 + + + pigx-common-core + pigx-common-log + pigx-common-security + pigx-common-swagger + + diff --git a/pigx-config/Dockerfile b/pigx-config/Dockerfile new file mode 100644 index 000000000..fa772aea8 --- /dev/null +++ b/pigx-config/Dockerfile @@ -0,0 +1,13 @@ +FROM anapsix/alpine-java:8_server-jre_unlimited + +MAINTAINER wangiegie@gmail.com + +RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-config + +WORKDIR /pigx/bin/com.pig4cloud/pigx-config + +EXPOSE 1025 + +ADD ./pigx-config/target/pigx-config.jar ./ + +CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-config.jar diff --git a/pigx-config/pom.xml b/pigx-config/pom.xml new file mode 100644 index 000000000..93c74f180 --- /dev/null +++ b/pigx-config/pom.xml @@ -0,0 +1,75 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + pigx-config + ${pigx.version} + jar + + pigx-config + pigx 配置中心,基于spring cloud config + + + + + org.springframework.cloud + spring-cloud-config-server + + + + org.springframework.boot + spring-boot-starter-web + + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${project.name} + + + + + + diff --git a/pigx-config/src/main/java/com/pig4cloud/pigx/config/PigxConfigApplication.java b/pigx-config/src/main/java/com/pig4cloud/pigx/config/PigxConfigApplication.java new file mode 100644 index 000000000..23e6f4790 --- /dev/null +++ b/pigx-config/src/main/java/com/pig4cloud/pigx/config/PigxConfigApplication.java @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.cloud.config.server.EnableConfigServer; + +/** + * @author lengleng + * @date 2018年06月22日 + * 配置中心 + */ +@EnableConfigServer +@SpringCloudApplication +public class PigxConfigApplication { + + public static void main(String[] args) { + SpringApplication.run(PigxConfigApplication.class, args); + } +} diff --git a/pigx-config/src/main/resources/bootstrap.yml b/pigx-config/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..5564b817f --- /dev/null +++ b/pigx-config/src/main/resources/bootstrap.yml @@ -0,0 +1,29 @@ +server: + port: 4001 + +spring: + application: + name: pigx-config + profiles: + active: native + # 配置中心 + cloud: + config: + server: + native: + search-locations: classpath:/config/ + +# 注册中心配置 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://pig:pig@localhost:1025/eureka/ + +# 暴露监控端点 +management: + endpoints: + web: + exposure: + include: '*' diff --git a/pigx-config/src/main/resources/config/application-dev.yml b/pigx-config/src/main/resources/config/application-dev.yml new file mode 100644 index 000000000..5e8f77d89 --- /dev/null +++ b/pigx-config/src/main/resources/config/application-dev.yml @@ -0,0 +1,48 @@ +# redis 相关 +spring: + redis: + password: + host: localhost +# 暴露监控端点 +management: + endpoints: + web: + exposure: + include: '*' + +# feign 配置 +feign: + hystrix: + enabled: true + okhttp: + enabled: true + httpclient: + enabled: false + client: + config: + feignName: + connectTimeout: 10000 + readTimeout: 10000 + compression: + request: + enabled: true + response: + enabled: true +# hystrix If you need to use ThreadLocal bound variables in your RequestInterceptor`s +# you will need to either set the thread isolation strategy for Hystrix to `SEMAPHORE or disable Hystrix in Feign. +hystrix: + command: + default: + execution: + isolation: + strategy: SEMAPHORE + thread: + timeoutInMilliseconds: 60000 + shareSecurityContext: true + +#请求处理的超时时间 +ribbon: + ReadTimeout: 10000 + ConnectTimeout: 10000 + + diff --git a/pigx-config/src/main/resources/config/pigx-auth-dev.yml b/pigx-config/src/main/resources/config/pigx-auth-dev.yml new file mode 100644 index 000000000..0c0a5346a --- /dev/null +++ b/pigx-config/src/main/resources/config/pigx-auth-dev.yml @@ -0,0 +1,8 @@ +# 数据源 +spring: + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.jdbc.Driver + username: root + password: root + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false diff --git a/pigx-config/src/main/resources/config/pigx-gateway-dev.yml b/pigx-config/src/main/resources/config/pigx-gateway-dev.yml new file mode 100644 index 000000000..30b6e0db8 --- /dev/null +++ b/pigx-config/src/main/resources/config/pigx-gateway-dev.yml @@ -0,0 +1,49 @@ +spring: + cloud: + gateway: + locator: + enabled: true + routes: + - id: pigx-auth + uri: lb://pigx-auth + predicates: + - Path=/auth/** + filters: + # 验证码处理 + - ImageCodeGatewayFilter + # 前端密码解密 + - PasswordDecoderFilter + - StripPrefix=1 + - id: pigx-upms + uri: lb://pigx-upms + predicates: + - Path=/admin/** + filters: + # Swagger请求头处理 + - SwaggerHeaderFilter + # 请求头清理避免不合法请求头 + - name: RemoveRequestHeader + args: + name: from + # 限流配置 + - name: RequestRateLimiter + args: + key-resolver: '#{@remoteAddrKeyResolver}' + redis-rate-limiter.replenishRate: 10 + redis-rate-limiter.burstCapacity: 20 + - StripPrefix=1 + # 降级配置 + - name: Hystrix + args: + name: default + fallbackUri: 'forward:/fallback' + +security: + encode: + # 前端密码密钥,必须16位 + key: 'pigxpigxpigxpigx' + +# 不校验验证码终端 +ignore: + clients: + - test diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml new file mode 100644 index 000000000..690527469 --- /dev/null +++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml @@ -0,0 +1,40 @@ +## spring security 配置 +security: + oauth2: + client: + client-id: pig + client-secret: pig + scope: server + resource: + token-info-uri: http://localhost:9999/auth/oauth/check_token + +# 数据源 +spring: + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.jdbc.Driver + username: root + password: root + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + +#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等 +mybatis-plus: + mapper-locations: classpath:/mapper/*Mapper.xml + typeAliasesPackage: com.pig4cloud.pigx.admin.api.entity + global-config: + #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; + id-type: 0 + #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断" + field-strategy: 1 + #驼峰下划线转换 + db-column-underline: true + #刷新mapper 调试神器 + refresh-mapper: true + # 逻辑删除字段 + logic-delete-value: 1 + logic-not-delete-value: 0 + #自定义SQL注入器 + sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector + configuration: + map-underscore-to-camel-case: true + cache-enabled: true diff --git a/pigx-eureka/Dockerfile b/pigx-eureka/Dockerfile new file mode 100644 index 000000000..e05fb249b --- /dev/null +++ b/pigx-eureka/Dockerfile @@ -0,0 +1,13 @@ +FROM anapsix/alpine-java:8_server-jre_unlimited + +MAINTAINER wangiegie@gmail.com + +RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-eureka + +WORKDIR /pigx/bin/com.pig4cloud/pigx-eureka + +EXPOSE 1025 + +ADD ./pigx-eureka/target/pigx-eureka.jar ./ + +CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-eureka.jar diff --git a/pigx-eureka/pom.xml b/pigx-eureka/pom.xml new file mode 100644 index 000000000..963a5f786 --- /dev/null +++ b/pigx-eureka/pom.xml @@ -0,0 +1,80 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + com.pig4cloud.pigx + pigx-eureka + ${pigx.version} + jar + + pigx-eureka + pigx 服务中心,基于eureka + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + org.springframework.cloud + spring-cloud-starter-security + + + + org.springframework.boot + spring-boot-starter-web + + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${project.name} + + + + + + diff --git a/pigx-eureka/src/main/java/com/pig4cloud/pigx/eureka/PigxEurekaApplication.java b/pigx-eureka/src/main/java/com/pig4cloud/pigx/eureka/PigxEurekaApplication.java new file mode 100644 index 000000000..c95bdb2c3 --- /dev/null +++ b/pigx-eureka/src/main/java/com/pig4cloud/pigx/eureka/PigxEurekaApplication.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.eureka; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +/** + * @author lengleng + * @date 2018年06月21日 + * 服务中心 + */ +@EnableEurekaServer +@SpringBootApplication +public class PigxEurekaApplication { + + public static void main(String[] args) { + SpringApplication.run(PigxEurekaApplication.class, args); + } +} diff --git a/pigx-eureka/src/main/java/com/pig4cloud/pigx/eureka/security/WebSecurityConfig.java b/pigx-eureka/src/main/java/com/pig4cloud/pigx/eureka/security/WebSecurityConfig.java new file mode 100644 index 000000000..3faacc7d4 --- /dev/null +++ b/pigx-eureka/src/main/java/com/pig4cloud/pigx/eureka/security/WebSecurityConfig.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.eureka.security; + +/** + * @author lengleng + * @date 2018/7/12 + */ + +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable() + .authorizeRequests() + .antMatchers("actuator/**").permitAll() + .anyRequest() + .authenticated().and().httpBasic(); + } +} diff --git a/pigx-eureka/src/main/resources/bootstrap.yml b/pigx-eureka/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..2c36ec856 --- /dev/null +++ b/pigx-eureka/src/main/resources/bootstrap.yml @@ -0,0 +1,32 @@ +server: + port: 1025 + +spring: + security: + user: + name: pig + password: pig + application: + name: pigx-eureka + +# docker-compose部署时候 hostname 换成pigx-eureka +# 类似的 redis 使用pigx-redis ,gateway 换成 pigx-gateway +eureka: + instance: + hostname: localhost + prefer-ip-address: true + client: + register-with-eureka: false + fetch-registry: false + service-url: + defaultZone: http://pig:pig@${eureka.instance.hostname}:${server.port}/eureka/ + server: + eviction-interval-timer-in-ms: 4000 + enable-self-preservation: false + renewal-percent-threshold: 0.9 + +management: + endpoints: + web: + exposure: + include: '*' diff --git a/pigx-gateway/Dockerfile b/pigx-gateway/Dockerfile new file mode 100644 index 000000000..40afbbe0a --- /dev/null +++ b/pigx-gateway/Dockerfile @@ -0,0 +1,13 @@ +FROM anapsix/alpine-java:8_server-jre_unlimited + +MAINTAINER wangiegie@gmail.com + +RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-gateway + +WORKDIR /pigx/bin/com.pig4cloud/pigx-gateway + +EXPOSE 1025 + +ADD ./pigx-gateway/target/pigx-gateway.jar ./ + +CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-gateway.jar diff --git a/pigx-gateway/pom.xml b/pigx-gateway/pom.xml new file mode 100644 index 000000000..437e7e34d --- /dev/null +++ b/pigx-gateway/pom.xml @@ -0,0 +1,88 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + pigx-gateway + ${pigx.version} + jar + pigx-gateway + pigx 服务网关,基于 spring cloud gateway + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + org.springframework.boot + spring-boot-starter-data-redis-reactive + + + + org.springframework.cloud + spring-cloud-starter-config + + + + com.github.axet + kaptcha + ${kaptcha.version} + + + + cn.hutool + hutool-all + ${hutool.version} + + + + io.springfox + springfox-swagger-ui + ${swagger.version} + + + io.springfox + springfox-swagger2 + ${swagger.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${project.name} + + + + + + diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/PigxGatewayApplication.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/PigxGatewayApplication.java new file mode 100644 index 000000000..387740c2d --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/PigxGatewayApplication.java @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.gateway; + + +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; + +/** + * @author lengleng + * @date 2018年06月21日 + * 网关应用 + */ +@SpringCloudApplication +public class PigxGatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(PigxGatewayApplication.class, args); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/FilterIgnorePropertiesConfig.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/FilterIgnorePropertiesConfig.java new file mode 100644 index 000000000..3aba34a94 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/FilterIgnorePropertiesConfig.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.config; + +import lombok.Data; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author lengleng + * @date 2018/7/22 + * 网关不简要终端配置 + */ +@Data +@Configuration +@RefreshScope +@ConditionalOnExpression("!'${ignore}'.isEmpty()") +@ConfigurationProperties(prefix = "ignore") +public class FilterIgnorePropertiesConfig { + private List clients = new ArrayList<>(); +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/KaptchaConfiguration.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/KaptchaConfiguration.java new file mode 100644 index 000000000..2d7db075a --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/KaptchaConfiguration.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.config; + +import com.google.code.kaptcha.impl.DefaultKaptcha; +import com.google.code.kaptcha.util.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Properties; + +/** + * @author lengleng + * @date 2017-12-21 21:12:18 + */ +@Configuration +public class KaptchaConfiguration { + + private static final String KAPTCHA_BORDER = "kaptcha.border"; + private static final String KAPTCHA_TEXTPRODUCER_FONT_COLOR = "kaptcha.textproducer.font.color"; + private static final String KAPTCHA_TEXTPRODUCER_CHAR_SPACE = "kaptcha.textproducer.char.space"; + private static final String KAPTCHA_IMAGE_WIDTH = "kaptcha.image.width"; + private static final String KAPTCHA_IMAGE_HEIGHT = "kaptcha.image.height"; + private static final String KAPTCHA_TEXTPRODUCER_CHAR_LENGTH = "kaptcha.textproducer.char.length"; + private static final Object KAPTCHA_IMAGE_FONT_SIZE = "kaptcha.textproducer.font.size"; + + /** + * 默认生成图形验证码宽度 + */ + private static final String DEFAULT_IMAGE_WIDTH = "100"; + + /** + * 默认生成图像验证码高度 + */ + private static final String DEFAULT_IMAGE_HEIGHT = "40"; + + /** + * 默认生成图形验证码长度 + */ + private static final String DEFAULT_IMAGE_LENGTH = "4"; + /** + * 边框颜色,合法值: r,g,b (and optional alpha) 或者 white,black,blue. + */ + private static final String DEFAULT_COLOR_FONT = "black"; + + /** + * 图片边框 + */ + private static final String DEFAULT_IMAGE_BORDER = "no"; + /** + * 默认图片间隔 + */ + private static final String DEFAULT_CHAR_SPACE = "5"; + /** + * 验证码文字大小 + */ + private static final String DEFAULT_IMAGE_FONT_SIZE = "30"; + + @Bean + public DefaultKaptcha producer() { + Properties properties = new Properties(); + properties.put(KAPTCHA_BORDER, DEFAULT_IMAGE_BORDER); + properties.put(KAPTCHA_TEXTPRODUCER_FONT_COLOR, DEFAULT_COLOR_FONT); + properties.put(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, DEFAULT_CHAR_SPACE); + properties.put(KAPTCHA_IMAGE_WIDTH, DEFAULT_IMAGE_WIDTH); + properties.put(KAPTCHA_IMAGE_HEIGHT, DEFAULT_IMAGE_HEIGHT); + properties.put(KAPTCHA_IMAGE_FONT_SIZE, DEFAULT_IMAGE_FONT_SIZE); + properties.put(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, DEFAULT_IMAGE_LENGTH); + Config config = new Config(properties); + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RateLimiterConfiguration.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RateLimiterConfiguration.java new file mode 100644 index 000000000..e5d1c2af3 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RateLimiterConfiguration.java @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.gateway.config; + +import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import reactor.core.publisher.Mono; + +/** + * @author lengleng + * @date 2018/7/1 + * 路由限流配置 + */ +@Configuration +public class RateLimiterConfiguration { + @Bean(value = "remoteAddrKeyResolver") + public KeyResolver remoteAddrKeyResolver() { + return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress()); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java new file mode 100644 index 000000000..c52f00318 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.config; + +import com.pig4cloud.pigx.gateway.handle.*; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; + +/** + * @author lengleng + * @date 2018/7/5 + * 路由配置信息 + */ +@Slf4j +@Configuration +@AllArgsConstructor +public class RouterFunctionConfiguration { + private final HystrixFallbackHandler hystrixFallbackHandler; + private final SwaggerResourceHandler swaggerResourceHandler; + private final SwaggerSecurityHandler swaggerSecurityHandler; + private final SwaggerUiHandler swaggerUiHandler; + private final ImageCodeHandler imageCodeHandler; + + @Bean + public RouterFunction routerFunction() { + return RouterFunctions.route( + RequestPredicates.GET("/fallback") + .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), hystrixFallbackHandler) + .andRoute(RequestPredicates.GET("/code") + .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), imageCodeHandler) + .andRoute(RequestPredicates.GET("/swagger-resources") + .and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler) + .andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui") + .and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler) + .andRoute(RequestPredicates.GET("/swagger-resources/configuration/security") + .and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler); + + } + +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/SwaggerProvider.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/SwaggerProvider.java new file mode 100644 index 000000000..d8b8a02f0 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/SwaggerProvider.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.config; + +import lombok.AllArgsConstructor; +import org.springframework.cloud.gateway.config.GatewayProperties; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.support.NameUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; +import springfox.documentation.swagger.web.SwaggerResource; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Sywd + * 聚合接口文档注册,和zuul实现类似 + */ +@Component +@Primary +@AllArgsConstructor +public class SwaggerProvider implements SwaggerResourcesProvider { + public static final String API_URI = "/v2/api-docs"; + private final RouteLocator routeLocator; + private final GatewayProperties gatewayProperties; + + + @Override + public List get() { + List resources = new ArrayList<>(); + List routes = new ArrayList<>(); + routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); + gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId())) + .forEach(routeDefinition -> routeDefinition.getPredicates().stream() + .filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName())) + .filter(predicateDefinition -> !"pigx-auth".equalsIgnoreCase(routeDefinition.getId())) + .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), + predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") + .replace("/**", API_URI))))); + return resources; + } + + private SwaggerResource swaggerResource(String name, String location) { + SwaggerResource swaggerResource = new SwaggerResource(); + swaggerResource.setName(name); + swaggerResource.setLocation(location); + swaggerResource.setSwaggerVersion("2.0"); + return swaggerResource; + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/exception/CheckedException.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/exception/CheckedException.java new file mode 100644 index 000000000..214174dc2 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/exception/CheckedException.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.exception; + +/** + * @author lengleng + * @date 2018年07月22日 + * 异常包装类 + */ +public class CheckedException extends Exception { + + private static final long serialVersionUID = 1L; + + public CheckedException() { + } + + public CheckedException(String message) { + super(message); + } + + public CheckedException(Throwable cause) { + super(cause); + } + + public CheckedException(String message, Throwable cause) { + super(message, cause); + } + + public CheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/exception/ValidateCodeException.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/exception/ValidateCodeException.java new file mode 100644 index 000000000..a86375ac3 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/exception/ValidateCodeException.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.exception; + +/** + * @author lengleng + */ +public class ValidateCodeException extends Exception { + +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ImageCodeGatewayFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ImageCodeGatewayFilter.java new file mode 100644 index 000000000..33f798076 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ImageCodeGatewayFilter.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.filter; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.StrUtil; +import com.pig4cloud.pigx.gateway.config.FilterIgnorePropertiesConfig; +import com.pig4cloud.pigx.gateway.exception.CheckedException; +import com.pig4cloud.pigx.gateway.exception.ValidateCodeException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +/** + * @author lengleng + * @date 2018/7/4 + * 验证码处理 + */ +@Slf4j +@Component +public class ImageCodeGatewayFilter extends AbstractGatewayFilterFactory { + public static final String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY"; + public static final String OAUTH_TOKEN_URL = "/oauth/token"; + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private FilterIgnorePropertiesConfig filterIgnorePropertiesConfig; + + @Override + public GatewayFilter apply(Object config) { + return (exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + + // 不是登录请求,直接向下执行 + if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath(), OAUTH_TOKEN_URL)) { + return chain.filter(exchange); + } + + // 终端设置不校验, 直接向下执行(1. 从请求参数中获取 2.从header取) + String clientId = request.getQueryParams().getFirst("client_id"); + if (StrUtil.isNotBlank(clientId)) { + if (filterIgnorePropertiesConfig.getClients().contains(clientId)) { + return chain.filter(exchange); + } + } + try { + String[] clientInfos = extractAndDecodeHeader(request); + if (filterIgnorePropertiesConfig.getClients().contains(clientInfos[0])) { + return chain.filter(exchange); + } + } catch (Exception e) { + ServerHttpResponse response = exchange.getResponse(); + response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED); + return response.setComplete(); + } + + //校验验证码合法性 + try { + checkCode(request); + } catch (ValidateCodeException e) { + ServerHttpResponse response = exchange.getResponse(); + response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED); + return response.setComplete(); + } + + return chain.filter(exchange); + }; + } + + + /** + * 检查code + * + * @param request + * @throws ValidateCodeException 校验异常 + */ + private void checkCode(ServerHttpRequest request) throws ValidateCodeException { + String code = request.getQueryParams().getFirst("code"); + + if (StrUtil.isBlank(code)) { + throw new ValidateCodeException(); + } + + String randomStr = request.getQueryParams().getFirst("randomStr"); + if (StrUtil.isBlank(randomStr)) { + throw new ValidateCodeException(); + } + + String key = DEFAULT_CODE_KEY + randomStr; + if (!redisTemplate.hasKey(key)) { + throw new ValidateCodeException(); + } + + Object codeObj = redisTemplate.opsForValue().get(key); + + if (codeObj == null) { + throw new ValidateCodeException(); + } + + String saveCode = codeObj.toString(); + if (StrUtil.isBlank(saveCode)) { + redisTemplate.delete(key); + throw new ValidateCodeException(); + } + + if (!StrUtil.equals(saveCode, code)) { + redisTemplate.delete(key); + throw new ValidateCodeException(); + } + + redisTemplate.delete(key); + } + + private static final String BASIC_ = "Basic "; + + /** + * 从header 请求中的clientId/clientsecect + * + * @param header header中的参数 + * @throws CheckedException if the Basic header is not present or is not valid + * Base64 + */ + public static String[] extractAndDecodeHeader(String header) + throws IOException, CheckedException { + + byte[] base64Token = header.substring(6).getBytes("UTF-8"); + byte[] decoded; + try { + decoded = Base64.decode(base64Token); + } catch (IllegalArgumentException e) { + throw new CheckedException( + "Failed to decode basic authentication token"); + } + + String token = new String(decoded, CharsetUtil.UTF_8); + + int delim = token.indexOf(":"); + + if (delim == -1) { + throw new CheckedException("Invalid basic authentication token"); + } + return new String[]{token.substring(0, delim), token.substring(delim + 1)}; + } + + /** + * *从header 请求中的clientId/clientsecect + * + * @param request + * @return + * @throws IOException + */ + public static String[] extractAndDecodeHeader(ServerHttpRequest request) + throws IOException, CheckedException { + String header = request.getHeaders().getFirst("Authorization"); + + if (header == null || !header.startsWith(BASIC_)) { + throw new CheckedException("请求头中client信息为空"); + } + + return extractAndDecodeHeader(header); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PasswordDecoderFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PasswordDecoderFilter.java new file mode 100644 index 000000000..025869e90 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PasswordDecoderFilter.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.filter; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.util.UriComponentsBuilder; +import reactor.core.publisher.Mono; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.net.URI; +import java.util.Map; + +/** + * @author lengleng + * @date 2018/7/15 + * 密码解密工具类 + */ +@Slf4j +@Component +public class PasswordDecoderFilter extends AbstractGatewayFilterFactory { + private static final String PASSWORD = "password"; + private static final String KEY_ALGORITHM = "AES"; + private static final String DEFAULT_CIPHER_ALGORITHM = "AES/CBC/NOPadding"; + @Value("${security.encode.key:1234567812345678}") + private String encodeKey; + + @Override + public GatewayFilter apply(Object config) { + return (exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + + // 不是登录请求,直接向下执行 + if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath(), ImageCodeGatewayFilter.OAUTH_TOKEN_URL)) { + return chain.filter(exchange); + } + + URI uri = exchange.getRequest().getURI(); + String queryParam = uri.getRawQuery(); + Map paramMap = HttpUtil.decodeParamMap(queryParam, CharsetUtil.UTF_8); + + String password = paramMap.get(PASSWORD); + if (StrUtil.isNotBlank(password)) { + try { + password = decryptAES(password, encodeKey); + } catch (Exception e) { + log.error("密码解密失败:{}", password); + return Mono.error(e); + } + paramMap.put(PASSWORD, password.trim()); + } + + URI newUri = UriComponentsBuilder.fromUri(uri) + .replaceQuery(HttpUtil.toParams(paramMap)) + .build(true) + .toUri(); + + ServerHttpRequest newRequest = exchange.getRequest().mutate().uri(newUri).build(); + return chain.filter(exchange.mutate().request(newRequest).build()); + }; + } + + + private static String decryptAES(String data, String pass) throws Exception { + Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); + SecretKeySpec keyspec = new SecretKeySpec(pass.getBytes(), KEY_ALGORITHM); + IvParameterSpec ivspec = new IvParameterSpec(pass.getBytes()); + cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec); + byte[] result = cipher.doFinal(Base64.decode(data.getBytes(CharsetUtil.UTF_8))); + return new String(result, CharsetUtil.UTF_8); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java new file mode 100644 index 000000000..964ac0d65 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.filter; + +import com.pig4cloud.pigx.gateway.config.SwaggerProvider; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.server.ServerWebExchange; + +/** + * @author Sywd + * 添加X-Forwarded-Prefix header + */ +@Component +public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { + private static final String HEADER_NAME = "X-Forwarded-Prefix"; + + @Override + public GatewayFilter apply(Object config) { + return (exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + String path = request.getURI().getPath(); + if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { + return chain.filter(exchange); + } + + String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI)); + + + ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build(); + ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); + return chain.filter(newExchange); + }; + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/HystrixFallbackHandler.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/HystrixFallbackHandler.java new file mode 100644 index 000000000..794f1080a --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/HystrixFallbackHandler.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.handle; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; + +/** + * @author lengleng + * @date 2018/7/5 + * Hystrix 降级处理 + */ +@Slf4j +@Component +public class HystrixFallbackHandler implements HandlerFunction { + @Override + public Mono handle(ServerRequest serverRequest) { + log.error("网关执行请求:{}失败,hystrix服务降级处理", serverRequest.uri()); + return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) + .contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("服务异常")); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/ImageCodeHandler.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/ImageCodeHandler.java new file mode 100644 index 000000000..98e9ddb8e --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/ImageCodeHandler.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.handle; + +import com.google.code.kaptcha.Producer; +import com.pig4cloud.pigx.gateway.filter.ImageCodeGatewayFilter; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.util.FastByteArrayOutputStream; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * @author lengleng + * @date 2018/7/5 + * 验证码生成逻辑处理类 + */ +@Slf4j +@Component +@AllArgsConstructor +public class ImageCodeHandler implements HandlerFunction { + private final Producer producer; + private final RedisTemplate redisTemplate; + + @Override + public Mono handle(ServerRequest serverRequest) { + //生成验证码 + String text = producer.createText(); + BufferedImage image = producer.createImage(text); + + //保存验证码信息 + String randomStr = serverRequest.queryParam("randomStr").get(); + redisTemplate.opsForValue().set(ImageCodeGatewayFilter.DEFAULT_CODE_KEY + randomStr, text, 60, TimeUnit.SECONDS); + + // 转换流信息写出 + FastByteArrayOutputStream os = new FastByteArrayOutputStream(); + try { + ImageIO.write(image, "jpeg", os); + } catch (IOException e) { + log.error("ImageIO write err", e); + return Mono.error(e); + } + + return ServerResponse + .status(HttpStatus.OK) + .contentType(MediaType.IMAGE_JPEG) + .body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray()))); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerResourceHandler.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerResourceHandler.java new file mode 100644 index 000000000..e443149b7 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerResourceHandler.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.handle; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +/** + * @author lengleng + * @date 2018-07-19 + * SwaggerResourceHandler + */ +@Slf4j +@Component +@AllArgsConstructor +public class SwaggerResourceHandler implements HandlerFunction { + private final SwaggerResourcesProvider swaggerResources; + + /** + * Handle the given request. + * + * @param request the request to handle + * @return the response + */ + @Override + public Mono handle(ServerRequest request) { + return ServerResponse.status(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .body(BodyInserters.fromObject(swaggerResources.get())); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerSecurityHandler.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerSecurityHandler.java new file mode 100644 index 000000000..b6a8b0b77 --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerSecurityHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.handle; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.SecurityConfiguration; +import springfox.documentation.swagger.web.SecurityConfigurationBuilder; + +import java.util.Optional; + +/** + * @author lengleng + * @date 2018-07-19 + * SwaggerSecurityHandler + */ +@Slf4j +@Component +public class SwaggerSecurityHandler implements HandlerFunction { + @Autowired(required = false) + private SecurityConfiguration securityConfiguration; + + /** + * Handle the given request. + * + * @param request the request to handle + * @return the response + */ + @Override + public Mono handle(ServerRequest request) { + return ServerResponse.status(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .body(BodyInserters.fromObject( + Optional.ofNullable(securityConfiguration) + .orElse(SecurityConfigurationBuilder.builder().build()))); + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerUiHandler.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerUiHandler.java new file mode 100644 index 000000000..a0f98630a --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handle/SwaggerUiHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.gateway.handle; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.UiConfiguration; +import springfox.documentation.swagger.web.UiConfigurationBuilder; + +import java.util.Optional; + +/** + * @author lengleng + * @date 2018-07-19 + * SwaggerUiHandler + */ +@Slf4j +@Component +public class SwaggerUiHandler implements HandlerFunction { + @Autowired(required = false) + private UiConfiguration uiConfiguration; + + /** + * Handle the given request. + * + * @param request the request to handle + * @return the response + */ + @Override + public Mono handle(ServerRequest request) { + return ServerResponse.status(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .body(BodyInserters.fromObject( + Optional.ofNullable(uiConfiguration) + .orElse(UiConfigurationBuilder.builder().build()))); + } +} diff --git a/pigx-gateway/src/main/resources/bootstrap.yml b/pigx-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..aeb0ffd87 --- /dev/null +++ b/pigx-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,27 @@ +server: + port: 9999 + +spring: + application: + name: pigx-gateway + # 配置中心 + cloud: + config: + fail-fast: true + name: ${spring.application.name} + profile: ${spring.profiles.active} + discovery: + enabled: true + service-id: pigx-config + profiles: + active: dev + +# 注册中心 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://pig:pig@localhost:1025/eureka/ + + diff --git a/pigx-monitor/Dockerfile b/pigx-monitor/Dockerfile new file mode 100644 index 000000000..b48ea7e08 --- /dev/null +++ b/pigx-monitor/Dockerfile @@ -0,0 +1,13 @@ +FROM anapsix/alpine-java:8_server-jre_unlimited + +MAINTAINER wangiegie@gmail.com + +RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-monitor + +WORKDIR /pigx/bin/com.pig4cloud/pigx-monitor + +EXPOSE 1025 + +ADD ./pigx-monitor/target/pigx-monitor.jar ./ + +CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-monitor.jar diff --git a/pigx-monitor/pom.xml b/pigx-monitor/pom.xml new file mode 100644 index 000000000..467dbcc54 --- /dev/null +++ b/pigx-monitor/pom.xml @@ -0,0 +1,80 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + pigx-monitor + ${pigx.version} + jar + + pigx-monitor + pigx 监控模块,基于 spring boot admin + + + + + de.codecentric + spring-boot-admin-starter-server + ${monitor.version} + + + + org.springframework.cloud + spring-cloud-starter-config + + + + org.springframework.boot + spring-boot-starter-web + + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${project.name} + + + + + + diff --git a/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/PigxMonitorApplication.java b/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/PigxMonitorApplication.java new file mode 100644 index 000000000..8ac0e57da --- /dev/null +++ b/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/PigxMonitorApplication.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.monitor; + + +import de.codecentric.boot.admin.server.config.EnableAdminServer; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author lengleng + * @date 2018年06月21日 + * 监控中心 + */ +@EnableAdminServer +@SpringBootApplication +public class PigxMonitorApplication { + + public static void main(String[] args) { + SpringApplication.run(PigxMonitorApplication.class, args); + } +} diff --git a/pigx-monitor/src/main/resources/bootstrap.yml b/pigx-monitor/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..1e29612c9 --- /dev/null +++ b/pigx-monitor/src/main/resources/bootstrap.yml @@ -0,0 +1,23 @@ +server: + port: 5001 + +spring: + application: + name: pigx-monitor + #配置中心 + cloud: + config: + fail-fast: true + name: ${spring.application.name} + profile: dev + discovery: + enabled: true + service-id: pigx-config + +# 注册中心配置 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://pig:pig@localhost:1025/eureka/ diff --git a/pigx-upms/pigx-upms-api/pom.xml b/pigx-upms/pigx-upms-api/pom.xml new file mode 100644 index 000000000..b2d2dface --- /dev/null +++ b/pigx-upms/pigx-upms-api/pom.xml @@ -0,0 +1,51 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx-upms + ${pigx.version} + + + pigx-upms-api + ${pigx.version} + jar + pigx-upms-api + pigx 通用用户权限管理系统公共api模块 + + + + + + com.baomidou + mybatis-plus-boot-starter + ${mbp.boot.version} + + + + com.pig4cloud + pigx-common-security + ${pigx.version} + + + diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/DeptTree.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/DeptTree.java new file mode 100644 index 000000000..078014de0 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/DeptTree.java @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import lombok.Data; + +/** + * @author lengleng + * @date 2018/1/20 + * 部门树 + */ +@Data +public class DeptTree extends TreeNode { + private String name; +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/MenuTree.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/MenuTree.java new file mode 100644 index 000000000..1ccf1dc1a --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/MenuTree.java @@ -0,0 +1,71 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import com.pig4cloud.pigx.admin.api.vo.MenuVO; +import lombok.Data; + +/** + * @author lengleng + * @date 2017年11月9日23:33:27 + */ +@Data +public class MenuTree extends TreeNode { + private String icon; + private String name; + private boolean spread = false; + private String path; + private String component; + private String authority; + private String redirect; + private String code; + private String type; + private String label; + private Integer sort; + + public MenuTree() { + } + + public MenuTree(int id, String name, int parentId) { + this.id = id; + this.parentId = parentId; + this.name = name; + this.label = name; + } + + public MenuTree(int id, String name, MenuTree parent) { + this.id = id; + this.parentId = parent.getId(); + this.name = name; + this.label = name; + } + + public MenuTree(MenuVO menuVo) { + this.id = menuVo.getMenuId(); + this.parentId = menuVo.getParentId(); + this.icon = menuVo.getIcon(); + this.name = menuVo.getName(); + this.path = menuVo.getPath(); + this.component = menuVo.getComponent(); + this.type = menuVo.getType(); + this.label = menuVo.getName(); + this.sort = menuVo.getSort(); + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/Query.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/Query.java new file mode 100644 index 000000000..8b4a53802 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/Query.java @@ -0,0 +1,55 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import com.baomidou.mybatisplus.plugins.Page; +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * @author lengleng + * @date 2017/12/10 + */ +public class Query extends Page { + private static final String PAGE = "page"; + private static final String LIMIT = "limit"; + private static final String ORDER_BY_FIELD = "orderByField"; + private static final String IS_ASC = "isAsc"; + + public Query(Map params) { + super(Integer.parseInt(params.getOrDefault(PAGE, 1).toString()) + , Integer.parseInt(params.getOrDefault(LIMIT, 10).toString())); + + String orderByField = params.getOrDefault(ORDER_BY_FIELD, "").toString(); + if (StringUtils.isNotEmpty(orderByField)) { + this.setOrderByField(orderByField); + } + + Boolean isAsc = Boolean.parseBoolean(params.getOrDefault(IS_ASC, Boolean.TRUE).toString()); + this.setAsc(isAsc); + + params.remove(PAGE); + params.remove(LIMIT); + params.remove(ORDER_BY_FIELD); + params.remove(IS_ASC); + this.setCondition(params); + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/RoleDTO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/RoleDTO.java new file mode 100644 index 000000000..85918aebd --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/RoleDTO.java @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import com.pig4cloud.pigx.admin.api.entity.SysRole; +import lombok.Data; + +/** + * @author lengleng + * @date 2018/1/20 + * 角色Dto + */ +@Data +public class RoleDTO extends SysRole { + /** + * 角色部门Id + */ + private Integer roleDeptId; + + /** + * 部门名称 + */ + private String deptName; +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/RouteConfig.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/RouteConfig.java new file mode 100644 index 000000000..67d7bc0bf --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/RouteConfig.java @@ -0,0 +1,58 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author lengleng + * @date 2017/11/7 + */ +@Data +public class RouteConfig implements Serializable { + + @com.alibaba.fastjson.annotation.JSONField(name = "path") + private String path; + @com.alibaba.fastjson.annotation.JSONField(name = "component") + private String component; + @com.alibaba.fastjson.annotation.JSONField(name = "name") + private String name; + @com.alibaba.fastjson.annotation.JSONField(name = "components") + private String components; + @com.alibaba.fastjson.annotation.JSONField(name = "redirect") + private String redirect; + @com.alibaba.fastjson.annotation.JSONField(name = "props") + private String props; + @com.alibaba.fastjson.annotation.JSONField(name = "alias") + private String alias; + @com.alibaba.fastjson.annotation.JSONField(name = "children") + private String children; + @com.alibaba.fastjson.annotation.JSONField(name = "beforeEnter") + private String beforeEnter; + @com.alibaba.fastjson.annotation.JSONField(name = "meta") + private Map meta; + @com.alibaba.fastjson.annotation.JSONField(name = "caseSensitive") + private Boolean caseSensitive; + @com.alibaba.fastjson.annotation.JSONField(name = "pathToRegexpOptions") + private String pathToRegexpOptions; +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/TreeNode.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/TreeNode.java new file mode 100644 index 000000000..d578da2f8 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/TreeNode.java @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author lengleng + * @date 2017年11月9日23:33:45 + */ +@Data +public class TreeNode { + protected int id; + protected int parentId; + protected List children = new ArrayList(); + + public void add(TreeNode node) { + children.add(node); + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserDTO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserDTO.java new file mode 100644 index 000000000..955da69aa --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserDTO.java @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import lombok.Data; + +import java.util.List; + +/** + * @author lengleng + * @date 2017/11/5 + */ +@Data +public class UserDTO extends SysUser { + /** + * 角色ID + */ + private List role; + + private Integer deptId; + + /** + * 新密码 + */ + private String newpassword1; +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserInfo.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserInfo.java new file mode 100644 index 000000000..448ef2ac8 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserInfo.java @@ -0,0 +1,74 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.dto; + +import com.pig4cloud.pigx.admin.api.entity.SysUser; + +import java.io.Serializable; + +/** + * @author lengleng + * @date 2017/11/11 + *

+ * commit('SET_ROLES', data) + * commit('SET_NAME', data) + * commit('SET_AVATAR', data) + * commit('SET_INTRODUCTION', data) + * commit('SET_PERMISSIONS', data) + */ +public class UserInfo implements Serializable { + /** + * 用户基本信息 + */ + private SysUser sysUser; + /** + * 权限标识集合 + */ + private String[] permissions; + + /** + * 角色集合 + */ + private String[] roles; + + public SysUser getSysUser() { + return sysUser; + } + + public void setSysUser(SysUser sysUser) { + this.sysUser = sysUser; + } + + public String[] getPermissions() { + return permissions; + } + + public void setPermissions(String[] permissions) { + this.permissions = permissions; + } + + public String[] getRoles() { + return roles; + } + + public void setRoles(String[] roles) { + this.roles = roles; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDept.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDept.java new file mode 100644 index 000000000..19cc3137f --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDept.java @@ -0,0 +1,95 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 部门管理 + *

+ * + * @author lengleng + * @since 2018-01-22 + */ +@Data +@TableName("sys_dept") +public class SysDept extends Model { + + private static final long serialVersionUID = 1L; + + @TableId(value = "dept_id", type = IdType.AUTO) + private Integer deptId; + /** + * 部门名称 + */ + private String name; + /** + * 排序 + */ + @TableField("order_num") + private Integer orderNum; + /** + * 创建时间 + */ + @TableField("create_time") + private Date createTime; + /** + * 修改时间 + */ + @TableField("update_time") + private Date updateTime; + /** + * 是否删除 -1:已删除 0:正常 + */ + @TableField("del_flag") + @TableLogic + private String delFlag; + + @TableField("parent_id") + private Integer parentId; + + + @Override + protected Serializable pkVal() { + return this.deptId; + } + + @Override + public String toString() { + return "SysDept{" + + ", deptId=" + deptId + + ", name=" + name + + ", orderNum=" + orderNum + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", delFlag=" + delFlag + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDeptRelation.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDeptRelation.java new file mode 100644 index 000000000..7a6e1f72e --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDeptRelation.java @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author lengleng + * @since 2018-01-22 + */ +@Data +@TableName("sys_dept_relation") +public class SysDeptRelation extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 祖先节点 + */ + private Integer ancestor; + /** + * 后代节点 + */ + private Integer descendant; + + + @Override + protected Serializable pkVal() { + return this.ancestor; + } + + @Override + public String toString() { + return "SysDeptRelation{" + + ", ancestor=" + ancestor + + ", descendant=" + descendant + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDict.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDict.java new file mode 100644 index 000000000..9c4d5f648 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysDict.java @@ -0,0 +1,115 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + *

+ * 字典表 + *

+ * + * @author lengleng + * @since 2017-11-19 + */ +@Data +@TableName("sys_dict") +public class SysDict extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 编号 + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 数据值 + */ + private String value; + /** + * 标签名 + */ + private String label; + /** + * 类型 + */ + private String type; + /** + * 描述 + */ + private String description; + /** + * 排序(升序) + */ + private BigDecimal sort; + /** + * 创建时间 + */ + @TableField("create_time") + private Date createTime; + /** + * 更新时间 + */ + @TableField("update_time") + private Date updateTime; + /** + * 备注信息 + */ + private String remarks; + /** + * 删除标记 + */ + @TableField("del_flag") + @TableLogic + private String delFlag; + + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "SysDict{" + + ", id=" + id + + ", value=" + value + + ", label=" + label + + ", type=" + type + + ", description=" + description + + ", sort=" + sort + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", remarks=" + remarks + + ", delFlag=" + delFlag + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysLog.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysLog.java new file mode 100644 index 000000000..17834b76f --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysLog.java @@ -0,0 +1,129 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 日志表 + *

+ * + * @author lengleng + * @since 2017-11-20 + */ +@Data +public class SysLog implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 编号 + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + /** + * 日志类型 + */ + private String type; + /** + * 日志标题 + */ + private String title; + /** + * 创建者 + */ + private String createBy; + /** + * 创建时间 + */ + private Date createTime; + /** + * 更新时间 + */ + private Date updateTime; + /** + * 操作IP地址 + */ + private String remoteAddr; + /** + * 用户代理 + */ + private String userAgent; + /** + * 请求URI + */ + private String requestUri; + /** + * 操作方式 + */ + private String method; + /** + * 操作提交的数据 + */ + private String params; + /** + * 执行时间 + */ + private Long time; + + /** + * 删除标记 + */ + @TableLogic + private String delFlag; + + /** + * 异常信息 + */ + private String exception; + + /** + * 服务ID + */ + private String serviceId; + + + @Override + public String toString() { + return "SysLog{" + + "id=" + id + + ", type='" + type + '\'' + + ", title='" + title + '\'' + + ", createBy='" + createBy + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", remoteAddr='" + remoteAddr + '\'' + + ", userAgent='" + userAgent + '\'' + + ", requestUri='" + requestUri + '\'' + + ", method='" + method + '\'' + + ", params='" + params + '\'' + + ", time=" + time + + ", delFlag='" + delFlag + '\'' + + ", exception='" + exception + '\'' + + '}'; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysMenu.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysMenu.java new file mode 100644 index 000000000..5ececf527 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysMenu.java @@ -0,0 +1,124 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 菜单权限表 + *

+ * + * @author lengleng + * @since 2017-11-08 + */ +@Data +@TableName("sys_menu") +public class SysMenu extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + @TableId(value = "menu_id", type = IdType.INPUT) + private Integer menuId; + /** + * 菜单名称 + */ + private String name; + /** + * 菜单权限标识 + */ + private String permission; + /** + * 父菜单ID + */ + @TableField("parent_id") + private Integer parentId; + /** + * 图标 + */ + private String icon; + /** + * VUE页面 + */ + private String component; + /** + * 排序值 + */ + private Integer sort; + /** + * 菜单类型 (0菜单 1按钮) + */ + private String type; + /** + * 创建时间 + */ + @TableField("create_time") + private Date createTime; + /** + * 更新时间 + */ + @TableField("update_time") + private Date updateTime; + /** + * 0--正常 1--删除 + */ + @TableLogic + @TableField("del_flag") + private String delFlag; + /** + * 前端URL + */ + private String path; + + + @Override + protected Serializable pkVal() { + return this.menuId; + } + + @Override + public String toString() { + return "SysMenu{" + + ", menuId=" + menuId + + ", name=" + name + + ", permission=" + permission + + ", parentId=" + parentId + + ", icon=" + icon + + ", component=" + component + + ", sort=" + sort + + ", type=" + type + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", delFlag=" + delFlag + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysOauthClientDetails.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysOauthClientDetails.java new file mode 100644 index 000000000..ef385aea8 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysOauthClientDetails.java @@ -0,0 +1,173 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author lengleng + * @since 2018-05-15 + */ +@TableName("sys_oauth_client_details") +public class SysOauthClientDetails extends Model { + + private static final long serialVersionUID = 1L; + + @TableId(value = "client_id", type = IdType.INPUT) + private String clientId; + @TableField("resource_ids") + private String resourceIds; + @TableField("client_secret") + private String clientSecret; + private String scope; + @TableField("authorized_grant_types") + private String authorizedGrantTypes; + @TableField("web_server_redirect_uri") + private String webServerRedirectUri; + private String authorities; + @TableField("access_token_validity") + private Integer accessTokenValidity; + @TableField("refresh_token_validity") + private Integer refreshTokenValidity; + @TableField("additional_information") + private String additionalInformation; + private String autoapprove; + + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getResourceIds() { + return resourceIds; + } + + public void setResourceIds(String resourceIds) { + this.resourceIds = resourceIds; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getAuthorizedGrantTypes() { + return authorizedGrantTypes; + } + + public void setAuthorizedGrantTypes(String authorizedGrantTypes) { + this.authorizedGrantTypes = authorizedGrantTypes; + } + + public String getWebServerRedirectUri() { + return webServerRedirectUri; + } + + public void setWebServerRedirectUri(String webServerRedirectUri) { + this.webServerRedirectUri = webServerRedirectUri; + } + + public String getAuthorities() { + return authorities; + } + + public void setAuthorities(String authorities) { + this.authorities = authorities; + } + + public Integer getAccessTokenValidity() { + return accessTokenValidity; + } + + public void setAccessTokenValidity(Integer accessTokenValidity) { + this.accessTokenValidity = accessTokenValidity; + } + + public Integer getRefreshTokenValidity() { + return refreshTokenValidity; + } + + public void setRefreshTokenValidity(Integer refreshTokenValidity) { + this.refreshTokenValidity = refreshTokenValidity; + } + + public String getAdditionalInformation() { + return additionalInformation; + } + + public void setAdditionalInformation(String additionalInformation) { + this.additionalInformation = additionalInformation; + } + + public String getAutoapprove() { + return autoapprove; + } + + public void setAutoapprove(String autoapprove) { + this.autoapprove = autoapprove; + } + + @Override + protected Serializable pkVal() { + return this.clientId; + } + + @Override + public String toString() { + return "SysOauthClientDetails{" + + ", clientId=" + clientId + + ", resourceIds=" + resourceIds + + ", clientSecret=" + clientSecret + + ", scope=" + scope + + ", authorizedGrantTypes=" + authorizedGrantTypes + + ", webServerRedirectUri=" + webServerRedirectUri + + ", authorities=" + authorities + + ", accessTokenValidity=" + accessTokenValidity + + ", refreshTokenValidity=" + refreshTokenValidity + + ", additionalInformation=" + additionalInformation + + ", autoapprove=" + autoapprove + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRole.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRole.java new file mode 100644 index 000000000..42726a62f --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRole.java @@ -0,0 +1,83 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ *

+ *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Data +@TableName("sys_role") +public class SysRole extends Model { + + private static final long serialVersionUID = 1L; + + @TableId(value = "role_id", type = IdType.AUTO) + private Integer roleId; + @TableField("role_name") + private String roleName; + @TableField("role_code") + private String roleCode; + @TableField("role_desc") + private String roleDesc; + @TableField("create_time") + private Date createTime; + @TableField("update_time") + private Date updateTime; + /** + * 删除标识(0-正常,1-删除) + */ + @TableLogic + @TableField("del_flag") + private String delFlag; + + @Override + protected Serializable pkVal() { + return this.roleId; + } + + @Override + public String toString() { + return "SysRole{" + + ", roleId=" + roleId + + ", roleName=" + roleName + + ", roleCode=" + roleCode + + ", roleDesc=" + roleDesc + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", delFlag=" + delFlag + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRoleDept.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRoleDept.java new file mode 100644 index 000000000..1333d79e7 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRoleDept.java @@ -0,0 +1,72 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 角色与部门对应关系 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +@Data +@TableName("sys_role_dept") +public class SysRoleDept extends Model { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 角色ID + */ + @TableField("role_id") + private Integer roleId; + /** + * 部门ID + */ + @TableField("dept_id") + private Integer deptId; + + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "SysRoleDept{" + + ", id=" + id + + ", roleId=" + roleId + + ", deptId=" + deptId + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRoleMenu.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRoleMenu.java new file mode 100644 index 000000000..39b63750e --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysRoleMenu.java @@ -0,0 +1,67 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 角色菜单表 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Data +@TableName("sys_role_menu") +public class SysRoleMenu extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 角色ID + */ + @TableId(type = IdType.INPUT) + private Integer roleId; + /** + * 菜单ID + */ + @TableId(type = IdType.INPUT) + private Integer menuId; + + @Override + protected Serializable pkVal() { + return this.roleId; + } + + @Override + public String toString() { + return "SysRoleMenu{" + + ", roleId=" + roleId + + ", menuId=" + menuId + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java new file mode 100644 index 000000000..783c56dd1 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java @@ -0,0 +1,110 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 用户表 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Data +@TableName("sys_user") +public class SysUser implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + @TableId(value = "user_id", type = IdType.AUTO) + private Integer userId; + /** + * 用户名 + */ + private String username; + + private String password; + /** + * 随机盐 + */ + @JsonIgnore + private String salt; + /** + * 创建时间 + */ + @TableField("create_time") + private Date createTime; + /** + * 修改时间 + */ + @TableField("update_time") + private Date updateTime; + /** + * 0-正常,1-删除 + */ + @TableLogic + @TableField("del_flag") + private String delFlag; + + /** + * 简介 + */ + private String phone; + /** + * 头像 + */ + private String avatar; + + /** + * 部门ID + */ + @TableField("dept_id") + private Integer deptId; + + @Override + public String toString() { + return "SysUser{" + + "userId=" + userId + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + ", salt='" + salt + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", delFlag='" + delFlag + '\'' + + ", phone='" + phone + '\'' + + ", avatar='" + avatar + '\'' + + ", deptId=" + deptId + + '}'; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUserRole.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUserRole.java new file mode 100644 index 000000000..2bd15f5f5 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUserRole.java @@ -0,0 +1,68 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 用户角色表 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Data +@TableName("sys_user_role") +public class SysUserRole extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + @TableId(type = IdType.INPUT) + private Integer userId; + /** + * 角色ID + */ + @TableId(type = IdType.INPUT) + private Integer roleId; + + + @Override + protected Serializable pkVal() { + return this.userId; + } + + @Override + public String toString() { + return "SysUserRole{" + + ", userId=" + userId + + ", roleId=" + roleId + + "}"; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysZuulRoute.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysZuulRoute.java new file mode 100644 index 000000000..5fec78581 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysZuulRoute.java @@ -0,0 +1,106 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 动态路由配置表 + *

+ * + * @author lengleng + * @since 2018-05-15 + */ +@Data +@TableName("sys_zuul_route") +public class SysZuulRoute extends Model { + + private static final long serialVersionUID = 1L; + + /** + * router Id + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 路由路径 + */ + private String path; + /** + * 服务名称 + */ + @TableField("service_id") + private String serviceId; + /** + * url代理 + */ + private String url; + /** + * 转发去掉前缀 + */ + @TableField("strip_prefix") + private String stripPrefix; + /** + * 是否重试 + */ + private String retryable; + /** + * 是否启用 + */ + private String enabled; + /** + * 敏感请求头 + */ + @TableField("sensitiveHeaders_list") + private String sensitiveheadersList; + /** + * 创建时间 + */ + @TableField("create_time") + private Date createTime; + /** + * 更新时间 + */ + @TableField("update_time") + private Date updateTime; + /** + * 删除标识(0-正常,1-删除) + */ + @TableLogic + @TableField("del_flag") + private String delFlag; + + @Override + protected Serializable pkVal() { + return this.id; + } + + +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteLogService.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteLogService.java new file mode 100644 index 000000000..8ab824b01 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteLogService.java @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.feign; + +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.api.feign.fallback.RemoteLogServiceFallbackImpl; +import com.pig4cloud.pigx.common.core.constant.ServiceNameConstant; +import com.pig4cloud.pigx.common.core.util.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author lengleng + * @date 2018/6/28 + */ +@FeignClient(value = ServiceNameConstant.UMPS_SERVICE, fallback = RemoteLogServiceFallbackImpl.class) +public interface RemoteLogService { + /** + * 保存日志 + * + * @param sysLog 日志实体 + * @return succes、false + */ + @PostMapping("/log") + R saveLog(@RequestBody SysLog sysLog); +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java new file mode 100644 index 000000000..319dc394f --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.feign; + +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl; +import com.pig4cloud.pigx.common.core.constant.ServiceNameConstant; +import com.pig4cloud.pigx.common.core.util.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; + +/** + * @author lengleng + * @date 2018/6/22 + */ + @FeignClient(value = ServiceNameConstant.UMPS_SERVICE, fallback = RemoteUserServiceFallbackImpl.class) + public interface RemoteUserService { + /** + * 通过用户名查询用户、角色信息 + * + * @param username 用户名 + * @param from 调用标志 + * @return R + */ + @GetMapping("/user/info/{username}") + R info(@PathVariable("username") String username + , @RequestHeader("from") String from); + } diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteLogServiceFallbackImpl.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteLogServiceFallbackImpl.java new file mode 100644 index 000000000..722e0435d --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteLogServiceFallbackImpl.java @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.feign.fallback; + +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.api.feign.RemoteLogService; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/6/26 + */ +@Slf4j +@Component +public class RemoteLogServiceFallbackImpl implements RemoteLogService { + + /** + * 保存日志 + * + * @param sysLog + * @return R + */ + @Override + public R saveLog(SysLog sysLog) { + log.error("feign 插入日志失败:{}"); + return null; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java new file mode 100644 index 000000000..900b354d0 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.feign.fallback; + +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.feign.RemoteUserService; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/6/26 + */ +@Slf4j +@Component +public class RemoteUserServiceFallbackImpl implements RemoteUserService { + /** + * 通过用户名查询用户、角色信息 + * + * @param username 用户名 + * @param from 内外标志 + * @return R + */ + @Override + public R info(String username, String from) { + log.error("feign 查询用户信息失败:{}", username); + return null; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ErrorPojo.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ErrorPojo.java new file mode 100644 index 000000000..d26624f27 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ErrorPojo.java @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author lengleng + * @date 2017/12/25 + * spring boot 的异常对象 + */ +@Data +public class ErrorPojo implements Serializable { + + @JSONField(name = "timestamp") + private long timestamp; + @JSONField(name = "status") + private int status; + @JSONField(name = "error") + private String error; + @JSONField(name = "exception") + private String exception; + @JSONField(name = "message") + private String message; + @JSONField(name = "path") + private String path; +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ImageCode.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ImageCode.java new file mode 100644 index 000000000..433057729 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ImageCode.java @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import lombok.Data; + +import java.awt.image.BufferedImage; +import java.io.Serializable; +import java.time.LocalDateTime; + + +/** + * @author lengleng + * @date 2017-12-18 + */ +@Data +public class ImageCode implements Serializable { + private String code; + + private LocalDateTime expireTime; + + private BufferedImage image; + + public ImageCode(BufferedImage image, String sRand, int defaultImageExpire) { + this.image = image; + this.code = sRand; + this.expireTime = LocalDateTime.now().plusSeconds(defaultImageExpire); + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/LogVO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/LogVO.java new file mode 100644 index 000000000..fa49802c2 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/LogVO.java @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author lengleng + * @date 2017/11/20 + */ +@Data +public class LogVO implements Serializable { + private static final long serialVersionUID = 1L; + + private SysLog sysLog; + private String username; +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/MenuVO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/MenuVO.java new file mode 100644 index 000000000..0a64a8da5 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/MenuVO.java @@ -0,0 +1,109 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 菜单权限表 + *

+ * + * @author lengleng + * @since 2017-11-08 + */ +@Data +public class MenuVO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + private Integer menuId; + /** + * 菜单名称 + */ + private String name; + /** + * 菜单权限标识 + */ + private String permission; + /** + * 父菜单ID + */ + private Integer parentId; + /** + * 图标 + */ + private String icon; + /** + * 一个路径 + */ + private String path; + /** + * VUE页面 + */ + private String component; + /** + * 排序值 + */ + private Integer sort; + /** + * 菜单类型 (0菜单 1按钮) + */ + private String type; + /** + * 创建时间 + */ + private Date createTime; + /** + * 更新时间 + */ + private Date updateTime; + /** + * 0--正常 1--删除 + */ + private String delFlag; + + + @Override + public int hashCode() { + return menuId.hashCode(); + } + + /** + * menuId 相同则相同 + * + * @param obj + * @return + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof MenuVO) { + Integer targetMenuId = ((MenuVO) obj).getMenuId(); + return menuId.equals(targetMenuId); + } + return super.equals(obj); + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java new file mode 100644 index 000000000..a695f5c27 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java @@ -0,0 +1,121 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.vo; + + +import com.pig4cloud.pigx.admin.api.dto.MenuTree; +import com.pig4cloud.pigx.admin.api.dto.TreeNode; +import com.pig4cloud.pigx.admin.api.entity.SysMenu; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author lengleng + * @date 2017年11月9日23:34:11 + */ +public class TreeUtil { + /** + * 两层循环实现建树 + * + * @param treeNodes 传入的树节点列表 + * @return + */ + public static List bulid(List treeNodes, Object root) { + + List trees = new ArrayList(); + + for (T treeNode : treeNodes) { + + if (root.equals(treeNode.getParentId())) { + trees.add(treeNode); + } + + for (T it : treeNodes) { + if (it.getParentId() == treeNode.getId()) { + if (treeNode.getChildren() == null) { + treeNode.setChildren(new ArrayList()); + } + treeNode.add(it); + } + } + } + return trees; + } + + /** + * 使用递归方法建树 + * + * @param treeNodes + * @return + */ + public static List buildByRecursive(List treeNodes, Object root) { + List trees = new ArrayList(); + for (T treeNode : treeNodes) { + if (root.equals(treeNode.getParentId())) { + trees.add(findChildren(treeNode, treeNodes)); + } + } + return trees; + } + + /** + * 递归查找子节点 + * + * @param treeNodes + * @return + */ + public static T findChildren(T treeNode, List treeNodes) { + for (T it : treeNodes) { + if (treeNode.getId() == it.getParentId()) { + if (treeNode.getChildren() == null) { + treeNode.setChildren(new ArrayList()); + } + treeNode.add(findChildren(it, treeNodes)); + } + } + return treeNode; + } + + /** + * 通过sysMenu创建树形节点 + * + * @param menus + * @param root + * @return + */ + public static List bulidTree(List menus, int root) { + List trees = new ArrayList(); + MenuTree node; + for (SysMenu menu : menus) { + node = new MenuTree(); + node.setId(menu.getMenuId()); + node.setParentId(menu.getParentId()); + node.setName(menu.getName()); + node.setPath(menu.getPath()); + node.setCode(menu.getPermission()); + node.setLabel(menu.getName()); + node.setComponent(menu.getComponent()); + node.setIcon(menu.getIcon()); + trees.add(node); + } + return TreeUtil.bulid(trees, root); + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java new file mode 100644 index 000000000..fc1a82c3f --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java @@ -0,0 +1,87 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import com.pig4cloud.pigx.admin.api.entity.SysRole; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author lengleng + * @date 2017/10/29 + */ +@Data +public class UserVO implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + private Integer userId; + /** + * 用户名 + */ + private String username; + /** + * 密码 + */ + private String password; + /** + * 随机盐 + */ + private String salt; + /** + * 创建时间 + */ + private Date createTime; + /** + * 修改时间 + */ + private Date updateTime; + /** + * 0-正常,1-删除 + */ + private String delFlag; + /** + * 简介 + */ + private String phone; + /** + * 头像 + */ + private String avatar; + + /** + * 部门ID + */ + private Integer deptId; + /** + * 部门名称 + */ + private String deptName; + + /** + * 角色列表 + */ + private List roleList; +} diff --git a/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring-devtools.properties b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring-devtools.properties new file mode 100644 index 000000000..6ba6501f2 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring-devtools.properties @@ -0,0 +1 @@ +restart.include.pigx-upms-api=/pigx-upms-api[\\w-]+\.jar diff --git a/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..d11d4b57c --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl,\ + com.pig4cloud.pigx.admin.api.feign.fallback.RemoteLogServiceFallbackImpl\ diff --git a/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.provides b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.provides new file mode 100644 index 000000000..709c4b9bc --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: mybatis-plus-boot-starter, pigx-common-security diff --git a/pigx-upms/pigx-upms-biz/Dockerfile b/pigx-upms/pigx-upms-biz/Dockerfile new file mode 100644 index 000000000..7709e058f --- /dev/null +++ b/pigx-upms/pigx-upms-biz/Dockerfile @@ -0,0 +1,13 @@ +FROM anapsix/alpine-java:8_server-jre_unlimited + +MAINTAINER wangiegie@gmail.com + +RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-upms + +WORKDIR /pigx/bin/com.pig4cloud/pigx-upms + +EXPOSE 1025 + +ADD ./pigx-upms/pigx-upms-biz/target/pigx-upms-biz.jar ./ + +CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-upms-biz.jar diff --git a/pigx-upms/pigx-upms-biz/pom.xml b/pigx-upms/pigx-upms-biz/pom.xml new file mode 100644 index 000000000..0f754dba0 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/pom.xml @@ -0,0 +1,113 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx-upms + ${pigx.version} + + + pigx-upms-biz + ${pigx.version} + jar + + pigx-upms-biz + pigx 通用用户权限管理系统业务处理模块 + + + + + com.pig4cloud + pigx-upms-api + ${pigx.version} + + + + com.pig4cloud + pigx-common-log + ${pigx.version} + + + + com.pig4cloud + pigx-common-swagger + ${pigx.version} + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.cloud + spring-cloud-starter-config + + + + org.springframework.cloud + spring-cloud-starter-security + + + + de.codecentric + spring-boot-admin-starter-client + ${monitor.version} + + + + mysql + mysql-connector-java + + + + org.springframework.boot + spring-boot-starter-web + + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${project.name} + + + + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java new file mode 100644 index 000000000..6fe57204f --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin; + + +import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2; +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * @author lengleng + * @date 2018年06月21日 + * 用户统一管理系统 + */ +@EnablePigxSwagger2 +@EnableFeignClients +@SpringCloudApplication +public class PigxAdminApplication { + public static void main(String[] args) { + SpringApplication.run(PigxAdminApplication.class, args); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/MybatisPlusConfigurer.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/MybatisPlusConfigurer.java new file mode 100644 index 000000000..9fd5436b4 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/MybatisPlusConfigurer.java @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.config; + +import com.baomidou.mybatisplus.plugins.PaginationInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author lengleng + * @date 2017/10/29 + */ +@Configuration +@MapperScan("com.pig4cloud.pigx.admin.mapper") +public class MybatisPlusConfigurer { + /** + * 分页插件 + * + * @return PaginationInterceptor + */ + @Bean + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java new file mode 100644 index 000000000..eaa1d9aad --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.config; + +import com.pig4cloud.pigx.common.security.compoent.PigAccessDeniedHandler; +import com.pig4cloud.pigx.common.security.compoent.ResourceAuthExceptionEntryPoint; +import lombok.AllArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; + +/** + * @author lengleng + * @date 2018/6/22 + */ +@Configuration +@EnableResourceServer +@AllArgsConstructor +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { + private final PigAccessDeniedHandler pigAccessDeniedHandler; + private final ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; + + @Override + public void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/actuator/**", "/user/info/*", "/log/**","/v2/api-docs").permitAll() + .anyRequest().authenticated() + .and().csrf().disable(); + } + + /** + * why add resourceId + * https://stackoverflow.com/questions/28703847/how-do-you-set-a-resource-id-for-a-token + * + * @param resources + * @throws Exception + */ + @Override + public void configure(ResourceServerSecurityConfigurer resources) throws Exception { + resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) + .accessDeniedHandler(pigAccessDeniedHandler); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java new file mode 100644 index 000000000..115266c1d --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DeptController.java @@ -0,0 +1,109 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.pig4cloud.pigx.admin.api.dto.DeptTree; +import com.pig4cloud.pigx.admin.api.entity.SysDept; +import com.pig4cloud.pigx.admin.service.SysDeptService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.Date; +import java.util.List; + +/** + *

+ * 部门管理 前端控制器 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +@RestController +@RequestMapping("/dept") +public class DeptController { + @Autowired + private SysDeptService sysDeptService; + + /** + * 通过ID查询 + * + * @param id ID + * @return SysDept + */ + @GetMapping("/{id}") + public SysDept get(@PathVariable Integer id) { + return sysDeptService.selectById(id); + } + + + /** + * 返回树形菜单集合 + * + * @return 树形菜单 + */ + @GetMapping(value = "/tree") + public List getTree() { + SysDept condition = new SysDept(); + condition.setDelFlag(CommonConstant.STATUS_NORMAL); + return sysDeptService.selectListTree(new EntityWrapper<>(condition)); + } + + /** + * 添加 + * + * @param sysDept 实体 + * @return success/false + */ + @PostMapping + @PreAuthorize("@pms.hasPermission('sys_dept_add')") + public R add(@RequestBody SysDept sysDept) { + return new R<>(sysDeptService.insertDept(sysDept)); + } + + /** + * 删除 + * + * @param id ID + * @return success/false + */ + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('sys_dept_del')") + public R delete(@PathVariable Integer id) { + return new R<>(sysDeptService.deleteDeptById(id)); + } + + /** + * 编辑 + * + * @param sysDept 实体 + * @return success/false + */ + @PutMapping + @PreAuthorize("@pms.hasPermission('sys_dept_edit')") + public Boolean edit(@RequestBody SysDept sysDept) { + sysDept.setUpdateTime(new Date()); + return sysDeptService.updateDeptById(sysDept); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java new file mode 100644 index 000000000..4d0d1d93d --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java @@ -0,0 +1,134 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.entity.SysDict; +import com.pig4cloud.pigx.admin.service.SysDictService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.R; +import com.pig4cloud.pigx.common.log.annotation.SysLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 字典表 前端控制器 + *

+ * + * @author lengleng + * @since 2017-11-19 + */ +@RestController +@RequestMapping("/dict") +public class DictController { + @Autowired + private SysDictService sysDictService; + + /** + * 通过ID查询字典信息 + * + * @param id ID + * @return 字典信息 + */ + @GetMapping("/{id}") + public SysDict dict(@PathVariable Integer id) { + return sysDictService.selectById(id); + } + + /** + * 分页查询字典信息 + * + * @param params 分页对象 + * @return 分页对象 + */ + @RequestMapping("/dictPage") + public Page dictPage(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return sysDictService.selectPage(new Query<>(params), new EntityWrapper<>()); + } + + /** + * 通过字典类型查找字典 + * + * @param type 类型 + * @return 同类型字典 + */ + @GetMapping("/type/{type}") + @Cacheable(value = "dict_details", key = "#type") + public List findDictByType(@PathVariable String type) { + SysDict condition = new SysDict(); + condition.setDelFlag(CommonConstant.STATUS_NORMAL); + condition.setType(type); + return sysDictService.selectList(new EntityWrapper<>(condition)); + } + + /** + * 添加字典 + * + * @param sysDict 字典信息 + * @return success、false + */ + @SysLog("添加字典") + @PostMapping + @CacheEvict(value = "dict_details", key = "#sysDict.type") + @PreAuthorize("@pms.hasPermission('sys_dict_add')") + public R dict(@RequestBody SysDict sysDict) { + return new R<>(sysDictService.insert(sysDict)); + } + + /** + * 删除字典,并且清除字典缓存 + * + * @param id ID + * @param type 类型 + * @return R + */ + @SysLog("删除字典") + @DeleteMapping("/{id}/{type}") + @CacheEvict(value = "dict_details", key = "#type") + @PreAuthorize("@pms.hasPermission('sys_dict_del')") + public R deleteDict(@PathVariable Integer id, @PathVariable String type) { + return new R<>(sysDictService.deleteById(id)); + } + + /** + * 修改字典 + * + * @param sysDict 字典信息 + * @return success/false + */ + @PutMapping + @SysLog("修改字典") + @CacheEvict(value = "dict_details", key = "#sysDict.type") + @PreAuthorize("@pms.hasPermission('sys_dict_edit')") + public R editDict(@RequestBody SysDict sysDict) { + return new R<>(sysDictService.updateById(sysDict)); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java new file mode 100644 index 000000000..cbb0efd37 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java @@ -0,0 +1,84 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.service.SysLogService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + *

+ * 日志表 前端控制器 + *

+ * + * @author lengleng + * @since 2017-11-20 + */ +@RestController +@RequestMapping("/log") +public class LogController { + @Autowired + private SysLogService sysLogService; + + /** + * 分页查询日志信息 + * + * @param params 分页对象 + * @return 分页对象 + */ + @RequestMapping("/logPage") + public Page logPage(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return sysLogService.selectPage(new Query<>(params), new EntityWrapper<>()); + } + + /** + * 根据ID + * + * @param id ID + * @return success/false + */ + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('sys_log_del')") + public R delete(@PathVariable Long id) { + return new R<>(sysLogService.updateByLogId(id)); + } + + /** + * 插入日志 + * + * @param sysLog 日志实体 + * @return success/false + */ + @PostMapping + public R save(@RequestBody SysLog sysLog) { + return new R<>(sysLogService.insert(sysLog)); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java new file mode 100644 index 000000000..6799a3d5e --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java @@ -0,0 +1,149 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.pig4cloud.pigx.admin.api.dto.MenuTree; +import com.pig4cloud.pigx.admin.api.entity.SysMenu; +import com.pig4cloud.pigx.admin.api.vo.MenuVO; +import com.pig4cloud.pigx.admin.api.vo.TreeUtil; +import com.pig4cloud.pigx.admin.service.SysMenuService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.R; +import com.pig4cloud.pigx.common.security.util.SecurityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +/** + * @author lengleng + * @date 2017/10/31 + */ +@RestController +@RequestMapping("/menu") +public class MenuController { + @Autowired + private SysMenuService sysMenuService; + + /** + * 通过角色名称查询用户菜单 + * + * @param role 角色名称 + * @return 菜单列表 + */ + @GetMapping("/findMenuByRole/{role}") + public List findMenuByRole(@PathVariable String role) { + return sysMenuService.findMenuByRoleCode(role); + } + + /** + * 返回当前用户的树形菜单集合 + * + * @return 当前用户的树形菜单 + */ + @GetMapping(value = "/userMenu") + public List userMenu() { + // 获取符合条件得菜单 + Set all = new HashSet<>(); + SecurityUtils.getRoles().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleCode(roleName))); + List menuTreeList = new ArrayList<>(); + all.forEach(menuVo -> { + if (CommonConstant.MENU.equals(menuVo.getType())) { + menuTreeList.add(new MenuTree(menuVo)); + } + }); + CollUtil.sort(menuTreeList, Comparator.comparingInt(MenuTree::getSort)); + return TreeUtil.bulid(menuTreeList, -1); + } + + /** + * 返回树形菜单集合 + * + * @return 树形菜单 + */ + @GetMapping(value = "/allTree") + public List getTree() { + SysMenu condition = new SysMenu(); + condition.setDelFlag(CommonConstant.STATUS_NORMAL); + return TreeUtil.bulidTree(sysMenuService.selectList(new EntityWrapper<>(condition)), -1); + } + + /** + * 返回角色的菜单集合 + * + * @param roleName 角色名称 + * @return 属性集合 + */ + @GetMapping("/roleTree/{roleName}") + public List roleTree(@PathVariable String roleName) { + List menus = sysMenuService.findMenuByRoleCode(roleName); + List menuList = new ArrayList<>(); + for (MenuVO menuVo : menus) { + menuList.add(menuVo.getMenuId()); + } + return menuList; + } + + /** + * 通过ID查询菜单的详细信息 + * + * @param id 菜单ID + * @return 菜单详细信息 + */ + @GetMapping("/{id}") + public SysMenu menu(@PathVariable Integer id) { + return sysMenuService.selectById(id); + } + + /** + * 新增菜单 + * + * @param sysMenu 菜单信息 + * @return success/false + */ + @PostMapping + @PreAuthorize("@pms.hasPermission('sys_menu_add')") + public R menu(@RequestBody SysMenu sysMenu) { + return new R<>(sysMenuService.insert(sysMenu)); + } + + /** + * 删除菜单 + * + * @param id 菜单ID + * @return success/false + * TODO 级联删除下级节点 + */ + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('sys_menu_del')") + public R menuDel(@PathVariable Integer id) { + return new R<>(sysMenuService.deleteMenu(id)); + } + + @PutMapping + @PreAuthorize("@pms.hasPermission('sys_menu_edit')") + public R menuUpdate(@RequestBody SysMenu sysMenu) { + return new R<>(sysMenuService.updateMenuById(sysMenu)); + } + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java new file mode 100644 index 000000000..ffc040c00 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java @@ -0,0 +1,108 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails; +import com.pig4cloud.pigx.admin.service.SysOauthClientDetailsService; +import com.pig4cloud.pigx.common.core.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + *

+ * 前端控制器 + *

+ * + * @author lengleng + * @since 2018-05-15 + */ +@RestController +@RequestMapping("/client") +public class OauthClientDetailsController { + @Autowired + private SysOauthClientDetailsService sysOauthClientDetailsService; + + /** + * 通过ID查询 + * + * @param id ID + * @return SysOauthClientDetails + */ + @GetMapping("/{id}") + public SysOauthClientDetails get(@PathVariable Integer id) { + return sysOauthClientDetailsService.selectById(id); + } + + + /** + * 分页查询信息 + * + * @param params 分页对象 + * @return 分页对象 + */ + @RequestMapping("/page") + public Page page(@RequestParam Map params) { + return sysOauthClientDetailsService.selectPage(new Query<>(params), new EntityWrapper<>()); + } + + /** + * 添加 + * + * @param sysOauthClientDetails 实体 + * @return success/false + */ + @PostMapping + @PreAuthorize("@pms.hasPermission('sys_client_add')") + public R add(@RequestBody SysOauthClientDetails sysOauthClientDetails) { + return new R<>(sysOauthClientDetailsService.insert(sysOauthClientDetails)); + } + + /** + * 删除 + * + * @param id ID + * @return success/false + */ + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('sys_client_del')") + public R delete(@PathVariable String id) { + SysOauthClientDetails sysOauthClientDetails = new SysOauthClientDetails(); + sysOauthClientDetails.setClientId(id); + return new R<>(sysOauthClientDetailsService.deleteById(sysOauthClientDetails)); + } + + /** + * 编辑 + * + * @param sysOauthClientDetails 实体 + * @return success/false + */ + @PutMapping + @PreAuthorize("@pms.hasPermission('sys_client_edit')") + public R edit(@RequestBody SysOauthClientDetails sysOauthClientDetails) { + return new R<>(sysOauthClientDetailsService.updateById(sysOauthClientDetails)); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java new file mode 100644 index 000000000..f0d49681c --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java @@ -0,0 +1,130 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.dto.RoleDTO; +import com.pig4cloud.pigx.admin.api.entity.SysRole; +import com.pig4cloud.pigx.admin.service.SysRoleMenuService; +import com.pig4cloud.pigx.admin.service.SysRoleService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * @author lengleng + * @date 2017/11/5 + */ +@RestController +@RequestMapping("/role") +public class RoleController { + @Autowired + private SysRoleService sysRoleService; + @Autowired + private SysRoleMenuService sysRoleMenuService; + + /** + * 通过ID查询角色信息 + * + * @param id ID + * @return 角色信息 + */ + @GetMapping("/{id}") + public SysRole role(@PathVariable Integer id) { + return sysRoleService.selectById(id); + } + + /** + * 添加角色 + * + * @param roleDto 角色信息 + * @return success、false + */ + @PostMapping + @PreAuthorize("@pms.hasPermission('sys_role_add')") + public R role(@RequestBody RoleDTO roleDto) { + return new R<>(sysRoleService.insertRole(roleDto)); + } + + /** + * 修改角色 + * + * @param roleDto 角色信息 + * @return success/false + */ + @PutMapping + @PreAuthorize("@pms.hasPermission('sys_role_edit')") + public R roleUpdate(@RequestBody RoleDTO roleDto) { + return new R<>(sysRoleService.updateRoleById(roleDto)); + } + + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('sys_role_del')") + public R roleDel(@PathVariable Integer id) { + SysRole sysRole = sysRoleService.selectById(id); + sysRole.setDelFlag(CommonConstant.STATUS_DEL); + return new R<>(sysRoleService.updateById(sysRole)); + } + + /** + * 获取角色列表 + * + * @param deptId 部门ID + * @return 角色列表 + */ + @GetMapping("/roleList/{deptId}") + public List roleList(@PathVariable Integer deptId) { + return sysRoleService.selectListByDeptId(deptId); + + } + + /** + * 分页查询角色信息 + * + * @param params 分页对象 + * @return 分页对象 + */ + @RequestMapping("/rolePage") + public Page rolePage(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return sysRoleService.selectwithDeptPage(new Query<>(params), new EntityWrapper<>()); + } + + /** + * 更新角色菜单 + * + * @param roleId 角色ID + * @param menuIds 菜单结合 + * @return success、false + */ + @PutMapping("/roleMenuUpd") + @PreAuthorize("@pms.hasPermission('sys_role_perm')") + public R roleMenuUpd(Integer roleId, @RequestParam("menuIds[]") Integer[] menuIds) { + SysRole sysRole = sysRoleService.selectById(roleId); + return new R<>(sysRoleMenuService.insertRoleMenus(sysRole.getRoleCode(), roleId, menuIds)); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java new file mode 100644 index 000000000..52883b095 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java @@ -0,0 +1,167 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.controller; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.dto.UserDTO; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.api.entity.SysUserRole; +import com.pig4cloud.pigx.admin.api.vo.UserVO; +import com.pig4cloud.pigx.admin.service.SysUserService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.core.util.R; +import com.pig4cloud.pigx.common.log.annotation.SysLog; +import com.pig4cloud.pigx.common.security.util.SecurityUtils; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author lengleng + * @date 2017/10/28 + */ +@RestController +@RequestMapping("/user") +public class UserController { + private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder(); + @Autowired + private SysUserService userService; + + /** + * 获取当前用户信息(角色、权限) + * 并且异步初始化用户部门信息 + * + * @param from 请求标志,该接口会被 auth、 前端调用 + * @param username 用户名 + * @return 用户名 + */ + @GetMapping(value = {"/info", "/info/{username}"}) + public R user(@PathVariable(required = false) String username, + @RequestHeader(required = false) String from) { + // 查询用户不为空时判断是不是内部请求 + if (StrUtil.isNotBlank(username) && !StrUtil.equals(SecurityConstants.FROM_IN, from)) { + return new R<>(null, "error"); + } + //为空时查询当前用户 + if (StrUtil.isBlank(username)) { + username = SecurityUtils.getUser(); + } + + return new R<>(userService.findUserInfo(username)); + } + + /** + * 通过ID查询当前用户信息 + * + * @param id ID + * @return 用户信息 + */ + @GetMapping("/{id}") + public UserVO user(@PathVariable Integer id) { + return userService.selectUserVoById(id); + } + + /** + * 删除用户信息 + * + * @param id ID + * @return R + */ + @SysLog("删除用户信息") + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('sys_user_del')") + @ApiOperation(value = "删除用户", notes = "根据ID删除用户") + @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int", paramType = "path",example = "1000") + public R userDel(@PathVariable Integer id) { + SysUser sysUser = userService.selectById(id); + return new R<>(userService.deleteUserById(sysUser)); + } + + /** + * 添加用户 + * + * @param userDto 用户信息 + * @return success/false + */ + @SysLog("添加用户") + @PostMapping + @PreAuthorize("@pms.hasPermission('sys_user_add')") + public R user(@RequestBody UserDTO userDto) { + SysUser sysUser = new SysUser(); + BeanUtils.copyProperties(userDto, sysUser); + sysUser.setDelFlag(CommonConstant.STATUS_NORMAL); + sysUser.setPassword(ENCODER.encode(userDto.getNewpassword1())); + userService.insert(sysUser); + + userDto.getRole().forEach(roleId -> { + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(sysUser.getUserId()); + userRole.setRoleId(roleId); + userRole.insert(); + }); + return new R<>(Boolean.TRUE); + } + + /** + * 更新用户信息 + * + * @param userDto 用户信息 + * @return R + */ + @PutMapping + @PreAuthorize("@pms.hasPermission('sys_user_edit')") + public R userUpdate(@RequestBody UserDTO userDto) { + SysUser user = userService.selectById(userDto.getUserId()); + return new R<>(userService.updateUser(userDto, user.getUsername())); + } + + /** + * 分页查询用户 + * + * @param params 参数集 + * @return 用户集合 + */ + @RequestMapping("/userPage") + public Page userPage(@RequestParam Map params) { + return userService.selectWithRolePage(new Query(params)); + } + + /** + * 修改个人信息 + * + * @param userDto userDto + * @return success/false + */ + @PutMapping("/editInfo") + public R editInfo(@RequestBody UserDTO userDto) { + return userService.updateUserInfo(userDto, SecurityUtils.getUser()); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDeptMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDeptMapper.java new file mode 100644 index 000000000..9f7b12ff4 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDeptMapper.java @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysDept; + +import java.util.List; + +/** + *

+ * 部门管理 Mapper 接口 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +public interface SysDeptMapper extends BaseMapper { + + /** + * 关联dept——relation + * + * @param delFlag 删除标记 + * @return 数据列表 + */ + List selectDeptDtoList(String delFlag); + + /** + * 删除部门关系表数据 + * + * @param id 部门ID + */ + void deleteDeptRealtion(Integer id); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDeptRelationMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDeptRelationMapper.java new file mode 100644 index 000000000..069c66bc4 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDeptRelationMapper.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; + +/** + *

+ * Mapper 接口 + *

+ * + * @author lengleng + * @since 2018-02-12 + */ +public interface SysDeptRelationMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDictMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDictMapper.java new file mode 100644 index 000000000..20c9c9c82 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysDictMapper.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysDict; + +/** + *

+ * 字典表 Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-11-19 + */ +public interface SysDictMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysLogMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysLogMapper.java new file mode 100644 index 000000000..c248310a4 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysLogMapper.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysLog; + +/** + *

+ * 日志表 Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-11-20 + */ +public interface SysLogMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysMenuMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysMenuMapper.java new file mode 100644 index 000000000..5304ebca7 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysMenuMapper.java @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysMenu; +import com.pig4cloud.pigx.admin.api.vo.MenuVO; + +import java.util.List; + +/** + *

+ * 菜单权限表 Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysMenuMapper extends BaseMapper { + + /** + * 通过角色编号查询菜单 + * + * @param role 角色编号 + * @return + */ + List findMenuByRoleCode(String role); + + /** + * 通过角色ID查询权限 + * + * @param roleIds Ids + * @return + */ + List findPermissionsByRoleIds(String roleIds); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysOauthClientDetailsMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysOauthClientDetailsMapper.java new file mode 100644 index 000000000..0baffe4b3 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysOauthClientDetailsMapper.java @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails; + +/** + *

+ * Mapper 接口 + *

+ * + * @author lengleng + * @since 2018-05-15 + */ +public interface SysOauthClientDetailsMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleDeptMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleDeptMapper.java new file mode 100644 index 000000000..3ed3d6892 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleDeptMapper.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysRoleDept; + +/** + *

+ * 角色与部门对应关系 Mapper 接口 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +public interface SysRoleDeptMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java new file mode 100644 index 000000000..36ed59c7c --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.entity.SysRole; + +import java.util.List; +import java.util.Map; + +/** + *

+ * Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysRoleMapper extends BaseMapper { + + /** + * 查询角色列表含有部门信息 + * + * @param query 查询对象 + * @param condition 条件 + * @return List + */ + List selectRolePage(Query query, Map condition); + + /** + * 通过部门ID查询角色列表 + * + * @param deptId 部门ID + * @return 角色列表 + */ + List selectListByDeptId(Integer deptId); + + /** + * 通过用户ID,查询角色信息 + * + * @param userId + * @return + */ + List findRolesByUserId(Integer userId); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMenuMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMenuMapper.java new file mode 100644 index 000000000..0843d7b08 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMenuMapper.java @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysRoleMenu; + +/** + *

+ * 角色菜单表 Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysRoleMenuMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java new file mode 100644 index 000000000..72a477535 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.api.vo.UserVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

+ * 用户表 Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysUserMapper extends BaseMapper { + /** + * 通过用户名查询用户信息(含有角色信息) + * + * @param username 用户名 + * @return userVo + */ + UserVO selectUserVoByUsername(String username); + + /** + * 分页查询用户信息(含角色) + * + * @param query 查询条件 + * @param username 用户名 + * @return list + */ + List selectUserVoPage(Query query, @Param("username") Object username); + + /** + * 通过ID查询用户信息 + * + * @param id 用户ID + * @return userVo + */ + UserVO selectUserVoById(Integer id); + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserRoleMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserRoleMapper.java new file mode 100644 index 000000000..71d9ec14e --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserRoleMapper.java @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.mapper; + + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysUserRole; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * 用户角色表 Mapper 接口 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysUserRoleMapper extends BaseMapper { + /** + * 根据用户Id删除该用户的角色关系 + * + * @param userId 用户ID + * @return boolean + * @author 寻欢·李 + * @date 2017年12月7日 16:31:38 + */ + Boolean deleteByUserId(@Param("userId") Integer userId); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java new file mode 100644 index 000000000..4c839b76b --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; + +/** + *

+ * 服务类 + *

+ * + * @author lengleng + * @since 2018-02-12 + */ +public interface SysDeptRelationService extends IService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptService.java new file mode 100644 index 000000000..2be8923e1 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptService.java @@ -0,0 +1,70 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.dto.DeptTree; +import com.pig4cloud.pigx.admin.api.entity.SysDept; + +import java.util.List; + +/** + *

+ * 部门管理 服务类 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +public interface SysDeptService extends IService { + + /** + * 查询部门树菜单 + * + * @param sysDeptEntityWrapper + * @return 树 + */ + List selectListTree(EntityWrapper sysDeptEntityWrapper); + + /** + * 添加信息部门 + * + * @param sysDept + * @return + */ + Boolean insertDept(SysDept sysDept); + + /** + * 删除部门 + * + * @param id 部门 ID + * @return 成功、失败 + */ + Boolean deleteDeptById(Integer id); + + /** + * 更新部门 + * + * @param sysDept 部门信息 + * @return 成功、失败 + */ + Boolean updateDeptById(SysDept sysDept); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDictService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDictService.java new file mode 100644 index 000000000..e5a5b3ff5 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDictService.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysDict; + +/** + *

+ * 字典表 服务类 + *

+ * + * @author lengleng + * @since 2017-11-19 + */ +public interface SysDictService extends IService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java new file mode 100644 index 000000000..8e0e88f3c --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysLogService.java @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysLog; + +/** + *

+ * 日志表 服务类 + *

+ * + * @author lengleng + * @since 2017-11-20 + */ +public interface SysLogService extends IService { + + /** + * 通过ID删除日志(逻辑删除) + * + * @param id 日志ID + * @return true/false + */ + Boolean updateByLogId(Long id); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysMenuService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysMenuService.java new file mode 100644 index 000000000..3800947a7 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysMenuService.java @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysMenu; +import com.pig4cloud.pigx.admin.api.vo.MenuVO; + +import java.util.List; + +/** + *

+ * 菜单权限表 服务类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysMenuService extends IService { + /** + * 通过角色编号查询URL 权限 + * + * @param role 角色编号 + * @return 菜单列表 + */ + List findMenuByRoleCode(String role); + + /** + * 级联删除菜单 + * + * @param id 菜单ID + * @return 成功、失败 + */ + Boolean deleteMenu(Integer id); + + /** + * 更新菜单信息 + * + * @param sysMenu 菜单信息 + * @return 成功、失败 + */ + Boolean updateMenuById(SysMenu sysMenu); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysOauthClientDetailsService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysOauthClientDetailsService.java new file mode 100644 index 000000000..0e1aaf999 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysOauthClientDetailsService.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails; + +/** + *

+ * 服务类 + *

+ * + * @author lengleng + * @since 2018-05-15 + */ +public interface SysOauthClientDetailsService extends IService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleDeptService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleDeptService.java new file mode 100644 index 000000000..9c0a1eb62 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleDeptService.java @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysRoleDept; + +/** + *

+ * 角色与部门对应关系 服务类 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +public interface SysRoleDeptService extends IService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleMenuService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleMenuService.java new file mode 100644 index 000000000..acf41d0fa --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleMenuService.java @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysRoleMenu; + +/** + *

+ * 角色菜单表 服务类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysRoleMenuService extends IService { + + /** + * 更新角色菜单 + * + * @param role + * @param roleId 角色 + * @param menuIds 菜单列表 + * @return + */ + Boolean insertRoleMenus(String role, Integer roleId, Integer[] menuIds); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java new file mode 100644 index 000000000..95e320467 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java @@ -0,0 +1,81 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.dto.RoleDTO; +import com.pig4cloud.pigx.admin.api.entity.SysRole; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysRoleService extends IService { + + /** + * 添加角色 + * + * @param roleDto 角色信息 + * @return 成功、失败 + */ + Boolean insertRole(RoleDTO roleDto); + + /** + * 分页查角色列表 + * + * @param objectQuery 查询条件 + * @param objectEntityWrapper wapper + * @return page + */ + Page selectwithDeptPage(Query objectQuery, EntityWrapper objectEntityWrapper); + + /** + * 更新角色 + * + * @param roleDto 含有部门信息 + * @return 成功、失败 + */ + Boolean updateRoleById(RoleDTO roleDto); + + /** + * 通过部门ID查询角色列表 + * + * @param deptId 部门ID + * @return 角色列表 + */ + List selectListByDeptId(Integer deptId); + + /** + * 通过用户ID,查询角色信息 + * + * @param userId + * @return + */ + List findRolesByUserId(Integer userId); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserRoleService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserRoleService.java new file mode 100644 index 000000000..5bba86ee0 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserRoleService.java @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysUserRole; + +/** + *

+ * 用户角色表 服务类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +public interface SysUserRoleService extends IService { + + /** + * 根据用户Id删除该用户的角色关系 + * + * @param userId 用户ID + * @return boolean + * @author 寻欢·李 + * @date 2017年12月7日 16:31:38 + */ + Boolean deleteByUserId(Integer userId); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java new file mode 100644 index 000000000..435ed7a69 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java @@ -0,0 +1,85 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.plugins.Page; +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.dto.UserDTO; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.api.vo.UserVO; +import com.pig4cloud.pigx.common.core.util.R; + +/** + * @author lengleng + * @date 2017/10/31 + */ +public interface SysUserService extends IService { + /** + * 查询用户信息 + * + * @param username 用户名 + * @return userInfo + */ + UserInfo findUserInfo(String username); + + /** + * 分页查询用户信息(含有角色信息) + * + * @param query 查询条件 + * @return + */ + Page selectWithRolePage(Query query); + + /** + * 删除用户 + * + * @param sysUser 用户 + * @return boolean + */ + Boolean deleteUserById(SysUser sysUser); + + /** + * 更新当前用户基本信息 + * + * @param userDto 用户信息 + * @param username 用户名 + * @return Boolean + */ + R updateUserInfo(UserDTO userDto, String username); + + /** + * 更新指定用户信息 + * + * @param userDto 用户信息 + * @param username 用户信息 + * @return + */ + Boolean updateUser(UserDTO userDto, String username); + + /** + * 通过ID查询用户信息 + * + * @param id 用户ID + * @return 用户信息 + */ + UserVO selectUserVoById(Integer id); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java new file mode 100644 index 000000000..0390c698e --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; +import com.pig4cloud.pigx.admin.mapper.SysDeptRelationMapper; +import com.pig4cloud.pigx.admin.service.SysDeptRelationService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author lengleng + * @since 2018-02-12 + */ +@Service +public class SysDeptRelationServiceImpl extends ServiceImpl implements SysDeptRelationService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java new file mode 100644 index 000000000..e42c229ae --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java @@ -0,0 +1,160 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.dto.DeptTree; +import com.pig4cloud.pigx.admin.api.entity.SysDept; +import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; +import com.pig4cloud.pigx.admin.api.vo.TreeUtil; +import com.pig4cloud.pigx.admin.mapper.SysDeptMapper; +import com.pig4cloud.pigx.admin.mapper.SysDeptRelationMapper; +import com.pig4cloud.pigx.admin.service.SysDeptService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + *

+ * 部门管理 服务实现类 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +@Service +public class SysDeptServiceImpl extends ServiceImpl implements SysDeptService { + @Autowired + private SysDeptMapper sysDeptMapper; + @Autowired + private SysDeptRelationMapper sysDeptRelationMapper; + + /** + * 添加信息部门 + * + * @param dept 部门 + * @return + */ + @Override + public Boolean insertDept(SysDept dept) { + SysDept sysDept = new SysDept(); + BeanUtils.copyProperties(dept, sysDept); + this.insert(sysDept); + this.insertDeptRelation(sysDept); + return Boolean.TRUE; + } + + /** + * 维护部门关系 + * + * @param sysDept 部门 + */ + private void insertDeptRelation(SysDept sysDept) { + //增加部门关系表 + SysDeptRelation deptRelation = new SysDeptRelation(); + deptRelation.setDescendant(sysDept.getParentId()); + List deptRelationList = sysDeptRelationMapper.selectList(new EntityWrapper<>(deptRelation)); + for (SysDeptRelation sysDeptRelation : deptRelationList) { + sysDeptRelation.setDescendant(sysDept.getDeptId()); + sysDeptRelationMapper.insert(sysDeptRelation); + } + //自己也要维护到关系表中 + SysDeptRelation own = new SysDeptRelation(); + own.setDescendant(sysDept.getDeptId()); + own.setAncestor(sysDept.getDeptId()); + sysDeptRelationMapper.insert(own); + } + + /** + * 删除部门 + * + * @param id 部门 ID + * @return 成功、失败 + */ + @Override + public Boolean deleteDeptById(Integer id) { + SysDept sysDept = new SysDept(); + sysDept.setDeptId(id); + sysDept.setUpdateTime(new Date()); + sysDept.setDelFlag(CommonConstant.STATUS_DEL); + this.deleteById(sysDept); + sysDeptMapper.deleteDeptRealtion(id); + return Boolean.TRUE; + } + + /** + * 更新部门 + * + * @param sysDept 部门信息 + * @return 成功、失败 + */ + @Override + public Boolean updateDeptById(SysDept sysDept) { + //更新部门状态 + this.updateById(sysDept); + //删除部门关系 + sysDeptMapper.deleteDeptRealtion(sysDept.getDeptId()); + //新建部门关系 + this.insertDeptRelation(sysDept); + return Boolean.TRUE; + } + + /** + * 查询部门树 + * + * @param sysDeptEntityWrapper + * @return 树 + */ + @Override + public List selectListTree(EntityWrapper sysDeptEntityWrapper) { + sysDeptEntityWrapper.orderBy("order_num", false); + return getDeptTree(this.selectList(sysDeptEntityWrapper), 0); + } + + + /** + * 构建部门树 + * + * @param depts 部门 + * @param root 根节点 + * @return + */ + private List getDeptTree(List depts, int root) { + List trees = new ArrayList<>(); + DeptTree node; + for (SysDept dept : depts) { + if (dept.getParentId().equals(dept.getDeptId())) { + continue; + } + node = new DeptTree(); + node.setId(dept.getDeptId()); + node.setParentId(dept.getParentId()); + node.setName(dept.getName()); + trees.add(node); + } + return TreeUtil.bulid(trees, root); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDictServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDictServiceImpl.java new file mode 100644 index 000000000..39519cbad --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDictServiceImpl.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysDict; +import com.pig4cloud.pigx.admin.mapper.SysDictMapper; +import com.pig4cloud.pigx.admin.service.SysDictService; +import org.springframework.stereotype.Service; + +/** + *

+ * 字典表 服务实现类 + *

+ * + * @author lengleng + * @since 2017-11-19 + */ +@Service +public class SysDictServiceImpl extends ServiceImpl implements SysDictService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java new file mode 100644 index 000000000..d3b126a57 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysLog; +import com.pig4cloud.pigx.admin.mapper.SysLogMapper; +import com.pig4cloud.pigx.admin.service.SysLogService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** + *

+ * 日志表 服务实现类 + *

+ * + * @author lengleng + * @since 2017-11-20 + */ +@Service +public class SysLogServiceImpl extends ServiceImpl implements SysLogService { + + @Override + public Boolean updateByLogId(Long id) { + + SysLog sysLog = new SysLog(); + sysLog.setId(id); + sysLog.setDelFlag(CommonConstant.STATUS_DEL); + sysLog.setUpdateTime(new Date()); + return updateById(sysLog); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysMenuServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysMenuServiceImpl.java new file mode 100644 index 000000000..1f8c322d5 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysMenuServiceImpl.java @@ -0,0 +1,78 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysMenu; +import com.pig4cloud.pigx.admin.api.vo.MenuVO; +import com.pig4cloud.pigx.admin.mapper.SysMenuMapper; +import com.pig4cloud.pigx.admin.service.SysMenuService; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 菜单权限表 服务实现类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Service +public class SysMenuServiceImpl extends ServiceImpl implements SysMenuService { + @Autowired + private SysMenuMapper sysMenuMapper; + + @Override + @Cacheable(value = "menu_details", key = "#role + '_menu'") + public List findMenuByRoleCode(String role) { + return sysMenuMapper.findMenuByRoleCode(role); + } + + @Override + @CacheEvict(value = "menu_details", allEntries = true) + public Boolean deleteMenu(Integer id) { + // 删除当前节点 + SysMenu condition1 = new SysMenu(); + condition1.setMenuId(id); + condition1.setDelFlag(CommonConstant.STATUS_DEL); + this.updateById(condition1); + + // 删除父节点为当前节点的节点 + SysMenu conditon2 = new SysMenu(); + conditon2.setParentId(id); + SysMenu sysMenu = new SysMenu(); + sysMenu.setDelFlag(CommonConstant.STATUS_DEL); + return this.update(sysMenu, new EntityWrapper<>(conditon2)); + } + + @Override + @CacheEvict(value = "menu_details", allEntries = true) + public Boolean updateMenuById(SysMenu sysMenu) { + return this.updateById(sysMenu); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysOauthClientDetailsServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysOauthClientDetailsServiceImpl.java new file mode 100644 index 000000000..7ed8a5280 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysOauthClientDetailsServiceImpl.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails; +import com.pig4cloud.pigx.admin.mapper.SysOauthClientDetailsMapper; +import com.pig4cloud.pigx.admin.service.SysOauthClientDetailsService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author lengleng + * @since 2018-05-15 + */ +@Service +public class SysOauthClientDetailsServiceImpl extends ServiceImpl implements SysOauthClientDetailsService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleDeptServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleDeptServiceImpl.java new file mode 100644 index 000000000..82620024e --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleDeptServiceImpl.java @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysRoleDept; +import com.pig4cloud.pigx.admin.mapper.SysRoleDeptMapper; +import com.pig4cloud.pigx.admin.service.SysRoleDeptService; +import org.springframework.stereotype.Service; + +/** + *

+ * 角色与部门对应关系 服务实现类 + *

+ * + * @author lengleng + * @since 2018-01-20 + */ +@Service +public class SysRoleDeptServiceImpl extends ServiceImpl implements SysRoleDeptService { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java new file mode 100644 index 000000000..0363aadda --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysRoleMenu; +import com.pig4cloud.pigx.admin.mapper.SysRoleMenuMapper; +import com.pig4cloud.pigx.admin.service.SysRoleMenuService; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + *

+ * 角色菜单表 服务实现类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Service +public class SysRoleMenuServiceImpl extends ServiceImpl implements SysRoleMenuService { + @Override + @CacheEvict(value = "menu_details", key = "#role + '_menu'") + public Boolean insertRoleMenus(String role, Integer roleId, Integer[] menuIds) { + SysRoleMenu condition = new SysRoleMenu(); + condition.setRoleId(roleId); + this.delete(new EntityWrapper<>(condition)); + + List roleMenuList = new ArrayList<>(); + for (Integer menuId : menuIds) { + SysRoleMenu roleMenu = new SysRoleMenu(); + roleMenu.setRoleId(roleId); + roleMenu.setMenuId(menuId); + roleMenuList.add(roleMenu); + } + return this.insertBatch(roleMenuList); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java new file mode 100644 index 000000000..dd82ea0da --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java @@ -0,0 +1,133 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.dto.RoleDTO; +import com.pig4cloud.pigx.admin.api.entity.SysRole; +import com.pig4cloud.pigx.admin.api.entity.SysRoleDept; +import com.pig4cloud.pigx.admin.mapper.SysRoleDeptMapper; +import com.pig4cloud.pigx.admin.mapper.SysRoleMapper; +import com.pig4cloud.pigx.admin.service.SysRoleService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Service +public class SysRoleServiceImpl extends ServiceImpl implements SysRoleService { + @Autowired + private SysRoleDeptMapper sysRoleDeptMapper; + @Autowired + private SysRoleMapper sysRoleMapper; + + /** + * 添加角色 + * + * @param roleDto 角色信息 + * @return 成功、失败 + */ + @Override + public Boolean insertRole(RoleDTO roleDto) { + SysRole sysRole = new SysRole(); + BeanUtils.copyProperties(roleDto, sysRole); + sysRoleMapper.insert(sysRole); + SysRoleDept roleDept = new SysRoleDept(); + roleDept.setRoleId(sysRole.getRoleId()); + roleDept.setDeptId(roleDto.getRoleDeptId()); + sysRoleDeptMapper.insert(roleDept); + return true; + } + + /** + * 分页查角色列表 + * + * @param query 查询条件 + * @param wrapper wapper + * @return page + */ + @Override + public Page selectwithDeptPage(Query query, EntityWrapper wrapper) { + query.setRecords(sysRoleMapper.selectRolePage(query, query.getCondition())); + return query; + } + + /** + * 更新角色 + * + * @param roleDto 含有部门信息 + * @return 成功、失败 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public Boolean updateRoleById(RoleDTO roleDto) { + //删除原有的角色部门关系 + SysRoleDept condition = new SysRoleDept(); + condition.setRoleId(roleDto.getRoleId()); + sysRoleDeptMapper.delete(new EntityWrapper<>(condition)); + + //更新角色信息 + SysRole sysRole = new SysRole(); + BeanUtils.copyProperties(roleDto, sysRole); + sysRoleMapper.updateById(sysRole); + + //维护角色部门关系 + SysRoleDept roleDept = new SysRoleDept(); + roleDept.setRoleId(sysRole.getRoleId()); + roleDept.setDeptId(roleDto.getRoleDeptId()); + sysRoleDeptMapper.insert(roleDept); + return true; + } + + /** + * 通过部门ID查询角色列表 + * + * @param deptId 部门ID + * @return 角色列表 + */ + @Override + public List selectListByDeptId(Integer deptId) { + return sysRoleMapper.selectListByDeptId(deptId); + } + + /** + * 通过用户ID,查询角色信息 + * + * @param userId + * @return + */ + @Override + public List findRolesByUserId(Integer userId) { + return sysRoleMapper.findRolesByUserId(userId); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserRoleServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserRoleServiceImpl.java new file mode 100644 index 000000000..648d3e66e --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserRoleServiceImpl.java @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysUserRole; +import com.pig4cloud.pigx.admin.mapper.SysUserRoleMapper; +import com.pig4cloud.pigx.admin.service.SysUserRoleService; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户角色表 服务实现类 + *

+ * + * @author lengleng + * @since 2017-10-29 + */ +@Service +public class SysUserRoleServiceImpl extends ServiceImpl implements SysUserRoleService { + + /** + * 根据用户Id删除该用户的角色关系 + * + * @param userId 用户ID + * @return boolean + * @author 寻欢·李 + * @date 2017年12月7日 16:31:38 + */ + @Override + public Boolean deleteByUserId(Integer userId) { + return baseMapper.deleteByUserId(userId); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java new file mode 100644 index 000000000..4751f98b5 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java @@ -0,0 +1,185 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.admin.api.dto.UserDTO; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysRole; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.api.entity.SysUserRole; +import com.pig4cloud.pigx.admin.api.vo.MenuVO; +import com.pig4cloud.pigx.admin.api.vo.UserVO; +import com.pig4cloud.pigx.admin.mapper.SysUserMapper; +import com.pig4cloud.pigx.admin.service.SysMenuService; +import com.pig4cloud.pigx.admin.service.SysRoleService; +import com.pig4cloud.pigx.admin.service.SysUserRoleService; +import com.pig4cloud.pigx.admin.service.SysUserService; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * @author lengleng + * @date 2017/10/31 + */ +@Slf4j +@Service +public class SysUserServiceImpl extends ServiceImpl implements SysUserService { + private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder(); + @Autowired + private SysMenuService sysMenuService; + @Autowired + private SysUserMapper sysUserMapper; + @Autowired + private SysRoleService sysRoleService; + @Autowired + private SysUserRoleService sysUserRoleService; + + /** + * 通过用户名查用户的全部信息 + * + * @param username 用户名 + * @return + */ + @Override + @Cacheable(value = "user_details", key = "#username") + public UserInfo findUserInfo(String username) { + SysUser condition = new SysUser(); + condition.setUsername(username); + SysUser sysUser = this.selectOne(new EntityWrapper<>(condition)); + if (sysUser == null) { + return null; + } + + UserInfo userInfo = new UserInfo(); + userInfo.setSysUser(sysUser); + //设置角色列表 + List roleList = sysRoleService.findRolesByUserId(sysUser.getUserId()); + List roleCodes = new ArrayList<>(); + if (CollUtil.isNotEmpty(roleList)) { + roleList.forEach(sysRole -> roleCodes.add(sysRole.getRoleCode())); + } + userInfo.setRoles(ArrayUtil.toArray(roleCodes, String.class)); + + //设置权限列表(menu.permission) + Set menuVoSet = new HashSet<>(); + for (String role : roleCodes) { + List menuVos = sysMenuService.findMenuByRoleCode(role); + menuVoSet.addAll(menuVos); + } + Set permissions = new HashSet<>(); + for (MenuVO menuVo : menuVoSet) { + if (StringUtils.isNotEmpty(menuVo.getPermission())) { + String permission = menuVo.getPermission(); + permissions.add(permission); + } + } + userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class)); + return userInfo; + } + + @Override + public Page selectWithRolePage(Query query) { + Object username = query.getCondition().get("username"); + query.setRecords(sysUserMapper.selectUserVoPage(query, username)); + return query; + } + + /** + * 通过ID查询用户信息 + * + * @param id 用户ID + * @return 用户信息 + */ + @Override + public UserVO selectUserVoById(Integer id) { + return sysUserMapper.selectUserVoById(id); + } + + /** + * 删除用户 + * + * @param sysUser 用户 + * @return Boolean + */ + @Override + @CacheEvict(value = "user_details", key = "#sysUser.username") + public Boolean deleteUserById(SysUser sysUser) { + sysUserRoleService.deleteByUserId(sysUser.getUserId()); + this.deleteById(sysUser.getUserId()); + return Boolean.TRUE; + } + + @Override + @CacheEvict(value = "user_details", key = "#username") + public R updateUserInfo(UserDTO userDto, String username) { + UserVO userVO = sysUserMapper.selectUserVoByUsername(username); + SysUser sysUser = new SysUser(); + if (StrUtil.isNotBlank(userDto.getPassword()) + && StrUtil.isNotBlank(userDto.getNewpassword1())) { + if (ENCODER.matches(userDto.getPassword(), userVO.getPassword())) { + sysUser.setPassword(ENCODER.encode(userDto.getNewpassword1())); + } else { + log.warn("原密码错误,修改密码失败:{}", username); + return new R<>(Boolean.FALSE, "原密码错误,修改失败"); + } + } + sysUser.setPhone(userDto.getPhone()); + sysUser.setUserId(userVO.getUserId()); + sysUser.setAvatar(userDto.getAvatar()); + return new R<>(this.updateById(sysUser)); + } + + @Override + @CacheEvict(value = "user_details", key = "#username") + public Boolean updateUser(UserDTO userDto, String username) { + SysUser sysUser = new SysUser(); + BeanUtils.copyProperties(userDto, sysUser); + sysUser.setUpdateTime(new Date()); + this.updateById(sysUser); + + SysUserRole condition = new SysUserRole(); + condition.setUserId(userDto.getUserId()); + sysUserRoleService.delete(new EntityWrapper<>(condition)); + userDto.getRole().forEach(roleId -> { + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(sysUser.getUserId()); + userRole.setRoleId(roleId); + userRole.insert(); + }); + return Boolean.TRUE; + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/bootstrap.yml b/pigx-upms/pigx-upms-biz/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..1dbe02882 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/bootstrap.yml @@ -0,0 +1,26 @@ +server: + port: 4000 + +spring: + application: + name: pigx-upms + # dev环境 + profiles: + active: dev + # 配置中心 + cloud: + config: + fail-fast: true + name: ${spring.application.name} + profile: ${spring.profiles.active} + discovery: + enabled: true + service-id: pigx-config + +# 注册中心配置 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://pig:pig@localhost:1025/eureka/ diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDeptMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDeptMapper.xml new file mode 100644 index 000000000..fdd683274 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDeptMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + dept_id AS deptId, parent_id AS parentId, name, order_num AS orderNum, create_time AS createTime, update_time AS updateTime, del_flag AS delFlag + + + DELETE + FROM + sys_dept_relation + WHERE + descendant IN ( + SELECT + temp.descendant + FROM + ( + SELECT + descendant + FROM + sys_dept_relation + WHERE + ancestor = #{id} + ) temp + ) + + + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDeptRelationMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDeptRelationMapper.xml new file mode 100644 index 000000000..d18d3d1e6 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDeptRelationMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + ancestor, descendant + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDictMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDictMapper.xml new file mode 100644 index 000000000..99029776c --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysDictMapper.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + id, value, label, type, description, sort, create_time AS createTime, update_time AS updateTime, remarks, del_flag AS delFlag + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysLogMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysLogMapper.xml new file mode 100644 index 000000000..01c09d98e --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysLogMapper.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, type, title, create_by AS createBy, create_time AS createTime, update_time AS updateTime, remote_addr AS remoteAddr, user_agent AS userAgent, request_uri AS requestUri, method, params, `time`, del_flag AS delFlag + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysMenuMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysMenuMapper.xml new file mode 100644 index 000000000..9eb4f10d3 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysMenuMapper.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysOauthClientDetailsMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysOauthClientDetailsMapper.xml new file mode 100644 index 000000000..54fd10e9d --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysOauthClientDetailsMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + client_id AS clientId, resource_ids AS resourceIds, client_secret AS clientSecret, scope, authorized_grant_types AS authorizedGrantTypes, web_server_redirect_uri AS webServerRedirectUri, authorities, access_token_validity AS accessTokenValidity, refresh_token_validity AS refreshTokenValidity, additional_information AS additionalInformation, autoapprove + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleDeptMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleDeptMapper.xml new file mode 100644 index 000000000..a93f88536 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleDeptMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + id, role_id AS roleId, dept_id AS deptId + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleMapper.xml new file mode 100644 index 000000000..7c61430b7 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleMapper.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleMenuMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleMenuMapper.xml new file mode 100644 index 000000000..9e3589622 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysRoleMenuMapper.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml new file mode 100644 index 000000000..c5e43b771 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + `user`.user_id, + `user`.username, + `user`.`password`, + `user`.salt, + `user`.phone, + `user`.avatar, + `user`.dept_id, + `user`.create_time AS ucreate_time, + `user`.update_time AS uupdate_time, + `user`.del_flag AS udel_flag, + `user`.dept_id AS deptId, + r.role_id, + r.role_name, + r.role_code, + r.role_desc, + r.create_time AS rcreate_time, + r.update_time AS rupdate_time + FROM + sys_user AS `user` + LEFT JOIN sys_user_role AS ur ON ur.user_id = `user`.user_id + LEFT JOIN sys_role AS r ON r.role_id = ur.role_id + + + + + + + + + diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserRoleMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserRoleMapper.xml new file mode 100644 index 000000000..1777eeeac --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserRoleMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + DELETE FROM sys_user_role WHERE user_id = #{userId} + + + diff --git a/pigx-upms/pom.xml b/pigx-upms/pom.xml new file mode 100644 index 000000000..2c0504f54 --- /dev/null +++ b/pigx-upms/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + + + pigx-upms + ${pigx.version} + pigx-upms + pigx 通用用户权限管理聚合模块 + pom + + + pigx-upms-api + pigx-upms-biz + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..468452106 --- /dev/null +++ b/pom.xml @@ -0,0 +1,174 @@ + + + + + 4.0.0 + + com.pig4cloud + pigx + ${pigx.version} + pigx + pom + https://www.pig4cloud.com + + + org.springframework.boot + spring-boot-starter-parent + 2.0.3.RELEASE + + + + + 1.2.3 + 2.0.3.RELEASE + Finchley.RELEASE + UTF-8 + 1.8 + 1.8 + 1.16.20 + 2.0.1 + 4.0.4 + 2.3 + 1.2.47 + 0.0.9 + 2.9.2 + 2.3.3.RELEASE + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-actuator + + + + de.codecentric + spring-boot-admin-starter-client + ${monitor.version} + + + + org.springframework.cloud + spring-cloud-starter-netflix-hystrix + + + + org.projectlombok + lombok + ${lombok.version} + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + pigx-eureka + pigx-config + pigx-gateway + pigx-auth + pigx-upms + pigx-common + pigx-monitor + + + + + + io.spring.platform + platform-bom + Cairo-SR2 + pom + import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + build-info + + + + + + maven-compiler-plugin + + ${java.version} + ${java.version} + UTF-8 + + + + + + + pl.project13.maven + git-commit-id-plugin + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone + + + aliyun + aliyun + http://maven.aliyun.com/nexus/content/groups/public/ + + +