....
This commit is contained in:
commit
7d4b2abd43
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
target
|
||||
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# virtual machine crash logs
|
||||
hs_err_pid*
|
||||
195
docs/database/cases.sql
Normal file
195
docs/database/cases.sql
Normal file
@ -0,0 +1,195 @@
|
||||
|
||||
USE `xgl_cases`;
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for data_dict
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `data_dict`;
|
||||
CREATE TABLE `data_dict` (
|
||||
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
`datakey` varchar(32) NOT NULL COMMENT '字典key值',
|
||||
`name` varchar(64) NOT NULL COMMENT '字典名称',
|
||||
`isvalid` tinyint(4) DEFAULT '1' COMMENT '是否有效(1:有效,0:无效)',
|
||||
`description` varchar(255) DEFAULT NULL COMMENT '描述',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `ukey_datakey`(`datakey`)
|
||||
) ENGINE = InnoDB COMMENT='数据字典表';
|
||||
|
||||
/*Data for the table `data_dict` */
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (1,'2020-05-27 15:54:33','2020-05-27 15:54:33','isValid','状态',1,'全局使用,不可删除');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (2,'2020-05-27 16:24:01','2020-05-27 16:24:01','logType','日志类型',1,'系统日志使用');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (3,'2020-05-27 16:25:09','2020-05-27 16:25:09','isTask','任务状态',1,'任务使用');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (4,'2020-05-27 16:29:08','2020-05-27 16:29:08','tag_ppqa','标签_品牌全案',1,'案例库-品牌全案目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (5,'2020-05-27 16:29:25','2020-05-27 16:29:49','tag_ggqa','标签_公关全案',1,'案例库-公关全案目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (6,'2020-05-27 16:30:16','2020-05-27 16:30:30','tag_design','标签_创意设计',1,'案例库-创意设计目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (7,'2020-05-27 16:30:43','2020-05-27 16:30:55','tag_video','标签_视频动画',1,'案例库-视频动画目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (8,'2020-05-27 16:31:05','2020-05-27 18:12:32','tag_h5','标签_技术开发',1,'案例库-技术开发目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (9,'2020-05-27 16:32:04','2020-05-27 16:32:14','tag_ldhd','标签_落地活动',1,'案例库-落地活动目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (10,'2020-05-27 16:32:24','2020-05-27 16:42:16','tag_others','标签_其他案例',1,'案例库-其他案例目录下的标签库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (11,'2020-05-27 16:39:02','2020-05-27 16:39:19','from_ppqa','来源_品牌全案',1,'案例库-品牌全案目录下的案例来源库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (12,'2020-05-27 16:39:36','2020-05-27 16:39:46','from_ggqa','来源_公关全案',1,'案例库-公关全案目录下的案例来源库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (13,'2020-05-27 16:40:01','2020-05-27 16:40:12','from_design','来源_创意设计',1,'案例库-创意设计目录下的案例来源库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (14,'2020-05-27 16:40:15','2020-05-27 16:40:34','from_video','来源_视频动画',1,'案例库-视频动画目录下的案例来源库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (15,'2020-05-27 16:40:47','2020-05-27 18:12:00','from_h5','来源_技术开发',1,'案例库-技术开发目录下的案例来源库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (16,'2020-05-27 16:41:19','2020-05-27 16:41:39','from_ldhd','来源_落地活动',1,'案例库-落地活动目录下的案例来源库');
|
||||
insert into `data_dict`(`id`,`createtime`,`updatetime`,`datakey`,`name`,`isvalid`,`description`) values (17,'2020-05-27 16:41:48','2020-05-27 16:42:18','from_others','来源_其他案例',1,'案例库-其他案例目录下的案例来源库');
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for data_dict_item
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `data_dict_item`;
|
||||
CREATE TABLE `data_dict_item` (
|
||||
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
`dictid` bigint(20) NOT NULL COMMENT '字典id值(data_dict表id)',
|
||||
`value` varchar(50) NOT NULL COMMENT '字典value值(组合主键)',
|
||||
`name` varchar(50) NOT NULL COMMENT '字典名字',
|
||||
`sort` int(10) NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `ukey`(`dictId`, `value`)
|
||||
) ENGINE = InnoDB COMMENT='数据字典值集合表';
|
||||
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for content
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `content`;
|
||||
CREATE TABLE `content` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
`type` enum('ppqa','ggqa','design','video','h5','ldhd','others') NOT NULL COMMENT '案例类型[ppqa:品牌全案, ggqa:公关全案, design:创意设计, video:视频动画, h5:技术开发, ldhd:落地活动, others:其他案例]',
|
||||
`isvalid` tinyint(4) DEFAULT '1' COMMENT '是否有效(1:有效,0:无效)',
|
||||
`fromid` int(11) NULL DEFAULT NULL COMMENT '案例来源ID',
|
||||
`title` varchar(100) NOT NULL COMMENT '标题',
|
||||
`desct` varchar(1000) NULL DEFAULT NULL COMMENT '摘要,描述',
|
||||
`viewno` int(11) NULL DEFAULT NULL COMMENT '查看数',
|
||||
`praiseno` int(11) NULL DEFAULT NULL COMMENT '点赞数',
|
||||
`listicon` varchar(200) NULL DEFAULT NULL COMMENT '列表icon图',
|
||||
`qrcode` varchar(200) NULL DEFAULT NULL COMMENT '二维码',
|
||||
`sort` int(11) NULL DEFAULT 0 COMMENT '排序值, 值越大越考前',
|
||||
`url` varchar(500) DEFAULT NULL COMMENT '访问地址',
|
||||
`content` mediumtext COMMENT 'HTML内容,富文本内容存储在这',
|
||||
`content_text` mediumtext COMMENT '纯Text内容,用于存到ES便于搜索',
|
||||
`attachment` json DEFAULT NULL COMMENT '附件',
|
||||
PRIMARY KEY (`ID`),
|
||||
INDEX `idx_title`(`title`),
|
||||
INDEX `idx_sort`(`sort`)
|
||||
) ENGINE = InnoDB COMMENT = '案例库内容表';
|
||||
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for content_images
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `content_images`;
|
||||
CREATE TABLE `content_images` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`cid` bigint(20) NOT NULL COMMENT '内容表ID',
|
||||
`imgurl` varchar(500) NOT NULL COMMENT '图片地址',
|
||||
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`ori_name` varchar(100) DEFAULT NULL COMMENT '原始名称',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB COMMENT = '内容图片集表';
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for content_tags
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `content_tags`;
|
||||
CREATE TABLE `content_tags` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`cid` bigint(20) NOT NULL COMMENT '内容表ID',
|
||||
`tid` bigint(20) NOT NULL COMMENT '标签id(与data_dict_item.id对应)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `ukey_value`(`cid`, `tid`)
|
||||
) ENGINE = InnoDB COMMENT = '内容标签关联表';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for wx_department
|
||||
-- 企业微信部门表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `wx_department`;
|
||||
CREATE TABLE `wx_department` (
|
||||
`id` bigint(20) NOT NULL COMMENT '主键, 部门id',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
`name` varchar(100) NOT NULL COMMENT '部门名称',
|
||||
`parentid` bigint(20) NOT NULL COMMENT '父亲部门id。根部门为1',
|
||||
`order` int(11) DEFAULT NULL COMMENT '在父部门中的排序值',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `ukey_deptid` (`id`)
|
||||
) DEFAULT CHARSET=utf8mb4 COMMENT='企业微信部门表';
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for wx_user
|
||||
-- 微信成员表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `wx_user`;
|
||||
CREATE TABLE `wx_user` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
`userid` varchar(50) NOT NULL COMMENT '成员UserID,对应管理端的帐号,企业内必须唯一',
|
||||
`name` varchar(50) NOT NULL COMMENT '成员名称',
|
||||
`mobile` varchar(25) DEFAULT NULL COMMENT '手机号码',
|
||||
`department` varchar(100) NOT NULL COMMENT '成员所属部门id列表',
|
||||
`position` varchar(100) DEFAULT NULL COMMENT '职位信息',
|
||||
`gender` char(1) DEFAULT '0' COMMENT '性别。0表示未定义,1表示男性,2表示女性',
|
||||
`email` varchar(100) DEFAULT NULL COMMENT '邮箱',
|
||||
`weixinid` varchar(50) DEFAULT NULL COMMENT '微信号',
|
||||
`isleader` varchar(25) DEFAULT NULL COMMENT '上级字段,标识是否为上级',
|
||||
`avatar` varchar(255) DEFAULT NULL COMMENT '头像url。注:如果要获取小图将url最后的”/0”改成”/100”即可',
|
||||
`english_name` varchar(50) DEFAULT NULL COMMENT '英文名',
|
||||
`status` smallint(6) NOT NULL DEFAULT '0' COMMENT '激活状态: 1=已激活,2=已禁用,4=未激活',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `ukey_userid` (`userid`)
|
||||
) DEFAULT CHARSET=utf8mb4 COMMENT='微信成员表';
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Function structure for getChildDeptIds
|
||||
-- 递归查询子部门ID函数
|
||||
-- ----------------------------
|
||||
DROP FUNCTION IF EXISTS getChildDeptIds;
|
||||
DELIMITER $$
|
||||
CREATE FUNCTION `getChildDeptIds`(rootdeptid INT) RETURNS VARCHAR(500) COMMENT '获取子部门ID列表,包含当前id'
|
||||
BEGIN
|
||||
DECLARE sChildList VARCHAR(500);
|
||||
DECLARE sChildTemp VARCHAR(500);
|
||||
SET sChildTemp =CAST(rootdeptid AS CHAR);
|
||||
WHILE sChildTemp IS NOT NULL DO
|
||||
IF (sChildList IS NOT NULL) THEN
|
||||
SET sChildList = CONCAT(sChildList,',',sChildTemp);
|
||||
ELSE
|
||||
SET sChildList = CONCAT(sChildTemp);
|
||||
END IF;
|
||||
SELECT GROUP_CONCAT(deptid) INTO sChildTemp FROM wx_department WHERE FIND_IN_SET(parentid,sChildTemp)>0;
|
||||
END WHILE;
|
||||
RETURN sChildList;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
|
||||
|
||||
186
docs/database/system.sql
Normal file
186
docs/database/system.sql
Normal file
@ -0,0 +1,186 @@
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS `xgl_cases` DEFAULT CHARACTER SET utf8mb4;
|
||||
|
||||
USE `xgl_cases`;
|
||||
|
||||
|
||||
|
||||
|
||||
/*Table structure for table `permission` */
|
||||
DROP TABLE IF EXISTS `permission`;
|
||||
CREATE TABLE `permission` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`permission_id` varchar(20) NOT NULL COMMENT '权限id',
|
||||
`name` varchar(100) NOT NULL COMMENT '权限名称',
|
||||
`description` varchar(255) DEFAULT NULL COMMENT '权限描述',
|
||||
`url` varchar(255) DEFAULT NULL COMMENT '权限访问路径',
|
||||
`perms` varchar(255) DEFAULT NULL COMMENT '权限标识',
|
||||
`parent_id` int(11) DEFAULT NULL COMMENT '父级权限id',
|
||||
`type` int(1) DEFAULT NULL COMMENT '类型 0:目录 1:菜单 2:按钮',
|
||||
`order_num` int(3) DEFAULT '0' COMMENT '排序',
|
||||
`icon` varchar(50) DEFAULT NULL COMMENT '图标',
|
||||
`status` int(1) NOT NULL COMMENT '状态:1有效;2删除',
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`update_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
/*Data for the table `permission` */
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (1,'1','工作台','工作台','/workdest','workdest',0,1,1,'fa fa-home',1,'2017-09-27 21:22:02','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (2,'2','权限管理','权限管理','',NULL,0,0,2,'fa fa-th-list',1,'2017-07-13 15:04:42','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (3,'201','用户管理','用户管理','/users','users',2,1,1,'fa fa-circle-o',1,'2017-07-13 15:05:47','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (4,'20101','列表查询','用户列表查询','/user/list','user:list',3,2,0,NULL,1,'2017-07-13 15:09:24','2017-10-09 05:38:29');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (5,'20102','新增','新增用户','/user/add','user:add',3,2,0,NULL,1,'2017-07-13 15:06:50','2018-02-28 17:58:46');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (6,'20103','编辑','编辑用户','/user/edit','user:edit',3,2,0,NULL,1,'2017-07-13 15:08:03','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (7,'20104','删除','删除用户','/user/delete','user:delete',3,2,0,NULL,1,'2017-07-13 15:08:42','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (8,'20105','批量删除','批量删除用户','/user/batch/delete','user:batchDelete',3,2,0,'',1,'2018-07-11 01:53:09','2018-07-11 01:53:09');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (9,'20106','分配角色','分配角色','/user/assign/role','user:assignRole',3,2,0,NULL,1,'2017-07-13 15:09:24','2017-10-09 05:38:29');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (10,'202','角色管理','角色管理','/roles','roles',2,1,2,'fa fa-circle-o',1,'2017-07-17 14:39:09','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (11,'20201','列表查询','角色列表查询','/role/list','role:list',10,2,0,NULL,1,'2017-10-10 15:31:36','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (12,'20202','新增','新增角色','/role/add','role:add',10,2,0,NULL,1,'2017-07-17 14:39:46','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (13,'20203','编辑','编辑角色','/role/edit','role:edit',10,2,0,NULL,1,'2017-07-17 14:40:15','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (14,'20204','删除','删除角色','/role/delete','role:delete',10,2,0,NULL,1,'2017-07-17 14:40:57','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (15,'20205','批量删除','批量删除角色','/role/batch/delete','role:batchDelete',10,2,0,'',1,'2018-07-10 22:20:43','2018-07-10 22:20:43');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (16,'20206','分配权限','分配权限','/role/assign/permission','role:assignPerms',10,2,0,NULL,1,'2017-09-26 07:33:05','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (17,'203','资源管理','资源管理','/permissions','permissions',2,1,3,'fa fa-circle-o',1,'2017-09-26 07:33:51','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (18,'20301','列表查询','资源列表','/permission/list','permission:list',17,2,0,NULL,1,'2018-07-12 16:25:28','2018-07-12 16:25:33');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (19,'20302','新增','新增资源','/permission/add','permission:add',17,2,0,NULL,1,'2017-09-26 08:06:58','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (20,'20303','编辑','编辑资源','/permission/edit','permission:edit',17,2,0,NULL,1,'2017-09-27 21:29:04','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (21,'20304','删除','删除资源','/permission/delete','permission:delete',17,2,0,NULL,1,'2017-09-27 21:29:50','2018-02-27 10:53:14');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (22,'3','运维管理','运维管理','',NULL,0,0,3,'fa fa-th-list',1,'2018-07-06 15:19:26','2018-07-06 15:19:26');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (23,'301','数据监控','数据监控','/database/monitoring','database',22,1,1,'fa fa-circle-o',1,'2018-07-06 15:19:55','2018-09-12 13:14:48');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (24,'4','系统工具','系统工具','',NULL,0,0,4,'fa fa-th-list',1,'2018-07-06 15:20:38','2018-07-06 15:20:38');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (25,'401','图标工具','图标工具','/icons','icons',24,1,1,'fa fa-circle-o',1,'2018-07-06 15:21:00','2018-07-06 15:21:00');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (28,'5','在线用户','在线用户','/online/users','onlineUsers',2,1,4,'fa fa-circle-o',1,'2018-07-18 21:00:38','2018-07-19 12:47:42');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (29,'501','在线用户查询','在线用户查询','/online/user/list','onlineUser:list',28,2,0,NULL,1,'2018-07-18 21:01:25','2018-07-19 12:48:04');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (30,'502','踢出用户','踢出用户','/online/user/kickout','onlineUser:kickout',28,2,0,NULL,1,'2018-07-18 21:41:54','2018-07-19 12:48:25');
|
||||
insert into `permission`(`id`,`permission_id`,`name`,`description`,`url`,`perms`,`parent_id`,`type`,`order_num`,`icon`,`status`,`create_time`,`update_time`) values (31,'503','批量踢出','批量踢出','/online/user/batch/kickout','onlineUser:batchKickout',28,2,0,'',1,'2018-07-19 12:49:30','2018-07-19 12:49:30');
|
||||
|
||||
|
||||
|
||||
|
||||
/*Table structure for table `role` */
|
||||
DROP TABLE IF EXISTS `role`;
|
||||
CREATE TABLE `role` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`role_id` varchar(20) NOT NULL COMMENT '角色id',
|
||||
`name` varchar(50) NOT NULL COMMENT '角色名称',
|
||||
`description` varchar(255) DEFAULT NULL COMMENT '角色描述',
|
||||
`status` int(1) NOT NULL COMMENT '状态:1有效;2删除',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
/*Data for the table `role` */
|
||||
insert into `role`(`id`,`role_id`,`name`,`description`,`status`,`create_time`,`update_time`) values (1,'1','超级管理员','超级管理员',1,'2017-06-28 20:30:05','2017-06-28 20:30:10');
|
||||
insert into `role`(`id`,`role_id`,`name`,`description`,`status`,`create_time`,`update_time`) values (2,'2','管理员','管理员',1,'2017-06-30 23:35:19','2017-10-11 09:32:33');
|
||||
insert into `role`(`id`,`role_id`,`name`,`description`,`status`,`create_time`,`update_time`) values (3,'3','普通用户','普通用户',1,'2017-06-30 23:35:44','2018-07-13 11:44:06');
|
||||
|
||||
|
||||
|
||||
|
||||
/*Table structure for table `role_permission` */
|
||||
DROP TABLE IF EXISTS `role_permission`;
|
||||
CREATE TABLE `role_permission` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`role_id` varchar(20) NOT NULL COMMENT '角色id',
|
||||
`permission_id` varchar(20) NOT NULL COMMENT '权限id',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
/*Data for the table `role_permission` */
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (1,'1','1');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (2,'1','2');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (3,'1','201');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (4,'1','20101');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (5,'1','20102');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (6,'1','20103');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (7,'1','20104');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (8,'1','20105');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (9,'1','20106');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (10,'1','202');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (11,'1','20201');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (12,'1','20202');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (13,'1','20203');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (14,'1','20204');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (15,'1','20205');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (16,'1','20206');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (17,'1','203');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (18,'1','20301');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (19,'1','20302');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (20,'1','20303');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (21,'1','20304');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (22,'1','5');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (23,'1','501');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (24,'1','502');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (25,'1','503');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (26,'1','3');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (27,'1','301');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (28,'1','4');
|
||||
insert into `role_permission`(`id`,`role_id`,`permission_id`) values (29,'1','401');
|
||||
|
||||
|
||||
|
||||
|
||||
/*Table structure for table `user` */
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` varchar(20) NOT NULL COMMENT '用户id',
|
||||
`username` varchar(50) NOT NULL COMMENT '用户名',
|
||||
`password` varchar(50) NOT NULL,
|
||||
`salt` varchar(128) DEFAULT NULL COMMENT '加密盐值',
|
||||
`email` varchar(50) DEFAULT NULL COMMENT '邮箱',
|
||||
`phone` varchar(50) DEFAULT NULL COMMENT '联系方式',
|
||||
`sex` int(255) DEFAULT NULL COMMENT '年龄:1男2女',
|
||||
`age` int(3) DEFAULT NULL COMMENT '年龄',
|
||||
`status` int(1) NOT NULL COMMENT '用户状态:1有效; 2删除',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
`last_login_time` datetime DEFAULT NULL COMMENT '最后登录时间',
|
||||
PRIMARY KEY (`id`,`user_id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
/*Data for the table `user` */
|
||||
insert into `user`(`id`,`user_id`,`username`,`password`,`salt`,`status`,`create_time`,`update_time`)
|
||||
values (1,'1','admin','64b4f7f481befa153d4be6273a5a9743','8ec2761c3ec31c4100884553abf1221b',1,'2019-12-01 12:00:00','2019-12-01 12:00:00');
|
||||
|
||||
|
||||
|
||||
|
||||
/*Table structure for table `user_role` */
|
||||
DROP TABLE IF EXISTS `user_role`;
|
||||
CREATE TABLE `user_role` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` varchar(20) NOT NULL COMMENT '用户id',
|
||||
`role_id` varchar(20) NOT NULL COMMENT '角色id',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
/*Data for the table `user_role` */
|
||||
insert into `user_role`(`id`,`user_id`,`role_id`) values (1,'1','1');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_log
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_log`;
|
||||
CREATE TABLE `sys_log` (
|
||||
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID, 主键,自增',
|
||||
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`type` int(10) NOT NULL COMMENT '日志类型(1:系统管理;2:登录日志;3:字典管理;4:案例管理)',
|
||||
`operator` varchar(100) DEFAULT NULL COMMENT '操作者',
|
||||
`ipaddr` varchar(150) DEFAULT NULL COMMENT 'IP地址',
|
||||
`description` varchar(255) NOT NULL COMMENT '描述',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB COMMENT='系统日志表';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
docs/document/公司案例库网站构建逻辑.docx
Normal file
BIN
docs/document/公司案例库网站构建逻辑.docx
Normal file
Binary file not shown.
289
pom.xml
Normal file
289
pom.xml
Normal file
@ -0,0 +1,289 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.nbclass</groupId>
|
||||
<artifactId>cases</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<name>cases</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<mapper.starter.version>2.1.5</mapper.starter.version>
|
||||
<pagehelper-spring-boot-starter.version>1.2.13</pagehelper-spring-boot-starter.version>
|
||||
<mybatis-spring-boot-starter.version>2.1.2</mybatis-spring-boot-starter.version>
|
||||
<druid.springboot.version>1.1.22</druid.springboot.version>
|
||||
<fastjson.version>1.2.70</fastjson.version>
|
||||
<commons-fileupload.version>1.4</commons-fileupload.version>
|
||||
<commons-io.version>2.7</commons-io.version>
|
||||
<ognl.version>3.2.14</ognl.version>
|
||||
<shiro-spring.version>1.5.3</shiro-spring.version>
|
||||
<aliyun-java-sdk-core.version>4.5.2</aliyun-java-sdk-core.version>
|
||||
<aliyun-sdk-oss.version>3.9.1</aliyun-sdk-oss.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion><!-- 去掉springboot默认的logback, 使用log4j2 -->
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<!--
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
-->
|
||||
</dependency>
|
||||
<!-- 引入log4j2依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Druid Spring Boot Starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.springboot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--mapper-->
|
||||
<dependency>
|
||||
<groupId>tk.mybatis</groupId>
|
||||
<artifactId>mapper-spring-boot-starter</artifactId>
|
||||
<version>${mapper.starter.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<!-- 这个persistence-api-1.0.jar与Spring Data JPA引入的javax.persistence-api-2.2.jar有冲突 -->
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>persistence-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--pagehelper-->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>${pagehelper-spring-boot-starter.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>${shiro-spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.theborakompanioni</groupId>
|
||||
<artifactId>thymeleaf-extras-shiro</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ognl</groupId>
|
||||
<artifactId>ognl</artifactId>
|
||||
<version>${ognl.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Aliyun SDK -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
<version>${aliyun-java-sdk-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>${aliyun-sdk-oss.version}</version>
|
||||
</dependency>
|
||||
<!-- Aliyun SDK -->
|
||||
|
||||
<!-- 整合 Elasticsearch -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- kindeditor start -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>${commons-fileupload.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.11</version>
|
||||
</dependency>
|
||||
<!-- kindeditor end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 测试用, 配置devtools实现热部署 -->
|
||||
<!--
|
||||
会导致ClassCastException异常
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
<scope>true</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--JavaServer Pages Standard Tag Library,JSP标准标签库-->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--内置tomcat对Jsp支持的依赖,用于编译Jsp-->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>cases</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.mybatis.generator</groupId>
|
||||
<artifactId>mybatis-generator-maven-plugin</artifactId>
|
||||
<version>1.3.7</version>
|
||||
<configuration>
|
||||
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
|
||||
<overwrite>true</overwrite>
|
||||
<verbose>true</verbose>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>tk.mybatis</groupId>
|
||||
<artifactId>mapper-generator</artifactId>
|
||||
<version>1.1.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
28
src/main/java/com/nbclass/CasesBootApplication.java
Normal file
28
src/main/java/com/nbclass/CasesBootApplication.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.nbclass;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
import tk.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2019年3月31日 下午7:21:36
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@MapperScan(basePackages = "com.nbclass.**.mapper")
|
||||
public class CasesBootApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CasesBootApplication.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(CasesBootApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
39
src/main/java/com/nbclass/Interceptor/InterceptorConfig.java
Normal file
39
src/main/java/com/nbclass/Interceptor/InterceptorConfig.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.nbclass.Interceptor;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @title: InterceptorConfig
|
||||
* @Author gjt
|
||||
* @Date: 2020-12-21
|
||||
* @Description:
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer{
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(jwtInterceptor())
|
||||
.addPathPatterns("/comment/**")// 拦截前端接口所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录
|
||||
//排除登录接口
|
||||
.excludePathPatterns("/wx/**");
|
||||
|
||||
//注册TestInterceptor拦截器
|
||||
// InterceptorRegistration registration = registry.addInterceptor(jwtInterceptor());
|
||||
// registration.addPathPatterns("/**"); //添加拦截路径
|
||||
// registration.excludePathPatterns( //添加不拦截路径
|
||||
// "/**/*.html", //html静态资源
|
||||
// "/**/*.js", //js静态资源
|
||||
// "/**/*.css", //css静态资源
|
||||
// "/**/*.woff",
|
||||
// "/**/*.ttf",
|
||||
// "/swagger-ui.html"
|
||||
// );
|
||||
}
|
||||
@Bean
|
||||
public JWTInterceptor jwtInterceptor() {
|
||||
return new JWTInterceptor();
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/nbclass/Interceptor/JWTInterceptor.java
Normal file
44
src/main/java/com/nbclass/Interceptor/JWTInterceptor.java
Normal file
@ -0,0 +1,44 @@
|
||||
package com.nbclass.Interceptor;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.auth0.jwt.exceptions.AlgorithmMismatchException;
|
||||
import com.auth0.jwt.exceptions.SignatureVerificationException;
|
||||
import com.auth0.jwt.exceptions.TokenExpiredException;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.util.JWTUtils;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
*/
|
||||
@Slf4j
|
||||
public class JWTInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
String token = request.getHeader("token");
|
||||
if(StringUtils.isEmpty(token)){
|
||||
throw new ParameterException("token不能为空");
|
||||
}
|
||||
try {
|
||||
Claims claims = JWTUtils.parseJWT(token);
|
||||
//获取token的签发时间
|
||||
long issuedAt = claims.getIssuedAt().getTime();
|
||||
//获取token的过期时间
|
||||
long expiration = claims.getExpiration().getTime();
|
||||
if(expiration < issuedAt){
|
||||
throw new ParameterException("token已过期!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("token无效! 错误 ->", e);
|
||||
throw new ParameterException("token无效!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
60
src/main/java/com/nbclass/activity/constant/Const.java
Normal file
60
src/main/java/com/nbclass/activity/constant/Const.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.nbclass.activity.constant;
|
||||
|
||||
import com.nbclass.util.CommonUtils;
|
||||
|
||||
/**
|
||||
* 项目常量
|
||||
* @author Leon
|
||||
* @datetime 2019年4月11日 上午11:22:59
|
||||
*/
|
||||
public class Const {
|
||||
|
||||
/**
|
||||
* 当前期数
|
||||
*/
|
||||
public volatile static Integer period = 1;
|
||||
|
||||
/**
|
||||
* 测试环境appid
|
||||
*/
|
||||
public static final String test_appid = "2018050300000578";
|
||||
/**
|
||||
* 生产环境appid
|
||||
*/
|
||||
public static final String product_appid = "2018081400000135";
|
||||
|
||||
/**
|
||||
* 测试环境
|
||||
*/
|
||||
public static final String test_client_id = "P_XGLBDHB";
|
||||
public static final String test_client_secret = "tX6Vwv72";
|
||||
public static final String test_api_host = "https://test-api.pingan.com.cn:20443";
|
||||
|
||||
/**
|
||||
* 正式环境
|
||||
*/
|
||||
public static final String product_client_id = "P_XGLKXSW";
|
||||
public static final String product_client_secret = " E1Fhw56u";
|
||||
public static final String product_api_host = "http://api.pingan.com.cn";
|
||||
|
||||
/**
|
||||
* 活动结束时间
|
||||
*/
|
||||
public static long hd_endtime = CommonUtils.getSimpleDate("2020-03-31 23:59:59").getTime();
|
||||
|
||||
/**
|
||||
* 信广龙企业微信接口
|
||||
*/
|
||||
public static final String QYWX_API_DOMAIN = "http://wx.szxgl.cn/qywx";
|
||||
|
||||
/**
|
||||
* 支持的上传图片后缀
|
||||
*/
|
||||
public static final String UPLOAD_IMAGE_SUFFIX = ".gif,.jpg,.jpeg,.png,.bmp";
|
||||
|
||||
/**
|
||||
* 支持的上传视频后缀
|
||||
*/
|
||||
public static final String UPLOAD_VIDEO_SUFFIX = ".mp4,.mov,.mkv,.rmvb,.rm,.avi,.flv";
|
||||
|
||||
}
|
||||
@ -0,0 +1,492 @@
|
||||
package com.nbclass.activity.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.nbclass.activity.model.*;
|
||||
import com.nbclass.activity.service.DataDictService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.JWTUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.enums.ContentType;
|
||||
import com.nbclass.activity.service.ContentService;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.system.model.SysLog;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.model.enums.SysLogType;
|
||||
import com.nbclass.system.service.SysLogService;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
import com.nbclass.util.PageUtil;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.vo.base.PageResultVo;
|
||||
import com.nbclass.vo.base.Result;
|
||||
|
||||
/**
|
||||
* 案例内容
|
||||
* @author Leon
|
||||
* @datetime 2020年5月28日 下午4:43:17
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/console/content")
|
||||
public class ContentController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ContentService service;
|
||||
|
||||
@Resource
|
||||
private SysLogService sysLogService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private DataDictService dataDictService;
|
||||
|
||||
/**
|
||||
* 案例页面
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/indexPage")
|
||||
public String indexPage(Model model){
|
||||
return "content/list2";
|
||||
}
|
||||
|
||||
/**
|
||||
* 案例页面
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-application")
|
||||
public String application(Model model){
|
||||
return "content/application";
|
||||
}
|
||||
|
||||
/**
|
||||
* i技术开发案例页面
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-h5")
|
||||
public String h5Page(Model model){
|
||||
model.addAttribute("caseType", ContentType.h5.key());
|
||||
return "content/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i创意设计案例页面
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-design")
|
||||
public String designPage(Model model){
|
||||
model.addAttribute("caseType", ContentType.design.key());
|
||||
// return "content/list";
|
||||
return "content-editor/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i视频动画案例页面
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-video")
|
||||
public String videoPage(Model model){
|
||||
model.addAttribute("caseType", ContentType.video.key());
|
||||
return "content/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i品牌全案 - 富文本编辑器形式
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-ppqa")
|
||||
public String ppqaPage(Model model){
|
||||
model.addAttribute("caseType", ContentType.ppqa.key());
|
||||
return "content-editor/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i公关全案 - 富文本编辑器形式
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-ggqa")
|
||||
public String ggqaPage(Model model){
|
||||
model.addAttribute("caseType", ContentType.ggqa.key());
|
||||
return "content-editor/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i落地活动 - 富文本编辑器形式
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-ldhd")
|
||||
public String ldhdPage(Model model){
|
||||
model.addAttribute("caseType", ContentType.ldhd.key());
|
||||
return "content-editor/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i其他案例 - 富文本编辑器形式
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index-others")
|
||||
public String othersPage(Model model){
|
||||
model.addAttribute("caseType", ContentType.others.key());
|
||||
return "content-editor/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i编辑页面
|
||||
* @param model
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/edit")
|
||||
public String editPage(Model model, String caseType, Long id){
|
||||
Content entity = new Content();
|
||||
if(id!=null && id>0)entity=service.findById(id);
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(entity);
|
||||
model.addAllAttributes(obj);
|
||||
model.addAttribute("caseType", caseType);
|
||||
return "content/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* i编辑页面
|
||||
* @param model
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/edit2")
|
||||
public String editPage2(Model model, String caseType, Long id,Long applicationId,Integer count){
|
||||
Content entity = new Content();
|
||||
if(id!=null && id>0)entity=service.findById(id);
|
||||
if(count!=null) entity.setCount(count);
|
||||
if(applicationId!=null) entity.setApplicationId(applicationId);
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(entity);
|
||||
model.addAllAttributes(obj);
|
||||
model.addAttribute("caseType", caseType);
|
||||
return "content/edit2";
|
||||
}
|
||||
|
||||
/**
|
||||
* i富文本编辑器的编辑页面
|
||||
* @param model
|
||||
* @param caseType
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/edit-editor")
|
||||
public String editEditorPage(Model model, String caseType, Long id){
|
||||
Content entity = new Content();
|
||||
if(id!=null && id>0)entity=service.findById(id);
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(entity);
|
||||
model.addAllAttributes(obj);
|
||||
model.addAttribute("caseType", caseType);
|
||||
return "content-editor/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* i查询数据列表
|
||||
* @param entity
|
||||
* @param limit
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public PageResultVo getList(Content entity, Integer limit, Integer offset){
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<Content> userList = service.getList(entity);
|
||||
PageInfo<Content> pages = new PageInfo<>(userList);
|
||||
return ResultUtil.table(userList,pages.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* i查询数据列表
|
||||
* @param entity
|
||||
* @param limit
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list2")
|
||||
@ResponseBody
|
||||
public PageResultVo getList2(Content entity, Integer limit, Integer offset,HttpServletRequest request){
|
||||
User loginUser = getLoginUser();
|
||||
User user = userService.selectByUsername(loginUser.getUsername());
|
||||
if(!user.getUsername().contains("admin")){
|
||||
entity.setUserId(Long.parseLong(user.getId().toString()));
|
||||
}
|
||||
List<String> list = Arrays.asList(entity.getTagLists());
|
||||
String[] strings = list.stream().filter(String -> !String.isEmpty()).toArray(String[]::new);
|
||||
if(strings.length == 0){
|
||||
entity.setTagLists(null);
|
||||
}else {
|
||||
entity.setTagLists(strings);
|
||||
entity.setCount(strings.length);
|
||||
}
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<Content> userList = service.getList2(entity);
|
||||
PageInfo<Content> pages = new PageInfo<>(userList);
|
||||
return ResultUtil.table(userList,pages.getTotal());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* i添加或修改数据
|
||||
* @param entity
|
||||
*/
|
||||
@PostMapping("/merge")
|
||||
@ResponseBody
|
||||
public Result merge(Content entity){
|
||||
if(StringUtils.isNotBlank(entity.getImages())) {
|
||||
// json数据去除多余的引号,否则存数据库报错
|
||||
String imgList = entity.getImages();
|
||||
imgList = imgList.replace("\"{", "{").replace("}\"", "}").replace("\\", "");
|
||||
entity.setImages(imgList);
|
||||
}
|
||||
String type = "";
|
||||
if(entity.getTagLists().length != 0){
|
||||
for (String tagList : entity.getTagLists()) {
|
||||
if(tagList.equals("106") || tagList.equals("107")
|
||||
|| tagList.equals("108") || tagList.equals("109")
|
||||
|| tagList.equals("110") || tagList.equals("111")
|
||||
|| tagList.equals("112")){
|
||||
type = ContentType.getNameByCode(tagList);
|
||||
}
|
||||
}
|
||||
}
|
||||
String desc = null;
|
||||
if(entity.getId()!=null && entity.getId()>0){
|
||||
service.update(entity);
|
||||
if(entity.getApplicationId()!=null){
|
||||
//更新审核申请单状态
|
||||
service.updateApplicationStatus(entity.getApplicationId());
|
||||
}
|
||||
desc="修改案例,案例类型:"+ContentType.getNameByCode(type)+",案例ID:"+entity.getId()+",案例标题:"+entity.getTitle();
|
||||
}else{
|
||||
User loginUser = getLoginUser();
|
||||
User user = userService.selectByUsername(loginUser.getUsername());
|
||||
entity.setUserId(Long.parseLong(user.getId().toString()));
|
||||
service.add(entity);
|
||||
//标签关联案例
|
||||
String[] tagList = entity.getTagLists();
|
||||
for (String s : tagList) {
|
||||
ContentTags contentTags = new ContentTags();
|
||||
contentTags.setCid(entity.getId());
|
||||
contentTags.setTid(Long.parseLong(s));
|
||||
service.addContentTags(contentTags);
|
||||
}
|
||||
desc="添加案例,案例类型:"+ContentType.getNameByCode(type)+",案例ID:"+entity.getId()+",案例标题:"+entity.getTitle();
|
||||
}
|
||||
User user = getLoginUser();
|
||||
sysLogService.add(new SysLog(SysLogType.cases.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), desc));
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**删除用户*/
|
||||
@PostMapping("/delete")
|
||||
@ResponseBody
|
||||
public Result delete(String ids) {
|
||||
List<Long> IdList = CommonUtils.toLongList(ids);
|
||||
service.delete(IdList);
|
||||
//取消案例关联标签的关系
|
||||
service.deleteContentTags(IdList);
|
||||
User user = getLoginUser();
|
||||
sysLogService.add(new SysLog(SysLogType.cases.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), "删除案例,ids:"+ids));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步MySQL数据到ES
|
||||
* @param ids 如果有值,同步指定id,如果没有值,同步全部
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/syncEsData")
|
||||
@ResponseBody
|
||||
public Result syncEsData(Content entity, @RequestParam(defaultValue="false")Boolean isReBuild) {
|
||||
long total = service.syncEsData(entity, isReBuild);
|
||||
User user = getLoginUser();
|
||||
String type = "";
|
||||
if(entity.getTagLists().length != 0){
|
||||
for (String tagList : entity.getTagLists()) {
|
||||
if(tagList.equals("106") || tagList.equals("107")
|
||||
|| tagList.equals("108") || tagList.equals("109")
|
||||
|| tagList.equals("110") || tagList.equals("111")
|
||||
|| tagList.equals("112")){
|
||||
type = ContentType.getNameByCode(tagList);
|
||||
}
|
||||
}
|
||||
}
|
||||
sysLogService.add(new SysLog(SysLogType.cases.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(),
|
||||
"同步案例到ElasticSearch,案例类型:"+ContentType.getNameByCode(type)+",是否重建:"+isReBuild+",受影响的记录数:"+total));
|
||||
return Result.success(total);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询案例标题、评论数和点赞数
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getCaseTitle")
|
||||
@ResponseBody
|
||||
public Result getCaseTitle(Integer page,Integer pageSize){
|
||||
PageInfo<Content> list = service.getCaseTitle(page,pageSize);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义标签列表
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getOtherLabels")
|
||||
@ResponseBody
|
||||
public Result getOtherLabels(Integer page,Integer pageSize){
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<DataDictItem> list = service.getOtherLabels();
|
||||
return Result.success(new PageInfo<>(list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加案例评分
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveScore")
|
||||
@ResponseBody
|
||||
public Result saveScore(HttpServletRequest request,Long contentId,Double score){
|
||||
String token = request.getHeader("token");
|
||||
String Id = JWTUtils.getUserId(token);
|
||||
Long userId = Long.parseLong(Id);
|
||||
//查看用户是否已经打过分
|
||||
int result = service.getScore(userId,contentId);
|
||||
if(result > 0 ) throw new ParameterException("请勿重复打分!");
|
||||
service.saveScore(userId,contentId,score);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据案例id查询案例详情
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getEditContent")
|
||||
@ResponseBody
|
||||
public Result getEditContent(Long contentId){
|
||||
Content content = service.getEditContent(contentId);
|
||||
return Result.success(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交审核申请单
|
||||
* @param application
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveApplication")
|
||||
@ResponseBody
|
||||
public Result saveApplication(Application application){
|
||||
//查询案例是否已提交过审核
|
||||
int result = service.getApplicationCount(application.getContentId());
|
||||
if(result > 0 ) throw new ParameterException("请勿重复提交审核!");
|
||||
User loginUser = getLoginUser();
|
||||
User user = userService.selectByUsername(loginUser.getUsername());
|
||||
application.setUserId(Long.parseLong(user.getId().toString()));
|
||||
//根据userId获取微信用户信息
|
||||
WxUser wxUser = service.getQyWxUser(user.getUsername());
|
||||
//根据部门id获取用户领导
|
||||
List<Check> checks = service.getUserLeader(wxUser.getDepartment());
|
||||
application.setChecks(checks);
|
||||
//添加审核申请单
|
||||
service.saveApplication(application);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回审核申请单
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteApplication")
|
||||
@ResponseBody
|
||||
public Result deleteApplication(Long applicationId){
|
||||
//删除案例审核申请
|
||||
service.deleteApplication(applicationId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取审核列表
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getContentApplication")
|
||||
@ResponseBody
|
||||
public PageResultVo getContentApplication(Content entity,Integer limit, Integer offset){
|
||||
User loginUser = getLoginUser();
|
||||
User user = userService.selectByUsername(loginUser.getUsername());
|
||||
entity.setUserId(Long.parseLong(user.getId().toString()));
|
||||
List<String> list = Arrays.asList(entity.getTagLists());
|
||||
String[] strings = list.stream().filter(String -> !String.isEmpty()).toArray(String[]::new);
|
||||
if(strings.length == 0){
|
||||
entity.setTagLists(null);
|
||||
}else {
|
||||
entity.setTagLists(strings);
|
||||
entity.setCount(strings.length);
|
||||
}
|
||||
PageHelper.startPage(limit,offset);
|
||||
List<Content> list2 = service.getContentApplication(entity);
|
||||
PageInfo<Content> pageInfo = new PageInfo<>(list2);
|
||||
return ResultUtil.table(list2,pageInfo.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核案例
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updateApplication")
|
||||
@ResponseBody
|
||||
public Result updateApplication(Check check){
|
||||
User loginUser = getLoginUser();
|
||||
User user = userService.selectByUsername(loginUser.getUsername());
|
||||
service.updateApplication(check,Long.parseLong(user.getId().toString()));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下线案例
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteRelease")
|
||||
@ResponseBody
|
||||
public Result deleteRelease(Long contentId){
|
||||
service.deleteRelease(contentId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,244 @@
|
||||
package com.nbclass.activity.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.nbclass.activity.mapper.DataDictMapper;
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import com.nbclass.activity.service.DataDictService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.system.model.SysLog;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.model.enums.SysLogType;
|
||||
import com.nbclass.system.service.SysLogService;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
import com.nbclass.util.PageUtil;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.vo.base.PageResultVo;
|
||||
import com.nbclass.vo.base.Result;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
* @author Leon
|
||||
* @datetime 2020年5月28日 下午3:27:43
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/console/datadict")
|
||||
public class DataDictController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private DataDictService service;
|
||||
|
||||
@Resource
|
||||
private SysLogService sysLogService;
|
||||
|
||||
@Resource
|
||||
private DataDictMapper dataDictMapper;
|
||||
|
||||
/**
|
||||
* 列表页面
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index")
|
||||
public String indexPage(){
|
||||
return "data_dict/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面
|
||||
* @param model
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/edit")
|
||||
public String editPage(Model model, Long id){
|
||||
DataDict entity = new DataDict();
|
||||
if(id!=null && id>0)entity=service.findById(id);
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(entity);
|
||||
model.addAllAttributes(obj);
|
||||
return "data_dict/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 报名用户信息列表
|
||||
* @param entity
|
||||
* @param limit
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public PageResultVo getList(DataDict entity, Integer limit, Integer offset){
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<DataDict> userList = service.getList(entity);
|
||||
PageInfo<DataDict> pages = new PageInfo<>(userList);
|
||||
return ResultUtil.table(userList,pages.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典ID查询子项列表
|
||||
* @param entity
|
||||
* @param limit
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getItemList")
|
||||
@ResponseBody
|
||||
public PageResultVo getItemList(DataDictItem entity, Integer limit, Integer offset){
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<DataDictItem> userList = service.getItemList(entity);
|
||||
PageInfo<DataDictItem> pages = new PageInfo<>(userList);
|
||||
return ResultUtil.table(userList,pages.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* i添加或修改记录
|
||||
* @param entity
|
||||
*/
|
||||
@PostMapping("/merge")
|
||||
@ResponseBody
|
||||
public Result merge(DataDict entity){
|
||||
String desc = null;
|
||||
if(entity.getId()!=null && entity.getId()>0){
|
||||
service.update(entity);
|
||||
desc = "修改数据字典,内容为:" + JSON.toJSONString(entity);
|
||||
}else{
|
||||
int result = dataDictMapper.getDataDicName(entity.getName());
|
||||
if(result > 0 ) throw new ParameterException("该字典已存在!");
|
||||
service.add(entity);
|
||||
desc = "添加数据字典,内容为:" + JSON.toJSONString(entity);
|
||||
}
|
||||
User user = getLoginUser();
|
||||
sysLogService.add(new SysLog(SysLogType.dict.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), desc));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**删除记录*/
|
||||
@PostMapping("/delete")
|
||||
@ResponseBody
|
||||
public Result delete(String ids) {
|
||||
List<Long> IdList = CommonUtils.toLongList(ids);
|
||||
service.delete(IdList);
|
||||
User user = getLoginUser();
|
||||
sysLogService.add(new SysLog(SysLogType.dict.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), "删除数据字典,ids:"+ids));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典key获取案例标签列表
|
||||
* @param dictKey
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("getTagSelect")
|
||||
@ResponseBody
|
||||
public Result getTagSelect(String dictKey){
|
||||
if(StringUtils.isBlank(dictKey)) {
|
||||
throw new ParameterException("参数不能为空");
|
||||
}
|
||||
try {
|
||||
List<DataDictItem> obj = service.getItemsByKey(dictKey);
|
||||
return Result.success(obj);
|
||||
} catch (Exception e) {
|
||||
logger.error("getTagSelect异常", e);
|
||||
return Result.error("获取数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签下拉联想获取数据
|
||||
* @param tags
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping("/getTags")
|
||||
public JSONArray getCategoryTrees(String dictKey, String tags){
|
||||
// if(StringUtils.isBlank(dictKey)) {
|
||||
// throw new ParameterException("参数不能为空");
|
||||
// }
|
||||
JSONArray result = new JSONArray();
|
||||
//List<DataDictItem> list = service.getItemsByKey(dictKey);
|
||||
List<DataDictItem> list = service.getItemsByKey("other_labels");
|
||||
for (DataDictItem entity : list) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("id", entity.getId());
|
||||
obj.put("value", entity.getName());
|
||||
result.add(obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据字典key获取案例来源列表
|
||||
* @param dictKey
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("getCaseFromSelect")
|
||||
@ResponseBody
|
||||
public Result getCaseFromSelect(String dictKey){
|
||||
if(StringUtils.isBlank(dictKey)) {
|
||||
throw new ParameterException("参数不能为空");
|
||||
}
|
||||
try {
|
||||
List<DataDictItem> obj = service.getItemsByKey(dictKey);
|
||||
return Result.success(obj);
|
||||
} catch (Exception e) {
|
||||
logger.error("getCaseFromSelect异常", e);
|
||||
return Result.error("获取数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加或修改字典子项
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/mergeDataDictItem")
|
||||
@ResponseBody
|
||||
public Result mergeDataDictItem(DataDictItem entity){
|
||||
service.mergeDataDictItem(entity);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典子项
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteDataDictItem")
|
||||
@ResponseBody
|
||||
public Result deleteDataDictItem(Long id){
|
||||
service.deleteDataDictItem(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDropDownBox")
|
||||
@ResponseBody
|
||||
public Result getDropDownBox(){
|
||||
List<ContentTags> list = service.getDropDownBox();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
package com.nbclass.activity.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.activity.constant.Const;
|
||||
import com.nbclass.aliyun.sdk.AliyunOSSUtils;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
import com.nbclass.vo.base.Result;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 阿里云OSS上传工具
|
||||
* @author Leon
|
||||
* @datetime 2020年5月27日 下午6:51:55
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/console/tool/oss")
|
||||
public class OssUploadController extends BaseController{
|
||||
|
||||
/**
|
||||
* i上传文件到阿里云OSS
|
||||
* @param file
|
||||
* @param category 文件类别【icon:案例列表icon图,attachment:案例附件,image:案例正文图集,video:视频】
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/uploadFile")
|
||||
public Result fileUploadTest(@RequestParam(required=false, value="file")MultipartFile file, String caseType, String category){
|
||||
if(file==null || file.isEmpty()){
|
||||
throw new ParameterException("请选择文件");
|
||||
}
|
||||
/*if(StringUtils.isBlank(caseType)) {
|
||||
throw new ParameterException("案例类型不能为空");
|
||||
}else if(!Arrays.<String> asList("ppqa,ggqa,design,video,h5,ldhd,others".split(",")).contains(caseType)) {
|
||||
throw new ParameterException("案例类型参数有误");
|
||||
}*/
|
||||
if(StringUtils.isBlank(category)) {
|
||||
throw new ParameterException("文件类别不能为空");
|
||||
}
|
||||
category = category.toLowerCase().trim();
|
||||
if(!Arrays.<String> asList("icon,attachment,image,video".split(",")).contains(category)) {
|
||||
throw new ParameterException("文件类别参数有误");
|
||||
}
|
||||
try {
|
||||
String suffix = "", ori_name = file.getOriginalFilename();
|
||||
if(StringUtils.isNotBlank(ori_name)){
|
||||
suffix = ori_name.substring(ori_name.lastIndexOf("."), ori_name.length());
|
||||
suffix = suffix.toLowerCase();
|
||||
}
|
||||
if(("icon".equals(category)||"image".equals(category))
|
||||
&& !Arrays.<String> asList(Const.UPLOAD_IMAGE_SUFFIX.split(",")).contains(suffix)) {
|
||||
throw new ParameterException("请上传正确的图片");
|
||||
}
|
||||
|
||||
if("video".equals(category) && !Arrays.<String> asList(Const.UPLOAD_VIDEO_SUFFIX.split(",")).contains(suffix)) {
|
||||
throw new ParameterException("请上传正确的视频");
|
||||
}
|
||||
|
||||
String daydir = CommonUtils.getSimpleDate(new Date(), "yyyyMM");
|
||||
if("icon".equals(category)) { // icon图上传一年1个目录
|
||||
daydir = CommonUtils.getSimpleDate(new Date(), "yyyy");
|
||||
}else if("video".equals(category)) { // 视频也是按一年1个目录
|
||||
daydir = CommonUtils.getSimpleDate(new Date(), "yyyy");
|
||||
}
|
||||
|
||||
String filename = CommonUtils.getSimpleDate(new Date(), "yyyyMMddHHmmss")+"_"+CommonUtils.getCode(5)+suffix;
|
||||
// 组成的文件key eg. /casetype-h5/icons/xxx.jpg
|
||||
String url = AliyunOSSUtils.uploadBytes("casetype-"+caseType+"/"+category+"s"+"/"+daydir, filename, file.getBytes());
|
||||
JSONObject fileObj = new JSONObject();
|
||||
fileObj.put("url", url);
|
||||
fileObj.put("ori_name", ori_name);
|
||||
return Result.success(fileObj);
|
||||
} catch (IOException e) {
|
||||
log.error("上传到OSS文件异常", e);
|
||||
return Result.error(e.getMessage()!=null ? e.getMessage() :"上传文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
package com.nbclass.activity.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.system.model.SysLog;
|
||||
import com.nbclass.system.service.SysLogService;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
import com.nbclass.util.PageUtil;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.vo.base.PageResultVo;
|
||||
|
||||
/**
|
||||
* i系统日志
|
||||
* @author Leon
|
||||
* @datetime 2020年6月3日 下午5:28:24
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/console/syslog")
|
||||
public class SysLogController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private SysLogService service;
|
||||
|
||||
/**
|
||||
* i查询列表页面
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/index")
|
||||
public String indexPage(){
|
||||
return "syslog/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* i查询数据列表
|
||||
* @param entity
|
||||
* @param limit
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public PageResultVo getList(SysLog entity, Integer limit, Integer offset){
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<SysLog> userList = service.getList(entity);
|
||||
PageInfo<SysLog> pages = new PageInfo<>(userList);
|
||||
return ResultUtil.table(userList,pages.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* i删除数据
|
||||
* @param ids
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@ResponseBody
|
||||
public void delete(String ids) {
|
||||
List<Long> IdList = CommonUtils.toLongList(ids);
|
||||
service.delete(IdList);
|
||||
outPrint();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
package com.nbclass.activity.controller.casesfirst;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.*;
|
||||
import com.nbclass.activity.service.CaseTypeService;
|
||||
import com.nbclass.vo.base.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 案例web前台
|
||||
* @author gao
|
||||
* @datetime 2021年10月12日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/caseType")
|
||||
public class CaseTypeController {
|
||||
|
||||
@Autowired
|
||||
private CaseTypeService caseTypeService;
|
||||
|
||||
/**
|
||||
* 数据字典(案例类型、案例用途、创意形式、节日事件)列表查询
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getTypeCase")
|
||||
public Result getTypeCase(Integer dictId){
|
||||
List<DataDictItem> list = caseTypeService.getTypeCase(dictId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典值类型列表查询
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDictionariesType")
|
||||
public Result getDictionariesType(){
|
||||
List<DataDict> list = caseTypeService.getDictionariesType();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 案例库列表
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getListCase")
|
||||
public Result getListCase(Integer page,Integer pageSize){
|
||||
PageInfo<Content> list = caseTypeService.getListCase(page,pageSize);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 案例搜索框
|
||||
* @param parameter 任意参数(案例标签,案例标题,案例编号)
|
||||
* @param dictItemId 案例类型id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getSearchCase")
|
||||
public Result getSearchCase(String parameter,Integer dictItemId,Integer page,Integer pageSize){
|
||||
PageInfo<Content> list = caseTypeService.getSearchCase(parameter,dictItemId,page,pageSize);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取案例标签
|
||||
* @param contentId 案例id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getContentTags")
|
||||
public Result getContentTags(Integer contentId){
|
||||
ContentTags contentTags = caseTypeService.getContentTags(contentId);
|
||||
return Result.success(contentTags);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,342 @@
|
||||
package com.nbclass.activity.controller.casesfirst;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.*;
|
||||
import com.nbclass.activity.service.CommentService;
|
||||
import com.nbclass.activity.service.ContentService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.util.JWTUtils;
|
||||
import com.nbclass.vo.base.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论api
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/comment")
|
||||
public class CommentController {
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
|
||||
@Autowired
|
||||
private ContentService contentService;
|
||||
|
||||
/**
|
||||
* 案例详情和评论列表
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getComment")
|
||||
public Result getComment(HttpServletRequest request,Long contentId){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
Content content = commentService.getComment(contentId,Long.parseLong(userId));
|
||||
return Result.success(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论回复列表
|
||||
* @param request
|
||||
* @param commentId 评论id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getCommentReplyList")
|
||||
public Result getCommentReplyList(HttpServletRequest request,Long commentId){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
Comment comment = commentService.getCommentReplyList(commentId,Long.parseLong(userId));
|
||||
return Result.success(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户发布信息
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveComment")
|
||||
public Result saveComment(Comment comment,HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
comment.setUserId(Long.parseLong(userId));
|
||||
commentService.saveComment(comment);
|
||||
//更新案例总评论数
|
||||
contentService.updateComments(comment.getContentId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加评论点赞
|
||||
* @param commentId 评论Id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updatePraiseNo")
|
||||
public Result updatePraiseNo(Long commentId, HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
//根据评论id获取被点赞人Id
|
||||
Comment comment = commentService.getCommentUserId(commentId);
|
||||
System.out.println(comment);
|
||||
Praise praise = new Praise();
|
||||
praise.setCommentId(commentId);
|
||||
praise.setPraiseId(Long.parseLong(userId));
|
||||
praise.setUserId(comment.getUserId());
|
||||
commentService.savePraiseNo(praise);
|
||||
//评论总数加1
|
||||
commentService.updatePraiseno(commentId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消评论点赞
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deletePraise")
|
||||
public Result deletePraise(Long commentId,HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
commentService.deletePraise(commentId,Long.parseLong(userId));
|
||||
//总点赞数减一
|
||||
commentService.updatePraiseNoONE(commentId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加案例点赞
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updateContentPraiseNo")
|
||||
public Result updateContentPraiseNo(Long contentId){
|
||||
commentService.updateContentPraiseNo(contentId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户回复
|
||||
* @param comment
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveUserReply")
|
||||
public Result saveUserReply(Comment comment,HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
comment.setReplyId(Long.parseLong(userId));
|
||||
commentService.saveUserReply(comment);
|
||||
//评论总回复数加一
|
||||
commentService.updateReplyNumberONE(comment.getCommentId());
|
||||
//更新案例总评论数
|
||||
contentService.updateComments(comment.getContentId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户举报
|
||||
* @param report
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveReport")
|
||||
public Result saveReport(Report report,HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
report.setReportId(Long.parseLong(userId));
|
||||
commentService.saveReport(report);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 举报列表获取
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getReport")
|
||||
public Result getReport(Integer page,Integer pageSize,HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<Report> list = commentService.getReport(page,pageSize,userId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加标签、索引反馈日志
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveLabelLogger")
|
||||
public Result saveLabelLogger(LabelLogger labelLogger,HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
labelLogger.setUserId(Long.parseLong(userId));
|
||||
commentService.saveLabelLogger(labelLogger);
|
||||
//案例索引标签反馈次数+1
|
||||
contentService.updateLabelFeedback(labelLogger.getContentId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签、索引反馈日志列表
|
||||
* @param request
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getLabelLogger")
|
||||
public Result getLabelLogger(HttpServletRequest request,Integer page,Integer pageSize){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<LabelLogger> list = commentService.getLabelLogger(page,pageSize,Long.parseLong(userId));
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建文件夹
|
||||
* @param favoritesFolder
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveFavorites")
|
||||
public Result saveFavorites(FavoritesFolder favoritesFolder, HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
//判断文件夹是否重名
|
||||
int result = commentService.getFavoritesName(favoritesFolder.getName());
|
||||
if(result > 0){
|
||||
throw new ParameterException("文件夹已存在!");
|
||||
}
|
||||
favoritesFolder.setUserId(Long.parseLong(userId));
|
||||
commentService.saveFavorites(favoritesFolder);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 案例详情的文件夹列表
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserFolder")
|
||||
public Result getUserFolder(HttpServletRequest request,Integer page,Integer pageSize,Long commentId){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<FavoritesFolder> list = commentService.getUserFolder(Long.parseLong(userId),page,pageSize,commentId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏案例到文件夹中
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveFolder")
|
||||
public Result saveFolder(Long folderId,Long contentId){
|
||||
//判断该文件夹是否已被收藏
|
||||
int result = commentService.getFolderExistence(folderId,contentId);
|
||||
if(result > 0 ){
|
||||
throw new ParameterException("该文件夹已被收藏!");
|
||||
}
|
||||
//收藏案例到文件夹中
|
||||
commentService.saveFolder(folderId,contentId);
|
||||
//添加收藏总数
|
||||
commentService.saveFolderTotal(folderId);
|
||||
//更新案例的收藏总数+1
|
||||
commentService.updateCollectionNumber(contentId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消文件夹中的案例收藏
|
||||
* @param folderId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteFolderResources")
|
||||
public Result deleteFolderResources(Long folderId,Long contentId){
|
||||
commentService.deleteFolderResources(folderId,contentId);
|
||||
//更新案例的收藏总数-1
|
||||
commentService.updateCollectionNumberReduce(contentId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户文件夹列表
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserFolderList")
|
||||
public Result getUserFolderList(HttpServletRequest request,Integer page,Integer pageSize){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<FavoritesFolder> list = commentService.getUserFolderList(Long.parseLong(userId),page,pageSize);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的收藏
|
||||
* @param request
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getMyCollection")
|
||||
public Result getMyCollection(HttpServletRequest request,Integer page,Integer pageSize,Long folderId){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<Content> list = commentService.getMyCollection(Long.parseLong(userId),page,pageSize,folderId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人中心回复列表
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getReplyList")
|
||||
public Result getReplyList(HttpServletRequest request,Integer page,Integer pageSize){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<Comment> list = commentService.getReplyList(Long.parseLong(userId),page,pageSize);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞列表
|
||||
* @param request
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getFabulousList")
|
||||
public Result getFabulousList(HttpServletRequest request,Integer page,Integer pageSize){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
PageInfo<Comment> list = commentService.getFabulousList(Long.parseLong(userId),page,pageSize);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 案例打分
|
||||
* @param scoring
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveScoring")
|
||||
public Result saveScoring(HttpServletRequest request,Scoring scoring){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
scoring.setUserId(Long.parseLong(userId));
|
||||
commentService.saveScoring(scoring);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,218 @@
|
||||
package com.nbclass.activity.controller.casesfirst;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.activity.model.WeiXiUser;
|
||||
import com.nbclass.activity.service.WxService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
|
||||
import com.nbclass.util.HttpUtils;
|
||||
import com.nbclass.util.JWTUtils;
|
||||
import com.nbclass.vo.base.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* 微信接口
|
||||
* @author gao
|
||||
* @datetime 2021年10月14日
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/wx")
|
||||
public class WxController {
|
||||
|
||||
/**
|
||||
* wx的AppID
|
||||
*/
|
||||
private static final String appId = "wx013ea7738ce6991f";
|
||||
|
||||
/**
|
||||
* wx的AppSecret
|
||||
*/
|
||||
private static final String AppSecret = "03255f509c6b53cb2b94c9bd21b8aaa8";
|
||||
|
||||
/**
|
||||
* 企业微信corpid
|
||||
*/
|
||||
private static final String corpid = "wwc0b239a20872ff25";
|
||||
|
||||
/**
|
||||
* 企业微信corpsecret(客户的secret)
|
||||
*/
|
||||
private static final String corpsecret = "VuJ-Sd2X-oUwFUCzzdQfDZDe0Ryb3IbvkczFu8KUP0o";
|
||||
|
||||
@Autowired
|
||||
private WxService wxService;
|
||||
|
||||
@RequestMapping("/loginPage")
|
||||
public String loginPage(){
|
||||
return "loginPage";
|
||||
}
|
||||
|
||||
@RequestMapping("/weixinLogin")
|
||||
public String weixinLogin(){
|
||||
return "weixinLogin";
|
||||
}
|
||||
|
||||
@RequestMapping("/demo")
|
||||
public String demo(){
|
||||
return "demo";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信用户信息
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getWxUser")
|
||||
@ResponseBody
|
||||
public Result getWxUser(HttpServletRequest request){
|
||||
if(request.getParameter("code")==null){
|
||||
throw new ParameterException("code参数异常!");
|
||||
}
|
||||
|
||||
//获取code
|
||||
String code = request.getParameter("code");
|
||||
|
||||
//获取access_token
|
||||
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
|
||||
url = String.format(url,appId,AppSecret,code);
|
||||
JSONObject jsonObject = HttpUtils.httpGet(url);
|
||||
|
||||
if(jsonObject.getString("access_token")==null){
|
||||
throw new ParameterException("access_token参数异常!");
|
||||
}
|
||||
|
||||
if(jsonObject.getString("openid")==null){
|
||||
throw new ParameterException("openid参数异常!");
|
||||
}
|
||||
|
||||
String accessToken = jsonObject.getString("access_token");
|
||||
String openid = jsonObject.getString("openid");
|
||||
//String wxUnionId = jsonObject.getString("unionid");
|
||||
|
||||
//数据库查询是否有该openid,如果有直接从数据库获取用户信息
|
||||
int result = wxService.getOpenId(openid);
|
||||
if(result == 0){
|
||||
//获取用户信息
|
||||
String url2 = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s";
|
||||
url2 = String.format(url2,accessToken,openid);
|
||||
JSONObject jsonUser = HttpUtils.httpGet(url2);
|
||||
WeiXiUser weiXiUser = jsonUser.toJavaObject(WeiXiUser.class);
|
||||
//添加用户信息到数据库
|
||||
wxService.saveWxUser(weiXiUser);
|
||||
}
|
||||
//数据库获取用户信息
|
||||
WeiXiUser weiXiUser = wxService.getWxUser(openid);
|
||||
WeiXiUser user = new WeiXiUser();
|
||||
user.setId(weiXiUser.getId());
|
||||
user.setOpenid(weiXiUser.getOpenid());
|
||||
|
||||
String token = "";
|
||||
|
||||
//生成token
|
||||
String subject = JSON.toJSONString(user);
|
||||
try {
|
||||
token = JWTUtils.createJWT(UUID.randomUUID().toString(), "admin", subject, 7200 * 1000, null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("token",token);
|
||||
map.put("nickname",weiXiUser.getNickname());
|
||||
map.put("headimgurl",weiXiUser.getHeadimgurl());
|
||||
|
||||
|
||||
//获取企业微信的access_token
|
||||
/* String qyWxUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
|
||||
qyWxUrl = String.format(qyWxUrl,corpid,corpsecret);
|
||||
JSONObject qyWxJson = HttpUtils.httpGet(qyWxUrl);
|
||||
if(qyWxJson.getString("access_token")==null){
|
||||
throw new ParameterException("企业微信的access_token参数异常!");
|
||||
}
|
||||
String qyWxAccessToken = qyWxJson.getString("access_token");
|
||||
|
||||
//获取客户群列表
|
||||
String qyWxListUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token=%s";
|
||||
qyWxListUrl = String.format(qyWxListUrl,qyWxAccessToken);
|
||||
String limit = "{\"limit\": 1000}";
|
||||
String s1 = HttpUtil.doPostJson(qyWxListUrl, limit);
|
||||
JSONObject jsonObject = JSON.parseObject(s1);
|
||||
|
||||
if(jsonObject.getString("group_chat_list")==null){
|
||||
throw new ParameterException("企业微信的chatId参数异常!");
|
||||
}
|
||||
|
||||
String s = jsonObject.toJSONString();
|
||||
System.out.println(s);
|
||||
Map groupChats = JSONObject.parseObject(s,Map.class);
|
||||
JSONArray jsonArray = JSONArray.parseArray(groupChats.get("group_chat_list").toString());
|
||||
//获取chatId
|
||||
String chatId = jsonArray.getJSONObject(0).getString("chat_id");
|
||||
|
||||
//获取客户群详情
|
||||
String khUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token=%s";
|
||||
khUrl = String.format(khUrl,qyWxAccessToken);
|
||||
String chat_id = "{\"chat_id\": \""+chatId+"\"}";
|
||||
String s2 = HttpUtil.doPostJson(khUrl, chat_id);
|
||||
System.out.println(s2);
|
||||
String group_chat = JSON.parseObject(s2).get("group_chat").toString();
|
||||
GroupChat groupChat = JSONObject.parseObject(group_chat, GroupChat.class);
|
||||
System.out.println(groupChat);
|
||||
List<MemberList> memberLists = groupChat.getMember_list();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (MemberList memberList : memberLists) {
|
||||
*//* if(wxUnionId.equals(memberList.getUnionid())){
|
||||
|
||||
}*//*
|
||||
|
||||
System.out.println(memberList.getUnionid());
|
||||
}*/
|
||||
|
||||
|
||||
return Result.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看用户基础信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserBasicData")
|
||||
@ResponseBody
|
||||
public Result getUserBasicData(HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
WeiXiUser weiXiUser = wxService.getUserBasicData(Long.parseLong(userId));
|
||||
return Result.success(weiXiUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户基础信息
|
||||
* @param weiXiUser
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updateBasicData")
|
||||
@ResponseBody
|
||||
public Result updateBasicData(WeiXiUser weiXiUser, HttpServletRequest request){
|
||||
String token = request.getHeader("token");
|
||||
String userId = JWTUtils.getUserId(token);
|
||||
weiXiUser.setId(Long.parseLong(userId));
|
||||
weiXiUser.setUpdateTime(new Date());
|
||||
wxService.updateBasicData(weiXiUser);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package com.nbclass.activity.controller.frontapi;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.activity.model.Content;
|
||||
import com.nbclass.activity.model.enums.ContentType;
|
||||
import com.nbclass.activity.service.ElasticSearchService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.vo.base.Result;
|
||||
|
||||
/**
|
||||
* i前端获取案例查询
|
||||
* @author Leon
|
||||
* @datetime 2020年5月21日 下午5:32:25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/front/api/content")
|
||||
public class FrontContentController extends BaseController {
|
||||
|
||||
// @Resource
|
||||
// private ContentService service;
|
||||
|
||||
@Resource
|
||||
private ElasticSearchService esService;
|
||||
|
||||
/**
|
||||
* 查询案例列表
|
||||
* @param page
|
||||
* @param o
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
public Result getList(String type, HttpServletResponse response,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,
|
||||
String keyWord, String tagIds, String sourceIds){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
if(StringUtils.isNotBlank(type)){
|
||||
type = type.trim().toLowerCase();
|
||||
if(!ContentType.ppqa.key().equals(type) && !ContentType.ggqa.key().equals(type) &&
|
||||
!ContentType.design.key().equals(type) && !ContentType.video.key().equals(type) &&
|
||||
!ContentType.h5.key().equals(type) && !ContentType.ldhd.key().equals(type)
|
||||
&& !ContentType.others.key().equals(type)){
|
||||
throw new ParameterException("参数[type]不是有效的数据!");
|
||||
}
|
||||
}
|
||||
// List<Integer> tagIdList = CommonUtils.toIntList(tagIds);
|
||||
// List<Integer> sourceIdList = CommonUtils.toIntList(sourceIds);
|
||||
JSONObject resultObj = esService.getList(pageNum, pageSize, type, keyWord, tagIds, sourceIds);
|
||||
return Result.success(resultObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查找单条记录
|
||||
* @param id
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/findById")
|
||||
public Result findById(Long id, String type, HttpServletResponse response){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
if(StringUtils.isBlank(type)){
|
||||
throw new ParameterException("参数[type]不能为空!");
|
||||
}
|
||||
type=type.trim().toLowerCase();
|
||||
if(!ContentType.ppqa.key().equals(type) && !ContentType.ggqa.key().equals(type) &&
|
||||
!ContentType.design.key().equals(type) && !ContentType.video.key().equals(type) &&
|
||||
!ContentType.h5.key().equals(type) && !ContentType.ldhd.key().equals(type)
|
||||
&& !ContentType.others.key().equals(type)){
|
||||
throw new ParameterException("参数[type]不是有效的数据!");
|
||||
}
|
||||
if(id == null || id < 1) {
|
||||
throw new ParameterException("参数[id]不能为空!");
|
||||
}
|
||||
// ES里保存的ID是唯一的,所以不需要提交type字段查询
|
||||
Content content = esService.findById(id);
|
||||
return Result.success(content);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package com.nbclass.activity.controller.frontapi;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.nbclass.activity.service.ContentService;
|
||||
import com.nbclass.exception.LogicalException;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.exception.ServiceException;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.util.WebUtils;
|
||||
import com.nbclass.vo.base.Result;
|
||||
|
||||
/**
|
||||
* i案例库阅读数点赞数功能
|
||||
* @author Leon
|
||||
* @datetime 2020年5月22日 下午2:02:13
|
||||
*/
|
||||
@RestController
|
||||
public class FrontContentLikeNumController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ContentService service;
|
||||
|
||||
/**
|
||||
* 提交阅读数点赞数
|
||||
* @param type 提交类型[view:阅读数, like:点赞数]
|
||||
* @param id 点赞记录id
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/front/api/content/addNum")
|
||||
public Result updateContentNum(String type, Long id, HttpServletResponse response){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
try {
|
||||
if(StringUtils.isBlank(type))throw new ParameterException("参数type不能为空");
|
||||
if(id == null || id < 1)throw new ParameterException("案例id不能为空");
|
||||
|
||||
String cookieNum = WebUtils.getValueFromCookie(getRequest(), "case_content_num_"+type+"_"+id);
|
||||
if(StringUtils.isNotBlank(cookieNum)){
|
||||
if("view".equals(type)){
|
||||
return Result.success();
|
||||
}else{
|
||||
throw new ParameterException("你已经点过赞了");
|
||||
}
|
||||
}
|
||||
int num = service.updateContentNum(type, id);;
|
||||
|
||||
WebUtils.addCookie(response, "case_content_num_"+type+"_"+id, String.valueOf(type+id), 3600 * 24 * 1);
|
||||
return Result.success(num);
|
||||
} catch (Exception e) {
|
||||
String errmsg = "保存失败";
|
||||
if(e instanceof ParameterException || e instanceof ServiceException || e instanceof LogicalException){
|
||||
errmsg = e.getMessage();
|
||||
}else{
|
||||
logger.error("提交阅读数点赞数失败", e);
|
||||
}
|
||||
return Result.error(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package com.nbclass.activity.controller.frontapi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import com.nbclass.activity.model.enums.ContentType;
|
||||
import com.nbclass.activity.service.DataDictService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.system.controller.BaseController;
|
||||
import com.nbclass.vo.base.Result;
|
||||
|
||||
/**
|
||||
* i前端获取案例标签或来源列表
|
||||
* @author Leon
|
||||
* @datetime 2020年5月21日 下午5:32:25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/front/api/dict")
|
||||
public class FrontDataDictController extends BaseController {
|
||||
|
||||
@Resource
|
||||
public DataDictService service;
|
||||
|
||||
/**
|
||||
* 根据类型查询案例标签列表
|
||||
* @param type
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getTags")
|
||||
public Result getTags(String type, HttpServletResponse response){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
if(StringUtils.isBlank(type)) {
|
||||
throw new ParameterException("参数type不能为空");
|
||||
}
|
||||
type=type.trim().toLowerCase();
|
||||
if(!ContentType.ppqa.key().equals(type) && !ContentType.ggqa.key().equals(type) &&
|
||||
!ContentType.design.key().equals(type) && !ContentType.video.key().equals(type) &&
|
||||
!ContentType.h5.key().equals(type) && !ContentType.ldhd.key().equals(type)
|
||||
&& !ContentType.others.key().equals(type)){
|
||||
throw new ParameterException("参数[type]不是有效的数据!");
|
||||
}
|
||||
type = "tag_"+type;
|
||||
List<DataDictItem> list = service.getItemsByKey(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型查询案例来源列表
|
||||
* @param type
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getSources")
|
||||
public Result getSources(String type, HttpServletResponse response){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
if(StringUtils.isBlank(type)) {
|
||||
throw new ParameterException("参数type不能为空");
|
||||
}
|
||||
type=type.trim().toLowerCase();
|
||||
if(!ContentType.ppqa.key().equals(type) && !ContentType.ggqa.key().equals(type) &&
|
||||
!ContentType.design.key().equals(type) && !ContentType.video.key().equals(type) &&
|
||||
!ContentType.h5.key().equals(type) && !ContentType.ldhd.key().equals(type)
|
||||
&& !ContentType.others.key().equals(type)){
|
||||
throw new ParameterException("参数[type]不是有效的数据!");
|
||||
}
|
||||
type = "from_"+type;
|
||||
List<DataDictItem> list = service.getItemsByKey(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,332 @@
|
||||
package com.nbclass.activity.controller.keditor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
|
||||
/**
|
||||
* kindeditor上传文件 - 保存的本地项目的相对目录
|
||||
* @author Leon
|
||||
* @datetime 2019年4月9日 下午7:52:31
|
||||
*/
|
||||
@RequestMapping("/console/kindeditor/local")
|
||||
@RestController
|
||||
public class KindEditorController {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(KindEditorController.class);
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private static final long upload_max_size = 5242880; // 上传文件最大值,5M
|
||||
|
||||
@PostMapping("/api/file-upload")
|
||||
public Map<String, Object> fileUpload(HttpServletRequest request,
|
||||
HttpServletResponse response,@RequestParam("imgFile")MultipartFile file)
|
||||
throws ServletException, IOException, FileUploadException {
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
ServletContext application = request.getSession().getServletContext();
|
||||
String savePath = application.getRealPath("/") + "keditor-attached/";
|
||||
|
||||
// 文件保存目录URL
|
||||
String saveUrl = request.getContextPath() + "/keditor-attached/";
|
||||
|
||||
// 定义允许上传的文件扩展名
|
||||
HashMap<String, String> extMap = new HashMap<String, String>();
|
||||
extMap.put("image", "gif,jpg,jpeg,png,bmp");
|
||||
extMap.put("flash", "swf,flv");
|
||||
extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb,mp4,mov"); // 上传音视频格式
|
||||
extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");
|
||||
|
||||
if (!ServletFileUpload.isMultipartContent(request)) {
|
||||
return getError("请选择文件。");
|
||||
}
|
||||
// 检查目录
|
||||
File uploadDir = new File(savePath);
|
||||
if (!uploadDir.isDirectory()) {
|
||||
// return getError("上传目录不存在。");
|
||||
uploadDir.mkdirs();
|
||||
}
|
||||
// 检查目录写权限
|
||||
if (!uploadDir.canWrite()) {
|
||||
return getError("上传目录没有写权限。");
|
||||
}
|
||||
|
||||
String dirName = request.getParameter("dir");
|
||||
if (dirName == null) {
|
||||
dirName = "image";
|
||||
}
|
||||
if (!extMap.containsKey(dirName)) {
|
||||
return getError("目录名不正确。");
|
||||
}
|
||||
// 创建文件夹
|
||||
savePath += dirName + "/";
|
||||
saveUrl += dirName + "/";
|
||||
File saveDirFile = new File(savePath);
|
||||
if (!saveDirFile.exists()) {
|
||||
saveDirFile.mkdirs();
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
String ymd = sdf.format(new Date());
|
||||
savePath += ymd + "/";
|
||||
saveUrl += ymd + "/";
|
||||
File dirFile = new File(savePath);
|
||||
if (!dirFile.exists()) {
|
||||
dirFile.mkdirs();
|
||||
}
|
||||
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
upload.setHeaderEncoding("UTF-8");
|
||||
//List items = upload.parseRequest(request);
|
||||
//Iterator itr = items.iterator();
|
||||
|
||||
// FileItem item = (FileItem) itr.next();
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
// 检查文件大小
|
||||
if (file.getSize() > upload_max_size) {
|
||||
return getError("上传文件大小超过限制,请上传5M内的文件。");
|
||||
}
|
||||
// 检查扩展名
|
||||
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (!Arrays.<String> asList(extMap.get(dirName).split(",")).contains(fileExt)) {
|
||||
return getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。");
|
||||
}
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
|
||||
try {
|
||||
logger.info("savePath="+savePath+", newFileName="+newFileName);
|
||||
// File uploadedFile = new File(savePath, newFileName);
|
||||
File saveFile = new File(savePath+newFileName);
|
||||
file.transferTo(saveFile);
|
||||
createThumbnail(savePath, newFileName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getError("上传文件失败。");
|
||||
}
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("error", 0);
|
||||
msg.put("url", saveUrl + newFileName);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private Map<String, Object> getError(String message) {
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("error", 1);
|
||||
msg.put("message", message);
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param savePath
|
||||
* @param newFileName
|
||||
*/
|
||||
private void createThumbnail(String savePath, String newFileName) {
|
||||
try {
|
||||
Thumbnails.of(savePath+newFileName)
|
||||
.size(200,200)
|
||||
.toFile(savePath+"thump"+newFileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping(value = "/api/file-manager")
|
||||
public void fileManager(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
ServletContext application = request.getSession().getServletContext();
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
// 根目录路径,可以指定绝对路径,比如 /var/www/attached/
|
||||
String rootPath = application.getRealPath("/") + "keditor-attached/";
|
||||
// 根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
|
||||
|
||||
String rootUrl = request.getContextPath() + "/keditor-attached/";
|
||||
|
||||
// 图片扩展名
|
||||
String[] fileTypes = new String[] { "gif", "jpg", "jpeg", "png", "bmp" };
|
||||
|
||||
String dirName = request.getParameter("dir");
|
||||
if (dirName != null) {
|
||||
if (!Arrays.<String> asList(new String[] { "image", "flash", "media", "file" }).contains(dirName)) {
|
||||
out.println("Invalid Directory name.");
|
||||
return;
|
||||
}
|
||||
rootPath += dirName + "/";
|
||||
rootUrl += dirName + "/";
|
||||
File saveDirFile = new File(rootPath);
|
||||
if (!saveDirFile.exists()) {
|
||||
saveDirFile.mkdirs();
|
||||
}
|
||||
}
|
||||
// 根据path参数,设置各路径和URL
|
||||
String path = StringUtils.trimToEmpty(request.getParameter("path"));
|
||||
String currentPath = rootPath + path;
|
||||
String currentUrl = rootUrl + path;
|
||||
String currentDirPath = path;
|
||||
String moveupDirPath = "";
|
||||
if (StringUtils.isNotBlank(path)) {
|
||||
String str = currentDirPath.substring(0,
|
||||
currentDirPath.length() - 1);
|
||||
moveupDirPath = str.lastIndexOf("/") >= 0 ? str.substring(0,
|
||||
str.lastIndexOf("/") + 1) : "";
|
||||
}
|
||||
|
||||
// 排序形式,name or size or type
|
||||
String order = request.getParameter("order") != null ? request.getParameter("order").toLowerCase() : "name";
|
||||
|
||||
// 不允许使用..移动到上一级目录
|
||||
if (path.indexOf("..") >= 0) {
|
||||
out.println("Access is not allowed.");
|
||||
return;
|
||||
}
|
||||
// 最后一个字符不是/
|
||||
if (!"".equals(path) && !path.endsWith("/")) {
|
||||
out.println("Parameter is not valid.");
|
||||
return;
|
||||
}
|
||||
// 目录不存在或不是目录
|
||||
File currentPathFile = new File(currentPath);
|
||||
if (!currentPathFile.isDirectory()) {
|
||||
out.println("Directory does not exist.");
|
||||
return;
|
||||
}
|
||||
// 遍历目录取的文件信息
|
||||
List<Hashtable<String, Object>> fileList = new ArrayList<Hashtable<String, Object>>();
|
||||
if (currentPathFile.listFiles() != null) {
|
||||
for (File file : currentPathFile.listFiles()) {
|
||||
Hashtable<String, Object> hash = new Hashtable<String, Object>();
|
||||
String fileName = file.getName();
|
||||
if (file.isDirectory()) {
|
||||
hash.put("is_dir", true);
|
||||
hash.put("has_file", (file.listFiles() != null));
|
||||
hash.put("filesize", 0L);
|
||||
hash.put("is_photo", false);
|
||||
hash.put("filetype", "");
|
||||
} else if (file.isFile()) {
|
||||
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
hash.put("is_dir", false);
|
||||
hash.put("has_file", false);
|
||||
hash.put("filesize", file.length());
|
||||
hash.put("is_photo", Arrays.<String> asList(fileTypes).contains(fileExt));
|
||||
hash.put("filetype", fileExt);
|
||||
}
|
||||
hash.put("filename", fileName);
|
||||
hash.put("datetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file.lastModified()));
|
||||
fileList.add(hash);
|
||||
}
|
||||
}
|
||||
|
||||
if ("size".equals(order)) {
|
||||
Collections.sort(fileList, new SizeComparator());
|
||||
} else if ("type".equals(order)) {
|
||||
Collections.sort(fileList, new TypeComparator());
|
||||
} else {
|
||||
Collections.sort(fileList, new NameComparator());
|
||||
}
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("moveup_dir_path", moveupDirPath);
|
||||
msg.put("current_dir_path", currentDirPath);
|
||||
msg.put("current_url", currentUrl);
|
||||
msg.put("total_count", fileList.size());
|
||||
msg.put("file_list", fileList);
|
||||
response.setContentType("application/json; charset=UTF-8");
|
||||
String msgStr = objectMapper.writeValueAsString(msg);
|
||||
out.println(msgStr);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class NameComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
return ((String) hashA.get("filename"))
|
||||
.compareTo((String) hashB.get("filename"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class SizeComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
if (((Long) hashA.get("filesize")) > ((Long) hashB
|
||||
.get("filesize"))) {
|
||||
return 1;
|
||||
} else if (((Long) hashA.get("filesize")) < ((Long) hashB
|
||||
.get("filesize"))) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class TypeComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
return ((String) hashA.get("filetype"))
|
||||
.compareTo((String) hashB.get("filetype"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,337 @@
|
||||
package com.nbclass.activity.controller.keditor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
|
||||
/**
|
||||
* kindeditor上传文件 - 保存到cdn
|
||||
* @author Leon
|
||||
* @datetime 2019年4月15日 下午4:50:49
|
||||
*/
|
||||
@RequestMapping("/console/kindeditor/cdn")
|
||||
@RestController
|
||||
public class KindEditorUploadToCDNController {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(KindEditorUploadToCDNController.class);
|
||||
|
||||
// CDN保存目录
|
||||
private static final String upload_dir = "/mnt/cdn/xgl-cases/keditor-attached/";
|
||||
|
||||
private static final String cdn_domain = "https://cdn.szxgl.cn/";
|
||||
|
||||
private static final long upload_max_size = 5242880; // 上传文件最大值,5M
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@PostMapping("/api/file-upload")
|
||||
public Map<String, Object> fileUpload(HttpServletRequest request,
|
||||
HttpServletResponse response,@RequestParam("imgFile")MultipartFile file)
|
||||
throws ServletException, IOException, FileUploadException {
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
// ServletContext application = request.getSession().getServletContext();
|
||||
String savePath = upload_dir;
|
||||
|
||||
// 文件保存目录URL
|
||||
// String saveUrl = request.getContextPath() + "/attached/";
|
||||
|
||||
// 定义允许上传的文件扩展名
|
||||
HashMap<String, String> extMap = new HashMap<String, String>();
|
||||
extMap.put("image", "gif,jpg,jpeg,png,bmp");
|
||||
extMap.put("flash", "swf,flv");
|
||||
extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb,mp4,mov"); // 上传音视频格式
|
||||
extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");
|
||||
|
||||
if (!ServletFileUpload.isMultipartContent(request)) {
|
||||
return getError("请选择文件。");
|
||||
}
|
||||
// 检查目录
|
||||
File uploadDir = new File(savePath);
|
||||
if (!uploadDir.isDirectory()) {
|
||||
uploadDir.mkdirs();
|
||||
}
|
||||
// 检查目录写权限
|
||||
if (!uploadDir.canWrite()) {
|
||||
return getError("上传目录没有写权限。");
|
||||
}
|
||||
|
||||
String dirName = request.getParameter("dir");
|
||||
if (dirName == null) {
|
||||
dirName = "image";
|
||||
}
|
||||
if (!extMap.containsKey(dirName)) {
|
||||
return getError("目录名不正确。");
|
||||
}
|
||||
// 创建文件夹
|
||||
savePath += dirName + "/";
|
||||
File saveDirFile = new File(savePath);
|
||||
if (!saveDirFile.exists()) {
|
||||
saveDirFile.mkdirs();
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
String ymd = sdf.format(new Date());
|
||||
savePath += ymd + "/";
|
||||
File dirFile = new File(savePath);
|
||||
if (!dirFile.exists()) {
|
||||
dirFile.mkdirs();
|
||||
}
|
||||
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
upload.setHeaderEncoding("UTF-8");
|
||||
//List items = upload.parseRequest(request);
|
||||
//Iterator itr = items.iterator();
|
||||
|
||||
// FileItem item = (FileItem) itr.next();
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
// 检查文件大小
|
||||
if (file.getSize() > upload_max_size) {
|
||||
return getError("上传文件大小超过限制,请上传5M内的文件。");
|
||||
}
|
||||
// 检查扩展名
|
||||
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (!Arrays.<String> asList(extMap.get(dirName).split(",")).contains(fileExt)) {
|
||||
return getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。");
|
||||
}
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
|
||||
try {
|
||||
logger.info("savePath="+savePath+", newFileName="+newFileName);
|
||||
// File uploadedFile = new File(savePath, newFileName);
|
||||
File saveFile = new File(savePath+newFileName);
|
||||
file.transferTo(saveFile);
|
||||
createThumbnail(savePath, newFileName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getError("上传文件失败。");
|
||||
}
|
||||
String url = savePath + newFileName;
|
||||
String host = cdn_domain;
|
||||
url = url.replace("/mnt/cdn/", host);
|
||||
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("error", 0);
|
||||
msg.put("url", url);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private Map<String, Object> getError(String message) {
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("error", 1);
|
||||
msg.put("message", message);
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param savePath
|
||||
* @param newFileName
|
||||
*/
|
||||
private void createThumbnail(String savePath, String newFileName){
|
||||
try {
|
||||
Thumbnails.of(savePath+newFileName)
|
||||
.size(200,200)
|
||||
.toFile(savePath+"thump"+newFileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping(value = "/api/file-manager")
|
||||
public void fileManager(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// ServletContext application = request.getSession().getServletContext();
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
// 根目录路径,可以指定绝对路径,比如 /var/www/attached/
|
||||
String rootPath = upload_dir;
|
||||
// 根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
|
||||
//String rootUrl = request.getContextPath() + "/attached/";
|
||||
|
||||
// 图片扩展名
|
||||
String[] fileTypes = new String[] { "gif", "jpg", "jpeg", "png", "bmp" };
|
||||
|
||||
String dirName = request.getParameter("dir");
|
||||
if (dirName != null) {
|
||||
if (!Arrays.<String> asList(new String[] { "image", "flash", "media", "file" }).contains(dirName)) {
|
||||
out.println("Invalid Directory name.");
|
||||
return;
|
||||
}
|
||||
rootPath += dirName + "/";
|
||||
File saveDirFile = new File(rootPath);
|
||||
if (!saveDirFile.exists()) {
|
||||
saveDirFile.mkdirs();
|
||||
}
|
||||
}
|
||||
// 根据path参数,设置各路径和URL
|
||||
String path = StringUtils.trimToEmpty(request.getParameter("path"));
|
||||
String currentPath = rootPath + path;
|
||||
String currentDirPath = path;
|
||||
String moveupDirPath = "";
|
||||
if (StringUtils.isNotBlank(path)) {
|
||||
String str = currentDirPath.substring(0, currentDirPath.length() - 1);
|
||||
moveupDirPath = str.lastIndexOf("/") >= 0 ? str.substring(0, str.lastIndexOf("/") + 1) : "";
|
||||
}
|
||||
|
||||
// 排序形式,name or size or type
|
||||
String order = request.getParameter("order") != null ? request.getParameter("order").toLowerCase() : "name";
|
||||
|
||||
// 不允许使用..移动到上一级目录
|
||||
if (path.indexOf("..") >= 0) {
|
||||
out.println("Access is not allowed.");
|
||||
return;
|
||||
}
|
||||
// 最后一个字符不是/
|
||||
if (!"".equals(path) && !path.endsWith("/")) {
|
||||
out.println("Parameter is not valid.");
|
||||
return;
|
||||
}
|
||||
// 目录不存在或不是目录
|
||||
File currentPathFile = new File(currentPath);
|
||||
if (!currentPathFile.isDirectory()) {
|
||||
out.println("Directory does not exist.");
|
||||
return;
|
||||
}
|
||||
// 遍历目录取的文件信息
|
||||
List<Hashtable<String, Object>> fileList = new ArrayList<Hashtable<String, Object>>();
|
||||
if (currentPathFile.listFiles() != null) {
|
||||
for (File file : currentPathFile.listFiles()) {
|
||||
Hashtable<String, Object> hash = new Hashtable<String, Object>();
|
||||
String fileName = file.getName();
|
||||
if (file.isDirectory()) {
|
||||
hash.put("is_dir", true);
|
||||
hash.put("has_file", (file.listFiles() != null));
|
||||
hash.put("filesize", 0L);
|
||||
hash.put("is_photo", false);
|
||||
hash.put("filetype", "");
|
||||
} else if (file.isFile()) {
|
||||
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
hash.put("is_dir", false);
|
||||
hash.put("has_file", false);
|
||||
hash.put("filesize", file.length());
|
||||
hash.put("is_photo", Arrays.<String> asList(fileTypes).contains(fileExt));
|
||||
hash.put("filetype", fileExt);
|
||||
}
|
||||
hash.put("filename", fileName);
|
||||
hash.put("datetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file.lastModified()));
|
||||
fileList.add(hash);
|
||||
}
|
||||
}
|
||||
|
||||
if ("size".equals(order)) {
|
||||
Collections.sort(fileList, new SizeComparator());
|
||||
} else if ("type".equals(order)) {
|
||||
Collections.sort(fileList, new TypeComparator());
|
||||
} else {
|
||||
Collections.sort(fileList, new NameComparator());
|
||||
}
|
||||
|
||||
String currentUrl = currentPath;
|
||||
String host = cdn_domain;
|
||||
currentUrl = currentUrl.replace("/mnt/cdn/", host);
|
||||
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("moveup_dir_path", moveupDirPath);
|
||||
msg.put("current_dir_path", currentDirPath);
|
||||
msg.put("current_url", currentUrl);
|
||||
msg.put("total_count", fileList.size());
|
||||
msg.put("file_list", fileList);
|
||||
response.setContentType("application/json; charset=UTF-8");
|
||||
String msgStr = objectMapper.writeValueAsString(msg);
|
||||
out.println(msgStr);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class NameComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
return ((String) hashA.get("filename"))
|
||||
.compareTo((String) hashB.get("filename"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class SizeComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
if (((Long) hashA.get("filesize")) > ((Long) hashB
|
||||
.get("filesize"))) {
|
||||
return 1;
|
||||
} else if (((Long) hashA.get("filesize")) < ((Long) hashB
|
||||
.get("filesize"))) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class TypeComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
return ((String) hashA.get("filetype"))
|
||||
.compareTo((String) hashB.get("filetype"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,216 @@
|
||||
package com.nbclass.activity.controller.keditor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.nbclass.aliyun.sdk.AliyunOSSUtils;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
|
||||
/**
|
||||
* kindeditor上传文件 - 保存到阿里云OSS
|
||||
* @author Leon
|
||||
* @datetime 2020年6月8日 下午2:26:44
|
||||
*/
|
||||
@Slf4j
|
||||
@RequestMapping("/console/kindeditor/oss")
|
||||
@RestController
|
||||
public class KindEditorUploadToOSSController {
|
||||
|
||||
// OSS保存目录
|
||||
private static final String upload_dir = "kindeditor-attached/";
|
||||
|
||||
private static final long upload_max_size = 5242880; // 上传文件最大值,5M
|
||||
|
||||
@PostMapping("/api/file-upload")
|
||||
public Map<String, Object> fileUpload(HttpServletRequest request,
|
||||
HttpServletResponse response,@RequestParam("imgFile")MultipartFile file)
|
||||
throws ServletException, IOException, FileUploadException {
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
String savePath = upload_dir;
|
||||
|
||||
// 文件保存目录URL
|
||||
// String saveUrl = request.getContextPath() + "/keditor-attached/";
|
||||
|
||||
// 定义允许上传的文件扩展名
|
||||
HashMap<String, String> extMap = new HashMap<String, String>();
|
||||
extMap.put("image", "gif,jpg,jpeg,png,bmp");
|
||||
extMap.put("flash", "swf,flv");
|
||||
extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb,mp4,mov"); // 上传音视频格式
|
||||
extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");
|
||||
|
||||
if (!ServletFileUpload.isMultipartContent(request)) {
|
||||
return getError("请选择文件。");
|
||||
}
|
||||
// 检查目录
|
||||
File uploadDir = new File(savePath);
|
||||
if (!uploadDir.isDirectory()){
|
||||
// return getError("上传目录不存在。");
|
||||
uploadDir.mkdirs();
|
||||
}
|
||||
// 检查目录写权限
|
||||
if (!uploadDir.canWrite()){
|
||||
return getError("上传目录没有写权限。");
|
||||
}
|
||||
|
||||
String dirName = request.getParameter("dir");
|
||||
if (StringUtils.isBlank(dirName)) {
|
||||
dirName = "image";
|
||||
}
|
||||
if (!extMap.containsKey(dirName)) {
|
||||
return getError("目录名不正确。");
|
||||
}
|
||||
// 文件夹加上类型目录
|
||||
savePath += dirName + "/";
|
||||
// 文件夹加上日期目录
|
||||
savePath += CommonUtils.getSimpleDate(new Date(), "yyyyMM"); // yyyyMMdd
|
||||
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
upload.setHeaderEncoding("UTF-8");
|
||||
//List items = upload.parseRequest(request);
|
||||
//Iterator itr = items.iterator();
|
||||
|
||||
// FileItem item = (FileItem) itr.next();
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
// 检查文件大小
|
||||
if (file.getSize() > upload_max_size) {
|
||||
return getError("上传文件大小超过限制,请上传5M内的文件。");
|
||||
}
|
||||
// 检查扩展名
|
||||
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (!Arrays.<String> asList(extMap.get(dirName).split(",")).contains(fileExt)) {
|
||||
return getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。");
|
||||
}
|
||||
|
||||
String url = null;
|
||||
String newFileName = CommonUtils.getSimpleDate(new Date(), "yyyyMMddHHmmss") + "_" + new Random().nextInt(1000) + "." + fileExt;
|
||||
try {
|
||||
// File saveFile = new File(savePath+newFileName);
|
||||
// file.transferTo(saveFile);
|
||||
// createThumbnail(savePath, newFileName);
|
||||
|
||||
url = AliyunOSSUtils.uploadBytes(savePath, newFileName, file.getBytes());
|
||||
log.info("kindeditor上传文件到oss, url="+url);
|
||||
// 阿里云OSS缩略图,在URL后面加上:?x-oss-process=image/resize,m_fill,h_200,w_200
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getError("上传文件失败。");
|
||||
}
|
||||
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("error", 0);
|
||||
msg.put("url", url);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private Map<String, Object> getError(String message) {
|
||||
Map<String, Object> msg = new HashMap<String, Object>();
|
||||
msg.put("error", 1);
|
||||
msg.put("message", message);
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param savePath
|
||||
* @param newFileName
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void createThumbnail(String savePath, String newFileName) {
|
||||
try {
|
||||
Thumbnails.of(savePath+newFileName)
|
||||
.size(200,200)
|
||||
.toFile(savePath+"thump"+newFileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class NameComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
return ((String) hashA.get("filename"))
|
||||
.compareTo((String) hashB.get("filename"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class SizeComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
if (((Long) hashA.get("filesize")) > ((Long) hashB
|
||||
.get("filesize"))) {
|
||||
return 1;
|
||||
} else if (((Long) hashA.get("filesize")) < ((Long) hashB
|
||||
.get("filesize"))) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
class TypeComparator implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
Hashtable hashA = (Hashtable) a;
|
||||
Hashtable hashB = (Hashtable) b;
|
||||
if (((Boolean) hashA.get("is_dir"))
|
||||
&& !((Boolean) hashB.get("is_dir"))) {
|
||||
return -1;
|
||||
} else if (!((Boolean) hashA.get("is_dir"))
|
||||
&& ((Boolean) hashB.get("is_dir"))) {
|
||||
return 1;
|
||||
} else {
|
||||
return ((String) hashA.get("filetype"))
|
||||
.compareTo((String) hashB.get("filetype"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import com.nbclass.activity.model.Content;
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CaseTypeMapper {
|
||||
|
||||
|
||||
/**
|
||||
* 查询(案例类型、案例用途、创意形式、节日事件)
|
||||
* @return
|
||||
*/
|
||||
List<DataDictItem> getTypeCase(Integer dictId);
|
||||
|
||||
/**
|
||||
* 字典值类型列表查询
|
||||
* @return
|
||||
*/
|
||||
List<DataDict> getDictionariesType();
|
||||
|
||||
/**
|
||||
* 案例搜索框
|
||||
* @param dictItemId 案例类型id
|
||||
* @return
|
||||
*/
|
||||
List<Content> getSearchCase(@Param("parameter") String parameter,
|
||||
@Param("dictItemId") Integer dictItemId);
|
||||
|
||||
/**
|
||||
* 案例库列表
|
||||
* @return
|
||||
*/
|
||||
List<Content> getListCase();
|
||||
|
||||
/**
|
||||
* 获取案例标签
|
||||
* @param contentId 案例id
|
||||
* @return
|
||||
*/
|
||||
ContentTags getContentTags(Integer contentId);
|
||||
|
||||
}
|
||||
212
src/main/java/com/nbclass/activity/mapper/CommentMapper.java
Normal file
212
src/main/java/com/nbclass/activity/mapper/CommentMapper.java
Normal file
@ -0,0 +1,212 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import com.nbclass.activity.model.*;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CommentMapper {
|
||||
|
||||
/**
|
||||
* 案例详情和评论列表
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
Content getComment(@Param("contentId") Long contentId,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 评论回复列表
|
||||
* @param commentId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Comment getCommentReplyList(@Param("commentId") Long commentId,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 添加用户发布信息
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
void saveComment(Comment comment);
|
||||
|
||||
/**
|
||||
* 根据评论id获取被点赞人Id
|
||||
* @param commentId
|
||||
* @return
|
||||
*/
|
||||
Comment getCommentUserId(Long commentId);
|
||||
|
||||
/**
|
||||
* 添加评论点赞
|
||||
* @param praise
|
||||
* @return
|
||||
*/
|
||||
void savePraiseNo(Praise praise);
|
||||
|
||||
/**
|
||||
* 添加案例点赞
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
void updateContentPraiseNo(Long contentId);
|
||||
|
||||
/**
|
||||
* 评论总数加1
|
||||
* @param commentId
|
||||
*/
|
||||
void updatePraiseno(Long commentId);
|
||||
|
||||
/**
|
||||
* 用户回复
|
||||
* @param comment
|
||||
*/
|
||||
void saveUserReply(Comment comment);
|
||||
|
||||
/**
|
||||
* 用户举报
|
||||
* @param report
|
||||
* @return
|
||||
*/
|
||||
void saveReport(Report report);
|
||||
|
||||
/**
|
||||
* 举报列表获取
|
||||
* @return
|
||||
*/
|
||||
List<Report> getReport(String userId);
|
||||
|
||||
/**
|
||||
* 添加标签、索引反馈日志
|
||||
* @return
|
||||
*/
|
||||
void saveLabelLogger(LabelLogger labelLogger);
|
||||
|
||||
/**
|
||||
* 新建文件夹
|
||||
* @param favoritesFolder
|
||||
* @return
|
||||
*/
|
||||
void saveFavorites(FavoritesFolder favoritesFolder);
|
||||
|
||||
/**
|
||||
* 案例详情的文件夹列表
|
||||
* @return
|
||||
*/
|
||||
List<FavoritesFolder> getUserFolder(@Param("userId") Long userId,
|
||||
@Param("commentId") Long commentId);
|
||||
|
||||
/**
|
||||
* 收藏案例到文件夹中
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
void saveFolder(@Param("folderId") Long folderId,
|
||||
@Param("contentId") Long contentId);
|
||||
|
||||
/**
|
||||
* 添加收藏总数
|
||||
* @param folderId
|
||||
*/
|
||||
void saveFolderTotal(Long folderId);
|
||||
|
||||
/**
|
||||
* 判断该文件夹是否已被收藏
|
||||
* @param folderId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
int getFolderExistence(@Param("folderId") Long folderId,
|
||||
@Param("contentId") Long contentId);
|
||||
|
||||
/**
|
||||
* 判断文件夹是否重名
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
int getFavoritesName(String name);
|
||||
|
||||
/**
|
||||
* 取消文件夹中的案例收藏
|
||||
* @param folderId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
void deleteFolderResources(@Param("folderId") Long folderId,
|
||||
@Param("contentId") Long contentId);
|
||||
|
||||
/**
|
||||
* 我的收藏
|
||||
* @return
|
||||
*/
|
||||
List<Content> getMyCollection(@Param("userId") Long userId,
|
||||
@Param("folderId") Long folderId);
|
||||
|
||||
/**
|
||||
* 获取用户文件夹列表
|
||||
* @return
|
||||
*/
|
||||
List<FavoritesFolder> getUserFolderList(Long userId);
|
||||
|
||||
/**
|
||||
* 取消评论点赞
|
||||
* @return
|
||||
*/
|
||||
void deletePraise(@Param("commentId") Long commentId,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 总点赞数减一
|
||||
* @param commentId
|
||||
*/
|
||||
void updatePraiseNoONE(Long commentId);
|
||||
|
||||
/**
|
||||
* 评论总回复数加一
|
||||
*/
|
||||
void updateReplyNumberONE(Long commentId);
|
||||
|
||||
/**
|
||||
* 回复列表
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Comment> getReplyList(Long userId);
|
||||
|
||||
/**
|
||||
* 点赞列表
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Comment> getFabulousList(Long userId);
|
||||
|
||||
/**
|
||||
* 更新案例的收藏总数+1
|
||||
* @param contentId
|
||||
*/
|
||||
void updateCollectionNumber(Long contentId);
|
||||
|
||||
/**
|
||||
* 更新案例的收藏总数-1
|
||||
* @param contentId
|
||||
*/
|
||||
void updateCollectionNumberReduce(Long contentId);
|
||||
|
||||
/**
|
||||
* 标签、索引反馈日志列表
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<LabelLogger> getLabelLogger(Long userId);
|
||||
|
||||
/**
|
||||
* 案例打分
|
||||
* @param scoring
|
||||
*/
|
||||
void saveScoring(Scoring scoring);
|
||||
|
||||
}
|
||||
221
src/main/java/com/nbclass/activity/mapper/ContentMapper.java
Normal file
221
src/main/java/com/nbclass/activity/mapper/ContentMapper.java
Normal file
@ -0,0 +1,221 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nbclass.activity.model.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nbclass.util.MyMapper;
|
||||
|
||||
public interface ContentMapper extends MyMapper<Content> {
|
||||
|
||||
/**
|
||||
* 根据id查找记录
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Content findById(long id);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<Content> getList(Content entity);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表 - 前端页面查询
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<Content> getListByFront(Content entity);
|
||||
|
||||
/**
|
||||
* 根据id批量删除记录
|
||||
* @param list
|
||||
*/
|
||||
public void deleteByIds(List<Long> list);
|
||||
|
||||
|
||||
/**
|
||||
* 删除关联的标签
|
||||
* @param cid
|
||||
*/
|
||||
public void deleteTags(long cid);
|
||||
|
||||
/**
|
||||
* 批量添加标签
|
||||
* @param list
|
||||
*/
|
||||
public void insertContentTags(List<ContentTags> list);
|
||||
|
||||
/**
|
||||
* 通过内容ID删除图片集
|
||||
* @param cid
|
||||
*/
|
||||
public void deleteImages(long cid);
|
||||
|
||||
/**
|
||||
* 批量添加图片
|
||||
* @param list
|
||||
*/
|
||||
public void insertContentImages(List<ContentImages> list);
|
||||
|
||||
/**
|
||||
* 添加点赞数阅读数
|
||||
* @param type [view, like]
|
||||
* @param id
|
||||
*/
|
||||
public void updateContentNum(@Param("type")String type, @Param("id")Long id);
|
||||
|
||||
/**
|
||||
* 查询案例标题和评论数和点赞数
|
||||
* @return
|
||||
*/
|
||||
List<Content> getCaseTitle();
|
||||
|
||||
/**
|
||||
* 标签关联案例
|
||||
* @param contentTags
|
||||
*/
|
||||
void addContentTags(ContentTags contentTags);
|
||||
|
||||
/**
|
||||
* 获取自定义标签列表
|
||||
* @return
|
||||
*/
|
||||
List<DataDictItem> getOtherLabels();
|
||||
|
||||
/**
|
||||
* 取消案例关联标签的关系
|
||||
* @param idList
|
||||
*/
|
||||
void deleteContentTags(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 案例索引标签反馈次数+1
|
||||
* @param contentId
|
||||
*/
|
||||
void updateLabelFeedback(Long contentId);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
List<Content> getList2(Content entity);
|
||||
|
||||
/**
|
||||
* 更新案例总评论数
|
||||
* @param contentId
|
||||
*/
|
||||
void updateComments(Long contentId);
|
||||
|
||||
/**
|
||||
* 添加案例评分
|
||||
* @param userId
|
||||
* @param contentId
|
||||
* @param score
|
||||
*/
|
||||
void saveScore(@Param("userId") Long userId,
|
||||
@Param("contentId") Long contentId,
|
||||
@Param("score") Double score);
|
||||
|
||||
/**
|
||||
* 查看用户是否已经打过分
|
||||
* @param userId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
int getScore(@Param("userId") Long userId,
|
||||
@Param("contentId") Long contentId);
|
||||
|
||||
/**
|
||||
* 根据案例id查询案例详情
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
Content getEditContent(Long contentId);
|
||||
|
||||
/**
|
||||
* 提交审核申请单
|
||||
* @param application
|
||||
*/
|
||||
void saveApplication(Application application);
|
||||
|
||||
/**
|
||||
* 添加审核人信息
|
||||
* @param check
|
||||
*/
|
||||
void saveCheck(Check check);
|
||||
|
||||
/**
|
||||
*查询案例是否已提交过审核
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
int getApplicationCount(Long contentId);
|
||||
|
||||
/**
|
||||
* 删除案例审核申请
|
||||
* @param applicationId
|
||||
*/
|
||||
void deleteApplication(Long applicationId);
|
||||
|
||||
/**
|
||||
* 删除审核人信息
|
||||
* @param applicationId
|
||||
*/
|
||||
void deleteCheck(Long applicationId);
|
||||
|
||||
/**
|
||||
* 更新审核申请单状态
|
||||
* @param applicationId
|
||||
*/
|
||||
void updateApplicationStatus(Long applicationId);
|
||||
|
||||
/**
|
||||
* 更新审核人状态
|
||||
* @param applicationId
|
||||
*/
|
||||
void updateCheckStatus(Long applicationId);
|
||||
|
||||
/**
|
||||
* 获取审核列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
List<Content> getContentApplication(Content entity);
|
||||
|
||||
/**
|
||||
* 更新审核表状态
|
||||
* @param check
|
||||
*/
|
||||
void updateCheck(Check check);
|
||||
|
||||
/**
|
||||
* 更新申请单状态
|
||||
* @param application
|
||||
*/
|
||||
void updateApplication(Application application);
|
||||
|
||||
/**
|
||||
* 查询案例id
|
||||
* @return
|
||||
*/
|
||||
Long getContentId(Long applicationId);
|
||||
|
||||
/**
|
||||
* 更新案例状态
|
||||
* @param contentId
|
||||
*/
|
||||
void updateContentRelease(Long contentId,Integer release);
|
||||
|
||||
/**
|
||||
* 根据案例id查询申请单信息
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
Application getApplication(Long contentId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import com.nbclass.util.MyMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年6月1日 下午9:15:33
|
||||
*/
|
||||
public interface DataDictItemMapper extends MyMapper<DataDictItem> {
|
||||
|
||||
/**
|
||||
* 根据dictid查询字典item列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<DataDictItem> getList(DataDictItem entity);
|
||||
|
||||
/**
|
||||
* 判断记录是否存在
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public Long checkExist(DataDictItem entity);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id检查字典是否在案例标签中有使用
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Long checkContentTag(@Param("id")Long id);
|
||||
|
||||
/**
|
||||
* 根据id检查字典是否在案例来源中有使用
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Long checkContentFrom(@Param("id")Long id);
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
* @return
|
||||
*/
|
||||
List<ContentTags> getDropDownBox();
|
||||
|
||||
/**
|
||||
* 根据名字查询tasId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
String[] getTagId(String name);
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import com.nbclass.util.MyMapper;
|
||||
|
||||
public interface DataDictMapper extends MyMapper<DataDict> {
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<DataDict> getList(DataDict entity);
|
||||
|
||||
/**
|
||||
* 删除前验证
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public Long delCheck(List<Long> list);
|
||||
|
||||
/**
|
||||
* 根据id批量删除记录
|
||||
* @param list
|
||||
*/
|
||||
public void deleteByIds(List<Long> list);
|
||||
|
||||
/**
|
||||
* 通过字典Key获取子集
|
||||
* @param datakey
|
||||
* @return
|
||||
*/
|
||||
public List<DataDictItem> getItemsByKey(@Param(value="datakey")String datakey);
|
||||
|
||||
/**
|
||||
* 根据字典名获取列表
|
||||
* @param datakey
|
||||
* @param tagNames
|
||||
* @return
|
||||
*/
|
||||
public List<DataDictItem> getItemsByNames(@Param(value="datakey")String datakey, @Param("tagNames")List<String> tagNames);
|
||||
|
||||
/**
|
||||
* 保存字典item
|
||||
* @param entity
|
||||
*/
|
||||
public void insertDataDictItem(DataDictItem entity);
|
||||
|
||||
/**
|
||||
* 根据标签名称查询标签信息
|
||||
* @param postTagList
|
||||
* @return
|
||||
*/
|
||||
List<DataDictItem> getDataDictTemName(@Param("tagNames")ArrayList<String> postTagList);
|
||||
|
||||
/**
|
||||
* 获取自定义标签id
|
||||
* @return
|
||||
*/
|
||||
Long getDataDictID();
|
||||
|
||||
/**
|
||||
* 查询字典值是否重复
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
int getDataDicName(String name);
|
||||
|
||||
}
|
||||
67
src/main/java/com/nbclass/activity/mapper/WXMapper.java
Normal file
67
src/main/java/com/nbclass/activity/mapper/WXMapper.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import com.nbclass.activity.model.Check;
|
||||
import com.nbclass.activity.model.WeiXiUser;
|
||||
import com.nbclass.activity.model.WxUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WXMapper {
|
||||
|
||||
/**
|
||||
* //数据库查询是否有该openid,如果有直接从数据库获取用户信息
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
int getOpenId(String openid);
|
||||
|
||||
|
||||
/**
|
||||
* //添加用户信息到数据库
|
||||
* @param weiXiUser
|
||||
*/
|
||||
void saveWxUser(WeiXiUser weiXiUser);
|
||||
|
||||
/**
|
||||
* //数据库获取用户信息
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
WeiXiUser getWxUser(String openid);
|
||||
|
||||
/**
|
||||
* 根据用户id获取信息
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
WeiXiUser getUser(String userId);
|
||||
|
||||
/**
|
||||
* 更新用户基础信息
|
||||
* @param weiXiUser
|
||||
* @return
|
||||
*/
|
||||
void updateBasicData(WeiXiUser weiXiUser);
|
||||
|
||||
/**
|
||||
* 查看用户基础信息
|
||||
* @return
|
||||
*/
|
||||
WeiXiUser getUserBasicData(Long userId);
|
||||
|
||||
/**
|
||||
* 根据userId获取微信用户信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
WxUser getQyWxUser(String username);
|
||||
|
||||
/**
|
||||
* 根据部门id获取用户领导
|
||||
* @return
|
||||
*/
|
||||
List<Check> getUserLeader(String department);
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nbclass.activity.model.WxDepartment;
|
||||
import com.nbclass.util.MyMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年6月2日 下午4:42:57
|
||||
*/
|
||||
public interface WxDepartmentMapper extends MyMapper<WxDepartment> {
|
||||
|
||||
|
||||
public void insertBatch(List<WxDepartment> list);
|
||||
|
||||
/**
|
||||
* 通过父极id获取子部门id列表,返回结果包含当前父级id
|
||||
* @param parentid
|
||||
* @return 返回id以逗号分隔
|
||||
*/
|
||||
public String getChildDeptIds(@Param("parentid")int parentid);
|
||||
|
||||
}
|
||||
53
src/main/java/com/nbclass/activity/mapper/WxUserMapper.java
Normal file
53
src/main/java/com/nbclass/activity/mapper/WxUserMapper.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.nbclass.activity.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nbclass.activity.model.WxUser;
|
||||
import com.nbclass.util.MyMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年6月2日 下午4:42:57
|
||||
*/
|
||||
public interface WxUserMapper extends MyMapper<WxUser> {
|
||||
|
||||
// 这个没用,使用insertSelective方法。
|
||||
public void insertCustom(WxUser entity);
|
||||
|
||||
/**
|
||||
* 根据userid修改记录
|
||||
* @param entity
|
||||
*/
|
||||
public void updateByUserId(WxUser entity);
|
||||
|
||||
/**
|
||||
* 获取成员UserID列表
|
||||
* @return
|
||||
*/
|
||||
public List<String> getUserIds();
|
||||
|
||||
/**
|
||||
* 通过部门ID列表获取用户信息列表
|
||||
* @param deptids
|
||||
* @return
|
||||
*/
|
||||
public List<WxUser> getUsersByDeptIds(@Param("deptids")String[] deptids);
|
||||
|
||||
/**
|
||||
* 通过用户ID列表获取用户信息列表
|
||||
* @param userids
|
||||
* @return
|
||||
*/
|
||||
public List<WxUser> getUsersByUserIds(@Param("userids")String[] userids);
|
||||
|
||||
|
||||
/**
|
||||
* 删除此userids之外的用户
|
||||
* @param userIds
|
||||
*/
|
||||
public void delOtherUsers(@Param("userids")List<String> userids);
|
||||
|
||||
}
|
||||
54
src/main/java/com/nbclass/activity/model/Application.java
Normal file
54
src/main/java/com/nbclass/activity/model/Application.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Application implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 22459352105621985L;
|
||||
|
||||
/**
|
||||
* id(主键自增)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 案例id
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
/**
|
||||
* 申请人id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 审核类型(1、案例审核)
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 审核状态(1、待审核 2、通过 3、不通过)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 审核人
|
||||
*/
|
||||
private List<Check> checks;
|
||||
|
||||
}
|
||||
46
src/main/java/com/nbclass/activity/model/Check.java
Normal file
46
src/main/java/com/nbclass/activity/model/Check.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Check implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6085309152205259190L;
|
||||
|
||||
/**
|
||||
* id(主键自增)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 申请单id
|
||||
*/
|
||||
private Long applicationId;
|
||||
|
||||
/**
|
||||
* 审核人id
|
||||
*/
|
||||
private Long checkId;
|
||||
|
||||
/**
|
||||
* 审核状态(1、待审核 2、通过 3、失败)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
|
||||
}
|
||||
81
src/main/java/com/nbclass/activity/model/Comment.java
Normal file
81
src/main/java/com/nbclass/activity/model/Comment.java
Normal file
@ -0,0 +1,81 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Comment implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1702315030539408893L;
|
||||
|
||||
/**
|
||||
* 评论id(主键自增)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 案例id
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
/**
|
||||
* 评论人id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 回复人id(回复有值,没有回复,默认值是0)
|
||||
*/
|
||||
private Long replyId;
|
||||
|
||||
/**
|
||||
* 评论id(有值代表回复,0代表主评论)
|
||||
*/
|
||||
private Long commentId;
|
||||
|
||||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
private String commentContent;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 点赞总数
|
||||
*/
|
||||
private Integer praiseNo;
|
||||
|
||||
/**
|
||||
* 总回复数
|
||||
*/
|
||||
private Integer replyNumber;
|
||||
|
||||
/**
|
||||
* 评论用户名称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 评论用户头像
|
||||
*/
|
||||
private String headimgurl;
|
||||
|
||||
/**
|
||||
* 点赞人id(有值代表已点赞,没有值代表没有点赞)
|
||||
*/
|
||||
private Long praiseId;
|
||||
|
||||
//回复列表
|
||||
private List<Comment> respondents;
|
||||
|
||||
//最新2人的点赞人列表
|
||||
private List<WeiXiUser> userList;
|
||||
|
||||
|
||||
}
|
||||
199
src/main/java/com/nbclass/activity/model/Content.java
Normal file
199
src/main/java/com/nbclass/activity/model/Content.java
Normal file
@ -0,0 +1,199 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Table(name = "content")
|
||||
public class Content implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6422276602170816740L;
|
||||
|
||||
/**
|
||||
* ID, 主键,自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updatetime;
|
||||
|
||||
/**
|
||||
* 案例类型[ppqa:品牌全案, ggqa:公关全案, design:创意设计, video:视频动画, h5:技术开发, ldhd:落地活动, others:其他案例]
|
||||
*/
|
||||
private String type;
|
||||
|
||||
|
||||
/**
|
||||
* 是否有效(1:有效,0:无效)
|
||||
*/
|
||||
private Byte isvalid;
|
||||
|
||||
/**
|
||||
* 案例来源ID
|
||||
*/
|
||||
private Integer fromid;
|
||||
// 案例来源名称
|
||||
@Transient
|
||||
private String fromName;
|
||||
@Transient
|
||||
private String fromids; // 案例来源id,多个逗号分隔
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要,描述
|
||||
*/
|
||||
private String desct;
|
||||
|
||||
/**
|
||||
* 查看数
|
||||
*/
|
||||
private Integer viewno;
|
||||
|
||||
/**
|
||||
* 点赞数
|
||||
*/
|
||||
private Integer praiseno;
|
||||
|
||||
/**
|
||||
* 收藏数
|
||||
*/
|
||||
private Integer collectionNumber;
|
||||
|
||||
/**
|
||||
* 列表icon图
|
||||
*/
|
||||
private String listicon;
|
||||
|
||||
/**
|
||||
* 二维码
|
||||
*/
|
||||
private String qrcode;
|
||||
|
||||
/**
|
||||
* 排序值, 值越大越考前
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 访问地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 内容,富文本内容存储在这
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 纯Text内容,用于存到ES便于搜索
|
||||
*/
|
||||
private String content_text;
|
||||
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
private String attachment;
|
||||
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 索引标签反馈次数
|
||||
*/
|
||||
private Integer labelFeedback;
|
||||
|
||||
/**
|
||||
* 字典数据名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 可见性
|
||||
*/
|
||||
private Integer visibility;
|
||||
|
||||
/**
|
||||
*评论数
|
||||
*/
|
||||
private Integer comments;
|
||||
|
||||
/**
|
||||
* 发布状态(1、未发布 2、已发布 4、已下线)
|
||||
*/
|
||||
private Integer release;
|
||||
|
||||
/**
|
||||
* 审核状态(1、待审核 2、已上线 3、不通过 4、已下线 5、未提交)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
//用户人名称
|
||||
private String userName;
|
||||
|
||||
//用户人职位
|
||||
private String position;
|
||||
|
||||
//申请单id
|
||||
@Transient
|
||||
private Long applicationId;
|
||||
|
||||
//审核表案例状态
|
||||
private Long checkStatus;
|
||||
|
||||
//申请单
|
||||
private Application application;
|
||||
|
||||
//总评分
|
||||
private Double TotalScore;
|
||||
|
||||
//评分总人数
|
||||
private Integer userTotal;
|
||||
|
||||
|
||||
|
||||
// 标签
|
||||
@Transient
|
||||
private String tags;
|
||||
@Transient
|
||||
private List<ContentTags> tagList = new ArrayList<ContentTags>();
|
||||
|
||||
//案例分类
|
||||
private String[] tagLists;
|
||||
|
||||
//反馈次数
|
||||
private Integer quantity;
|
||||
|
||||
// 图片集
|
||||
@Transient
|
||||
private String images;
|
||||
@Transient
|
||||
private List<ContentImages> imgList = new ArrayList<ContentImages>();
|
||||
|
||||
//评论列表
|
||||
private List<Comment> commentators;
|
||||
|
||||
//查询标签个数 控制前端案例列表的查看操作
|
||||
private Integer count;
|
||||
|
||||
}
|
||||
47
src/main/java/com/nbclass/activity/model/ContentImages.java
Normal file
47
src/main/java/com/nbclass/activity/model/ContentImages.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Table(name = "content_images")
|
||||
public class ContentImages {
|
||||
/**
|
||||
* ID, 主键,自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
|
||||
/**
|
||||
* 内容表ID
|
||||
*/
|
||||
private Long cid;
|
||||
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String imgurl;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
private String ori_name;
|
||||
|
||||
}
|
||||
53
src/main/java/com/nbclass/activity/model/ContentTags.java
Normal file
53
src/main/java/com/nbclass/activity/model/ContentTags.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Table(name = "content_tags")
|
||||
public class ContentTags {
|
||||
/**
|
||||
* ID, 主键,自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
|
||||
/**
|
||||
* 内容表ID
|
||||
*/
|
||||
private Long cid;
|
||||
|
||||
/**
|
||||
* 标签id(与data_dict_item.id对应)
|
||||
*/
|
||||
private Long tid;
|
||||
|
||||
/**
|
||||
* 字典id
|
||||
*/
|
||||
private Long dictId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// 标签名(查询字段)
|
||||
@Transient
|
||||
private String tagName;
|
||||
|
||||
}
|
||||
52
src/main/java/com/nbclass/activity/model/DataDict.java
Normal file
52
src/main/java/com/nbclass/activity/model/DataDict.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Table(name = "data_dict")
|
||||
public class DataDict {
|
||||
/**
|
||||
* ID, 主键,自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updatetime;
|
||||
|
||||
/**
|
||||
* 字典key值
|
||||
*/
|
||||
private String datakey;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 是否有效(1:有效,0:无效)
|
||||
*/
|
||||
private Byte isvalid;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
}
|
||||
53
src/main/java/com/nbclass/activity/model/DataDictItem.java
Normal file
53
src/main/java/com/nbclass/activity/model/DataDictItem.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Table(name = "data_dict_item")
|
||||
public class DataDictItem {
|
||||
/**
|
||||
* ID, 主键,自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updatetime;
|
||||
|
||||
/**
|
||||
* 字典id值(data_dict表id)
|
||||
*/
|
||||
private Long dictid;
|
||||
|
||||
/**
|
||||
* 字典value值(组合主键)
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 字典名字
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class FavoritesFolder implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -220203874286975484L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文件夹名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
*创建人id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 收藏总数
|
||||
*/
|
||||
private Integer totalCollections;
|
||||
|
||||
/**
|
||||
* 案例Id
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
}
|
||||
29
src/main/java/com/nbclass/activity/model/GroupChat.java
Normal file
29
src/main/java/com/nbclass/activity/model/GroupChat.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class GroupChat implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4159209038197422844L;
|
||||
|
||||
private String chat_id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String owner;
|
||||
|
||||
private Date create_time;
|
||||
|
||||
private String notice;
|
||||
|
||||
|
||||
|
||||
private List<MemberList> member_list;
|
||||
|
||||
|
||||
}
|
||||
16
src/main/java/com/nbclass/activity/model/GroupChatList.java
Normal file
16
src/main/java/com/nbclass/activity/model/GroupChatList.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class GroupChatList implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 279034174223992751L;
|
||||
|
||||
private String chat_id;
|
||||
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
54
src/main/java/com/nbclass/activity/model/LabelLogger.java
Normal file
54
src/main/java/com/nbclass/activity/model/LabelLogger.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class LabelLogger implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8533327511622545026L;
|
||||
|
||||
/**
|
||||
* id(主键自增)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 案例id
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
/**
|
||||
* 反馈人
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private String logger;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 状态(0、待解决 1、已解决)
|
||||
*/
|
||||
private int status;
|
||||
|
||||
/**
|
||||
* 反馈人名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 案例名称
|
||||
*/
|
||||
private String contentName;
|
||||
|
||||
}
|
||||
|
||||
26
src/main/java/com/nbclass/activity/model/MemberList.java
Normal file
26
src/main/java/com/nbclass/activity/model/MemberList.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class MemberList implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2160707045527379917L;
|
||||
|
||||
private String userid;
|
||||
|
||||
private String type;
|
||||
|
||||
private String unionid;
|
||||
|
||||
private Long join_time;
|
||||
|
||||
private Integer join_scene;
|
||||
|
||||
private String group_nickname;
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
||||
38
src/main/java/com/nbclass/activity/model/Praise.java
Normal file
38
src/main/java/com/nbclass/activity/model/Praise.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class Praise implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1111401809162956593L;
|
||||
|
||||
/**
|
||||
* 点赞id(主键自增)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 评论id
|
||||
*/
|
||||
private Long commentId;
|
||||
|
||||
/**
|
||||
* 点赞人id
|
||||
*/
|
||||
private Long praiseId;
|
||||
|
||||
/**
|
||||
* 被点赞人id(评论人id)
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 点赞时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
|
||||
}
|
||||
95
src/main/java/com/nbclass/activity/model/QueryCriteria.java
Normal file
95
src/main/java/com/nbclass/activity/model/QueryCriteria.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class QueryCriteria {
|
||||
|
||||
/**
|
||||
* 案例编号
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
/**
|
||||
* 案例标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 案例状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 反馈次数
|
||||
*/
|
||||
private Integer labelFeedback;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String labelName;
|
||||
|
||||
/**
|
||||
* 品牌公司
|
||||
*/
|
||||
private String brandCompany;
|
||||
|
||||
/**
|
||||
* 广告公司
|
||||
*/
|
||||
private String advertisingAgency;
|
||||
|
||||
/**
|
||||
* 案例用途
|
||||
*/
|
||||
private Integer purposeCase;
|
||||
|
||||
/**
|
||||
* 创意形式
|
||||
*/
|
||||
private Integer formCreative;
|
||||
|
||||
/**
|
||||
* 案例类型
|
||||
*/
|
||||
private Integer typeCase;
|
||||
|
||||
/**
|
||||
* 节日事件
|
||||
*/
|
||||
private Integer eventsFestival;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建时间区间
|
||||
*/
|
||||
private Date createTimeSection;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 修改时间区间
|
||||
*/
|
||||
private Date updateTimeSection;
|
||||
|
||||
/**
|
||||
* 上线时间
|
||||
*/
|
||||
private Date onlineTime;
|
||||
|
||||
/**
|
||||
* 上线时间
|
||||
*/
|
||||
private Date onlineTimeSection;
|
||||
|
||||
}
|
||||
49
src/main/java/com/nbclass/activity/model/Report.java
Normal file
49
src/main/java/com/nbclass/activity/model/Report.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Report implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6136060231077523641L;
|
||||
|
||||
/**
|
||||
* id(主键自增)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 评论id
|
||||
*/
|
||||
private Long commentId;
|
||||
|
||||
/**
|
||||
* 举报人Id
|
||||
*/
|
||||
private Long reportId;
|
||||
|
||||
|
||||
/**
|
||||
* 举报内容
|
||||
*/
|
||||
private String reportContent;
|
||||
|
||||
/**
|
||||
*举报类型(1、政治、色情等违法言论,2、人身攻击,3、故意引战倾向等不当言论,4、其他原因)
|
||||
*/
|
||||
private Integer reportType;
|
||||
|
||||
/**
|
||||
* 处理状态(0、未处理,1、已处理)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 举报时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
36
src/main/java/com/nbclass/activity/model/Scoring.java
Normal file
36
src/main/java/com/nbclass/activity/model/Scoring.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Scoring implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -9026107018961218312L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 案例id
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
/**
|
||||
* 评分数
|
||||
*/
|
||||
private Double score;
|
||||
|
||||
/**
|
||||
* 评分人
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
||||
95
src/main/java/com/nbclass/activity/model/WeiXiUser.java
Normal file
95
src/main/java/com/nbclass/activity/model/WeiXiUser.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 微信用户成员
|
||||
*/
|
||||
@Data
|
||||
public class WeiXiUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4661130931634820819L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 普通用户的标识,对当前开发者帐号唯一
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* 普通用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 普通用户性别,1为男性,2为女性
|
||||
*/
|
||||
private Integer sex;
|
||||
|
||||
/**
|
||||
* 普通用户个人资料填写的省份
|
||||
*/
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 普通用户个人资料填写的城市
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 国家,如中国为CN
|
||||
*/
|
||||
private String country;
|
||||
|
||||
/**
|
||||
* 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空
|
||||
*/
|
||||
private String headimgurl;
|
||||
|
||||
/**
|
||||
* 用户特权信息,json数组,如微信沃卡用户为(chinaunicom)
|
||||
*/
|
||||
private JSON privilege;
|
||||
|
||||
/**
|
||||
* 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。
|
||||
*/
|
||||
private String unionid;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 职业id(dict_item的id)
|
||||
*/
|
||||
private Integer occupationId;
|
||||
|
||||
/**
|
||||
* 公司
|
||||
*/
|
||||
private String company;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String mailbox;
|
||||
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
private String briefIntroduction;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
30
src/main/java/com/nbclass/activity/model/WxDepartment.java
Normal file
30
src/main/java/com/nbclass/activity/model/WxDepartment.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 企业微信部门表
|
||||
* @author leiyun
|
||||
* @datetime 2017年12月21日 下午4:17:39
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "wx_department")
|
||||
public class WxDepartment implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentid;
|
||||
|
||||
private Integer order;
|
||||
|
||||
}
|
||||
46
src/main/java/com/nbclass/activity/model/WxUser.java
Normal file
46
src/main/java/com/nbclass/activity/model/WxUser.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.nbclass.activity.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 微信成员
|
||||
* @author leiyun
|
||||
* @datetime 2017年12月21日 上午10:58:59
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "wx_user")
|
||||
public class WxUser implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID, 主键,自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String userid;
|
||||
private String name;
|
||||
private String mobile;
|
||||
|
||||
private String department;
|
||||
private String position;
|
||||
private String gender; // 性别。0表示未定义,1表示男性,2表示女性
|
||||
|
||||
private String email;
|
||||
private String weixinid;
|
||||
private String isleader;
|
||||
private String avatar;
|
||||
private String english_name;
|
||||
|
||||
private int status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package com.nbclass.activity.model.enums;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* i案例类型枚举
|
||||
* @author Leon
|
||||
* @datetime 2020年5月29日 下午1:56:11
|
||||
*/
|
||||
public enum ContentType {
|
||||
|
||||
ppqa("106", "品牌全案"),
|
||||
|
||||
ggqa("107", "公关全案"),
|
||||
|
||||
design("108", "创意设计"),
|
||||
|
||||
video("109", "视频动画"),
|
||||
|
||||
h5("110", "技术开发"),
|
||||
|
||||
ldhd("111", "落地活动"),
|
||||
|
||||
others("112", "其他案例")
|
||||
;
|
||||
|
||||
// 枚举值
|
||||
private final String key;
|
||||
|
||||
// 枚举描述
|
||||
private final String desc;
|
||||
|
||||
|
||||
ContentType(final String key, final String desc ) {
|
||||
this.key = key;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String desc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
||||
public static String getNameByCode(String key){
|
||||
for(ContentType entity : ContentType.values()){
|
||||
if(key.equals(entity.key)){
|
||||
return entity.desc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.Content;
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author gaojiuqi
|
||||
* @datetime 2021年10月12日 下午14:42
|
||||
*/
|
||||
public interface CaseTypeService {
|
||||
|
||||
/**
|
||||
* 查询(案例类型、案例用途、创意形式、节日事件)
|
||||
* @return
|
||||
*/
|
||||
List<DataDictItem> getTypeCase(Integer dictId);
|
||||
|
||||
/**
|
||||
* 字典值类型列表查询
|
||||
* @return
|
||||
*/
|
||||
List<DataDict> getDictionariesType();
|
||||
|
||||
/**
|
||||
* 案例搜索框
|
||||
* @param dictItemId 案例类型id
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Content> getSearchCase(String parameter, Integer dictItemId,Integer page, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 案例库列表
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Content> getListCase(Integer page, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 获取案例标签
|
||||
* @param contentId 案例id
|
||||
* @return
|
||||
*/
|
||||
ContentTags getContentTags(Integer contentId);
|
||||
|
||||
}
|
||||
208
src/main/java/com/nbclass/activity/service/CommentService.java
Normal file
208
src/main/java/com/nbclass/activity/service/CommentService.java
Normal file
@ -0,0 +1,208 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.*;
|
||||
|
||||
public interface CommentService {
|
||||
|
||||
/**
|
||||
* 案例详情和评论列表
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
Content getComment(Long contentId,Long userId);
|
||||
|
||||
/**
|
||||
* 评论回复列表
|
||||
* @param commentId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Comment getCommentReplyList(Long commentId,Long userId);
|
||||
|
||||
/**
|
||||
* 添加用户发布信息
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
void saveComment(Comment comment);
|
||||
|
||||
/**
|
||||
* 根据评论id获取被点赞人Id
|
||||
* @param commentId
|
||||
* @return
|
||||
*/
|
||||
Comment getCommentUserId(Long commentId);
|
||||
|
||||
/**
|
||||
* 添加评论点赞
|
||||
* @param praise
|
||||
* @return
|
||||
*/
|
||||
void savePraiseNo(Praise praise);
|
||||
|
||||
/**
|
||||
* 添加案例点赞
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
void updateContentPraiseNo(Long contentId);
|
||||
|
||||
/**
|
||||
* 评论总数加1
|
||||
* @param commentId
|
||||
*/
|
||||
void updatePraiseno(Long commentId);
|
||||
|
||||
/**
|
||||
* 用户回复
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
void saveUserReply(Comment comment);
|
||||
|
||||
/**
|
||||
* 用户举报
|
||||
* @param report
|
||||
* @return
|
||||
*/
|
||||
void saveReport(Report report);
|
||||
|
||||
/**
|
||||
* 举报列表获取
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Report> getReport(Integer page, Integer pageSize, String userId);
|
||||
|
||||
/**
|
||||
* 添加标签、索引反馈日志
|
||||
* @return
|
||||
*/
|
||||
void saveLabelLogger(LabelLogger labelLogger);
|
||||
|
||||
/**
|
||||
* 新建文件夹
|
||||
* @param favoritesFolder
|
||||
* @return
|
||||
*/
|
||||
void saveFavorites(FavoritesFolder favoritesFolder);
|
||||
|
||||
/**
|
||||
* 案例详情的文件夹列表
|
||||
* @return
|
||||
*/
|
||||
PageInfo<FavoritesFolder> getUserFolder(Long userId, Integer page, Integer pageSize,Long commentId);
|
||||
|
||||
/**
|
||||
* 收藏案例到文件夹中
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
void saveFolder(Long folderId,Long contentId);
|
||||
|
||||
/**
|
||||
* 添加收藏总数
|
||||
* @param folderId
|
||||
*/
|
||||
void saveFolderTotal(Long folderId);
|
||||
|
||||
/**
|
||||
* 判断该文件夹是否已被收藏
|
||||
* @param folderId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
int getFolderExistence(Long folderId, Long contentId);
|
||||
|
||||
/**
|
||||
* 判断文件夹是否重名
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
int getFavoritesName(String name);
|
||||
|
||||
/**
|
||||
* 取消文件夹中的案例收藏
|
||||
* @param folderId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
void deleteFolderResources(Long folderId, Long contentId);
|
||||
|
||||
/**
|
||||
* 我的收藏
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Content> getMyCollection(Long userId, Integer page, Integer pageSize,Long folderId);
|
||||
|
||||
/**
|
||||
* 获取用户文件夹列表
|
||||
* @return
|
||||
*/
|
||||
PageInfo<FavoritesFolder> getUserFolderList(Long userId, Integer page, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 取消评论点赞
|
||||
* @return
|
||||
*/
|
||||
void deletePraise(Long commentId, Long userId);
|
||||
|
||||
/**
|
||||
* 总点赞数减一
|
||||
* @param commentId
|
||||
*/
|
||||
void updatePraiseNoONE(Long commentId);
|
||||
|
||||
/**
|
||||
* 评论总回复数加一
|
||||
*/
|
||||
void updateReplyNumberONE(Long commentId);
|
||||
|
||||
/**
|
||||
* 回复列表
|
||||
* @param userId
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Comment> getReplyList(Long userId, Integer page, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 点赞列表
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Comment> getFabulousList(Long userId, Integer page, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 更新案例的收藏总数+1
|
||||
* @param contentId
|
||||
*/
|
||||
void updateCollectionNumber(Long contentId);
|
||||
|
||||
/**
|
||||
* 更新案例的收藏总数-1
|
||||
* @param contentId
|
||||
*/
|
||||
void updateCollectionNumberReduce(Long contentId);
|
||||
|
||||
/**
|
||||
* 标签、索引反馈日志列表
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageInfo<LabelLogger> getLabelLogger(Integer page, Integer pageSize, Long userId);
|
||||
|
||||
/**
|
||||
* 案例打分
|
||||
* @param scoring
|
||||
*/
|
||||
void saveScoring(Scoring scoring);
|
||||
|
||||
}
|
||||
193
src/main/java/com/nbclass/activity/service/ContentService.java
Normal file
193
src/main/java/com/nbclass/activity/service/ContentService.java
Normal file
@ -0,0 +1,193 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年5月28日 下午4:42:15
|
||||
*/
|
||||
public interface ContentService {
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param entity
|
||||
*/
|
||||
public void add(Content entity);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param entity
|
||||
*/
|
||||
public void update(Content entity);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids
|
||||
*/
|
||||
public void delete(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return entity
|
||||
*/
|
||||
public Content findById(Long id);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<Content> getList(Content entity);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表 - 前端页面查询
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<Content> getListByFront(Content entity);
|
||||
|
||||
/**
|
||||
* 添加点赞数阅读数
|
||||
* @param type [view, like]
|
||||
* @param id 案例ID
|
||||
*/
|
||||
public int updateContentNum(String type, Long id);
|
||||
|
||||
/**
|
||||
* 同步数据库数据到ES
|
||||
* @param entity
|
||||
* @param isReBuild 是否重建,true:删除所有文档重建
|
||||
*/
|
||||
public long syncEsData(Content entity, boolean isReBuild);
|
||||
|
||||
/**
|
||||
* 查询案例标题和评论数和点赞数
|
||||
* @return
|
||||
*/
|
||||
PageInfo<Content> getCaseTitle(Integer page,Integer pageSize);
|
||||
|
||||
/**
|
||||
* 标签关联案例
|
||||
* @param contentTags
|
||||
*/
|
||||
void addContentTags(ContentTags contentTags);
|
||||
|
||||
/**
|
||||
* 获取自定义标签列表
|
||||
* @return
|
||||
*/
|
||||
List<DataDictItem> getOtherLabels();
|
||||
|
||||
/**
|
||||
* 取消案例关联标签的关系
|
||||
* @param idList
|
||||
*/
|
||||
void deleteContentTags(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 案例索引标签反馈次数+1
|
||||
* @param contentId
|
||||
*/
|
||||
void updateLabelFeedback(Long contentId);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
List<Content> getList2(Content entity);
|
||||
|
||||
/**
|
||||
* 更新案例总评论数
|
||||
* @param contentId
|
||||
*/
|
||||
void updateComments(Long contentId);
|
||||
|
||||
/**
|
||||
* 添加案例评分
|
||||
* @param userId
|
||||
* @param contentId
|
||||
* @param score
|
||||
*/
|
||||
void saveScore(Long userId, Long contentId, Double score);
|
||||
|
||||
/**
|
||||
* 查看用户是否已经打过分
|
||||
* @param userId
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
int getScore(Long userId, Long contentId);
|
||||
|
||||
/**
|
||||
* 根据案例id查询案例详情
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
Content getEditContent(Long contentId);
|
||||
|
||||
/**
|
||||
* 提交审核申请单
|
||||
* @param application
|
||||
*/
|
||||
void saveApplication(Application application);
|
||||
|
||||
/**
|
||||
* 查询案例是否已提交过审核
|
||||
* @param contentId
|
||||
* @return
|
||||
*/
|
||||
int getApplicationCount(Long contentId);
|
||||
|
||||
/**
|
||||
* 删除案例审核申请
|
||||
* @param applicationId
|
||||
*/
|
||||
void deleteApplication(Long applicationId);
|
||||
|
||||
/**
|
||||
* 更新审核申请单状态
|
||||
* @param applicationId
|
||||
*/
|
||||
void updateApplicationStatus(Long applicationId);
|
||||
|
||||
/**
|
||||
* 获取审核列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
List<Content> getContentApplication(Content entity);
|
||||
|
||||
/**
|
||||
* 审核案例
|
||||
* @param check
|
||||
* @param userId
|
||||
*/
|
||||
void updateApplication(Check check, Long userId);
|
||||
|
||||
/**
|
||||
* 根据userId获取微信用户信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
WxUser getQyWxUser(String username);
|
||||
|
||||
/**
|
||||
* 根据部门id获取用户领导
|
||||
* @param department
|
||||
* @return
|
||||
*/
|
||||
List<Check> getUserLeader(String department);
|
||||
|
||||
/**
|
||||
* 下线案例
|
||||
* @param contentId
|
||||
*/
|
||||
void deleteRelease(Long contentId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年5月28日 下午3:13:52
|
||||
*/
|
||||
public interface DataDictService {
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param entity
|
||||
*/
|
||||
public void add(DataDict entity);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param entity
|
||||
*/
|
||||
public void update(DataDict entity);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids
|
||||
*/
|
||||
public void delete(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return entity
|
||||
*/
|
||||
public DataDict findById(Long id);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<DataDict> getList(DataDict entity);
|
||||
|
||||
/**
|
||||
* 通过字典Key获取子集
|
||||
* @param datakey
|
||||
* @return
|
||||
*/
|
||||
public List<DataDictItem> getItemsByKey(String datakey);
|
||||
|
||||
/**
|
||||
* 根据dictid查询字典item列表
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public List<DataDictItem> getItemList(DataDictItem entity);
|
||||
|
||||
/**
|
||||
* 添加或修改字典子项
|
||||
* @param entity
|
||||
*/
|
||||
public void mergeDataDictItem(DataDictItem entity);
|
||||
|
||||
/**
|
||||
* 删除字典子项
|
||||
* @param id
|
||||
*/
|
||||
public void deleteDataDictItem(Long id);
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
* @return
|
||||
*/
|
||||
List<ContentTags> getDropDownBox();
|
||||
|
||||
/**
|
||||
* 根据名字查询tasId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
String[] getTagId(String name);
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.activity.model.Content;
|
||||
|
||||
/**
|
||||
* ES搜索
|
||||
* @author Leon
|
||||
* @datetime 2020年6月1日 下午3:00:41
|
||||
*/
|
||||
public interface ElasticSearchService {
|
||||
|
||||
/**
|
||||
* 添加或修改文档索引
|
||||
* @param entity
|
||||
*/
|
||||
public void merge(Content entity);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids
|
||||
*/
|
||||
public void deleteDocByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据条件删除
|
||||
* @param entity
|
||||
*/
|
||||
public void deleteDocByQuery(Content entity);
|
||||
|
||||
/**
|
||||
* 判断一个文档是否存在
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public boolean existDoc(Long id);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return entity
|
||||
*/
|
||||
public Content findById(Long id);
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @param type 案例类型
|
||||
* @param keyWord 关键词
|
||||
* @param tagIds 标签ID, 多个英文逗号分隔
|
||||
* @param sourceIds 案例来源ID, 多个英文逗号分隔
|
||||
* @return
|
||||
*/
|
||||
public JSONObject getList(Integer pageNum, Integer pageSize, String type, String keyWord, String tagIds, String sourceIds);
|
||||
|
||||
|
||||
}
|
||||
47
src/main/java/com/nbclass/activity/service/WxService.java
Normal file
47
src/main/java/com/nbclass/activity/service/WxService.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import com.nbclass.activity.model.WeiXiUser;
|
||||
|
||||
public interface WxService {
|
||||
|
||||
/**
|
||||
* 数据库查询是否有该openid,如果有直接从数据库获取用户信息
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
int getOpenId(String openid);
|
||||
|
||||
/**
|
||||
* 添加用户信息到数据库
|
||||
* @param weiXiUser
|
||||
*/
|
||||
void saveWxUser(WeiXiUser weiXiUser);
|
||||
|
||||
/**
|
||||
* 数据库获取用户信息
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
WeiXiUser getWxUser(String openid);
|
||||
|
||||
/**
|
||||
* 根据用户id获取信息
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
WeiXiUser getUser(String userId);
|
||||
|
||||
/**
|
||||
* 更新用户基础信息
|
||||
* @param weiXiUser
|
||||
* @return
|
||||
*/
|
||||
void updateBasicData(WeiXiUser weiXiUser);
|
||||
|
||||
/**
|
||||
* 查看用户基础信息
|
||||
* @return
|
||||
*/
|
||||
WeiXiUser getUserBasicData(Long userId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.nbclass.activity.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nbclass.activity.model.WxUser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年6月2日 下午4:50:28
|
||||
*/
|
||||
public interface WxUserService{
|
||||
|
||||
/**
|
||||
* 批量保存用户
|
||||
* @param userList
|
||||
*/
|
||||
public void merge(List<WxUser> userList);
|
||||
|
||||
/**
|
||||
* 同步企业微信成员
|
||||
*/
|
||||
public void syncWxUser();
|
||||
|
||||
/**
|
||||
* 同步企业微信部门
|
||||
*/
|
||||
public void syncWxDepartment();
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.mapper.CaseTypeMapper;
|
||||
import com.nbclass.activity.model.Content;
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import com.nbclass.activity.service.CaseTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CaseTypeServiceImpl implements CaseTypeService {
|
||||
|
||||
@Autowired
|
||||
private CaseTypeMapper caseTypeMapper;
|
||||
|
||||
@Override
|
||||
public List<DataDictItem> getTypeCase(Integer dictId) {
|
||||
return caseTypeMapper.getTypeCase(dictId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDict> getDictionariesType() {
|
||||
return caseTypeMapper.getDictionariesType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Content> getSearchCase(String parameter, Integer dictItemId,Integer page, Integer pageSize) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Content> list = caseTypeMapper.getSearchCase(parameter,dictItemId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Content> getListCase(Integer page, Integer pageSize) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Content> list = caseTypeMapper.getListCase();
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentTags getContentTags(Integer contentId) {
|
||||
return caseTypeMapper.getContentTags(contentId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,178 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.mapper.CommentMapper;
|
||||
import com.nbclass.activity.model.*;
|
||||
import com.nbclass.activity.service.CommentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
|
||||
@Autowired
|
||||
private CommentMapper commentMapper;
|
||||
|
||||
@Override
|
||||
public Content getComment(Long contentId,Long userId) {
|
||||
return commentMapper.getComment(contentId,userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment getCommentReplyList(Long commentId, Long userId) {
|
||||
return commentMapper.getCommentReplyList(commentId,userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveComment(Comment comment) {
|
||||
commentMapper.saveComment(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment getCommentUserId(Long commentId) {
|
||||
return commentMapper.getCommentUserId(commentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePraiseNo(Praise praise) {
|
||||
commentMapper.savePraiseNo(praise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContentPraiseNo(Long contentId) {
|
||||
commentMapper.updateContentPraiseNo(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePraiseno(Long commentId) {
|
||||
commentMapper.updatePraiseno(commentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserReply(Comment comment) {
|
||||
commentMapper.saveUserReply(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveReport(Report report) {
|
||||
commentMapper.saveReport(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Report> getReport(Integer page, Integer pageSize, String userId) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Report> list = commentMapper.getReport(userId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLabelLogger(LabelLogger labelLogger) {
|
||||
commentMapper.saveLabelLogger(labelLogger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFavorites(FavoritesFolder favoritesFolder) {
|
||||
commentMapper.saveFavorites(favoritesFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<FavoritesFolder> getUserFolder(Long userId, Integer page, Integer pageSize,Long commentId) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<FavoritesFolder> list = commentMapper.getUserFolder(userId,commentId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFolder(Long folderId,Long contentId) {
|
||||
commentMapper.saveFolder(folderId,contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFolderTotal(Long folderId) {
|
||||
commentMapper.saveFolderTotal(folderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFolderExistence(Long folderId, Long contentId) {
|
||||
return commentMapper.getFolderExistence(folderId,contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFavoritesName(String name) {
|
||||
return commentMapper.getFavoritesName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFolderResources(Long folderId, Long contentId) {
|
||||
commentMapper.deleteFolderResources(folderId,contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Content> getMyCollection(Long userId, Integer page, Integer pageSize,Long folderId) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Content> list = commentMapper.getMyCollection(userId,folderId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<FavoritesFolder> getUserFolderList(Long userId, Integer page, Integer pageSize) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<FavoritesFolder> list = commentMapper.getUserFolderList(userId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePraise(Long commentId, Long userId) {
|
||||
commentMapper.deletePraise(commentId,userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePraiseNoONE(Long commentId) {
|
||||
commentMapper.updatePraiseNoONE(commentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReplyNumberONE(Long commentId) {
|
||||
commentMapper.updateReplyNumberONE(commentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Comment> getReplyList(Long userId, Integer page, Integer pageSize) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Comment> list = commentMapper.getReplyList(userId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Comment> getFabulousList(Long userId, Integer page, Integer pageSize) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Comment> list = commentMapper.getFabulousList(userId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCollectionNumber(Long contentId) {
|
||||
commentMapper.updateCollectionNumber(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCollectionNumberReduce(Long contentId) {
|
||||
commentMapper.updateCollectionNumberReduce(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<LabelLogger> getLabelLogger(Integer page, Integer pageSize, Long userId) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<LabelLogger> list = commentMapper.getLabelLogger(userId);
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveScoring(Scoring scoring) {
|
||||
commentMapper.saveScoring(scoring);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,470 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import com.nbclass.activity.mapper.WXMapper;
|
||||
import com.nbclass.activity.model.*;
|
||||
import com.nbclass.activity.service.WxService;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.mapper.ContentMapper;
|
||||
import com.nbclass.activity.mapper.DataDictMapper;
|
||||
import com.nbclass.activity.model.enums.ContentType;
|
||||
import com.nbclass.activity.service.ContentService;
|
||||
import com.nbclass.activity.service.ElasticSearchService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年5月28日 下午4:42:45
|
||||
*/
|
||||
@Service
|
||||
public class ContentServiceImpl implements ContentService {
|
||||
|
||||
@Resource
|
||||
private ContentMapper mapper;
|
||||
|
||||
@Resource
|
||||
private DataDictMapper dataDictMapper;
|
||||
|
||||
@Resource
|
||||
private ElasticSearchService esService;
|
||||
|
||||
@Resource
|
||||
private DataDictMapper dataDictMapper2;
|
||||
|
||||
@Resource
|
||||
private WXMapper wxMapper;
|
||||
|
||||
|
||||
private void baseSaveVerify(Content entity) {
|
||||
/*if(StringUtils.isBlank(entity.getType())) {
|
||||
throw new ParameterException("案例类型不能为空");
|
||||
}*/
|
||||
if(StringUtils.isBlank(entity.getTitle())) {
|
||||
throw new ParameterException("标题不能为空");
|
||||
}
|
||||
/*if(entity.getFromid() == null || entity.getFromid() < 1) {
|
||||
throw new ParameterException("案例来源不能为空");
|
||||
}*/
|
||||
if(StringUtils.isBlank(entity.getDesct())) {
|
||||
throw new ParameterException("描述不能为空");
|
||||
}
|
||||
if(StringUtils.isBlank(entity.getListicon())) {
|
||||
throw new ParameterException("封面图不能为空");
|
||||
}
|
||||
|
||||
// 链接形式的案例
|
||||
if(ContentType.h5.key().equals(entity.getType()) || ContentType.video.key().equals(entity.getType())) {
|
||||
if(StringUtils.isBlank(entity.getUrl())) {
|
||||
throw new ParameterException("URL不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
// 富文本编辑的案例
|
||||
// 0527开发群确认的,记录关键词“都是富文本”
|
||||
if(ContentType.design.key().equals(entity.getType())
|
||||
|| ContentType.ppqa.key().equals(entity.getType())
|
||||
|| ContentType.ggqa.key().equals(entity.getType())
|
||||
|| ContentType.ldhd.key().equals(entity.getType())
|
||||
|| ContentType.others.key().equals(entity.getType())) {
|
||||
if(StringUtils.isBlank(entity.getContent())) {
|
||||
throw new ParameterException("内容不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
if(StringUtils.isBlank(entity.getAttachment()))entity.setAttachment(null); // 空字符串导致MySQL存储json类型异常
|
||||
}
|
||||
|
||||
// // 修改案例标签和图集
|
||||
// private void updateLabelAndImages(Content o){
|
||||
// long cid = o.getId();
|
||||
// List<ContentTags> newTagList = new ArrayList<ContentTags>();
|
||||
// if(StringUtils.isNotBlank(o.getTags())){
|
||||
// ArrayList<String> postTagList = CommonUtils.str2List(o.getTags());
|
||||
// // 查询出 dictid
|
||||
// DataDict dataDict = new DataDict();
|
||||
// dataDict.setDatakey("tag_"+o.getType());
|
||||
// dataDict = dataDictMapper.selectOne(dataDict);
|
||||
//
|
||||
//
|
||||
// List<DataDictItem> taglist = dataDictMapper.getItemsByNames("tag_"+o.getType(), postTagList);
|
||||
// HashMap<String, DataDictItem> tagMap = new HashMap<String, DataDictItem>();
|
||||
// for (DataDictItem dataDictItem : taglist) {
|
||||
// tagMap.put(dataDictItem.getName(), dataDictItem);
|
||||
// }
|
||||
// for (String tag : postTagList) {
|
||||
// if(StringUtils.isBlank(tag))continue;
|
||||
// DataDictItem ddItem = null;
|
||||
// if(tagMap.containsKey(tag)) {
|
||||
// ddItem = tagMap.get(tag);
|
||||
// }else {
|
||||
// // 字典表里没有则新增标签
|
||||
// ddItem = new DataDictItem();
|
||||
// ddItem.setDictid(dataDict.getId());
|
||||
// ddItem.setName(tag);
|
||||
// ddItem.setValue(tag);
|
||||
// dataDictMapper.insertDataDictItem(ddItem);
|
||||
// }
|
||||
// ContentTags label = new ContentTags();
|
||||
// label.setCid(cid);
|
||||
// label.setTid(ddItem.getId());
|
||||
// newTagList.add(label);
|
||||
// }
|
||||
// }
|
||||
// mapper.deleteTags(cid);
|
||||
// if(newTagList.size() > 0)mapper.insertContentTags(newTagList);
|
||||
//
|
||||
//
|
||||
// List<ContentImages> imgList = new ArrayList<ContentImages>();
|
||||
// String images = o.getImages();
|
||||
// if(StringUtils.isNotBlank(images)){
|
||||
// JSONArray array = JSONArray.parseArray(images);
|
||||
// for(int i=0, j=array.size();i<j;i++){
|
||||
// JSONObject obj = array.getJSONObject(i);
|
||||
// ContentImages contentImages = new ContentImages();
|
||||
// contentImages.setCid(cid);
|
||||
// contentImages.setSort(obj.getIntValue("sort"));
|
||||
// contentImages.setImgurl(obj.getString("imgurl"));
|
||||
// contentImages.setOri_name(obj.getString("filename"));
|
||||
// imgList.add(contentImages);
|
||||
// }
|
||||
// }
|
||||
// mapper.deleteImages(cid);
|
||||
// if(imgList.size() > 0){
|
||||
// mapper.insertContentImages(imgList);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 修改案例标签和图集
|
||||
private void updateLabelAndImages(Content o){
|
||||
long cid = o.getId();
|
||||
List<ContentTags> newTagList = new ArrayList<ContentTags>();
|
||||
if(StringUtils.isNotBlank(o.getTags())){
|
||||
ArrayList<String> postTagList = CommonUtils.str2List(o.getTags());
|
||||
// 查询自定义标签的dictid
|
||||
Long dictId = dataDictMapper2.getDataDictID();
|
||||
|
||||
//根据标签名称查询标签信息
|
||||
List<DataDictItem> tagList = dataDictMapper2.getDataDictTemName(postTagList);
|
||||
HashMap<String, DataDictItem> tagMap = new HashMap<String, DataDictItem>();
|
||||
for (DataDictItem dataDictItem : tagList) {
|
||||
tagMap.put(dataDictItem.getName(), dataDictItem);
|
||||
}
|
||||
for (String tag : postTagList) {
|
||||
if(StringUtils.isBlank(tag))continue;
|
||||
DataDictItem ddItem = null;
|
||||
if(tagMap.containsKey(tag)) {
|
||||
ddItem = tagMap.get(tag);
|
||||
}else {
|
||||
// 字典表里没有则新增标签
|
||||
ddItem = new DataDictItem();
|
||||
ddItem.setDictid(dictId);
|
||||
ddItem.setName(tag);
|
||||
ddItem.setValue(tag);
|
||||
dataDictMapper.insertDataDictItem(ddItem);
|
||||
}
|
||||
ContentTags label = new ContentTags();
|
||||
label.setCid(cid);
|
||||
label.setTid(ddItem.getId());
|
||||
newTagList.add(label);
|
||||
}
|
||||
}
|
||||
mapper.deleteTags(cid);
|
||||
if(o.getTagLists() != null){
|
||||
String[] tagList1 = o.getTagLists();
|
||||
for (String s : tagList1) {
|
||||
ContentTags contentTags = new ContentTags();
|
||||
contentTags.setCid(cid);
|
||||
contentTags.setTid(Long.parseLong(s));
|
||||
newTagList.add(contentTags);
|
||||
}
|
||||
}
|
||||
if(newTagList.size() > 0)mapper.insertContentTags(newTagList);
|
||||
|
||||
|
||||
List<ContentImages> imgList = new ArrayList<ContentImages>();
|
||||
String images = o.getImages();
|
||||
if(StringUtils.isNotBlank(images)){
|
||||
JSONArray array = JSONArray.parseArray(images);
|
||||
for(int i=0, j=array.size();i<j;i++){
|
||||
JSONObject obj = array.getJSONObject(i);
|
||||
ContentImages contentImages = new ContentImages();
|
||||
contentImages.setCid(cid);
|
||||
contentImages.setSort(obj.getIntValue("sort"));
|
||||
contentImages.setImgurl(obj.getString("imgurl"));
|
||||
contentImages.setOri_name(obj.getString("filename"));
|
||||
imgList.add(contentImages);
|
||||
}
|
||||
}
|
||||
mapper.deleteImages(cid);
|
||||
if(imgList.size() > 0){
|
||||
mapper.insertContentImages(imgList);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void add(Content entity) {
|
||||
baseSaveVerify(entity);
|
||||
entity.setType(null);
|
||||
mapper.insertSelective(entity);
|
||||
updateLabelAndImages(entity);
|
||||
|
||||
// 提交到ElasticSearch
|
||||
entity = findById(entity.getId());
|
||||
esService.merge(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void update(Content entity) {
|
||||
baseSaveVerify(entity);
|
||||
entity.setType(null);
|
||||
mapper.updateByPrimaryKeySelective(entity);
|
||||
updateLabelAndImages(entity);
|
||||
|
||||
// 提交到ElasticSearch
|
||||
entity = findById(entity.getId());
|
||||
esService.merge(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(List<Long> ids) {
|
||||
if(ids == null || ids.isEmpty()){
|
||||
throw new ParameterException("id不能为空");
|
||||
}
|
||||
// 从数据库中删除
|
||||
mapper.deleteByIds(ids);
|
||||
// 从ES中删除
|
||||
esService.deleteDocByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content findById(Long id) {
|
||||
if(id == null || id < 1){
|
||||
throw new ParameterException("id不能为空");
|
||||
}
|
||||
Content entity = mapper.findById(id);
|
||||
if(entity!=null&&entity.getId()!=null&&entity.getId()>0) {
|
||||
if(entity.getImgList()!=null)entity.setImages(JSON.toJSONString(entity.getImgList()));
|
||||
if(entity.getTagList()!=null)entity.setTags(JSON.toJSONString(entity.getTagList()));
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Content> getList(Content entity) {
|
||||
return mapper.getList(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Content> getListByFront(Content entity) {
|
||||
return mapper.getListByFront(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateContentNum(String type, Long id) {
|
||||
if(StringUtils.isBlank(type)){
|
||||
throw new ParameterException("类型不能为空");
|
||||
}
|
||||
if(id == null || id < 1){
|
||||
throw new ParameterException("id不能为空");
|
||||
}
|
||||
mapper.updateContentNum(type, id);
|
||||
Content entity = findById(id);
|
||||
|
||||
// 提交到ElasticSearch
|
||||
esService.merge(entity);
|
||||
|
||||
Integer result = 0;
|
||||
if("view".equals(type)){
|
||||
result = entity.getViewno();
|
||||
}else if("like".equals(type)){
|
||||
result = entity.getPraiseno();
|
||||
}
|
||||
if(result == null)result=1;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long syncEsData(Content entity, boolean isReBuild) {
|
||||
if(StringUtils.isBlank(entity.getType())) {
|
||||
throw new ParameterException("案例类型不能为空");
|
||||
}
|
||||
if(isReBuild) {
|
||||
// 如果重建索引,则先把所有记录删除,这个也可用于删除脏数据。
|
||||
esService.deleteDocByQuery(entity);
|
||||
}
|
||||
PageHelper.startPage(1, 1000);
|
||||
List<Content> dataList = getListByFront(entity);
|
||||
PageInfo<Content> pages = new PageInfo<>(dataList);
|
||||
for (Content content : dataList) {
|
||||
// 提交到ElasticSearch
|
||||
esService.merge(content);
|
||||
}
|
||||
return pages.getTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Content> getCaseTitle(Integer page,Integer pageSize) {
|
||||
PageHelper.startPage(page,pageSize);
|
||||
List<Content> list = mapper.getCaseTitle();
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContentTags(ContentTags contentTags) {
|
||||
mapper.addContentTags(contentTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDictItem> getOtherLabels() {
|
||||
List<DataDictItem> list = mapper.getOtherLabels();
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContentTags(List<Long> idList) {
|
||||
mapper.deleteContentTags(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLabelFeedback(Long contentId) {
|
||||
mapper.updateLabelFeedback(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Content> getList2(Content entity) {
|
||||
return mapper.getList2(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateComments(Long contentId) {
|
||||
mapper.updateComments(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveScore(Long userId, Long contentId, Double score) {
|
||||
mapper.saveScore(userId,contentId,score);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScore(Long userId, Long contentId) {
|
||||
return mapper.getScore(userId,contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content getEditContent(Long contentId) {
|
||||
return mapper.getEditContent(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveApplication(Application application) {
|
||||
//添加审核申请单
|
||||
mapper.saveApplication(application);
|
||||
//添加审核人信息
|
||||
Check check = new Check();
|
||||
check.setApplicationId(application.getId());
|
||||
List<Check> checks = application.getChecks();
|
||||
if(checks == null ) throw new ParameterException("审核人不能为空!");
|
||||
for (Check check1 : checks) {
|
||||
check.setCheckId(check1.getCheckId());
|
||||
mapper.saveCheck(check);
|
||||
}
|
||||
//更新案例状态(审核可能是下架重新申请的)
|
||||
mapper.updateContentRelease(application.getContentId(),1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getApplicationCount(Long contentId) {
|
||||
return mapper.getApplicationCount(contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteApplication(Long applicationId) {
|
||||
//删除案例审核申请
|
||||
mapper.deleteApplication(applicationId);
|
||||
//删除审核人信息
|
||||
mapper.deleteCheck(applicationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateApplicationStatus(Long applicationId) {
|
||||
//更新审核申请单状态
|
||||
mapper.updateApplicationStatus(applicationId);
|
||||
//更新审核人状态
|
||||
mapper.updateCheckStatus(applicationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Content> getContentApplication(Content entity) {
|
||||
return mapper.getContentApplication(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateApplication(Check check, Long userId) {
|
||||
//更新审核表状态
|
||||
check.setCheckId(userId);
|
||||
mapper.updateCheck(check);
|
||||
Application application = new Application();
|
||||
application.setId(check.getApplicationId());
|
||||
//更新申请单状态
|
||||
if(check.getStatus() == 2){
|
||||
//审核通过
|
||||
application.setStatus(2);
|
||||
//查询案例id
|
||||
Long contentId = mapper.getContentId(check.getApplicationId());
|
||||
//更新案例状态
|
||||
mapper.updateContentRelease(contentId,2);
|
||||
}else {
|
||||
//审核驳回
|
||||
application.setStatus(3);
|
||||
}
|
||||
mapper.updateApplication(application);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxUser getQyWxUser(String username) {
|
||||
return wxMapper.getQyWxUser(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Check> getUserLeader(String department) {
|
||||
return wxMapper.getUserLeader(department);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteRelease(Long contentId) {
|
||||
//根据案例id查询申请单信息
|
||||
Application application = mapper.getApplication(contentId);
|
||||
//删除申请单信息
|
||||
mapper.deleteApplication(application.getId());
|
||||
//删除审核表信息
|
||||
mapper.deleteCheck(application.getId());
|
||||
//案例表状态修改为已下线
|
||||
mapper.updateContentRelease(contentId,4);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,146 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.nbclass.activity.mapper.DataDictItemMapper;
|
||||
import com.nbclass.activity.mapper.DataDictMapper;
|
||||
import com.nbclass.activity.model.DataDict;
|
||||
import com.nbclass.activity.model.DataDictItem;
|
||||
import com.nbclass.activity.service.DataDictService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2020年5月28日 下午3:23:26
|
||||
*/
|
||||
@Service
|
||||
public class DataDictServiceImpl implements DataDictService {
|
||||
|
||||
@Resource
|
||||
private DataDictMapper mapper;
|
||||
|
||||
@Resource
|
||||
DataDictItemMapper dataDictItemMapper;
|
||||
|
||||
private void baseSaveVerify(DataDict entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DataDict entity) {
|
||||
baseSaveVerify(entity);
|
||||
mapper.insertSelective(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DataDict entity) {
|
||||
baseSaveVerify(entity);
|
||||
mapper.updateByPrimaryKeySelective(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(List<Long> ids) {
|
||||
if(ids == null || ids.isEmpty()){
|
||||
throw new ParameterException("id不能为空");
|
||||
}
|
||||
Long cnt = mapper.delCheck(ids);
|
||||
if(cnt!=null && cnt>0) {
|
||||
throw new ParameterException("请先删除子项再删除字典!");
|
||||
}
|
||||
Long dataDictID = mapper.getDataDictID();
|
||||
for (Long id : ids) {
|
||||
if(dataDictID.equals(id)) throw new ParameterException("该字典不可删除!");
|
||||
}
|
||||
mapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataDict findById(Long id) {
|
||||
if(id == null || id < 1){
|
||||
throw new ParameterException("id不能为空");
|
||||
}
|
||||
DataDict search = new DataDict();
|
||||
search.setId(id);
|
||||
DataDict entity = mapper.selectOne(search);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDict> getList(DataDict entity) {
|
||||
return mapper.getList(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDictItem> getItemsByKey(String datakey) {
|
||||
if(StringUtils.isBlank(datakey)) {
|
||||
throw new ParameterException("参数不能为空");
|
||||
}
|
||||
return mapper.getItemsByKey(datakey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDictItem> getItemList(DataDictItem entity) {
|
||||
return dataDictItemMapper.getList(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeDataDictItem(DataDictItem entity) {
|
||||
if(entity.getDictid() == null || entity.getDictid() < 1) {
|
||||
throw new ParameterException("字典ID不能为空");
|
||||
}
|
||||
if(StringUtils.isBlank(entity.getValue())) {
|
||||
throw new ParameterException("编码不能为空");
|
||||
}
|
||||
if(StringUtils.isBlank(entity.getName())) {
|
||||
throw new ParameterException("名称不能为空");
|
||||
}
|
||||
|
||||
Long cnt = dataDictItemMapper.checkExist(entity);
|
||||
if(cnt!=null && cnt>0) {
|
||||
throw new ParameterException("该记录已存在");
|
||||
}
|
||||
if(entity.getId()!=null && entity.getId()>0) {
|
||||
dataDictItemMapper.updateByPrimaryKeySelective(entity);
|
||||
}else {
|
||||
entity.setId(null);
|
||||
dataDictItemMapper.insertSelective(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDataDictItem(Long id) {
|
||||
if(id == null || id < 1) {
|
||||
throw new ParameterException("ID不能为空");
|
||||
}
|
||||
Long cnt = dataDictItemMapper.checkContentTag(id);
|
||||
if(cnt!=null && cnt>0) {
|
||||
throw new ParameterException("该标签正在使用,请先从案例中解除此标签");
|
||||
}
|
||||
|
||||
Long cnt2 = dataDictItemMapper.checkContentFrom(id);
|
||||
if(cnt2!=null && cnt2>0) {
|
||||
throw new ParameterException("该案例来源正在使用,请先从案例中解除此来源");
|
||||
}
|
||||
|
||||
dataDictItemMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContentTags> getDropDownBox() {
|
||||
return dataDictItemMapper.getDropDownBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTagId(String name) {
|
||||
return dataDictItemMapper.getTagId(name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,349 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.activity.model.Content;
|
||||
import com.nbclass.activity.model.ContentTags;
|
||||
import com.nbclass.activity.service.ContentService;
|
||||
import com.nbclass.activity.service.ElasticSearchService;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.exception.ServiceException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 案例内容ES操作
|
||||
* @author Leon
|
||||
* @datetime 2020年6月1日 下午3:02:00
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ElasticSearchServiceImpl implements ElasticSearchService {
|
||||
|
||||
@Resource
|
||||
private RestHighLevelClient restHighLevelClient;
|
||||
|
||||
@Resource
|
||||
private ContentService contentService;
|
||||
|
||||
private static final String es_index_content = "es-cases-content";
|
||||
|
||||
|
||||
/**
|
||||
* 检查索引是否存在
|
||||
* @throws IOException
|
||||
*/
|
||||
private boolean existIndex() throws IOException{
|
||||
GetIndexRequest request = new GetIndexRequest().indices(es_index_content);
|
||||
@SuppressWarnings("deprecation")
|
||||
boolean exists = restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT);
|
||||
return exists;
|
||||
}
|
||||
|
||||
// 创建索引
|
||||
public void createIndex(){
|
||||
try {
|
||||
// 检查索引是否存在
|
||||
if(existIndex())return;
|
||||
|
||||
CreateIndexRequest indexRequest = new CreateIndexRequest(es_index_content);
|
||||
CreateIndexResponse indexResponse = restHighLevelClient.indices().create(indexRequest, RequestOptions.DEFAULT);
|
||||
log.info("创建索引, 返回值=>{}, 确认状态=>{}", indexResponse.index(), indexResponse.isAcknowledged());
|
||||
}catch (Exception e) {
|
||||
log.info("创建索引异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除索引
|
||||
public void deleteIndex(){
|
||||
try {
|
||||
DeleteIndexRequest indexRequest = new DeleteIndexRequest(es_index_content);
|
||||
AcknowledgedResponse delete = restHighLevelClient.indices().delete(indexRequest, RequestOptions.DEFAULT);
|
||||
log.info("删除索引, 返回值=>{}, 确认状态=>{}", delete.isFragment(), delete.isAcknowledged());
|
||||
}catch (Exception e) {
|
||||
log.info("删除索引异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建或者更新文档
|
||||
@Override
|
||||
public void merge(Content entity) {
|
||||
try {
|
||||
if(entity!=null && entity.getTagList()!=null && entity.getTagList().size()>0) {
|
||||
String tags = "";
|
||||
for(ContentTags tag : entity.getTagList()) {
|
||||
if(StringUtils.isBlank(tag.getTagName()))continue;
|
||||
tags += (StringUtils.isBlank(tags)?"":",")+tag.getTagName();
|
||||
}
|
||||
entity.setTags(tags); // 将标签组到字符串里,便于搜索。
|
||||
}
|
||||
|
||||
createIndex(); // 判断索引是否存在,不存在创建索引
|
||||
|
||||
// 判断document是否存在,存在修改,不存在新增
|
||||
GetRequest getRequest = new GetRequest(es_index_content, String.valueOf(entity.getId()));
|
||||
boolean exists = restHighLevelClient.exists(getRequest, RequestOptions.DEFAULT);
|
||||
if(!exists) {
|
||||
// 创建文档索引
|
||||
IndexRequest indexRequest = new IndexRequest(es_index_content);
|
||||
indexRequest.id(String.valueOf(entity.getId())).source(JSON.toJSONString(entity), XContentType.JSON);
|
||||
@SuppressWarnings("unused")
|
||||
IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
|
||||
log.info("添加文档,新建ES索引成功,id = " + entity.getId());
|
||||
}else {
|
||||
// 修改文档索引
|
||||
UpdateRequest updateRequest = new UpdateRequest(es_index_content, String.valueOf(entity.getId()));
|
||||
updateRequest.doc(JSON.toJSONString(entity), XContentType.JSON);
|
||||
@SuppressWarnings("unused")
|
||||
UpdateResponse updateResponse = restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
|
||||
log.info("修改文档,重建ES索引成功,id = " + entity.getId());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("添加文档,新建ES索引失败,id = " + entity.getId(), e);
|
||||
throw new ServiceException("案例更新ES索引失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDocByIds(List<Long> ids) {
|
||||
if(ids == null || ids.isEmpty()){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (Long id : ids) {
|
||||
// DeleteRequest
|
||||
DeleteRequest deleteRequest = new DeleteRequest(es_index_content, String.valueOf(id));
|
||||
@SuppressWarnings("unused")
|
||||
DeleteResponse deleteResponse = restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("删除案例ES索引失败", e);
|
||||
throw new ServiceException("删除案例ES索引失败");
|
||||
}
|
||||
}
|
||||
|
||||
// matchQuery:会将搜索词分词,再与目标查询字段进行匹配,若分词中的任意一个词与目标字段匹配上,则可查询到。
|
||||
// termQuery:不会对搜索词进行分词处理,而是作为一个整体与目标字段进行匹配,若完全匹配,则可查询到。
|
||||
@Override
|
||||
public void deleteDocByQuery(Content entity) {
|
||||
if(entity.getType()!=null) {
|
||||
throw new ParameterException("案例类型不能为空");
|
||||
}
|
||||
try {
|
||||
DeleteByQueryRequest request = new DeleteByQueryRequest(es_index_content);
|
||||
request.setConflicts("proceed"); // 发生冲突即略过
|
||||
request.setQuery(QueryBuilders.termQuery("type", entity.getType()));
|
||||
BulkByScrollResponse bulkResponse = restHighLevelClient.deleteByQuery(request, RequestOptions.DEFAULT);
|
||||
|
||||
TimeValue timeTaken = bulkResponse.getTook();
|
||||
boolean timedOut = bulkResponse.isTimedOut();
|
||||
long totalDocs = bulkResponse.getTotal();
|
||||
long updatedDocs = bulkResponse.getUpdated();
|
||||
long deletedDocs = bulkResponse.getDeleted();
|
||||
long batches = bulkResponse.getBatches();
|
||||
long noops = bulkResponse.getNoops();
|
||||
long versionConflicts = bulkResponse.getVersionConflicts();
|
||||
log.info("根据案例类型删除文档,花费时间:" + timeTaken + ",是否超时:" + timedOut + ",总文档数:" + totalDocs + ",更新数:" +
|
||||
updatedDocs + ",删除数:" + deletedDocs + ",批量次数:" + batches + ",跳过数:" + noops + ",冲突数:" + versionConflicts);
|
||||
} catch (IOException e) {
|
||||
log.error("根据案例类型删除文档异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existDoc(Long id){
|
||||
boolean exists = false;
|
||||
GetRequest getRequest = new GetRequest(es_index_content, String.valueOf(id));
|
||||
try {
|
||||
exists = restHighLevelClient.exists(getRequest, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
// 获取文档
|
||||
@Override
|
||||
public Content findById(Long id) {
|
||||
// GetRequest
|
||||
GetRequest getRequest = new GetRequest(es_index_content, String.valueOf(id));
|
||||
// 查询ES
|
||||
GetResponse getResponse;
|
||||
Content content = null;
|
||||
try {
|
||||
getResponse = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
|
||||
content = JSON.parseObject(getResponse.getSourceAsString(), Content.class);
|
||||
if(content == null) {
|
||||
content = contentService.findById(id);
|
||||
}
|
||||
if(content!=null && content.getId()!=null && content.getId()>0) {
|
||||
content.setTags(null);
|
||||
content.setImages(null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("从ES查询数据失败", e);
|
||||
throw new ServiceException("从ES查询数据失败");
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库查询
|
||||
* @return
|
||||
*/
|
||||
private JSONObject getListByMySQL(Integer pageNum, Integer pageSize, String type, String keyWord, String tagIds, String sourceIds) {
|
||||
JSONObject result = new JSONObject();
|
||||
Content param = new Content();
|
||||
param.setType(type);
|
||||
param.setTitle(keyWord);
|
||||
param.setTags(tagIds);
|
||||
param.setFromids(sourceIds);
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Content> dataList = contentService.getListByFront(param);
|
||||
PageInfo<Content> pages = new PageInfo<>(dataList);
|
||||
if(dataList!=null && dataList.size()>0) {
|
||||
for (Content entity : dataList) {
|
||||
// 清空一些前端用不上的字段
|
||||
entity.setTags(null);
|
||||
entity.setImages(null);
|
||||
entity.setImgList(null);
|
||||
}
|
||||
}
|
||||
|
||||
result.put("total", pages.getTotal()); // 总记录数
|
||||
result.put("rows", dataList); // 数据体
|
||||
int totalPage = (int)(pages.getTotal() % pageSize==0 ? pages.getTotal()/pageSize : pages.getTotal()/pageSize+1);
|
||||
result.put("totalPage", totalPage); // 总页数
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getList(Integer pageNum, Integer pageSize, String type, String keyWord, String tagIds, String sourceIds) {
|
||||
// 封装Map参数返回
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
// 选择标签或来源过滤时,从数据库查询记录
|
||||
/*if(StringUtils.isNotBlank(tagIds) || StringUtils.isNotBlank(sourceIds)) {
|
||||
return getListByMySQL(pageNum, pageSize, type, keyWord, tagIds, sourceIds);
|
||||
}*/
|
||||
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
// 分页采用简单的from + size分页,适用数据量小的,了解更多分页方式可自行查阅资料
|
||||
searchSourceBuilder.from((pageNum - 1) * pageSize); // 从0开始
|
||||
searchSourceBuilder.size(pageSize);
|
||||
|
||||
// 查询条件,只有查询关键字不为空才带查询条件
|
||||
if (StringUtils.isNoneBlank(keyWord)) {
|
||||
// QueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword, "name", "desc");
|
||||
// searchSourceBuilder.query(queryBuilder);
|
||||
}
|
||||
|
||||
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
||||
if(StringUtils.isNotBlank(type)) { // 案例类型
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery("type", type));
|
||||
if (StringUtils.isNoneBlank(keyWord)){
|
||||
BoolQueryBuilder keywordQuery = QueryBuilders.boolQuery();
|
||||
keywordQuery.should(QueryBuilders.matchQuery("title", keyWord));
|
||||
keywordQuery.should(QueryBuilders.matchQuery("desct", keyWord));
|
||||
keywordQuery.should(QueryBuilders.matchQuery("fromName", keyWord));
|
||||
keywordQuery.should(QueryBuilders.matchQuery("tags", keyWord));
|
||||
keywordQuery.should(QueryBuilders.matchQuery("content_text", keyWord));
|
||||
boolQueryBuilder.must(keywordQuery);
|
||||
}
|
||||
}else {
|
||||
if (StringUtils.isNoneBlank(keyWord)){
|
||||
boolQueryBuilder.should(QueryBuilders.matchQuery("title", keyWord)); //.boost(3) // 给name字段更高的权重
|
||||
boolQueryBuilder.should(QueryBuilders.matchQuery("desct", keyWord)); // description 默认权重 1
|
||||
boolQueryBuilder.should(QueryBuilders.matchQuery("fromName", keyWord));
|
||||
boolQueryBuilder.should(QueryBuilders.matchQuery("tags", keyWord));
|
||||
boolQueryBuilder.should(QueryBuilders.matchQuery("content_text", keyWord));
|
||||
boolQueryBuilder.minimumShouldMatch(1); // 至少一个should条件满足
|
||||
}
|
||||
}
|
||||
//选择标签或来源过滤
|
||||
if(StringUtils.isNotBlank(tagIds)){
|
||||
List<String> tagIdList = Arrays.asList(tagIds.split(","));
|
||||
for(String tagId:tagIdList) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery("tagList.id", tagId));
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(sourceIds)){
|
||||
List<String> sourIdList = Arrays.asList(sourceIds.split(","));
|
||||
for(String sourId:sourIdList) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery("fromid", sourId));
|
||||
}
|
||||
}
|
||||
searchSourceBuilder.query(boolQueryBuilder);
|
||||
|
||||
|
||||
// 排序,根据ID倒叙
|
||||
searchSourceBuilder.sort("id", SortOrder.DESC);
|
||||
// SearchRequest
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
// 查询ES
|
||||
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
SearchHits hits = searchResponse.getHits();
|
||||
// 获取总数
|
||||
Long total = hits.getTotalHits().value;
|
||||
// 遍历封装列表对象
|
||||
List<Content> dataList = new ArrayList<>();
|
||||
SearchHit[] searchHits = hits.getHits();
|
||||
for (SearchHit searchHit : searchHits) {
|
||||
Content entity = JSON.parseObject(searchHit.getSourceAsString(), Content.class);
|
||||
// 清空一些前端用不上的字段
|
||||
entity.setTags(null);
|
||||
entity.setImages(null);
|
||||
entity.setImgList(null);
|
||||
dataList.add(entity);
|
||||
}
|
||||
result.put("total", total); // 总记录数
|
||||
result.put("rows", dataList); // 数据体
|
||||
int totalPage = (int)(total % pageSize==0 ? total/pageSize : total/pageSize+1);
|
||||
result.put("totalPage", totalPage); // 总页数
|
||||
}catch (Exception e) {
|
||||
log.error("从es查询数据列表异常", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import com.nbclass.activity.mapper.WXMapper;
|
||||
import com.nbclass.activity.model.WeiXiUser;
|
||||
import com.nbclass.activity.service.WxService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class WxServiceImpl implements WxService {
|
||||
|
||||
@Autowired
|
||||
private WXMapper wxMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public int getOpenId(String openid) {
|
||||
return wxMapper.getOpenId(openid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWxUser(WeiXiUser weiXiUser) {
|
||||
wxMapper.saveWxUser(weiXiUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeiXiUser getWxUser(String openid) {
|
||||
return wxMapper.getWxUser(openid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeiXiUser getUser(String userId) {
|
||||
return wxMapper.getUser(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBasicData(WeiXiUser weiXiUser) {
|
||||
wxMapper.updateBasicData(weiXiUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeiXiUser getUserBasicData(Long userId) {
|
||||
return wxMapper.getUserBasicData(userId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,145 @@
|
||||
package com.nbclass.activity.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.activity.constant.Const;
|
||||
import com.nbclass.activity.mapper.WxDepartmentMapper;
|
||||
import com.nbclass.activity.mapper.WxUserMapper;
|
||||
import com.nbclass.activity.model.WxDepartment;
|
||||
import com.nbclass.activity.model.WxUser;
|
||||
import com.nbclass.activity.service.WxUserService;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.HttpUtils;
|
||||
import com.nbclass.util.PasswordHelper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WxUserServiceImpl implements WxUserService {
|
||||
|
||||
@Resource
|
||||
private WxUserMapper wxUserMapper;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private WxDepartmentMapper deptMapper;
|
||||
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void merge(List<WxUser> userList){
|
||||
if(userList == null || userList.size() == 0)return;
|
||||
|
||||
List<String> dbUserIds = wxUserMapper.getUserIds(); // 查询数据库已有的数据
|
||||
List<String> existIds = new ArrayList<String>();
|
||||
for (WxUser wxUser : userList) {
|
||||
User account = new User();
|
||||
account.setUserId(wxUser.getName()); // 将姓名存储到userid字段
|
||||
account.setUsername(wxUser.getUserid()); // 企业微信userid,作为登录账号
|
||||
account.setPassword("password");
|
||||
account.setEmail(wxUser.getEmail());
|
||||
account.setPhone(wxUser.getMobile());
|
||||
account.setSex(StringUtils.isBlank(wxUser.getGender()) ? null : Integer.parseInt(wxUser.getGender()));
|
||||
account.setStatus(1);
|
||||
account.setPassword("szxgl.cn"); // 默认登录密码
|
||||
PasswordHelper.encryptPassword(account);
|
||||
|
||||
existIds.add(wxUser.getUserid());
|
||||
if(dbUserIds.contains(wxUser.getUserid())){
|
||||
wxUserMapper.updateByUserId(wxUser);
|
||||
}else{
|
||||
wxUserMapper.insertSelective(wxUser);
|
||||
}
|
||||
userService.updateQyWxUser(account);
|
||||
}
|
||||
// 删除当前企业微信不存在的用户
|
||||
if(existIds.size()>0)wxUserMapper.delOtherUsers(existIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncWxUser() {
|
||||
try {
|
||||
String url = Const.QYWX_API_DOMAIN + "/open/api/user/list?secretKey=yunlei.888";
|
||||
JSONObject jsonObject = HttpUtils.httpPost(url);
|
||||
if(jsonObject !=null && jsonObject.getIntValue("ret") == 0){
|
||||
List<WxUser> userList = new ArrayList<WxUser>();
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("list");
|
||||
if(jsonArray!=null && jsonArray.size() > 0){
|
||||
/*
|
||||
for(int i=0; i<jsonArray.size(); i++){
|
||||
JSONObject obj = jsonArray.getJSONObject(i);
|
||||
WxUser wxUser = new WxUser();
|
||||
wxUser.setUserid(obj.getString("userID"));
|
||||
wxUser.setName(obj.getString("name"));
|
||||
wxUser.setMobile(obj.getString("Mobile"));
|
||||
wxUser.setDepartment(obj.getString("Department"));
|
||||
wxUser.setPosition(obj.getString("Position"));
|
||||
wxUser.setGender(obj.getString("Gender"));
|
||||
wxUser.setEmail(obj.getString("Email"));
|
||||
wxUser.setIsleader(obj.getString("IsLeader"));
|
||||
wxUser.setAvatar(obj.getString("Avatar"));
|
||||
wxUser.setEnglish_name(obj.getString("EnglishName"));
|
||||
wxUser.setStatus(obj.getInteger("Status"));
|
||||
userList.add(wxUser);
|
||||
}
|
||||
*/
|
||||
for (Object object : jsonArray) {
|
||||
WxUser wxUser = JSON.toJavaObject((JSONObject)object, WxUser.class);
|
||||
userList.add(wxUser);
|
||||
}
|
||||
}
|
||||
merge(userList);
|
||||
log.info("同步企业成员成功,成员数量为:"+userList.size());
|
||||
}else{
|
||||
log.error("同步企业成员出错: "+jsonObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("同步企业成员异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncWxDepartment() {
|
||||
try {
|
||||
String url = Const.QYWX_API_DOMAIN + "/open/api/department/list?secretKey=yunlei.888";
|
||||
JSONObject jsonObject = HttpUtils.httpPost(url, "POST");
|
||||
if(jsonObject !=null && jsonObject.getIntValue("ret") == 0){
|
||||
List<WxDepartment> list = new ArrayList<WxDepartment>();
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("list");
|
||||
if(jsonArray!=null && jsonArray.size() > 0){
|
||||
for (Object object : jsonArray) {
|
||||
WxDepartment wxDepartment = JSON.toJavaObject((JSONObject)object, WxDepartment.class);
|
||||
list.add(wxDepartment);
|
||||
}
|
||||
}
|
||||
if(list.size() > 0)deptMapper.insertBatch(list);
|
||||
log.info("同步企业部门成功,部门数量为:"+list.size());
|
||||
}else{
|
||||
log.error("同步企业部门出错: "+jsonObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("同步企业部门异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String jsonstr = "{\"id\":1,\"Name\":\"信广龙\",\"Order\":100000000,\"parentId\":5}";
|
||||
WxDepartment wxUser = JSON.toJavaObject(JSONObject.parseObject(jsonstr), WxDepartment.class);
|
||||
System.out.println(JSON.toJSON(wxUser));
|
||||
}
|
||||
|
||||
}
|
||||
25
src/main/java/com/nbclass/activity/task/ActivityRunner.java
Normal file
25
src/main/java/com/nbclass/activity/task/ActivityRunner.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.nbclass.activity.task;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 启动时加载的任务
|
||||
* Created by Leon on 2019/12/11 15:10
|
||||
*/
|
||||
@Component
|
||||
@Order(1)
|
||||
public class ActivityRunner implements ApplicationRunner {
|
||||
|
||||
//@Resource
|
||||
// private UserInfoService userInfoService;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
public void run(ApplicationArguments appArgs) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package com.nbclass.activity.task;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.nbclass.activity.service.WxUserService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
* @author Leon
|
||||
* @datetime 2020年6月2日 下午6:53:05
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@EnableScheduling // 1.开启定时任务
|
||||
@EnableAsync // 2.开启多线程/异步注解
|
||||
public class MultiThreadScheduleTask {
|
||||
|
||||
@Resource
|
||||
private WxUserService wxUserService;
|
||||
|
||||
/**
|
||||
* 定时同步企业微信用户
|
||||
*/
|
||||
@Async
|
||||
@Scheduled(cron="0 0 */6 * * ? ") // 每6小时运行一次
|
||||
public void syncWxUser() {
|
||||
log.info("同步企业微信用户 ......");
|
||||
wxUserService.syncWxUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时同步企业微信部门
|
||||
*/
|
||||
@Async
|
||||
/* @Scheduled(fixedDelay = 1000*120) */
|
||||
@Scheduled(cron="0 0 1 * * ?") // 每天凌晨1点执行一次
|
||||
public void syncWxDepartment() {
|
||||
log.info("同步企业微信部门 ......");
|
||||
wxUserService.syncWxDepartment();
|
||||
}
|
||||
|
||||
/**
|
||||
* 每天中午12点触发:0 0 12 * * ?
|
||||
* 每天凌晨1点执行一次:0 0 1 * * ?
|
||||
* 每隔1分钟执行一次:0 *\/1 * * * ?
|
||||
*/
|
||||
|
||||
}
|
||||
40
src/main/java/com/nbclass/aliyun/sdk/AliyunConstant.java
Normal file
40
src/main/java/com/nbclass/aliyun/sdk/AliyunConstant.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.nbclass.aliyun.sdk;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2019年4月12日 下午5:27:12
|
||||
*/
|
||||
public class AliyunConstant {
|
||||
|
||||
// 编码类型
|
||||
public static final String ENCODE_TYPE = "UTF-8";
|
||||
// 阿里云API签名方式,目前支持HMAC-SHA1
|
||||
public static final String ALGORITHM = "HmacSHA1";
|
||||
|
||||
// AccessKey ID
|
||||
public static final String accessKeyId = "sSJ5t0yC1CaKhPJ4";
|
||||
// AccessKey Secret
|
||||
public static final String accessKeySecret = "PsbdUTexU95BkiqO4ADELXpIaYdWGk";
|
||||
|
||||
// 访问域名
|
||||
public static final String access_doamin = "https://szxgl.oss-cn-shenzhen.aliyuncs.com/";
|
||||
// endpoint外网地址
|
||||
public static final String endpoint_ww = "oss-cn-shenzhen.aliyuncs.com";
|
||||
// endpoint内网地址
|
||||
public static final String endpoint_nw = "oss-cn-shenzhen-internal.aliyuncs.com";
|
||||
// 区域ID
|
||||
public static final String regionId = "cn-shenzhen";
|
||||
// OSS区域
|
||||
public static final String ossLocation = "oss-cn-shenzhen";
|
||||
// OSS Bucket
|
||||
public static final String ossBucketName = "szxgl";
|
||||
|
||||
|
||||
/**
|
||||
* oss文件存放目录前缀
|
||||
*/
|
||||
public static final String key_prefix = "xgl-cases/";
|
||||
|
||||
|
||||
}
|
||||
174
src/main/java/com/nbclass/aliyun/sdk/AliyunOSSUtils.java
Normal file
174
src/main/java/com/nbclass/aliyun/sdk/AliyunOSSUtils.java
Normal file
@ -0,0 +1,174 @@
|
||||
package com.nbclass.aliyun.sdk;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.nbclass.exception.ParameterException;
|
||||
import com.nbclass.exception.ServiceException;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
|
||||
/**
|
||||
* 阿里云OSS操作
|
||||
* @author leiyun
|
||||
* @datetime 2017年1月17日 下午3:58:16
|
||||
*/
|
||||
public class AliyunOSSUtils {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AliyunOSSUtils.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean flag = true;
|
||||
deleteObject(AliyunConstant.key_prefix + "casetype-h5/attachments/202005/20200529104151_wsblg.jpg");
|
||||
if(flag)return;
|
||||
File file = new File("D:\\Temp\\images\\2.jpg");
|
||||
byte[] bt = Files.readAllBytes(file.toPath());
|
||||
String imgurl = uploadBytes("test","oppo.jpg", bt);
|
||||
System.out.println("imgurl="+imgurl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param key
|
||||
*/
|
||||
public static void deleteObject(String key){
|
||||
if(StringUtils.isBlank(key)) {
|
||||
throw new ParameterException("key不能为空");
|
||||
}
|
||||
OSSClient ossClient = null;
|
||||
try {
|
||||
// 创建OSSClient实例
|
||||
OSSClientBuilder builder = new OSSClientBuilder();
|
||||
// 国内服务器使用内网上传到oss
|
||||
if(CommonUtils.isNw()){
|
||||
// 使用内网节点
|
||||
ossClient = (OSSClient) builder.build(AliyunConstant.endpoint_nw, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
}else{
|
||||
// 使用外网节点
|
||||
ossClient = (OSSClient) builder.build(AliyunConstant.endpoint_ww, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
}
|
||||
ossClient.deleteObject(AliyunConstant.ossBucketName, key);
|
||||
} catch (RuntimeException e) {
|
||||
logger.error("阿里云OSS上传文件出错", e);
|
||||
throw new ServiceException("网络异常,请稍候再试!");
|
||||
} finally{
|
||||
if(ossClient!=null){
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传Byte数组
|
||||
* @param filename
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
public static String uploadBytes(String filename, byte[] content){
|
||||
return uploadBytes(null, filename, content);
|
||||
}
|
||||
|
||||
public static String uploadBytes(String key, String filename, byte[] content){
|
||||
String url = null;
|
||||
OSSClient ossClient = null;
|
||||
try {
|
||||
// 创建OSSClient实例
|
||||
// ossClient = new OSSClient(AliyunConstant.endpoint_nw, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
OSSClientBuilder builder = new OSSClientBuilder();
|
||||
|
||||
// 国内服务器使用内网上传到oss
|
||||
if(CommonUtils.isNw()){
|
||||
logger.info("上传文件到OSS, 使用内网节点");
|
||||
ossClient = (OSSClient) builder.build(AliyunConstant.endpoint_nw, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
}else{
|
||||
logger.info("上传文件到OSS, 使用外网节点");
|
||||
ossClient = (OSSClient) builder.build(AliyunConstant.endpoint_ww, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(key)){
|
||||
key = AliyunConstant.key_prefix + key +"/";
|
||||
}else{
|
||||
key = AliyunConstant.key_prefix;
|
||||
}
|
||||
// String daydir = Tools.getSimpleDate(new Date(), "yyyyMM")+"/";
|
||||
String daydir = "";
|
||||
key = key + daydir + filename;
|
||||
ossClient.putObject(AliyunConstant.ossBucketName, key, new ByteArrayInputStream(content));
|
||||
url = AliyunConstant.access_doamin + key;
|
||||
} catch (RuntimeException e) {
|
||||
logger.error("阿里云OSS上传文件出错", e);
|
||||
throw new ServiceException("网络异常,请稍候再试!");
|
||||
} finally{
|
||||
if(ossClient!=null){
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传网络流
|
||||
* @param filename
|
||||
* @param sourceUrl
|
||||
* @return
|
||||
*/
|
||||
public static String uploadByURL(String filename, String sourceUrl){
|
||||
if(StringUtils.isBlank(sourceUrl))return null;
|
||||
sourceUrl = sourceUrl.trim();
|
||||
if(!sourceUrl.startsWith("http://") && !sourceUrl.startsWith("https://"))return null;
|
||||
String url = null;
|
||||
OSSClient ossClient = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
// 创建OSSClient实例
|
||||
// ossClient = new OSSClient(AliyunConstant.endpoint_ww, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
OSSClientBuilder builder = new OSSClientBuilder();
|
||||
|
||||
// 国内服务器使用内网上传到oss
|
||||
if(CommonUtils.isNw()){
|
||||
logger.info("上传文件到OSS, 使用内网节点");
|
||||
ossClient = (OSSClient) builder.build(AliyunConstant.endpoint_nw, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
}else{
|
||||
logger.info("上传文件到OSS, 使用外网节点");
|
||||
ossClient = (OSSClient) builder.build(AliyunConstant.endpoint_ww, AliyunConstant.accessKeyId, AliyunConstant.accessKeySecret);
|
||||
|
||||
}
|
||||
|
||||
String daydir = CommonUtils.getSimpleDate(new Date(), "yyyyMM")+"/";
|
||||
String key = AliyunConstant.key_prefix + daydir + filename;
|
||||
// 上传网络流
|
||||
inputStream = new URL(sourceUrl).openStream();
|
||||
ossClient.putObject(AliyunConstant.ossBucketName, key, inputStream);
|
||||
|
||||
url = AliyunConstant.access_doamin + key;
|
||||
} catch (IOException | RuntimeException e) {
|
||||
logger.error("阿里云OSS上传文件出错", e);
|
||||
throw new ServiceException("网络异常,请稍候再试!");
|
||||
} finally{
|
||||
if(ossClient!=null){
|
||||
ossClient.shutdown();
|
||||
}
|
||||
try {
|
||||
if(inputStream!=null)inputStream.close();
|
||||
inputStream=null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
27
src/main/java/com/nbclass/component/MyErrorAttributes.java
Normal file
27
src/main/java/com/nbclass/component/MyErrorAttributes.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.nbclass.component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Component
|
||||
public class MyErrorAttributes extends DefaultErrorAttributes{
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Map<String,Object> map = super.getErrorAttributes(webRequest, includeStackTrace);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> ext = (Map<String,Object>)webRequest.getAttribute("ext", 0);
|
||||
map.put("ext",ext);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
31
src/main/java/com/nbclass/config/CorsConfig.java
Normal file
31
src/main/java/com/nbclass/config/CorsConfig.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.nbclass.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 跨域请求配置
|
||||
* @author Leon
|
||||
* @datetime 2019年4月3日 下午4:45:49
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry
|
||||
.addMapping("/api/**") // 允许跨域请求的地址
|
||||
.allowedOrigins("*") // 允许任何域请求
|
||||
.allowedMethods("*") // 允许任何方法(post、get等)
|
||||
.allowedHeaders("*") // 允许任何头
|
||||
.allowCredentials(true)
|
||||
;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
21
src/main/java/com/nbclass/config/DateConverter.java
Normal file
21
src/main/java/com/nbclass/config/DateConverter.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.nbclass.config;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@Component
|
||||
public class DateConverter implements Converter<String, Date> {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@Override
|
||||
public Date convert(String source) {
|
||||
try {
|
||||
return sdf.parse(source);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
23
src/main/java/com/nbclass/config/DefaultViewConfig.java
Normal file
23
src/main/java/com/nbclass/config/DefaultViewConfig.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.nbclass.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 默认首页
|
||||
* @author Leon
|
||||
* @datetime 2019年4月11日 下午5:14:24
|
||||
*/
|
||||
@Configuration
|
||||
public class DefaultViewConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("forward:/index.html");
|
||||
registry.setOrder(Ordered.HIGHEST_PRECEDENCE); // 设置为最高级,哪怕其他controller里有映射(也就是 /)那么根据优先级,也会先加载这个配置
|
||||
WebMvcConfigurer.super.addViewControllers(registry);
|
||||
}
|
||||
|
||||
}
|
||||
33
src/main/java/com/nbclass/enums/ResponseStatus.java
Normal file
33
src/main/java/com/nbclass/enums/ResponseStatus.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.nbclass.enums;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月13日
|
||||
* @author superzheng
|
||||
*/
|
||||
public enum ResponseStatus {
|
||||
|
||||
/**
|
||||
* 返回状态
|
||||
*/
|
||||
SUCCESS(200, "操作成功!"),
|
||||
FORBIDDEN(403, "您没有权限访问!"),
|
||||
NOT_FOUND(404, "资源不存在!"),
|
||||
ERROR(500, "服务器内部错误!");
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
ResponseStatus(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.nbclass.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.nbclass.vo.base.Result;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.util.CoreConst;
|
||||
|
||||
/**
|
||||
* 实现spring注解进行异常统一处理
|
||||
* @author Leon
|
||||
* @datetime 2019年3月5日 下午6:08:54
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class CommonExceptionAdvice {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CommonExceptionAdvice.class);
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public void defaultErrorHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String error = null;
|
||||
try {
|
||||
logger.info("RequestURL = "+request.getRequestURL());
|
||||
if(exception instanceof ParameterException || exception instanceof ServiceException || exception instanceof LogicalException){
|
||||
logger.info(exception.toString());
|
||||
}else if(exception instanceof org.springframework.web.multipart.MaxUploadSizeExceededException){
|
||||
error = "customer.file.upload.exceedlimit";
|
||||
}else{
|
||||
logger.error("系统异常: ", exception);
|
||||
}
|
||||
if(StringUtils.isBlank(error))error = exception.getMessage();
|
||||
|
||||
PrintWriter out = response.getWriter();
|
||||
if(StringUtils.isBlank(error)){
|
||||
response.setHeader("Content-Type", "text/html;charset=UTF-8");
|
||||
out.print("<div style=\"width:100%;margin-top:20px;text-align:center;\">Sorry, System error !</div>");
|
||||
}else{
|
||||
JSONObject json = new JSONObject();
|
||||
json.put(CoreConst.STATUS, CoreConst.STATUS_ERROR);
|
||||
json.put(CoreConst.MSG, error);
|
||||
out.print(json.toString());
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("统一处理异常错误", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ExceptionHandler(AuthorizationException.class)
|
||||
public String handleAuth(HttpServletRequest request) {
|
||||
request.setAttribute("javax.servlet.error.status_code",com.nbclass.enums.ResponseStatus.FORBIDDEN.getCode());
|
||||
return "forward:/error";
|
||||
}
|
||||
|
||||
@ExceptionHandler(ParameterException.class)
|
||||
@ResponseBody
|
||||
public Result ParameterException(RuntimeException runtimeException){
|
||||
return Result.error(runtimeException.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
26
src/main/java/com/nbclass/exception/DataBaseException.java
Normal file
26
src/main/java/com/nbclass/exception/DataBaseException.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.nbclass.exception;
|
||||
|
||||
/**
|
||||
* 数据库异常类
|
||||
* @author Leon
|
||||
* @datetime 2019年3月31日 下午11:17:35
|
||||
*/
|
||||
public class DataBaseException extends RuntimeException{
|
||||
|
||||
private static final long serialVersionUID = -7912461660403185962L;
|
||||
|
||||
public DataBaseException(){
|
||||
}
|
||||
|
||||
public DataBaseException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DataBaseException(String message){
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DataBaseException(Throwable cause){
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/nbclass/exception/LogicalException.java
Normal file
26
src/main/java/com/nbclass/exception/LogicalException.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.nbclass.exception;
|
||||
|
||||
/**
|
||||
* 业务逻辑异常类
|
||||
* @author Leon
|
||||
* @datetime 2019年3月31日 下午11:16:56
|
||||
*/
|
||||
public class LogicalException extends RuntimeException{
|
||||
|
||||
private static final long serialVersionUID = 2494732724125452953L;
|
||||
|
||||
public LogicalException(){
|
||||
}
|
||||
|
||||
public LogicalException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public LogicalException(String message){
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LogicalException(Throwable cause){
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/nbclass/exception/ParameterException.java
Normal file
26
src/main/java/com/nbclass/exception/ParameterException.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.nbclass.exception;
|
||||
|
||||
/**
|
||||
* 参数错误异常类
|
||||
* @author Leon
|
||||
* @datetime 2019年3月31日 下午11:01:35
|
||||
*/
|
||||
public class ParameterException extends RuntimeException{
|
||||
|
||||
private static final long serialVersionUID = 7936887727544416780L;
|
||||
|
||||
public ParameterException(){
|
||||
}
|
||||
|
||||
public ParameterException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ParameterException(String message){
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParameterException(Throwable cause){
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/nbclass/exception/ServiceException.java
Normal file
26
src/main/java/com/nbclass/exception/ServiceException.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.nbclass.exception;
|
||||
|
||||
/**
|
||||
* 服务异常类
|
||||
* @author Leon
|
||||
* @datetime 2019年3月31日 下午11:16:09
|
||||
*/
|
||||
public class ServiceException extends RuntimeException{
|
||||
|
||||
private static final long serialVersionUID = 3794850430751334041L;
|
||||
|
||||
public ServiceException(){
|
||||
}
|
||||
|
||||
public ServiceException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ServiceException(String message){
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ServiceException(Throwable cause){
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
53
src/main/java/com/nbclass/holder/SpringContextHolder.java
Normal file
53
src/main/java/com/nbclass/holder/SpringContextHolder.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.nbclass.holder;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringContextHolder implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext appContext = null;
|
||||
|
||||
/**
|
||||
* 通过name获取 Bean.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static Object getBean(String name) {
|
||||
return appContext.getBean(name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过class获取Bean.
|
||||
*
|
||||
* @param clazz
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getBean(Class<T> clazz) {
|
||||
return appContext.getBean(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过name,以及Clazz返回指定的Bean
|
||||
*
|
||||
* @param name
|
||||
* @param clazz
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getBean(String name, Class<T> clazz) {
|
||||
return appContext.getBean(name, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (appContext == null) {
|
||||
appContext = applicationContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
156
src/main/java/com/nbclass/shiro/MyShiroRealm.java
Normal file
156
src/main/java/com/nbclass/shiro/MyShiroRealm.java
Normal file
@ -0,0 +1,156 @@
|
||||
package com.nbclass.shiro;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.mgt.RealmSecurityManager;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.eis.SessionDAO;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.support.DefaultSubjectContext;
|
||||
import org.apache.shiro.util.ByteSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.service.PermissionService;
|
||||
import com.nbclass.system.service.RoleService;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.CoreConst;
|
||||
import com.nbclass.util.IpUtil;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
public class MyShiroRealm extends AuthorizingRealm {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
//@Autowired
|
||||
//private RedisSessionDAO redisSessionDAO;
|
||||
@Autowired
|
||||
private SessionDAO sessionDAO;
|
||||
|
||||
//授权
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
if(principals == null){
|
||||
throw new AuthorizationException("principals should not be null");
|
||||
}
|
||||
User user = (User) principals.getPrimaryPrincipal();
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.setRoles(roleService.findRoleByUserId(user.getUserId()));
|
||||
info.setStringPermissions(permissionService.findPermsByUserId(user.getUserId()));
|
||||
return info;
|
||||
}
|
||||
|
||||
//认证
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
|
||||
//获取用户的输入的账号.
|
||||
String username = (String)token.getPrincipal();
|
||||
User user = userService.selectByUsername(username);
|
||||
if(user==null) {
|
||||
throw new UnknownAccountException();
|
||||
}
|
||||
if (CoreConst.STATUS_INVALID.equals(user.getStatus())) {
|
||||
// 帐号锁定
|
||||
throw new LockedAccountException();
|
||||
}
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
// 把ip放入user存入redis缓存里
|
||||
user.setLoginIpAddress(IpUtil.getIpAddr(request));
|
||||
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
|
||||
user,
|
||||
user.getPassword(),
|
||||
ByteSource.Util.bytes(user.getCredentialsSalt()),
|
||||
getName()
|
||||
);
|
||||
return authenticationInfo;
|
||||
}
|
||||
|
||||
/**清除认证信息*/
|
||||
public void removeCachedAuthenticationInfo(List<String> userIds) {
|
||||
if(null == userIds || userIds.size() == 0) {
|
||||
return ;
|
||||
}
|
||||
List<SimplePrincipalCollection> list = getSpcListByUserIds(userIds);
|
||||
RealmSecurityManager securityManager =
|
||||
(RealmSecurityManager) SecurityUtils.getSecurityManager();
|
||||
MyShiroRealm realm = (MyShiroRealm)securityManager.getRealms().iterator().next();
|
||||
for (SimplePrincipalCollection simplePrincipalCollection : list) {
|
||||
realm.clearCachedAuthenticationInfo(simplePrincipalCollection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据userId 清除当前session存在的用户的权限缓存
|
||||
* @param userIds 已经修改了权限的userId
|
||||
*/
|
||||
public void clearAuthorizationByUserId(List<String> userIds){
|
||||
if(null == userIds || userIds.size() == 0) {
|
||||
return ;
|
||||
}
|
||||
List<SimplePrincipalCollection> list = getSpcListByUserIds(userIds);
|
||||
RealmSecurityManager securityManager =
|
||||
(RealmSecurityManager) SecurityUtils.getSecurityManager();
|
||||
MyShiroRealm realm = (MyShiroRealm)securityManager.getRealms().iterator().next();
|
||||
for (SimplePrincipalCollection simplePrincipalCollection : list) {
|
||||
realm.clearCachedAuthorizationInfo(simplePrincipalCollection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id获取所有spc
|
||||
* @param userIds 已经修改了权限的userId
|
||||
*/
|
||||
private List<SimplePrincipalCollection> getSpcListByUserIds(List<String> userIds){
|
||||
//获取所有session
|
||||
// Collection<Session> sessions = redisSessionDAO.getActiveSessions();
|
||||
Collection<Session> sessions = sessionDAO.getActiveSessions();
|
||||
//定义返回
|
||||
List<SimplePrincipalCollection> list = new ArrayList<SimplePrincipalCollection>();
|
||||
for (Session session:sessions){
|
||||
//获取session登录信息。
|
||||
Object obj = session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
|
||||
if(null != obj && obj instanceof SimplePrincipalCollection){
|
||||
//强转
|
||||
SimplePrincipalCollection spc = (SimplePrincipalCollection)obj;
|
||||
//判断用户,匹配用户ID。
|
||||
obj = spc.getPrimaryPrincipal();
|
||||
if(null != obj && obj instanceof User){
|
||||
User user = (User) obj;
|
||||
System.out.println("user:"+user);
|
||||
//比较用户ID,符合即加入集合
|
||||
if(null != user && userIds.contains(user.getUserId())){
|
||||
list.add(spc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
19
src/main/java/com/nbclass/shiro/PermsService.java
Normal file
19
src/main/java/com/nbclass/shiro/PermsService.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.nbclass.shiro;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* js调用 thymeleaf 实现按钮权限
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Component("perms")
|
||||
public class PermsService
|
||||
{
|
||||
public boolean hasPerm(String permission)
|
||||
{
|
||||
return SecurityUtils.getSubject().isPermitted(permission);
|
||||
}
|
||||
}
|
||||
125
src/main/java/com/nbclass/shiro/ShiroService.java
Normal file
125
src/main/java/com/nbclass/shiro/ShiroService.java
Normal file
@ -0,0 +1,125 @@
|
||||
package com.nbclass.shiro;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.filter.mgt.DefaultFilterChainManager;
|
||||
import org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver;
|
||||
import org.apache.shiro.web.servlet.AbstractShiroFilter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.nbclass.holder.SpringContextHolder;
|
||||
import com.nbclass.system.model.Permission;
|
||||
import com.nbclass.system.service.PermissionService;
|
||||
import com.nbclass.util.CoreConst;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2019年4月1日 下午2:47:53
|
||||
*/
|
||||
@Service
|
||||
public class ShiroService {
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 初始化加载权限
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> loadFilterChainDefinitions() {
|
||||
// 权限控制map.从数据库获取
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
|
||||
filterChainDefinitionMap.put("/register", "anon");
|
||||
filterChainDefinitionMap.put("/login", "anon");
|
||||
filterChainDefinitionMap.put("/error/**", "anon");
|
||||
filterChainDefinitionMap.put("/kickout", "anon");
|
||||
/*filterChainDefinitionMap.put("/logout", "logout");*/
|
||||
filterChainDefinitionMap.put("/verificationCode", "anon"); // 登录验证码
|
||||
filterChainDefinitionMap.put("/qywx/qrLogin", "anon"); // 企业微信登录页面
|
||||
|
||||
// 前端接口放行
|
||||
filterChainDefinitionMap.put("/front/api/**", "anon"); // 前端接口
|
||||
filterChainDefinitionMap.put("/", "anon"); // 网站首页
|
||||
filterChainDefinitionMap.put("/caseType/**", "anon"); // 数据字典
|
||||
filterChainDefinitionMap.put("/wx/**", "anon"); // wx接口
|
||||
filterChainDefinitionMap.put("/comment/**", "anon"); // wx接口
|
||||
filterChainDefinitionMap.put("/console/content/saveScore", "anon"); //
|
||||
|
||||
filterChainDefinitionMap.put("/mobile/*.html", "wxWebOAuth"); // 移动端页面授权拦截
|
||||
|
||||
// 静态资源按目录排除
|
||||
filterChainDefinitionMap.put("/css/**","anon");
|
||||
filterChainDefinitionMap.put("/js/**","anon");
|
||||
filterChainDefinitionMap.put("/img/**","anon");
|
||||
filterChainDefinitionMap.put("/libs/**","anon");
|
||||
// 静态资源按后缀排除
|
||||
filterChainDefinitionMap.put("/**/*.ico", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.htm", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.html", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.css", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.js", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.jpg", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.png", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.gif", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.webp", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.ttf", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.woff", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.woff2", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.mp3", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.mp4", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.txt", "anon");
|
||||
|
||||
|
||||
List<Permission> permissionList = permissionService.selectAll(CoreConst.STATUS_VALID);
|
||||
for(Permission permission : permissionList){
|
||||
if (StringUtils.isNotBlank(permission.getUrl())&& StringUtils.isNotBlank(permission.getPerms())) {
|
||||
String perm = "perms[" + permission.getPerms()+ "]";
|
||||
filterChainDefinitionMap.put(permission.getUrl(),perm+",kickout");
|
||||
}
|
||||
}
|
||||
|
||||
filterChainDefinitionMap.put("/**", "user,kickout");
|
||||
|
||||
return filterChainDefinitionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/修改/删除 后 重新加载权限
|
||||
*/
|
||||
public void updatePermission() {
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = SpringContextHolder.getBean(ShiroFilterFactoryBean.class);
|
||||
synchronized (shiroFilterFactoryBean) {
|
||||
AbstractShiroFilter shiroFilter = null;
|
||||
try {
|
||||
shiroFilter = (AbstractShiroFilter) shiroFilterFactoryBean.getObject();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("get ShiroFilter from shiroFilterFactoryBean error!");
|
||||
}
|
||||
|
||||
PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter
|
||||
.getFilterChainResolver();
|
||||
DefaultFilterChainManager manager = (DefaultFilterChainManager) filterChainResolver
|
||||
.getFilterChainManager();
|
||||
|
||||
// 清空老的权限控制
|
||||
manager.getFilterChains().clear();
|
||||
|
||||
shiroFilterFactoryBean.getFilterChainDefinitionMap().clear();
|
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(loadFilterChainDefinitions());
|
||||
// 重新构建生成
|
||||
Map<String, String> chains = shiroFilterFactoryBean.getFilterChainDefinitionMap();
|
||||
for (Map.Entry<String, String> entry : chains.entrySet()) {
|
||||
String url = entry.getKey();
|
||||
String chainDefinition = entry.getValue().trim().replace(" ", "");
|
||||
manager.createChain(url, chainDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/main/java/com/nbclass/shiro/config/LoginType.java
Normal file
22
src/main/java/com/nbclass/shiro/config/LoginType.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.nbclass.shiro.config;
|
||||
|
||||
/**
|
||||
* 登录类型
|
||||
* @author Leon
|
||||
* @datetime 2019年4月22日 下午8:48:14
|
||||
*/
|
||||
public enum LoginType {
|
||||
|
||||
PASSWORD("password"), // 密码登录
|
||||
NOPASSWD("nopassword"); // 免密登录
|
||||
|
||||
private String code;// 状态值
|
||||
|
||||
private LoginType(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
public String getCode () {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.nbclass.shiro.config;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
|
||||
public class MyHashedCredentialsMatcher extends HashedCredentialsMatcher {
|
||||
|
||||
@Override
|
||||
public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
|
||||
MyUsernamePasswordToken tk = (MyUsernamePasswordToken) authcToken;
|
||||
// 如果是免密登录直接返回true
|
||||
if(tk.getType().equals(LoginType.NOPASSWD)){
|
||||
return true;
|
||||
}
|
||||
// 不是免密登录,调用父类的方法
|
||||
return super.doCredentialsMatch(tk, info);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.nbclass.shiro.config;
|
||||
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2019年4月22日 下午8:59:23
|
||||
*/
|
||||
public class MyUsernamePasswordToken extends UsernamePasswordToken {
|
||||
|
||||
private static final long serialVersionUID = 1744966815127132051L;
|
||||
|
||||
private LoginType type;
|
||||
|
||||
public MyUsernamePasswordToken() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MyUsernamePasswordToken(String username, String password, LoginType type, boolean rememberMe, String host) {
|
||||
super(username, password, rememberMe, host);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**免密登录*/
|
||||
public MyUsernamePasswordToken(String username) {
|
||||
super(username, "", false, null);
|
||||
this.type = LoginType.NOPASSWD;
|
||||
}
|
||||
|
||||
/**账号密码登录*/
|
||||
public MyUsernamePasswordToken(String username, String password) {
|
||||
super(username, password, false, null);
|
||||
this.type = LoginType.PASSWORD;
|
||||
}
|
||||
|
||||
public LoginType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(LoginType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
267
src/main/java/com/nbclass/shiro/config/ShiroConfig.java
Normal file
267
src/main/java/com/nbclass/shiro/config/ShiroConfig.java
Normal file
@ -0,0 +1,267 @@
|
||||
package com.nbclass.shiro.config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
|
||||
import org.apache.shiro.codec.Base64;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
|
||||
import org.apache.shiro.session.mgt.eis.SessionDAO;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.CookieRememberMeManager;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.apache.shiro.web.servlet.SimpleCookie;
|
||||
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.nbclass.shiro.MyShiroRealm;
|
||||
import com.nbclass.shiro.ShiroService;
|
||||
import com.nbclass.shiro.filter.KickoutSessionControlFilter;
|
||||
import com.nbclass.shiro.filter.MobilePageOAuthFilter;
|
||||
import com.nbclass.shiro.filter.ResetPwdUrlFilter;
|
||||
|
||||
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
|
||||
@Autowired
|
||||
private ShiroService shiroService;
|
||||
|
||||
/*
|
||||
@Value("${spring.redis.host}")
|
||||
private String host;
|
||||
|
||||
@Value("${spring.redis.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${spring.redis.timeout}")
|
||||
private int timeout;
|
||||
|
||||
@Value("${spring.redis.password}")
|
||||
private String password;
|
||||
*/
|
||||
|
||||
@Bean
|
||||
public static LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* ShiroDialect,为了在thymeleaf里使用shiro的标签的bean
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ShiroDialect shiroDialect() {
|
||||
return new ShiroDialect();
|
||||
}
|
||||
/**
|
||||
* ShiroFilterFactoryBean 处理拦截资源文件问题。
|
||||
* 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在
|
||||
* 初始化ShiroFilterFactoryBean的时候需要注入:SecurityManager
|
||||
*
|
||||
Filter Chain定义说明
|
||||
1、一个URL可以配置多个Filter,使用逗号分隔
|
||||
2、当设置多个过滤器时,全部验证通过,才视为通过
|
||||
3、部分过滤器可指定参数,如perms,roles
|
||||
*
|
||||
*/
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||
// 必须设置 SecurityManager
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||
// 登录url
|
||||
shiroFilterFactoryBean.setLoginUrl("/login");
|
||||
// 登录成功后要跳转的链接
|
||||
shiroFilterFactoryBean.setSuccessUrl("/index");
|
||||
//未授权界面;
|
||||
shiroFilterFactoryBean.setUnauthorizedUrl("/error/403");
|
||||
//自定义拦截器
|
||||
Map<String, Filter> filtersMap = new LinkedHashMap<String, Filter>();
|
||||
//限制同一帐号同时在线的个数。
|
||||
filtersMap.put("kickout", kickoutSessionControlFilter());
|
||||
// 找回密码链接拦截验证
|
||||
filtersMap.put("resetPwdUrl", new ResetPwdUrlFilter());
|
||||
// 移动端页面授权拦截器
|
||||
filtersMap.put("wxWebOAuth", new MobilePageOAuthFilter());
|
||||
|
||||
shiroFilterFactoryBean.setFilters(filtersMap);
|
||||
//拦截器.
|
||||
Map<String,String> filterChainDefinitionMap = shiroService.loadFilterChainDefinitions();
|
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||
return shiroFilterFactoryBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookie对象;
|
||||
* @return
|
||||
*/
|
||||
public SimpleCookie rememberMeCookie(){
|
||||
//这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
|
||||
SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
|
||||
//<!-- 记住我cookie生效时间30天 ,单位秒;-->
|
||||
simpleCookie.setMaxAge(2592000);
|
||||
return simpleCookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookie管理对象;记住我功能
|
||||
* @return
|
||||
*/
|
||||
public CookieRememberMeManager rememberMeManager(){
|
||||
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
|
||||
cookieRememberMeManager.setCookie(rememberMeCookie());
|
||||
//rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位)
|
||||
cookieRememberMeManager.setCipherKey(Base64.decode("3AvVhmFLUs0KTA3Kprsdag=="));
|
||||
return cookieRememberMeManager;
|
||||
}
|
||||
|
||||
@Bean(name = "securityManager")
|
||||
public SecurityManager securityManager(){
|
||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||
//设置realm.
|
||||
securityManager.setRealm(myShiroRealm());
|
||||
/*记住我*/
|
||||
securityManager.setRememberMeManager(rememberMeManager());
|
||||
// 自定义缓存实现 使用redis
|
||||
// securityManager.setCacheManager(redisCacheManager());
|
||||
securityManager.setCacheManager(new MemoryConstrainedCacheManager()); //Shiro默认提供了CacheManager的简单内存实现MemoryConstrainedCacheManager,可用于生产环境;
|
||||
// 自定义session管理 使用redis
|
||||
securityManager.setSessionManager(sessionManager());
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MyShiroRealm myShiroRealm(){
|
||||
MyShiroRealm myShiroRealm = new MyShiroRealm();
|
||||
myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
|
||||
return myShiroRealm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 凭证匹配器
|
||||
* )
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public HashedCredentialsMatcher hashedCredentialsMatcher(){
|
||||
// HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
|
||||
MyHashedCredentialsMatcher hashedCredentialsMatcher = new MyHashedCredentialsMatcher(); // 使用自定义匹配器,方便使用免密登录
|
||||
hashedCredentialsMatcher.setHashAlgorithmName("md5");
|
||||
hashedCredentialsMatcher.setHashIterations(2);
|
||||
return hashedCredentialsMatcher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启shiro aop注解支持.
|
||||
* 使用代理方式;所以需要开启代码支持;
|
||||
* @param securityManager
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager){
|
||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
||||
return authorizationAttributeSourceAdvisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置shiro redisManager
|
||||
* 使用的是shiro-redis开源插件
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
public RedisManager redisManager() {
|
||||
RedisManager redisManager = new RedisManager();
|
||||
redisManager.setHost(host+":"+port);
|
||||
// redisManager.setPort(port);
|
||||
// 配置缓存过期时间
|
||||
// redisManager.setExpire(1800);
|
||||
|
||||
redisManager.setTimeout(timeout);
|
||||
redisManager.setPassword(password);
|
||||
return redisManager;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* cacheManager 缓存 redis实现
|
||||
* 使用的是shiro-redis开源插件
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
@Bean
|
||||
public RedisCacheManager redisCacheManager() {
|
||||
RedisCacheManager redisCacheManager = new RedisCacheManager();
|
||||
redisCacheManager.setRedisManager(redisManager());
|
||||
return redisCacheManager;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* RedisSessionDAO shiro sessionDao层的实现 通过redis
|
||||
* 使用的是shiro-redis开源插件
|
||||
*/
|
||||
/*
|
||||
@Bean
|
||||
public RedisSessionDAO redisSessionDAO() {
|
||||
RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
|
||||
redisSessionDAO.setRedisManager(redisManager());
|
||||
return redisSessionDAO;
|
||||
}
|
||||
*/
|
||||
@Bean
|
||||
public SessionDAO sessionDAO() {
|
||||
// return new MemorySessionDAO(); //使用默认的MemorySessionDAO
|
||||
return new EnterpriseCacheSessionDAO();
|
||||
}
|
||||
|
||||
/**
|
||||
* shiro session的管理
|
||||
*/
|
||||
@Bean
|
||||
public DefaultWebSessionManager sessionManager() {
|
||||
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
|
||||
// sessionManager.setSessionDAO(redisSessionDAO());
|
||||
sessionManager.setSessionDAO(sessionDAO());
|
||||
return sessionManager;
|
||||
}
|
||||
/**
|
||||
* 限制同一账号登录同时登录人数控制
|
||||
* @return
|
||||
*/
|
||||
public KickoutSessionControlFilter kickoutSessionControlFilter(){
|
||||
KickoutSessionControlFilter kickoutSessionControlFilter = new KickoutSessionControlFilter();
|
||||
//使用cacheManager获取相应的cache来缓存用户登录的会话;用于保存用户—会话之间的关系的;
|
||||
//这里我们还是用之前shiro使用的redisManager()实现的cacheManager()缓存管理
|
||||
//也可以重新另写一个,重新配置缓存时间之类的自定义缓存属性
|
||||
// kickoutSessionControlFilter.setCacheManager(redisCacheManager());
|
||||
kickoutSessionControlFilter.setCacheManager(new MemoryConstrainedCacheManager()); //Shiro默认提供了CacheManager的简单内存实现MemoryConstrainedCacheManager,可用于生产环境;
|
||||
//用于根据会话ID,获取会话进行踢出操作的;
|
||||
kickoutSessionControlFilter.setSessionManager(sessionManager());
|
||||
//是否踢出后来登录的,默认是false;即后者登录的用户踢出前者登录的用户;踢出顺序。
|
||||
kickoutSessionControlFilter.setKickoutAfter(false);
|
||||
//同一个用户最大的会话数,默认5;比如5的意思是同一个用户允许最多同时五个人登录;
|
||||
kickoutSessionControlFilter.setMaxSession(5);
|
||||
//被踢出后重定向到的地址;
|
||||
kickoutSessionControlFilter.setKickoutUrl("/kickout");
|
||||
return kickoutSessionControlFilter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,175 @@
|
||||
package com.nbclass.shiro.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.DefaultSessionKey;
|
||||
import org.apache.shiro.session.mgt.SessionManager;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.web.filter.AccessControlFilter;
|
||||
import org.apache.shiro.web.util.WebUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.nbclass.system.model.User;
|
||||
|
||||
/**
|
||||
* @author superzheng
|
||||
* @date 2018-07-18
|
||||
*/
|
||||
public class KickoutSessionControlFilter extends AccessControlFilter {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(KickoutSessionControlFilter.class);
|
||||
|
||||
/**
|
||||
* 踢出后到的地址
|
||||
*/
|
||||
private String kickoutUrl;
|
||||
/**
|
||||
* 踢出之前登录的/之后登录的用户 默认踢出之前登录的用户
|
||||
*/
|
||||
private boolean kickoutAfter = false;
|
||||
/**
|
||||
* 同一个帐号最大会话数 默认5
|
||||
*/
|
||||
private int maxSession = 5;
|
||||
|
||||
private SessionManager sessionManager;
|
||||
private Cache<String, Deque<Serializable>> cache;
|
||||
|
||||
public void setKickoutUrl(String kickoutUrl) {
|
||||
this.kickoutUrl = kickoutUrl;
|
||||
}
|
||||
|
||||
public void setKickoutAfter(boolean kickoutAfter) {
|
||||
this.kickoutAfter = kickoutAfter;
|
||||
}
|
||||
|
||||
public void setMaxSession(int maxSession) {
|
||||
this.maxSession = maxSession;
|
||||
}
|
||||
|
||||
public void setSessionManager(SessionManager sessionManager) {
|
||||
this.sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
public void setCacheManager(CacheManager cacheManager) {
|
||||
this.cache = cacheManager.getCache("shiro_redis_cache");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||
// HttpServletRequest req = (HttpServletRequest) request;
|
||||
|
||||
Subject subject = getSubject(request, response);
|
||||
if(!subject.isAuthenticated() && !subject.isRemembered()) {
|
||||
//如果没有登录,直接进行之后的流程
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Session session = subject.getSession();
|
||||
User user = (User) subject.getPrincipal();
|
||||
String username = user.getUsername();
|
||||
Serializable sessionId = session.getId();
|
||||
|
||||
//读取缓存 没有就存入
|
||||
Deque<Serializable> deque = cache.get(username);
|
||||
|
||||
//如果此用户没有session队列,也就是还没有登录过,缓存中没有
|
||||
//就new一个空队列,不然deque对象为空,会报空指针
|
||||
if(deque==null){
|
||||
deque = new LinkedList<Serializable>();
|
||||
}
|
||||
|
||||
//如果队列里没有此sessionId,且用户没有被踢出;放入队列
|
||||
if(!deque.contains(sessionId) && session.getAttribute("kickout") == null) {
|
||||
//将sessionId存入队列
|
||||
deque.push(sessionId);
|
||||
//将用户的sessionId队列缓存
|
||||
cache.put(username, deque);
|
||||
}
|
||||
|
||||
//如果队列里的sessionId数超出最大会话数,开始踢人
|
||||
while(deque.size() > maxSession) {
|
||||
Serializable kickoutSessionId = null;
|
||||
//如果踢出后者
|
||||
if(kickoutAfter) {
|
||||
kickoutSessionId = deque.removeFirst();
|
||||
//踢出后再更新下缓存队列
|
||||
cache.put(username, deque);
|
||||
} else { //否则踢出前者
|
||||
kickoutSessionId = deque.removeLast();
|
||||
//踢出后再更新下缓存队列
|
||||
cache.put(username, deque);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
//获取被踢出的sessionId的session对象
|
||||
Session kickoutSession = sessionManager.getSession(new DefaultSessionKey(kickoutSessionId));
|
||||
if(kickoutSession != null) {
|
||||
//设置会话的kickout属性表示踢出了
|
||||
kickoutSession.setAttribute("kickout", true);
|
||||
}
|
||||
} catch (Exception e) {//ignore exception
|
||||
}
|
||||
}
|
||||
|
||||
//如果被踢出了,直接退出,重定向到踢出后的地址
|
||||
if ((Boolean)session.getAttribute("kickout")!=null&&(Boolean)session.getAttribute("kickout") == true) {
|
||||
//会话被踢出了
|
||||
try {
|
||||
//退出登录
|
||||
subject.logout();
|
||||
} catch (Exception e) { //ignore
|
||||
}
|
||||
saveRequest(request);
|
||||
|
||||
Map<String, String> resultMap = new HashMap<String, String>(2);
|
||||
//判断是不是Ajax请求
|
||||
if ("XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With"))) {
|
||||
resultMap.put("user_status", "300");
|
||||
resultMap.put("message", "您已经在其他地方登录,请重新登录!");
|
||||
//输出json串
|
||||
out(response, resultMap);
|
||||
}else{
|
||||
//重定向
|
||||
WebUtils.issueRedirect(request, response, kickoutUrl);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void out(ServletResponse hresponse, Map<String, String> resultMap)
|
||||
throws IOException {
|
||||
try {
|
||||
hresponse.setCharacterEncoding("UTF-8");
|
||||
PrintWriter out = hresponse.getWriter();
|
||||
out.println(JSON.toJSONString(resultMap));
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
System.err.println("KickoutSessionFilter.class 输出JSON异常,可以忽略。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
package com.nbclass.shiro.filter;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
import com.nbclass.util.HttpUtils;
|
||||
import com.nbclass.util.WebUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.web.filter.AccessControlFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 移动端页面授权拦截器
|
||||
* @author Leon
|
||||
* @datetime 2019年9月2日 上午10:55:53
|
||||
*/
|
||||
public class MobilePageOAuthFilter extends AccessControlFilter {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(MobilePageOAuthFilter.class);
|
||||
|
||||
private static final String WX_API_DOMAIN = "http://www.qiween.cn/wxapi";
|
||||
|
||||
private static final String OAUTH2_SCOPE = "snsapi_base";
|
||||
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object mappedValue) throws Exception {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
|
||||
String userAgent = StringUtils.trimToEmpty(request.getHeader("User-Agent")).toLowerCase();
|
||||
if(!userAgent.contains("micromessenger")){ // pc端打开不拦截
|
||||
return true;
|
||||
}
|
||||
|
||||
String openId = WebUtils.getValueFromCookie(request, "cookie_key_s3_vote_uid");
|
||||
String s_openId = (String) request.getSession().getAttribute("sk_wx_openid");
|
||||
if(StringUtils.isNotBlank(openId) && StringUtils.isNotBlank(s_openId)){
|
||||
return true;
|
||||
}
|
||||
|
||||
String httpRequestFullURL = getHttpRequestFullURL(request);
|
||||
String redirectUrl = WX_API_DOMAIN+"/api/oauth?redirect_uri=" + URLEncoder.encode(httpRequestFullURL, "UTF-8")+"&scope="+OAUTH2_SCOPE;
|
||||
String code = request.getParameter("code");
|
||||
if(StringUtils.isNotBlank(code)){
|
||||
String url = WX_API_DOMAIN+"/api/oauthInfo?code="+code+"&scope="+OAUTH2_SCOPE;
|
||||
try {
|
||||
JSONObject json = HttpUtils.httpGet(url);
|
||||
if(json == null || json.getIntValue("errcode") == 40029 || json.getIntValue("errcode") == 40163
|
||||
|| (StringUtils.isNotBlank(json.getString("msg")) && (json.getString("msg").contains("40029") || json.getString("msg").contains("40163"))) ){
|
||||
logger.info("微信授权失败,将重新跳转授权......");
|
||||
redirectUrl = CommonUtils.removeParamValue(redirectUrl, "code");
|
||||
response.sendRedirect(redirectUrl);
|
||||
return false;
|
||||
}
|
||||
logger.info("微信授权获取到用户信息: "+json);
|
||||
openId = json.getString("openId");
|
||||
WebUtils.addCookie(response, "cookie_key_s3_vote_uid", openId, 3600 * 24 * 7);
|
||||
request.getSession().setAttribute("sk_wx_openid", openId);
|
||||
} catch (Exception e) {
|
||||
logger.error("授权失败:", e);
|
||||
openId = UUID.randomUUID().toString().replace("-", "");
|
||||
WebUtils.addCookie(response, "cookie_key_s3_vote_uid", openId, 3600 * 24 * 7); // 7天有效期
|
||||
}
|
||||
}else{
|
||||
response.sendRedirect(redirectUrl);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getHttpRequestFullURL(HttpServletRequest request) {
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
String queryString = request.getQueryString();
|
||||
if (queryString == null) {
|
||||
return requestURL.toString();
|
||||
} else {
|
||||
return requestURL.append('?').append(queryString).toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package com.nbclass.shiro.filter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.web.filter.AccessControlFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* 找回密码链接验证
|
||||
* @author Leon
|
||||
* @datetime 2019年5月2日 下午6:59:01
|
||||
*/
|
||||
public class ResetPwdUrlFilter extends AccessControlFilter {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(ResetPwdUrlFilter.class);
|
||||
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
|
||||
logger.info("ResetPwdUrlFilter.isAccessAllowed ......");
|
||||
String verifyCode = request.getParameter("verifyCode");
|
||||
if(StringUtils.isBlank(verifyCode)){
|
||||
logger.info("进入重置密码页面,参数[verifyCode]为null ......");
|
||||
outPrintError(response, "The requested URL was not found on this server.");
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
CustomerMapper customerMapper = SpringContextHolder.getBean(CustomerMapper.class);
|
||||
try{
|
||||
// 查询验证码是否有效,半小时重置密码才有效
|
||||
CustomerResetPwd customerResetPwd = customerMapper.selectResetPwd(verifyCode);
|
||||
if(customerResetPwd == null || customerResetPwd.getStatus() == null || customerResetPwd.getStatus() != 1){
|
||||
logger.info("进入重置密码页面,验证码已失效[verifyCode="+verifyCode+"].");
|
||||
outPrintError(response, "The requested URL was not found on this server.");
|
||||
return false;
|
||||
}
|
||||
}finally{
|
||||
customerMapper = null;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void outPrintError(ServletResponse response, String result) {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
String html = "<!DOCTYPE html><html><head>";
|
||||
html += "<title>Error 404 (Not Found)</title>";
|
||||
html += "<meta charset=\"utf-8\">";
|
||||
html += "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1\">";
|
||||
html += "</head><body>";
|
||||
html+="<center><div style=\"width:85%; text-align:center; font-size: 16px; line-height:35px;\">";
|
||||
html += result;
|
||||
html+="</div></center></body></html>";
|
||||
out = response.getWriter();
|
||||
out.print(html);
|
||||
} catch (IOException e) {
|
||||
logger.error("IO工作流出现异常!", e);
|
||||
} finally {
|
||||
if(out!=null){
|
||||
out.close();
|
||||
out = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
186
src/main/java/com/nbclass/system/controller/BaseController.java
Normal file
186
src/main/java/com/nbclass/system/controller/BaseController.java
Normal file
@ -0,0 +1,186 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.util.CoreConst;
|
||||
import com.nbclass.util.WebUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2019年4月1日 下午3:22:58
|
||||
*/
|
||||
public abstract class BaseController {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private static ThreadLocal<Map<String,Object>> outPutMsg = new ThreadLocal<Map<String,Object>>();
|
||||
|
||||
/**
|
||||
* 获取request
|
||||
* @return HttpServletRequest
|
||||
*/
|
||||
protected HttpServletRequest getRequest() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Response
|
||||
* @return HttpServletResponse
|
||||
*/
|
||||
protected HttpServletResponse getResponse() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取session
|
||||
* @return HttpSession
|
||||
*/
|
||||
protected HttpSession getSession() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
|
||||
}
|
||||
|
||||
protected ServletContext getServletContext() {
|
||||
return ContextLoader.getCurrentWebApplicationContext().getServletContext();
|
||||
}
|
||||
|
||||
public void outPrint() {
|
||||
outPrint(null);
|
||||
}
|
||||
|
||||
public void outPrint(Object result) {
|
||||
outPrint(result, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出,同时清空outPutMsg
|
||||
* @param response
|
||||
* @param result
|
||||
* @param respCode -- 是否返回响应状态吗,false:将直接输出result
|
||||
*/
|
||||
public void outPrint(Object result, boolean respCode) {
|
||||
try {
|
||||
HttpServletResponse response = getResponse();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("application/json");
|
||||
|
||||
PrintWriter out = response.getWriter();
|
||||
if(respCode){
|
||||
JSONObject obj = new JSONObject();
|
||||
if(result == null){
|
||||
// no msg
|
||||
}else if(result instanceof String){
|
||||
obj.put(CoreConst.MSG, result);
|
||||
}else{
|
||||
obj = (JSONObject) JSONObject.toJSON(result);
|
||||
}
|
||||
obj.put(CoreConst.STATUS, CoreConst.STATUS_SUCCESS);
|
||||
out.print(obj.toString());
|
||||
}else{
|
||||
out.print(result.toString());
|
||||
}
|
||||
getOutputMsg().clear();
|
||||
} catch (IOException e) {
|
||||
logger.error("输出异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出失败信息,同时清空outPutMsg
|
||||
* @param response
|
||||
* @param result void
|
||||
*/
|
||||
public void outPrintFail(Object result) {
|
||||
try {
|
||||
HttpServletResponse response = getResponse();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("application/json");
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
if(result == null){
|
||||
// no msg
|
||||
}else if(result instanceof String){
|
||||
obj.put(CoreConst.MSG, result);
|
||||
}else{
|
||||
obj = (JSONObject) JSONObject.toJSON(result);
|
||||
}
|
||||
obj.put(CoreConst.STATUS, CoreConst.STATUS_ERROR);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print(obj.toString());
|
||||
getOutputMsg().clear();
|
||||
} catch (IOException e) {
|
||||
logger.error("输出异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线程绑定,其内容会在outPrint方法调用后清空
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
public Map<String,Object> getOutputMsg() {
|
||||
Map<String,Object> output = outPutMsg.get();
|
||||
if(output==null){
|
||||
output = new HashMap<String, Object>();
|
||||
outPutMsg.set(output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public User getLoginUser(){
|
||||
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
return user;
|
||||
}
|
||||
|
||||
public int getLoginUserId(){
|
||||
int userid = -1;
|
||||
User user = getLoginUser();
|
||||
if(user!=null && user.getId()!=null)userid=user.getId();
|
||||
return userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ip地址
|
||||
* @return
|
||||
*/
|
||||
public String getIpAddr() {
|
||||
String ip = WebUtils.getReqIpAddr(getRequest());
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是管理员角色
|
||||
* @return
|
||||
*/
|
||||
public boolean isAdminRole(){
|
||||
boolean isSuperAdmin = SecurityUtils.getSubject().hasRole("1"); //是否是超级管理员,admin的roleid为1
|
||||
boolean isBaseAdmin = SecurityUtils.getSubject().hasRole("1000000002073979"); //是否是普通管理员, 给客户的管理员
|
||||
boolean isAdmin = isSuperAdmin||isBaseAdmin;
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Object result = null;
|
||||
result = "";
|
||||
JSONObject obj = (JSONObject) JSONObject.toJSON(result);
|
||||
obj.put(CoreConst.STATUS, CoreConst.STATUS_SUCCESS);
|
||||
System.out.println(obj);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/database")
|
||||
public class DatabaseController{
|
||||
@GetMapping(value = "/monitoring")
|
||||
public ModelAndView databaseMonitoring(){
|
||||
return new ModelAndView("database/monitoring");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/error")
|
||||
public class ErrorController {
|
||||
/*shiro无权限时进入*/
|
||||
@RequestMapping("/403")
|
||||
public String noPermission(HttpServletRequest request, HttpServletResponse response){
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
return "error/403";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.vo.UserOnlineVo;
|
||||
import com.nbclass.vo.UserSessionVo;
|
||||
import com.nbclass.vo.base.PageResultVo;
|
||||
import com.nbclass.vo.base.ResponseVo;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/online/user")
|
||||
public class OnlineUserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
// 在线用户列表
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public PageResultVo onlineUsers(UserOnlineVo user, Integer limit, Integer offset){
|
||||
List<UserOnlineVo> userList = userService.selectOnlineUsers(user);
|
||||
int endIndex = (offset+limit) > userList.size() ? userList.size() : (offset+limit);
|
||||
return ResultUtil.table(userList.subList(offset,endIndex),(long)userList.size());
|
||||
}
|
||||
|
||||
// 强制踢出用户
|
||||
@PostMapping("/kickout")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> kickout(String sessionId,String username) {
|
||||
try {
|
||||
if(SecurityUtils.getSubject().getSession().getId().equals(sessionId)){
|
||||
return ResultUtil.error("不能踢出自己");
|
||||
}
|
||||
userService.kickout(sessionId,username);
|
||||
return ResultUtil.success("踢出用户成功");
|
||||
} catch (Exception e) {
|
||||
return ResultUtil.error("踢出用户失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 批量强制踢出用户
|
||||
@PostMapping("/batch/kickout")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> kickout(@RequestBody List<UserSessionVo> sessions) {
|
||||
try {
|
||||
//要踢出的用户中是否有自己
|
||||
boolean hasOwn=false;
|
||||
Serializable sessionId = SecurityUtils.getSubject().getSession().getId();
|
||||
for (UserSessionVo sessionVo : sessions) {
|
||||
if(sessionVo.getSessionId().equals(sessionId)){
|
||||
hasOwn=true;
|
||||
}else{
|
||||
userService.kickout(sessionVo.getSessionId(),sessionVo.getUsername());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if(hasOwn){
|
||||
return ResultUtil.success("不能踢出自己");
|
||||
}
|
||||
return ResultUtil.success("踢出用户成功");
|
||||
} catch (Exception e) {
|
||||
return ResultUtil.error("踢出用户失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nbclass.shiro.ShiroService;
|
||||
import com.nbclass.system.model.Permission;
|
||||
import com.nbclass.system.service.PermissionService;
|
||||
import com.nbclass.util.CoreConst;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.vo.base.ResponseVo;
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/permission")
|
||||
public class PermissionController{
|
||||
private static final Logger logger = LoggerFactory.getLogger(PermissionController.class);
|
||||
/**1:全部资源,2:菜单资源*/
|
||||
private static final String[] MENU_FLAG ={"1","2"};
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
@Autowired
|
||||
private ShiroService shiroService;
|
||||
|
||||
|
||||
|
||||
/*权限列表数据*/
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public List<Permission> loadPermissions(String flag){
|
||||
List<Permission> permissionListList = new ArrayList<Permission>();
|
||||
if(StringUtils.isBlank(flag) || MENU_FLAG[0].equals(flag)){
|
||||
permissionListList = permissionService.selectAll(CoreConst.STATUS_VALID);
|
||||
}else if(MENU_FLAG[1].equals(flag)){
|
||||
permissionListList = permissionService.selectAllMenuName(CoreConst.STATUS_VALID);
|
||||
}
|
||||
return permissionListList;
|
||||
}
|
||||
|
||||
/*添加权限*/
|
||||
@ResponseBody
|
||||
@PostMapping("/add")
|
||||
public ResponseVo<Object> addPermission(Permission permission){
|
||||
try {
|
||||
int a = permissionService.insert(permission);
|
||||
if (a > 0) {
|
||||
shiroService.updatePermission();
|
||||
return ResultUtil.success("添加权限成功");
|
||||
} else {
|
||||
return ResultUtil.error("添加权限失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("PermissionController.addPermission%s", e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/*删除权限*/
|
||||
@ResponseBody
|
||||
@PostMapping("/delete")
|
||||
public ResponseVo<Object> deletePermission(String permissionId){
|
||||
try {
|
||||
int subPermsByPermissionIdCount = permissionService.selectSubPermsByPermissionId(permissionId);
|
||||
if(subPermsByPermissionIdCount>0){
|
||||
return ResultUtil.error("改资源存在下级资源,无法删除!");
|
||||
}
|
||||
int a = permissionService.updateStatus(permissionId,CoreConst.STATUS_INVALID);
|
||||
if (a > 0) {
|
||||
shiroService.updatePermission();
|
||||
return ResultUtil.success("删除权限成功");
|
||||
} else {
|
||||
return ResultUtil.error("删除权限失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("PermissionController.deletePermission%s", e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/*权限详情*/
|
||||
@GetMapping("/edit")
|
||||
public String detail(Model model, String permissionId) {
|
||||
Permission permission = permissionService.findByPermissionId(permissionId);
|
||||
if(null!=permission){
|
||||
if(permission.getParentId().equals(CoreConst.TOP_MENU_ID)){
|
||||
model.addAttribute("parentName", CoreConst.TOP_MENU_NAME);
|
||||
}else{
|
||||
Permission parent = permissionService.findById(permission.getParentId());
|
||||
model.addAttribute("parentName", parent.getName());
|
||||
}
|
||||
}
|
||||
model.addAttribute("permission", permission);
|
||||
return "permission/detail";
|
||||
}
|
||||
|
||||
/*编辑权限*/
|
||||
@ResponseBody
|
||||
@PostMapping("/edit")
|
||||
public ResponseVo<Object> editPermission(@ModelAttribute("permission")Permission permission){
|
||||
int a = permissionService.updateByPermissionId(permission);
|
||||
if (a > 0) {
|
||||
shiroService.updatePermission();
|
||||
return ResultUtil.success("编辑权限成功");
|
||||
} else {
|
||||
return ResultUtil.error("编辑权限失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,138 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nbclass.shiro.config.MyUsernamePasswordToken;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.CommonUtils;
|
||||
import com.nbclass.util.HttpUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 企业微信扫码登录
|
||||
* @author Leon
|
||||
* @datetime 2020年6月2日 下午4:18:04
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/qywx")
|
||||
public class QyWxLoginController {
|
||||
|
||||
private static final int AgentId = 1000016; // 企业微信登录应用ID(信广龙广告)
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* PC端网页授权(企业微信授权登录)
|
||||
* @param code
|
||||
* @param request
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping("/qrLogin")
|
||||
public void qrLogin(String code, HttpServletRequest request, HttpServletResponse response) throws IOException{
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
String httpRequestFullURL = URLEncoder.encode(getBaseUrl(request)+"/qywx/qrLogin", "UTF-8");
|
||||
String redirectUrl = "http://show.szxgl.cn/qywx/api/sso/login?agentid="+AgentId+"&redirect_uri=" + httpRequestFullURL;
|
||||
if(StringUtils.isBlank(code)){
|
||||
response.sendRedirect(redirectUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
String url = "http://show.szxgl.cn/qywx/api/sso/getUserInfo?agentid="+AgentId+"&code="+code;
|
||||
try {
|
||||
JSONObject json = HttpUtils.httpPost(url);
|
||||
if(json == null || json.getIntValue("errcode") == 40029 || json.getIntValue("errcode") == 40163){
|
||||
log.info("企业微信授权失败,将重新跳转授权......");
|
||||
redirectUrl = CommonUtils.removeParamValue(redirectUrl, "code");
|
||||
response.sendRedirect(redirectUrl);
|
||||
return;
|
||||
}
|
||||
log.info("企业微信扫码登录, 用户信息: "+json);
|
||||
String userid = json.getString("userid");
|
||||
if(StringUtils.isBlank(userid)){
|
||||
outPrintError(response, "该账号未经授权,请联系管理员授权后再试!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 企业微信登录成功,下一步进行系统shiro身份验证
|
||||
String username = userid;
|
||||
MyUsernamePasswordToken token = new MyUsernamePasswordToken(username); // 免密登录,用于扫码登录手机验证码登录等场景
|
||||
try{
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
subject.login(token);
|
||||
} catch (LockedAccountException e) {
|
||||
token.clear();
|
||||
outPrintError(response, "用户已经被锁定不能登录,请联系管理员!");
|
||||
return;
|
||||
} catch (AuthenticationException e) {
|
||||
token.clear();
|
||||
outPrintError(response, "账号异常,请联系管理员处理!");
|
||||
return;
|
||||
}
|
||||
//更新最后登录时间
|
||||
userService.updateLastLoginTime((User) SecurityUtils.getSubject().getPrincipal());
|
||||
|
||||
response.sendRedirect(request.getContextPath()+"/admin");
|
||||
} catch (Exception e) {
|
||||
log.error("企业微信登录授权失败", e);
|
||||
outPrintError(response, "企业微信授权失败,请稍候再试!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出错误信息到页面
|
||||
* @param response
|
||||
* @param result
|
||||
*/
|
||||
public void outPrintError(HttpServletResponse response, String result) {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
String html = "<!DOCTYPE html><html><head>";
|
||||
html += "<title>鉴权错误</title>";
|
||||
html += "<meta charset=\"utf-8\">";
|
||||
html += "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1\">";
|
||||
html += "</head><body>";
|
||||
html+="<center><div style=\"width:85%; text-align:center; font-size: 18px; line-height:35px; color: red; margin-top: 15px;\">";
|
||||
html += result;
|
||||
html+="</div></center></body></html>";
|
||||
out = response.getWriter();
|
||||
out.print(html);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("IO工作流出现异常!");
|
||||
} finally {
|
||||
if(out!=null){
|
||||
out.close();
|
||||
out = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getBaseUrl(HttpServletRequest request){
|
||||
String result = null;
|
||||
int port = request.getServerPort();
|
||||
result = request.getScheme()+"://"+request.getServerName()+(port==80||port==443 ? "" : ":"+port)+request.getContextPath()+"/";
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月13日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
public class RenderController {
|
||||
|
||||
/*工作台*/
|
||||
@GetMapping("/workdest")
|
||||
public String workdest(){
|
||||
return "index/workdest";
|
||||
}
|
||||
|
||||
/**用户列表入口*/
|
||||
@GetMapping("/users")
|
||||
public String userList(){
|
||||
return "user/list";
|
||||
}
|
||||
|
||||
/*角色列表入口*/
|
||||
@GetMapping("/roles")
|
||||
public String roleList() {
|
||||
return "role/list";
|
||||
}
|
||||
|
||||
/*权限列表入口*/
|
||||
@GetMapping("/permissions")
|
||||
public String permissionList(){
|
||||
return "permission/list";
|
||||
}
|
||||
|
||||
/*在线用户入口*/
|
||||
@GetMapping("/online/users")
|
||||
public String onlineUsers(){return "onlineUsers/list";}
|
||||
}
|
||||
184
src/main/java/com/nbclass/system/controller/RoleController.java
Normal file
184
src/main/java/com/nbclass/system/controller/RoleController.java
Normal file
@ -0,0 +1,184 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.shiro.MyShiroRealm;
|
||||
import com.nbclass.system.model.Permission;
|
||||
import com.nbclass.system.model.Role;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.service.PermissionService;
|
||||
import com.nbclass.system.service.RoleService;
|
||||
import com.nbclass.util.CoreConst;
|
||||
import com.nbclass.util.PageUtil;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.vo.PermissionTreeListVo;
|
||||
import com.nbclass.vo.base.PageResultVo;
|
||||
import com.nbclass.vo.base.ResponseVo;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/role")
|
||||
public class RoleController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RoleController.class);
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
@Autowired
|
||||
private MyShiroRealm myShiroRealm;
|
||||
|
||||
/*角色列表数据*/
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public PageResultVo pageRoles(Role role, Integer limit, Integer offset) {
|
||||
try {
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<Role> roleList = roleService.selectRoles(role);
|
||||
PageInfo<Role> pages = new PageInfo<>(roleList);
|
||||
return ResultUtil.table(roleList,pages.getTotal());
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("RoleController.loadRoles%s", e));
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*新增角色*/
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> addRole(Role role) {
|
||||
try {
|
||||
int a = roleService.insert(role);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("添加角色成功");
|
||||
} else {
|
||||
return ResultUtil.error("添加角色失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("RoleController.addRole%s", e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/*删除角色*/
|
||||
@GetMapping("/delete")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> deleteRole(String roleId) {
|
||||
if(roleService.findByRoleId(roleId).size()>0){
|
||||
return ResultUtil.error("删除失败,该角色下存在用户");
|
||||
}
|
||||
List<String> roleIdsList = Arrays.asList(roleId);
|
||||
int a = roleService.updateStatusBatch(roleIdsList, CoreConst.STATUS_INVALID);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("删除角色成功");
|
||||
} else {
|
||||
return ResultUtil.error("删除角色失败");
|
||||
}
|
||||
}
|
||||
|
||||
/*批量删除角色*/
|
||||
@GetMapping("/batch/delete")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> batchDeleteRole(String roleIdStr) {
|
||||
String[] roleIds = roleIdStr.split(",");
|
||||
List<String> roleIdsList = Arrays.asList(roleIds);
|
||||
if(roleService.findByRoleIds(roleIdsList).size()>0){
|
||||
return ResultUtil.error("删除失败,选择的角色下存在用户");
|
||||
}
|
||||
int a = roleService.updateStatusBatch(roleIdsList, CoreConst.STATUS_INVALID);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("删除角色成功");
|
||||
} else {
|
||||
return ResultUtil.error("删除角色失败");
|
||||
}
|
||||
}
|
||||
|
||||
/*编辑角色详情*/
|
||||
@GetMapping("/edit")
|
||||
public String detail(Model model, Integer id) {
|
||||
Role role = roleService.findById(id);
|
||||
model.addAttribute("role", role);
|
||||
return "role/detail";
|
||||
}
|
||||
|
||||
/*编辑角色*/
|
||||
@PostMapping("/edit")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> editRole(@ModelAttribute("role") Role role) {
|
||||
int a = roleService.updateByRoleId(role);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("编辑角色成功");
|
||||
} else {
|
||||
return ResultUtil.error("编辑角色失败");
|
||||
}
|
||||
}
|
||||
|
||||
/*分配权限列表查询*/
|
||||
@PostMapping("/assign/permission/list")
|
||||
@ResponseBody
|
||||
public List<PermissionTreeListVo> assignRole(String roleId){
|
||||
List<PermissionTreeListVo> listVos = new ArrayList<>();
|
||||
List<Permission> allPermissions = permissionService.selectAll(CoreConst.STATUS_VALID);
|
||||
List<Permission> hasPermissions = roleService.findPermissionsByRoleId(roleId);
|
||||
for(Permission permission : allPermissions){
|
||||
PermissionTreeListVo vo = new PermissionTreeListVo();
|
||||
vo.setId(permission.getId());
|
||||
vo.setPermissionId(permission.getPermissionId());
|
||||
vo.setName(permission.getName());
|
||||
vo.setParentId(permission.getParentId());
|
||||
for(Permission hasPermission:hasPermissions){
|
||||
//有权限则选中
|
||||
if(hasPermission.getPermissionId().equals(permission.getPermissionId())){
|
||||
vo.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
listVos.add(vo);
|
||||
}
|
||||
return listVos;
|
||||
}
|
||||
|
||||
|
||||
/*分配权限*/
|
||||
@PostMapping("/assign/permission")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> assignRole(String roleId, String permissionIdStr){
|
||||
List<String> permissionIdsList = new ArrayList<>();
|
||||
if(StringUtils.isNotBlank(permissionIdStr)){
|
||||
String[] permissionIds = permissionIdStr.split(",");
|
||||
permissionIdsList = Arrays.asList(permissionIds);
|
||||
}
|
||||
ResponseVo<Object> rv = roleService.addAssignPermission(roleId,permissionIdsList);
|
||||
/*重新加载角色下所有用户权限*/
|
||||
List<User> userList = roleService.findByRoleId(roleId);
|
||||
if(userList.size()>0){
|
||||
List<String> userIds = new ArrayList<>();
|
||||
for(User user : userList){
|
||||
userIds.add(user.getUserId());
|
||||
}
|
||||
myShiroRealm.clearAuthorizationByUserId(userIds);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nbclass.shiro.config.MyUsernamePasswordToken;
|
||||
import com.nbclass.system.model.Permission;
|
||||
import com.nbclass.system.model.SysLog;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.model.enums.SysLogType;
|
||||
import com.nbclass.system.service.PermissionService;
|
||||
import com.nbclass.system.service.SysLogService;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.CoreConst;
|
||||
import com.nbclass.util.PasswordHelper;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.util.UUIDUtil;
|
||||
import com.nbclass.vo.base.ResponseVo;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
public class SystemController extends BaseController{
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
@Resource
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/*首页*/
|
||||
@RequestMapping(value={"/admin"})
|
||||
public String admin(){
|
||||
return "index/index";
|
||||
}
|
||||
|
||||
/*注册*/
|
||||
@GetMapping(value = "/register")
|
||||
public String register(){
|
||||
return "system/register";
|
||||
}
|
||||
|
||||
/*提交注册*/
|
||||
@PostMapping("/register")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> register(HttpServletRequest request, User registerUser, String confirmPassword, String verification){
|
||||
if(true)return ResultUtil.error("注册失败,请稍后再试!");
|
||||
@SuppressWarnings("unused")
|
||||
//判断验证码
|
||||
/*
|
||||
* String rightCode = (String)
|
||||
* request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY); if
|
||||
* (StringUtils.isNotBlank(verification) && StringUtils.isNotBlank(rightCode) &&
|
||||
* verification.equals(rightCode)) { //验证码通过 } else { return
|
||||
* ResultUtil.error("验证码错误!"); }
|
||||
*/
|
||||
String username = registerUser.getUsername();
|
||||
User user = userService.selectByUsername(username);
|
||||
if (null != user) {
|
||||
return ResultUtil.error("用户名已存在!");
|
||||
}
|
||||
String password = registerUser.getPassword();
|
||||
//判断两次输入密码是否相等
|
||||
if (confirmPassword != null && password != null) {
|
||||
if (!confirmPassword.equals(password)) {
|
||||
return ResultUtil.error("两次密码不一致!");
|
||||
}
|
||||
}
|
||||
registerUser.setUserId(UUIDUtil.getUniqueIdByUUId());
|
||||
registerUser.setStatus(CoreConst.STATUS_VALID);
|
||||
Date date = new Date();
|
||||
registerUser.setCreateTime(date);
|
||||
registerUser.setUpdateTime(date);
|
||||
registerUser.setLastLoginTime(date);
|
||||
PasswordHelper.encryptPassword(registerUser);
|
||||
//注册
|
||||
int registerResult = userService.register(registerUser);
|
||||
if(registerResult > 0){
|
||||
return ResultUtil.success("注册成功!");
|
||||
}else {
|
||||
return ResultUtil.error("注册失败,请稍后再试!");
|
||||
}
|
||||
}
|
||||
|
||||
/*登陆*/
|
||||
@GetMapping("/login")
|
||||
public String login(){
|
||||
return "system/login";
|
||||
}
|
||||
|
||||
/*提交登录*/
|
||||
@PostMapping("/login")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> login(HttpServletRequest request, String username, String password,
|
||||
String verification, @RequestParam(value = "rememberMe", defaultValue = "0") Integer rememberMe){
|
||||
|
||||
/*
|
||||
//判断验证码
|
||||
String rightCode = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
|
||||
if (StringUtils.isNotBlank(verification) && StringUtils.isNotBlank(rightCode) && verification.equalsIgnoreCase(rightCode)) {
|
||||
//验证码通过
|
||||
} else {
|
||||
return ResultUtil.error("验证码错误!");
|
||||
}
|
||||
*/
|
||||
|
||||
MyUsernamePasswordToken token = new MyUsernamePasswordToken(username, password); // 账密登录
|
||||
// MyUsernamePasswordToken token = new MyUsernamePasswordToken(username); // 免密登录,用于扫码登录手机验证码登录等场景
|
||||
try{
|
||||
token.setRememberMe(1 == rememberMe);
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
subject.login(token);
|
||||
} catch (LockedAccountException e) {
|
||||
token.clear();
|
||||
return ResultUtil.error("用户已经被锁定不能登录,请联系管理员!");
|
||||
} catch (AuthenticationException e) {
|
||||
token.clear();
|
||||
return ResultUtil.error("用户名或者密码错误!");
|
||||
}
|
||||
//更新最后登录时间
|
||||
userService.updateLastLoginTime((User) SecurityUtils.getSubject().getPrincipal());
|
||||
User user = getLoginUser();
|
||||
request.getSession().setAttribute("username",user.getUsername());
|
||||
sysLogService.add(new SysLog(SysLogType.login.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), "登录系统!"));
|
||||
return ResultUtil.success("登录成功!");
|
||||
}
|
||||
|
||||
/*踢出*/
|
||||
@GetMapping("/kickout")
|
||||
public String kickout(){
|
||||
return "system/kickout";
|
||||
}
|
||||
|
||||
/*登出*/
|
||||
@RequestMapping(value = "/logout")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> logout() {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
if(null!=subject){
|
||||
/*
|
||||
String username = ((User) SecurityUtils.getSubject().getPrincipal()).getUsername();
|
||||
Serializable sessionId = SecurityUtils.getSubject().getSession().getId();
|
||||
Cache<String, Deque<Serializable>> cache = redisCacheManager.getCache(redisCacheManager.getKeyPrefix()+username);
|
||||
Deque<Serializable> deques = cache.get(username);
|
||||
for(Serializable deque : deques){
|
||||
if(sessionId.equals(deque)){
|
||||
deques.remove(deque);
|
||||
break;
|
||||
}
|
||||
}
|
||||
cache.put(username,deques);
|
||||
*/
|
||||
}
|
||||
subject.logout();
|
||||
return ResultUtil.success("退出成功");
|
||||
}
|
||||
|
||||
/*获取当前登录用户的菜单*/
|
||||
@PostMapping("/menu")
|
||||
@ResponseBody
|
||||
public List<Permission> getMenus(){
|
||||
List<Permission> permissionListList = permissionService.selectMenuByUserId(((User) SecurityUtils.getSubject().getPrincipal()).getUserId());
|
||||
return permissionListList;
|
||||
}
|
||||
|
||||
/*图标*/
|
||||
@GetMapping(value = "/icons")
|
||||
public String getIcons(){
|
||||
return "ui/icons";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/test")
|
||||
public String test(){
|
||||
return "ui/icons";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/test1")
|
||||
public String test1(){
|
||||
return "ui/icons";
|
||||
}
|
||||
|
||||
}
|
||||
239
src/main/java/com/nbclass/system/controller/UserController.java
Normal file
239
src/main/java/com/nbclass/system/controller/UserController.java
Normal file
@ -0,0 +1,239 @@
|
||||
package com.nbclass.system.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.nbclass.shiro.MyShiroRealm;
|
||||
import com.nbclass.system.model.Role;
|
||||
import com.nbclass.system.model.SysLog;
|
||||
import com.nbclass.system.model.User;
|
||||
import com.nbclass.system.model.enums.SysLogType;
|
||||
import com.nbclass.system.service.RoleService;
|
||||
import com.nbclass.system.service.SysLogService;
|
||||
import com.nbclass.system.service.UserService;
|
||||
import com.nbclass.util.CopyUtil;
|
||||
import com.nbclass.util.CoreConst;
|
||||
import com.nbclass.util.PageUtil;
|
||||
import com.nbclass.util.PasswordHelper;
|
||||
import com.nbclass.util.ResultUtil;
|
||||
import com.nbclass.util.UUIDUtil;
|
||||
import com.nbclass.vo.ChangePasswordVo;
|
||||
import com.nbclass.vo.base.PageResultVo;
|
||||
import com.nbclass.vo.base.ResponseVo;
|
||||
/**
|
||||
* @version V1.0
|
||||
* @date 2018年7月11日
|
||||
* @author superzheng
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController extends BaseController{
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private MyShiroRealm myShiroRealm;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private MyShiroRealm shiroRealm;
|
||||
@Resource
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/**用户列表数据*/
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public PageResultVo loadUsers(User user, Integer limit, Integer offset){
|
||||
PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
|
||||
List<User> userList = userService.selectUsers(user);
|
||||
PageInfo<User> pages = new PageInfo<>(userList);
|
||||
return ResultUtil.table(userList,pages.getTotal());
|
||||
}
|
||||
|
||||
/**新增用户*/
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> add(User userForm, String confirmPassword){
|
||||
String username = userForm.getUsername();
|
||||
User user = userService.selectByUsername(username);
|
||||
if (null != user) {
|
||||
return ResultUtil.error("用户名已存在");
|
||||
}
|
||||
String password = userForm.getPassword();
|
||||
//判断两次输入密码是否相等
|
||||
if (confirmPassword != null && password != null) {
|
||||
if (!confirmPassword.equals(password)) {
|
||||
return ResultUtil.error("两次密码不一致");
|
||||
}
|
||||
}
|
||||
userForm.setUserId(UUIDUtil.getUniqueIdByUUId());
|
||||
userForm.setStatus(CoreConst.STATUS_VALID);
|
||||
Date date = new Date();
|
||||
userForm.setCreateTime(date);
|
||||
userForm.setUpdateTime(date);
|
||||
userForm.setLastLoginTime(date);
|
||||
PasswordHelper.encryptPassword(userForm);
|
||||
int num = userService.register(userForm);
|
||||
if(num > 0){
|
||||
return ResultUtil.success("添加用户成功");
|
||||
}else {
|
||||
return ResultUtil.error("添加用户失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**编辑用户详情*/
|
||||
@GetMapping("/edit")
|
||||
public String userDetail(Model model, String userId){
|
||||
User user = userService.selectByUserId(userId);
|
||||
model.addAttribute("user", user);
|
||||
return "user/userDetail";
|
||||
}
|
||||
|
||||
/**编辑用户*/
|
||||
@PostMapping("/edit")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> editUser(User userForm){
|
||||
int a = userService.updateByUserId(userForm);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("编辑用户成功!");
|
||||
} else {
|
||||
return ResultUtil.error("编辑用户失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**删除用户*/
|
||||
@GetMapping("/delete")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> deleteUser(String userId) {
|
||||
List<String> userIdsList = Arrays.asList(userId);
|
||||
int a = userService.updateStatusBatch(userIdsList,CoreConst.STATUS_INVALID);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("删除用户成功");
|
||||
} else {
|
||||
return ResultUtil.error("删除用户失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**批量删除用户*/
|
||||
@GetMapping("/batch/delete")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> batchDeleteUser(String userIdStr) {
|
||||
String[] userIds = userIdStr.split(",");
|
||||
List<String> userIdsList = Arrays.asList(userIds);
|
||||
int a = userService.updateStatusBatch(userIdsList,CoreConst.STATUS_INVALID);
|
||||
if (a > 0) {
|
||||
return ResultUtil.success("删除用户成功");
|
||||
} else {
|
||||
return ResultUtil.error("删除用户失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**分配角色列表查询*/
|
||||
@PostMapping("/assign/role/list")
|
||||
@ResponseBody
|
||||
public Map<String,Object> assignRoleList(String userId){
|
||||
List<Role> roleList = roleService.selectRoles(new Role());
|
||||
Set<String> hasRoles = roleService.findRoleByUserId(userId);
|
||||
Map<String, Object> jsonMap = new HashMap<>(2);
|
||||
jsonMap.put("rows", roleList);
|
||||
jsonMap.put("hasRoles",hasRoles);
|
||||
return jsonMap;
|
||||
}
|
||||
|
||||
/**保存分配角色*/
|
||||
@PostMapping("/assign/role")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> assignRole(String userId, String roleIdStr){
|
||||
String[] roleIds = roleIdStr.split(",");
|
||||
List<String> roleIdsList = Arrays.asList(roleIds);
|
||||
ResponseVo<Object> responseVo = userService.addAssignRole(userId,roleIdsList);
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add(userId);
|
||||
myShiroRealm.clearAuthorizationByUserId(userIds);
|
||||
return responseVo;
|
||||
}
|
||||
|
||||
/*修改密码*/
|
||||
@RequestMapping(value = "/changePassword",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> changePassword(ChangePasswordVo changePasswordVo) {
|
||||
if(!changePasswordVo.getNewPassword().equals(changePasswordVo.getConfirmNewPassword())){
|
||||
return ResultUtil.error("两次密码输入不一致");
|
||||
}
|
||||
User loginUser = userService.selectByUserId(((User) SecurityUtils.getSubject().getPrincipal()).getUserId());
|
||||
User newUser = CopyUtil.getCopy(loginUser,User.class);
|
||||
String sysOldPassword = loginUser.getPassword();
|
||||
newUser.setPassword(changePasswordVo.getOldPassword());
|
||||
String entryOldPassword = PasswordHelper.getPassword(newUser);
|
||||
if(sysOldPassword.equals(entryOldPassword)){
|
||||
newUser.setPassword(changePasswordVo.getNewPassword());
|
||||
PasswordHelper.encryptPassword(newUser);
|
||||
newUser.setUpdateTime(new Date());
|
||||
userService.updateUserByPrimaryKey(newUser);
|
||||
//*清除登录缓存*//
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add(loginUser.getUserId());
|
||||
shiroRealm.removeCachedAuthenticationInfo(userIds);
|
||||
/*SecurityUtils.getSubject().logout();*/
|
||||
}else{
|
||||
return ResultUtil.error("您输入的旧密码有误");
|
||||
}
|
||||
logger.info("账号[username="+loginUser.getUsername()+"]修改密码, 提交的参数为: "+JSON.toJSONString(changePasswordVo));
|
||||
|
||||
User user = getLoginUser();
|
||||
sysLogService.add(new SysLog(SysLogType.xtgl.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), "修改密码"));
|
||||
return ResultUtil.success("修改密码成功");
|
||||
}
|
||||
|
||||
/*管理员重置密码*/
|
||||
@PostMapping("/resetPwd")
|
||||
@ResponseBody
|
||||
public ResponseVo<Object> resetPassword(String userid, String password) {
|
||||
if(StringUtils.isBlank(userid)){
|
||||
return ResultUtil.error("用户不能为空");
|
||||
}
|
||||
if(StringUtils.isBlank(password)){
|
||||
return ResultUtil.error("密码不能为空");
|
||||
}
|
||||
User dbUser = userService.selectByUserId(userid);
|
||||
User newUser = new User();
|
||||
newUser.setId(dbUser.getId());
|
||||
newUser.setUserId(dbUser.getUserId());
|
||||
newUser.setUsername(dbUser.getUsername());
|
||||
newUser.setStatus(dbUser.getStatus());
|
||||
newUser.setPassword(password);
|
||||
PasswordHelper.encryptPassword(newUser);
|
||||
newUser.setUpdateTime(new Date());
|
||||
userService.updateUserByPrimaryKey(newUser);
|
||||
logger.info("管理员重置密码[username="+dbUser.getUsername()+"], 提交的参数为: "+password);
|
||||
User user = getLoginUser();
|
||||
sysLogService.add(new SysLog(SysLogType.xtgl.key(), user.getUserId()+"("+user.getUsername()+")", getIpAddr(), "管理员重置密码,账号:"+userid+"("+dbUser.getUsername()+")"));
|
||||
return ResultUtil.success("修改密码成功");
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user