@ -1,9 +0,0 @@
|
||||
*.md linguist-language=Java
|
||||
*.yml linguist-language=Java
|
||||
*.html linguist-language=Java
|
||||
*.js linguist-language=Java
|
||||
*.xml linguist-language=Java
|
||||
*.css linguist-language=Java
|
||||
*.sql linguist-language=Java
|
||||
*.uml linguist-language=Java
|
||||
*.cmd linguist-language=Java
|
||||
@ -1,7 +0,0 @@
|
||||
**/logs
|
||||
**/.idea
|
||||
**/cachedata
|
||||
**/target
|
||||
**/*.iml
|
||||
**/.DS_Store
|
||||
|
||||
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@ -1,53 +0,0 @@
|
||||
mode:
|
||||
# 单机模式
|
||||
type: Standalone
|
||||
# 元数据持久化
|
||||
repository:
|
||||
# 数据库持久化
|
||||
type: JDBC
|
||||
|
||||
# 数据源配置
|
||||
dataSources:
|
||||
ds_1:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
ds_2:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/information_schema?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
# 规则配置
|
||||
rules:
|
||||
- !SINGLE
|
||||
tables:
|
||||
- "*.*"
|
||||
- !SHARDING
|
||||
tables: # 数据分片规则配置
|
||||
book_content:
|
||||
# 分库策略,缺省表示使用默认分库策略
|
||||
actualDataNodes: ds_${1}.book_content${0..9}
|
||||
# 分表策略
|
||||
tableStrategy:
|
||||
standard:
|
||||
# 分片列名称
|
||||
shardingColumn: index_id
|
||||
# 分片算法名称
|
||||
shardingAlgorithmName: bookContentSharding
|
||||
|
||||
shardingAlgorithms:
|
||||
bookContentSharding:
|
||||
# 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
|
||||
type: INLINE
|
||||
props:
|
||||
# 分片算法的行表达式
|
||||
algorithm-expression: book_content${index_id % 10}
|
||||
|
||||
|
||||
|
||||
props:
|
||||
# 是否在日志中打印 SQL
|
||||
sql-show: true
|
||||
@ -1,82 +0,0 @@
|
||||
PUT /novel
|
||||
{
|
||||
"mappings" : {
|
||||
"book" : {
|
||||
"properties" : {
|
||||
"id" : {
|
||||
"type" : "long"
|
||||
},
|
||||
"authorId" : {
|
||||
"type" : "long"
|
||||
},
|
||||
"authorName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 1.9
|
||||
},
|
||||
|
||||
"bookName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 2
|
||||
},
|
||||
|
||||
"bookDesc" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 0.1
|
||||
},
|
||||
|
||||
"bookStatus" : {
|
||||
"type" : "short"
|
||||
},
|
||||
|
||||
"catId" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
|
||||
"catName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 1.0
|
||||
},
|
||||
|
||||
"lastIndexId" : {
|
||||
"type" : "long"
|
||||
},
|
||||
|
||||
"lastIndexName" : {
|
||||
"type" : "text",
|
||||
"analyzer": "ik_smart",
|
||||
"boost": 0.1
|
||||
},
|
||||
|
||||
"lastIndexUpdateTime" : {
|
||||
"type": "keyword"
|
||||
},
|
||||
|
||||
"picUrl" : {
|
||||
"type" : "keyword"
|
||||
},
|
||||
|
||||
"score" : {
|
||||
"type" : "float"
|
||||
},
|
||||
|
||||
"wordCount" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
|
||||
"workDirection" : {
|
||||
"type" : "short"
|
||||
},
|
||||
|
||||
"visitCount" : {
|
||||
"type": "long"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
INSERT INTO `crawl_source` (`id`, `source_name`, `crawl_rule`, `source_status`, `create_time`, `update_time`) VALUES ('4', '书趣阁', '{\r\n \"bookListUrl\": \"http://m.shuquge.com/sort/{catId}/0_{page}.html\",\r\n \"catIdRule\": {\r\n \"catId1\": \"1\",\r\n \"catId2\": \"2\",\r\n \"catId3\": \"3\",\r\n \"catId4\": \"4\",\r\n \"catId5\": \"7\",\r\n \"catId6\": \"6\",\r\n \"catId7\": \"8\"\r\n },\r\n \"bookIdPatten\": \"href=\\\"/s/(\\\\d+)\\\\.html\\\"\",\r\n \"pagePatten\": \"第(\\\\d+)/\\\\d+页\",\r\n \"totalPagePatten\": \"第\\\\d+/(\\\\d+)页\",\r\n \"bookDetailUrl\": \"http://m.shuquge.com/s/{bookId}.html\",\r\n \"bookNamePatten\": \"<a\\\\s+href=\\\"/s/\\\\d+\\\\.html\\\"><h2>([^/]+)</h2></a>\",\r\n \"authorNamePatten\": \"<p>作者:([^/]+)</p>\",\r\n \"picUrlPatten\": \"src=\\\"(http://www.shuquge.com/files/article/image/\\\\d+/\\\\d+/\\\\d+s\\\\.jpg)\\\"\",\r\n \"statusPatten\": \"<p>状态:([^/]+)</p>\",\r\n \"bookStatusRule\": {\r\n \"连载中\": 0,\r\n \"完本\": 1\r\n },\r\n \"descStart\": \"<div class=\\\"intro_info\\\">\",\r\n \"descEnd\": \"最新章节推荐地址\",\r\n \"bookIndexUrl\": \"http://www.shuquge.com/txt/{bookId}/index.html\",\r\n \"bookIndexStart\": \"》正文\",\r\n \"indexIdPatten\": \"<dd><a\\\\s+href=\\\"(\\\\d+)\\\\.html\\\">[^/]+</a></dd>\",\r\n \"indexNamePatten\": \"<dd><a\\\\s+href=\\\"\\\\d+\\\\.html\\\">([^/]+)</a></dd>\",\r\n \"bookContentUrl\": \"http://www.shuquge.com/txt/{bookId}/{indexId}.html\",\r\n \"contentStart\": \"<div id=\\\"content\\\" class=\\\"showtxt\\\">\",\r\n \"contentEnd\": \"http://www.shuquge.com\"\r\n}', '1', '2020-05-18 12:02:34', '2020-05-18 12:02:34');
|
||||
INSERT INTO `crawl_source` (`id`, `source_name`, `crawl_rule`, `source_status`, `create_time`, `update_time`) VALUES ('5', '笔趣阁', '{\"bookListUrl\":\"http://m.mcmssc.com/xclass/{catId}/{page}.html\",\"catIdRule\":{\"catId1\":\"1\",\"catId2\":\"2\",\"catId3\":\"3\",\"catId4\":\"4\",\"catId5\":\"5\",\"catId6\":\"6\",\"catId7\":\"7\"},\"bookIdPatten\":\"href=\\\"/(\\\\d+_\\\\d+)/\\\"\",\"pagePatten\":\"class=\\\"page_txt\\\"\\\\s+value=\\\"(\\\\d+)/\\\\d+\\\"\\\\s+size=\",\"totalPagePatten\":\"class=\\\"page_txt\\\"\\\\s+value=\\\"\\\\d+/(\\\\d+)\\\"\\\\s+size=\",\"bookDetailUrl\":\"http://m.mcmssc.com/{bookId}/\",\"bookNamePatten\":\"<span\\\\s+class=\\\"title\\\">([^/]+)</span>\",\"authorNamePatten\":\"<a\\\\s+href=\\\"/author/\\\\d+/\\\">([^/]+)</a>\",\"picUrlPatten\":\"<img\\\\s+src=\\\"([^>]+)\\\"\\\\s+onerror=\",\"picUrlPrefix\":\"http://m.mcmssc.com/\",\"statusPatten\":\">状态:([^/]+)<\",\"bookStatusRule\":{\"连载\":0,\"全本\":1},\"visitCountPatten\":\">点击:(\\\\d+)<\",\"descStart\":\"<p class=\\\"review\\\">\",\"descEnd\":\"</p>\",\"bookIndexUrl\":\"http://m.mcmssc.com/{bookId}/all.html\",\"indexIdPatten\":\"<a\\\\s+href=\\\"/\\\\d+_\\\\d+/(\\\\d+)\\\\.html\\\">[^/]+</a>\",\"indexNamePatten\":\"<a\\\\s+href=\\\"/\\\\d+_\\\\d+/\\\\d+\\\\.html\\\">([^/]+)</a>\",\"bookContentUrl\":\"http://www.mcmssc.com/{bookId}/{indexId}.html\",\"contentStart\":\"</p>\",\"contentEnd\":\"<div align=\\\"center\\\">\"}', '1', '2020-05-18 15:57:41', '2020-05-18 15:57:41');
|
||||
UPDATE `crawl_source` SET `source_name` = '书趣阁', `crawl_rule` = '{\n \"bookListUrl\": \"http://m.shuquge.com/sort/{catId}/0_{page}.html\",\n \"catIdRule\": {\n \"catId1\": \"1\",\n \"catId2\": \"2\",\n \"catId3\": \"3\",\n \"catId4\": \"4\",\n \"catId5\": \"7\",\n \"catId6\": \"6\",\n \"catId7\": \"8\"\n },\n \"bookIdPatten\": \"href=\\\"/s/(\\\\d+)\\\\.html\\\"\",\n \"pagePatten\": \"第(\\\\d+)/\\\\d+页\",\n \"totalPagePatten\": \"第\\\\d+/(\\\\d+)页\",\n \"bookDetailUrl\": \"http://m.shuquge.com/s/{bookId}.html\",\n \"bookNamePatten\": \"<a\\\\s+href=\\\"/s/\\\\d+\\\\.html\\\"><h2>([^/]+)</h2></a>\",\n \"authorNamePatten\": \"<p>作者:([^/]+)</p>\",\n \"picUrlPatten\": \"src=\\\"(http://www.shuquge.com/files/article/image/\\\\d+/\\\\d+/\\\\d+s\\\\.jpg)\\\"\",\n \"statusPatten\": \"<p>状态:([^/]+)</p>\",\n \"bookStatusRule\": {\n \"连载中\": 0,\n \"完本\": 1\n },\n \"descStart\": \"<div class=\\\"intro_info\\\">\",\n \"descEnd\": \"最新章节推荐地址\",\n \"bookIndexUrl\": \"http://www.shuquge.com/txt/{bookId}/index.html\",\n \"bookIndexStart\": \"<dt>《\",\n \"indexIdPatten\": \"<dd><a\\\\s+href=\\\"(\\\\d+)\\\\.html\\\">[^/]+</a></dd>\",\n \"indexNamePatten\": \"<dd><a\\\\s+href=\\\"\\\\d+\\\\.html\\\">([^/]+)</a></dd>\",\n \"bookContentUrl\": \"http://www.shuquge.com/txt/{bookId}/{indexId}.html\",\n \"contentStart\": \"<div id=\\\"content\\\" class=\\\"showtxt\\\">\",\n \"contentEnd\": \"http://www.shuquge.com\"\n}', `source_status` = 1, `create_time` = '2020-05-18 12:02:34', `update_time` = '2020-05-18 12:02:34' WHERE `id` = 4;
|
||||
@ -1,2 +0,0 @@
|
||||
INSERT INTO `crawl_source` (`id`, `source_name`, `crawl_rule`, `source_status`, `create_time`, `update_time`) VALUES
|
||||
(6, '新笔趣阁', '{\n \"bookListUrl\": \"http://www.xbiquge.la/fenlei/{catId}_{page}.html\",\n \"catIdRule\": {\n \"catId1\": \"1\",\n \"catId2\": \"2\",\n \"catId3\": \"3\",\n \"catId4\": \"4\",\n \"catId5\": \"6\",\n \"catId6\": \"5\"\n },\n \"bookIdPatten\": \"<a\\\\s+href=\\\"http://www.xbiquge.la/(\\\\d+/\\\\d+)/\\\"\\\\s+target=\\\"_blank\\\">\",\n \"pagePatten\": \"<em\\\\s+id=\\\"pagestats\\\">(\\\\d+)/\\\\d+</em>\",\n \"totalPagePatten\": \"<em\\\\s+id=\\\"pagestats\\\">\\\\d+/(\\\\d+)</em>\",\n \"bookDetailUrl\": \"http://www.xbiquge.la/{bookId}/\",\n \"bookNamePatten\": \"<h1>([^/]+)</h1>\",\n \"authorNamePatten\": \"者:([^/]+)</p>\",\n \"picUrlPatten\": \"src=\\\"(http://www.xbiquge.la/files/article/image/\\\\d+/\\\\d+/\\\\d+s\\\\.jpg)\\\"\",\n \"bookStatusRule\": {},\n \"descStart\": \"<div id=\\\"intro\\\">\",\n \"descEnd\": \"</div>\",\n \"upadateTimePatten\": \"<p>最后更新:(\\\\d+-\\\\d+-\\\\d+\\\\s\\\\d+:\\\\d+:\\\\d+)</p>\",\n \"upadateTimeFormatPatten\": \"yyyy-MM-dd HH:mm:ss\",\n \"bookIndexUrl\": \"http://www.xbiquge.la/{bookId}/\",\n \"indexIdPatten\": \"<a\\\\s+href=\'/\\\\d+/\\\\d+/(\\\\d+)\\\\.html\'\\\\s+>[^/]+</a>\",\n \"indexNamePatten\": \"<a\\\\s+href=\'/\\\\d+/\\\\d+/\\\\d+\\\\.html\'\\\\s+>([^/]+)</a>\",\n \"bookContentUrl\": \"http://www.xbiquge.la/{bookId}/{indexId}.html\",\n \"contentStart\": \"<div id=\\\"content\\\">\",\n \"contentEnd\": \"<p>\"\n}', 0, '2020-05-23 22:46:58', '2020-05-23 22:46:58');
|
||||
@ -1 +0,0 @@
|
||||
alter table book add column `yesterday_buy` int(11) DEFAULT '0' COMMENT '昨日订阅数' after comment_count;
|
||||
@ -1 +0,0 @@
|
||||
alter table book_index add column `book_price` int(3) DEFAULT 0 COMMENT '章节费用(屋币)' after `is_vip`;
|
||||
@ -1,32 +0,0 @@
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (246, 241, '批量删除', NULL, 'novel:news:batchRemove', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (245, 241, '删除', NULL, 'novel:news:remove', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (244, 241, '修改', NULL, 'novel:news:edit', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (243, 241, '新增', NULL, 'novel:news:add', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (242, 241, '查看', NULL, 'novel:news:detail', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (241, 234, '新闻列表', 'novel/news', 'novel:news:news', 1, 'fa', 8, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (240, 235, '批量删除', NULL, 'novel:category:batchRemove', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (239, 235, '删除', NULL, 'novel:category:remove', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (238, 235, '修改', NULL, 'novel:category:edit', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (237, 235, '新增', NULL, 'novel:category:add', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (236, 235, '查看', NULL, 'novel:category:detail', 2, NULL, 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (235, 234, '类别管理', 'novel/category', 'novel:category:category', 1, 'fa', 6, NULL, NULL);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`, `gmt_create`, `gmt_modified`) VALUES (234, 0, '新闻管理', '', '', 0, 'fa fa-newspaper-o', 8, NULL, NULL);
|
||||
|
||||
|
||||
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4889, 1, 246);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4890, 1, 245);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4891, 1, 244);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4892, 1, 243);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4893, 1, 242);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4899, 1, 241);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4894, 1, 240);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4895, 1, 239);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4896, 1, 238);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4897, 1, 237);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4898, 1, 236);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4900, 1, 235);
|
||||
INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4888, 1, 234);
|
||||
|
||||
|
||||
delete from sys_menu where menu_id = 202;
|
||||
@ -1 +0,0 @@
|
||||
alter table news add column `read_count` BIGINT NOT NULL DEFAULT '0' COMMENT '阅读量' after content;
|
||||
@ -1,3 +0,0 @@
|
||||
alter table book_index add column storage_type varchar(10) NOT NULL DEFAULT 'db' COMMENT '存储方式' after book_price ;
|
||||
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
INSERT INTO sys_dict (name, value, type, description, sort, parent_id, create_by, create_date, update_by,
|
||||
update_date, remarks, del_flag)
|
||||
VALUES ('轮播图', '0', 'book_rec_type', '小说推荐类型', 0, null, null, null, null, null, '', null);
|
||||
INSERT INTO sys_dict (name, value, type, description, sort, parent_id, create_by, create_date, update_by,
|
||||
update_date, remarks, del_flag)
|
||||
VALUES ('顶部小说栏', '1', 'book_rec_type', '小说推荐类型', 1, null, null, null, null, null, '', null);
|
||||
INSERT INTO sys_dict (name, value, type, description, sort, parent_id, create_by, create_date, update_by,
|
||||
update_date, remarks, del_flag)
|
||||
VALUES ('本周强推', '2', 'book_rec_type', '小说推荐类型', 2, null, null, null, null, null, '', null);
|
||||
INSERT INTO sys_dict (name, value, type, description, sort, parent_id, create_by, create_date, update_by,
|
||||
update_date, remarks, del_flag)
|
||||
VALUES ('热门推荐', '3', 'book_rec_type', '小说推荐类型', 3, null, null, null, null, null, '', null);
|
||||
INSERT INTO sys_dict (name, value, type, description, sort, parent_id, create_by, create_date, update_by,
|
||||
update_date, remarks, del_flag)
|
||||
VALUES ('精品推荐', '4', 'book_rec_type', '小说推荐类型', 4, null, null, null, null, null, '', null);
|
||||
|
||||
|
||||
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (320, '300', '小说推荐', 'novel/bookSetting', 'novel:bookSetting:bookSetting', '1', 'fa', '6');
|
||||
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (321, '320', '查看', null, 'novel:bookSetting:detail', '2', null, '6');
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (322, '320', '新增', null, 'novel:bookSetting:add', '2', null, '6');
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (323, '320', '修改', null, 'novel:bookSetting:edit', '2', null, '6');
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (324, '320', '删除', null, 'novel:bookSetting:remove', '2', null, '6');
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (325, '320', '批量删除', null, 'novel:bookSetting:batchRemove', '2', null, '6');
|
||||
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 320);
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 321);
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 322);
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 323);
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 324);
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 325);
|
||||
|
||||
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (410, '400', '会员反馈', 'novel/userFeedback', 'novel:userFeedback:userFeedback', '1', 'fa', '16');
|
||||
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 410);
|
||||
@ -1,4 +0,0 @@
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
VALUES (305, '301', '修改', null, 'novel:websiteInfo:edit', '2', null, '6');
|
||||
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES (1, 305);
|
||||
@ -1,3 +0,0 @@
|
||||
update crawl_source
|
||||
set crawl_rule = replace(crawl_rule, 'ibiquge.net', 'ibiquzw.org')
|
||||
where id = 16;
|
||||
@ -1,44 +0,0 @@
|
||||
INSERT INTO crawl_source (source_name, crawl_rule, source_status, create_time, update_time)
|
||||
VALUES ('香书小说网', '{
|
||||
"bookListUrl": "http://www.xbiqugu.la/fenlei/{catId}_{page}.html",
|
||||
"catIdRule": {
|
||||
"catId1": "1",
|
||||
"catId2": "2",
|
||||
"catId3": "3",
|
||||
"catId4": "4",
|
||||
"catId5": "6",
|
||||
"catId6": "5"
|
||||
},
|
||||
"bookIdPatten": "<a\\\\s+href=\\"http://www.xbiqugu.la/(\\\\d+/\\\\d+)/\\"\\\\s+target=\\"_blank\\">",
|
||||
"pagePatten": "<em\\\\s+id=\\"pagestats\\">(\\\\d+)/\\\\d+</em>",
|
||||
"totalPagePatten": "<em\\\\s+id=\\"pagestats\\">\\\\d+/(\\\\d+)</em>",
|
||||
"bookDetailUrl": "http://www.xbiqugu.la/{bookId}/",
|
||||
"bookNamePatten": "<h1>([^/]+)</h1>",
|
||||
"authorNamePatten": "者:([^/]+)</p>",
|
||||
"picUrlPatten": "src=\\"(http://www.xbiqugu.la/files/article/image/\\\\d+/\\\\d+/\\\\d+s\\\\.jpg)\\"",
|
||||
"bookStatusRule": {},
|
||||
"descStart": "<div id=\\"intro\\">",
|
||||
"descEnd": "</div>",
|
||||
"upadateTimePatten": "<p>最后更新:(\\\\d+-\\\\d+-\\\\d+\\\\s\\\\d+:\\\\d+:\\\\d+)</p>",
|
||||
"upadateTimeFormatPatten": "yyyy-MM-dd HH:mm:ss",
|
||||
"bookIndexUrl": "http://www.xbiqugu.la/{bookId}/",
|
||||
"indexIdPatten": "<a\\\\s+href=''/\\\\d+/\\\\d+/(\\\\d+)\\\\.html''\\\\s+>[^/]+</a>",
|
||||
"indexNamePatten": "<a\\\\s+href=''/\\\\d+/\\\\d+/\\\\d+\\\\.html''\\\\s+>([^/]+)</a>",
|
||||
"bookContentUrl": "http://www.xbiqugu.la/{bookId}/{indexId}.html",
|
||||
"contentStart": "<div id=\\"content\\">",
|
||||
"contentEnd": "<p>",
|
||||
"filterContent":"<div\\\\s+id=\\"content_tip\\">\\\\s*<b>([^/]+)</b>\\\\s*</div>"
|
||||
}', 0, '2024-06-01 10:11:39', '2024-06-01 10:11:39');
|
||||
|
||||
|
||||
update crawl_source
|
||||
set crawl_rule = replace(crawl_rule, 'ibiquzw.org', 'biquxs.info')
|
||||
where id = 16;
|
||||
|
||||
delete
|
||||
from sys_menu
|
||||
where menu_id = 104;
|
||||
|
||||
delete
|
||||
from sys_menu
|
||||
where menu_id = 57;
|
||||
@ -1,2 +0,0 @@
|
||||
FROM mysql:8.0
|
||||
COPY novel_plus.sql /docker-entrypoint-initdb.d/init.sql
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,13 +0,0 @@
|
||||
#端口号
|
||||
server:
|
||||
port: 8088
|
||||
spring:
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password: 123456
|
||||
|
||||
#
|
||||
#pic:
|
||||
# save:
|
||||
# path: F:/novel-system/novel-plus/novel-admin/src/main/resources/
|
||||
@ -1,9 +0,0 @@
|
||||
FROM openjdk:8
|
||||
ADD novel-admin.jar /root
|
||||
ENV dburl=""
|
||||
ENV username=""
|
||||
ENV password=""
|
||||
ENV redishost = ""
|
||||
ENV redisport = ""
|
||||
ENV redispwd = ""
|
||||
ENTRYPOINT ["sh","-c","java -Dspring.datasource.url=${dburl} -Dspring.datasource.username=${username} -Dspring.datasource.password=${password} -Dspring.redis.host=${redishost} -Dspring.redis.port=${redisport} -Dspring.redis.password=${redispwd} -jar /root/novel-admin.jar"]
|
||||
@ -1,37 +0,0 @@
|
||||
package com.java2nb;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
|
||||
@EnableTransactionManagement
|
||||
@ServletComponentScan
|
||||
@MapperScan("com.java2nb.*.dao")
|
||||
@SpringBootApplication(exclude = {
|
||||
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
||||
})
|
||||
@EnableCaching
|
||||
@Slf4j
|
||||
public class AdminApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
||||
return args -> {
|
||||
log.info("项目启动啦,访问路径:{}", "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment().getProperty("server.port"));
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package com.java2nb.common.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
String value() default "";
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
package com.java2nb.common.aspect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.java2nb.common.service.LogService;
|
||||
import com.java2nb.system.domain.UserToken;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.java2nb.common.annotation.Log;
|
||||
import com.java2nb.common.dao.LogDao;
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
import com.java2nb.common.utils.HttpContextUtils;
|
||||
import com.java2nb.common.utils.IPUtils;
|
||||
import com.java2nb.common.utils.JSONUtils;
|
||||
import com.java2nb.common.utils.ShiroUtils;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class LogAspect {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
|
||||
|
||||
@Autowired
|
||||
LogService logService;
|
||||
|
||||
|
||||
@Pointcut("@annotation(com.java2nb.common.annotation.Log)")
|
||||
public void logPointCut() {
|
||||
}
|
||||
|
||||
@Around("logPointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
long beginTime = System.currentTimeMillis();
|
||||
// 执行方法
|
||||
Object result = point.proceed();
|
||||
// 执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
//异步保存日志
|
||||
saveLog(point, time);
|
||||
return result;
|
||||
}
|
||||
|
||||
void saveLog(ProceedingJoinPoint joinPoint, long time) throws InterruptedException {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
LogDO sysLog = new LogDO();
|
||||
Log syslog = method.getAnnotation(Log.class);
|
||||
if (syslog != null) {
|
||||
// 注解上的描述
|
||||
sysLog.setOperation(syslog.value());
|
||||
}
|
||||
// 请求的方法名
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = signature.getName();
|
||||
sysLog.setMethod(className + "." + methodName + "()");
|
||||
// 请求的参数
|
||||
Object[] args = joinPoint.getArgs();
|
||||
try {
|
||||
String params = JSONUtils.beanToJson(args[0]).substring(0, 4999);
|
||||
sysLog.setParams(params);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
// 获取request
|
||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||
// 设置IP地址
|
||||
sysLog.setIp(IPUtils.getIpAddr(request));
|
||||
// 用户名
|
||||
UserDO currUser = ShiroUtils.getUser();
|
||||
if (null == currUser) {
|
||||
if (null != sysLog.getParams()) {
|
||||
sysLog.setUserId(-1L);
|
||||
sysLog.setUsername(sysLog.getParams());
|
||||
} else {
|
||||
sysLog.setUserId(-1L);
|
||||
sysLog.setUsername("获取用户信息为空");
|
||||
}
|
||||
} else {
|
||||
sysLog.setUserId(ShiroUtils.getUserId());
|
||||
sysLog.setUsername(ShiroUtils.getUser().getUsername());
|
||||
}
|
||||
sysLog.setTime((int) time);
|
||||
// 系统当前时间
|
||||
Date date = new Date();
|
||||
sysLog.setGmtCreate(date);
|
||||
// 保存系统日志
|
||||
logService.save(sysLog);
|
||||
}
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package com.java2nb.common.aspect;
|
||||
|
||||
import com.java2nb.common.utils.IPUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class WebLogAspect {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
|
||||
|
||||
@Pointcut("execution( * com.java2nb..controller.*.*(..))")//两个..代表所有子目录,最后括号里的两个..代表所有参数
|
||||
public void logPointCut() {
|
||||
}
|
||||
|
||||
|
||||
@Before("logPointCut()")
|
||||
public void doBefore(JoinPoint joinPoint) throws Throwable {
|
||||
// 接收到请求,记录请求内容
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
|
||||
// 记录下请求内容
|
||||
logger.info("请求地址 : " + request.getRequestURL().toString());
|
||||
logger.info("HTTP METHOD : " + request.getMethod());
|
||||
// 获取真实的ip地址
|
||||
logger.info("IP : " + IPUtils.getIpAddr(request));
|
||||
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
|
||||
+ joinPoint.getSignature().getName());
|
||||
logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
|
||||
|
||||
}
|
||||
|
||||
@AfterReturning(returning = "ret", pointcut = "logPointCut()")// returning的值和doAfterReturning的参数名一致
|
||||
public void doAfterReturning(Object ret) throws Throwable {
|
||||
// 处理完请求,返回内容(返回值太复杂时,打印的是物理存储空间的地址)
|
||||
logger.debug("返回值 : " + ret);
|
||||
}
|
||||
|
||||
@Around("logPointCut()")
|
||||
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object ob = pjp.proceed();// ob 为方法的返回值
|
||||
logger.info("耗时 : " + (System.currentTimeMillis() - startTime));
|
||||
return ob;
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xiongxy
|
||||
* @date 2019-09-25 15:09:21
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Component
|
||||
public class ApplicationContextRegister implements ApplicationContextAware {
|
||||
private static Logger logger = LoggerFactory.getLogger(ApplicationContextRegister.class);
|
||||
private static ApplicationContext APPLICATION_CONTEXT;
|
||||
/**
|
||||
* 设置spring上下文
|
||||
* @param applicationContext spring上下文
|
||||
* @throws BeansException
|
||||
* */
|
||||
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
logger.debug("ApplicationContext registed-->{}", applicationContext);
|
||||
APPLICATION_CONTEXT = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取容器
|
||||
* @return
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return APPLICATION_CONTEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取容器对象
|
||||
* @param type
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getBean(Class<T> type) {
|
||||
return APPLICATION_CONTEXT.getBean(type);
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.SessionListener;
|
||||
|
||||
public class BDSessionListener implements SessionListener {
|
||||
|
||||
private final AtomicInteger sessionCount = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
public void onStart(Session session) {
|
||||
sessionCount.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(Session session) {
|
||||
sessionCount.decrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpiration(Session session) {
|
||||
sessionCount.decrementAndGet();
|
||||
|
||||
}
|
||||
|
||||
public int getSessionCount() {
|
||||
return sessionCount.get();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
public interface CacheKey {
|
||||
|
||||
/**
|
||||
* 首页小说设置
|
||||
*/
|
||||
String INDEX_BOOK_SETTINGS_KEY = "indexBookSettingsKey";
|
||||
|
||||
/**
|
||||
* 首页新闻
|
||||
*/
|
||||
String INDEX_NEWS_KEY = "indexNewsKey";
|
||||
|
||||
/**
|
||||
* 首页点击榜单
|
||||
*/
|
||||
String INDEX_CLICK_BANK_BOOK_KEY = "indexClickBankBookKey";
|
||||
|
||||
/**
|
||||
* 首页友情链接
|
||||
*/
|
||||
String INDEX_LINK_KEY = "indexLinkKey";
|
||||
|
||||
/**
|
||||
* 首页新书榜单
|
||||
*/
|
||||
String INDEX_NEW_BOOK_KEY = "indexNewBookKey";
|
||||
|
||||
|
||||
/**
|
||||
* 首页更新榜单
|
||||
*/
|
||||
String INDEX_UPDATE_BOOK_KEY = "indexUpdateBookKey";
|
||||
|
||||
/**
|
||||
* 模板目录保存key
|
||||
*/
|
||||
String TEMPLATE_DIR_KEY = "templateDirKey";
|
||||
;
|
||||
|
||||
/**
|
||||
* 正在运行的爬虫线程存储KEY前缀
|
||||
*/
|
||||
String RUNNING_CRAWL_THREAD_KEY_PREFIX = "runningCrawlTreadDataKeyPrefix";
|
||||
|
||||
/**
|
||||
* 上一次搜索引擎更新的时间
|
||||
*/
|
||||
String ES_LAST_UPDATE_TIME = "esLastUpdateTime";
|
||||
|
||||
/**
|
||||
* 搜索引擎转换锁
|
||||
*/
|
||||
String ES_TRANS_LOCK = "esTransLock";
|
||||
|
||||
/**
|
||||
* 上一次搜索引擎是否更新过小说点击量
|
||||
*/
|
||||
String ES_IS_UPDATE_VISIT = "esIsUpdateVisit";
|
||||
|
||||
/**
|
||||
* 累积的小说点击量
|
||||
*/
|
||||
String BOOK_ADD_VISIT_COUNT = "bookAddVisitCount";
|
||||
/**
|
||||
* 测试爬虫规则缓存
|
||||
*/
|
||||
String BOOK_TEST_PARSE = "testParse";
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
public class Constant {
|
||||
|
||||
//演示系统账户
|
||||
public static String DEMO_ACCOUNT = "test";
|
||||
//自动去除表前缀
|
||||
public static String AUTO_REOMVE_PRE = "true";
|
||||
//停止计划任务
|
||||
public static String STATUS_RUNNING_STOP = "stop";
|
||||
//开启计划任务
|
||||
public static String STATUS_RUNNING_START = "start";
|
||||
//通知公告阅读状态-未读
|
||||
public static String OA_NOTIFY_READ_NO = "0";
|
||||
//通知公告阅读状态-已读
|
||||
public static int OA_NOTIFY_READ_YES = 1;
|
||||
//部门根节点id
|
||||
public static Long DEPT_ROOT_ID = 0l;
|
||||
//缓存方式
|
||||
public static String CACHE_TYPE_REDIS = "redis";
|
||||
|
||||
public static String LOG_ERROR = "error";
|
||||
|
||||
public static final String UPLOAD_FILES_PREFIX = "/files/";
|
||||
|
||||
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.zip.DataFormatException;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @date 2019-09-25 15:09:21
|
||||
*/
|
||||
@Configuration
|
||||
public class DateConverConfig {
|
||||
@Bean
|
||||
public Converter<String, Date> stringDateConvert() {
|
||||
return new Converter<String, Date>() {
|
||||
@Override
|
||||
public Date convert(String source) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = null;
|
||||
try {
|
||||
date = sdf.parse((String) source);
|
||||
} catch (Exception e) {
|
||||
SimpleDateFormat sdfday = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
date = sdfday.parse((String) source);
|
||||
} catch (ParseException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix="java2nb")
|
||||
public class JnConfig {
|
||||
//上传路径
|
||||
private String uploadPath;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
public String getUploadPath() {
|
||||
return uploadPath;
|
||||
}
|
||||
|
||||
public void setUploadPath(String uploadPath) {
|
||||
this.uploadPath = uploadPath;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@EnableAutoConfiguration(exclude = {
|
||||
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
||||
})
|
||||
@Configuration
|
||||
public class SecuityConfig {
|
||||
|
||||
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class SpringAsyncConfig {
|
||||
// @Bean
|
||||
// public AsyncTaskExecutor taskExecutor() {
|
||||
// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
// executor.setMaxPoolSize(10);
|
||||
// return executor;
|
||||
// }
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.java2nb.common.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Component
|
||||
class WebConfigurer extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
JnConfig jnConfig;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler(Constant.UPLOAD_FILES_PREFIX + "**")
|
||||
.addResourceLocations("file:///" + jnConfig.getUploadPath());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.java2nb.system.domain.UserToken;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.java2nb.common.utils.ShiroUtils;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
|
||||
@Controller
|
||||
public class BaseController {
|
||||
public UserDO getUser() {
|
||||
return ShiroUtils.getUser();
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return getUser().getUserId();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return getUser().getUsername();
|
||||
}
|
||||
}
|
||||
@ -1,148 +0,0 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.java2nb.common.config.Constant;
|
||||
import com.java2nb.common.domain.DictDO;
|
||||
import com.java2nb.common.service.DictService;
|
||||
import com.java2nb.common.utils.PageBean;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import com.java2nb.common.utils.R;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-09-29 18:28:07
|
||||
*/
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/common/dict")
|
||||
public class DictController extends BaseController {
|
||||
@Autowired
|
||||
private DictService dictService;
|
||||
|
||||
@GetMapping()
|
||||
@RequiresPermissions("common:dict:dict")
|
||||
String dict() {
|
||||
return "common/dict/dict";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("common:dict:dict")
|
||||
public PageBean list(@RequestParam Map<String, Object> params) {
|
||||
// 查询列表数据
|
||||
Query query = new Query(params);
|
||||
List<DictDO> dictList = dictService.list(query);
|
||||
int total = dictService.count(query);
|
||||
PageBean pageBean = new PageBean(dictList, total);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@GetMapping("/add")
|
||||
@RequiresPermissions("common:dict:add")
|
||||
String add() {
|
||||
return "common/dict/add";
|
||||
}
|
||||
|
||||
@GetMapping("/edit/{id}")
|
||||
@RequiresPermissions("common:dict:edit")
|
||||
String edit(@PathVariable("id") Long id, Model model) {
|
||||
DictDO dict = dictService.get(id);
|
||||
model.addAttribute("dict", dict);
|
||||
return "common/dict/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("common:dict:add")
|
||||
public R save(DictDO dict) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
if (dictService.save(dict) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping("/update")
|
||||
@RequiresPermissions("common:dict:edit")
|
||||
public R update(DictDO dict) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
dictService.update(dict);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ResponseBody
|
||||
@RequiresPermissions("common:dict:remove")
|
||||
public R remove(Long id) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
if (dictService.remove(id) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
@RequiresPermissions("common:dict:batchRemove")
|
||||
public R remove(@RequestParam("ids[]") Long[] ids) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
dictService.batchRemove(ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/type")
|
||||
@ResponseBody
|
||||
public List<DictDO> listType() {
|
||||
return dictService.listType();
|
||||
};
|
||||
|
||||
// 类别已经指定增加
|
||||
@GetMapping("/add/{type}/{description}")
|
||||
@RequiresPermissions("common:dict:add")
|
||||
String addD(Model model, @PathVariable("type") String type, @PathVariable("description") String description) {
|
||||
model.addAttribute("type", type);
|
||||
model.addAttribute("description", description);
|
||||
return "common/dict/add";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list/{type}")
|
||||
public List<DictDO> listByType(@PathVariable("type") String type) {
|
||||
// 查询列表数据
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
map.put("type", type);
|
||||
List<DictDO> dictList = dictService.list(map);
|
||||
return dictList;
|
||||
}
|
||||
}
|
||||
@ -1,157 +0,0 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.java2nb.common.domain.GenColumnsDO;
|
||||
import com.java2nb.common.service.GeneratorService;
|
||||
import com.java2nb.common.utils.GenUtils;
|
||||
import com.java2nb.common.utils.PageBean;
|
||||
import com.java2nb.common.utils.R;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.commons.configuration.PropertiesConfiguration;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequestMapping("/common/generator")
|
||||
@Controller
|
||||
public class GeneratorController {
|
||||
String prefix = "common/generator";
|
||||
@Autowired
|
||||
GeneratorService generatorService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@GetMapping()
|
||||
String generator() {
|
||||
return prefix + "/list";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
List<Map<String, Object>> list(String tableName) {
|
||||
List<Map<String, Object>> list = generatorService.list(tableName);
|
||||
return list;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@RequestMapping("/downLoadCode/{tableName}")
|
||||
public void downLoadCode(HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable("tableName") String tableName) throws IOException {
|
||||
String[] tableNames = new String[]{tableName};
|
||||
byte[] data = generatorService.downloadCode(tableNames);
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"java2nb.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/genCode")
|
||||
public R genCode(String tableName) {
|
||||
String[] tableNames = new String[]{tableName};
|
||||
generatorService.generatorCode(tableNames);
|
||||
return R.ok("代码生成成功,请到本地项目中查看!");
|
||||
}
|
||||
|
||||
@RequestMapping("/batchDownload")
|
||||
public void batchDownload(HttpServletRequest request, HttpServletResponse response, String tables) throws IOException {
|
||||
String[] tableNames = new String[]{};
|
||||
tableNames = JSON.parseArray(tables).toArray(tableNames);
|
||||
byte[] data = generatorService.downloadCode(tableNames);
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"java2nb.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/batchCode")
|
||||
public R batchCode(String tables) {
|
||||
String[] tableNames = new String[]{};
|
||||
tableNames = JSON.parseArray(tables).toArray(tableNames);
|
||||
generatorService.generatorCode(tableNames);
|
||||
return R.ok("代码批量生成成功,请到本地项目中查看!");
|
||||
}
|
||||
|
||||
@GetMapping("/edit")
|
||||
public String edit(Model model) {
|
||||
Configuration conf = GenUtils.getConfig();
|
||||
Map<String, Object> property = new HashMap<>(16);
|
||||
property.put("author", conf.getProperty("author"));
|
||||
property.put("email", conf.getProperty("email"));
|
||||
property.put("package", conf.getProperty("package"));
|
||||
property.put("autoRemovePre", conf.getProperty("autoRemovePre"));
|
||||
property.put("tablePrefix", conf.getProperty("tablePrefix"));
|
||||
property.put("srcPath", conf.getProperty("srcPath"));
|
||||
model.addAttribute("property", property);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/update")
|
||||
R update(@RequestParam Map<String, Object> map) {
|
||||
try {
|
||||
PropertiesConfiguration conf = new PropertiesConfiguration("generator.properties");
|
||||
conf.setProperty("author", map.get("author"));
|
||||
conf.setProperty("email", map.get("email"));
|
||||
conf.setProperty("package", map.get("package"));
|
||||
conf.setProperty("autoRemovePre", map.get("autoRemovePre"));
|
||||
conf.setProperty("tablePrefix", map.get("tablePrefix"));
|
||||
conf.setProperty("srcPath", map.get("srcPath"));
|
||||
conf.save();
|
||||
} catch (ConfigurationException e) {
|
||||
return R.error("保存配置文件出错");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/genColumns")
|
||||
String genColumns(String tableName, Model model) {
|
||||
model.addAttribute("tableName", tableName);
|
||||
return "common/genColumns/genColumns";
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/genColumns/list")
|
||||
@SneakyThrows
|
||||
public R genColumnsList(String tableName) {
|
||||
List<GenColumnsDO> genColumns = generatorService.listColumnsByTableName(tableName);
|
||||
int total = genColumns.size();
|
||||
PageBean pageBean = new PageBean(genColumns, total);
|
||||
return R.ok().put("data", pageBean);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@ApiOperation(value = "新增", notes = "新增")
|
||||
@ResponseBody
|
||||
@PostMapping("/genColumns/save")
|
||||
public R save(@RequestBody List<GenColumnsDO> list) {
|
||||
generatorService.genColumnsSave(list);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
import com.java2nb.common.domain.PageDO;
|
||||
import com.java2nb.common.service.LogService;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import com.java2nb.common.utils.R;
|
||||
|
||||
@RequestMapping("/common/log")
|
||||
@Controller
|
||||
public class LogController {
|
||||
@Autowired
|
||||
LogService logService;
|
||||
String prefix = "common/log";
|
||||
|
||||
@GetMapping()
|
||||
String log() {
|
||||
return prefix + "/log";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
PageDO<LogDO> list(@RequestParam Map<String, Object> params) {
|
||||
Query query = new Query(params);
|
||||
PageDO<LogDO> page = logService.queryList(query);
|
||||
return page;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/remove")
|
||||
R remove(Long id) {
|
||||
if (logService.remove(id)>0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/batchRemove")
|
||||
R batchRemove(@RequestParam("ids[]") Long[] ids) {
|
||||
int r = logService.batchRemove(ids);
|
||||
if (r > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package com.java2nb.common.dao;
|
||||
|
||||
import com.java2nb.common.domain.DictDO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
*
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-10-03 15:45:42
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictDao {
|
||||
|
||||
DictDO get(Long id);
|
||||
|
||||
List<DictDO> list(Map<String, Object> map);
|
||||
|
||||
int count(Map<String, Object> map);
|
||||
|
||||
int save(DictDO dict);
|
||||
|
||||
int update(DictDO dict);
|
||||
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
List<DictDO> listType();
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.java2nb.common.dao;
|
||||
|
||||
import com.java2nb.common.domain.FileDO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-10-03 15:45:42
|
||||
*/
|
||||
@Mapper
|
||||
public interface FileDao {
|
||||
|
||||
FileDO get(Long id);
|
||||
|
||||
List<FileDO> list(Map<String,Object> map);
|
||||
|
||||
int count(Map<String,Object> map);
|
||||
|
||||
int save(FileDO file);
|
||||
|
||||
int update(FileDO file);
|
||||
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package com.java2nb.common.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.java2nb.common.domain.GenColumnsDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-11-22 10:39:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface GenColumnsDao {
|
||||
|
||||
|
||||
GenColumnsDO get(Long id);
|
||||
|
||||
List<GenColumnsDO> list(Map<String,Object> map);
|
||||
|
||||
int count(Map<String,Object> map);
|
||||
|
||||
int save(GenColumnsDO genColumns);
|
||||
|
||||
int update(GenColumnsDO genColumns);
|
||||
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
|
||||
void saveBatch(List<GenColumnsDO> list);
|
||||
|
||||
void deleteByTableName(@Param("tableName") String tableName);
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package com.java2nb.common.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface GeneratorMapper {
|
||||
|
||||
@Select(
|
||||
"select table_name tableName, engine, table_comment tableComment, create_time createTime from tables"
|
||||
+ " where table_schema = 'novel_plus' and table_name like concat('%',#{tableName},'%')")
|
||||
List<Map<String, Object>> list(@Param("tableName") String tableName);
|
||||
|
||||
@Select("select count(*) from tables where table_schema = 'novel_plus'")
|
||||
int count(Map<String, Object> map);
|
||||
|
||||
@Select(
|
||||
"select table_name tableName, engine, table_comment tableComment, create_time createTime from tables \r\n"
|
||||
+ " where table_schema = 'novel_plus' and table_name = #{tableName}")
|
||||
Map<String, String> get(String tableName);
|
||||
|
||||
@Select(
|
||||
"select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from columns\r\n"
|
||||
+ " where table_name = #{tableName} and table_schema = 'novel_plus' order by ordinal_position")
|
||||
List<Map<String, String>> listColumns(String tableName);
|
||||
|
||||
@Select(
|
||||
"select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from columns\r\n"
|
||||
+ " where table_name = #{tableName} and table_schema = 'novel_plus' and column_key = 'PRI' limit 1")
|
||||
Map<String, String> getPriColumn(String tableName);
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.java2nb.common.dao;
|
||||
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-10-03 15:45:42
|
||||
*/
|
||||
@Mapper
|
||||
public interface LogDao {
|
||||
|
||||
LogDO get(Long id);
|
||||
|
||||
List<LogDO> list(Map<String,Object> map);
|
||||
|
||||
int count(Map<String,Object> map);
|
||||
|
||||
int save(LogDO log);
|
||||
|
||||
int update(LogDO log);
|
||||
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
package com.java2nb.common.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class LogDO {
|
||||
private Long id;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String username;
|
||||
|
||||
private String operation;
|
||||
|
||||
private Integer time;
|
||||
|
||||
private String method;
|
||||
|
||||
private String params;
|
||||
|
||||
private String ip;
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date gmtCreate;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username == null ? null : username.trim();
|
||||
}
|
||||
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public void setOperation(String operation) {
|
||||
this.operation = operation == null ? null : operation.trim();
|
||||
}
|
||||
|
||||
public Integer getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Integer time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method == null ? null : method.trim();
|
||||
}
|
||||
|
||||
public String getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(String params) {
|
||||
this.params = params == null ? null : params.trim();
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip == null ? null : ip.trim();
|
||||
}
|
||||
|
||||
public Date getGmtCreate() {
|
||||
return gmtCreate;
|
||||
}
|
||||
|
||||
public void setGmtCreate(Date gmtCreate) {
|
||||
this.gmtCreate = gmtCreate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LogDO{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", username='" + username + '\'' +
|
||||
", operation='" + operation + '\'' +
|
||||
", time=" + time +
|
||||
", method='" + method + '\'' +
|
||||
", params='" + params + '\'' +
|
||||
", ip='" + ip + '\'' +
|
||||
", gmtCreate=" + gmtCreate +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
package com.java2nb.common.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PageDO<T> {
|
||||
|
||||
private int offset;
|
||||
private int limit;
|
||||
private int total;
|
||||
private Map<String, Object> params;
|
||||
private String param;
|
||||
private List<T> rows;
|
||||
|
||||
public PageDO() {
|
||||
super();
|
||||
this.offset = 0;
|
||||
this.limit = 10;
|
||||
this.total = 1;
|
||||
this.params = new HashMap<>();
|
||||
this.param = "";
|
||||
this.rows = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, Object> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public List<T> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<T> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public String getParam() {
|
||||
return param;
|
||||
}
|
||||
|
||||
public void setParam(String param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PageDO{" +
|
||||
"offset=" + offset +
|
||||
", limit=" + limit +
|
||||
", total=" + total +
|
||||
", params=" + params +
|
||||
", param='" + param + '\'' +
|
||||
", rows=" + rows +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package com.java2nb.common.exception;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自定义业务异常
|
||||
*/
|
||||
@Data
|
||||
public class BusinessException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String msg;
|
||||
private int code;
|
||||
|
||||
public BusinessException(int code,String msg) {
|
||||
//不调用父类Throwable的fillInStackTrace()方法生成栈追踪信息,提高应用性能
|
||||
//构造器之间的调用必须在第一行
|
||||
super(msg, null, false, false);
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
package com.java2nb.common.exception;
|
||||
|
||||
import com.java2nb.common.config.Constant;
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
import com.java2nb.common.service.LogService;
|
||||
import com.java2nb.common.utils.HttpServletUtils;
|
||||
import com.java2nb.common.utils.R;
|
||||
import com.java2nb.common.utils.ShiroUtils;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 异常处理器
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class CommonExceptionHandler {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
@Autowired
|
||||
LogService logService;
|
||||
|
||||
/**
|
||||
* 自定义业务异常处理
|
||||
*/
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public R handleBusinessException(BusinessException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return R.error(e.getCode(),e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(DuplicateKeyException.class)
|
||||
public R handleDuplicateKeyException(DuplicateKeyException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return R.error("数据库中已存在该记录");
|
||||
}
|
||||
|
||||
@ExceptionHandler(org.springframework.web.servlet.NoHandlerFoundException.class)
|
||||
public R noHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return R.error(404, "没找找到页面");
|
||||
}
|
||||
|
||||
@ExceptionHandler(AuthorizationException.class)
|
||||
public Object handleAuthorizationException(AuthorizationException e, HttpServletRequest request) {
|
||||
logger.error(e.getMessage(), e);
|
||||
if (HttpServletUtils.jsAjax(request)) {
|
||||
return R.error(403, "未授权");
|
||||
}
|
||||
return new ModelAndView("error/403");
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler({Exception.class})
|
||||
public Object handleException(Exception e, HttpServletRequest request) {
|
||||
LogDO logDO = new LogDO();
|
||||
logDO.setGmtCreate(new Date());
|
||||
logDO.setOperation(Constant.LOG_ERROR);
|
||||
logDO.setMethod(request.getRequestURL().toString());
|
||||
logDO.setParams(e.toString());
|
||||
UserDO current = ShiroUtils.getUser();
|
||||
if(null!=current){
|
||||
logDO.setUserId(current.getUserId());
|
||||
logDO.setUsername(current.getUsername());
|
||||
}
|
||||
logService.save(logDO);
|
||||
logger.error(e.getMessage(), e);
|
||||
if (HttpServletUtils.jsAjax(request)) {
|
||||
return R.error(500, "服务器错误,请联系管理员");
|
||||
}
|
||||
return new ModelAndView("error/500");
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package com.java2nb.common.exception;
|
||||
|
||||
|
||||
import com.java2nb.common.utils.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@RestController
|
||||
public class MainsiteErrorController implements ErrorController {
|
||||
|
||||
private static final String ERROR_PATH = "/error";
|
||||
|
||||
@Autowired
|
||||
ErrorAttributes errorAttributes;
|
||||
|
||||
@RequestMapping(
|
||||
value = {ERROR_PATH},
|
||||
produces = {"text/html"}
|
||||
)
|
||||
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
|
||||
int code = response.getStatus();
|
||||
if (404 == code) {
|
||||
return new ModelAndView("error/404");
|
||||
} else if (403 == code) {
|
||||
return new ModelAndView("error/403");
|
||||
} else if (401 == code) {
|
||||
return new ModelAndView("login");
|
||||
} else {
|
||||
return new ModelAndView("error/500");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = ERROR_PATH)
|
||||
public R handleError(HttpServletRequest request, HttpServletResponse response) {
|
||||
response.setStatus(200);
|
||||
int code = response.getStatus();
|
||||
if (404 == code) {
|
||||
return R.error(404, "未找到资源");
|
||||
} else if (403 == code) {
|
||||
return R.error(403, "没有访问权限");
|
||||
} else if (401 == code) {
|
||||
return R.error(403, "登录过期");
|
||||
} else {
|
||||
return R.error(500, "服务器错误");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,155 +0,0 @@
|
||||
package com.java2nb.common.interceptor;
|
||||
|
||||
import com.java2nb.common.utils.ShiroUtils;
|
||||
import com.java2nb.system.domain.DataPermDO;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
import org.apache.ibatis.cache.CacheKey;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Intercepts({@Signature(
|
||||
type = Executor.class,
|
||||
method = "query",
|
||||
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
|
||||
), @Signature(
|
||||
type = Executor.class,
|
||||
method = "query",
|
||||
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}
|
||||
)})
|
||||
@Component
|
||||
public class DataPermInterceptor implements Interceptor {
|
||||
|
||||
|
||||
public DataPermInterceptor() {
|
||||
super();
|
||||
}
|
||||
|
||||
//插件运行的代码,它将代替原有的方法
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
Object[] args = invocation.getArgs();
|
||||
MappedStatement mappedStatement = (MappedStatement) args[0];
|
||||
String sqlId = mappedStatement.getId();
|
||||
String methodName = sqlId.substring(sqlId.lastIndexOf(".") + 1);
|
||||
if (methodName.endsWith("ByPerm")) {
|
||||
Object parameter = args[1];
|
||||
RowBounds rowBounds = (RowBounds) args[2];
|
||||
ResultHandler resultHandler = (ResultHandler) args[3];
|
||||
Executor executor = (Executor) invocation.getTarget();
|
||||
CacheKey cacheKey;
|
||||
BoundSql boundSql;
|
||||
if (args.length == 4) {
|
||||
boundSql = mappedStatement.getBoundSql(parameter);
|
||||
cacheKey = executor.createCacheKey(mappedStatement, parameter, rowBounds, boundSql);
|
||||
} else {
|
||||
cacheKey = (CacheKey) args[4];
|
||||
boundSql = (BoundSql) args[5];
|
||||
}
|
||||
Class<BoundSql> boundSqlClass = BoundSql.class;
|
||||
Field field = boundSqlClass.getDeclaredField("sql");
|
||||
field.setAccessible(true);
|
||||
String lastSql = boundSql.getSql();
|
||||
Pattern tableNamePattern = Pattern.compile("\\s+from\\s+([^\\s]+)\\s*");
|
||||
Matcher tableNameMatcher = tableNamePattern.matcher(lastSql);
|
||||
if (tableNameMatcher.find()) {
|
||||
String tableName = tableNameMatcher.group(1);
|
||||
if(!tableName.contains("_")){
|
||||
if(tableNameMatcher.find()) {
|
||||
tableName = tableNameMatcher.group(1);
|
||||
}
|
||||
}
|
||||
UserDO user = ShiroUtils.getUser();
|
||||
List<DataPermDO> perms = user.getDataPerms().get(tableName);
|
||||
String pageSql = "";
|
||||
int limitIndex = lastSql.indexOf(" limit ");
|
||||
if (limitIndex != -1) {
|
||||
pageSql = lastSql.substring(limitIndex);
|
||||
lastSql = lastSql.substring(0, limitIndex);
|
||||
}
|
||||
String orderSql = "";
|
||||
int orderIndex = lastSql.indexOf(" order ");
|
||||
if (orderIndex == -1) {
|
||||
orderIndex = lastSql.indexOf(" ORDER ");
|
||||
}
|
||||
if (orderIndex != -1) {
|
||||
orderSql = lastSql.substring(orderIndex);
|
||||
lastSql = lastSql.substring(0, orderIndex);
|
||||
}
|
||||
|
||||
String linkSql = " WHERE ";
|
||||
String permSql = "";
|
||||
boolean allPerms= false;
|
||||
if (perms != null && perms.size() > 0) {
|
||||
|
||||
Class userClass = UserDO.class;
|
||||
for (DataPermDO perm : perms) {
|
||||
if (allPerms) {
|
||||
break;
|
||||
}
|
||||
|
||||
String attrName = perm.getCrlAttrName();
|
||||
String columnName = perm.getCrlColumnName();
|
||||
String permCode = perm.getPermCode();
|
||||
|
||||
switch (permCode.substring(0, permCode.indexOf("_"))) {
|
||||
case "all": {
|
||||
allPerms = true;
|
||||
break;
|
||||
}
|
||||
case "own": {
|
||||
Field attrNameField = userClass.getDeclaredField(attrName);
|
||||
attrNameField.setAccessible(true);
|
||||
String attrValue = attrNameField.get(user) + "";
|
||||
permSql += ("or " + columnName + "=" + attrValue + " ");
|
||||
break;
|
||||
}
|
||||
case "sup": {
|
||||
Field supAttrNameField = userClass.getDeclaredField("sup" + (attrName.substring(0, 1).toUpperCase() + attrName.substring(1)) + "s");
|
||||
supAttrNameField.setAccessible(true);
|
||||
String supAttrValue = (String) supAttrNameField.get(user);
|
||||
permSql += ("or " + columnName + " in(" + supAttrValue + ") ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (!allPerms) {
|
||||
if(permSql.length()==0){
|
||||
permSql = "0";
|
||||
}else{
|
||||
permSql = permSql.replaceFirst("or","");
|
||||
}
|
||||
lastSql = lastSql + linkSql + "(" + permSql + ")";
|
||||
}
|
||||
lastSql += (orderSql + pageSql);
|
||||
|
||||
}
|
||||
|
||||
field.set(boundSql, lastSql);
|
||||
return executor.query(mappedStatement, parameter, rowBounds, resultHandler, cacheKey, boundSql);
|
||||
}
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
// 拦截类型StatementHandler
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
return Plugin.wrap(target, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.java2nb.common.jsonserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LongToStringSerializer extends JsonSerializer<Long> {
|
||||
@Override
|
||||
public void serialize(Long value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||
|
||||
if(value != null){
|
||||
jsonGenerator.writeString(value+"");
|
||||
}else{
|
||||
jsonGenerator.writeNull();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,194 +0,0 @@
|
||||
package com.java2nb.common.redis.shiro;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @version V1.0
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
import org.apache.shiro.util.CollectionUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RedisCache<K, V> implements Cache<K, V> {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* The wrapped Jedis instance.
|
||||
*/
|
||||
private RedisManager cache;
|
||||
|
||||
/**
|
||||
* The Redis key prefix for the sessions
|
||||
*/
|
||||
private String keyPrefix = "shiro_redis_session:";
|
||||
|
||||
/**
|
||||
* Returns the Redis session keys
|
||||
* prefix.
|
||||
* @return The prefix
|
||||
*/
|
||||
public String getKeyPrefix() {
|
||||
return keyPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Redis sessions key
|
||||
* prefix.
|
||||
* @param keyPrefix The prefix
|
||||
*/
|
||||
public void setKeyPrefix(String keyPrefix) {
|
||||
this.keyPrefix = keyPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过一个JedisManager实例构造RedisCache
|
||||
*/
|
||||
public RedisCache(RedisManager cache){
|
||||
if (cache == null) {
|
||||
throw new IllegalArgumentException("Cache argument cannot be null.");
|
||||
}
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a cache instance with the specified
|
||||
* Redis manager and using a custom key prefix.
|
||||
* @param cache The cache manager instance
|
||||
* @param prefix The Redis key prefix
|
||||
*/
|
||||
public RedisCache(RedisManager cache,
|
||||
String prefix){
|
||||
|
||||
this( cache );
|
||||
|
||||
// set the prefix
|
||||
this.keyPrefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得byte[]型的key
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
private byte[] getByteKey(K key){
|
||||
if(key instanceof String){
|
||||
String preKey = this.keyPrefix + key;
|
||||
return preKey.getBytes();
|
||||
}else{
|
||||
return SerializeUtils.serialize(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) throws CacheException {
|
||||
logger.debug("根据key从Redis中获取对象 key [" + key + "]");
|
||||
try {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}else{
|
||||
byte[] rawValue = cache.get(getByteKey(key));
|
||||
@SuppressWarnings("unchecked")
|
||||
V value = (V)SerializeUtils.deserialize(rawValue);
|
||||
return value;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) throws CacheException {
|
||||
logger.debug("根据key从存储 key [" + key + "]");
|
||||
try {
|
||||
cache.set(getByteKey(key), SerializeUtils.serialize(value));
|
||||
return value;
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(K key) throws CacheException {
|
||||
logger.debug("从redis中删除 key [" + key + "]");
|
||||
try {
|
||||
V previous = get(key);
|
||||
cache.del(getByteKey(key));
|
||||
return previous;
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws CacheException {
|
||||
logger.debug("从redis中删除所有元素");
|
||||
try {
|
||||
cache.flushDB();
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
try {
|
||||
Long longSize = new Long(cache.dbSize());
|
||||
return longSize.intValue();
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<K> keys() {
|
||||
try {
|
||||
Set<byte[]> keys = cache.keys(this.keyPrefix + "*");
|
||||
if (CollectionUtils.isEmpty(keys)) {
|
||||
return Collections.emptySet();
|
||||
}else{
|
||||
Set<K> newKeys = new HashSet<K>();
|
||||
for(byte[] key:keys){
|
||||
newKeys.add((K)key);
|
||||
}
|
||||
return newKeys;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
try {
|
||||
Set<byte[]> keys = cache.keys(this.keyPrefix + "*");
|
||||
if (!CollectionUtils.isEmpty(keys)) {
|
||||
List<V> values = new ArrayList<V>(keys.size());
|
||||
for (byte[] key : keys) {
|
||||
@SuppressWarnings("unchecked")
|
||||
V value = get((K)key);
|
||||
if (value != null) {
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
throw new CacheException(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package com.java2nb.common.redis.shiro;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @version V1.0
|
||||
*/
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RedisCacheManager implements CacheManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(RedisCacheManager.class);
|
||||
|
||||
// fast lookup by name map
|
||||
private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
|
||||
|
||||
private RedisManager redisManager;
|
||||
|
||||
/**
|
||||
* The Redis key prefix for caches
|
||||
*/
|
||||
private String keyPrefix = "shiro_redis_cache:";
|
||||
|
||||
/**
|
||||
* Returns the Redis session keys
|
||||
* prefix.
|
||||
* @return The prefix
|
||||
*/
|
||||
public String getKeyPrefix() {
|
||||
return keyPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Redis sessions key
|
||||
* prefix.
|
||||
* @param keyPrefix The prefix
|
||||
*/
|
||||
public void setKeyPrefix(String keyPrefix) {
|
||||
this.keyPrefix = keyPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
|
||||
logger.debug("获取名称为: " + name + " 的RedisCache实例");
|
||||
|
||||
Cache c = caches.get(name);
|
||||
|
||||
if (c == null) {
|
||||
|
||||
// initialize the Redis manager instance
|
||||
redisManager.init();
|
||||
|
||||
// create a new cache instance
|
||||
c = new RedisCache<K, V>(redisManager, keyPrefix);
|
||||
|
||||
// add it to the cache collection
|
||||
caches.put(name, c);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public RedisManager getRedisManager() {
|
||||
return redisManager;
|
||||
}
|
||||
|
||||
public void setRedisManager(RedisManager redisManager) {
|
||||
this.redisManager = redisManager;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,228 +0,0 @@
|
||||
package com.java2nb.common.redis.shiro;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @version V1.0
|
||||
*/
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RedisManager {
|
||||
|
||||
@Value("${spring.redis.host}")
|
||||
private String host = "127.0.0.1";
|
||||
|
||||
@Value("${spring.redis.port}")
|
||||
private int port = 6379;
|
||||
|
||||
// 0 - never expire
|
||||
private int expire = 0;
|
||||
|
||||
//timeout for jedis try to connect to redis server, not expire time! In milliseconds
|
||||
@Value("${spring.redis.timeout}")
|
||||
private int timeout = 0;
|
||||
|
||||
@Value("${spring.redis.password}")
|
||||
private String password = "";
|
||||
|
||||
private static JedisPool jedisPool = null;
|
||||
|
||||
public RedisManager() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
public void init() {
|
||||
if (jedisPool == null) {
|
||||
if (password != null && !"".equals(password)) {
|
||||
jedisPool = new JedisPool(new JedisPoolConfig(), host, port, timeout, password);
|
||||
} else if (timeout != 0) {
|
||||
jedisPool = new JedisPool(new JedisPoolConfig(), host, port, timeout);
|
||||
} else {
|
||||
jedisPool = new JedisPool(new JedisPoolConfig(), host, port);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get value from redis
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public byte[] get(byte[] key) {
|
||||
byte[] value = null;
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
value = jedis.get(key);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* set
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public byte[] set(byte[] key, byte[] value) {
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
jedis.set(key, value);
|
||||
if (this.expire != 0) {
|
||||
jedis.expire(key, this.expire);
|
||||
}
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* set
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param expire
|
||||
* @return
|
||||
*/
|
||||
public byte[] set(byte[] key, byte[] value, int expire) {
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
jedis.set(key, value);
|
||||
if (expire != 0) {
|
||||
jedis.expire(key, expire);
|
||||
}
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* del
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public void del(byte[] key) {
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
jedis.del(key);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* flush
|
||||
*/
|
||||
public void flushDB() {
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
jedis.flushDB();
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* size
|
||||
*/
|
||||
public Long dbSize() {
|
||||
Long dbSize = 0L;
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
dbSize = jedis.dbSize();
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
return dbSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* keys
|
||||
*
|
||||
* @param regex
|
||||
* @return
|
||||
*/
|
||||
public Set<byte[]> keys(String pattern) {
|
||||
Set<byte[]> keys = null;
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
try {
|
||||
keys = jedis.keys(pattern.getBytes());
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public int getExpire() {
|
||||
return expire;
|
||||
}
|
||||
|
||||
public void setExpire(int expire) {
|
||||
this.expire = expire;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,139 +0,0 @@
|
||||
package com.java2nb.common.redis.shiro;
|
||||
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.UnknownSessionException;
|
||||
import org.apache.shiro.session.mgt.eis.AbstractSessionDAO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @version V1.0
|
||||
*/
|
||||
public class RedisSessionDAO extends AbstractSessionDAO {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RedisSessionDAO.class);
|
||||
/**
|
||||
* shiro-redis的session对象前缀
|
||||
*/
|
||||
private RedisManager redisManager;
|
||||
|
||||
/**
|
||||
* The Redis key prefix for the sessions
|
||||
*/
|
||||
private String keyPrefix = "shiro_redis_session:";
|
||||
|
||||
@Override
|
||||
public void update(Session session) throws UnknownSessionException {
|
||||
this.saveSession(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* save session
|
||||
* @param session
|
||||
* @throws UnknownSessionException
|
||||
*/
|
||||
private void saveSession(Session session) throws UnknownSessionException{
|
||||
if(session == null || session.getId() == null){
|
||||
logger.error("session or session id is null");
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] key = getByteKey(session.getId());
|
||||
byte[] value = SerializeUtils.serialize(session);
|
||||
session.setTimeout(redisManager.getExpire()*1000);
|
||||
this.redisManager.set(key, value, redisManager.getExpire());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Session session) {
|
||||
if(session == null || session.getId() == null){
|
||||
logger.error("session or session id is null");
|
||||
return;
|
||||
}
|
||||
redisManager.del(this.getByteKey(session.getId()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Session> getActiveSessions() {
|
||||
Set<Session> sessions = new HashSet<Session>();
|
||||
|
||||
Set<byte[]> keys = redisManager.keys(this.keyPrefix + "*");
|
||||
if(keys != null && keys.size()>0){
|
||||
for(byte[] key:keys){
|
||||
Session s = (Session)SerializeUtils.deserialize(redisManager.get(key));
|
||||
sessions.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
return sessions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable doCreate(Session session) {
|
||||
Serializable sessionId = this.generateSessionId(session);
|
||||
this.assignSessionId(session, sessionId);
|
||||
this.saveSession(session);
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Session doReadSession(Serializable sessionId) {
|
||||
if(sessionId == null){
|
||||
logger.error("session id is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
Session s = (Session)SerializeUtils.deserialize(redisManager.get(this.getByteKey(sessionId)));
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得byte[]型的key
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
private byte[] getByteKey(Serializable sessionId){
|
||||
String preKey = this.keyPrefix + sessionId;
|
||||
return preKey.getBytes();
|
||||
}
|
||||
|
||||
public RedisManager getRedisManager() {
|
||||
return redisManager;
|
||||
}
|
||||
|
||||
public void setRedisManager(RedisManager redisManager) {
|
||||
this.redisManager = redisManager;
|
||||
|
||||
/**
|
||||
* 初始化redisManager
|
||||
*/
|
||||
this.redisManager.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Redis session keys
|
||||
* prefix.
|
||||
* @return The prefix
|
||||
*/
|
||||
public String getKeyPrefix() {
|
||||
return keyPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Redis sessions key
|
||||
* prefix.
|
||||
* @param keyPrefix The prefix
|
||||
*/
|
||||
public void setKeyPrefix(String keyPrefix) {
|
||||
this.keyPrefix = keyPrefix;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
package com.java2nb.common.redis.shiro;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @version V1.0
|
||||
*/
|
||||
public class SerializeUtils {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SerializeUtils.class);
|
||||
|
||||
/**
|
||||
* 反序列化
|
||||
* @param bytes
|
||||
* @return
|
||||
*/
|
||||
public static Object deserialize(byte[] bytes) {
|
||||
|
||||
Object result = null;
|
||||
|
||||
if (isEmpty(bytes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
|
||||
try {
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(byteStream);
|
||||
try {
|
||||
result = objectInputStream.readObject();
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new Exception("Failed to deserialize object type", ex);
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new Exception("Failed to deserialize", ex);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to deserialize",e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(byte[] data) {
|
||||
return (data == null || data.length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static byte[] serialize(Object object) {
|
||||
|
||||
byte[] result = null;
|
||||
|
||||
if (object == null) {
|
||||
return new byte[0];
|
||||
}
|
||||
try {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(128);
|
||||
try {
|
||||
if (!(object instanceof Serializable)) {
|
||||
throw new IllegalArgumentException(SerializeUtils.class.getSimpleName() + " requires a Serializable payload " +
|
||||
"but received an object of type [" + object.getClass().getName() + "]");
|
||||
}
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteStream);
|
||||
objectOutputStream.writeObject(object);
|
||||
objectOutputStream.flush();
|
||||
result = byteStream.toByteArray();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new Exception("Failed to serialize", ex);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Failed to serialize",ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package com.java2nb.common.service;
|
||||
|
||||
import com.java2nb.common.domain.DictDO;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
*
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-09-29 18:28:07
|
||||
*/
|
||||
public interface DictService {
|
||||
|
||||
DictDO get(Long id);
|
||||
|
||||
List<DictDO> list(Map<String, Object> map);
|
||||
|
||||
int count(Map<String, Object> map);
|
||||
|
||||
int save(DictDO dict);
|
||||
|
||||
int update(DictDO dict);
|
||||
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
List<DictDO> listType();
|
||||
|
||||
String getName(String type,String value);
|
||||
|
||||
/**
|
||||
* 获取爱好列表
|
||||
* @return
|
||||
* @param userDO
|
||||
*/
|
||||
List<DictDO> getHobbyList(UserDO userDO);
|
||||
|
||||
/**
|
||||
* 获取性别列表
|
||||
* @return
|
||||
*/
|
||||
List<DictDO> getSexList();
|
||||
|
||||
/**
|
||||
* 根据type获取数据
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
List<DictDO> listByType(String type);
|
||||
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package com.java2nb.common.service;
|
||||
|
||||
import com.java2nb.common.domain.FileDO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-09-19 16:02:20
|
||||
*/
|
||||
public interface FileService {
|
||||
|
||||
FileDO get(Long id);
|
||||
|
||||
List<FileDO> list(Map<String, Object> map);
|
||||
|
||||
int count(Map<String, Object> map);
|
||||
|
||||
int save(FileDO sysFile);
|
||||
|
||||
int update(FileDO sysFile);
|
||||
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
/**
|
||||
* 判断一个文件是否存在
|
||||
* @param url FileDO中存的路径
|
||||
* @return
|
||||
*/
|
||||
Boolean isExist(String url);
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.java2nb.common.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.java2nb.common.domain.GenColumnsDO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @Time 2019-10-20 11:23:09
|
||||
* @description
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public interface GeneratorService {
|
||||
List<Map<String, Object>> list(String tableName);
|
||||
|
||||
void generatorCode(String[] tableNames);
|
||||
|
||||
byte[] downloadCode(String[] tableNames);
|
||||
|
||||
|
||||
List<GenColumnsDO> listColumnsByTableName(String tableName);
|
||||
|
||||
boolean genColumnsSave(List<GenColumnsDO> list);
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package com.java2nb.common.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
import com.java2nb.common.domain.PageDO;
|
||||
import com.java2nb.common.utils.Query;
|
||||
@Service
|
||||
public interface LogService {
|
||||
void save(LogDO logDO);
|
||||
PageDO<LogDO> queryList(Query query);
|
||||
int remove(Long id);
|
||||
int batchRemove(Long[] ids);
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
package com.java2nb.common.service.impl;
|
||||
|
||||
import com.java2nb.common.dao.DictDao;
|
||||
import com.java2nb.common.domain.DictDO;
|
||||
import com.java2nb.common.service.DictService;
|
||||
import com.java2nb.common.utils.StringUtils;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
public class DictServiceImpl implements DictService {
|
||||
|
||||
@Autowired
|
||||
private DictDao dictDao;
|
||||
|
||||
@Override
|
||||
public DictDO get(Long id) {
|
||||
return dictDao.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictDO> list(Map<String, Object> map) {
|
||||
return dictDao.list(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Map<String, Object> map) {
|
||||
return dictDao.count(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int save(DictDO dict) {
|
||||
return dictDao.save(dict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(DictDO dict) {
|
||||
return dictDao.update(dict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(Long id) {
|
||||
return dictDao.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchRemove(Long[] ids) {
|
||||
return dictDao.batchRemove(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public List<DictDO> listType() {
|
||||
return dictDao.listType().stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(String type, String value) {
|
||||
Map<String, Object> param = new HashMap<String, Object>(16);
|
||||
param.put("type", type);
|
||||
param.put("value", value);
|
||||
String rString = dictDao.list(param).get(0).getName();
|
||||
return rString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictDO> getHobbyList(UserDO userDO) {
|
||||
Map<String, Object> param = new HashMap<>(16);
|
||||
param.put("type", "hobby");
|
||||
List<DictDO> hobbyList = dictDao.list(param);
|
||||
|
||||
if (StringUtils.isNotEmpty(userDO.getHobby())) {
|
||||
String userHobbys[] = userDO.getHobby().split(";");
|
||||
for (String userHobby : userHobbys) {
|
||||
for (DictDO hobby : hobbyList) {
|
||||
if (!Objects.equals(userHobby, hobby.getId().toString())) {
|
||||
continue;
|
||||
}
|
||||
hobby.setRemarks("true");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hobbyList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictDO> getSexList() {
|
||||
Map<String, Object> param = new HashMap<>(16);
|
||||
param.put("type", "sex");
|
||||
return dictDao.list(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictDO> listByType(String type) {
|
||||
Map<String, Object> param = new HashMap<>(16);
|
||||
param.put("type", type);
|
||||
return dictDao.list(param);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
package com.java2nb.common.service.impl;
|
||||
|
||||
import com.java2nb.common.config.Constant;
|
||||
import com.java2nb.common.config.JnConfig;
|
||||
import com.java2nb.common.dao.FileDao;
|
||||
import com.java2nb.common.domain.FileDO;
|
||||
import com.java2nb.common.service.FileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service
|
||||
public class FileServiceImpl implements FileService {
|
||||
|
||||
@Autowired
|
||||
private FileDao sysFileMapper;
|
||||
|
||||
@Autowired
|
||||
private JnConfig jnConfig;
|
||||
|
||||
@Override
|
||||
public FileDO get(Long id) {
|
||||
return sysFileMapper.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileDO> list(Map<String, Object> map) {
|
||||
return sysFileMapper.list(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Map<String, Object> map) {
|
||||
return sysFileMapper.count(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int save(FileDO sysFile) {
|
||||
return sysFileMapper.save(sysFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(FileDO sysFile) {
|
||||
return sysFileMapper.update(sysFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(Long id) {
|
||||
return sysFileMapper.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchRemove(Long[] ids) {
|
||||
return sysFileMapper.batchRemove(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isExist(String url) {
|
||||
Boolean isExist = false;
|
||||
if (!StringUtils.isEmpty(url)) {
|
||||
String filePath = url.replace(Constant.UPLOAD_FILES_PREFIX, "");
|
||||
filePath = jnConfig.getUploadPath() + filePath;
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
isExist = true;
|
||||
}
|
||||
}
|
||||
return isExist;
|
||||
}
|
||||
}
|
||||
@ -1,141 +0,0 @@
|
||||
package com.java2nb.common.service.impl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.java2nb.common.dao.GenColumnsDao;
|
||||
import com.java2nb.common.domain.GenColumnsDO;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.configuration.PropertiesConfiguration;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.java2nb.common.dao.GeneratorMapper;
|
||||
import com.java2nb.common.service.GeneratorService;
|
||||
import com.java2nb.common.utils.GenUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
@Autowired
|
||||
GeneratorMapper generatorMapper;
|
||||
|
||||
@Autowired
|
||||
GenColumnsDao genColumnsDao;
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> list(String tableName) {
|
||||
List<Map<String, Object>> list = generatorMapper.list(tableName);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generatorCode(String[] tableNames) {
|
||||
for (String tableName : tableNames) {
|
||||
//查询表信息
|
||||
Map<String, String> table = generatorMapper.get(tableName);
|
||||
//查询列信息
|
||||
List<Map<String, String>> columns = generatorMapper.listColumns(tableName);
|
||||
//生成代码
|
||||
GenUtils.generatorCode(table, columns, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] downloadCode(String[] tableNames) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
for (String tableName : tableNames) {
|
||||
//查询表信息
|
||||
Map<String, String> table = generatorMapper.get(tableName);
|
||||
//查询列信息
|
||||
List<Map<String, String>> columns = generatorMapper.listColumns(tableName);
|
||||
//生成代码
|
||||
GenUtils.generatorCode(table, columns, zip);
|
||||
}
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<GenColumnsDO> listColumnsByTableName(String tableName) {
|
||||
Map<String, Object> query = new HashMap<>();
|
||||
query.put("tableName", tableName);
|
||||
query.put("sort", "column_sort");
|
||||
query.put("order", "asc");
|
||||
List<GenColumnsDO> columnList = genColumnsDao.list(query);
|
||||
if (columnList.size() == 0) {
|
||||
//查询列信息
|
||||
List<Map<String, String>> columns = generatorMapper.listColumns(tableName);
|
||||
|
||||
int columnSort = 0;
|
||||
for (Map<String, String> column : columns) {
|
||||
GenColumnsDO genColumnsDO = transGenColumnDO(tableName,column,++columnSort);
|
||||
|
||||
if(!"PRI".equalsIgnoreCase(column.get("columnKey"))) {
|
||||
columnList.add(genColumnsDO);
|
||||
}else{
|
||||
genColumnsDO.setColumnSort(0);
|
||||
genColumnsDO.setPageType(11);
|
||||
columnList.add(0,genColumnsDO);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
Map<String, String> column = generatorMapper.getPriColumn(tableName);
|
||||
GenColumnsDO genColumnsDO = transGenColumnDO(tableName,column,0);
|
||||
genColumnsDO.setPageType(11);
|
||||
columnList.add(0,genColumnsDO);
|
||||
}
|
||||
return columnList;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public boolean genColumnsSave(List<GenColumnsDO> list) {
|
||||
GenColumnsDO pkColumn = list.get(0);
|
||||
String tableName = pkColumn.getTableName();
|
||||
genColumnsDao.deleteByTableName(tableName);
|
||||
list.remove(0);
|
||||
genColumnsDao.saveBatch(list);
|
||||
//查询表信息
|
||||
Map<String, String> table = generatorMapper.get(tableName);
|
||||
//生成代码
|
||||
GenUtils.generatorCode(table,pkColumn, list);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public GenColumnsDO transGenColumnDO(String tableName,Map<String, String> column,int columnSort){
|
||||
GenColumnsDO genColumnsDO = new GenColumnsDO();
|
||||
genColumnsDO.setTableName(tableName);
|
||||
genColumnsDO.setColumnName(column.get("columnName"));
|
||||
genColumnsDO.setColumnType(column.get("dataType"));
|
||||
genColumnsDO.setColumnComment(column.get("columnComment"));
|
||||
PropertiesConfiguration conf = new PropertiesConfiguration("generator.properties");
|
||||
genColumnsDO.setJavaType(conf.getString(column.get("dataType")));
|
||||
genColumnsDO.setColumnSort(columnSort);
|
||||
genColumnsDO.setExtra(column.get("extra"));
|
||||
genColumnsDO.setIsRequired(0);
|
||||
if ("Date".equals(conf.getString(column.get("dataType")))) {
|
||||
genColumnsDO.setPageType(4);
|
||||
|
||||
} else {
|
||||
genColumnsDO.setPageType(1);
|
||||
}
|
||||
genColumnsDO.setColumnLabel(column.get("columnComment"));
|
||||
return genColumnsDO;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
package com.java2nb.common.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.java2nb.common.dao.LogDao;
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
import com.java2nb.common.domain.PageDO;
|
||||
import com.java2nb.common.service.LogService;
|
||||
import com.java2nb.common.utils.Query;
|
||||
|
||||
@Service
|
||||
public class LogServiceImpl implements LogService {
|
||||
@Autowired
|
||||
LogDao logMapper;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void save(LogDO logDO) {
|
||||
logMapper.save(logDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageDO<LogDO> queryList(Query query) {
|
||||
int total = logMapper.count(query);
|
||||
List<LogDO> logs = logMapper.list(query);
|
||||
PageDO<LogDO> page = new PageDO<>();
|
||||
page.setTotal(total);
|
||||
page.setRows(logs);
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(Long id) {
|
||||
int count = logMapper.remove(id);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchRemove(Long[] ids){
|
||||
return logMapper.batchRemove(ids);
|
||||
}
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
/**
|
||||
* 自定义异常
|
||||
*
|
||||
*/
|
||||
public class BDException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String msg;
|
||||
private int code = 500;
|
||||
|
||||
public BDException(String msg) {
|
||||
super(msg);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public BDException(String msg, Throwable e) {
|
||||
super(msg, e);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public BDException(String msg, int code) {
|
||||
super(msg);
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BDException(String msg, int code, Throwable e) {
|
||||
super(msg, e);
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
public class Base64Utils {
|
||||
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import com.java2nb.common.domain.Tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BuildTree {
|
||||
|
||||
public static <T> Tree<T> build(List<Tree<T>> nodes) {
|
||||
|
||||
if (nodes == null) {
|
||||
return null;
|
||||
}
|
||||
List<Tree<T>> topNodes = new ArrayList<Tree<T>>();
|
||||
|
||||
for (Tree<T> children : nodes) {
|
||||
|
||||
String pid = children.getParentId();
|
||||
if (pid == null || "0".equals(pid)) {
|
||||
topNodes.add(children);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Tree<T> parent : nodes) {
|
||||
String id = parent.getId();
|
||||
if (id != null && id.equals(pid)) {
|
||||
parent.getChildren().add(children);
|
||||
children.setHasParent(true);
|
||||
parent.setChildren(true);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Tree<T> root = new Tree<T>();
|
||||
if (topNodes.size() == 1) {
|
||||
root = topNodes.get(0);
|
||||
} else {
|
||||
root.setId("-1");
|
||||
root.setParentId("");
|
||||
root.setHasParent(false);
|
||||
root.setChildren(true);
|
||||
root.setChecked(true);
|
||||
root.setChildren(topNodes);
|
||||
root.setText("顶级节点");
|
||||
Map<String, Object> state = new HashMap<>(16);
|
||||
state.put("opened", true);
|
||||
root.setState(state);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public static <T> List<Tree<T>> buildList(List<Tree<T>> nodes, String idParam) {
|
||||
if (nodes == null) {
|
||||
return null;
|
||||
}
|
||||
List<Tree<T>> topNodes = new ArrayList<Tree<T>>();
|
||||
|
||||
for (Tree<T> children : nodes) {
|
||||
|
||||
String pid = children.getParentId();
|
||||
if (pid == null || idParam.equals(pid)) {
|
||||
topNodes.add(children);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Tree<T> parent : nodes) {
|
||||
String id = parent.getId();
|
||||
if (id != null && id.equals(pid)) {
|
||||
parent.getChildren().add(children);
|
||||
children.setHasParent(true);
|
||||
parent.setChildren(true);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return topNodes;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
public class ExceptionUtils {
|
||||
public static String getExceptionAllinformation(Exception ex) {
|
||||
String sOut = "";
|
||||
StackTraceElement[] trace = ex.getStackTrace();
|
||||
for (StackTraceElement s : trace) {
|
||||
sOut += "\tat " + s + "\r\n";
|
||||
}
|
||||
return sOut;
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception {
|
||||
File targetFile = new File(filePath);
|
||||
if (!targetFile.exists()) {
|
||||
targetFile.mkdirs();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(filePath + fileName);
|
||||
out.write(file);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (file.delete()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String renameToUUID(String fileName) {
|
||||
return UUID.randomUUID() + "." + fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
public class HttpContextUtils {
|
||||
public static HttpServletRequest getHttpServletRequest() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
* @date 2019-09-25 15:09:21
|
||||
*/
|
||||
@Slf4j
|
||||
public class ImageUtils {
|
||||
/***
|
||||
* 剪裁图片
|
||||
* @param file 图片
|
||||
* @param x 起点横坐标
|
||||
* @param y 纵坐标
|
||||
* @param w 长
|
||||
* @param h 高
|
||||
* @throws IOException
|
||||
* @date 2019-09-25 15:09:21
|
||||
*/
|
||||
public static BufferedImage cutImage(MultipartFile file, int x, int y, int w, int h,String prefix) {
|
||||
|
||||
Iterator iterator = ImageIO.getImageReadersByFormatName(prefix);
|
||||
try {
|
||||
ImageReader reader = (ImageReader)iterator.next();
|
||||
//转换成输入流
|
||||
InputStream in = file.getInputStream();
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(in);
|
||||
reader.setInput(iis, true);
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
Rectangle rect = new Rectangle(x, y, w,h);
|
||||
param.setSourceRegion(rect);
|
||||
BufferedImage bi = reader.read(0,param);
|
||||
return bi;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/***
|
||||
* 图片旋转指定角度
|
||||
* @param bufferedimage 图像
|
||||
* @param degree 角度
|
||||
* @return
|
||||
* @date 2019-09-25 15:09:21
|
||||
*/
|
||||
public static BufferedImage rotateImage(BufferedImage bufferedimage, int degree) {
|
||||
int w = bufferedimage.getWidth();
|
||||
int h = bufferedimage.getHeight();
|
||||
int type = bufferedimage.getColorModel().getTransparency();
|
||||
BufferedImage img;
|
||||
Graphics2D graphics2d;
|
||||
(graphics2d = (img = new BufferedImage(w, h, type))
|
||||
.createGraphics()).setRenderingHint(
|
||||
RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2d.setPaint(Color.WHITE);
|
||||
graphics2d.fillRect(0, 0, w, h);
|
||||
graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2);
|
||||
graphics2d.drawImage(bufferedimage, 0, 0,Color.WHITE, null);
|
||||
graphics2d.dispose();
|
||||
return img;
|
||||
}
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JSONUtils {
|
||||
|
||||
/**
|
||||
* Bean对象转JSON
|
||||
*
|
||||
* @param object
|
||||
* @param dataFormatString
|
||||
* @return
|
||||
*/
|
||||
public static String beanToJson(Object object, String dataFormatString) {
|
||||
if (object != null) {
|
||||
if (StringUtils.isEmpty(dataFormatString)) {
|
||||
return JSONObject.toJSONString(object);
|
||||
}
|
||||
return JSON.toJSONStringWithDateFormat(object, dataFormatString);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean对象转JSON
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static String beanToJson(Object object) {
|
||||
if (object != null) {
|
||||
return JSON.toJSONString(object);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* String转JSON字符串
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static String stringToJsonByFastjson(String key, String value) {
|
||||
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> map = new HashMap<String, String>(16);
|
||||
map.put(key, value);
|
||||
return beanToJson(map, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将json字符串转换成对象
|
||||
*
|
||||
* @param json
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static Object jsonToBean(String json, Object clazz) {
|
||||
if (StringUtils.isEmpty(json) || clazz == null) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(json, clazz.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* json字符串转map
|
||||
*
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> jsonToMap(String json) {
|
||||
if (StringUtils.isEmpty(json)) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(json, Map.class);
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import org.apache.shiro.crypto.hash.SimpleHash;
|
||||
import org.apache.shiro.util.ByteSource;
|
||||
|
||||
public class MD5Utils {
|
||||
private static final String SALT = "1qazxsw2";
|
||||
|
||||
private static final String ALGORITH_NAME = "md5";
|
||||
|
||||
private static final int HASH_ITERATIONS = 2;
|
||||
|
||||
public static String encrypt(String pswd) {
|
||||
String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
public static String encrypt(String username, String pswd) {
|
||||
String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username + SALT),
|
||||
HASH_ITERATIONS).toHex();
|
||||
return newPassword;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
//System.out.println(MD5Utils.encrypt("admin", "1"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author xiongxy
|
||||
*/
|
||||
public class PageBean implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int total;
|
||||
private List<?> rows;
|
||||
|
||||
public PageBean(List<?> list, int total) {
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<?> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<?> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 查询参数
|
||||
*/
|
||||
public class Query extends LinkedHashMap<String, Object> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
//
|
||||
private int offset;
|
||||
// 每页条数
|
||||
private int limit;
|
||||
|
||||
public Query(Map<String, Object> params) {
|
||||
this.putAll(params);
|
||||
// 分页参数
|
||||
this.offset = Integer.parseInt(params.get("offset").toString());
|
||||
this.limit = Integer.parseInt(params.get("limit").toString());
|
||||
this.put("offset", offset);
|
||||
this.put("page", offset / limit + 1);
|
||||
this.put("limit", limit);
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset) {
|
||||
this.put("offset", offset);
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class R extends HashMap<String, Object> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public R() {
|
||||
put("code", 0);
|
||||
put("msg", "操作成功");
|
||||
}
|
||||
|
||||
public static R error() {
|
||||
return error(1, "操作失败");
|
||||
}
|
||||
|
||||
public static R error(String msg) {
|
||||
return error(500, msg);
|
||||
}
|
||||
|
||||
public static R error(int code, String msg) {
|
||||
R r = new R();
|
||||
r.put("code", code);
|
||||
r.put("msg", msg);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static R ok(String msg) {
|
||||
R r = new R();
|
||||
r.put("msg", msg);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static R ok(Map<String, Object> map) {
|
||||
R r = new R();
|
||||
r.putAll(map);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static R ok() {
|
||||
return new R();
|
||||
}
|
||||
|
||||
@Override
|
||||
public R put(String key, Object value) {
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -1,122 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author xiongxy
|
||||
*/
|
||||
public class RandomValidateCodeUtil {
|
||||
|
||||
|
||||
public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";//放到session中的key
|
||||
private String randString = "0123456789";//随机产生只有数字的字符串 private String
|
||||
//private String randString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生只有字母的字符串
|
||||
//private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串
|
||||
private int width = 95;// 图片宽
|
||||
private int height = 25;// 图片高
|
||||
private int lineSize = 40;// 干扰线数量
|
||||
private int stringNum = 4;// 随机产生字符数量
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RandomValidateCodeUtil.class);
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
/**
|
||||
* 获得字体
|
||||
*/
|
||||
private Font getFont() {
|
||||
return new Font("Fixedsys", Font.CENTER_BASELINE, 18);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得颜色
|
||||
*/
|
||||
private Color getRandColor(int fc, int bc) {
|
||||
if (fc > 255) {
|
||||
fc = 255;
|
||||
}
|
||||
if (bc > 255) {
|
||||
bc = 255;
|
||||
}
|
||||
int r = fc + random.nextInt(bc - fc - 16);
|
||||
int g = fc + random.nextInt(bc - fc - 14);
|
||||
int b = fc + random.nextInt(bc - fc - 18);
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机图片
|
||||
*/
|
||||
public void getRandcode(HttpServletRequest request, HttpServletResponse response) {
|
||||
HttpSession session = request.getSession();
|
||||
// BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
|
||||
Graphics g = image.getGraphics();// 产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作
|
||||
g.fillRect(0, 0, width, height);//图片大小
|
||||
g.setFont(new Font("Default", Font.ROMAN_BASELINE, 18));//字体大小
|
||||
g.setColor(getRandColor(110, 133));//字体颜色
|
||||
// 绘制干扰线
|
||||
for (int i = 0; i <= lineSize; i++) {
|
||||
drowLine(g);
|
||||
}
|
||||
// 绘制随机字符
|
||||
String randomString = "";
|
||||
for (int i = 1; i <= stringNum; i++) {
|
||||
randomString = drowString(g, randomString, i);
|
||||
}
|
||||
logger.info(randomString);
|
||||
//将生成的随机字符串保存到session中
|
||||
session.removeAttribute(RANDOMCODEKEY);
|
||||
session.setAttribute(RANDOMCODEKEY, randomString);
|
||||
g.dispose();
|
||||
try {
|
||||
// 将内存中的图片通过流动形式输出到客户端
|
||||
ImageIO.write(image, "JPEG", response.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
logger.error("将内存中的图片通过流动形式输出到客户端失败>>>> ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制字符串
|
||||
*/
|
||||
private String drowString(Graphics g, String randomString, int i) {
|
||||
g.setFont(getFont());
|
||||
g.setColor(new Color(random.nextInt(101), random.nextInt(111), random
|
||||
.nextInt(121)));
|
||||
String rand = String.valueOf(getRandomString(random.nextInt(randString
|
||||
.length())));
|
||||
randomString += rand;
|
||||
g.translate(random.nextInt(3), random.nextInt(3));
|
||||
g.drawString(rand, 13 * i, 16);
|
||||
return randomString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制干扰线
|
||||
*/
|
||||
private void drowLine(Graphics g) {
|
||||
int x = random.nextInt(width);
|
||||
int y = random.nextInt(height);
|
||||
int xl = random.nextInt(13);
|
||||
int yl = random.nextInt(15);
|
||||
g.drawLine(x, y, x + xl, y + yl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取随机的字符
|
||||
*/
|
||||
public String getRandomString(int num) {
|
||||
return String.valueOf(randString.charAt(num));
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import com.java2nb.system.domain.UserToken;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.eis.SessionDAO;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.Principal;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ShiroUtils {
|
||||
@Autowired
|
||||
private static SessionDAO sessionDAO;
|
||||
|
||||
public static Subject getSubjct() {
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
public static UserDO getUser() {
|
||||
Object object = getSubjct().getPrincipal();
|
||||
return (UserDO)object;
|
||||
}
|
||||
public static Long getUserId() {
|
||||
return getUser().getUserId();
|
||||
}
|
||||
public static void logout() {
|
||||
getSubjct().logout();
|
||||
}
|
||||
|
||||
public static List<Principal> getPrinciples() {
|
||||
List<Principal> principals = null;
|
||||
Collection<Session> sessions = sessionDAO.getActiveSessions();
|
||||
return principals;
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
//package com.java2nb.common.utils;
|
||||
//
|
||||
//import org.apache.commons.lang3.Validate;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.beans.factory.DisposableBean;
|
||||
//import org.springframework.context.ApplicationContext;
|
||||
//import org.springframework.context.ApplicationContextAware;
|
||||
//import org.springframework.context.annotation.Lazy;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
///**
|
||||
// * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext.
|
||||
// *
|
||||
// */
|
||||
//@Service
|
||||
//@Lazy(false)
|
||||
//public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
|
||||
//
|
||||
// private static ApplicationContext applicationContext = null;
|
||||
//
|
||||
// private static Logger logger = LoggerFactory.getLogger(SpringContextHolder.class);
|
||||
//
|
||||
// /**
|
||||
// * 取得存储在静态变量中的ApplicationContext.
|
||||
// */
|
||||
// public static ApplicationContext getApplicationContext() {
|
||||
// assertContextInjected();
|
||||
// return applicationContext;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||
// */
|
||||
// @SuppressWarnings("unchecked")
|
||||
// public static <T> T getBean(String name) {
|
||||
// assertContextInjected();
|
||||
// return (T) applicationContext.getBean(name);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||
// */
|
||||
// public static <T> T getBean(Class<T> requiredType) {
|
||||
// assertContextInjected();
|
||||
// return applicationContext.getBean(requiredType);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 清除SpringContextHolder中的ApplicationContext为Null.
|
||||
// */
|
||||
// public static void clearHolder() {
|
||||
// if (logger.isDebugEnabled()) {
|
||||
// logger.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext);
|
||||
// }
|
||||
// applicationContext = null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 实现ApplicationContextAware接口, 注入Context到静态变量中.
|
||||
// */
|
||||
// @Override
|
||||
// public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
// SpringContextHolder.applicationContext = applicationContext;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 实现DisposableBean接口, 在Context关闭时清理静态变量.
|
||||
// */
|
||||
// @Override
|
||||
// public void destroy() throws Exception {
|
||||
// SpringContextHolder.clearHolder();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 检查ApplicationContext不为空.
|
||||
// */
|
||||
// private static void assertContextInjected() {
|
||||
// Validate.validState(applicationContext != null,
|
||||
// "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
|
||||
// }
|
||||
//}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue