Compare commits
36 Commits
dependabot
...
feat-multl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d462cc876 | ||
|
|
ec96a787ef | ||
|
|
91de56cb32 | ||
|
|
e2a3fb6a6c | ||
|
|
49ff1865bb | ||
|
|
b920034ad6 | ||
|
|
76f3d16e09 | ||
|
|
9dafc6d5a7 | ||
|
|
ec693da079 | ||
|
|
58498ef225 | ||
|
|
c56a3eaf83 | ||
|
|
e0abfb7d70 | ||
|
|
96cb2dcee4 | ||
|
|
e39763ad0c | ||
|
|
a3edc00a03 | ||
|
|
c0687b4776 | ||
|
|
b3b3a7a908 | ||
|
|
56efdc44d7 | ||
|
|
e4684e6150 | ||
|
|
65d65221e8 | ||
|
|
47df223655 | ||
|
|
fa95f2f69e | ||
|
|
5598804ddc | ||
|
|
ed7d18d491 | ||
|
|
2fbe030da9 | ||
|
|
5f3cbece7b | ||
|
|
4942daf900 | ||
|
|
9f070169b4 | ||
|
|
4fa114eb1e | ||
|
|
431ce8ac28 | ||
|
|
49000e9ee6 | ||
|
|
19068ff14d | ||
|
|
3d0253a35a | ||
|
|
0283bd11dc | ||
|
|
60347c7629 | ||
|
|
8de0cbded8 |
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@@ -1,12 +0,0 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "maven" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
open-pull-requests-limit: 10
|
||||
41
.github/workflows/build.yml
vendored
41
.github/workflows/build.yml
vendored
@@ -1,23 +1,21 @@
|
||||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths-ignore:
|
||||
- "doc/**"
|
||||
- "**/README.md"
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
paths-ignore:
|
||||
- "doc/**"
|
||||
- "**/README.md"
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: "!contains(github.event.head_commit.message, '[skip ci]')" # 如果 commit 信息包含以下关键字则跳过该任务
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
KEY: ${{ secrets.WEB_HOOK_ACCESS_KEY }}
|
||||
QINIU_ACCESSKEY: ${{ secrets.QINIU_ACCESSKEY }}
|
||||
QINIU_SECRETKEY: ${{ secrets.QINIU_SECRETKEY }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -26,24 +24,5 @@ jobs:
|
||||
with:
|
||||
java-version: 1.8
|
||||
|
||||
- name: Sync repository
|
||||
uses: x-dr/sync-repo-to-gitee@v1.0
|
||||
env:
|
||||
# 在 Settings->Secrets 配置 GITEE_KEY
|
||||
SSH_KEY: ${{ secrets.GITEE_KEY }}
|
||||
with:
|
||||
# GitHub存储库的SSH URL.
|
||||
github-repo: git@github.com:xiaohai2271/blog-backEnd.git
|
||||
# Gitee存储库的SSH URL.
|
||||
gitee-repo: git@gitee.com:xiaohai2271/blog-backEnd.git
|
||||
|
||||
- name: Cache local Maven repository
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
|
||||
- name: Unit Test
|
||||
run: mvn package -B -pl blog-deploy -am
|
||||
- name: Deploy
|
||||
run: mvn -B test --file pom.xml && curl http://bt.celess.cn:2271/hook?access_key=$KEY
|
||||
|
||||
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [master]
|
||||
schedule:
|
||||
- cron: '0 14 * * 2'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Override automatic language detection by changing the below list
|
||||
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
|
||||
language: ['java']
|
||||
# Learn more...
|
||||
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
29
.github/workflows/test.yml
vendored
Normal file
29
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
QINIU_ACCESSKEY: ${{ secrets.QINIU_ACCESSKEY }}
|
||||
QINIU_SECRETKEY: ${{ secrets.QINIU_SECRETKEY }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
|
||||
- name: Test
|
||||
run: mvn -B test --file pom.xml
|
||||
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,5 +4,5 @@
|
||||
target/
|
||||
|
||||
# 本地项目的私有文件
|
||||
blog-deploy/src/main/resources/application-dev.properties
|
||||
src/main/resources/application-dev.properties
|
||||
src/main/resources/application-prod.properties
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-article</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--MarkDown 2 html -->
|
||||
<dependency>
|
||||
<groupId>com.youbenzi</groupId>
|
||||
<artifactId>MDTool</artifactId>
|
||||
<version>1.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.minidev</groupId>
|
||||
<artifactId>json-smart</artifactId>
|
||||
<version>2.4.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.celess.article;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import cn.celess.user.UserApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {ArticleApplication.class, CommonApplication.class, UserApplication.class})
|
||||
public class ArticleApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(ArticleApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _ _ _
|
||||
| | | | (_) | _ \ | | /\ | | (_) | |
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ / \ _ __ | |_ _ ___ | | ___
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| / /\ \ | '__| | __| | | / __| | | / _ \
|
||||
| | | | | | | |_) | | | | (_) | | (_| | / ____ \ | | | |_ | | | (__ | | | __/
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | /_/ \_\ |_| \__| |_| \___| |_| \___|
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess.article;
|
||||
|
||||
import cn.celess.common.test.BaseRedisTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = {ArticleApplication.class})
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class ArticleBaseTest extends BaseRedisTest {
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package cn.celess.article.serviceimpl;
|
||||
|
||||
import cn.celess.article.ArticleBaseTest;
|
||||
import cn.celess.common.entity.vo.ArticleModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.mapper.ArticleMapper;
|
||||
import cn.celess.common.service.ArticleService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ArticleServiceTest extends ArticleBaseTest {
|
||||
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
@Resource
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
@Test
|
||||
public void adminArticles() {
|
||||
// 测deleted参数传值
|
||||
PageData<ArticleModel> pageData = articleService.adminArticles(10, 1, true);
|
||||
assertTrue(pageData.getList().stream().allMatch(ArticleModel::isDeleted));
|
||||
pageData = articleService.adminArticles(10, 1, false);
|
||||
assertFalse(pageData.getList().stream().allMatch(ArticleModel::isDeleted));
|
||||
pageData = articleService.adminArticles(10, 1, null);
|
||||
assertTrue(pageData.getList().stream().anyMatch(ArticleModel::isDeleted));
|
||||
assertTrue(pageData.getList().stream().anyMatch(articleModel -> !articleModel.isDeleted()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrievePageForOpen() {
|
||||
PageData<ArticleModel> articleModelPageData = articleService.retrievePageForOpen(10, 1);
|
||||
assertEquals(10, articleModelPageData.getPageSize());
|
||||
assertEquals(1, articleModelPageData.getPageNum());
|
||||
assertEquals(10, articleModelPageData.getList().size());
|
||||
articleModelPageData.getList().forEach(Assert::assertNotNull);
|
||||
|
||||
// 测试open字段
|
||||
articleModelPageData.getList().forEach(articleModel -> {
|
||||
// 当前文章
|
||||
assertTrue(articleMapper.findArticleById(articleModel.getId()).getOpen());
|
||||
if (articleModel.getPreArticle() != null) {
|
||||
assertTrue(articleMapper.findArticleById(articleModel.getPreArticle().getId()).getOpen());
|
||||
}
|
||||
if (articleModel.getNextArticle() != null) {
|
||||
assertTrue(articleMapper.findArticleById(articleModel.getNextArticle().getId()).getOpen());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-categorytag</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,19 +0,0 @@
|
||||
package cn.celess.categorytag;
|
||||
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import cn.celess.user.UserApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {CategoryTagApplication.class, CommonApplication.class, UserApplication.class})
|
||||
public class CategoryTagApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(CategoryTagApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _______
|
||||
| | | | (_) | _ \ | | |__ __|
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ | | __ _ __ _
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| | | / _` | / _` |
|
||||
| | | | | | | |_) | | | | (_) | | (_| | | | | (_| | | (_| |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | |_| \__,_| \__, |
|
||||
__/ | __/ |
|
||||
|___/ |___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess.categorytag;
|
||||
|
||||
import cn.celess.common.test.BaseTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = {CategoryTagApplication.class})
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class CategoryTagBaseTest extends BaseTest {
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-comment</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.celess.comment;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import cn.celess.user.UserApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {CommentApplication.class, CommonApplication.class, UserApplication.class})
|
||||
public class CommentApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(CommentApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _____ _
|
||||
| | | | (_) | _ \ | | / ____| | |
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ | | ___ _ __ ___ _ __ ___ ___ _ __ | |_
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| | | / _ \ | '_ ` _ \ | '_ ` _ \ / _ \ | '_ \ | __|
|
||||
| | | | | | | |_) | | | | (_) | | (_| | | |____ | (_) | | | | | | | | | | | | | | __/ | | | | | |_
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | \_____| \___/ |_| |_| |_| |_| |_| |_| \___| |_| |_| \__|
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess.comment;
|
||||
|
||||
import cn.celess.common.test.BaseTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = {CommentApplication.class})
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class CommentBaseTest extends BaseTest {
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-resource</artifactId>
|
||||
<version>${blog-resource.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.8</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>jconsole</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pageHelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--Email-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<!-- TODO: remove this -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>[7.2.0, 7.2.99]</version>
|
||||
</dependency>
|
||||
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
<version>2.53.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- protostuff序列化依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.dyuproject.protostuff</groupId>
|
||||
<artifactId>protostuff-core</artifactId>
|
||||
<version>1.1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dyuproject.protostuff</groupId>
|
||||
<artifactId>protostuff-runtime</artifactId>
|
||||
<version>1.1.6</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.celess.common;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
|
||||
@SpringBootApplication(
|
||||
scanBasePackageClasses = {
|
||||
CommonApplication.class
|
||||
}
|
||||
)
|
||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
|
||||
@MapperScan("cn.celess.common.mapper")
|
||||
public class CommonApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(CommonApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package cn.celess.common.config;
|
||||
|
||||
import cn.celess.common.util.EnvironmentUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.logging.DeferredLog;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
@Component
|
||||
public class CommonEnvPostProcessor implements EnvironmentPostProcessor, ApplicationListener<ApplicationEvent>, Ordered {
|
||||
public static final DeferredLog log = new DeferredLog();
|
||||
|
||||
private static final String CONFIG_PATH = "/HBlog/config/blog.properties";
|
||||
private static final String SOURCE_NAME = "localize";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment configurableEnvironment, SpringApplication springApplication) {
|
||||
|
||||
EnvironmentUtil.setEnvironment(configurableEnvironment);
|
||||
|
||||
log.info("加载本地配置文件--");
|
||||
//获取环境变量
|
||||
String homeEnv = EnvironmentUtil.getEnv("BLOG_HOME", EnvironmentUtil.getEnv("USERPROFILE"));
|
||||
String configPath = (homeEnv + CONFIG_PATH).replaceAll("[\\|/]+", Matcher.quoteReplacement(File.separator));
|
||||
try (InputStream input = new FileInputStream(configPath)) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(input);
|
||||
PropertiesPropertySource propertySource = new PropertiesPropertySource(SOURCE_NAME, properties);
|
||||
configurableEnvironment.getPropertySources().addLast(propertySource);
|
||||
log.info("成功加载本地配置文件:)");
|
||||
} catch (Exception e) {
|
||||
log.info("加载本地[" + configPath + "]的配置文件失败:(");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
log.replayTo(CommonEnvPostProcessor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/21 22:43
|
||||
*/
|
||||
public class QiniuResponse implements Serializable {
|
||||
public String key;
|
||||
public String hash;
|
||||
public String bucket;
|
||||
public long fsize;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.vo.QiniuResponse;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
public interface QiniuService {
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param is InputStream流
|
||||
* @param fileName 文件名
|
||||
* @return 响应数据
|
||||
*/
|
||||
QiniuResponse uploadFile(InputStream is, String fileName);
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
* @return 文件列表
|
||||
*/
|
||||
FileInfo[] getFileList();
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package cn.celess.common.test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import redis.embedded.RedisServer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/08/14 16:20
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class BaseRedisTest extends BaseTest {
|
||||
private static RedisServer redisServer;
|
||||
|
||||
@PostConstruct
|
||||
public static void startRedis() {
|
||||
try {
|
||||
if (redisServer == null) {
|
||||
redisServer = new RedisServer(6380);
|
||||
redisServer.start();
|
||||
log.info("start Redis success");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("start Redis failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy()
|
||||
public static void stopRedis() {
|
||||
if (redisServer.isActive()) {
|
||||
redisServer.stop();
|
||||
log.info("stop Redis success");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package cn.celess.common.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@Slf4j
|
||||
public class EnvironmentUtil {
|
||||
|
||||
private static Environment environment;
|
||||
|
||||
public static String getEnv(String name) {
|
||||
String value = System.getenv(name);
|
||||
if (StringUtils.isBlank(value)) {
|
||||
log.error("没有找到环境变量:" + name);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String getEnv(String name, String defaultValue) {
|
||||
String env = getEnv(name);
|
||||
if (env == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
public static String getProperties(String key) {
|
||||
String value = environment.getProperty(key);
|
||||
if (StringUtils.isBlank(value)) {
|
||||
log.error("没有找到配置项: {}", key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String getProperties(String key, String defaultValue) {
|
||||
return environment.getProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
public static void setEnvironment(Environment environment) {
|
||||
EnvironmentUtil.environment = environment;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package cn.celess.common.util;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:21
|
||||
*/
|
||||
public class StringUtil {
|
||||
/**
|
||||
* 从html中提取纯文本
|
||||
*
|
||||
* @param html html string
|
||||
* @return 纯文本
|
||||
*/
|
||||
public static String getString(String html) {
|
||||
//剔出<html>的标签
|
||||
String txtcontent = html.replaceAll("</?[^>]+>", "");
|
||||
//去除字符串中的空格,回车,换行符,制表符
|
||||
txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
|
||||
return txtcontent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成MD5
|
||||
*
|
||||
* @param str 源数据
|
||||
* @return md5 内容
|
||||
*/
|
||||
public static String getMD5(String str) {
|
||||
return DigestUtils.md5DigestAsHex(str.getBytes());
|
||||
}
|
||||
|
||||
public static String getCompleteUrlAndMethod(HttpServletRequest request) {
|
||||
// like this : GET:/articles?page=1&count=5
|
||||
return request.getMethod() + ":" + request.getRequestURI() +
|
||||
(request.getQueryString() == null ? "" : "?" + request.getQueryString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=cn.celess.common.config.CommonEnvPostProcessor
|
||||
org.springframework.context.ApplicationListener=cn.celess.common.config.CommonEnvPostProcessor
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _____
|
||||
| | | | (_) | _ \ | | / ____|
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ | | ___ _ __ ___ _ __ ___ ___ _ __
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| | | / _ \ | '_ ` _ \ | '_ ` _ \ / _ \ | '_ \
|
||||
| | | | | | | |_) | | | | (_) | | (_| | | |____ | (_) | | | | | | | | | | | | | | (_) | | | | |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | \_____| \___/ |_| |_| |_| |_| |_| |_| \___/ |_| |_|
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,11 +0,0 @@
|
||||
package cn.celess.common;
|
||||
|
||||
import cn.celess.common.test.BaseTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = CommonApplication.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class CommonBaseTest extends BaseTest {
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package cn.celess.common.util;
|
||||
|
||||
import cn.celess.common.CommonBaseTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class StringUtilTest extends CommonBaseTest {
|
||||
|
||||
@Test
|
||||
public void getMD5() {
|
||||
assertEquals("25f9e794323b453885f5181f1b624d0b", StringUtil.getMD5("123456789"));
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-deploy</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-article</artifactId>
|
||||
<version>${blog-article.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-categorytag</artifactId>
|
||||
<version>${blog-categorytag.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-comment</artifactId>
|
||||
<version>${blog-comment.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-extension</artifactId>
|
||||
<version>${blog-extension.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-partnersite</artifactId>
|
||||
<version>${blog-partnersite.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-siteinfo</artifactId>
|
||||
<version>${blog-siteinfo.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-visitor</artifactId>
|
||||
<version>${blog-visitor.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.5.5</version>
|
||||
<configuration>
|
||||
<mainClass>cn.celess.BlogApplication</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,27 +0,0 @@
|
||||
package cn.celess;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAsync
|
||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
|
||||
public class BlogApplication {
|
||||
public static final Logger logger = LoggerFactory.getLogger(BlogApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(BlogApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
logger.info("启动完成!");
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package cn.celess.configuration;
|
||||
|
||||
import cn.celess.common.util.EnvironmentUtil;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:26
|
||||
*/
|
||||
@Configuration
|
||||
public class DruidConfig {
|
||||
|
||||
@Bean
|
||||
public DruidDataSource druidDataSource() {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setDriverClassName(EnvironmentUtil.getProperties("spring.datasource.driver-class-name"));
|
||||
// 数据库基本信息
|
||||
dataSource.setUrl(EnvironmentUtil.getProperties("spring.datasource.url"));
|
||||
dataSource.setUsername(EnvironmentUtil.getProperties("spring.datasource.username"));
|
||||
dataSource.setPassword(EnvironmentUtil.getProperties("spring.datasource.password"));
|
||||
|
||||
// 数据库连接池配置
|
||||
dataSource.setInitialSize(10);
|
||||
dataSource.setMinIdle(10);
|
||||
dataSource.setMaxActive(100);
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _
|
||||
| | | | (_) | _ \ | |
|
||||
| |__| | _ | |_) | | | ___ __ _
|
||||
| __ | | | | _ < | | / _ \ / _` |
|
||||
| | | | | | | |_) | | | | (_) | | (_| |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, |
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess;
|
||||
|
||||
import cn.celess.common.test.BaseTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = {BlogApplication.class})
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class DeployBaseTest extends BaseTest {
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-extension</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 七牛云SDK -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>[7.2.0, 7.2.99]</version>
|
||||
</dependency>
|
||||
|
||||
<!--Email-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,17 +0,0 @@
|
||||
package cn.celess.extension;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {ExtensionApplication.class, CommonApplication.class})
|
||||
public class ExtensionApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(ExtensionApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package cn.celess.extension.serviceimpl;
|
||||
|
||||
import cn.celess.common.entity.vo.QiniuResponse;
|
||||
import cn.celess.common.service.QiniuService;
|
||||
import cn.celess.common.util.EnvironmentUtil;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
public class QiniuServiceImpl implements QiniuService {
|
||||
private static final Configuration cfg = new Configuration(Zone.zone2());
|
||||
private static UploadManager uploadManager;
|
||||
private static BucketManager bucketManager;
|
||||
private static Auth auth;
|
||||
|
||||
private void init() {
|
||||
String accessKey = EnvironmentUtil.getProperties("qiniu.accessKey");
|
||||
String secretKey = EnvironmentUtil.getProperties("qiniu.secretKey");
|
||||
if (auth == null || uploadManager == null || bucketManager == null) {
|
||||
auth = Auth.create(accessKey, secretKey);
|
||||
uploadManager = new UploadManager(cfg);
|
||||
bucketManager = new BucketManager(auth, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QiniuResponse uploadFile(InputStream is, String fileName) {
|
||||
init();
|
||||
String bucket = EnvironmentUtil.getProperties("qiniu.bucket");
|
||||
//文件存在则删除文件
|
||||
if (continueFile(fileName)) {
|
||||
try {
|
||||
System.out.println(bucketManager.delete(bucket, fileName).toString());
|
||||
} catch (QiniuException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//上传
|
||||
try {
|
||||
Response response = uploadManager.put(is, fileName, auth.uploadToken(bucket), null, null);
|
||||
return response.jsonToObject(QiniuResponse.class);
|
||||
} catch (QiniuException e) {
|
||||
Response r = e.response;
|
||||
System.err.println(r.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo[] getFileList() {
|
||||
init();
|
||||
String bucket = EnvironmentUtil.getProperties("qiniu.bucket");
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, "", 1000, "");
|
||||
FileInfo[] items = null;
|
||||
while (fileListIterator.hasNext()) {
|
||||
//处理获取的file list结果
|
||||
items = fileListIterator.next();
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private boolean continueFile(String key) {
|
||||
FileInfo[] allFile = getFileList();
|
||||
for (FileInfo fileInfo : allFile) {
|
||||
if (key.equals(fileInfo.key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _ _
|
||||
| | | | (_) | _ \ | | | | (_)
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ ___ __ __ | |_ ___ _ __ ___ _ ___ _ __
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| / _ \ \ \/ / | __| / _ \ | '_ \ / __| | | / _ \ | '_ \
|
||||
| | | | | | | |_) | | | | (_) | | (_| | | __/ > < | |_ | __/ | | | | \__ \ | | | (_) | | | | |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | \___| /_/\_\ \__| \___| |_| |_| |___/ |_| \___/ |_| |_|
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-partnersite</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- OkHttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.9.2</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.jetbrains.kotlin</groupId>-->
|
||||
<!-- <artifactId>kotlin-stdlib</artifactId>-->
|
||||
<!-- <version>1.4.20</version>-->
|
||||
<!-- <scope>compile</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.celess.partnersite;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import cn.celess.user.UserApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {PartnerSiteApplication.class, CommonApplication.class, UserApplication.class})
|
||||
public class PartnerSiteApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(PartnerSiteApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _ _ _
|
||||
| | | | (_) | _ \ | | | | (_) | |
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ _ __ __ _ _ __ | |_ _ __ ___ _ __ ___ _ | |_ ___
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| | '_ \ / _` | | '__| | __| | '_ \ / _ \ | '__| / __| | | | __| / _ \
|
||||
| | | | | | | |_) | | | | (_) | | (_| | | |_) | | (_| | | | | |_ | | | | | __/ | | \__ \ | | | |_ | __/
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | | .__/ \__,_| |_| \__| |_| |_| \___| |_| |___/ |_| \__| \___|
|
||||
__/ | | |
|
||||
|___/ |_|
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess.partnersite;
|
||||
|
||||
import cn.celess.common.test.BaseRedisTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = PartnerSiteApplication.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class PartnerSiteBaseTest extends BaseRedisTest {
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-resource</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>13</maven.compiler.source>
|
||||
<maven.compiler.target>13</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-siteinfo</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.celess.siteinfo;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import cn.celess.user.UserApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {SiteInfoApplication.class, CommonApplication.class, UserApplication.class})
|
||||
public class SiteInfoApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(SiteInfoApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _ _ _ __
|
||||
| | | | (_) | _ \ | | (_) | | (_) / _|
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ ___ _ | |_ ___ _ _ __ | |_ ___
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| / __| | | | __| / _ \ | | | '_ \ | _| / _ \
|
||||
| | | | | | | |_) | | | | (_) | | (_| | \__ \ | | | |_ | __/ | | | | | | | | | (_) |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | |___/ |_| \__| \___| |_| |_| |_| |_| \___/
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess.siteinfo;
|
||||
|
||||
import cn.celess.common.test.BaseTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = SiteInfoApplication.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class SiteInfoBaseTest extends BaseTest {
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-user</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JJwt -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-core</artifactId>
|
||||
<version>2.3.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,17 +0,0 @@
|
||||
package cn.celess.user;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {UserApplication.class, CommonApplication.class})
|
||||
public class UserApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(UserApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package cn.celess.user.config;
|
||||
|
||||
import cn.celess.user.filter.AuthenticationFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 14:19
|
||||
* @Description:
|
||||
*/
|
||||
@Configuration
|
||||
public class AuthorizationInterceptorConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authenticationFilter()).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthenticationFilter authenticationFilter() {
|
||||
return new AuthenticationFilter();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _ _
|
||||
| | | | (_) | _ \ | | | | | |
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ | | | | ___ ___ _ __
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| | | | | / __| / _ \ | '__|
|
||||
| | | | | | | |_) | | | | (_) | | (_| | | |__| | \__ \ | __/ | |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | \____/ |___/ \___| |_|
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.celess.user;
|
||||
|
||||
import cn.celess.common.test.BaseRedisTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Component
|
||||
public abstract class UserBaseTest extends BaseRedisTest {
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-visitor</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-extension</artifactId>
|
||||
<version>${blog-extension.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Ua解析-->
|
||||
<dependency>
|
||||
<groupId>eu.bitwalker</groupId>
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,24 +0,0 @@
|
||||
package cn.celess.visitor;
|
||||
|
||||
import cn.celess.common.CommonApplication;
|
||||
import cn.celess.extension.ExtensionApplication;
|
||||
import cn.celess.user.UserApplication;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.core.SpringVersion;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = {
|
||||
VisitorApplication.class,
|
||||
CommonApplication.class,
|
||||
ExtensionApplication.class,
|
||||
UserApplication.class
|
||||
})
|
||||
public class VisitorApplication {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(VisitorApplication.class)
|
||||
.main(SpringVersion.class)
|
||||
.bannerMode(Banner.Mode.CONSOLE)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
_ _ _ ____ _ _ _ _
|
||||
| | | | (_) | _ \ | | (_) (_) | |
|
||||
| |__| | _ | |_) | | | ___ __ _ ______ __ __ _ ___ _ | |_ ___ _ __
|
||||
| __ | | | | _ < | | / _ \ / _` | |______| \ \ / / | | / __| | | | __| / _ \ | '__|
|
||||
| | | | | | | |_) | | | | (_) | | (_| | \ V / | | \__ \ | | | |_ | (_) | | |
|
||||
|_| |_| |_| |____/ |_| \___/ \__, | \_/ |_| |___/ |_| \__| \___/ |_|
|
||||
__/ |
|
||||
|___/
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
Application Version: ${application.version}${application.formatted-version}
|
||||
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.celess.visitor;
|
||||
|
||||
import cn.celess.common.test.BaseRedisTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBootTest(classes = VisitorApplication.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
public abstract class VisitorBaseTest extends BaseRedisTest {
|
||||
}
|
||||
299
doc/API.md
299
doc/API.md
@@ -1411,6 +1411,78 @@
|
||||
| 401 | Unauthorized ||
|
||||
| 403 | Forbidden ||
|
||||
| 404 | Not Found ||
|
||||
## fileUpload
|
||||
|
||||
|
||||
**接口描述**:
|
||||
|
||||
|
||||
**接口地址**:`/fileUpload`
|
||||
|
||||
|
||||
**请求方式**:`POST`
|
||||
|
||||
|
||||
**consumes**:`["application/json"]`
|
||||
|
||||
|
||||
**produces**:`["*/*"]`
|
||||
|
||||
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema |
|
||||
| ------------ | -------------------------------- |-----------|--------|----|--- |
|
||||
|file[]| file[] | formData | true |array | file |
|
||||
|
||||
**响应示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"msg": "",
|
||||
"result": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**响应参数**:
|
||||
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | -------------------|-------|----------- |
|
||||
|code| |integer(int32) | integer(int32) |
|
||||
|msg| |string | |
|
||||
|result| |array | Map«string,object» |
|
||||
|
||||
|
||||
|
||||
**schema属性说明**
|
||||
|
||||
|
||||
|
||||
|
||||
**Map«string,object»**
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | ------------------|--------|----------- |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
**响应状态**:
|
||||
|
||||
|
||||
| 状态码 | 说明 | schema |
|
||||
| ------------ | -------------------------------- |---------------------- |
|
||||
| 200 | OK |Response«List«Map«string,object»»»|
|
||||
| 201 | Created ||
|
||||
| 401 | Unauthorized ||
|
||||
| 403 | Forbidden ||
|
||||
| 404 | Not Found ||
|
||||
## headerInfo
|
||||
|
||||
|
||||
@@ -1623,6 +1695,231 @@
|
||||
| 401 | Unauthorized ||
|
||||
| 403 | Forbidden ||
|
||||
| 404 | Not Found ||
|
||||
# config-controller
|
||||
|
||||
## getConfiguration
|
||||
|
||||
|
||||
**接口描述**:
|
||||
|
||||
|
||||
**接口地址**:`/admin/config`
|
||||
|
||||
|
||||
**请求方式**:`GET`
|
||||
|
||||
|
||||
**consumes**:``
|
||||
|
||||
|
||||
**produces**:`["*/*"]`
|
||||
|
||||
|
||||
|
||||
**请求参数**:
|
||||
暂无
|
||||
|
||||
|
||||
|
||||
**响应示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"msg": "",
|
||||
"result": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**响应参数**:
|
||||
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | -------------------|-------|----------- |
|
||||
|code| |integer(int32) | integer(int32) |
|
||||
|msg| |string | |
|
||||
|result| |array | Config |
|
||||
|
||||
|
||||
|
||||
**schema属性说明**
|
||||
|
||||
|
||||
|
||||
|
||||
**Config**
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | ------------------|--------|----------- |
|
||||
|id | |integer(int32) | |
|
||||
|name | |string | |
|
||||
|value | |string | |
|
||||
|
||||
**响应状态**:
|
||||
|
||||
|
||||
| 状态码 | 说明 | schema |
|
||||
| ------------ | -------------------------------- |---------------------- |
|
||||
| 200 | OK |Response«List«Config»»|
|
||||
| 401 | Unauthorized ||
|
||||
| 403 | Forbidden ||
|
||||
| 404 | Not Found ||
|
||||
## addConfiguration
|
||||
|
||||
|
||||
**接口描述**:
|
||||
|
||||
|
||||
**接口地址**:`/admin/config`
|
||||
|
||||
|
||||
**请求方式**:`POST`
|
||||
|
||||
|
||||
**consumes**:`["application/json"]`
|
||||
|
||||
|
||||
**produces**:`["*/*"]`
|
||||
|
||||
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema |
|
||||
| ------------ | -------------------------------- |-----------|--------|----|--- |
|
||||
|configs| configs | query | false |array | Config |
|
||||
|
||||
**响应示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"msg": "",
|
||||
"result": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**响应参数**:
|
||||
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | -------------------|-------|----------- |
|
||||
|code| |integer(int32) | integer(int32) |
|
||||
|msg| |string | |
|
||||
|result| |array | Config |
|
||||
|
||||
|
||||
|
||||
**schema属性说明**
|
||||
|
||||
|
||||
|
||||
|
||||
**Config**
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | ------------------|--------|----------- |
|
||||
|id | |integer(int32) | |
|
||||
|name | |string | |
|
||||
|value | |string | |
|
||||
|
||||
**响应状态**:
|
||||
|
||||
|
||||
| 状态码 | 说明 | schema |
|
||||
| ------------ | -------------------------------- |---------------------- |
|
||||
| 200 | OK |Response«List«Config»»|
|
||||
| 201 | Created ||
|
||||
| 401 | Unauthorized ||
|
||||
| 403 | Forbidden ||
|
||||
| 404 | Not Found ||
|
||||
## updateConfiguration
|
||||
|
||||
|
||||
**接口描述**:
|
||||
|
||||
|
||||
**接口地址**:`/admin/config`
|
||||
|
||||
|
||||
**请求方式**:`PUT`
|
||||
|
||||
|
||||
**consumes**:`["application/json"]`
|
||||
|
||||
|
||||
**produces**:`["*/*"]`
|
||||
|
||||
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema |
|
||||
| ------------ | -------------------------------- |-----------|--------|----|--- |
|
||||
|configs| configs | query | false |array | Config |
|
||||
|
||||
**响应示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"msg": "",
|
||||
"result": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**响应参数**:
|
||||
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | -------------------|-------|----------- |
|
||||
|code| |integer(int32) | integer(int32) |
|
||||
|msg| |string | |
|
||||
|result| |array | Config |
|
||||
|
||||
|
||||
|
||||
**schema属性说明**
|
||||
|
||||
|
||||
|
||||
|
||||
**Config**
|
||||
|
||||
| 参数名称 | 参数说明 | 类型 | schema |
|
||||
| ------------ | ------------------|--------|----------- |
|
||||
|id | |integer(int32) | |
|
||||
|name | |string | |
|
||||
|value | |string | |
|
||||
|
||||
**响应状态**:
|
||||
|
||||
|
||||
| 状态码 | 说明 | schema |
|
||||
| ------------ | -------------------------------- |---------------------- |
|
||||
| 200 | OK |Response«List«Config»»|
|
||||
| 201 | Created ||
|
||||
| 401 | Unauthorized ||
|
||||
| 403 | Forbidden ||
|
||||
| 404 | Not Found ||
|
||||
# links-controller
|
||||
|
||||
## all
|
||||
@@ -1649,8 +1946,8 @@
|
||||
| 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema |
|
||||
| ------------ | -------------------------------- |-----------|--------|----|--- |
|
||||
|count| count | query | true |integer | |
|
||||
|page| page | query | true |integer | |
|
||||
|deleted| deleted | query | false |boolean | |
|
||||
|page| page | query | true |integer | |
|
||||
|
||||
**响应示例**:
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ git clone git@github.com:xiaohai2271/blog-backEnd.git
|
||||
|
||||
### 3. maven构建
|
||||
```shell script
|
||||
mvn clean package -pl blog-deploy -am
|
||||
mvn package
|
||||
```
|
||||
|
||||
### 4. 运行
|
||||
```shell script
|
||||
java -jar blog-deploy/target/blog-*.jar
|
||||
java -jar target/blog-0.0.1-SNAPSHOT.jar
|
||||
```
|
||||
|
||||
### 5. 其他命令
|
||||
|
||||
222
pom.xml
222
pom.xml
@@ -2,54 +2,130 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>blog-common</module>
|
||||
<module>blog-article</module>
|
||||
<module>blog-categorytag</module>
|
||||
<module>blog-user</module>
|
||||
<module>blog-comment</module>
|
||||
<module>blog-partnersite</module>
|
||||
<module>blog-visitor</module>
|
||||
<module>blog-siteinfo</module>
|
||||
<module>blog-extension</module>
|
||||
<module>blog-deploy</module>
|
||||
<module>blog-resource</module>
|
||||
</modules>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>blog</name>
|
||||
<description>personal blog system project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<blog-common.version>1.0.0</blog-common.version>
|
||||
<blog-article.version>1.0.0</blog-article.version>
|
||||
<blog-categorytag.version>1.0.0</blog-categorytag.version>
|
||||
<blog-user.version>1.0.0</blog-user.version>
|
||||
<blog-comment.version>1.0.0</blog-comment.version>
|
||||
<blog-partnersite.version>1.0.0</blog-partnersite.version>
|
||||
<blog-visitor.version>1.0.0</blog-visitor.version>
|
||||
<blog-siteinfo.version>1.0.0</blog-siteinfo.version>
|
||||
<blog-extension.version>1.0.0</blog-extension.version>
|
||||
<blog-resource.version>1.0.0</blog-resource.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!--druid-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<version>1.18.6</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
|
||||
<!--MarkDown 2 html -->
|
||||
<dependency>
|
||||
<groupId>com.youbenzi</groupId>
|
||||
<artifactId>MDTool</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.minidev</groupId>
|
||||
<artifactId>json-smart</artifactId>
|
||||
<version>2.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 七牛云SDK -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>[7.2.0, 7.2.99]</version>
|
||||
</dependency>
|
||||
|
||||
<!--Email-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pageHelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.2.12</version>
|
||||
</dependency>
|
||||
|
||||
<!-- protostuff序列化依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.dyuproject.protostuff</groupId>
|
||||
<artifactId>protostuff-core</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dyuproject.protostuff</groupId>
|
||||
<artifactId>protostuff-runtime</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Ua解析-->
|
||||
<dependency>
|
||||
<groupId>eu.bitwalker</groupId>
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
<version>1.20</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -57,11 +133,99 @@
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JJwt -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OkHttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>1.3.72</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
<version>2.42.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>0.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-core</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>1.3.72</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
34
src/main/java/cn/celess/blog/BlogApplication.java
Normal file
34
src/main/java/cn/celess/blog/BlogApplication.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package cn.celess.blog;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* @author zheng
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAsync
|
||||
@MapperScan("cn.celess.blog.mapper")
|
||||
public class BlogApplication {
|
||||
public static ConfigurableApplicationContext context;
|
||||
|
||||
public static void main(String[] args) {
|
||||
context = SpringApplication.run(BlogApplication.class, args);
|
||||
}
|
||||
|
||||
public static void restart() {
|
||||
ApplicationArguments args = context.getBean(ApplicationArguments.class);
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
context.close();
|
||||
context = SpringApplication.run(BlogApplication.class, args.getSourceArgs());
|
||||
});
|
||||
thread.setDaemon(false);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import cn.celess.blog.enmu.ConfigKeyEnum;
|
||||
import cn.celess.blog.entity.Config;
|
||||
import cn.celess.blog.mapper.ConfigMapper;
|
||||
import cn.celess.blog.service.fileserviceimpl.LocalFileServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/16 16:00
|
||||
* @desc :
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ApplicationListener implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
ConfigMapper configMapper;
|
||||
@Autowired
|
||||
Environment env;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("博客启动!");
|
||||
// 设置初始值
|
||||
setProperty(ConfigKeyEnum.FILE_QINIU_SECRET_KEY);
|
||||
setProperty(ConfigKeyEnum.FILE_QINIU_ACCESS_KEY);
|
||||
setProperty(ConfigKeyEnum.FILE_QINIU_BUCKET);
|
||||
setProperty(ConfigKeyEnum.BLOG_FILE_PATH);
|
||||
|
||||
List<Config> configurations = configMapper.getConfigurations()
|
||||
.stream()
|
||||
.filter(config -> config.getValue() != null && !"".equals(config.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
configurations.forEach(config -> System.setProperty(config.getName(), config.getValue()));
|
||||
log.debug("注入配置成功 {}", configurations.stream().map(Config::getName).collect(Collectors.toList()));
|
||||
File path = new File(LocalFileServiceImpl.getPath(System.getProperty(ConfigKeyEnum.BLOG_FILE_PATH.getKey())));
|
||||
if (!path.exists() && !path.mkdirs()) {
|
||||
throw new IllegalAccessException("创建数据目录失败==>" + path.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private void setProperty(ConfigKeyEnum e) {
|
||||
String property = env.getProperty(e.getKey());
|
||||
if (property != null) {
|
||||
System.setProperty(e.getKey(), property);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,45 @@
|
||||
package cn.celess.configuration;
|
||||
|
||||
import cn.celess.common.util.EnvironmentUtil;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 19:55
|
||||
* 跨域
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.addAllowedOrigin("http://celess.cn");
|
||||
config.addAllowedOrigin("http://www.celess.cn");
|
||||
config.addAllowedOrigin("https://celess.cn");
|
||||
config.addAllowedOrigin("https://www.celess.cn");
|
||||
// 本地调试时的跨域
|
||||
if (!"prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||
config.addAllowedOrigin("http://localhost:4200");
|
||||
config.addAllowedOrigin("http://127.0.0.1:4200");
|
||||
}
|
||||
config.addAllowedHeader("*");
|
||||
config.addAllowedMethod("OPTIONS");
|
||||
config.addAllowedMethod("GET");
|
||||
config.addAllowedMethod("POST");
|
||||
config.addAllowedMethod("PUT");
|
||||
config.addAllowedMethod("DELETE");
|
||||
config.addExposedHeader("Authorization");
|
||||
config.setAllowCredentials(true);
|
||||
config.setMaxAge(10800L);
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 19:55
|
||||
* 跨域
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.addAllowedOrigin("http://celess.cn");
|
||||
config.addAllowedOrigin("http://www.celess.cn");
|
||||
config.addAllowedOrigin("https://celess.cn");
|
||||
config.addAllowedOrigin("https://www.celess.cn");
|
||||
// 本地调试时的跨域
|
||||
if (!"prod".equals(activeModel)) {
|
||||
config.addAllowedOrigin("http://localhost:4200");
|
||||
config.addAllowedOrigin("http://127.0.0.1:4200");
|
||||
}
|
||||
config.addAllowedHeader("*");
|
||||
config.addAllowedMethod("OPTIONS");
|
||||
config.addAllowedMethod("GET");
|
||||
config.addAllowedMethod("POST");
|
||||
config.addAllowedMethod("PUT");
|
||||
config.addAllowedMethod("DELETE");
|
||||
config.addExposedHeader("Authorization");
|
||||
config.setAllowCredentials(true);
|
||||
config.setMaxAge(10800L);
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
81
src/main/java/cn/celess/blog/configuration/DruidConfig.java
Normal file
81
src/main/java/cn/celess/blog/configuration/DruidConfig.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:26
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class DruidConfig {
|
||||
|
||||
@Autowired
|
||||
Environment env;
|
||||
|
||||
public static final String DB_CONFIG_PATH = System.getProperty("user.home") + "/blog/application.properties";
|
||||
public static final String DB_CONFIG_URL_PREFIX = "spring.datasource.url";
|
||||
public static final String DB_CONFIG_USERNAME_PREFIX = "spring.datasource.username";
|
||||
public static final String DB_CONFIG_PASSWORD_PREFIX = "spring.datasource.password";
|
||||
public static final String DB_CONFIG_DRIVER_CLASS_NAME_PREFIX = "spring.datasource.driver-class-name";
|
||||
public static final String TEST_PROFILES = "test";
|
||||
|
||||
@Bean
|
||||
public DruidDataSource initDataSource() throws IOException {
|
||||
DruidDataSource dataSource;
|
||||
File file = new File(DB_CONFIG_PATH);
|
||||
if (file.exists() && !Arrays.asList(env.getActiveProfiles()).contains(TEST_PROFILES)) {
|
||||
log.debug("从文件中获取数据库配置");
|
||||
dataSource = readConfigFromFile(file);
|
||||
} else {
|
||||
log.debug("默认数据库配置");
|
||||
dataSource = defaultDruidSource();
|
||||
}
|
||||
dataSource.setInitialSize(10);
|
||||
dataSource.setMinIdle(10);
|
||||
dataSource.setMaxActive(100);
|
||||
dataSource.setValidationQuery("select 1");
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
private DruidDataSource readConfigFromFile(File file) throws IOException {
|
||||
Properties properties = new Properties();
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
properties.load(fis);
|
||||
fis.close();
|
||||
String url = properties.getProperty(DB_CONFIG_URL_PREFIX, null);
|
||||
String username = properties.getProperty(DB_CONFIG_USERNAME_PREFIX, null);
|
||||
String password = properties.getProperty(DB_CONFIG_PASSWORD_PREFIX, null);
|
||||
String className = properties.getProperty(DB_CONFIG_DRIVER_CLASS_NAME_PREFIX, null);
|
||||
if (url == null || username == null || password == null || className == null) {
|
||||
return defaultDruidSource();
|
||||
}
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setDriverClassName(className);
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
|
||||
private DruidDataSource defaultDruidSource() {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setDriverClassName(env.getProperty(DruidConfig.DB_CONFIG_DRIVER_CLASS_NAME_PREFIX));
|
||||
dataSource.setUrl(env.getProperty(DruidConfig.DB_CONFIG_URL_PREFIX));
|
||||
dataSource.setUsername(env.getProperty(DruidConfig.DB_CONFIG_USERNAME_PREFIX));
|
||||
dataSource.setPassword(env.getProperty(DruidConfig.DB_CONFIG_PASSWORD_PREFIX));
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,39 @@
|
||||
package cn.celess.configuration;
|
||||
|
||||
import cn.celess.configuration.filter.MultipleSubmitFilter;
|
||||
import cn.celess.configuration.filter.VisitorRecord;
|
||||
import cn.celess.configuration.listener.SessionListener;
|
||||
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 14:19
|
||||
* @Description:
|
||||
*/
|
||||
@Configuration
|
||||
public class DeployInterceptorConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new MultipleSubmitFilter()).addPathPatterns("/**");
|
||||
registry.addInterceptor(new VisitorRecord()).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletListenerRegistrationBean<SessionListener> servletListenerRegistrationBean() {
|
||||
// session listener register bean
|
||||
ServletListenerRegistrationBean<SessionListener> slrBean = new ServletListenerRegistrationBean<SessionListener>();
|
||||
slrBean.setListener(new SessionListener());
|
||||
return slrBean;
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import cn.celess.blog.configuration.filter.AuthenticationFilter;
|
||||
import cn.celess.blog.configuration.filter.MultipleSubmitFilter;
|
||||
import cn.celess.blog.configuration.filter.VisitorRecord;
|
||||
import cn.celess.blog.configuration.listener.SessionListener;
|
||||
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 14:19
|
||||
* @Description:
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new MultipleSubmitFilter()).addPathPatterns("/**");
|
||||
registry.addInterceptor(new VisitorRecord()).addPathPatterns("/**");
|
||||
registry.addInterceptor(authenticationFilter()).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthenticationFilter authenticationFilter() {
|
||||
return new AuthenticationFilter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletListenerRegistrationBean<SessionListener> servletListenerRegistrationBean() {
|
||||
// session listener register bean
|
||||
ServletListenerRegistrationBean<SessionListener> slrBean = new ServletListenerRegistrationBean<SessionListener>();
|
||||
slrBean.setListener(new SessionListener());
|
||||
return slrBean;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,69 @@
|
||||
package cn.celess.configuration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/22 17:35
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
|
||||
/**
|
||||
* 缓存的命名前缀
|
||||
*
|
||||
* @return KeyGenerator
|
||||
*/
|
||||
@Override
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
return (target, method, params) -> {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String name = target.getClass().getName();
|
||||
sb.append(name.substring(name.lastIndexOf(".") + 1));
|
||||
sb.append(":");
|
||||
sb.append(method.getName());
|
||||
for (Object obj : params) {
|
||||
sb.append("-").append(obj.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置redisTemplate
|
||||
*
|
||||
* @param redisConnectionFactory redisConnectionFactory
|
||||
* @return redisTemplate
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
|
||||
template.setConnectionFactory(redisConnectionFactory);
|
||||
template.setKeySerializer(jackson2JsonRedisSerializer);
|
||||
template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.setHashKeySerializer(jackson2JsonRedisSerializer);
|
||||
template.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/22 17:35
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
|
||||
/**
|
||||
* 缓存的命名前缀
|
||||
*
|
||||
* @return KeyGenerator
|
||||
*/
|
||||
@Override
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
return (target, method, params) -> {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String name = target.getClass().getName();
|
||||
sb.append(name.substring(name.lastIndexOf(".") + 1));
|
||||
sb.append(":");
|
||||
sb.append(method.getName());
|
||||
for (Object obj : params) {
|
||||
sb.append("-").append(obj.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置redisTemplate
|
||||
*
|
||||
* @param redisConnectionFactory redisConnectionFactory
|
||||
* @return redisTemplate
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
|
||||
template.setConnectionFactory(redisConnectionFactory);
|
||||
template.setKeySerializer(jackson2JsonRedisSerializer);
|
||||
template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.setHashKeySerializer(jackson2JsonRedisSerializer);
|
||||
template.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,46 @@
|
||||
package cn.celess.configuration;
|
||||
|
||||
import cn.celess.common.util.EnvironmentUtil;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:55
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.enable(!"prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev")))
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("cn.celess"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("小海博客的APi")
|
||||
.description("小海博客的APi")
|
||||
.contact(new Contact("小海", "https://www.celess.cn", "a@celess.cn"))
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:55
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String environment;
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.enable(!"prod".equals(environment))
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("cn.celess.blog"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("小海博客的APi")
|
||||
.description("小海博客的APi")
|
||||
.contact(new Contact("小海", "https://www.celess.cn", "a@celess.cn"))
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +1,93 @@
|
||||
package cn.celess.user.filter;
|
||||
|
||||
|
||||
import cn.celess.common.constant.ResponseEnum;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.service.UserService;
|
||||
import cn.celess.common.util.RedisUtil;
|
||||
import cn.celess.user.util.JwtUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/11/16 11:21
|
||||
* @Description: 鉴权拦截器
|
||||
*/
|
||||
public class AuthenticationFilter implements HandlerInterceptor {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuthenticationFilter.class);
|
||||
private static final String USER_PREFIX = "/user";
|
||||
private static final String ADMIN_PREFIX = "/admin";
|
||||
private static final String ROLE_ADMIN = "admin";
|
||||
private static final String ROLE_USER = "user";
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String path = request.getRequestURI();
|
||||
path = path.replaceAll("/+", "/");
|
||||
int indexOf = path.indexOf("/", 1);
|
||||
String rootPath = indexOf == -1 ? path : path.substring(0, indexOf);
|
||||
String jwtStr = request.getHeader("Authorization");
|
||||
if (jwtStr != null && !jwtStr.isEmpty() && !JwtUtil.isTokenExpired(jwtStr)) {
|
||||
// 已登录 记录当前email
|
||||
request.getSession().setAttribute("email", JwtUtil.getUsernameFromToken(jwtStr));
|
||||
}
|
||||
// 不需要鉴权的路径
|
||||
if (!USER_PREFIX.equalsIgnoreCase(rootPath) && !ADMIN_PREFIX.equalsIgnoreCase(rootPath)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jwtStr == null || jwtStr.isEmpty()) {
|
||||
return writeResponse(ResponseEnum.HAVE_NOT_LOG_IN, response, request);
|
||||
}
|
||||
if (JwtUtil.isTokenExpired(jwtStr)) {
|
||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
||||
}
|
||||
String email = JwtUtil.getUsernameFromToken(jwtStr);
|
||||
if (JwtUtil.isTokenExpired(jwtStr)) {
|
||||
// 登陆过期
|
||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
||||
}
|
||||
if (!redisUtil.hasKey(email + "-login")) {
|
||||
return writeResponse(ResponseEnum.LOGOUT, response, request);
|
||||
}
|
||||
String role = userService.getUserRoleByEmail(email);
|
||||
if (role.equals(ROLE_USER) || role.equals(ROLE_ADMIN)) {
|
||||
// 更新token
|
||||
String token = JwtUtil.updateTokenDate(jwtStr);
|
||||
response.setHeader("Authorization", token);
|
||||
}
|
||||
if (role.equals(ROLE_ADMIN)) {
|
||||
// admin
|
||||
return true;
|
||||
}
|
||||
if (role.equals(ROLE_USER) && !rootPath.equals(ADMIN_PREFIX)) {
|
||||
// user not admin page
|
||||
return true;
|
||||
}
|
||||
return writeResponse(ResponseEnum.PERMISSION_ERROR, response, request);
|
||||
}
|
||||
|
||||
private boolean writeResponse(ResponseEnum e, HttpServletResponse response, HttpServletRequest request) {
|
||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
try {
|
||||
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
||||
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.configuration.filter;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.util.JwtUtil;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/11/16 11:21
|
||||
* @Description: 鉴权拦截器
|
||||
*/
|
||||
public class AuthenticationFilter implements HandlerInterceptor {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuthenticationFilter.class);
|
||||
private static final String USER_PREFIX = "/user";
|
||||
private static final String ADMIN_PREFIX = "/admin";
|
||||
private static final String ROLE_ADMIN = "admin";
|
||||
private static final String ROLE_USER = "user";
|
||||
@Autowired
|
||||
JwtUtil jwtUtil;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String path = request.getRequestURI();
|
||||
path = path.replaceAll("/+", "/");
|
||||
int indexOf = path.indexOf("/", 1);
|
||||
String rootPath = indexOf == -1 ? path : path.substring(0, indexOf);
|
||||
String jwtStr = request.getHeader("Authorization");
|
||||
if (jwtStr != null && !jwtStr.isEmpty() && !jwtUtil.isTokenExpired(jwtStr)) {
|
||||
// 已登录 记录当前email
|
||||
request.getSession().setAttribute("email", jwtUtil.getUsernameFromToken(jwtStr));
|
||||
}
|
||||
// 不需要鉴权的路径
|
||||
if (!USER_PREFIX.equals(rootPath.toLowerCase()) && !ADMIN_PREFIX.equals(rootPath.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jwtStr == null || jwtStr.isEmpty()) {
|
||||
return writeResponse(ResponseEnum.HAVE_NOT_LOG_IN, response, request);
|
||||
}
|
||||
if (jwtUtil.isTokenExpired(jwtStr)) {
|
||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
||||
}
|
||||
String email = jwtUtil.getUsernameFromToken(jwtStr);
|
||||
if (jwtUtil.isTokenExpired(jwtStr)) {
|
||||
// 登陆过期
|
||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
||||
}
|
||||
if (!redisUtil.hasKey(email + "-login")) {
|
||||
return writeResponse(ResponseEnum.LOGOUT, response, request);
|
||||
}
|
||||
String role = userService.getUserRoleByEmail(email);
|
||||
if (role.equals(ROLE_USER) || role.equals(ROLE_ADMIN)) {
|
||||
// 更新token
|
||||
String token = jwtUtil.updateTokenDate(jwtStr);
|
||||
response.setHeader("Authorization", token);
|
||||
}
|
||||
if (role.equals(ROLE_ADMIN)) {
|
||||
// admin
|
||||
return true;
|
||||
}
|
||||
if (role.equals(ROLE_USER) && !rootPath.equals(ADMIN_PREFIX)) {
|
||||
// user not admin page
|
||||
return true;
|
||||
}
|
||||
return writeResponse(ResponseEnum.PERMISSION_ERROR, response, request);
|
||||
}
|
||||
|
||||
private boolean writeResponse(ResponseEnum e, HttpServletResponse response, HttpServletRequest request) {
|
||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
try {
|
||||
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
||||
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,44 @@
|
||||
package cn.celess.configuration.filter;
|
||||
|
||||
import cn.celess.common.constant.ResponseEnum;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.util.StringUtil;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 13:46
|
||||
* @Description: 多次请求拦截器
|
||||
*/
|
||||
public class MultipleSubmitFilter implements HandlerInterceptor {
|
||||
private static final int WAIT_TIME = 200;// 多次提交中间的间隔
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
Long lastSubmitTime = (Long) request.getSession().getAttribute("lastSubmitTime");
|
||||
String completeUrl = (String) request.getSession().getAttribute("completeUrl&method");
|
||||
if (lastSubmitTime == null || completeUrl == null) {
|
||||
return true;
|
||||
}
|
||||
if (System.currentTimeMillis() - lastSubmitTime < WAIT_TIME && StringUtil.getCompleteUrlAndMethod(request).equals(completeUrl)) {
|
||||
// 请求参数和路径均相同 且请求时间间隔小于 WAIT_TIME
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
Response result = new Response(ResponseEnum.FAILURE.getCode(), "重复请求", null);
|
||||
response.getWriter().println(result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
HttpSession session = request.getSession();
|
||||
session.setAttribute("lastSubmitTime", System.currentTimeMillis());
|
||||
session.setAttribute("completeUrl&method", StringUtil.getCompleteUrlAndMethod(request));
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.configuration.filter;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.util.RequestUtil;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 13:46
|
||||
* @Description: 多次请求拦截器
|
||||
*/
|
||||
public class MultipleSubmitFilter implements HandlerInterceptor {
|
||||
private static final int WAIT_TIME = 200;// 多次提交中间的间隔
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
Long lastSubmitTime = (Long) request.getSession().getAttribute("lastSubmitTime");
|
||||
String completeUrl = (String) request.getSession().getAttribute("completeUrl&method");
|
||||
if (lastSubmitTime == null || completeUrl == null) {
|
||||
return true;
|
||||
}
|
||||
if (System.currentTimeMillis() - lastSubmitTime < WAIT_TIME && RequestUtil.getCompleteUrlAndMethod(request).equals(completeUrl)) {
|
||||
// 请求参数和路径均相同 且请求时间间隔小于 WAIT_TIME
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
Response result = new Response(ResponseEnum.FAILURE.getCode(), "重复请求", null);
|
||||
response.getWriter().println(result.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
HttpSession session = request.getSession();
|
||||
session.setAttribute("lastSubmitTime", System.currentTimeMillis());
|
||||
session.setAttribute("completeUrl&method", RequestUtil.getCompleteUrlAndMethod(request));
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,38 @@
|
||||
package cn.celess.configuration.filter;
|
||||
|
||||
import cn.celess.common.util.StringUtil;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 15:38
|
||||
* @Description: 记录访问情况
|
||||
*/
|
||||
@Configuration
|
||||
public class VisitorRecord implements HandlerInterceptor {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
HashMap<String, Integer> visitDetail = (HashMap<String, Integer>) session.getAttribute("visitDetail");
|
||||
if (visitDetail == null) {
|
||||
return true;
|
||||
}
|
||||
// 获取访问次数
|
||||
Integer count = visitDetail.get(StringUtil.getCompleteUrlAndMethod(request));
|
||||
// 自增
|
||||
count = count == null ? 1 : ++count;
|
||||
// 更新
|
||||
visitDetail.put(StringUtil.getCompleteUrlAndMethod(request), count);
|
||||
session.setAttribute("ip", request.getRemoteAddr());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.configuration.filter;
|
||||
|
||||
import cn.celess.blog.util.RequestUtil;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 15:38
|
||||
* @Description: 记录访问情况
|
||||
*/
|
||||
@Configuration
|
||||
public class VisitorRecord implements HandlerInterceptor {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
HashMap<String, Integer> visitDetail = (HashMap<String, Integer>) session.getAttribute("visitDetail");
|
||||
if (visitDetail == null) {
|
||||
return true;
|
||||
}
|
||||
// 获取访问次数
|
||||
Integer count = visitDetail.get(RequestUtil.getCompleteUrlAndMethod(request));
|
||||
// 自增
|
||||
count = count == null ? 1 : ++count;
|
||||
// 更新
|
||||
visitDetail.put(RequestUtil.getCompleteUrlAndMethod(request), count);
|
||||
session.setAttribute("ip", request.getRemoteAddr());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
package cn.celess.configuration.listener;
|
||||
|
||||
import cn.celess.user.util.RedisUserUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.annotation.WebListener;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 15:33
|
||||
* @Description: 监听session的情况
|
||||
*/
|
||||
@Log4j2
|
||||
@WebListener
|
||||
public class SessionListener implements HttpSessionListener {
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
@Override
|
||||
public void sessionCreated(HttpSessionEvent se) {
|
||||
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
|
||||
// 10s for debug
|
||||
// se.getSession().setMaxInactiveInterval(10);
|
||||
// log.info("新增一个Session[{}]", se.getSession().getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void sessionDestroyed(HttpSessionEvent se) {
|
||||
HashMap<String, Integer> visitDetail = (HashMap<String, Integer>) se.getSession().getAttribute("visitDetail");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("ip => ").append(se.getSession().getAttribute("ip"));
|
||||
if (visitDetail.size() == 0) {
|
||||
return;
|
||||
}
|
||||
sb.append("\t登录情况 => ");
|
||||
String email = (String) se.getSession().getAttribute("email");
|
||||
sb.append(email == null ? "游客访问" : email);
|
||||
visitDetail.forEach((s, integer) -> sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]"));
|
||||
log.info(sb.toString());
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.configuration.listener;
|
||||
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.annotation.WebListener;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 15:33
|
||||
* @Description: 监听session的情况
|
||||
*/
|
||||
@Log4j2
|
||||
@WebListener
|
||||
public class SessionListener implements HttpSessionListener {
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
@Override
|
||||
public void sessionCreated(HttpSessionEvent se) {
|
||||
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
|
||||
// 10s for debug
|
||||
// se.getSession().setMaxInactiveInterval(10);
|
||||
// log.info("新增一个Session[{}]", se.getSession().getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void sessionDestroyed(HttpSessionEvent se) {
|
||||
HashMap<String, Integer> visitDetail = (HashMap<String, Integer>) se.getSession().getAttribute("visitDetail");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("ip => ").append(se.getSession().getAttribute("ip"));
|
||||
if (visitDetail.size() == 0) {
|
||||
return;
|
||||
}
|
||||
sb.append("\t登录情况 => ");
|
||||
String email = (String) se.getSession().getAttribute("email");
|
||||
sb.append(email == null ? "游客访问" : email);
|
||||
visitDetail.forEach((s, integer) -> sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]"));
|
||||
log.info(sb.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,161 +1,163 @@
|
||||
package cn.celess.article.controller;
|
||||
|
||||
import cn.celess.article.util.SitemapGenerateUtil;
|
||||
import cn.celess.common.constant.ResponseEnum;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.dto.ArticleReq;
|
||||
import cn.celess.common.entity.vo.ArticleModel;
|
||||
import cn.celess.common.service.ArticleService;
|
||||
import cn.celess.common.util.EnvironmentUtil;
|
||||
import cn.celess.user.util.RedisUserUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:18
|
||||
*/
|
||||
@RestController
|
||||
public class ArticleController {
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
@Autowired
|
||||
SitemapGenerateUtil sitemapGenerateUtil;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
/**
|
||||
* 新建一篇文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/article/create")
|
||||
public Response create(@RequestBody ArticleReq body) {
|
||||
ArticleModel articleModel = articleService.create(body);
|
||||
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(articleModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文章id 删除一篇文章
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/article/del")
|
||||
public Response delete(@RequestParam("articleID") long articleId) {
|
||||
boolean delete = articleService.delete(articleId);
|
||||
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/article/update")
|
||||
public Response update(@RequestBody ArticleReq body) {
|
||||
ArticleModel update = articleService.update(body);
|
||||
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查找一篇文章
|
||||
* 公开 =>返回数据
|
||||
* 不公开
|
||||
* *** =>作者 返回数据
|
||||
* *** =>其他 抛出错误
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是更新
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/article/articleID/{articleID}")
|
||||
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
||||
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
||||
HttpServletRequest request) {
|
||||
ArticleModel article = articleService.retrieveOneById(articleId, is4update);
|
||||
if (article.getOpen()) {
|
||||
return Response.success(article);
|
||||
} else if (article.getAuthor().getId().equals(redisUserUtil.get().getId())) {
|
||||
return Response.success(article);
|
||||
}
|
||||
return Response.response(ResponseEnum.PERMISSION_ERROR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章状态为开放的的文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles")
|
||||
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "5") int count) {
|
||||
return Response.success(articleService.retrievePageForOpen(count, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/admin/articles")
|
||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count,
|
||||
@RequestParam(name = "deleted", required = false) Boolean deleted) {
|
||||
return Response.success(articleService.adminArticles(count, page, deleted));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分类获取文章(文章摘要)
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/category/{name}")
|
||||
public Response findByCategory(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByCategory(name, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过标签名获取文章(文章摘要)
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/tag/{name}")
|
||||
public Response findByTag(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByTag(name, page, count));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/createSitemap")
|
||||
public Response createSitemap() {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return Response.success(null);
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.request.ArticleReq;
|
||||
import cn.celess.blog.service.ArticleService;
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:18
|
||||
*/
|
||||
@RestController
|
||||
public class ArticleController {
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
@Autowired
|
||||
SitemapGenerateUtil sitemapGenerateUtil;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
/**
|
||||
* 新建一篇文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/article/create")
|
||||
public Response create(@RequestBody ArticleReq body) {
|
||||
ArticleModel articleModel = articleService.create(body);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(articleModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文章id 删除一篇文章
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/article/del")
|
||||
public Response delete(@RequestParam("articleID") long articleId) {
|
||||
boolean delete = articleService.delete(articleId);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/article/update")
|
||||
public Response update(@RequestBody ArticleReq body) {
|
||||
ArticleModel update = articleService.update(body);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查找一篇文章
|
||||
* 公开 =>返回数据
|
||||
* 不公开
|
||||
* *** =>作者 返回数据
|
||||
* *** =>其他 抛出错误
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是更新
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/article/articleID/{articleID}")
|
||||
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
||||
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
||||
HttpServletRequest request) {
|
||||
ArticleModel article = articleService.retrieveOneById(articleId, is4update);
|
||||
if (article.getOpen()) {
|
||||
return Response.success(article);
|
||||
} else if (article.getAuthor().getId().equals(redisUserUtil.get().getId())) {
|
||||
return Response.success(article);
|
||||
}
|
||||
return Response.response(ResponseEnum.PERMISSION_ERROR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章状态为开放的的文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles")
|
||||
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "5") int count) {
|
||||
return Response.success(articleService.retrievePageForOpen(count, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/admin/articles")
|
||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count,
|
||||
@RequestParam(name = "deleted", required = false) Boolean deleted) {
|
||||
return Response.success(articleService.adminArticles(count, page, deleted));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分类获取文章(文章摘要)
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/category/{name}")
|
||||
public Response findByCategory(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByCategory(name, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过标签名获取文章(文章摘要)
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/tag/{name}")
|
||||
public Response findByTag(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByTag(name, page, count));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/createSitemap")
|
||||
public Response createSitemap() {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return Response.success(null);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,63 @@
|
||||
package cn.celess.categorytag.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 新增一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/category/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.create(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/category/del")
|
||||
public Response deleteOne(@RequestParam("id") long id) {
|
||||
return Response.success(categoryService.delete(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 更新后的名字
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/category/update")
|
||||
public Response updateOne(@RequestParam("id") Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.update(id, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的分类
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public Response getPage(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "1000") int count) {
|
||||
return Response.success(categoryService.retrievePage(page, count));
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 新增一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/category/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.create(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/category/del")
|
||||
public Response deleteOne(@RequestParam("id") long id) {
|
||||
return Response.success(categoryService.delete(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 更新后的名字
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/category/update")
|
||||
public Response updateOne(@RequestParam("id") Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.update(id, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的分类
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public Response getPage(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "1000") int count) {
|
||||
return Response.success(categoryService.retrievePage(page, count));
|
||||
}
|
||||
}
|
||||
@@ -1,119 +1,119 @@
|
||||
package cn.celess.comment.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.dto.CommentReq;
|
||||
import cn.celess.common.service.CommentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class CommentController {
|
||||
@Autowired
|
||||
CommentService commentService;
|
||||
|
||||
/**
|
||||
* 新增一条评论数据
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/user/comment/create")
|
||||
public Response addOne(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/comment/del")
|
||||
public Response delete(@RequestParam("id") long id) {
|
||||
return Response.success(commentService.delete(id));
|
||||
}
|
||||
|
||||
@PutMapping("/user/comment/update")
|
||||
public Response update(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.update(reqBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的评论
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 页码
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comments/{pagePath}/{pid}")
|
||||
public Response commentsOfArticle(@PathVariable("pagePath") String pagePath, @PathVariable(value = "pid") long pid,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPageAndPid(path, pid, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count count
|
||||
* @param page page
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comment/pagePath/{pagePath}")
|
||||
public Response retrievePage(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePage(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/user/comment/pagePath/{pagePath}")
|
||||
public Response userComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByAuthor(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/comment/pagePath/{pagePath}")
|
||||
public Response adminComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPage(path, page, count));
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.CommentReq;
|
||||
import cn.celess.blog.service.CommentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class CommentController {
|
||||
@Autowired
|
||||
CommentService commentService;
|
||||
|
||||
/**
|
||||
* 新增一条评论数据
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/user/comment/create")
|
||||
public Response addOne(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/comment/del")
|
||||
public Response delete(@RequestParam("id") long id) {
|
||||
return Response.success(commentService.delete(id));
|
||||
}
|
||||
|
||||
@PutMapping("/user/comment/update")
|
||||
public Response update(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.update(reqBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的评论
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 页码
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comments/{pagePath}/{pid}")
|
||||
public Response commentsOfArticle(@PathVariable("pagePath") String pagePath, @PathVariable(value = "pid") long pid,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPageAndPid(path, pid, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count count
|
||||
* @param page page
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comment/pagePath/{pagePath}")
|
||||
public Response retrievePage(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePage(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/user/comment/pagePath/{pagePath}")
|
||||
public Response userComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByAuthor(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/comment/pagePath/{pagePath}")
|
||||
public Response adminComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPage(path, page, count));
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package cn.celess.extension.controller;
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.common.constant.ResponseEnum;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.vo.QiniuResponse;
|
||||
import cn.celess.common.exception.BlogResponseException;
|
||||
import cn.celess.common.service.CountService;
|
||||
import cn.celess.common.service.QiniuService;
|
||||
import cn.celess.common.util.HttpUtil;
|
||||
import cn.celess.common.util.RedisUtil;
|
||||
import cn.celess.common.util.VeriCodeUtil;
|
||||
import cn.celess.user.util.RedisUserUtil;
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.FileResponse;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.service.CountService;
|
||||
import cn.celess.blog.service.FileService;
|
||||
import cn.celess.blog.util.HttpUtil;
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import cn.celess.blog.util.VeriCodeUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
@@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -37,16 +36,16 @@ import java.util.concurrent.TimeUnit;
|
||||
* @date : 2019/04/02 22:03
|
||||
*/
|
||||
@RestController
|
||||
public class ExtensionController {
|
||||
public class CommonController {
|
||||
public static final Logger logger = LoggerFactory.getLogger(Object.class);
|
||||
|
||||
@Autowired
|
||||
CountService countService;
|
||||
@Autowired
|
||||
QiniuService qiniuService;
|
||||
FileService fileService;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Resource
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
|
||||
@@ -112,10 +111,10 @@ public class ExtensionController {
|
||||
request.getSession().setAttribute("verImgCodeStatus", false);
|
||||
String codeStr = (String) request.getSession().getAttribute("code");
|
||||
if (code == null) {
|
||||
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
if (codeStr == null) {
|
||||
throw new BlogResponseException(ResponseEnum.IMG_CODE_TIMEOUT);
|
||||
throw new MyException(ResponseEnum.IMG_CODE_TIMEOUT);
|
||||
}
|
||||
code = code.toLowerCase();
|
||||
codeStr = codeStr.toLowerCase();
|
||||
@@ -147,7 +146,7 @@ public class ExtensionController {
|
||||
uploadTimes = Integer.parseInt(uploadTimesStr);
|
||||
}
|
||||
if (uploadTimes == 10) {
|
||||
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||
}
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||
@@ -160,12 +159,12 @@ public class ExtensionController {
|
||||
String fileName = file.getOriginalFilename();
|
||||
assert fileName != null;
|
||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||
if (".png".equalsIgnoreCase(mime) || ".jpg".equalsIgnoreCase(mime) ||
|
||||
".jpeg".equalsIgnoreCase(mime) || ".bmp".equalsIgnoreCase(mime)) {
|
||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||
FileResponse fileResponse = fileService.getFileManager().uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||
map.put("success", 1);
|
||||
map.put("message", "上传成功");
|
||||
map.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||
map.put("url", "http://cdn.celess.cn/" + fileResponse.key);
|
||||
response.getWriter().println(mapper.writeValueAsString(map));
|
||||
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
||||
return;
|
||||
@@ -180,7 +179,7 @@ public class ExtensionController {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root;
|
||||
try {
|
||||
root = mapper.readTree(HttpUtil.getHttpResponse("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||
root = mapper.readTree(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||
} catch (IOException e) {
|
||||
return Response.failure(null);
|
||||
}
|
||||
@@ -197,10 +196,10 @@ public class ExtensionController {
|
||||
uploadTimes = Integer.parseInt(uploadTimesStr);
|
||||
}
|
||||
if (uploadTimes == 10) {
|
||||
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||
}
|
||||
if (files.length == 0) {
|
||||
throw new BlogResponseException(ResponseEnum.NO_FILE);
|
||||
throw new MyException(ResponseEnum.NO_FILE);
|
||||
}
|
||||
for (MultipartFile file : files) {
|
||||
Map<String, Object> resp = new HashMap<>(4);
|
||||
@@ -209,12 +208,12 @@ public class ExtensionController {
|
||||
assert fileName != null;
|
||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||
String name = fileName.replace(mime, "").replaceAll(" ", "");
|
||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "file_" + name + '_' + System.currentTimeMillis() + mime);
|
||||
FileResponse fileResponse = fileService.getFileManager().uploadFile(file.getInputStream(), "file_" + name + '_' + System.currentTimeMillis() + mime);
|
||||
resp.put("originalFilename", fileName);
|
||||
resp.put("success", qiniuResponse != null);
|
||||
if (qiniuResponse != null) {
|
||||
resp.put("success", fileResponse != null);
|
||||
if (fileResponse != null) {
|
||||
resp.put("host", "http://cdn.celess.cn/");
|
||||
resp.put("path", qiniuResponse.key);
|
||||
resp.put("path", fileResponse.key);
|
||||
}
|
||||
result.add(resp);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Config;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.mapper.ConfigMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/16 20:56
|
||||
* @desc : 配置管理接口
|
||||
*/
|
||||
@RestController
|
||||
public class ConfigController {
|
||||
@Autowired
|
||||
ConfigMapper configMapper;
|
||||
|
||||
@GetMapping("/admin/config")
|
||||
public Response<List<Config>> getConfiguration() {
|
||||
return Response.success(configMapper.getConfigurations());
|
||||
}
|
||||
|
||||
@PutMapping("/admin/config")
|
||||
public Response<List<Config>> updateConfiguration(@RequestBody List<Config> configs) {
|
||||
configs.forEach(config -> configMapper.updateConfiguration(config));
|
||||
configs.forEach(config -> System.setProperty(config.getName(), config.getValue()));
|
||||
return Response.success(configMapper.getConfigurations());
|
||||
}
|
||||
|
||||
@PostMapping("/admin/config")
|
||||
public Response<List<Config>> addConfiguration(@RequestBody List<Config> configs) {
|
||||
configs.forEach(config -> configMapper.addConfiguration(config));
|
||||
configs.forEach(config -> System.setProperty(config.getName(), config.getValue()));
|
||||
return Response.success(configMapper.getConfigurations());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.BlogApplication;
|
||||
import cn.celess.blog.enmu.ConfigKeyEnum;
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Config;
|
||||
import cn.celess.blog.entity.InstallParam;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.mapper.ConfigMapper;
|
||||
import cn.celess.blog.service.InstallService;
|
||||
import cn.celess.blog.util.RegexUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/18 15:36
|
||||
* @desc :
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@Validated
|
||||
public class InstallController {
|
||||
|
||||
@Autowired
|
||||
InstallService installService;
|
||||
@Autowired
|
||||
ConfigMapper configMapper;
|
||||
|
||||
|
||||
@GetMapping("/is_install")
|
||||
@ResponseBody
|
||||
public Response<Map<String, Object>> isInstall() {
|
||||
Map<String, Object> install = installService.isInstall();
|
||||
return Response.success(install);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/install")
|
||||
@ResponseBody
|
||||
public Response<Object> install(@Valid @RequestBody InstallParam installParam) {
|
||||
if (!RegexUtil.emailMatch(installParam.getEmail())) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||
}
|
||||
if (!RegexUtil.pwdMatch(installParam.getPassword())) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||
}
|
||||
return Response.success(installService.install(installParam));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/default_config")
|
||||
@ResponseBody
|
||||
public Response<String> defaultConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/install")
|
||||
public String install() {
|
||||
Config configuration = configMapper.getConfiguration(ConfigKeyEnum.BLOG_INSTALLED.getKey());
|
||||
if (Boolean.parseBoolean(configuration.getValue())) {
|
||||
return "index.html";
|
||||
}
|
||||
log.info("博客第一次运行,还未安装");
|
||||
return "install.html";
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,69 @@
|
||||
package cn.celess.partnersite.controller;
|
||||
|
||||
|
||||
import cn.celess.common.entity.PartnerSite;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.dto.LinkApplyReq;
|
||||
import cn.celess.common.entity.dto.LinkReq;
|
||||
import cn.celess.common.service.MailService;
|
||||
import cn.celess.common.service.PartnerSiteService;
|
||||
import cn.celess.common.util.RedisUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 13:26
|
||||
*/
|
||||
@RestController
|
||||
public class PartnerSiteController {
|
||||
@Autowired
|
||||
PartnerSiteService partnerSiteService;
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
@PostMapping("/admin/links/create")
|
||||
public Response create(@RequestBody LinkReq reqBody) {
|
||||
return Response.success(partnerSiteService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/links/del/{id}")
|
||||
public Response del(@PathVariable("id") long id) {
|
||||
return Response.success(partnerSiteService.del(id));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/links/update")
|
||||
public Response update(@RequestBody LinkReq reqBody) {
|
||||
return Response.success(partnerSiteService.update(reqBody));
|
||||
}
|
||||
|
||||
@GetMapping("/links")
|
||||
public Response allForOpen() {
|
||||
List<PartnerSite> sites = partnerSiteService.findAll().stream().peek(partnerSite -> partnerSite.setOpen(null)).collect(Collectors.toList());
|
||||
return Response.success(sites);
|
||||
}
|
||||
|
||||
@GetMapping("/admin/links")
|
||||
public Response all(@RequestParam("page") int page,
|
||||
@RequestParam("count") int count,
|
||||
@RequestParam(value = "deleted", required = false) Boolean deleted) {
|
||||
return Response.success(partnerSiteService.partnerSitePages(page, count, deleted));
|
||||
}
|
||||
|
||||
@PostMapping("/apply")
|
||||
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
||||
return Response.success(partnerSiteService.apply(linkApplyReq));
|
||||
}
|
||||
|
||||
@PostMapping("/reapply")
|
||||
public Response reapply(@RequestParam("key") String key) {
|
||||
return Response.success(partnerSiteService.reapply(key));
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.PartnerSite;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||
import cn.celess.blog.entity.request.LinkReq;
|
||||
import cn.celess.blog.service.MailService;
|
||||
import cn.celess.blog.service.PartnerSiteService;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 13:26
|
||||
*/
|
||||
@RestController
|
||||
public class LinksController {
|
||||
@Autowired
|
||||
PartnerSiteService partnerSiteService;
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
@PostMapping("/admin/links/create")
|
||||
public Response create(@RequestBody LinkReq reqBody) {
|
||||
return Response.success(partnerSiteService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/links/del/{id}")
|
||||
public Response del(@PathVariable("id") long id) {
|
||||
return Response.success(partnerSiteService.del(id));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/links/update")
|
||||
public Response update(@RequestBody LinkReq reqBody) {
|
||||
return Response.success(partnerSiteService.update(reqBody));
|
||||
}
|
||||
|
||||
@GetMapping("/links")
|
||||
public Response allForOpen() {
|
||||
List<PartnerSite> sites = partnerSiteService.findAll().stream().peek(partnerSite -> partnerSite.setOpen(null)).collect(Collectors.toList());
|
||||
return Response.success(sites);
|
||||
}
|
||||
|
||||
@GetMapping("/admin/links")
|
||||
public Response all(@RequestParam("page") int page,
|
||||
@RequestParam("count") int count,
|
||||
@RequestParam(value = "deleted", required = false) Boolean deleted) {
|
||||
return Response.success(partnerSiteService.partnerSitePages(page, count, deleted));
|
||||
}
|
||||
|
||||
@PostMapping("/apply")
|
||||
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
||||
return Response.success(partnerSiteService.apply(linkApplyReq));
|
||||
}
|
||||
|
||||
@PostMapping("/reapply")
|
||||
public Response reapply(@RequestParam("key") String key) {
|
||||
return Response.success(partnerSiteService.reapply(key));
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,59 @@
|
||||
package cn.celess.categorytag.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.vo.TagModel;
|
||||
import cn.celess.common.service.TagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class TagController {
|
||||
@Autowired
|
||||
TagService tagService;
|
||||
|
||||
|
||||
@PostMapping("/admin/tag/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(tagService.create(name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/tag/del")
|
||||
public Response delOne(@RequestParam("id") long id) {
|
||||
return Response.success(tagService.delete(id));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/admin/tag/update")
|
||||
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
||||
return Response.success(tagService.update(id, name));
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
||||
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
||||
return Response.success(tagService.retrievePage(page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/tags/nac")
|
||||
public Response getTagNameAndCount() {
|
||||
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||
List<TagModel> all = tagService.findAll();
|
||||
for (TagModel t : all) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("name", t.getName());
|
||||
map.put("size", t.getArticles().size());
|
||||
nameAndCount.add(map);
|
||||
}
|
||||
return Response.success(nameAndCount);
|
||||
}
|
||||
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.TagModel;
|
||||
import cn.celess.blog.service.TagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class TagController {
|
||||
@Autowired
|
||||
TagService tagService;
|
||||
|
||||
|
||||
@PostMapping("/admin/tag/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(tagService.create(name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/tag/del")
|
||||
public Response delOne(@RequestParam("id") long id) {
|
||||
return Response.success(tagService.delete(id));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/admin/tag/update")
|
||||
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
||||
return Response.success(tagService.update(id, name));
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
||||
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
||||
return Response.success(tagService.retrievePage(page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/tags/nac")
|
||||
public Response getTagNameAndCount() {
|
||||
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||
List<TagModel> all = tagService.findAll();
|
||||
for (TagModel t : all) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("name", t.getName());
|
||||
map.put("size", t.getArticles().size());
|
||||
nameAndCount.add(map);
|
||||
}
|
||||
return Response.success(nameAndCount);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,129 +1,129 @@
|
||||
package cn.celess.user.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.dto.LoginReq;
|
||||
import cn.celess.common.entity.dto.UserReq;
|
||||
import cn.celess.common.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
public Response login(@RequestBody LoginReq loginReq) {
|
||||
return Response.success(userService.login(loginReq));
|
||||
}
|
||||
|
||||
@PostMapping("/registration")
|
||||
public Response registration(@RequestParam("email") String email,
|
||||
@RequestParam("password") String password) {
|
||||
return Response.success(userService.registration(email, password));
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public Response logout() {
|
||||
return Response.success(userService.logout());
|
||||
}
|
||||
|
||||
@PutMapping("/user/userInfo/update")
|
||||
public Response updateInfo(String desc, String displayName) {
|
||||
return Response.success(userService.update(desc, displayName));
|
||||
}
|
||||
|
||||
@GetMapping("/user/userInfo")
|
||||
public Response getUserInfo() {
|
||||
return Response.success(userService.getUserInfoBySession());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新头像
|
||||
*
|
||||
* @param file file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/user/imgUpload")
|
||||
@ResponseBody
|
||||
public Response upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
return Response.failure("上传失败,请选择文件");
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||
if (".png".equalsIgnoreCase(mime) || ".jpg".equalsIgnoreCase(mime) ||
|
||||
".jpeg".equalsIgnoreCase(mime) || ".bmp".equalsIgnoreCase(mime)) {
|
||||
return (Response) userService.updateUserAavatarImg(file.getInputStream(), mime);
|
||||
}
|
||||
return Response.failure("请上传图片文件");
|
||||
}
|
||||
|
||||
@PostMapping("/sendResetPwdEmail")
|
||||
public Response sendResetPwdEmail(@RequestParam("email") String email) {
|
||||
return Response.success(userService.sendResetPwdEmail(email));
|
||||
}
|
||||
|
||||
@PostMapping("/sendVerifyEmail")
|
||||
public Response sendVerifyEmail(@RequestParam("email") String email) {
|
||||
return Response.success(userService.sendVerifyEmail(email));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/emailVerify")
|
||||
public Response emailVerify(@RequestParam("verifyId") String verifyId,
|
||||
@RequestParam("email") String mail) {
|
||||
return Response.success(userService.verifyEmail(verifyId, mail));
|
||||
}
|
||||
|
||||
@PostMapping("/resetPwd")
|
||||
public Response resetPwd(@RequestParam("verifyId") String verifyId,
|
||||
@RequestParam("email") String email,
|
||||
@RequestParam("pwd") String pwd) {
|
||||
return Response.success(userService.reSetPwd(verifyId, email, pwd));
|
||||
}
|
||||
|
||||
@PostMapping("/user/setPwd")
|
||||
public Response setPwd(@RequestParam("pwd") String pwd,
|
||||
@RequestParam("newPwd") String newPwd,
|
||||
@RequestParam("confirmPwd") String confirmPwd) {
|
||||
return Response.success(userService.setPwd(pwd, newPwd, confirmPwd));
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/admin/user/delete")
|
||||
public Response multipleDelete(@RequestBody Integer[] ids) {
|
||||
return Response.success(userService.deleteUser(ids));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/user/delete/{id}")
|
||||
public Response delete(@PathVariable("id") Integer id) {
|
||||
return Response.success(userService.deleteUser(new Integer[]{id}));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/user")
|
||||
public Response updateInfoByAdmin(@RequestBody UserReq user) {
|
||||
return Response.success(userService.adminUpdate(user));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/users")
|
||||
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count, @RequestParam(name = "status", required = false) Integer status) {
|
||||
return Response.success(userService.getUserList(pageNum, count, status));
|
||||
}
|
||||
|
||||
@GetMapping("/emailStatus/{email}")
|
||||
public Response getEmailStatus(@PathVariable("email") String email) {
|
||||
return Response.success(userService.getStatusOfEmail(email));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.LoginReq;
|
||||
import cn.celess.blog.entity.request.UserReq;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
public Response login(@RequestBody LoginReq loginReq) {
|
||||
return Response.success(userService.login(loginReq));
|
||||
}
|
||||
|
||||
@PostMapping("/registration")
|
||||
public Response registration(@RequestParam("email") String email,
|
||||
@RequestParam("password") String password) {
|
||||
return Response.success(userService.registration(email, password));
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public Response logout() {
|
||||
return Response.success(userService.logout());
|
||||
}
|
||||
|
||||
@PutMapping("/user/userInfo/update")
|
||||
public Response updateInfo(String desc, String displayName) {
|
||||
return Response.success(userService.update(desc, displayName));
|
||||
}
|
||||
|
||||
@GetMapping("/user/userInfo")
|
||||
public Response getUserInfo() {
|
||||
return Response.success(userService.getUserInfoBySession());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新头像
|
||||
*
|
||||
* @param file file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/user/imgUpload")
|
||||
@ResponseBody
|
||||
public Response upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
return Response.failure("上传失败,请选择文件");
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||
return (Response) userService.updateUserAavatarImg(file.getInputStream(), mime);
|
||||
}
|
||||
return Response.failure("请上传图片文件");
|
||||
}
|
||||
|
||||
@PostMapping("/sendResetPwdEmail")
|
||||
public Response sendResetPwdEmail(@RequestParam("email") String email) {
|
||||
return Response.success(userService.sendResetPwdEmail(email));
|
||||
}
|
||||
|
||||
@PostMapping("/sendVerifyEmail")
|
||||
public Response sendVerifyEmail(@RequestParam("email") String email) {
|
||||
return Response.success(userService.sendVerifyEmail(email));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/emailVerify")
|
||||
public Response emailVerify(@RequestParam("verifyId") String verifyId,
|
||||
@RequestParam("email") String mail) {
|
||||
return Response.success(userService.verifyEmail(verifyId, mail));
|
||||
}
|
||||
|
||||
@PostMapping("/resetPwd")
|
||||
public Response resetPwd(@RequestParam("verifyId") String verifyId,
|
||||
@RequestParam("email") String email,
|
||||
@RequestParam("pwd") String pwd) {
|
||||
return Response.success(userService.reSetPwd(verifyId, email, pwd));
|
||||
}
|
||||
|
||||
@PostMapping("/user/setPwd")
|
||||
public Response setPwd(@RequestParam("pwd") String pwd,
|
||||
@RequestParam("newPwd") String newPwd,
|
||||
@RequestParam("confirmPwd") String confirmPwd) {
|
||||
return Response.success(userService.setPwd(pwd, newPwd, confirmPwd));
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/admin/user/delete")
|
||||
public Response multipleDelete(@RequestBody Integer[] ids) {
|
||||
return Response.success(userService.deleteUser(ids));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/user/delete/{id}")
|
||||
public Response delete(@PathVariable("id") Integer id) {
|
||||
return Response.success(userService.deleteUser(new Integer[]{id}));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/user")
|
||||
public Response updateInfoByAdmin(@RequestBody UserReq user) {
|
||||
return Response.success(userService.adminUpdate(user));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/users")
|
||||
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count, @RequestParam(name = "status", required = false) Integer status) {
|
||||
return Response.success(userService.getUserList(pageNum, count, status));
|
||||
}
|
||||
|
||||
@GetMapping("/emailStatus/{email}")
|
||||
public Response getEmailStatus(@PathVariable("email") String email) {
|
||||
return Response.success(userService.getStatusOfEmail(email));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,59 +1,59 @@
|
||||
package cn.celess.visitor.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.service.CountService;
|
||||
import cn.celess.common.service.VisitorService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 23:09
|
||||
*/
|
||||
@RestController
|
||||
public class VisitorController {
|
||||
@Autowired
|
||||
VisitorService visitorService;
|
||||
@Autowired
|
||||
CountService countService;
|
||||
|
||||
@GetMapping("/visitor/count")
|
||||
public Response getVisitorCount() {
|
||||
return Response.success(countService.getVisitorCount());
|
||||
}
|
||||
|
||||
@GetMapping("/admin/visitor/page")
|
||||
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
||||
@RequestParam(value = "showLocation", required = false, defaultValue = "true") boolean showLocation) {
|
||||
return Response.success(visitorService.visitorPage(page, count, showLocation));
|
||||
}
|
||||
|
||||
@PostMapping("/visit")
|
||||
public Response add(HttpServletRequest request) {
|
||||
return Response.success(visitorService.addVisitor(request));
|
||||
}
|
||||
|
||||
@GetMapping("/dayVisitCount")
|
||||
public Response dayVisitCount() {
|
||||
return Response.success(countService.getDayVisitCount());
|
||||
}
|
||||
|
||||
@GetMapping("/ip/{ip}")
|
||||
public Response ipLocation(@PathVariable("ip") String ip) {
|
||||
return Response.success(visitorService.location(ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地访问者的ip
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/ip")
|
||||
public Response getIp(HttpServletRequest request) {
|
||||
return Response.success(request.getRemoteAddr());
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.CountService;
|
||||
import cn.celess.blog.service.VisitorService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 23:09
|
||||
*/
|
||||
@RestController
|
||||
public class VisitorController {
|
||||
@Autowired
|
||||
VisitorService visitorService;
|
||||
@Autowired
|
||||
CountService countService;
|
||||
|
||||
@GetMapping("/visitor/count")
|
||||
public Response getVisitorCount() {
|
||||
return Response.success(countService.getVisitorCount());
|
||||
}
|
||||
|
||||
@GetMapping("/admin/visitor/page")
|
||||
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
||||
@RequestParam(value = "showLocation", required = false, defaultValue = "true") boolean showLocation) {
|
||||
return Response.success(visitorService.visitorPage(page, count, showLocation));
|
||||
}
|
||||
|
||||
@PostMapping("/visit")
|
||||
public Response add(HttpServletRequest request) {
|
||||
return Response.success(visitorService.addVisitor(request));
|
||||
}
|
||||
|
||||
@GetMapping("/dayVisitCount")
|
||||
public Response dayVisitCount() {
|
||||
return Response.success(countService.getDayVisitCount());
|
||||
}
|
||||
|
||||
@GetMapping("/ip/{ip}")
|
||||
public Response ipLocation(@PathVariable("ip") String ip) {
|
||||
return Response.success(visitorService.location(ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地访问者的ip
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/ip")
|
||||
public Response getIp(HttpServletRequest request) {
|
||||
return Response.success(request.getRemoteAddr());
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,48 @@
|
||||
package cn.celess.siteinfo.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.service.WebUpdateInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 13:09
|
||||
*/
|
||||
@RestController
|
||||
public class WebUpdateInfoController {
|
||||
@Autowired
|
||||
WebUpdateInfoService webUpdateInfoService;
|
||||
|
||||
@PostMapping("/admin/webUpdate/create")
|
||||
public Response create(@RequestParam("info") String info) {
|
||||
return Response.success(webUpdateInfoService.create(info));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/webUpdate/del/{id}")
|
||||
public Response del(@PathVariable("id") long id) {
|
||||
return Response.success(webUpdateInfoService.del(id));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/webUpdate/update")
|
||||
public Response update(@RequestParam("id") long id, @RequestParam("info") String info) {
|
||||
return Response.success(webUpdateInfoService.update(id, info));
|
||||
}
|
||||
|
||||
@GetMapping("/webUpdate")
|
||||
public Response findAll() {
|
||||
return Response.success(webUpdateInfoService.findAll());
|
||||
}
|
||||
|
||||
@GetMapping("/webUpdate/pages")
|
||||
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
||||
return Response.success(webUpdateInfoService.pages(count, page));
|
||||
}
|
||||
|
||||
@GetMapping("/lastestUpdate")
|
||||
public Response lastestUpdateTime() {
|
||||
return Response.success(webUpdateInfoService.getLastestUpdateTime());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.WebUpdateInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 13:09
|
||||
*/
|
||||
@RestController
|
||||
public class WebUpdateInfoController {
|
||||
@Autowired
|
||||
WebUpdateInfoService webUpdateInfoService;
|
||||
|
||||
@PostMapping("/admin/webUpdate/create")
|
||||
public Response create(@RequestParam("info") String info) {
|
||||
return Response.success(webUpdateInfoService.create(info));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/webUpdate/del/{id}")
|
||||
public Response del(@PathVariable("id") long id) {
|
||||
return Response.success(webUpdateInfoService.del(id));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/webUpdate/update")
|
||||
public Response update(@RequestParam("id") long id, @RequestParam("info") String info) {
|
||||
return Response.success(webUpdateInfoService.update(id, info));
|
||||
}
|
||||
|
||||
@GetMapping("/webUpdate")
|
||||
public Response findAll() {
|
||||
return Response.success(webUpdateInfoService.findAll());
|
||||
}
|
||||
|
||||
@GetMapping("/webUpdate/pages")
|
||||
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
||||
return Response.success(webUpdateInfoService.pages(count, page));
|
||||
}
|
||||
|
||||
@GetMapping("/lastestUpdate")
|
||||
public Response lastestUpdateTime() {
|
||||
return Response.success(webUpdateInfoService.getLastestUpdateTime());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.common.constant;
|
||||
package cn.celess.blog.enmu;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
37
src/main/java/cn/celess/blog/enmu/ConfigKeyEnum.java
Normal file
37
src/main/java/cn/celess/blog/enmu/ConfigKeyEnum.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package cn.celess.blog.enmu;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/16 16:41
|
||||
* @desc :
|
||||
*/
|
||||
public enum ConfigKeyEnum {
|
||||
|
||||
/**
|
||||
* 枚举
|
||||
*/
|
||||
FILE_TYPE("file.type"),
|
||||
FILE_QINIU_ACCESS_KEY("file.qiniu.accessKey"),
|
||||
FILE_QINIU_SECRET_KEY("file.qiniu.secretKey"),
|
||||
FILE_QINIU_BUCKET("file.qiniu.bucket"),
|
||||
FILE_LOCAL_DIRECTORY_PATH("file.local.directoryPath"),
|
||||
BLOG_FILE_PATH("blog.file.path"),
|
||||
BLOG_INSTALLED("blog.installed"),
|
||||
DB_TYPE("db.type"),
|
||||
DB_URL("spring.datasource.url"),
|
||||
DB_USERNAME("spring.datasource.username"),
|
||||
DB_PASSWORD("spring.datasource.password"),
|
||||
DB_DRIVER_CLASS_NAME("spring.datasource.driver-class-name"),
|
||||
BLOG_DB_PATH("blog.db.path");
|
||||
|
||||
|
||||
private final String key;
|
||||
|
||||
ConfigKeyEnum(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +1,96 @@
|
||||
package cn.celess.common.constant;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:37
|
||||
*/
|
||||
public enum ResponseEnum {
|
||||
// Response enum
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
FAILURE(-1, "失败"),
|
||||
ERROR(-2, "错误"),
|
||||
|
||||
DATA_IS_DELETED(1000, "数据已被删除"),
|
||||
|
||||
//文章类
|
||||
ARTICLE_NOT_EXIST(2010, "文章不存在"),
|
||||
ARTICLE_HAS_EXIST(2020, "文章已存在"),
|
||||
ARTICLE_NOT_PUBLIC(2030, "文章暂未公开"),
|
||||
ARTICLE_NOT_BELONG_YOU(2040, "无权限操作别人的文章"),
|
||||
|
||||
//用户类
|
||||
HAVE_NOT_LOG_IN(3010, "还未登录"),
|
||||
PERMISSION_ERROR(3020, "没有此权限"),
|
||||
USER_NOT_EXIST(3030, "用户不存在"),
|
||||
USERNAME_HAS_EXIST(3040, "用户名已存在"),
|
||||
USERNAME_TOO_SHORT(3050, "用户名太短"),
|
||||
PASSWORD_TOO_SHORT_OR_LONG(3060, "密码长度过长或者过短"),
|
||||
LOGIN_FAILURE(3100, "登录失败,用户名/密码不正确"),
|
||||
USEREMAIL_NULL(3310, "未设置邮箱"),
|
||||
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
||||
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
||||
PWD_SAME(3601, "新密码与原密码相同"),
|
||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||
LOGOUT(3710, "账户已注销"),
|
||||
CAN_NOT_USE(3711, "账户不可用"),
|
||||
PWD_WRONG(3800, "密码不正确"),
|
||||
|
||||
JWT_EXPIRED(3810, "Token过期"),
|
||||
JWT_MALFORMED(3820, "Token格式不对"),
|
||||
JWT_SIGNATURE(3830, "Token签名错误"),
|
||||
JWT_NOT_SUPPORT(3840, "不支持的Token"),
|
||||
|
||||
//标签
|
||||
TAG_NOT_EXIST(4010, "标签不存在"),
|
||||
TAG_HAS_EXIST(4020, "标签已存在"),
|
||||
|
||||
//分类
|
||||
CATEGORY_NOT_EXIST(5010, "分类不存在"),
|
||||
CATEGORY_HAS_EXIST(5020, "分类已存在"),
|
||||
|
||||
//评论/留言
|
||||
COMMENT_NOT_EXIST(6010, "评论/留言不存在"),
|
||||
COMMENT_HAS_EXIST(6020, "评论/留言已存在,请不要重复提交"),
|
||||
|
||||
//webUdpateInfo amd PartnerSite
|
||||
DATA_NOT_EXIST(7010, "数据不存在"),
|
||||
DATA_HAS_EXIST(7020, "数据已存在"),
|
||||
|
||||
//其他
|
||||
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
||||
DATA_EXPIRED(7300, "数据过期"),
|
||||
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
|
||||
NO_FILE(7500, "未选择文件,请重新选择"),
|
||||
|
||||
|
||||
//提交更新之前,没有获取数据/,
|
||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||
IMG_CODE_TIMEOUT(8100, "验证码已失效"),
|
||||
IMG_CODE_DIDNOTVERIFY(8200, "请先验证验证码"),
|
||||
VERIFY_ERROR(8300, "验证失败"),
|
||||
PARAMETERS_ERROR(8500, "参数错误"),
|
||||
PARAMETERS_URL_ERROR(8510, "链接格式错误"),
|
||||
PARAMETERS_EMAIL_ERROR(8520, "邮箱格式错误"),
|
||||
PARAMETERS_PHONE_ERROR(8530, "手机格式错误"),
|
||||
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
|
||||
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
|
||||
VERIFY_OUT(8400, "已经验证过了");
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
|
||||
ResponseEnum(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.enmu;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:37
|
||||
*/
|
||||
public enum ResponseEnum {
|
||||
// Response enum
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
FAILURE(-1, "失败"),
|
||||
ERROR(-2, "错误"),
|
||||
|
||||
DATA_IS_DELETED(1000, "数据已被删除"),
|
||||
|
||||
//文章类
|
||||
ARTICLE_NOT_EXIST(2010, "文章不存在"),
|
||||
ARTICLE_HAS_EXIST(2020, "文章已存在"),
|
||||
ARTICLE_NOT_PUBLIC(2030, "文章暂未公开"),
|
||||
ARTICLE_NOT_BELONG_YOU(2040, "无权限操作别人的文章"),
|
||||
|
||||
//用户类
|
||||
HAVE_NOT_LOG_IN(3010, "还未登录"),
|
||||
PERMISSION_ERROR(3020, "没有此权限"),
|
||||
USER_NOT_EXIST(3030, "用户不存在"),
|
||||
USERNAME_HAS_EXIST(3040, "用户名已存在"),
|
||||
USERNAME_TOO_SHORT(3050, "用户名太短"),
|
||||
PASSWORD_TOO_SHORT_OR_LONG(3060, "密码长度过长或者过短"),
|
||||
LOGIN_FAILURE(3100, "登录失败,用户名/密码不正确"),
|
||||
USEREMAIL_NULL(3310, "未设置邮箱"),
|
||||
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
||||
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
||||
PWD_SAME(3601, "新密码与原密码相同"),
|
||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||
LOGOUT(3710, "账户已注销"),
|
||||
CAN_NOT_USE(3711, "账户不可用"),
|
||||
PWD_WRONG(3800, "密码不正确"),
|
||||
|
||||
JWT_EXPIRED(3810, "Token过期"),
|
||||
JWT_MALFORMED(3820, "Token格式不对"),
|
||||
JWT_SIGNATURE(3830, "Token签名错误"),
|
||||
JWT_NOT_SUPPORT(3840, "不支持的Token"),
|
||||
|
||||
//标签
|
||||
TAG_NOT_EXIST(4010, "标签不存在"),
|
||||
TAG_HAS_EXIST(4020, "标签已存在"),
|
||||
|
||||
//分类
|
||||
CATEGORY_NOT_EXIST(5010, "分类不存在"),
|
||||
CATEGORY_HAS_EXIST(5020, "分类已存在"),
|
||||
|
||||
//评论/留言
|
||||
COMMENT_NOT_EXIST(6010, "评论/留言不存在"),
|
||||
COMMENT_HAS_EXIST(6020, "评论/留言已存在,请不要重复提交"),
|
||||
|
||||
//webUdpateInfo amd PartnerSite
|
||||
DATA_NOT_EXIST(7010, "数据不存在"),
|
||||
DATA_HAS_EXIST(7020, "数据已存在"),
|
||||
|
||||
//其他
|
||||
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
||||
DATA_EXPIRED(7300, "数据过期"),
|
||||
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
|
||||
NO_FILE(7500, "未选择文件,请重新选择"),
|
||||
|
||||
|
||||
//提交更新之前,没有获取数据/,
|
||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||
IMG_CODE_TIMEOUT(8100, "验证码已失效"),
|
||||
IMG_CODE_DIDNOTVERIFY(8200, "请先验证验证码"),
|
||||
VERIFY_ERROR(8300, "验证失败"),
|
||||
PARAMETERS_ERROR(8500, "参数错误"),
|
||||
PARAMETERS_URL_ERROR(8510, "链接格式错误"),
|
||||
PARAMETERS_EMAIL_ERROR(8520, "邮箱格式错误"),
|
||||
PARAMETERS_PHONE_ERROR(8530, "手机格式错误"),
|
||||
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
|
||||
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
|
||||
VERIFY_OUT(8400, "已经验证过了");
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
|
||||
ResponseEnum(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.common.constant;
|
||||
package cn.celess.blog.enmu;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.common.constant;
|
||||
package cn.celess.blog.enmu;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
@@ -1,64 +1,63 @@
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Article implements Serializable {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* Markdown正文
|
||||
*/
|
||||
private String mdContent;
|
||||
|
||||
/**
|
||||
* 文章类型 true(1)为原创 false(0)为转载
|
||||
*/
|
||||
private Boolean type;
|
||||
|
||||
/**
|
||||
* 若为转载 则为转载文章的url
|
||||
*/
|
||||
private String url = null;
|
||||
|
||||
private Date publishDate;
|
||||
|
||||
private Date updateDate = null;
|
||||
|
||||
private Long readingNumber;
|
||||
|
||||
/**
|
||||
* 文章的状态 true:公开 false:不公开
|
||||
*/
|
||||
private Boolean open;
|
||||
|
||||
private Category category;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Integer dislikeCount;
|
||||
|
||||
private User user;
|
||||
|
||||
private boolean deleted = false;
|
||||
}
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Article {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* Markdown正文
|
||||
*/
|
||||
private String mdContent;
|
||||
|
||||
/**
|
||||
* 文章类型 true(1)为原创 false(0)为转载
|
||||
*/
|
||||
private Boolean type;
|
||||
|
||||
/**
|
||||
* 若为转载 则为转载文章的url
|
||||
*/
|
||||
private String url = null;
|
||||
|
||||
private Date publishDate;
|
||||
|
||||
private Date updateDate = null;
|
||||
|
||||
private Long readingNumber;
|
||||
|
||||
/**
|
||||
* 文章的状态 true:公开 false:不公开
|
||||
*/
|
||||
private Boolean open;
|
||||
|
||||
private Category category;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Integer dislikeCount;
|
||||
|
||||
private User user;
|
||||
|
||||
private boolean deleted = false;
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package cn.celess.common.entity;
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2020-05-24 14:52
|
||||
@@ -14,7 +12,7 @@ import java.io.Serializable;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ArticleTag implements Serializable {
|
||||
public class ArticleTag {
|
||||
private Long id;
|
||||
|
||||
private Article article;
|
||||
@@ -1,15 +1,13 @@
|
||||
package cn.celess.common.entity;
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:18
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class Category extends TagCategory implements Serializable {
|
||||
public class Category extends TagCategory {
|
||||
public Category(String name) {
|
||||
super.setName(name);
|
||||
}
|
||||
@@ -1,35 +1,34 @@
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 16:47
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Comment implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private int status;
|
||||
|
||||
private String pagePath;
|
||||
|
||||
private String content;
|
||||
|
||||
private Date date;
|
||||
|
||||
private User fromUser;
|
||||
|
||||
private User toUser;
|
||||
/**
|
||||
* 评论的父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
// private boolean delete;
|
||||
}
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 16:47
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Comment {
|
||||
|
||||
private Long id;
|
||||
|
||||
private int status;
|
||||
|
||||
private String pagePath;
|
||||
|
||||
private String content;
|
||||
|
||||
private Date date;
|
||||
|
||||
private User fromUser;
|
||||
|
||||
private User toUser;
|
||||
/**
|
||||
* 评论的父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
// private boolean delete;
|
||||
}
|
||||
26
src/main/java/cn/celess/blog/entity/Config.java
Normal file
26
src/main/java/cn/celess/blog/entity/Config.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import cn.celess.blog.enmu.ConfigKeyEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/16 15:24
|
||||
* @desc :
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class Config {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public Config(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Config(ConfigKeyEnum e) {
|
||||
this.name = e.getKey();
|
||||
}
|
||||
}
|
||||
38
src/main/java/cn/celess/blog/entity/InstallParam.java
Normal file
38
src/main/java/cn/celess/blog/entity/InstallParam.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/18 14:52
|
||||
* @desc :
|
||||
*/
|
||||
@Data
|
||||
public class InstallParam {
|
||||
@NotBlank(message = "数据库类型不可为空")
|
||||
private String dbType;
|
||||
|
||||
@NotBlank(message = "数据库主机不可为空")
|
||||
private String dbHost;
|
||||
|
||||
@NotBlank(message = "数据库名称不可为空")
|
||||
private String dbName;
|
||||
|
||||
@NotBlank(message = "数据库用户名不可为空")
|
||||
private String dbUsername;
|
||||
|
||||
@NotBlank(message = "数据库密码不可为空")
|
||||
private String dbPassword;
|
||||
|
||||
|
||||
/**
|
||||
* user 相关
|
||||
*/
|
||||
@NotBlank(message = "用户邮箱地址不可为空")
|
||||
private String email;
|
||||
|
||||
@NotBlank(message = "用户密码不可为空")
|
||||
private String password;
|
||||
}
|
||||
@@ -1,42 +1,40 @@
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 友链
|
||||
*
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:33
|
||||
*/
|
||||
@Data
|
||||
public class PartnerSite implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
private Boolean open;
|
||||
|
||||
private String iconPath;
|
||||
|
||||
private String desc;
|
||||
|
||||
private Boolean delete = false;
|
||||
|
||||
private String email;
|
||||
|
||||
private Boolean notification = true;
|
||||
|
||||
public PartnerSite() {
|
||||
}
|
||||
|
||||
public PartnerSite(String name, String url, Boolean open) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.open = open;
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 友链
|
||||
*
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:33
|
||||
*/
|
||||
@Data
|
||||
public class PartnerSite {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
private Boolean open;
|
||||
|
||||
private String iconPath;
|
||||
|
||||
private String desc;
|
||||
|
||||
private Boolean delete = false;
|
||||
|
||||
private String email;
|
||||
|
||||
private Boolean notification = true;
|
||||
|
||||
public PartnerSite() {
|
||||
}
|
||||
|
||||
public PartnerSite(String name, String url, Boolean open) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.open = open;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,65 @@
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import cn.celess.common.constant.ResponseEnum;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:24
|
||||
*/
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
private int code;
|
||||
private String msg;
|
||||
private T result;
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
public Response(int code, String msg, T result) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功相应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> success(T result) {
|
||||
return new Response<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败的响应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static Response<String> failure(String result) {
|
||||
return new Response<String>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他的响应
|
||||
*
|
||||
* @param r 枚举常量
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> response(ResponseEnum r, T result) {
|
||||
return new Response<T>(r.getCode(), r.getMsg(), result);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ObjectMapper().writeValueAsString(this);
|
||||
}
|
||||
}
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:24
|
||||
*/
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
private int code;
|
||||
private String msg;
|
||||
private T result;
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
public Response(int code, String msg, T result) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功相应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> success(T result) {
|
||||
return new Response<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败的响应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static Response<String> failure(String result) {
|
||||
return new Response<String>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他的响应
|
||||
*
|
||||
* @param r 枚举常量
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> response(ResponseEnum r, T result) {
|
||||
return new Response<T>(r.getCode(), r.getMsg(), result);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ObjectMapper().writeValueAsString(this);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package cn.celess.common.entity;
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:19
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class Tag extends TagCategory implements Serializable {
|
||||
public class Tag extends TagCategory {
|
||||
|
||||
public Tag(String name) {
|
||||
super.setName(name);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user