Compare commits
279 Commits
v1.2
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14c9a95a61 | ||
|
|
2d649b0373 | ||
|
|
4ed8939945 | ||
|
|
2c287b5c08 | ||
|
|
d07b1f9b96 | ||
|
|
4879a4bb79 | ||
|
|
027b81c006 | ||
|
|
1c976f1310 | ||
|
|
a544e1bd54 | ||
|
|
5a00e6c62f | ||
|
|
07e84ab875 | ||
|
|
a6c91fc3f1 | ||
|
|
fb88f90b70 | ||
|
|
692ce19320 | ||
|
|
5c7e3344c9 | ||
|
|
6ac9c69ff9 | ||
|
|
c6a5de6335 | ||
|
|
ab13a1713f | ||
|
|
f8ee1da333 | ||
|
|
366ce4b829 | ||
|
|
fa120a6da5 | ||
|
|
ef2f98e45f | ||
|
|
7e700b6499 | ||
|
|
c1c7f38ee9 | ||
|
|
fd509e0042 | ||
|
|
330d4d525a | ||
|
|
8c18abf120 | ||
|
|
113a054bea | ||
|
|
6d3739517a | ||
|
|
c8e93c45c7 | ||
|
|
32de31a21e | ||
|
|
cc20df91e6 | ||
|
|
71d79ed008 | ||
|
|
f7ff494ea4 | ||
|
|
971f48c5f9 | ||
|
|
e1522a8cc1 | ||
|
|
3cc4989960 | ||
|
|
8c751e6e76 | ||
|
|
af47631126 | ||
|
|
2107a1c100 | ||
|
|
2eac16dbe4 | ||
|
|
d248e15cea | ||
|
|
91a818d293 | ||
|
|
65c31e96b4 | ||
|
|
81b4851e42 | ||
|
|
9c580cf6d9 | ||
|
|
9eea5b3db9 | ||
|
|
eacb2e29f3 | ||
|
|
fafee4f918 | ||
|
|
30a4c11366 | ||
|
|
5632d47674 | ||
|
|
15b5d89554 | ||
|
|
79426dbe24 | ||
|
|
b3b19dbc45 | ||
|
|
87ec6d24ca | ||
|
|
0148c5e3f5 | ||
|
|
7cff3b9c08 | ||
|
|
a354f48edf | ||
|
|
2cd2dc93d7 | ||
|
|
d5fbc0fbf1 | ||
|
|
b29362eb8c | ||
|
|
d7c6cca683 | ||
|
|
8020eaeff3 | ||
|
|
aedcaf207b | ||
|
|
af9bf9ef46 | ||
|
|
b38ce4c8ce | ||
|
|
3d3548b984 | ||
|
|
4be9eda566 | ||
|
|
e5711746fb | ||
|
|
cc9cf8b1e8 | ||
|
|
ff076f8366 | ||
|
|
dd9ae0b3f9 | ||
|
|
0e7d5f2d23 | ||
|
|
1de1af2a54 | ||
|
|
857a3d9473 | ||
|
|
78efa62476 | ||
|
|
674812c5c6 | ||
|
|
14ce46c312 | ||
|
|
5f5fbadfd8 | ||
|
|
c153d9a0e3 | ||
|
|
18d35809f5 | ||
|
|
75e2424f75 | ||
|
|
b6c4251198 | ||
|
|
fc1bfa0e4f | ||
|
|
e37de0e177 | ||
|
|
082662af66 | ||
|
|
0c0e2404d0 | ||
|
|
71f82bfe32 | ||
|
|
61ce2fddad | ||
|
|
a245f259f7 | ||
|
|
aa22369b13 | ||
|
|
8c3866afe6 | ||
|
|
2c85c3eaac | ||
|
|
2559937e02 | ||
|
|
8de4be602e | ||
|
|
1f88995884 | ||
|
|
c879fbff5f | ||
|
|
f6020bf8d0 | ||
|
|
418b1d78e5 | ||
|
|
98ed489bb1 | ||
|
|
cfdd818829 | ||
|
|
3afbef009f | ||
|
|
8f4d1cd6c8 | ||
|
|
0ba7e06695 | ||
|
|
512d04f3e9 | ||
|
|
ada8f67171 | ||
|
|
6e12331e61 | ||
|
|
81ee71adf1 | ||
|
|
7e7332694e | ||
|
|
8db690a55f | ||
|
|
0b40522e93 | ||
|
|
9026ba0732 | ||
|
|
f5f2437fa4 | ||
|
|
0bcca091e1 | ||
|
|
3c69baa4ad | ||
|
|
baf5b1bbb7 | ||
|
|
38621bcfa4 | ||
|
|
cf435a588f | ||
|
|
feab26f4f7 | ||
|
|
578dbe6cc5 | ||
|
|
f3b03f4853 | ||
|
|
ee85b1f175 | ||
|
|
925e816f7a | ||
|
|
a59bb7f231 | ||
|
|
7f17c20e01 | ||
|
|
6eabb3ab22 | ||
|
|
72674f4612 | ||
|
|
9b460ff33c | ||
|
|
a26946a583 | ||
|
|
01407aba7e | ||
|
|
a54e04abf3 | ||
|
|
450b4a40bd | ||
|
|
9f883d12df | ||
|
|
c17b56b436 | ||
|
|
b55a50d548 | ||
|
|
4c9b193857 | ||
|
|
18a8c916c3 | ||
|
|
99f2907621 | ||
|
|
939b06d0a9 | ||
|
|
a7f947a017 | ||
|
|
40e1f4d6ab | ||
|
|
6b77655c16 | ||
|
|
7ff44fd73e | ||
|
|
c9f91bf2c1 | ||
|
|
03fcddb971 | ||
|
|
dc851e84a4 | ||
|
|
b34acee733 | ||
|
|
d46dada23a | ||
|
|
47e5030f52 | ||
|
|
94c9fc1c46 | ||
|
|
bdcfaef5f8 | ||
|
|
3b6439c5cf | ||
|
|
938a051487 | ||
|
|
a04b51a82e | ||
|
|
ee4c4bd87e | ||
|
|
e70ad72523 | ||
|
|
c466ddddea | ||
|
|
7257f23ef6 | ||
|
|
7c96151830 | ||
|
|
5a47803611 | ||
|
|
af9f243a83 | ||
|
|
3c8abc895a | ||
|
|
9ffa293d24 | ||
|
|
d13ab4e522 | ||
|
|
2fce2d8a1c | ||
|
|
6eb7d01875 | ||
|
|
aa751dbba1 | ||
|
|
14ff60ecfc | ||
|
|
5dae647885 | ||
|
|
bf2abd6072 | ||
|
|
a62b395a8a | ||
|
|
5059859ae4 | ||
|
|
ecdbf8e21c | ||
|
|
c69eee7027 | ||
|
|
8e8a7c809d | ||
|
|
c6a97e4c5b | ||
|
|
d50cd93e55 | ||
|
|
e32600d892 | ||
|
|
d473b5931b | ||
|
|
ab6f9d894d | ||
|
|
49ee7c73e2 | ||
|
|
4a65df2a7d | ||
|
|
b6c6cda4ae | ||
|
|
a9efb1c04d | ||
|
|
4ac430445d | ||
|
|
7ac3d69da4 | ||
|
|
657a200d81 | ||
|
|
85c3541445 | ||
|
|
c6877c2b4a | ||
|
|
9e98134003 | ||
|
|
7a81d8e4ce | ||
|
|
1b52e27b72 | ||
|
|
cd9d9ff0e6 | ||
|
|
dcf44cefb6 | ||
|
|
d83e4de9a3 | ||
|
|
9c949576aa | ||
|
|
85b24891be | ||
|
|
da95470993 | ||
|
|
3b368c92cb | ||
|
|
ad5271f740 | ||
|
|
d2cf640133 | ||
|
|
4a2abc47cc | ||
|
|
6b29cd39d4 | ||
|
|
69da168fc1 | ||
|
|
f375def613 | ||
|
|
d6cede718b | ||
|
|
7922ea558f | ||
|
|
f65c96fa2d | ||
|
|
af43657b5b | ||
|
|
1bfd2d713e | ||
|
|
ffed0d5cd0 | ||
|
|
b9094c1345 | ||
|
|
e9209d1852 | ||
|
|
9900605e1a | ||
|
|
883a78e872 | ||
|
|
c7016dcf5f | ||
|
|
526b73b4f8 | ||
|
|
66b2b26b15 | ||
|
|
f1d3a79919 | ||
|
|
003f74f5f1 | ||
|
|
2f6253c175 | ||
|
|
aa3ee5db72 | ||
|
|
d340ba8218 | ||
|
|
7be1c9dfb0 | ||
|
|
b7f26cbfdb | ||
|
|
d9db98849a | ||
|
|
6c3645ba15 | ||
|
|
43a5e2ab2f | ||
|
|
739256424f | ||
|
|
3c839ad8ca | ||
|
|
efbd5b3d72 | ||
|
|
5ba7e684fa | ||
|
|
f7c1726d51 | ||
|
|
5504abe3e0 | ||
|
|
5aeec0cfe4 | ||
|
|
e2fe41c2e0 | ||
|
|
48f485b378 | ||
|
|
6ee8fb65c3 | ||
|
|
de5e40e6b8 | ||
|
|
2106bf4d94 | ||
|
|
72cef158a1 | ||
|
|
d1f08b58c0 | ||
|
|
2ef9073650 | ||
|
|
260ae53c8d | ||
|
|
21adedea84 | ||
|
|
7d7a0fc82d | ||
|
|
4770c37f4f | ||
|
|
450978ecd9 | ||
|
|
4035c7e024 | ||
|
|
7aebaaa98b | ||
|
|
03cb04ab06 | ||
|
|
aa882406d0 | ||
|
|
fde9b8511c | ||
|
|
9582725b3a | ||
|
|
2f27578bb0 | ||
|
|
d3757c5880 | ||
|
|
c39dac30fb | ||
|
|
73a1d3eadf | ||
|
|
4e383b6598 | ||
|
|
030aaaca25 | ||
|
|
d19e5b6286 | ||
|
|
c4ed6602e7 | ||
|
|
ae7d063fdd | ||
|
|
67a1b1faf9 | ||
|
|
9e6868b638 | ||
|
|
9185ff8f58 | ||
|
|
190e1624ca | ||
|
|
86b6bae6e6 | ||
|
|
0adf936085 | ||
|
|
4f63f7b3d5 | ||
|
|
0136435a41 | ||
|
|
87de48b5a0 | ||
|
|
732bbe4444 | ||
|
|
9b6293fbeb | ||
|
|
bc20173084 | ||
|
|
8b255372dd | ||
|
|
f88bf105a9 | ||
|
|
0e26eab2e6 | ||
|
|
778c2dba58 |
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
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
Normal file
12
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# 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
|
||||||
49
.github/workflows/build.yml
vendored
Normal file
49
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
paths-ignore:
|
||||||
|
- "doc/**"
|
||||||
|
- "**/README.md"
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
paths-ignore:
|
||||||
|
- "doc/**"
|
||||||
|
- "**/README.md"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: "!contains(github.event.head_commit.message, '[skip ci]')" # 如果 commit 信息包含以下关键字则跳过该任务
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
KEY: ${{ secrets.WEB_HOOK_ACCESS_KEY }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK 1.8
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
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
|
||||||
47
.github/workflows/mavenpublish.yml
vendored
47
.github/workflows/mavenpublish.yml
vendored
@@ -1,47 +0,0 @@
|
|||||||
# 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: Blog backEnd CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
APPLICATION_PROPERTIES_TEST: ${{ secrets.APPLICATION_PROPERTIES_TEST }}
|
|
||||||
APPLICATION_PROPERTIES_PROD: ${{ secrets.APPLICATION_PROPERTIES_PROD }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up JDK 1.8
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 1.8
|
|
||||||
|
|
||||||
- name: Build jar file
|
|
||||||
run: echo $APPLICATION_PROPERTIES_TEST|base64 -d > src/main/resources/application-test.properties && echo $APPLICATION_PROPERTIES_PROD|base64 -d> src/main/resources/application-prod.properties && mvn -B package --file pom.xml
|
|
||||||
|
|
||||||
- name: SCP
|
|
||||||
uses: appleboy/scp-action@master
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.SSH_HOST }}
|
|
||||||
username: ${{ secrets.SSH_USERNAME }}
|
|
||||||
password: ${{ secrets.SSH_PASSWORD }}
|
|
||||||
port: ${{ secrets.SSH_PORT }}
|
|
||||||
source: "target/blog-0.0.1-SNAPSHOT.jar"
|
|
||||||
target: "/www/wwwroot/api.celess.cn"
|
|
||||||
|
|
||||||
- name: Run SSH command
|
|
||||||
uses: garygrossgarten/github-action-ssh@v0.5.0
|
|
||||||
with:
|
|
||||||
command: cd /www/wwwroot/api.celess.cn && bash build.sh
|
|
||||||
host: ${{ secrets.SSH_HOST }}
|
|
||||||
username: ${{ secrets.SSH_USERNAME }}
|
|
||||||
password: ${{ secrets.SSH_PASSWORD }}
|
|
||||||
port: ${{ secrets.SSH_PORT }}
|
|
||||||
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,9 +1,8 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*.imi
|
*.imi
|
||||||
|
*.iml
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# 本地项目的私有文件
|
# 本地项目的私有文件
|
||||||
back-end/blog-dev.sql
|
blog-deploy/src/main/resources/application-dev.properties
|
||||||
src/main/resources/application-dev.properties
|
|
||||||
src/main/resources/application-prod.properties
|
src/main/resources/application-prod.properties
|
||||||
src/main/resources/application-test.properties
|
|
||||||
|
|||||||
7
.mvn/wrapper/MavenWrapperDownloader.java
vendored
7
.mvn/wrapper/MavenWrapperDownloader.java
vendored
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2007-present the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
@@ -21,7 +20,7 @@ import java.util.Properties;
|
|||||||
|
|
||||||
public class MavenWrapperDownloader {
|
public class MavenWrapperDownloader {
|
||||||
|
|
||||||
private static final String WRAPPER_VERSION = "0.5.5";
|
private static final String WRAPPER_VERSION = "0.5.6";
|
||||||
/**
|
/**
|
||||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||||
*/
|
*/
|
||||||
|
|||||||
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Binary file not shown.
4
.mvn/wrapper/maven-wrapper.properties
vendored
4
.mvn/wrapper/maven-wrapper.properties
vendored
@@ -1,2 +1,2 @@
|
|||||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
|
||||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
|
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019 小海
|
Copyright (c) 2020 禾几海
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
36
README.md
36
README.md
@@ -1,11 +1,23 @@
|
|||||||
# 小海博客后端管理系统
|
<h1 align="center">
|
||||||
   [](https://www.celess.cn)
|
小海博客后端管理系统
|
||||||
## 基于Springboot的后端博客管理系统
|
</h1>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
基于Springboot的后端博客管理系统
|
||||||
|
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://github.com/xiaohai2271/blog-backEnd)
|
||||||
|
[](https://www.celess.cn)
|
||||||
|
</div>
|
||||||
|
|
||||||
### 主要使用的技术
|
> 请配合前端项目一起食用 [https://github.com/xiaohai2271/blog-frontEnd](https://github.com/xiaohai2271/blog-frontEnd)
|
||||||
|
## 🎈主要使用的技术
|
||||||
|
|
||||||
| 使用的技术 | 名称 | 版本 |
|
| 使用的技术 | 名称 | 版本 |
|
||||||
| :--------------: | :--------: | :-----------: |
|
| :--------------: | :--------: | :-----------: |
|
||||||
@@ -20,16 +32,14 @@
|
|||||||
| 缓存(线上环境) | redis | 3.0.6 |
|
| 缓存(线上环境) | redis | 3.0.6 |
|
||||||
| 数据库 |mysql |5.7 |
|
| 数据库 |mysql |5.7 |
|
||||||
|
|
||||||
### 接口文档
|
## 🔨如何构建
|
||||||
|
详情参照[Build](./doc/Build.md)文档
|
||||||
|
|
||||||
项目采用swagger2,接口文档自动生成,具体为 http://ip:端口/swagger-ui.html
|
|
||||||
|
|
||||||
### 📝TODO
|
## 📒接口文档
|
||||||
|
项目采用swagger2,接口文档自动生成,具体为 http://ip:port/doc.html
|
||||||
|
|
||||||
- [x] 密码重置
|
或者参照[离线API文档](./doc/API.md)
|
||||||
- [x] 信息修改
|
|
||||||
- [ ] 接入qq登录
|
|
||||||
|
|
||||||
### 📌FIXME
|
## ☀授权协议
|
||||||
|
[MIT](./LICENSE)
|
||||||
- [ ] `/write` 图片上传的跨域问题
|
|
||||||
|
|||||||
45
blog-article/pom.xml
Normal file
45
blog-article/pom.xml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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,13 +1,13 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.article.controller;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.article.util.SitemapGenerateUtil;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
import cn.celess.common.entity.Response;
|
||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.common.entity.dto.ArticleReq;
|
||||||
import cn.celess.blog.service.ArticleService;
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.common.service.ArticleService;
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
import cn.celess.common.util.EnvironmentUtil;
|
||||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
import cn.celess.user.util.RedisUserUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -35,8 +35,10 @@ public class ArticleController {
|
|||||||
@PostMapping("/admin/article/create")
|
@PostMapping("/admin/article/create")
|
||||||
public Response create(@RequestBody ArticleReq body) {
|
public Response create(@RequestBody ArticleReq body) {
|
||||||
ArticleModel articleModel = articleService.create(body);
|
ArticleModel articleModel = articleService.create(body);
|
||||||
|
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(articleModel);
|
}
|
||||||
|
return Response.success(articleModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +50,10 @@ public class ArticleController {
|
|||||||
@DeleteMapping("/admin/article/del")
|
@DeleteMapping("/admin/article/del")
|
||||||
public Response delete(@RequestParam("articleID") long articleId) {
|
public Response delete(@RequestParam("articleID") long articleId) {
|
||||||
boolean delete = articleService.delete(articleId);
|
boolean delete = articleService.delete(articleId);
|
||||||
|
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(delete);
|
}
|
||||||
|
return Response.success(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,8 +65,10 @@ public class ArticleController {
|
|||||||
@PutMapping("/admin/article/update")
|
@PutMapping("/admin/article/update")
|
||||||
public Response update(@RequestBody ArticleReq body) {
|
public Response update(@RequestBody ArticleReq body) {
|
||||||
ArticleModel update = articleService.update(body);
|
ArticleModel update = articleService.update(body);
|
||||||
|
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(update);
|
}
|
||||||
|
return Response.success(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,13 +86,13 @@ public class ArticleController {
|
|||||||
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
||||||
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
ArticleModel article = articleService.retrieveOneByID(articleId, is4update);
|
ArticleModel article = articleService.retrieveOneById(articleId, is4update);
|
||||||
if (article.getOpen()) {
|
if (article.getOpen()) {
|
||||||
return ResponseUtil.success(article);
|
return Response.success(article);
|
||||||
} else if (article.getAuthorId().equals(redisUserUtil.get().getId())) {
|
} else if (article.getAuthor().getId().equals(redisUserUtil.get().getId())) {
|
||||||
return ResponseUtil.success(article);
|
return Response.success(article);
|
||||||
}
|
}
|
||||||
return ResponseUtil.response(ResponseEnum.PERMISSION_ERROR, null);
|
return Response.response(ResponseEnum.PERMISSION_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +105,7 @@ public class ArticleController {
|
|||||||
@GetMapping("/articles")
|
@GetMapping("/articles")
|
||||||
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||||
@RequestParam(name = "count", defaultValue = "5") int count) {
|
@RequestParam(name = "count", defaultValue = "5") int count) {
|
||||||
return ResponseUtil.success(articleService.retrievePageForOpen(count, page));
|
return Response.success(articleService.retrievePageForOpen(count, page));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,8 +117,9 @@ public class ArticleController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/admin/articles")
|
@GetMapping("/admin/articles")
|
||||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
@RequestParam(name = "count", defaultValue = "10") int count,
|
||||||
return ResponseUtil.success(articleService.adminArticles(count, page));
|
@RequestParam(name = "deleted", required = false) Boolean deleted) {
|
||||||
|
return Response.success(articleService.adminArticles(count, page, deleted));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +134,7 @@ public class ArticleController {
|
|||||||
public Response findByCategory(@PathVariable("name") String name,
|
public Response findByCategory(@PathVariable("name") String name,
|
||||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||||
return ResponseUtil.success(articleService.findByCategory(name, page, count));
|
return Response.success(articleService.findByCategory(name, page, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,13 +149,13 @@ public class ArticleController {
|
|||||||
public Response findByTag(@PathVariable("name") String name,
|
public Response findByTag(@PathVariable("name") String name,
|
||||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||||
return ResponseUtil.success(articleService.findByTag(name, page, count));
|
return Response.success(articleService.findByTag(name, page, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/createSitemap")
|
@GetMapping("/createSitemap")
|
||||||
public Response createSitemap() {
|
public Response createSitemap() {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(null);
|
return Response.success(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,368 @@
|
|||||||
|
package cn.celess.article.serviceimpl;
|
||||||
|
|
||||||
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
|
import cn.celess.common.constant.RoleEnum;
|
||||||
|
import cn.celess.common.entity.*;
|
||||||
|
import cn.celess.common.entity.dto.ArticleReq;
|
||||||
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
|
import cn.celess.common.mapper.*;
|
||||||
|
import cn.celess.common.service.ArticleService;
|
||||||
|
import cn.celess.common.service.UserService;
|
||||||
|
import cn.celess.common.util.ModalTrans;
|
||||||
|
import cn.celess.common.util.RegexUtil;
|
||||||
|
import cn.celess.common.util.StringUtil;
|
||||||
|
import cn.celess.user.util.RedisUserUtil;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.youbenzi.mdtool.tool.MDTool;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/03/28 15:21
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class ArticleServiceImpl implements ArticleService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
TagMapper tagMapper;
|
||||||
|
@Resource
|
||||||
|
CategoryMapper categoryMapper;
|
||||||
|
@Resource
|
||||||
|
CommentMapper commentMapper;
|
||||||
|
@Resource
|
||||||
|
ArticleTagMapper articleTagMapper;
|
||||||
|
@Resource
|
||||||
|
UserService userService;
|
||||||
|
@Autowired
|
||||||
|
HttpServletRequest request;
|
||||||
|
@Resource
|
||||||
|
RedisUserUtil redisUserUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ArticleModel create(ArticleReq reqBody) {
|
||||||
|
if (reqBody == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
//数据判断
|
||||||
|
if (reqBody.getTitle() == null || reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
} else if (reqBody.getMdContent() == null || reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
//转载 判断链接
|
||||||
|
if (!reqBody.getType()) {
|
||||||
|
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
if (reqBody.getTags() == null || reqBody.getTags().length == 0) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
if (articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||||
|
}
|
||||||
|
// 查看是否存在已有的分类
|
||||||
|
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||||
|
if (category == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建 需要写入数据库的对象数据
|
||||||
|
Article article = new Article();
|
||||||
|
BeanUtils.copyProperties(reqBody, article);
|
||||||
|
|
||||||
|
article.setUser(redisUserUtil.get());
|
||||||
|
|
||||||
|
//markdown->html->summary
|
||||||
|
String str = StringUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||||
|
//获取摘要 摘要长度为255个字符
|
||||||
|
String summary = str.length() > 240 ? str.substring(0, 240) + "......" : str;
|
||||||
|
article.setSummary(summary);
|
||||||
|
|
||||||
|
article.setCategory(category);
|
||||||
|
|
||||||
|
//文章存数据库
|
||||||
|
articleMapper.insert(article);
|
||||||
|
//将标签写入数据库
|
||||||
|
for (String tagName : reqBody.getTags()) {
|
||||||
|
if (tagName.replaceAll(" ", "").length() == 0) {
|
||||||
|
//单个标签只含空格
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Tag tag = tagMapper.findTagByName(tagName);
|
||||||
|
if (tag == null) {
|
||||||
|
tag = new Tag();
|
||||||
|
tag.setName(tagName);
|
||||||
|
tagMapper.insert(tag);
|
||||||
|
}
|
||||||
|
ArticleTag articleTag = new ArticleTag(article, tag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
}
|
||||||
|
Article articleFromDb = articleMapper.findArticleById(article.getId());
|
||||||
|
|
||||||
|
ArticleModel articleModel = ModalTrans.article(articleFromDb);
|
||||||
|
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(article.getId()), true));
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean delete(long articleId) {
|
||||||
|
Article articleForDel = articleMapper.findArticleById(articleId);
|
||||||
|
|
||||||
|
if (articleForDel == null) {
|
||||||
|
//文章不存在
|
||||||
|
throw new BlogResponseException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
//对访问情况进行判断 非admin 权限不可删除文章
|
||||||
|
User user = redisUserUtil.get();
|
||||||
|
if (!RoleEnum.ADMIN_ROLE.getRoleName().equals(user.getRole())) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PERMISSION_ERROR);
|
||||||
|
}
|
||||||
|
//删除指定文章
|
||||||
|
articleMapper.delete(articleId);
|
||||||
|
|
||||||
|
//articleTagMapper.deleteByArticleId(articleId);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@Override
|
||||||
|
public ArticleModel update(ArticleReq reqBody) {
|
||||||
|
if (reqBody == null || reqBody.getId() == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
// 查找数据
|
||||||
|
Article article = articleMapper.findArticleById(reqBody.getId());
|
||||||
|
|
||||||
|
//数据判断
|
||||||
|
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||||
|
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||||
|
}
|
||||||
|
article.setTitle(reqBody.getTitle());
|
||||||
|
}
|
||||||
|
if (reqBody.getMdContent() != null && !reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||||
|
article.setMdContent(reqBody.getMdContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
//转载 判断链接
|
||||||
|
if (reqBody.getType() != null) {
|
||||||
|
if (!reqBody.getType() && reqBody.getUrl() == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
|
}
|
||||||
|
article.setType(reqBody.getType());
|
||||||
|
article.setUrl(reqBody.getUrl());
|
||||||
|
}
|
||||||
|
if (reqBody.getCategory() != null && !reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||||
|
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||||
|
if (category == null) {
|
||||||
|
category = new Category();
|
||||||
|
category.setName(reqBody.getCategory());
|
||||||
|
categoryMapper.insert(category);
|
||||||
|
}
|
||||||
|
article.setCategory(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
//写入数据库的数据
|
||||||
|
article.setOpen(reqBody.getOpen() == null ? article.getOpen() : reqBody.getOpen());
|
||||||
|
String str = StringUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||||
|
article.setSummary(str.length() > 240 ? str.substring(0, 240) + "......" : str);
|
||||||
|
articleMapper.update(article);
|
||||||
|
|
||||||
|
|
||||||
|
List<ArticleTag> allByArticleId = articleTagMapper.findAllByArticleId(article.getId());
|
||||||
|
List<ArticleTag> updateList = new ArrayList<>();
|
||||||
|
List<ArticleTag> deleteList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 获取要更新 的标签
|
||||||
|
for (String tag : reqBody.getTags()) {
|
||||||
|
boolean contain = allByArticleId.stream().anyMatch(articleTag -> articleTag.getTag().getName().equals(tag));
|
||||||
|
if (!contain) {
|
||||||
|
ArticleTag articleTag = new ArticleTag();
|
||||||
|
articleTag.setArticle(article);
|
||||||
|
Tag tagByName = tagMapper.findTagByName(tag);
|
||||||
|
if (tagByName == null) {
|
||||||
|
tagByName = new Tag(tag);
|
||||||
|
tagMapper.insert(tagByName);
|
||||||
|
}
|
||||||
|
articleTag.setTag(tagByName);
|
||||||
|
updateList.add(articleTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 获取要删除的标签
|
||||||
|
allByArticleId.forEach(articleTag -> {
|
||||||
|
boolean contain = false;
|
||||||
|
for (String tag : reqBody.getTags()) {
|
||||||
|
if (articleTag.getTag().getName().equals(tag)) {
|
||||||
|
contain = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!contain) {
|
||||||
|
deleteList.add(articleTag);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (updateList.size() != 0) {
|
||||||
|
updateList.forEach(articleTag -> articleTagMapper.insert(articleTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deleteList.size() != 0) {
|
||||||
|
articleTagMapper.deleteMultiById(deleteList);
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新完成移除
|
||||||
|
request.getSession().removeAttribute("article4update");
|
||||||
|
ArticleModel articleModel = ModalTrans.article(articleMapper.findArticleById(article.getId()));
|
||||||
|
setPreAndNextArticle(articleModel);
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable(value = {"article"}, key = "'retrieveOneById'+#articleId")
|
||||||
|
public ArticleModel retrieveOneById(long articleId, boolean is4update) {
|
||||||
|
Article article = articleMapper.findArticleById(articleId);
|
||||||
|
if (article == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
if (!article.getOpen()) {
|
||||||
|
User user = redisUserUtil.getWithOutExc();
|
||||||
|
if (user == null || "user".equals(user.getRole())) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArticleModel articleModel = ModalTrans.article(article);
|
||||||
|
|
||||||
|
if (is4update) {
|
||||||
|
//因更新而获取文章 不需要增加阅读量
|
||||||
|
request.getSession().setAttribute("article4update", article);
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
setPreAndNextArticle(articleModel);
|
||||||
|
articleMapper.updateReadingNumber(articleId);
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param count 数目
|
||||||
|
* @param page 页面
|
||||||
|
* @return PageInfo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Article> articleList = articleMapper.findAll();
|
||||||
|
|
||||||
|
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||||
|
|
||||||
|
List<Article> collect;
|
||||||
|
if (deleted != null) {
|
||||||
|
collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
collect = articleList;
|
||||||
|
}
|
||||||
|
List<ArticleModel> articleModels = collect.stream()
|
||||||
|
.peek(article -> article.setMdContent(null))
|
||||||
|
.map(ModalTrans::article)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
pageData.setList(articleModels);
|
||||||
|
|
||||||
|
return pageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable(value = {"article"}, key = "'retrievePageForOpen:'+#page+':'+#count")
|
||||||
|
public PageData<ArticleModel> retrievePageForOpen(int count, int page) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Article> articleList = articleMapper.findAllByOpen(true);
|
||||||
|
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||||
|
|
||||||
|
List<ArticleModel> articleModelList = articleList
|
||||||
|
.stream()
|
||||||
|
.map(article -> setPreAndNextArticle(ModalTrans.article(article, true)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
pageData.setList(articleModelList);
|
||||||
|
return pageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable(value = {"article"}, key = "'findByCategory:'+#name")
|
||||||
|
public PageData<ArticleModel> findByCategory(String name, int page, int count) {
|
||||||
|
Category category = categoryMapper.findCategoryByName(name);
|
||||||
|
if (category == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
|
}
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
||||||
|
|
||||||
|
List<ArticleModel> modelList = open.stream()
|
||||||
|
.map(article -> ModalTrans.article(article, true))
|
||||||
|
.peek(articleModel -> {
|
||||||
|
articleModel.setNextArticle(null);
|
||||||
|
articleModel.setPreArticle(null);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return new PageData<>(new PageInfo<>(open), modelList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable(value = {"article"}, key = "'findByTag:'+#name")
|
||||||
|
public PageData<ArticleModel> findByTag(String name, int page, int count) {
|
||||||
|
Tag tag = tagMapper.findTagByName(name);
|
||||||
|
if (tag == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.TAG_NOT_EXIST);
|
||||||
|
}
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
||||||
|
List<ArticleModel> modelList = articleByTag
|
||||||
|
.stream()
|
||||||
|
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||||
|
.peek(articleModel -> {
|
||||||
|
articleModel.setNextArticle(null);
|
||||||
|
articleModel.setPreArticle(null);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return new PageData<>(new PageInfo<>(articleByTag), modelList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ArticleModel setPreAndNextArticle(ArticleModel articleModel) {
|
||||||
|
if (articleModel == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
||||||
|
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.article.util;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Article;
|
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.common.entity.Article;
|
||||||
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
|
import cn.celess.common.util.DateFormatUtil;
|
||||||
|
import cn.celess.common.util.EnvironmentUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -24,6 +26,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
@@ -33,17 +36,26 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
public class SitemapGenerateUtil {
|
public class SitemapGenerateUtil {
|
||||||
|
|
||||||
@Value("${sitemap.path}")
|
|
||||||
private String path;
|
|
||||||
private Map<String, String> urlList;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
|
private Map<String, String> urlList;
|
||||||
|
|
||||||
|
private static DocumentBuilder getDocumentBuilder() {
|
||||||
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder db = null;
|
||||||
|
try {
|
||||||
|
db = dbf.newDocumentBuilder();
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void createSitemap() {
|
public void createSitemap() {
|
||||||
initList();
|
initList();
|
||||||
if ("".equals(path) || "classpath".equals(path)) {
|
String path = EnvironmentUtil.getProperties("sitemap.path", System.getProperty("user.dir"));
|
||||||
|
if ("classpath".equals(path)) {
|
||||||
path = System.getProperty("user.dir") + "/sitemap.xml";
|
path = System.getProperty("user.dir") + "/sitemap.xml";
|
||||||
}
|
}
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
@@ -89,24 +101,11 @@ public class SitemapGenerateUtil {
|
|||||||
urlList.put("https://www.celess.cn", DateFormatUtil.getForXmlDate(new Date()));
|
urlList.put("https://www.celess.cn", DateFormatUtil.getForXmlDate(new Date()));
|
||||||
urlList.put("https://www.celess.cn/links", DateFormatUtil.getForXmlDate(new Date()));
|
urlList.put("https://www.celess.cn/links", DateFormatUtil.getForXmlDate(new Date()));
|
||||||
urlList.put("https://www.celess.cn/leaveMsg", DateFormatUtil.getForXmlDate(new Date()));
|
urlList.put("https://www.celess.cn/leaveMsg", DateFormatUtil.getForXmlDate(new Date()));
|
||||||
List<Article> articles = articleMapper.findAll();
|
List<Article> articles = articleMapper.findAll().stream().filter(article -> article.getOpen() && !article.isDeleted()).collect(Collectors.toList());
|
||||||
articles.forEach(article -> {
|
articles.forEach(article -> {
|
||||||
urlList.put("https://www.celess.cn/article/" + article.getId(), DateFormatUtil.getForXmlDate(
|
urlList.put("https://www.celess.cn/article/" + article.getId(), DateFormatUtil.getForXmlDate(
|
||||||
article.getUpdateDate() == null ? article.getPublishDate() : article.getUpdateDate()));
|
article.getUpdateDate() == null ? article.getPublishDate() : article.getUpdateDate()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static DocumentBuilder getDocumentBuilder() {
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder db = null;
|
|
||||||
try {
|
|
||||||
db = dbf.newDocumentBuilder();
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
12
blog-article/src/main/resources/banner.txt
Normal file
12
blog-article/src/main/resources/banner.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
${AnsiColor.BRIGHT_GREEN}
|
||||||
|
_ _ _ ____ _ _ _ _
|
||||||
|
| | | | (_) | _ \ | | /\ | | (_) | |
|
||||||
|
| |__| | _ | |_) | | | ___ __ _ ______ / \ _ __ | |_ _ ___ | | ___
|
||||||
|
| __ | | | | _ < | | / _ \ / _` | |______| / /\ \ | '__| | __| | | / __| | | / _ \
|
||||||
|
| | | | | | | |_) | | | | (_) | | (_| | / ____ \ | | | |_ | | | (__ | | | __/
|
||||||
|
|_| |_| |_| |____/ |_| \___/ \__, | /_/ \_\ |_| \__| |_| \___| |_| \___|
|
||||||
|
__/ |
|
||||||
|
|___/
|
||||||
|
${AnsiColor.BRIGHT_RED}
|
||||||
|
Application Version: ${application.version}${application.formatted-version}
|
||||||
|
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,303 @@
|
|||||||
|
package cn.celess.article.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.celess.article.ArticleBaseTest;
|
||||||
|
import cn.celess.common.entity.Article;
|
||||||
|
import cn.celess.common.entity.Response;
|
||||||
|
import cn.celess.common.entity.Tag;
|
||||||
|
import cn.celess.common.entity.dto.ArticleReq;
|
||||||
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.celess.common.constant.ResponseEnum.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
public class ArticleControllerTest extends ArticleBaseTest {
|
||||||
|
@Resource
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
private static final TypeReference<?> ARTICLE_MODEL_TYPE = new TypeReference<Response<ArticleModel>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> ARTICLE_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<ArticleModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void create() {
|
||||||
|
ArticleReq articleReq = new ArticleReq();
|
||||||
|
// 应该正常通过
|
||||||
|
articleReq.setTitle("test-" + randomStr());
|
||||||
|
articleReq.setMdContent("# test title");
|
||||||
|
articleReq.setCategory("随笔");
|
||||||
|
String[] tagList = {"tag", "category"};
|
||||||
|
articleReq.setTags(tagList);
|
||||||
|
articleReq.setOpen(true);
|
||||||
|
articleReq.setType(true);
|
||||||
|
articleReq.setUrl("http://xxxx.com");
|
||||||
|
MockHttpServletRequestBuilder post = post("/admin/article/create");
|
||||||
|
|
||||||
|
try {
|
||||||
|
getMockData(post, adminLogin(), articleReq).andDo(result -> {
|
||||||
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
ArticleModel articleModel = response.getResult();
|
||||||
|
assertNotNull(articleModel.getId());
|
||||||
|
assertNotNull(articleModel.getTitle());
|
||||||
|
assertNotNull(articleModel.getSummary());
|
||||||
|
assertNotNull(articleModel.getOriginal());
|
||||||
|
assertNotNull(articleModel.getTags());
|
||||||
|
assertNotNull(articleModel.getCategory());
|
||||||
|
assertNotNull(articleModel.getPublishDateFormat());
|
||||||
|
assertNotNull(articleModel.getMdContent());
|
||||||
|
assertNotNull(articleModel.getPreArticle());
|
||||||
|
assertNull(articleModel.getNextArticle());
|
||||||
|
assertNotNull(articleModel.getOpen());
|
||||||
|
assertNotNull(articleModel.getReadingNumber());
|
||||||
|
assertNotNull(articleModel.getAuthor());
|
||||||
|
assertNotNull(articleModel.getUrl());
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() {
|
||||||
|
Article article;
|
||||||
|
do {
|
||||||
|
article = articleMapper.getLastestArticle();
|
||||||
|
create();
|
||||||
|
} while (article.isDeleted());
|
||||||
|
assertFalse(article.isDeleted());
|
||||||
|
MockHttpServletRequestBuilder delete = MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId());
|
||||||
|
try {
|
||||||
|
Article finalArticle = article;
|
||||||
|
getMockData(delete, adminLogin()).andDo(result -> {
|
||||||
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
// 断言删除成功
|
||||||
|
assertTrue(response.getResult());
|
||||||
|
assertTrue(articleMapper.isDeletedById(finalArticle.getId()));
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() {
|
||||||
|
Article article = articleMapper.getLastestArticle();
|
||||||
|
ArticleReq articleReq = new ArticleReq();
|
||||||
|
articleReq.setId(article.getId());
|
||||||
|
articleReq.setUrl("http://www.test.test");
|
||||||
|
articleReq.setType(!article.getType());
|
||||||
|
articleReq.setCategory("test");
|
||||||
|
articleReq.setMdContent("test-" + article.getMdContent());
|
||||||
|
articleReq.setOpen(!article.getOpen());
|
||||||
|
String tag1 = randomStr(4);
|
||||||
|
String tag2 = randomStr(4);
|
||||||
|
String[] tagList = {"test", tag1, tag2};
|
||||||
|
articleReq.setTags(tagList);
|
||||||
|
articleReq.setTitle("test-" + article.getTitle());
|
||||||
|
try {
|
||||||
|
getMockData(put("/admin/article/update"), adminLogin(), articleReq).andDo(result -> {
|
||||||
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
ArticleModel a = response.getResult();
|
||||||
|
assertEquals(articleReq.getCategory(), a.getCategory());
|
||||||
|
assertEquals(articleReq.getUrl(), a.getUrl());
|
||||||
|
assertEquals(articleReq.getMdContent(), a.getMdContent());
|
||||||
|
assertEquals(articleReq.getTitle(), a.getTitle());
|
||||||
|
assertEquals(articleReq.getType(), a.getOriginal());
|
||||||
|
// Tag
|
||||||
|
List<Tag> asList = a.getTags();
|
||||||
|
assertEquals(3, asList.size());
|
||||||
|
assertEquals(articleReq.getOpen(), a.getOpen());
|
||||||
|
assertEquals(articleReq.getId(), a.getId());
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void retrieveOneById() {
|
||||||
|
try {
|
||||||
|
long articleID = 3;
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID));
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=true"));
|
||||||
|
|
||||||
|
// 文章不存在
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/-1"))
|
||||||
|
.andDo(result -> assertEquals(ARTICLE_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
|
|
||||||
|
// 正常情况
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=false")).andDo(result -> {
|
||||||
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
|
// 断言获取数据成功
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
|
||||||
|
ArticleModel a = response.getResult();
|
||||||
|
assertNotNull(a.getTitle());
|
||||||
|
assertNotNull(a.getId());
|
||||||
|
assertNotNull(a.getSummary());
|
||||||
|
assertNotNull(a.getMdContent());
|
||||||
|
assertNotNull(a.getUrl());
|
||||||
|
assertNotNull(a.getUpdateDateFormat());
|
||||||
|
assertTrue(a.getPreArticle() != null || a.getNextArticle() != null);
|
||||||
|
assertNotNull(a.getReadingNumber());
|
||||||
|
assertNotNull(a.getOriginal());
|
||||||
|
assertNotNull(a.getPublishDateFormat());
|
||||||
|
assertNotNull(a.getCategory());
|
||||||
|
assertNotNull(a.getTags());
|
||||||
|
assertNotNull(a.getAuthor());
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void articles() {
|
||||||
|
try {
|
||||||
|
// 测试不带参数访问
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/articles"));
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/articles?page=1&count=5")).andDo(result -> {
|
||||||
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
|
// 断言获取数据成功
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
// 结果集非空
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
// 判断pageInfo是否包装完全
|
||||||
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
|
assertNotEquals(0, pageData.getTotal());
|
||||||
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(5, pageData.getPageSize());
|
||||||
|
// 内容完整
|
||||||
|
for (ArticleModel a : pageData.getList()) {
|
||||||
|
assertNotNull(a.getTitle());
|
||||||
|
assertNotNull(a.getId());
|
||||||
|
assertNotNull(a.getSummary());
|
||||||
|
assertNotNull(a.getOriginal());
|
||||||
|
assertNotNull(a.getPublishDateFormat());
|
||||||
|
assertNotNull(a.getCategory());
|
||||||
|
assertNotNull(a.getTags());
|
||||||
|
assertNotNull(a.getAuthor());
|
||||||
|
assertNull(a.getOpen());
|
||||||
|
assertNull(a.getMdContent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void adminArticles() {
|
||||||
|
try {
|
||||||
|
getMockData(get("/admin/articles?page=1&count=5")).andExpect(result ->
|
||||||
|
assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result, ARTICLE_MODEL_PAGE_TYPE).getCode())
|
||||||
|
);
|
||||||
|
|
||||||
|
// User权限登陆
|
||||||
|
getMockData(get("/admin/articles?page=1&count=5"), userLogin()).andDo(result ->
|
||||||
|
assertEquals(PERMISSION_ERROR.getCode(), getResponse(result, ARTICLE_MODEL_PAGE_TYPE).getCode())
|
||||||
|
);
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
// admin权限登陆
|
||||||
|
int finalI = i;
|
||||||
|
getMockData(get("/admin/articles?page=1&count=5&deleted=" + (i == 1)), adminLogin()).andDo(result -> {
|
||||||
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
// 判断pageInfo是否包装完全
|
||||||
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
|
assertNotEquals(0, pageData.getTotal());
|
||||||
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(5, pageData.getPageSize());
|
||||||
|
// 内容完整
|
||||||
|
for (ArticleModel a : pageData.getList()) {
|
||||||
|
assertNotNull(a.getTitle());
|
||||||
|
assertNotNull(a.getId());
|
||||||
|
assertNotNull(a.getOriginal());
|
||||||
|
assertNotNull(a.getPublishDateFormat());
|
||||||
|
assertNotNull(a.getOpen());
|
||||||
|
assertNotNull(a.getReadingNumber());
|
||||||
|
assertNotNull(a.getLikeCount());
|
||||||
|
assertNotNull(a.getDislikeCount());
|
||||||
|
assertEquals((finalI == 1), a.isDeleted());
|
||||||
|
assertNull(a.getMdContent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByCategory() {
|
||||||
|
try {
|
||||||
|
// 分类不存在
|
||||||
|
String categoryName = "NoSuchCategory";
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
||||||
|
.andDo(result -> assertEquals(CATEGORY_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
|
// 正常查询
|
||||||
|
categoryName = "linux";
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
||||||
|
.andDo(result -> {
|
||||||
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
|
assertNotEquals(0, pageData.getTotal());
|
||||||
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(10, pageData.getPageSize());
|
||||||
|
for (ArticleModel arc : pageData.getList()) {
|
||||||
|
assertNotEquals(0, arc.getId().longValue());
|
||||||
|
assertNotNull(arc.getTitle());
|
||||||
|
assertNotNull(arc.getSummary());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByTag() {
|
||||||
|
try {
|
||||||
|
// 分类不存在
|
||||||
|
String tagName = "NoSuchTag";
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
||||||
|
.andDo(result -> assertEquals(TAG_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
|
// 正常查询
|
||||||
|
tagName = "linux";
|
||||||
|
getMockData(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
||||||
|
.andDo(result -> {
|
||||||
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
|
assertNotEquals(0, pageData.getTotal());
|
||||||
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(10, pageData.getPageSize());
|
||||||
|
|
||||||
|
for (ArticleModel arc : pageData.getList()) {
|
||||||
|
assertNotEquals(0, arc.getId().longValue());
|
||||||
|
assertNotNull(arc.getTitle());
|
||||||
|
assertNotNull(arc.getSummary());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
33
blog-categorytag/pom.xml
Normal file
33
blog-categorytag/pom.xml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
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,8 +1,7 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.categorytag.controller;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.common.entity.Response;
|
||||||
import cn.celess.blog.service.CategoryService;
|
import cn.celess.common.service.CategoryService;
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ public class CategoryController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/admin/category/create")
|
@PostMapping("/admin/category/create")
|
||||||
public Response addOne(@RequestParam("name") String name) {
|
public Response addOne(@RequestParam("name") String name) {
|
||||||
return ResponseUtil.success(categoryService.create(name));
|
return Response.success(categoryService.create(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +34,7 @@ public class CategoryController {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping("/admin/category/del")
|
@DeleteMapping("/admin/category/del")
|
||||||
public Response deleteOne(@RequestParam("id") long id) {
|
public Response deleteOne(@RequestParam("id") long id) {
|
||||||
return ResponseUtil.success(categoryService.delete(id));
|
return Response.success(categoryService.delete(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +47,7 @@ public class CategoryController {
|
|||||||
@PutMapping("/admin/category/update")
|
@PutMapping("/admin/category/update")
|
||||||
public Response updateOne(@RequestParam("id") Long id,
|
public Response updateOne(@RequestParam("id") Long id,
|
||||||
@RequestParam("name") String name) {
|
@RequestParam("name") String name) {
|
||||||
return ResponseUtil.success(categoryService.update(id, name));
|
return Response.success(categoryService.update(id, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +56,8 @@ public class CategoryController {
|
|||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
@GetMapping("/categories")
|
@GetMapping("/categories")
|
||||||
public Response getPage() {
|
public Response getPage(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||||
return ResponseUtil.success(categoryService.retrievePage());
|
@RequestParam(name = "count", defaultValue = "1000") int count) {
|
||||||
|
return Response.success(categoryService.retrievePage(page, count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package cn.celess.categorytag.serviceimpl;
|
||||||
|
|
||||||
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
|
import cn.celess.common.entity.Article;
|
||||||
|
import cn.celess.common.entity.Category;
|
||||||
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
|
import cn.celess.common.entity.vo.CategoryModel;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
|
import cn.celess.common.mapper.CategoryMapper;
|
||||||
|
import cn.celess.common.service.CategoryService;
|
||||||
|
import cn.celess.common.util.ModalTrans;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/03/28 22:43
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CategoryServiceImpl implements CategoryService {
|
||||||
|
@Autowired
|
||||||
|
CategoryMapper categoryMapper;
|
||||||
|
@Autowired
|
||||||
|
HttpServletRequest request;
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CategoryModel create(String name) {
|
||||||
|
if (categoryMapper.existsByName(name)) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.CATEGORY_HAS_EXIST);
|
||||||
|
}
|
||||||
|
Category category = new Category();
|
||||||
|
category.setName(name);
|
||||||
|
categoryMapper.insert(category);
|
||||||
|
return ModalTrans.category(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(long id) {
|
||||||
|
Category category = categoryMapper.findCategoryById(id);
|
||||||
|
if (category == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
|
}
|
||||||
|
return categoryMapper.delete(id) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CategoryModel update(Long id, String name) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||||
|
}
|
||||||
|
Category category = categoryMapper.findCategoryById(id);
|
||||||
|
category.setName(name);
|
||||||
|
categoryMapper.update(category);
|
||||||
|
return ModalTrans.category(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<CategoryModel> retrievePage(int page, int count) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Category> all = categoryMapper.findAll();
|
||||||
|
// 遍历没一个category
|
||||||
|
List<CategoryModel> modelList = all
|
||||||
|
.stream()
|
||||||
|
.map(ModalTrans::category)
|
||||||
|
.peek(categoryModel -> {
|
||||||
|
// 根据category去查article,并赋值给categoryModel
|
||||||
|
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(categoryModel.getId());
|
||||||
|
List<ArticleModel> articleModelList = allByCategoryId
|
||||||
|
.stream()
|
||||||
|
.map(article -> ModalTrans.article(article, true))
|
||||||
|
.peek(articleModel -> {
|
||||||
|
// 去除不必要的字段
|
||||||
|
articleModel.setPreArticle(null);
|
||||||
|
articleModel.setNextArticle(null);
|
||||||
|
articleModel.setTags(null);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
categoryModel.setArticles(articleModelList);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return new PageData<>(new PageInfo<>(all), modelList);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package cn.celess.categorytag.serviceimpl;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
|
import cn.celess.common.entity.ArticleTag;
|
||||||
|
import cn.celess.common.entity.Tag;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.entity.vo.TagModel;
|
||||||
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
|
import cn.celess.common.mapper.ArticleTagMapper;
|
||||||
|
import cn.celess.common.mapper.TagMapper;
|
||||||
|
import cn.celess.common.service.TagService;
|
||||||
|
import cn.celess.common.util.ModalTrans;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/03/28 22:29
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TagServiceImpl implements TagService {
|
||||||
|
@Autowired
|
||||||
|
TagMapper tagMapper;
|
||||||
|
@Autowired
|
||||||
|
HttpServletRequest request;
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
@Autowired
|
||||||
|
ArticleTagMapper articleTagMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TagModel create(String name) {
|
||||||
|
boolean b = tagMapper.existsByName(name);
|
||||||
|
if (b) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.TAG_HAS_EXIST);
|
||||||
|
}
|
||||||
|
Tag tag = new Tag();
|
||||||
|
tag.setName(name);
|
||||||
|
tagMapper.insert(tag);
|
||||||
|
return ModalTrans.tag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean delete(long tagId) {
|
||||||
|
Tag tag = tagMapper.findTagById(tagId);
|
||||||
|
if (tag == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.TAG_NOT_EXIST);
|
||||||
|
}
|
||||||
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(tagId);
|
||||||
|
// 删除文章
|
||||||
|
articleByTag.forEach(articleTag -> articleMapper.delete(articleTag.getArticle().getId()));
|
||||||
|
return tagMapper.delete(tagId) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TagModel update(Long id, String name) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
||||||
|
}
|
||||||
|
Tag tag = tagMapper.findTagById(id);
|
||||||
|
tag.setName(name);
|
||||||
|
tagMapper.update(tag);
|
||||||
|
return ModalTrans.tag(tag);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<TagModel> retrievePage(int page, int count) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Tag> tagList = tagMapper.findAll();
|
||||||
|
List<TagModel> modelList = new ArrayList<>();
|
||||||
|
tagList.forEach(tag -> modelList.add(ModalTrans.tag(tag)));
|
||||||
|
return new PageData<>(new PageInfo<>(tagList), modelList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TagModel> findAll() {
|
||||||
|
return tagMapper.findAll().stream()
|
||||||
|
.map(ModalTrans::tag)
|
||||||
|
.peek(tagModel -> {
|
||||||
|
List<ArticleTag> articleByTagAndOpen = articleTagMapper.findArticleByTagAndOpen(tagModel.getId());
|
||||||
|
tagModel.setArticles(
|
||||||
|
articleByTagAndOpen
|
||||||
|
.stream()
|
||||||
|
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
12
blog-categorytag/src/main/resources/banner.txt
Normal file
12
blog-categorytag/src/main/resources/banner.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
${AnsiColor.BRIGHT_GREEN}
|
||||||
|
_ _ _ ____ _ _______
|
||||||
|
| | | | (_) | _ \ | | |__ __|
|
||||||
|
| |__| | _ | |_) | | | ___ __ _ ______ | | __ _ __ _
|
||||||
|
| __ | | | | _ < | | / _ \ / _` | |______| | | / _` | / _` |
|
||||||
|
| | | | | | | |_) | | | | (_) | | (_| | | | | (_| | | (_| |
|
||||||
|
|_| |_| |_| |____/ |_| \___/ \__, | |_| \__,_| \__, |
|
||||||
|
__/ | __/ |
|
||||||
|
|___/ |___/
|
||||||
|
${AnsiColor.BRIGHT_RED}
|
||||||
|
Application Version: ${application.version}${application.formatted-version}
|
||||||
|
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package cn.celess.categorytag.controller;
|
||||||
|
|
||||||
|
import cn.celess.categorytag.CategoryTagBaseTest;
|
||||||
|
import cn.celess.common.entity.Category;
|
||||||
|
import cn.celess.common.entity.Response;
|
||||||
|
import cn.celess.common.entity.vo.CategoryModel;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.mapper.CategoryMapper;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import static cn.celess.common.constant.ResponseEnum.SUCCESS;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
public class CategoryControllerTest extends CategoryTagBaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CategoryMapper categoryMapper;
|
||||||
|
private static final TypeReference<?> CATEGORY_MODEL_TYPE = new TypeReference<Response<CategoryModel>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> CATEGORY_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<CategoryModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addOne() throws Exception {
|
||||||
|
String categoryName = randomStr(4);
|
||||||
|
getMockData(post("/admin/category/create?name=" + categoryName), adminLogin()).andDo(result -> {
|
||||||
|
Response<CategoryModel> response = getResponse(result, CATEGORY_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
CategoryModel category = response.getResult();
|
||||||
|
assertEquals(categoryName, category.getName());
|
||||||
|
assertNotNull(category.getId());
|
||||||
|
assertNull(category.getArticles());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteOne() throws Exception {
|
||||||
|
Category category = categoryMapper.getLastestCategory();
|
||||||
|
getMockData(delete("/admin/category/del?id=" + category.getId()), adminLogin()).andDo(result -> {
|
||||||
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertTrue(response.getResult());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateOne() throws Exception {
|
||||||
|
Category category = categoryMapper.getLastestCategory();
|
||||||
|
String name = randomStr(4);
|
||||||
|
getMockData(put("/admin/category/update?id=" + category.getId() + "&name=" + name), adminLogin()).andDo(result -> {
|
||||||
|
// Response<CategoryModel> response = mapper.readValue(result.getResponse().getContentAsString(), new ResponseType<Response<CategoryModel>>());
|
||||||
|
Response<CategoryModel> response = getResponse(result, CATEGORY_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
CategoryModel c = response.getResult();
|
||||||
|
assertEquals(name, c.getName());
|
||||||
|
assertNull(c.getArticles());
|
||||||
|
assertNotNull(c.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPage() throws Exception {
|
||||||
|
getMockData(get("/categories")).andDo(result -> {
|
||||||
|
Response<PageData<CategoryModel>> response = getResponse(result, CATEGORY_MODEL_PAGE_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
response.getResult().getList().forEach(c -> {
|
||||||
|
assertNotNull(c.getName());
|
||||||
|
assertNotNull(c.getId());
|
||||||
|
assertNotNull(c.getArticles());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package cn.celess.categorytag.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.celess.categorytag.CategoryTagBaseTest;
|
||||||
|
import cn.celess.common.entity.Response;
|
||||||
|
import cn.celess.common.entity.Tag;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.entity.vo.TagModel;
|
||||||
|
import cn.celess.common.mapper.TagMapper;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.celess.common.constant.ResponseEnum.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
public class TagControllerTest extends CategoryTagBaseTest {
|
||||||
|
@Autowired
|
||||||
|
TagMapper tagMapper;
|
||||||
|
private static final TypeReference<?> TAG_MODEL_TYPE = new TypeReference<Response<TagModel>>() {
|
||||||
|
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> TAG_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<TagModel>>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> TAG_NAC_LIST_TYPE = new TypeReference<Response<List<Map<String, Object>>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addOne() throws Exception {
|
||||||
|
String name = randomStr(4);
|
||||||
|
getMockData(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
|
getMockData(post("/admin/tag/create?name=" + name), userLogin()).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
|
getMockData(post("/admin/tag/create?name=" + name), adminLogin()).andDo(result -> {
|
||||||
|
Response<TagModel> response = getResponse(result, TAG_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
TagModel tag = response.getResult();
|
||||||
|
assertNotNull(tag.getId());
|
||||||
|
assertEquals(name, tag.getName());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delOne() throws Exception {
|
||||||
|
Tag lastestTag = tagMapper.getLastestTag();
|
||||||
|
assertNotNull(lastestTag.getId());
|
||||||
|
getMockData(delete("/admin/tag/del?id=" + lastestTag.getId()), adminLogin()).andDo(result -> {
|
||||||
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertTrue(response.getResult());
|
||||||
|
});
|
||||||
|
long id = lastestTag.getId() * 2;
|
||||||
|
getMockData(delete("/admin/tag/del?id=" + id), adminLogin())
|
||||||
|
.andDo(result -> assertEquals(TAG_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateOne() throws Exception {
|
||||||
|
Tag tag = tagMapper.getLastestTag();
|
||||||
|
assertNotNull(tag.getId());
|
||||||
|
String name = randomStr(4);
|
||||||
|
getMockData(put("/admin/tag/update?id=" + tag.getId() + "&name=" + name), adminLogin()).andDo(result -> {
|
||||||
|
Response<TagModel> response = getResponse(result, TAG_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
TagModel t = response.getResult();
|
||||||
|
assertEquals(name, t.getName());
|
||||||
|
assertEquals(tag.getId(), t.getId());
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPage() throws Exception {
|
||||||
|
getMockData(get("/tags?page=1&count=5")).andDo(result -> {
|
||||||
|
Response<PageData<TagModel>> response = getResponse(result, TAG_MODEL_PAGE_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
// 结果集非空
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
// 判断pageInfo是否包装完全
|
||||||
|
PageData<TagModel> pageData = response.getResult();
|
||||||
|
assertNotEquals(0, pageData.getTotal());
|
||||||
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(5, pageData.getPageSize());
|
||||||
|
// 内容完整
|
||||||
|
for (TagModel t : pageData.getList()) {
|
||||||
|
assertNotNull(t.getId());
|
||||||
|
assertNotNull(t.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getTagNameAndCount() throws Exception {
|
||||||
|
getMockData(get("/tags/nac")).andDo(result -> {
|
||||||
|
Response<List<Map<String, Object>>> response = getResponse(result, TAG_NAC_LIST_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
|
response.getResult().forEach(o -> {
|
||||||
|
assertNotNull(o.get("name"));
|
||||||
|
assertNotNull(o.get("size"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
34
blog-comment/pom.xml
Normal file
34
blog-comment/pom.xml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package cn.celess.comment.serviceimpl;
|
||||||
|
|
||||||
|
import cn.celess.common.constant.CommentStatusEnum;
|
||||||
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
|
import cn.celess.common.entity.Comment;
|
||||||
|
import cn.celess.common.entity.User;
|
||||||
|
import cn.celess.common.entity.dto.CommentReq;
|
||||||
|
import cn.celess.common.entity.vo.CommentModel;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
|
import cn.celess.common.mapper.CommentMapper;
|
||||||
|
import cn.celess.common.mapper.UserMapper;
|
||||||
|
import cn.celess.common.service.CommentService;
|
||||||
|
import cn.celess.common.util.ModalTrans;
|
||||||
|
import cn.celess.user.util.RedisUserUtil;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/03/29 17:05
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CommentServiceImpl implements CommentService {
|
||||||
|
@Autowired
|
||||||
|
CommentMapper commentMapper;
|
||||||
|
@Autowired
|
||||||
|
UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
@Autowired
|
||||||
|
HttpServletRequest request;
|
||||||
|
@Autowired
|
||||||
|
RedisUserUtil redisUserUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommentModel create(CommentReq reqBody) {
|
||||||
|
if (reqBody == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
User user = redisUserUtil.get();
|
||||||
|
Comment pComment = null;
|
||||||
|
if (reqBody.getPid() != -1) {
|
||||||
|
pComment = commentMapper.findCommentById(reqBody.getPid());
|
||||||
|
}
|
||||||
|
//不是一级评论
|
||||||
|
if (reqBody.getPid() != -1 && pComment == null) {
|
||||||
|
//父评论不存在
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
Comment comment = new Comment();
|
||||||
|
comment.setFromUser(user);
|
||||||
|
User userTo = new User();
|
||||||
|
userTo.setId(null);
|
||||||
|
if (reqBody.getToUserId() != -1) {
|
||||||
|
userTo = userMapper.findById(reqBody.getToUserId());
|
||||||
|
comment.setToUser(userTo);
|
||||||
|
}
|
||||||
|
comment.setToUser(userTo);
|
||||||
|
userMapper.findById(reqBody.getToUserId());
|
||||||
|
BeanUtils.copyProperties(reqBody, comment);
|
||||||
|
commentMapper.insert(comment);
|
||||||
|
return ModalTrans.comment(commentMapper.findCommentById(comment.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(long id) {
|
||||||
|
Comment b = commentMapper.findCommentById(id);
|
||||||
|
if (b == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.COMMENT_NOT_EXIST);
|
||||||
|
}
|
||||||
|
if (b.getStatus() == CommentStatusEnum.DELETED.getCode()) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.DATA_IS_DELETED);
|
||||||
|
}
|
||||||
|
commentMapper.delete(id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommentModel update(CommentReq reqBody) {
|
||||||
|
if (reqBody.getId() == null) {
|
||||||
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||||
|
}
|
||||||
|
Comment comment = commentMapper.findCommentById(reqBody.getId());
|
||||||
|
if (!comment.getContent().equals(reqBody.getContent())) {
|
||||||
|
commentMapper.updateContent(reqBody.getContent(), reqBody.getId());
|
||||||
|
comment.setContent(reqBody.getContent());
|
||||||
|
}
|
||||||
|
return ModalTrans.comment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<CommentModel> retrievePage(String pagePath, int page, int count) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Comment> list = commentMapper.findAllByPagePathAndPidAndNormal(pagePath, -1);
|
||||||
|
return pageTrans(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommentModel> retrievePageByPid(long pid) {
|
||||||
|
List<Comment> allByPagePath = commentMapper.findAllByPid(pid);
|
||||||
|
return allByPagePath
|
||||||
|
.stream()
|
||||||
|
.filter(comment -> comment.getStatus() != CommentStatusEnum.DELETED.getCode())
|
||||||
|
.map(ModalTrans::comment)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count) {
|
||||||
|
User user = redisUserUtil.get();
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Comment> list = commentMapper.findAllByPagePathAndFromUser(pagePath, user.getId());
|
||||||
|
return pageTrans(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||||
|
return pageTrans(list, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||||
|
return pageTrans(list, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PageData<CommentModel> pageTrans(List<Comment> commentList) {
|
||||||
|
return pageTrans(commentList, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PageData<CommentModel> pageTrans(List<Comment> commentList, boolean noResponseList) {
|
||||||
|
PageInfo<Comment> p = PageInfo.of(commentList);
|
||||||
|
List<CommentModel> modelList = commentList
|
||||||
|
.stream()
|
||||||
|
.map(ModalTrans::comment)
|
||||||
|
.peek(commentModel -> commentModel.setRespComment(this.retrievePageByPid(commentModel.getId())))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return new PageData<>(p, modelList);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
blog-comment/src/main/resources/banner.txt
Normal file
12
blog-comment/src/main/resources/banner.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
${AnsiColor.BRIGHT_GREEN}
|
||||||
|
_ _ _ ____ _ _____ _
|
||||||
|
| | | | (_) | _ \ | | / ____| | |
|
||||||
|
| |__| | _ | |_) | | | ___ __ _ ______ | | ___ _ __ ___ _ __ ___ ___ _ __ | |_
|
||||||
|
| __ | | | | _ < | | / _ \ / _` | |______| | | / _ \ | '_ ` _ \ | '_ ` _ \ / _ \ | '_ \ | __|
|
||||||
|
| | | | | | | |_) | | | | (_) | | (_| | | |____ | (_) | | | | | | | | | | | | | | __/ | | | | | |_
|
||||||
|
|_| |_| |_| |____/ |_| \___/ \__, | \_____| \___/ |_| |_| |_| |_| |_| |_| \___| |_| |_| \__|
|
||||||
|
__/ |
|
||||||
|
|___/
|
||||||
|
${AnsiColor.BRIGHT_RED}
|
||||||
|
Application Version: ${application.version}${application.formatted-version}
|
||||||
|
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package cn.celess.comment.controller;
|
||||||
|
|
||||||
|
import cn.celess.comment.CommentBaseTest;
|
||||||
|
import cn.celess.common.entity.Article;
|
||||||
|
import cn.celess.common.entity.Comment;
|
||||||
|
import cn.celess.common.entity.Response;
|
||||||
|
import cn.celess.common.entity.User;
|
||||||
|
import cn.celess.common.entity.dto.CommentReq;
|
||||||
|
import cn.celess.common.entity.vo.CommentModel;
|
||||||
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
|
import cn.celess.common.mapper.CommentMapper;
|
||||||
|
import cn.celess.common.mapper.UserMapper;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.celess.common.constant.ResponseEnum.DATA_IS_DELETED;
|
||||||
|
import static cn.celess.common.constant.ResponseEnum.SUCCESS;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
public class CommentControllerTest extends CommentBaseTest {
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
@Autowired
|
||||||
|
UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
CommentMapper commentMapper;
|
||||||
|
private static final TypeReference<?> COMMENT_MODEL_TYPE = new TypeReference<Response<CommentModel>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addOne() throws Exception {
|
||||||
|
Article article = articleMapper.getLastestArticle();
|
||||||
|
CommentReq commentReq = new CommentReq();
|
||||||
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
|
commentReq.setContent(randomStr());
|
||||||
|
List<User> all = userMapper.findAll();
|
||||||
|
commentReq.setPid(1L);
|
||||||
|
commentReq.setToUserId(2l);
|
||||||
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
CommentModel model = response.getResult();
|
||||||
|
assertNotEquals(0, model.getId());
|
||||||
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
|
assertEquals(1, model.getPid().longValue());
|
||||||
|
assertEquals(commentReq.getContent(), model.getContent());
|
||||||
|
assertNotNull(model.getDate());
|
||||||
|
assertNotNull(model.getFromUser());
|
||||||
|
assertNotNull(model.getToUser());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
|
commentReq.setContent(randomStr());
|
||||||
|
commentReq.setPid(-1L);
|
||||||
|
commentReq.setToUserId(2);
|
||||||
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
CommentModel model = response.getResult();
|
||||||
|
// 响应数据的完整性
|
||||||
|
assertNotEquals(0, model.getId());
|
||||||
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
|
assertEquals(-1, model.getPid().longValue());
|
||||||
|
assertEquals(commentReq.getContent(), model.getContent());
|
||||||
|
assertEquals(commentReq.getPagePath(), "/article/" + article.getId());
|
||||||
|
assertNotNull(model.getDate());
|
||||||
|
assertNotNull(model.getFromUser());
|
||||||
|
assertNotNull(model.getToUser());
|
||||||
|
});
|
||||||
|
|
||||||
|
// 测试二级回复
|
||||||
|
Comment latestComment = commentMapper.getLastestComment();
|
||||||
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
|
commentReq.setContent(randomStr());
|
||||||
|
commentReq.setPid(latestComment.getId());
|
||||||
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
CommentModel model = response.getResult();
|
||||||
|
// 重新获取父评论信息
|
||||||
|
Comment pCommon = commentMapper.findCommentById(latestComment.getId());
|
||||||
|
assertEquals(pCommon.getId(), model.getPid());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteTest() throws Exception {
|
||||||
|
// 准备数据
|
||||||
|
User from = userMapper.findByEmail("zh56462271@qq.com");
|
||||||
|
assertNotNull(from);
|
||||||
|
User to = userMapper.findByEmail("a@celess.cn");
|
||||||
|
assertNotNull(to);
|
||||||
|
|
||||||
|
Comment comment = new Comment();
|
||||||
|
comment.setContent(randomStr(8));
|
||||||
|
comment.setFromUser(from);
|
||||||
|
comment.setToUser(to);
|
||||||
|
comment.setPagePath("/tags");
|
||||||
|
comment.setPid(-1L);
|
||||||
|
commentMapper.insert(comment);
|
||||||
|
comment = commentMapper.findCommentById(comment.getId());
|
||||||
|
// 接口测试
|
||||||
|
long id = comment.getId();
|
||||||
|
assertNotEquals(0, id);
|
||||||
|
getMockData(delete("/user/comment/del?id=" + id), userLogin()).andDo(result -> {
|
||||||
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertTrue(response.getResult());
|
||||||
|
});
|
||||||
|
getMockData(delete("/user/comment/del?id=" + id), userLogin())
|
||||||
|
.andDo(result -> assertEquals(DATA_IS_DELETED.getCode(), getResponse(result, COMMENT_MODEL_TYPE).getCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() throws Exception {
|
||||||
|
Comment comment = commentMapper.getLastestComment();
|
||||||
|
CommentReq commentReq = new CommentReq();
|
||||||
|
commentReq.setId(comment.getId());
|
||||||
|
commentReq.setContent(randomStr());
|
||||||
|
// 不合法数据 setResponseId
|
||||||
|
getMockData(put("/user/comment/update"), userLogin(), commentReq).andDo(result -> {
|
||||||
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
CommentModel c = response.getResult();
|
||||||
|
assertEquals(commentReq.getContent(), c.getContent());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
116
blog-common/pom.xml
Normal file
116
blog-common/pom.xml
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package cn.celess.common.constant;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-25 08:58
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum CommentStatusEnum {
|
||||||
|
// 正常
|
||||||
|
NORMAL(0, "正常"),
|
||||||
|
DELETED(3, "已删除");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String msg;
|
||||||
|
|
||||||
|
CommentStatusEnum(int code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.celess.blog.enmu;
|
package cn.celess.common.constant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -11,6 +11,8 @@ public enum ResponseEnum {
|
|||||||
FAILURE(-1, "失败"),
|
FAILURE(-1, "失败"),
|
||||||
ERROR(-2, "错误"),
|
ERROR(-2, "错误"),
|
||||||
|
|
||||||
|
DATA_IS_DELETED(1000, "数据已被删除"),
|
||||||
|
|
||||||
//文章类
|
//文章类
|
||||||
ARTICLE_NOT_EXIST(2010, "文章不存在"),
|
ARTICLE_NOT_EXIST(2010, "文章不存在"),
|
||||||
ARTICLE_HAS_EXIST(2020, "文章已存在"),
|
ARTICLE_HAS_EXIST(2020, "文章已存在"),
|
||||||
@@ -31,6 +33,8 @@ public enum ResponseEnum {
|
|||||||
PWD_SAME(3601, "新密码与原密码相同"),
|
PWD_SAME(3601, "新密码与原密码相同"),
|
||||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||||
|
LOGOUT(3710, "账户已注销"),
|
||||||
|
CAN_NOT_USE(3711, "账户不可用"),
|
||||||
PWD_WRONG(3800, "密码不正确"),
|
PWD_WRONG(3800, "密码不正确"),
|
||||||
|
|
||||||
JWT_EXPIRED(3810, "Token过期"),
|
JWT_EXPIRED(3810, "Token过期"),
|
||||||
@@ -55,6 +59,11 @@ public enum ResponseEnum {
|
|||||||
DATA_HAS_EXIST(7020, "数据已存在"),
|
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, "非法访问"),
|
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||||
@@ -68,9 +77,8 @@ public enum ResponseEnum {
|
|||||||
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
|
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
|
||||||
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
|
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
|
||||||
VERIFY_OUT(8400, "已经验证过了");
|
VERIFY_OUT(8400, "已经验证过了");
|
||||||
|
private final int code;
|
||||||
private int code;
|
private final String msg;
|
||||||
private String msg;
|
|
||||||
|
|
||||||
|
|
||||||
ResponseEnum(int code, String msg) {
|
ResponseEnum(int code, String msg) {
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package cn.celess.common.constant;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 16:31
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum RoleEnum {
|
||||||
|
// admin 权限
|
||||||
|
ADMIN_ROLE("admin"),
|
||||||
|
// user 权限
|
||||||
|
USER_ROLE("user");
|
||||||
|
|
||||||
|
|
||||||
|
private final String roleName;
|
||||||
|
|
||||||
|
RoleEnum(String roleName) {
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package cn.celess.common.constant;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-22 21:32
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
public enum UserAccountStatusEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账户正常
|
||||||
|
*/
|
||||||
|
NORMAL(0, "正常"),
|
||||||
|
/**
|
||||||
|
* 账户被锁定
|
||||||
|
*/
|
||||||
|
LOCKED(1, "锁定"),
|
||||||
|
/**
|
||||||
|
* 账户被删除
|
||||||
|
*/
|
||||||
|
DELETED(2, "已删除");
|
||||||
|
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String desc;
|
||||||
|
|
||||||
|
UserAccountStatusEnum(int code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserAccountStatusEnum get(int code) {
|
||||||
|
for (UserAccountStatusEnum value : UserAccountStatusEnum.values()) {
|
||||||
|
if (value.code == code) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static UserAccountStatusEnum get(Map<String, Object> map) {
|
||||||
|
for (UserAccountStatusEnum value : UserAccountStatusEnum.values()) {
|
||||||
|
if (value.code == (int) map.get("code") && value.desc.equals(map.get("desc"))) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public Map<String, Object> toJson() {
|
||||||
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
|
map.put("code", code);
|
||||||
|
map.put("desc", desc);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/28 14:51
|
* @date : 2019/03/28 14:51
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Article {
|
public class Article implements Serializable {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,16 +43,6 @@ public class Article {
|
|||||||
|
|
||||||
private Date updateDate = null;
|
private Date updateDate = null;
|
||||||
|
|
||||||
private Long categoryId;
|
|
||||||
|
|
||||||
private String tagsId;
|
|
||||||
|
|
||||||
private Long authorId;
|
|
||||||
|
|
||||||
private Long preArticleId;
|
|
||||||
|
|
||||||
private Long nextArticleId;
|
|
||||||
|
|
||||||
private Long readingNumber;
|
private Long readingNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,4 +50,15 @@ public class Article {
|
|||||||
*/
|
*/
|
||||||
private Boolean open;
|
private Boolean open;
|
||||||
|
|
||||||
|
private Category category;
|
||||||
|
|
||||||
|
private List<Tag> tags;
|
||||||
|
|
||||||
|
private Integer likeCount;
|
||||||
|
|
||||||
|
private Integer dislikeCount;
|
||||||
|
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
private boolean deleted = false;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 14:52
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ArticleTag implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Article article;
|
||||||
|
|
||||||
|
private TagCategory tag;
|
||||||
|
|
||||||
|
public ArticleTag(Article article, TagCategory tag) {
|
||||||
|
this.article = article;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package cn.celess.common.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 Category(String name) {
|
||||||
|
super.setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 友链
|
* 友链
|
||||||
*
|
*
|
||||||
@@ -9,7 +11,7 @@ import lombok.Data;
|
|||||||
* @date : 2019/05/12 11:33
|
* @date : 2019/05/12 11:33
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PartnerSite {
|
public class PartnerSite implements Serializable {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@@ -19,6 +21,16 @@ public class PartnerSite {
|
|||||||
|
|
||||||
private Boolean open;
|
private Boolean open;
|
||||||
|
|
||||||
|
private String iconPath;
|
||||||
|
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
private Boolean delete = false;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private Boolean notification = true;
|
||||||
|
|
||||||
public PartnerSite() {
|
public PartnerSite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +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);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
blog-common/src/main/java/cn/celess/common/entity/Tag.java
Normal file
17
blog-common/src/main/java/cn/celess/common/entity/Tag.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.celess.common.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 Tag(String name) {
|
||||||
|
super.setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 14:03
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TagCategory implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Boolean category = true;
|
||||||
|
|
||||||
|
private Boolean deleted = false;
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +12,8 @@ import java.util.Date;
|
|||||||
* @date : 2019/03/28 14:52
|
* @date : 2019/03/28 14:52
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class User {
|
@NoArgsConstructor
|
||||||
|
public class User implements Serializable {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,12 +21,6 @@ public class User {
|
|||||||
*/
|
*/
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户唯一标识码
|
|
||||||
*/
|
|
||||||
@JsonIgnore
|
|
||||||
private String uid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
@@ -46,15 +43,12 @@ public class User {
|
|||||||
|
|
||||||
private Date recentlyLandedDate;
|
private Date recentlyLandedDate;
|
||||||
|
|
||||||
/**
|
|
||||||
* 随机码 用户验证邮箱/找回密码
|
|
||||||
* 暂时废弃这一字段
|
|
||||||
*/
|
|
||||||
private String emailVerifyId;
|
|
||||||
|
|
||||||
private String role = "user";
|
private String role = "user";
|
||||||
|
|
||||||
public User() {
|
private int status;
|
||||||
}
|
|
||||||
|
|
||||||
|
public User(String email, String pwd) {
|
||||||
|
this.email = email;
|
||||||
|
this.pwd = pwd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,12 +10,13 @@ import java.util.Date;
|
|||||||
* @date : 2019/04/02 22:14
|
* @date : 2019/04/02 22:14
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Visitor {
|
public class Visitor implements Serializable {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
private String ip;
|
private String ip;
|
||||||
private Date date;
|
private Date date;
|
||||||
private String ua;
|
private String ua;
|
||||||
|
private boolean delete;
|
||||||
|
|
||||||
public Visitor(String ip, Date date, String ua) {
|
public Visitor(String ip, Date date, String ua) {
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.common.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,7 +10,7 @@ import java.util.Date;
|
|||||||
* @date : 2019/05/12 11:29
|
* @date : 2019/05/12 11:29
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class WebUpdate {
|
public class WebUpdate implements Serializable {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@@ -17,11 +18,12 @@ public class WebUpdate {
|
|||||||
|
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
|
private boolean delete;
|
||||||
|
|
||||||
public WebUpdate() {
|
public WebUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebUpdate(String updateInfo, Date updateTime) {
|
public WebUpdate(String updateInfo) {
|
||||||
this.updateInfo = updateInfo;
|
this.updateInfo = updateInfo;
|
||||||
this.updateTime = updateTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.common.entity.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/06/01 22:46
|
* @date : 2019/06/01 22:46
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ArticleReq {
|
public class ArticleReq implements Serializable {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String title;
|
private String title;
|
||||||
private String mdContent;
|
private String mdContent;
|
||||||
private String tags;
|
private String[] tags;
|
||||||
private Boolean type;
|
private Boolean type;
|
||||||
private String url;
|
private String url;
|
||||||
private String category;
|
private String category;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.celess.common.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/06/02 10:35
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CommentReq implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
private String content;
|
||||||
|
private long pid = -1;
|
||||||
|
private String pagePath;
|
||||||
|
private long toUserId = -1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.celess.common.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2020/07/31 20:50
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LinkApplyReq implements Serializable {
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String url;
|
||||||
|
private String linkUrl;
|
||||||
|
private String desc;
|
||||||
|
private String iconPath;
|
||||||
|
}
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.common.entity.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/06/02 11:40
|
* @date : 2019/06/02 11:40
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class LinkReq {
|
public class LinkReq implements Serializable {
|
||||||
private long id;
|
private long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String url;
|
private String url;
|
||||||
|
private String iconPath;
|
||||||
|
private String desc;
|
||||||
private boolean open;
|
private boolean open;
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.common.entity.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/06/01 22:47
|
* @date : 2019/06/01 22:47
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class LoginReq {
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LoginReq implements Serializable {
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
/**
|
/**
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.common.entity.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
* @Date: 2019/09/06 13:33
|
* @Date: 2019/09/06 13:33
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class UserReq {
|
public class UserReq implements Serializable {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String email;
|
private String email;
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
import cn.celess.common.entity.Tag;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -11,7 +13,7 @@ import java.io.Serializable;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class ArticleModel {
|
public class ArticleModel implements Serializable {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,40 +59,30 @@ public class ArticleModel {
|
|||||||
/**
|
/**
|
||||||
* 标签
|
* 标签
|
||||||
*/
|
*/
|
||||||
private String[] tags;
|
private List<Tag> tags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作者
|
* 作者
|
||||||
*/
|
*/
|
||||||
private Long authorId;
|
private UserModel author;
|
||||||
|
|
||||||
/**
|
private ArticleModel preArticle;
|
||||||
* 作者名字
|
|
||||||
*/
|
|
||||||
private String authorName;
|
|
||||||
|
|
||||||
/**
|
private ArticleModel nextArticle;
|
||||||
* 上一篇文章
|
|
||||||
*/
|
|
||||||
private Long preArticleId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下一篇文章
|
|
||||||
*/
|
|
||||||
private Long nextArticleId;
|
|
||||||
|
|
||||||
private String preArticleTitle;
|
|
||||||
|
|
||||||
private String nextArticleTitle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阅读数
|
* 阅读数
|
||||||
*/
|
*/
|
||||||
private Long readingNumber;
|
private Long readingNumber;
|
||||||
|
|
||||||
|
private Integer likeCount;
|
||||||
|
|
||||||
|
private Integer dislikeCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章的状态 true:公开 false:不公开
|
* 文章的状态 true:公开 false:不公开
|
||||||
*/
|
*/
|
||||||
private Boolean open;
|
private Boolean open;
|
||||||
|
|
||||||
|
private boolean deleted;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-03-29 12:18
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CategoryModel implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private List<ArticleModel> articles;
|
||||||
|
private boolean deleted;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/04/22 21:50
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class CommentModel implements Serializable {
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private UserModel fromUser;
|
||||||
|
|
||||||
|
private UserModel toUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
private String pagePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布日期
|
||||||
|
*/
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论的父ID
|
||||||
|
*/
|
||||||
|
private Long pid;
|
||||||
|
|
||||||
|
private List<CommentModel> respComment;
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-25 17:13
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PageData<T> implements Serializable {
|
||||||
|
|
||||||
|
private List<T> list;
|
||||||
|
|
||||||
|
private long total;
|
||||||
|
|
||||||
|
private int pageSize;
|
||||||
|
|
||||||
|
private int pageNum;
|
||||||
|
|
||||||
|
public PageData(PageInfo pageInfo) {
|
||||||
|
this.pageNum = pageInfo.getPageNum();
|
||||||
|
this.pageSize = pageInfo.getPageSize();
|
||||||
|
this.total = pageInfo.getTotal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageData(PageInfo pageInfo, List<T> data) {
|
||||||
|
this(pageInfo);
|
||||||
|
this.list = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/04/21 22:43
|
* @date : 2019/04/21 22:43
|
||||||
*/
|
*/
|
||||||
public class QiniuResponse {
|
public class QiniuResponse implements Serializable {
|
||||||
public String key;
|
public String key;
|
||||||
public String hash;
|
public String hash;
|
||||||
public String bucket;
|
public String bucket;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-03-29 13:56
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TagModel implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private List<ArticleModel> articles;
|
||||||
|
|
||||||
|
private boolean deleted;
|
||||||
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
|
import cn.celess.common.constant.UserAccountStatusEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/04/22 23:13
|
* @date : 2019/04/22 23:13
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class UserModel {
|
public class UserModel implements Serializable {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@@ -37,4 +40,6 @@ public class UserModel {
|
|||||||
private String role = "user";
|
private String role = "user";
|
||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
private UserAccountStatusEnum status;
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/05/05 16:05
|
* @date : 2019/05/05 16:05
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class VisitorModel {
|
public class VisitorModel implements Serializable {
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String ip;
|
private String ip;
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.common.entity.vo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/05/12 11:32
|
* @date : 2019/05/12 11:32
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class WebUpdateModel {
|
public class WebUpdateModel implements Serializable {
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String info;
|
private String info;
|
||||||
@@ -21,4 +23,6 @@ public class WebUpdateModel {
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean deleted;
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package cn.celess.blog.exception;
|
package cn.celess.common.exception;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.common.entity.Response;
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.common.service.MailService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.common.util.DateFormatUtil;
|
||||||
|
import cn.celess.common.util.EnvironmentUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
@@ -25,52 +25,50 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class ExceptionHandle {
|
public class BlogExceptionHandler {
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(BlogExceptionHandler.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
MailService mailService;
|
MailService mailService;
|
||||||
@Autowired
|
@Autowired
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
|
|
||||||
|
|
||||||
@Value("${spring.profiles.active}")
|
|
||||||
private String activeModel;
|
|
||||||
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Response handle(Exception e) {
|
public Response handle(Exception e) {
|
||||||
//自定义错误
|
//自定义错误
|
||||||
if (e instanceof MyException) {
|
if (e instanceof BlogResponseException) {
|
||||||
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
|
BlogResponseException exception = (BlogResponseException) e;
|
||||||
return new Response(((MyException) e).getCode(), e.getMessage(), null, System.currentTimeMillis());
|
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
|
||||||
|
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
|
||||||
}
|
}
|
||||||
//请求路径不支持该方法
|
//请求路径不支持该方法
|
||||||
if (e instanceof HttpRequestMethodNotSupportedException) {
|
if (e instanceof HttpRequestMethodNotSupportedException) {
|
||||||
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={},path:{},method:{}]", e.getMessage(), request.getRequestURL(), request.getMethod());
|
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={},path:{},method:{}]", e.getMessage(), request.getRequestURL(), request.getMethod());
|
||||||
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null, System.currentTimeMillis());
|
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null);
|
||||||
}
|
}
|
||||||
//数据输入类型不匹配
|
//数据输入类型不匹配
|
||||||
if (e instanceof MethodArgumentTypeMismatchException) {
|
if (e instanceof MethodArgumentTypeMismatchException) {
|
||||||
logger.debug("输入类型不匹配,[msg={}]", e.getMessage());
|
logger.debug("输入类型不匹配,[msg={}]", e.getMessage());
|
||||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null, System.currentTimeMillis());
|
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null);
|
||||||
}
|
}
|
||||||
//数据验证失败
|
//数据验证失败
|
||||||
if (e instanceof BindException) {
|
if (e instanceof BindException) {
|
||||||
logger.debug("数据验证失败,[msg={}]", e.getMessage());
|
logger.debug("数据验证失败,[msg={}]", e.getMessage());
|
||||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null, System.currentTimeMillis());
|
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null);
|
||||||
}
|
}
|
||||||
//数据输入不完整
|
//数据输入不完整
|
||||||
if (e instanceof MissingServletRequestParameterException) {
|
if (e instanceof MissingServletRequestParameterException) {
|
||||||
logger.debug("数据输入不完整,[msg={}]", e.getMessage());
|
logger.debug("数据输入不完整,[msg={}]", e.getMessage());
|
||||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null, System.currentTimeMillis());
|
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送错误信息到邮箱
|
// 发送错误信息到邮箱
|
||||||
if ("prod".equals(activeModel)) {
|
if ("prod".equals(EnvironmentUtil.getProperties("spring.profiles.active", "dev"))) {
|
||||||
logger.debug("有一个未捕获的bug,已发送到邮箱");
|
logger.debug("有一个未捕获的bug,已发送到邮箱");
|
||||||
sendMessage(e);
|
sendMessage(e);
|
||||||
}
|
}
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null, System.currentTimeMillis());
|
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +81,12 @@ public class ExceptionHandle {
|
|||||||
simpleMailMessage.setTo("a@celess.cn");
|
simpleMailMessage.setTo("a@celess.cn");
|
||||||
simpleMailMessage.setSubject("服务器出现了错误");
|
simpleMailMessage.setSubject("服务器出现了错误");
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("requirePath:\n").append(request.getRequestURL().toString()).append("?").append(request.getQueryString()).append("\n\n\n");
|
String queryString = request.getQueryString();
|
||||||
|
msg.append("requirePath:\n").append(request.getRequestURL().toString());
|
||||||
|
if (queryString != null) {
|
||||||
|
msg.append("?").append(queryString);
|
||||||
|
}
|
||||||
|
msg.append("\n\n\n");
|
||||||
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
|
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
|
||||||
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
|
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
|
||||||
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
|
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package cn.celess.common.exception;
|
||||||
|
|
||||||
|
import cn.celess.common.constant.ResponseEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/03/28 16:56
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BlogResponseException extends RuntimeException {
|
||||||
|
private int code;
|
||||||
|
private Object result;
|
||||||
|
|
||||||
|
public BlogResponseException(int code, String msg) {
|
||||||
|
super(msg);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlogResponseException(ResponseEnum e) {
|
||||||
|
super(e.getMsg());
|
||||||
|
this.code = e.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlogResponseException(ResponseEnum e, Object result) {
|
||||||
|
super(e.getMsg());
|
||||||
|
this.code = e.getCode();
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlogResponseException(ResponseEnum e, String msg) {
|
||||||
|
super(msg + e.getMsg());
|
||||||
|
this.code = e.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlogResponseException(ResponseEnum e, String msg, Object result) {
|
||||||
|
super(e.getMsg());
|
||||||
|
this.code = e.getCode();
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
|
import cn.celess.common.entity.Article;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2019/06/27 20:43
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface ArticleMapper {
|
||||||
|
|
||||||
|
int insert(Article a);
|
||||||
|
|
||||||
|
int delete(long id);
|
||||||
|
|
||||||
|
int update(Article a);
|
||||||
|
|
||||||
|
Article getLastestArticle();
|
||||||
|
|
||||||
|
Article findArticleById(long id);
|
||||||
|
|
||||||
|
boolean existsByTitle(String title);
|
||||||
|
|
||||||
|
boolean isDeletedById(long id);
|
||||||
|
|
||||||
|
List<Article> findAllByAuthorId(long authorId);
|
||||||
|
|
||||||
|
List<Article> findAllByOpen(boolean isOpen);
|
||||||
|
|
||||||
|
String getTitleById(long id);
|
||||||
|
|
||||||
|
List<Article> findAllByCategoryId(long id);
|
||||||
|
|
||||||
|
List<Article> findAllByCategoryIdAndOpen(long id);
|
||||||
|
|
||||||
|
List<Article> findAll();
|
||||||
|
|
||||||
|
@Cacheable(value = {"articleDao"}, key = "'getPreArticle:'+#id")
|
||||||
|
Article getPreArticle(Long id);
|
||||||
|
|
||||||
|
@Cacheable(value = {"articleDao"}, key = "'getNextArticle:'+#id")
|
||||||
|
Article getNextArticle(Long id);
|
||||||
|
|
||||||
|
int updateReadingNumber(long id);
|
||||||
|
|
||||||
|
long count();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
|
import cn.celess.common.entity.ArticleTag;
|
||||||
|
import cn.celess.common.entity.Tag;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 14:21
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface ArticleTagMapper {
|
||||||
|
|
||||||
|
int insert(ArticleTag articleTag);
|
||||||
|
|
||||||
|
int update(ArticleTag articleTag);
|
||||||
|
|
||||||
|
ArticleTag findOneById(Long id);
|
||||||
|
|
||||||
|
int deleteById(Long id);
|
||||||
|
|
||||||
|
int deleteByArticleId(Long articleId);
|
||||||
|
|
||||||
|
List<ArticleTag> findAllByArticleId(Long articleId);
|
||||||
|
|
||||||
|
List<Tag> findTagByArticleId(Long articleId);
|
||||||
|
|
||||||
|
int deleteMultiById(List<ArticleTag> articleTags);
|
||||||
|
|
||||||
|
List<ArticleTag> findArticleByTag(Long tagId);
|
||||||
|
|
||||||
|
List<ArticleTag> findArticleByTagAndOpen(Long tagId);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Category;
|
import cn.celess.common.entity.Category;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ public interface CategoryMapper {
|
|||||||
|
|
||||||
String getNameById(long id);
|
String getNameById(long id);
|
||||||
|
|
||||||
Long getIDByName(String name);
|
Long getIdByName(String name);
|
||||||
|
|
||||||
Category getLastestCategory();
|
Category getLastestCategory();
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
|
import cn.celess.common.entity.Comment;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2019/06/30 16:19
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface CommentMapper {
|
||||||
|
int insert(Comment c);
|
||||||
|
|
||||||
|
int updateContent(String content, long id);
|
||||||
|
|
||||||
|
int delete(long id);
|
||||||
|
|
||||||
|
int deleteByPagePath(String pagePath);
|
||||||
|
|
||||||
|
boolean existsById(long id);
|
||||||
|
|
||||||
|
Comment findCommentById(long id);
|
||||||
|
|
||||||
|
Comment getLastestComment();
|
||||||
|
|
||||||
|
List<Comment> findAllByFromUser(long id);
|
||||||
|
|
||||||
|
List<Comment> findAllByPid(long pid);
|
||||||
|
|
||||||
|
List<Comment> findAllByPagePath(String pagePath);
|
||||||
|
|
||||||
|
List<Comment> findAllByPagePathAndFromUser(String pagePath, long userId);
|
||||||
|
|
||||||
|
List<Comment> findAllByPagePathAndPidAndNormal(String pagePath, long pid);
|
||||||
|
|
||||||
|
long countByPagePath(String pagePath);
|
||||||
|
|
||||||
|
long count();
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.common.entity.PartnerSite;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -36,5 +36,6 @@ public interface PartnerMapper {
|
|||||||
|
|
||||||
List<PartnerSite> findAll();
|
List<PartnerSite> findAll();
|
||||||
|
|
||||||
|
List<PartnerSite> findAll(Boolean deleted);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Tag;
|
import cn.celess.common.entity.Tag;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -26,10 +26,6 @@ public interface TagMapper {
|
|||||||
|
|
||||||
Boolean existsByName(String name);
|
Boolean existsByName(String name);
|
||||||
|
|
||||||
Long getIDByName(String name);
|
|
||||||
|
|
||||||
String getNameById(long id);
|
|
||||||
|
|
||||||
Tag getLastestTag();
|
Tag getLastestTag();
|
||||||
|
|
||||||
List<Tag> findAll();
|
List<Tag> findAll();
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.common.entity.User;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,13 +15,13 @@ import java.util.List;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
|
|
||||||
int addUser(String email, String pwd);
|
int addUser(User user);
|
||||||
|
|
||||||
int updateInfo(String desc, String displayName, long id);
|
int updateInfo(String desc, String displayName, long id);
|
||||||
|
|
||||||
int updateAvatarImgUrl(String avatarImgUrl, long id);
|
int updateAvatarImgUrl(String avatarImgUrl, long id);
|
||||||
|
|
||||||
int updateLoginTime(String email, Date date);
|
int updateLoginTime(String email);
|
||||||
|
|
||||||
int updateEmailStatus(String email, boolean status);
|
int updateEmailStatus(String email, boolean status);
|
||||||
|
|
||||||
@@ -50,7 +49,11 @@ public interface UserMapper {
|
|||||||
|
|
||||||
int delete(long id);
|
int delete(long id);
|
||||||
|
|
||||||
int setUserRole(Long uid, String role);
|
int lock(long id);
|
||||||
|
|
||||||
|
int setUserRole(Long id, String role);
|
||||||
|
|
||||||
|
List<User> findAll(Integer status);
|
||||||
|
|
||||||
List<User> findAll();
|
List<User> findAll();
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Visitor;
|
import cn.celess.common.entity.Visitor;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -20,5 +20,7 @@ public interface VisitorMapper {
|
|||||||
|
|
||||||
List<Visitor> findAll();
|
List<Visitor> findAll();
|
||||||
|
|
||||||
|
List<Visitor> findAllNotDeleted();
|
||||||
|
|
||||||
long count();
|
long count();
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.common.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.common.entity.WebUpdate;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,5 +26,7 @@ public interface WebUpdateInfoMapper {
|
|||||||
|
|
||||||
List<WebUpdate> findAll();
|
List<WebUpdate> findAll();
|
||||||
|
|
||||||
|
List<WebUpdate> findAllNotDeleted();
|
||||||
|
|
||||||
WebUpdate getLastestOne();
|
WebUpdate getLastestOne();
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
import cn.celess.common.entity.dto.ArticleReq;
|
||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
@@ -39,11 +39,11 @@ public interface ArticleService {
|
|||||||
/**
|
/**
|
||||||
* 获取一篇文章的数据
|
* 获取一篇文章的数据
|
||||||
*
|
*
|
||||||
* @param articleID 文章id
|
* @param articleId 文章id
|
||||||
* @param is4update 是否是因文章更新而请求数据
|
* @param is4update 是否是因文章更新而请求数据
|
||||||
* @return 文章数据
|
* @return 文章数据
|
||||||
*/
|
*/
|
||||||
ArticleModel retrieveOneByID(long articleID, boolean is4update);
|
ArticleModel retrieveOneById(long articleId, boolean is4update);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理员 获取分页数据
|
* 管理员 获取分页数据
|
||||||
@@ -52,7 +52,7 @@ public interface ArticleService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo adminArticles(int count, int page);
|
PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文章状态为开放的文章
|
* 获取文章状态为开放的文章
|
||||||
@@ -61,7 +61,7 @@ public interface ArticleService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo retrievePageForOpen(int count, int page);
|
PageData<ArticleModel> retrievePageForOpen(int count, int page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据分类名获取文章数据
|
* 根据分类名获取文章数据
|
||||||
@@ -71,7 +71,7 @@ public interface ArticleService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo findByCategory(String name, int page, int count);
|
PageData<ArticleModel> findByCategory(String name, int page, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据标签名获取文章数据
|
* 根据标签名获取文章数据
|
||||||
@@ -81,5 +81,5 @@ public interface ArticleService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo findByTag(String name, int page, int count);
|
PageData<ArticleModel> findByTag(String name, int page, int count);
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Category;
|
import cn.celess.common.entity.vo.CategoryModel;
|
||||||
import cn.celess.blog.entity.model.CategoryModel;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/28 22:42
|
* @date : 2019/03/28 22:42
|
||||||
@@ -20,14 +18,6 @@ public interface CategoryService {
|
|||||||
*/
|
*/
|
||||||
CategoryModel create(String name);
|
CategoryModel create(String name);
|
||||||
|
|
||||||
/**
|
|
||||||
* 增加一个分类
|
|
||||||
*
|
|
||||||
* @param category 分类对象
|
|
||||||
* @return 所增加的分类数据
|
|
||||||
*/
|
|
||||||
CategoryModel create(Category category);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过id删除分类
|
* 通过id删除分类
|
||||||
*
|
*
|
||||||
@@ -50,6 +40,6 @@ public interface CategoryService {
|
|||||||
*
|
*
|
||||||
* @return 全部的分类数据
|
* @return 全部的分类数据
|
||||||
*/
|
*/
|
||||||
List<CategoryModel> retrievePage();
|
PageData<CategoryModel> retrievePage(int page, int count);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package cn.celess.common.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.celess.common.entity.dto.CommentReq;
|
||||||
|
import cn.celess.common.entity.vo.CommentModel;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2019/03/29 16:58
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public interface CommentService {
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param reqBody 请求数据体
|
||||||
|
* @return 增加的comment数据
|
||||||
|
*/
|
||||||
|
CommentModel create(CommentReq reqBody);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据
|
||||||
|
*
|
||||||
|
* @param id comment的id
|
||||||
|
* @return 删除状态
|
||||||
|
*/
|
||||||
|
boolean delete(long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新数据
|
||||||
|
*
|
||||||
|
* @param reqBody comment请求体
|
||||||
|
* @return 更新后的数据
|
||||||
|
*/
|
||||||
|
CommentModel update(CommentReq reqBody);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取数据
|
||||||
|
*
|
||||||
|
* @param pagePath pagePath
|
||||||
|
* @param count 单页数据量
|
||||||
|
* @param page 数据页
|
||||||
|
* @return 分页数据
|
||||||
|
*/
|
||||||
|
PageData<CommentModel> retrievePage(String pagePath, int page, int count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过pid获取数据
|
||||||
|
*
|
||||||
|
* @param pid 父id
|
||||||
|
* @return 分页数据
|
||||||
|
*/
|
||||||
|
List<CommentModel> retrievePageByPid(long pid);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论者获取数据
|
||||||
|
*
|
||||||
|
* @param pagePath pagePath
|
||||||
|
* @param count 单页数据量
|
||||||
|
* @param page 数据页
|
||||||
|
* @return 分页数据
|
||||||
|
*/
|
||||||
|
PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据数据的type和pid获取数据
|
||||||
|
*
|
||||||
|
* @param pagePath pagePath
|
||||||
|
* @param pid 父id
|
||||||
|
* @param count 单页数据量
|
||||||
|
* @param page 数据页
|
||||||
|
* @return 分页数据
|
||||||
|
*/
|
||||||
|
PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据type获取数据
|
||||||
|
*
|
||||||
|
* @param pagePath pagePath
|
||||||
|
* @param count 单页数据量
|
||||||
|
* @param page 数据页
|
||||||
|
* @return 分页数据
|
||||||
|
*/
|
||||||
|
PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -36,13 +36,6 @@ public interface CountService {
|
|||||||
*/
|
*/
|
||||||
long getTagsCount();
|
long getTagsCount();
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取留言数量
|
|
||||||
*
|
|
||||||
* @return 留言数量
|
|
||||||
*/
|
|
||||||
long getLeaveMessageCount();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户量
|
* 获取用户量
|
||||||
*
|
*
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.common.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.common.entity.dto.LinkApplyReq;
|
||||||
import com.github.pagehelper.PageInfo;
|
import cn.celess.common.entity.dto.LinkReq;
|
||||||
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,7 +45,7 @@ public interface PartnerSiteService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<PartnerSite> PartnerSitePages(int page, int count);
|
PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部数据
|
* 获取全部数据
|
||||||
@@ -53,4 +54,19 @@ public interface PartnerSiteService {
|
|||||||
*/
|
*/
|
||||||
List<PartnerSite> findAll();
|
List<PartnerSite> findAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请友链
|
||||||
|
*
|
||||||
|
* @param linkApplyReq linkApplyReq
|
||||||
|
* @return linkApplyReq
|
||||||
|
*/
|
||||||
|
PartnerSite apply(LinkApplyReq linkApplyReq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写申请友链
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @return msg
|
||||||
|
*/
|
||||||
|
String reapply(String key);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.model.QiniuResponse;
|
import cn.celess.common.entity.vo.QiniuResponse;
|
||||||
import com.qiniu.storage.model.FileInfo;
|
import com.qiniu.storage.model.FileInfo;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Tag;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.common.entity.vo.TagModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,15 +20,6 @@ public interface TagService {
|
|||||||
*/
|
*/
|
||||||
TagModel create(String name);
|
TagModel create(String name);
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增数据
|
|
||||||
*
|
|
||||||
* @param tag tag对象
|
|
||||||
* @return 新增后的数据
|
|
||||||
*/
|
|
||||||
|
|
||||||
TagModel create(Tag tag);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除数据
|
* 删除数据
|
||||||
*
|
*
|
||||||
@@ -47,23 +37,6 @@ public interface TagService {
|
|||||||
*/
|
*/
|
||||||
TagModel update(Long id, String name);
|
TagModel update(Long id, String name);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询单个标签信息
|
|
||||||
*
|
|
||||||
* @param tagId id
|
|
||||||
* @return 标签的数据
|
|
||||||
*/
|
|
||||||
TagModel retrieveOneById(long tagId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过name查询标签的信息
|
|
||||||
*
|
|
||||||
* @param name tag的名称
|
|
||||||
* @return 标签数据
|
|
||||||
*/
|
|
||||||
TagModel retrieveOneByName(String name);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页获取标签数据
|
* 分页获取标签数据
|
||||||
*
|
*
|
||||||
@@ -71,7 +44,7 @@ public interface TagService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<TagModel> retrievePage(int page, int count);
|
PageData<TagModel> retrievePage(int page, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部标签数据
|
* 获取全部标签数据
|
||||||
@@ -1,16 +1,12 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.common.entity.dto.LoginReq;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.common.entity.dto.UserReq;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.blog.entity.request.UserReq;
|
import cn.celess.common.entity.vo.UserModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -42,14 +38,6 @@ public interface UserService {
|
|||||||
*/
|
*/
|
||||||
Object logout();
|
Object logout();
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户头像的链接
|
|
||||||
*
|
|
||||||
* @param id 用户id
|
|
||||||
* @return 头像链接
|
|
||||||
*/
|
|
||||||
String getAvatarImg(long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户数据
|
* 更新用户数据
|
||||||
*
|
*
|
||||||
@@ -83,14 +71,6 @@ public interface UserService {
|
|||||||
*/
|
*/
|
||||||
String getUserRoleByEmail(String email);
|
String getUserRoleByEmail(String email);
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过邮箱获取用户的信息
|
|
||||||
*
|
|
||||||
* @param email 用户邮箱
|
|
||||||
* @return 用户信息
|
|
||||||
*/
|
|
||||||
User getUserInfoByEmail(String email);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取邮箱是否注册过
|
* 获取邮箱是否注册过
|
||||||
*
|
*
|
||||||
@@ -99,14 +79,6 @@ public interface UserService {
|
|||||||
*/
|
*/
|
||||||
boolean isExistOfEmail(String email);
|
boolean isExistOfEmail(String email);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户的name 优先返回displayName 否则返回email
|
|
||||||
*
|
|
||||||
* @param id 用户id
|
|
||||||
* @return name
|
|
||||||
*/
|
|
||||||
String getNameById(long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送重置密码邮件
|
* 发送重置密码邮件
|
||||||
*
|
*
|
||||||
@@ -157,7 +129,7 @@ public interface UserService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<UserModel> getUserList(Integer page, Integer count);
|
PageData<UserModel> getUserList(Integer page, Integer count, Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改用户信息
|
* 更改用户信息
|
||||||
@@ -177,10 +149,11 @@ public interface UserService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置密码
|
* 设置密码
|
||||||
* @param pwd
|
*
|
||||||
* @param newPwd
|
* @param pwd pwd
|
||||||
* @param confirmPwd
|
* @param newPwd newPwd
|
||||||
* @return
|
* @param confirmPwd confirmPwd
|
||||||
|
* @return UserModel
|
||||||
*/
|
*/
|
||||||
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
|
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.model.VisitorModel;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import com.github.pagehelper.PageInfo;
|
import cn.celess.common.entity.vo.VisitorModel;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -20,7 +20,7 @@ public interface VisitorService {
|
|||||||
* @param showLocation 是否显示位置信息 开启改选项数据响应超慢
|
* @param showLocation 是否显示位置信息 开启改选项数据响应超慢
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<VisitorModel> visitorPage(int page, int count, boolean showLocation);
|
PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增访客
|
* 新增访客
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.common.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.common.entity.vo.WebUpdateModel;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -45,7 +46,7 @@ public interface WebUpdateInfoService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<WebUpdateModel> pages(int count, int page);
|
PageData<WebUpdateModel> pages(int count, int page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部的更新记录
|
* 获取全部的更新记录
|
||||||
@@ -59,5 +60,5 @@ public interface WebUpdateInfoService {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JSONObject getLastestUpdateTime();
|
Map<String, Object> getLastestUpdateTime();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
331
blog-common/src/main/java/cn/celess/common/test/BaseTest.java
Normal file
331
blog-common/src/main/java/cn/celess/common/test/BaseTest.java
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
package cn.celess.common.test;
|
||||||
|
|
||||||
|
import cn.celess.common.entity.Response;
|
||||||
|
import cn.celess.common.entity.dto.LoginReq;
|
||||||
|
import cn.celess.common.entity.vo.QiniuResponse;
|
||||||
|
import cn.celess.common.entity.vo.UserModel;
|
||||||
|
import cn.celess.common.service.MailService;
|
||||||
|
import cn.celess.common.service.QiniuService;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.qiniu.storage.model.FileInfo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static cn.celess.common.constant.ResponseEnum.SUCCESS;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2019/08/22 12:46
|
||||||
|
* @Description: 测试基类
|
||||||
|
*/
|
||||||
|
@WebAppConfiguration
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
public abstract class BaseTest {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
protected MockMvc mockMvc;
|
||||||
|
protected final static String Code = "code";
|
||||||
|
protected final static String Result = "result";
|
||||||
|
protected final static String USERE_MAIL = "zh56462271@qq.com";
|
||||||
|
protected final static String ADMIN_EMAIL = "a@celess.cn";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jackson 序列化/反序列化Json
|
||||||
|
*/
|
||||||
|
protected static final TypeReference<?> BOOLEAN_TYPE = new TypeReference<Response<Boolean>>() {
|
||||||
|
};
|
||||||
|
protected static final TypeReference<?> STRING_TYPE = new TypeReference<Response<String>>() {
|
||||||
|
};
|
||||||
|
protected static final TypeReference<?> OBJECT_TYPE = new TypeReference<Response<Object>>() {
|
||||||
|
};
|
||||||
|
protected static final TypeReference<?> MAP_OBJECT_TYPE = new TypeReference<Response<Map<String, Object>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebApplicationContext wac;
|
||||||
|
protected MockHttpSession session;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
||||||
|
session = new MockHttpSession();
|
||||||
|
System.out.println("==========> 开始测试 <=========");
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after() {
|
||||||
|
System.out.println("==========> 测试结束 <=========");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* admin 权限用户登录
|
||||||
|
*
|
||||||
|
* @return token
|
||||||
|
*/
|
||||||
|
protected String adminLogin() {
|
||||||
|
LoginReq req = new LoginReq();
|
||||||
|
req.setEmail(ADMIN_EMAIL);
|
||||||
|
req.setPassword("123456789");
|
||||||
|
req.setIsRememberMe(true);
|
||||||
|
String token = login(req);
|
||||||
|
assertNotNull(token);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user 权限用户登录
|
||||||
|
*
|
||||||
|
* @return token
|
||||||
|
*/
|
||||||
|
protected String userLogin() {
|
||||||
|
LoginReq req = new LoginReq();
|
||||||
|
req.setEmail(USERE_MAIL);
|
||||||
|
req.setPassword("123456789");
|
||||||
|
req.setIsRememberMe(true);
|
||||||
|
String token = login(req);
|
||||||
|
assertNotNull(token);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录逻辑
|
||||||
|
*
|
||||||
|
* @param req 用户信息
|
||||||
|
* @return token | null
|
||||||
|
*/
|
||||||
|
protected String login(LoginReq req) {
|
||||||
|
String str = null;
|
||||||
|
try {
|
||||||
|
str = getMockData(MockMvcRequestBuilders.post("/login"), null, req)
|
||||||
|
.andReturn().getResponse().getContentAsString();
|
||||||
|
Response<UserModel> response = new ObjectMapper().readValue(str, new TypeReference<Response<UserModel>>() {
|
||||||
|
});
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
String token = response.getResult().getToken();
|
||||||
|
assertNotNull(token);
|
||||||
|
return token;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("测试登录错误");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
assertNotNull(str);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产生指定长度的随机字符
|
||||||
|
*
|
||||||
|
* @param len len
|
||||||
|
* @return str
|
||||||
|
*/
|
||||||
|
protected String randomStr(int len) {
|
||||||
|
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产生指定长度的随机字符
|
||||||
|
*
|
||||||
|
* @return str
|
||||||
|
*/
|
||||||
|
protected String randomStr() {
|
||||||
|
return UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽离的mock请求方法
|
||||||
|
*
|
||||||
|
* @param builder MockHttpServletRequestBuilder :get(...) post(...) ....
|
||||||
|
* @return 返回 ResultActions
|
||||||
|
* @throws Exception exc
|
||||||
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder) throws Exception {
|
||||||
|
return getMockData(builder, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽离的mock请求方法 重载
|
||||||
|
*
|
||||||
|
* @param builder ..
|
||||||
|
* @param token 用户登录的token
|
||||||
|
* @return ..
|
||||||
|
* @throws Exception ..
|
||||||
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token) throws Exception {
|
||||||
|
return getMockData(builder, token, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽离的mock请求方法 重载
|
||||||
|
*
|
||||||
|
* @param builder ..
|
||||||
|
* @param token ..
|
||||||
|
* @param content http中发送的APPLICATION_JSON的json数据
|
||||||
|
* @return ..
|
||||||
|
* @throws Exception ..
|
||||||
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token, Object content) throws Exception {
|
||||||
|
// MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(url);
|
||||||
|
if (token != null) {
|
||||||
|
builder.header("Authorization", "Bearer "+token);
|
||||||
|
}
|
||||||
|
if (content != null) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
builder.content(mapper.writeValueAsString(content)).contentType(MediaType.APPLICATION_JSON);
|
||||||
|
logger.debug("param::json->{}", mapper.writeValueAsString(content));
|
||||||
|
}
|
||||||
|
return mockMvc.perform(builder).andExpect(MockMvcResultMatchers.status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected <T> Response<T> getResponse(String json) {
|
||||||
|
return getResponse(json, OBJECT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> Response<T> getResponse(MvcResult result) {
|
||||||
|
return getResponse(result, OBJECT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据json 信息反序列化成Response对象
|
||||||
|
*
|
||||||
|
* @param json json
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @return Response对象
|
||||||
|
*/
|
||||||
|
protected <T> Response<T> getResponse(String json, TypeReference<?> responseType) {
|
||||||
|
Response<T> response = null;
|
||||||
|
try {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
|
||||||
|
response = mapper.readValue(json, responseType);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("解析json Response对象错误,json:[{}]", json);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
assertNotNull(response);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据json 信息反序列化成Response对象
|
||||||
|
*
|
||||||
|
* @param result MvcResult
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @return Response对象
|
||||||
|
*/
|
||||||
|
protected <T> Response<T> getResponse(MvcResult result, TypeReference<?> responseType) {
|
||||||
|
try {
|
||||||
|
return getResponse(result.getResponse().getContentAsString(), responseType);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.error("解析json Response对象错误,result:[{}]", result);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 mailService 的实现类
|
||||||
|
*
|
||||||
|
* @param service service 类
|
||||||
|
* @param mailFiledName service 中自动注入的mailService字段名
|
||||||
|
*/
|
||||||
|
protected void mockInjectInstance(Object service, String mailFiledName, Object impl) {
|
||||||
|
Field field;
|
||||||
|
try {
|
||||||
|
assertNotNull(service);
|
||||||
|
field = service.getClass().getDeclaredField(mailFiledName);
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(service, impl);
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("mailService")
|
||||||
|
public static class TestMailServiceImpl implements MailService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean AsyncSend(SimpleMailMessage message) {
|
||||||
|
log.debug("异步邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean send(SimpleMailMessage message) {
|
||||||
|
log.debug("邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转json
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getJson(Object o) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
return mapper.writeValueAsString(o);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("qiniuService")
|
||||||
|
public static class TestQiNiuServiceImpl implements QiniuService {
|
||||||
|
@Override
|
||||||
|
public QiniuResponse uploadFile(InputStream is, String fileName) {
|
||||||
|
QiniuResponse response = new QiniuResponse();
|
||||||
|
log.debug("上传文件请求,[fileName:{}]", fileName);
|
||||||
|
|
||||||
|
response.key = "key";
|
||||||
|
response.bucket = "bucket";
|
||||||
|
response.hash = "hash";
|
||||||
|
response.fsize = 1;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileInfo[] getFileList() {
|
||||||
|
log.debug("获取文件列表请求");
|
||||||
|
return new FileInfo[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.common.util;
|
||||||
|
|
||||||
import javax.xml.datatype.DatatypeConfigurationException;
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package cn.celess.common.util;
|
||||||
|
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||||
|
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
|
||||||
|
import com.gargoylesoftware.htmlunit.Page;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-04-23 15:51
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
public class HttpUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取http请求的响应
|
||||||
|
*
|
||||||
|
* @param url url链接
|
||||||
|
* @return 请求的响应
|
||||||
|
*/
|
||||||
|
public static String getHttpResponse(String url) {
|
||||||
|
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
|
||||||
|
webClient.getOptions().setCssEnabled(false);
|
||||||
|
webClient.getOptions().setJavaScriptEnabled(false);
|
||||||
|
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
|
||||||
|
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
||||||
|
webClient.getOptions().setDownloadImages(false);
|
||||||
|
webClient.getOptions().setActiveXNative(false);
|
||||||
|
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
|
||||||
|
Page clientPage = webClient.getPage(url);
|
||||||
|
return clientPage.getWebResponse().getContentAsString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取渲染后的网页数据
|
||||||
|
*
|
||||||
|
* @param url url链接
|
||||||
|
* @return 经js渲染后的网页源代码
|
||||||
|
*/
|
||||||
|
public static String getAfterRendering(String url) {
|
||||||
|
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
|
||||||
|
webClient.getOptions().setCssEnabled(false);
|
||||||
|
webClient.getOptions().setJavaScriptEnabled(true);
|
||||||
|
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
|
||||||
|
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
||||||
|
webClient.getOptions().setDownloadImages(false);
|
||||||
|
webClient.getOptions().setActiveXNative(false);
|
||||||
|
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
|
||||||
|
final HtmlPage page = webClient.getPage(url);
|
||||||
|
return page.asXml();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
112
blog-common/src/main/java/cn/celess/common/util/ModalTrans.java
Normal file
112
blog-common/src/main/java/cn/celess/common/util/ModalTrans.java
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
package cn.celess.common.util;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.celess.common.constant.UserAccountStatusEnum;
|
||||||
|
import cn.celess.common.entity.*;
|
||||||
|
import cn.celess.common.entity.vo.*;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 18:04
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
public class ModalTrans {
|
||||||
|
|
||||||
|
public static ArticleModel article(Article article) {
|
||||||
|
if (article == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArticleModel articleModel = new ArticleModel();
|
||||||
|
BeanUtils.copyProperties(article, articleModel);
|
||||||
|
articleModel.setPublishDateFormat(DateFormatUtil.get(article.getPublishDate()));
|
||||||
|
articleModel.setUpdateDateFormat(DateFormatUtil.get(article.getUpdateDate()));
|
||||||
|
articleModel.setOriginal(article.getType());
|
||||||
|
articleModel.setCategory(article.getCategory().getName());
|
||||||
|
articleModel.setAuthor(user(article.getUser()));
|
||||||
|
articleModel.getTags().forEach(tag -> {
|
||||||
|
tag.setCategory(null);
|
||||||
|
tag.setDeleted(null);
|
||||||
|
});
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ArticleModel article(Article article, boolean noMdContent) {
|
||||||
|
ArticleModel article1 = article(article);
|
||||||
|
if (!noMdContent || article1 == null) {
|
||||||
|
return article1;
|
||||||
|
}
|
||||||
|
article1.setMdContent(null);
|
||||||
|
article1.setOpen(null);
|
||||||
|
return article1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserModel userFullInfo(User user) {
|
||||||
|
if (user == null || user.getId() == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
UserModel userModel = new UserModel();
|
||||||
|
BeanUtils.copyProperties(user, userModel);
|
||||||
|
userModel.setStatus(UserAccountStatusEnum.get(user.getStatus()));
|
||||||
|
userModel.setAvatarImgUrl(user.getAvatarImgUrl() == null || user.getAvatarImgUrl().length() == 0 ?
|
||||||
|
null :
|
||||||
|
"http://cdn.celess.cn/" + user.getAvatarImgUrl());
|
||||||
|
userModel.setDisplayName(user.getDisplayName() == null ? user.getEmail() : user.getDisplayName());
|
||||||
|
userModel.setRecentlyLandedDate(DateFormatUtil.get(user.getRecentlyLandedDate()));
|
||||||
|
return userModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserModel user(User user) {
|
||||||
|
UserModel model = userFullInfo(user);
|
||||||
|
if (model == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
model.setRole(null);
|
||||||
|
model.setEmailStatus(null);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CategoryModel category(Category category) {
|
||||||
|
if (category == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CategoryModel model = new CategoryModel();
|
||||||
|
BeanUtils.copyProperties(category, model);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static TagModel tag(Tag tag) {
|
||||||
|
if (tag == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TagModel model = new TagModel();
|
||||||
|
BeanUtils.copyProperties(tag, model);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static WebUpdateModel webUpdate(WebUpdate update) {
|
||||||
|
if (update == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
WebUpdateModel model = new WebUpdateModel();
|
||||||
|
model.setId(update.getId());
|
||||||
|
model.setInfo(update.getUpdateInfo());
|
||||||
|
model.setTime(DateFormatUtil.get(update.getUpdateTime()));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommentModel comment(Comment comment) {
|
||||||
|
if (comment == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CommentModel model = new CommentModel();
|
||||||
|
BeanUtils.copyProperties(comment, model);
|
||||||
|
model.setFromUser(user(comment.getFromUser()));
|
||||||
|
model.setToUser(user(comment.getToUser()));
|
||||||
|
model.setDate(DateFormatUtil.get(comment.getDate()));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.common.util;
|
||||||
|
|
||||||
|
|
||||||
import com.dyuproject.protostuff.LinkedBuffer;
|
import com.dyuproject.protostuff.LinkedBuffer;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.common.util;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -20,8 +20,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* Redis工具类
|
* Redis工具类
|
||||||
*
|
*
|
||||||
* @author WangFan
|
* @author WangFan
|
||||||
* @date 2018-02-24 下午03:09:50
|
|
||||||
* @version 1.1 (GitHub文档: https://github.com/whvcse/RedisUtil )
|
* @version 1.1 (GitHub文档: https://github.com/whvcse/RedisUtil )
|
||||||
|
* @date 2018-02-24 下午03:09:50
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -29,14 +29,14 @@ public class RedisUtil {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redisTemplate;
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
public void setRedisTemplate(StringRedisTemplate redisTemplate) {
|
|
||||||
this.redisTemplate = redisTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringRedisTemplate getRedisTemplate() {
|
public StringRedisTemplate getRedisTemplate() {
|
||||||
return this.redisTemplate;
|
return this.redisTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRedisTemplate(StringRedisTemplate redisTemplate) {
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
/** -------------------key相关操作--------------------- */
|
/** -------------------key相关操作--------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,6 +196,7 @@ public class RedisUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置指定 key 的值
|
* 设置指定 key 的值
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
@@ -205,6 +206,7 @@ public class RedisUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定 key 的值
|
* 获取指定 key 的值
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -214,6 +216,7 @@ public class RedisUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回 key 中字符串值的子字符
|
* 返回 key 中字符串值的子字符
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param start
|
* @param start
|
||||||
* @param end
|
* @param end
|
||||||
@@ -259,10 +262,8 @@ public class RedisUtil {
|
|||||||
* 设置ASCII码, 字符串'a'的ASCII码是97, 转为二进制是'01100001', 此方法是将二进制第offset位值变为value
|
* 设置ASCII码, 字符串'a'的ASCII码是97, 转为二进制是'01100001', 此方法是将二进制第offset位值变为value
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param postion
|
* @param offset 位置
|
||||||
* 位置
|
* @param value 值,true为1, false为0
|
||||||
* @param value
|
|
||||||
* 值,true为1, false为0
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean setBit(String key, long offset, boolean value) {
|
public boolean setBit(String key, long offset, boolean value) {
|
||||||
@@ -274,10 +275,8 @@ public class RedisUtil {
|
|||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @param timeout
|
* @param timeout 过期时间
|
||||||
* 过期时间
|
* @param unit 时间单位, 天:TimeUnit.DAYS 小时:TimeUnit.HOURS 分钟:TimeUnit.MINUTES
|
||||||
* @param unit
|
|
||||||
* 时间单位, 天:TimeUnit.DAYS 小时:TimeUnit.HOURS 分钟:TimeUnit.MINUTES
|
|
||||||
* 秒:TimeUnit.SECONDS 毫秒:TimeUnit.MILLISECONDS
|
* 秒:TimeUnit.SECONDS 毫秒:TimeUnit.MILLISECONDS
|
||||||
*/
|
*/
|
||||||
public void setEx(String key, String value, long timeout, TimeUnit unit) {
|
public void setEx(String key, String value, long timeout, TimeUnit unit) {
|
||||||
@@ -300,8 +299,7 @@ public class RedisUtil {
|
|||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @param offset
|
* @param offset 从指定位置开始覆写
|
||||||
* 从指定位置开始覆写
|
|
||||||
*/
|
*/
|
||||||
public void setRange(String key, String value, long offset) {
|
public void setRange(String key, String value, long offset) {
|
||||||
redisTemplate.opsForValue().set(key, value, offset);
|
redisTemplate.opsForValue().set(key, value, offset);
|
||||||
@@ -340,7 +338,7 @@ public class RedisUtil {
|
|||||||
* 增加(自增长), 负数则为自减
|
* 增加(自增长), 负数则为自减
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param increment
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Long incrBy(String key, long increment) {
|
public Long incrBy(String key, long increment) {
|
||||||
@@ -348,9 +346,8 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param increment
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Double incrByFloat(String key, double increment) {
|
public Double incrByFloat(String key, double increment) {
|
||||||
@@ -526,10 +523,8 @@ public class RedisUtil {
|
|||||||
* 获取列表指定范围内的元素
|
* 获取列表指定范围内的元素
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param start
|
* @param start 开始位置, 0是开始位置
|
||||||
* 开始位置, 0是开始位置
|
* @param end 结束位置, -1返回所有
|
||||||
* @param end
|
|
||||||
* 结束位置, -1返回所有
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<String> lRange(String key, long start, long end) {
|
public List<String> lRange(String key, long start, long end) {
|
||||||
@@ -548,7 +543,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@@ -558,7 +552,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@@ -591,7 +584,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@@ -601,7 +593,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@@ -611,7 +602,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@@ -647,8 +637,7 @@ public class RedisUtil {
|
|||||||
* 通过索引设置列表元素的值
|
* 通过索引设置列表元素的值
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param index
|
* @param index 位置
|
||||||
* 位置
|
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public void lSet(String key, long index, String value) {
|
public void lSet(String key, long index, String value) {
|
||||||
@@ -669,10 +658,8 @@ public class RedisUtil {
|
|||||||
* 移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
* 移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param timeout
|
* @param timeout 等待时间
|
||||||
* 等待时间
|
* @param unit 时间单位
|
||||||
* @param unit
|
|
||||||
* 时间单位
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String lBLeftPop(String key, long timeout, TimeUnit unit) {
|
public String lBLeftPop(String key, long timeout, TimeUnit unit) {
|
||||||
@@ -693,10 +680,8 @@ public class RedisUtil {
|
|||||||
* 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
* 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param timeout
|
* @param timeout 等待时间
|
||||||
* 等待时间
|
* @param unit 时间单位
|
||||||
* @param unit
|
|
||||||
* 时间单位
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String lBRightPop(String key, long timeout, TimeUnit unit) {
|
public String lBRightPop(String key, long timeout, TimeUnit unit) {
|
||||||
@@ -734,8 +719,7 @@ public class RedisUtil {
|
|||||||
* 删除集合中值等于value得元素
|
* 删除集合中值等于value得元素
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param index
|
* @param index index=0, 删除所有值等于value的元素; index>0, 从头部开始删除第一个值等于value的元素;
|
||||||
* index=0, 删除所有值等于value的元素; index>0, 从头部开始删除第一个值等于value的元素;
|
|
||||||
* index<0, 从尾部开始删除第一个值等于value的元素;
|
* index<0, 从尾部开始删除第一个值等于value的元素;
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@@ -981,8 +965,6 @@ public class RedisUtil {
|
|||||||
* 获取集合所有元素
|
* 获取集合所有元素
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param otherKeys
|
|
||||||
* @param destKey
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<String> setMembers(String key) {
|
public Set<String> setMembers(String key) {
|
||||||
@@ -1022,7 +1004,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param options
|
* @param options
|
||||||
* @return
|
* @return
|
||||||
@@ -1046,7 +1027,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param values
|
* @param values
|
||||||
* @return
|
* @return
|
||||||
@@ -1056,7 +1036,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param values
|
* @param values
|
||||||
* @return
|
* @return
|
||||||
@@ -1103,10 +1082,8 @@ public class RedisUtil {
|
|||||||
* 获取集合的元素, 从小到大排序
|
* 获取集合的元素, 从小到大排序
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param start
|
* @param start 开始位置
|
||||||
* 开始位置
|
* @param end 结束位置, -1查询所有
|
||||||
* @param end
|
|
||||||
* 结束位置, -1查询所有
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<String> zRange(String key, long start, long end) {
|
public Set<String> zRange(String key, long start, long end) {
|
||||||
@@ -1130,10 +1107,8 @@ public class RedisUtil {
|
|||||||
* 根据Score值查询集合元素
|
* 根据Score值查询集合元素
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param min
|
* @param min 最小值
|
||||||
* 最小值
|
* @param max 最大值
|
||||||
* @param max
|
|
||||||
* 最大值
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<String> zRangeByScore(String key, double min, double max) {
|
public Set<String> zRangeByScore(String key, double min, double max) {
|
||||||
@@ -1144,10 +1119,8 @@ public class RedisUtil {
|
|||||||
* 根据Score值查询集合元素, 从小到大排序
|
* 根据Score值查询集合元素, 从小到大排序
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param min
|
* @param min 最小值
|
||||||
* 最小值
|
* @param max 最大值
|
||||||
* @param max
|
|
||||||
* 最大值
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<TypedTuple<String>> zRangeByScoreWithScores(String key,
|
public Set<TypedTuple<String>> zRangeByScoreWithScores(String key,
|
||||||
@@ -1156,7 +1129,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param min
|
* @param min
|
||||||
* @param max
|
* @param max
|
||||||
@@ -1224,7 +1196,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param min
|
* @param min
|
||||||
* @param max
|
* @param max
|
||||||
@@ -1318,7 +1289,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param otherKeys
|
* @param otherKeys
|
||||||
* @param destKey
|
* @param destKey
|
||||||
@@ -1359,7 +1329,6 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param options
|
* @param options
|
||||||
* @return
|
* @return
|
||||||
@@ -1370,6 +1339,7 @@ public class RedisUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Redis List 序列化
|
* 获取Redis List 序列化
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param targetClass
|
* @param targetClass
|
||||||
* @param <T>
|
* @param <T>
|
||||||
@@ -1399,12 +1369,9 @@ public class RedisUtil {
|
|||||||
public <T> boolean putListCacheWithExpireTime(String key, List<T> objList, final long expireTime) {
|
public <T> boolean putListCacheWithExpireTime(String key, List<T> objList, final long expireTime) {
|
||||||
final byte[] bkey = key.getBytes();
|
final byte[] bkey = key.getBytes();
|
||||||
final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
|
final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
|
||||||
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
|
boolean result = redisTemplate.execute((RedisCallback<Boolean>) connection -> {
|
||||||
@Override
|
|
||||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
|
||||||
connection.setEx(bkey, expireTime, bvalue);
|
connection.setEx(bkey, expireTime, bvalue);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user