Compare commits
182 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
59b7be00eb | ||
|
|
0e26eab2e6 | ||
|
|
2f6a9679da | ||
|
|
778c2dba58 | ||
|
|
5b8700930b | ||
|
|
18477706d1 | ||
|
|
cd7e6b6378 | ||
|
|
d934fbe284 | ||
|
|
55589c6a59 | ||
|
|
4ab402ccf8 | ||
|
|
c74aea6c3b | ||
|
|
7c2b8d8d28 | ||
|
|
6798cae1b8 | ||
|
|
ba7a02c5c0 | ||
|
|
bd50cfc339 | ||
|
|
e282e16fd3 | ||
|
|
18366b7aa4 | ||
|
|
66dffbfefe | ||
|
|
a7cd83a6b5 | ||
|
|
0a5921b66d | ||
|
|
e04238f0c9 | ||
|
|
09cb012b14 | ||
|
|
922b83e169 | ||
|
|
1cd6e0d7c9 |
26
.github/workflows/build.yml
vendored
Normal file
26
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||||
|
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||||
|
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
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: Deploy
|
||||||
|
run: mvn -B test --file pom.xml && curl http://bt.celess.cn:2271/hook?access_key=$KEY
|
||||||
29
.github/workflows/test.yml
vendored
Normal file
29
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||||
|
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||||
|
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# env:
|
||||||
|
# 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: Test
|
||||||
|
run: mvn -B test --file pom.xml
|
||||||
|
|
||||||
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,8 +1,8 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*.imi
|
*.imi
|
||||||
|
*.iml
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# 本地项目的私有文件
|
# 本地项目的私有文件
|
||||||
back-end/blog-dev.sql
|
|
||||||
src/main/resources/application-prod.properties
|
|
||||||
src/main/resources/application-dev.properties
|
src/main/resources/application-dev.properties
|
||||||
|
src/main/resources/application-prod.properties
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
image: maven:3.3.9-jdk-8
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .m2/repository
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
|
|
||||||
test:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- cp "$APP_TEST" ./src/main/resources/application-test.properties
|
|
||||||
- mvn clean test && cat target/site/jacoco/index.html
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
stage: deploy
|
|
||||||
script:
|
|
||||||
- cp "$APP_PROD" ./src/main/resources/application-prod.properties
|
|
||||||
- mvn package -DskipTests
|
|
||||||
- eval $(ssh-agent -s)
|
|
||||||
- ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 --decode)
|
|
||||||
- mkdir -p ~/.ssh
|
|
||||||
- chmod 700 ~/.ssh
|
|
||||||
- ssh-keyscan celess.cn >> ~/.ssh/known_hosts
|
|
||||||
- chmod 644 ~/.ssh/known_hosts
|
|
||||||
- scp target/blog-0.0.1-SNAPSHOT.jar root@celess.cn:/www/wwwroot/api.celess.cn
|
|
||||||
- ssh root@celess.cn "cd /www/wwwroot/api.celess.cn && bash build.sh"
|
|
||||||
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
|
||||||
|
|||||||
32
README.md
32
README.md
@@ -1,11 +1,19 @@
|
|||||||
# 小海博客后端管理系统
|
<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://www.celess.cn)
|
||||||
|
</div>
|
||||||
|
|
||||||
### 主要使用的技术
|
> 请配合前端项目一起食用 [https://github.com/xiaohai2271/blog-frontEnd](https://github.com/xiaohai2271/blog-frontEnd)
|
||||||
|
## 🎈主要使用的技术
|
||||||
|
|
||||||
| 使用的技术 | 名称 | 版本 |
|
| 使用的技术 | 名称 | 版本 |
|
||||||
| :--------------: | :--------: | :-----------: |
|
| :--------------: | :--------: | :-----------: |
|
||||||
@@ -20,16 +28,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` 图片上传的跨域问题
|
|
||||||
|
|||||||
149
blog.iml
149
blog.iml
@@ -1,149 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="Spring" name="Spring">
|
|
||||||
<configuration />
|
|
||||||
</facet>
|
|
||||||
<facet type="web" name="Web">
|
|
||||||
<configuration>
|
|
||||||
<webroots />
|
|
||||||
<sourceRoots>
|
|
||||||
<root url="file://$MODULE_DIR$/src/main/java" />
|
|
||||||
<root url="file://$MODULE_DIR$/src/main/resources" />
|
|
||||||
</sourceRoots>
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.11.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.16" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.16" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.16" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.14.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: mysql:mysql-connector-java:8.0.15" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.11.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.23.4" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.9.10" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.9.10" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.6.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.alibaba:druid:1.1.14" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.6" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-core:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-schema:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.4.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.0.0.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.youbenzi:MDTool:1.2.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.minidev:json-smart:2.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.minidev:accessors-smart:1.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.sf.json-lib:json-lib:jdk15:2.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.8.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.qiniu:qiniu-java-sdk:7.2.27" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.squareup.okhttp3:okhttp:3.14.4" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-mail:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.6.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.lettuce:lettuce-core:5.1.4.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.33.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.33.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.33.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.33.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.33.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.33.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.2.6.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.1.3.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.1.5.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.2.12" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.2.12" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.1.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:2.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.dyuproject.protostuff:protostuff-core:1.0.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.dyuproject.protostuff:protostuff-api:1.0.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.dyuproject.protostuff:protostuff-runtime:1.0.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.dyuproject.protostuff:protostuff-collectionschema:1.0.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: eu.bitwalker:UserAgentUtils:1.20" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt:0.9.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.8" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
92
blog.sql
92
blog.sql
@@ -1,92 +0,0 @@
|
|||||||
CREATE DATABASE `blog`;
|
|
||||||
|
|
||||||
USE blog;
|
|
||||||
|
|
||||||
CREATE TABLE `article`
|
|
||||||
(
|
|
||||||
`a_id` bigint(20) primary key auto_increment,
|
|
||||||
`a_title` varchar(255) not null unique comment '文章标题',
|
|
||||||
`a_summary` varchar(255) not null comment '文章摘要',
|
|
||||||
`a_md_content` longtext not null comment '文章Markdown内容',
|
|
||||||
`a_tags_id` varchar(255) not null comment '标签id \',\'处于最尾端',
|
|
||||||
`a_category_id` bigint(20) not null comment '分类的id',
|
|
||||||
`a_url` tinytext default null comment '转载文章的原文链接',
|
|
||||||
`a_author_id` bigint(20) not null comment '作者id',
|
|
||||||
`a_is_open` boolean default true comment '文章是否可见',
|
|
||||||
`a_is_original` boolean default true comment '文章是否原创',
|
|
||||||
`next_a_id` bigint(20) default -1 comment '下篇文章id',
|
|
||||||
`pre_a_id` bigint(20) default -1 comment '前一篇文章的id',
|
|
||||||
`a_reading_number` int default 0 comment '文章阅读数',
|
|
||||||
`a_publish_date` datetime not null comment '文章发布时间',
|
|
||||||
`a_update_date` datetime default null comment '文章的更新时间'
|
|
||||||
) DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci,comment '文章表';
|
|
||||||
|
|
||||||
CREATE TABLE `tag`
|
|
||||||
(
|
|
||||||
`tag_id` bigint(20) primary key auto_increment,
|
|
||||||
`tag_name` varchar(255) unique not null,
|
|
||||||
`articles` tinytext default null comment 'tag对应的文章id'
|
|
||||||
) comment '标签表';
|
|
||||||
|
|
||||||
CREATE table `category`
|
|
||||||
(
|
|
||||||
`c_id` bigint(20) primary key auto_increment,
|
|
||||||
`c_name` varchar(255) unique not null,
|
|
||||||
`articles` varchar(255) comment '分类下的文章'
|
|
||||||
)comment '分类表';
|
|
||||||
|
|
||||||
CREATE TABLE `comment`
|
|
||||||
(
|
|
||||||
`co_id` bigint(20) primary key auto_increment,
|
|
||||||
`co_article_id` bigint(20) default -1 comment '文章id',
|
|
||||||
`is_comment` boolean default true comment '是否是评论',
|
|
||||||
`author_id` bigint(20) not null comment '留言者id',
|
|
||||||
`co_content` text not null comment '评论/留言内容',
|
|
||||||
`co_date` datetime not null comment '评论/留言的日期',
|
|
||||||
`co_pid` bigint not null default -1 comment '评论/留言的父id',
|
|
||||||
`co_response_id` tinytext
|
|
||||||
) DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci,comment '评论/留言表';
|
|
||||||
|
|
||||||
CREATE TABLE `links`
|
|
||||||
(
|
|
||||||
`site_id` bigint(20) primary key auto_increment,
|
|
||||||
`site_name` varchar(255) not null comment '友站名称',
|
|
||||||
`is_open` boolean default true comment '是否公开',
|
|
||||||
`site_url` varchar(255) not null comment '首页地址'
|
|
||||||
) comment '友站表';
|
|
||||||
|
|
||||||
CREATE TABLE `visitor`
|
|
||||||
(
|
|
||||||
`v_id` bigint(20) primary key auto_increment,
|
|
||||||
`v_date` datetime not null comment '访问时间',
|
|
||||||
`v_ip` varchar(255) not null comment '访客ip',
|
|
||||||
`v_user_agent` text comment '访客ua'
|
|
||||||
) comment '访客表';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `web_update`
|
|
||||||
(
|
|
||||||
`update_id` bigint(20) primary key auto_increment,
|
|
||||||
`update_info` varchar(255) not null comment '更新内容',
|
|
||||||
`update_time` datetime not null comment '更新时间'
|
|
||||||
) comment '更新内容表';
|
|
||||||
|
|
||||||
create table `user`
|
|
||||||
(
|
|
||||||
`u_id` int not null primary key auto_increment,
|
|
||||||
`u_email` varchar(50) not null,
|
|
||||||
`u_uid` varchar(40) default null comment '用户唯一标识码',
|
|
||||||
`u_pwd` varchar(40) not null comment '密码',
|
|
||||||
`email_status` boolean default false comment '邮箱验证状态',
|
|
||||||
`u_avatar` varchar(255) comment '用户头像',
|
|
||||||
`u_desc` tinytext comment '用户的描述',
|
|
||||||
`recently_landed_time` datetime comment '最近的登录时间',
|
|
||||||
`email_verify_id` varchar(40) comment '用于找回密码或验证邮箱的id',
|
|
||||||
`display_name` varchar(30) comment '展示的昵称',
|
|
||||||
`role` varchar(40) not null default 'user' comment '权限组',
|
|
||||||
unique key `uni_user_id` (`u_id`),
|
|
||||||
unique key `uni_user_uid` (`u_uid`),
|
|
||||||
unique key `uni_user_email` (`u_email`)
|
|
||||||
) comment '用户表';
|
|
||||||
|
|
||||||
8
build.sh
8
build.sh
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "查询已存在进程"
|
|
||||||
pgrep -af blog-0.0.1-SNAPSHOT.jar
|
|
||||||
echo "结束已存在进程"
|
|
||||||
pkill -f blog-0.0.1-SNAPSHOT.jar
|
|
||||||
echo "开始运行小海博客"
|
|
||||||
nohup java -jar -Dfile.encoding=UTF-8 blog-0.0.1-SNAPSHOT.jar >blog.log &
|
|
||||||
echo "更新结束"
|
|
||||||
4079
doc/API.md
Normal file
4079
doc/API.md
Normal file
File diff suppressed because it is too large
Load Diff
32
doc/Build.md
Normal file
32
doc/Build.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# 如何构建
|
||||||
|
### 1. 构建前准备
|
||||||
|
- 安装jdk
|
||||||
|
- 安装maven(也可使使用项目中的maven wrapper)
|
||||||
|
- 安装mysql
|
||||||
|
- 安装redis
|
||||||
|
- 获取七牛云的AccessKey/SecretKey (个人中心-密钥管理) [七牛云官网](https://www.qiniu.com/)
|
||||||
|
|
||||||
|
### 2. 拉取项目到本地
|
||||||
|
``` shell script
|
||||||
|
git clone https://github.com/xiaohai2271/blog-backEnd.git
|
||||||
|
或 git clone git@github.com:xiaohai2271/blog-backEnd.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. maven构建
|
||||||
|
```shell script
|
||||||
|
mvn package
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 运行
|
||||||
|
```shell script
|
||||||
|
java -jar target/blog-0.0.1-SNAPSHOT.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 其他命令
|
||||||
|
```shell script
|
||||||
|
mvn clean # 清理项目资源
|
||||||
|
mvn clean package # 清理项目资源并重新打包
|
||||||
|
mvn clean package -DskipTest # 清理项目资源,重新打包并跳过测试
|
||||||
|
mvn test # 运行测试
|
||||||
|
..... #待添加
|
||||||
|
```
|
||||||
98
mvnw
vendored
98
mvnw
vendored
@@ -8,7 +8,7 @@
|
|||||||
# "License"); you may not use this file except in compliance
|
# "License"); you may not use this file except in compliance
|
||||||
# with the License. You may obtain a copy of the License at
|
# with the License. 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,
|
# Unless required by applicable law or agreed to in writing,
|
||||||
# software distributed under the License is distributed on an
|
# software distributed under the License is distributed on an
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Maven2 Start Up Batch script
|
# Maven Start Up Batch script
|
||||||
#
|
#
|
||||||
# Required ENV vars:
|
# Required ENV vars:
|
||||||
# ------------------
|
# ------------------
|
||||||
@@ -47,19 +47,18 @@ if [ -z "$MAVEN_SKIP_RC" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# OS specific support. $var _must_ be set to either true or false.
|
# OS specific support. $var _must_ be set to either true or false.
|
||||||
cygwin=false
|
cygwin=false;
|
||||||
darwin=false
|
darwin=false;
|
||||||
mingw=false
|
mingw=false
|
||||||
case "$(uname)" in
|
case "`uname`" in
|
||||||
CYGWIN*) cygwin=true ;;
|
CYGWIN*) cygwin=true ;;
|
||||||
MINGW*) mingw=true;;
|
MINGW*) mingw=true;;
|
||||||
Darwin*)
|
Darwin*) darwin=true
|
||||||
darwin=true
|
|
||||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
if [ -x "/usr/libexec/java_home" ]; then
|
if [ -x "/usr/libexec/java_home" ]; then
|
||||||
export JAVA_HOME="$(/usr/libexec/java_home)"
|
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||||
else
|
else
|
||||||
export JAVA_HOME="/Library/Java/Home"
|
export JAVA_HOME="/Library/Java/Home"
|
||||||
fi
|
fi
|
||||||
@@ -69,7 +68,7 @@ esac
|
|||||||
|
|
||||||
if [ -z "$JAVA_HOME" ] ; then
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
if [ -r /etc/gentoo-release ] ; then
|
if [ -r /etc/gentoo-release ] ; then
|
||||||
JAVA_HOME=$(java-config --jre-home)
|
JAVA_HOME=`java-config --jre-home`
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -79,21 +78,21 @@ if [ -z "$M2_HOME" ]; then
|
|||||||
|
|
||||||
# need this for relative symlinks
|
# need this for relative symlinks
|
||||||
while [ -h "$PRG" ] ; do
|
while [ -h "$PRG" ] ; do
|
||||||
ls=$(ls -ld "$PRG")
|
ls=`ls -ld "$PRG"`
|
||||||
link=$(expr "$ls" : '.*-> \(.*\)$')
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
PRG="$link"
|
PRG="$link"
|
||||||
else
|
else
|
||||||
PRG="$(dirname "$PRG")/$link"
|
PRG="`dirname "$PRG"`/$link"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
saveddir=$(pwd)
|
saveddir=`pwd`
|
||||||
|
|
||||||
M2_HOME=$(dirname "$PRG")/..
|
M2_HOME=`dirname "$PRG"`/..
|
||||||
|
|
||||||
# make it fully qualified
|
# make it fully qualified
|
||||||
M2_HOME=$(cd "$M2_HOME" && pwd)
|
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||||
|
|
||||||
cd "$saveddir"
|
cd "$saveddir"
|
||||||
# echo Using m2 at $M2_HOME
|
# echo Using m2 at $M2_HOME
|
||||||
@@ -102,41 +101,35 @@ fi
|
|||||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||||
if $cygwin ; then
|
if $cygwin ; then
|
||||||
[ -n "$M2_HOME" ] &&
|
[ -n "$M2_HOME" ] &&
|
||||||
M2_HOME=$(cygpath --unix "$M2_HOME")
|
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||||
[ -n "$JAVA_HOME" ] &&
|
[ -n "$JAVA_HOME" ] &&
|
||||||
JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
|
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||||
[ -n "$CLASSPATH" ] &&
|
[ -n "$CLASSPATH" ] &&
|
||||||
CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
|
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||||
if $mingw ; then
|
if $mingw ; then
|
||||||
[ -n "$M2_HOME" ] &&
|
[ -n "$M2_HOME" ] &&
|
||||||
M2_HOME="$( (
|
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||||
cd "$M2_HOME"
|
|
||||||
pwd
|
|
||||||
))"
|
|
||||||
[ -n "$JAVA_HOME" ] &&
|
[ -n "$JAVA_HOME" ] &&
|
||||||
JAVA_HOME="$( (
|
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||||
cd "$JAVA_HOME"
|
|
||||||
pwd
|
|
||||||
))"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
javaExecutable="$(which javac)"
|
javaExecutable="`which javac`"
|
||||||
if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then
|
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||||
# readlink(1) is not available as standard on Solaris 10.
|
# readlink(1) is not available as standard on Solaris 10.
|
||||||
readLink=$(which readlink)
|
readLink=`which readlink`
|
||||||
if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then
|
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||||
if $darwin ; then
|
if $darwin ; then
|
||||||
javaHome="$(dirname \"$javaExecutable\")"
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac"
|
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||||
else
|
else
|
||||||
javaExecutable="$(readlink -f \"$javaExecutable\")"
|
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||||
fi
|
fi
|
||||||
javaHome="$(dirname \"$javaExecutable\")"
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
|
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||||
JAVA_HOME="$javaHome"
|
JAVA_HOME="$javaHome"
|
||||||
export JAVA_HOME
|
export JAVA_HOME
|
||||||
fi
|
fi
|
||||||
@@ -152,7 +145,7 @@ if [ -z "$JAVACMD" ]; then
|
|||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="$(which java)"
|
JAVACMD="`which java`"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -172,7 +165,8 @@ CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
|||||||
# first directory with .mvn subdirectory is considered project base directory
|
# first directory with .mvn subdirectory is considered project base directory
|
||||||
find_maven_basedir() {
|
find_maven_basedir() {
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
echo "Path not specified to find_maven_basedir"
|
echo "Path not specified to find_maven_basedir"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -186,10 +180,7 @@ find_maven_basedir() {
|
|||||||
fi
|
fi
|
||||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||||
if [ -d "${wdir}" ]; then
|
if [ -d "${wdir}" ]; then
|
||||||
wdir=$(
|
wdir=`cd "$wdir/.."; pwd`
|
||||||
cd "$wdir/.."
|
|
||||||
pwd
|
|
||||||
)
|
|
||||||
fi
|
fi
|
||||||
# end of workaround
|
# end of workaround
|
||||||
done
|
done
|
||||||
@@ -203,9 +194,9 @@ concat_lines() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
BASE_DIR=$(find_maven_basedir "$(pwd)")
|
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||||
if [ -z "$BASE_DIR" ]; then
|
if [ -z "$BASE_DIR" ]; then
|
||||||
exit 1
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
@@ -221,15 +212,12 @@ else
|
|||||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||||
fi
|
fi
|
||||||
if [ -n "$MVNW_REPOURL" ]; then
|
if [ -n "$MVNW_REPOURL" ]; then
|
||||||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
|
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||||
else
|
else
|
||||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
|
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||||
fi
|
fi
|
||||||
while IFS="=" read key value; do
|
while IFS="=" read key value; do
|
||||||
case "$key" in wrapperUrl)
|
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||||
jarUrl="$value"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
@@ -237,7 +225,7 @@ else
|
|||||||
fi
|
fi
|
||||||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||||
if $cygwin; then
|
if $cygwin; then
|
||||||
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
|
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v wget > /dev/null; then
|
if command -v wget > /dev/null; then
|
||||||
@@ -266,7 +254,7 @@ else
|
|||||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||||
# For Cygwin, switch paths to Windows format before running javac
|
# For Cygwin, switch paths to Windows format before running javac
|
||||||
if $cygwin; then
|
if $cygwin; then
|
||||||
javaClass=$(cygpath --path --windows "$javaClass")
|
javaClass=`cygpath --path --windows "$javaClass"`
|
||||||
fi
|
fi
|
||||||
if [ -e "$javaClass" ]; then
|
if [ -e "$javaClass" ]; then
|
||||||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
@@ -299,13 +287,13 @@ MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
|||||||
# For Cygwin, switch paths to Windows format before running java
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
if $cygwin; then
|
if $cygwin; then
|
||||||
[ -n "$M2_HOME" ] &&
|
[ -n "$M2_HOME" ] &&
|
||||||
M2_HOME=$(cygpath --path --windows "$M2_HOME")
|
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||||
[ -n "$JAVA_HOME" ] &&
|
[ -n "$JAVA_HOME" ] &&
|
||||||
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
|
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||||
[ -n "$CLASSPATH" ] &&
|
[ -n "$CLASSPATH" ] &&
|
||||||
CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
|
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||||
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
|
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Provide a "standardized" way to retrieve the CLI args that will
|
# Provide a "standardized" way to retrieve the CLI args that will
|
||||||
|
|||||||
8
mvnw.cmd
vendored
8
mvnw.cmd
vendored
@@ -7,7 +7,7 @@
|
|||||||
@REM "License"); you may not use this file except in compliance
|
@REM "License"); you may not use this file except in compliance
|
||||||
@REM with the License. You may obtain a copy of the License at
|
@REM with the License. You may obtain a copy of the License at
|
||||||
@REM
|
@REM
|
||||||
@REM https://www.apache.org/licenses/LICENSE-2.0
|
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||||
@REM
|
@REM
|
||||||
@REM Unless required by applicable law or agreed to in writing,
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
@REM software distributed under the License is distributed on an
|
@REM software distributed under the License is distributed on an
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
@REM ----------------------------------------------------------------------------
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
@REM ----------------------------------------------------------------------------
|
@REM ----------------------------------------------------------------------------
|
||||||
@REM Maven2 Start Up Batch script
|
@REM Maven Start Up Batch script
|
||||||
@REM
|
@REM
|
||||||
@REM Required ENV vars:
|
@REM Required ENV vars:
|
||||||
@REM JAVA_HOME - location of a JDK home dir
|
@REM JAVA_HOME - location of a JDK home dir
|
||||||
@@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
|||||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
|
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||||
|
|
||||||
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||||
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
||||||
@@ -134,7 +134,7 @@ if exist %WRAPPER_JAR% (
|
|||||||
)
|
)
|
||||||
) else (
|
) else (
|
||||||
if not "%MVNW_REPOURL%" == "" (
|
if not "%MVNW_REPOURL%" == "" (
|
||||||
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
|
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||||
)
|
)
|
||||||
if "%MVNW_VERBOSE%" == "true" (
|
if "%MVNW_VERBOSE%" == "true" (
|
||||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||||
|
|||||||
69
pom.xml
69
pom.xml
@@ -55,12 +55,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>2.9.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>1.9.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--MarkDown 2 html -->
|
<!--MarkDown 2 html -->
|
||||||
@@ -76,14 +76,6 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Json-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.sf.json-lib</groupId>
|
|
||||||
<artifactId>json-lib</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
<classifier>jdk15</classifier>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 七牛云SDK -->
|
<!-- 七牛云SDK -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.qiniu</groupId>
|
<groupId>com.qiniu</groupId>
|
||||||
@@ -148,6 +140,41 @@
|
|||||||
<artifactId>jjwt</artifactId>
|
<artifactId>jjwt</artifactId>
|
||||||
<version>0.9.1</version>
|
<version>0.9.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- OkHttp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>4.8.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
|
<version>1.3.72</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sourceforge.htmlunit</groupId>
|
||||||
|
<artifactId>htmlunit</artifactId>
|
||||||
|
<version>2.42.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>1.4.200</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.kstyrc</groupId>
|
||||||
|
<artifactId>embedded-redis</artifactId>
|
||||||
|
<version>0.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -157,21 +184,15 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
<version>0.7.9</version>
|
<version>1.3.72</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>pre-unit-test</id>
|
<id>compile</id>
|
||||||
|
<phase>process-sources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>prepare-agent</goal>
|
<goal>compile</goal>
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>post-unit-test</id>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.celess.blog.configuration;
|
package cn.celess.blog.configuration;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
@@ -13,6 +14,9 @@ import org.springframework.web.filter.CorsFilter;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class CorsConfig {
|
public class CorsConfig {
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String activeModel;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CorsFilter corsFilter() {
|
public CorsFilter corsFilter() {
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
@@ -22,14 +26,17 @@ public class CorsConfig {
|
|||||||
config.addAllowedOrigin("https://celess.cn");
|
config.addAllowedOrigin("https://celess.cn");
|
||||||
config.addAllowedOrigin("https://www.celess.cn");
|
config.addAllowedOrigin("https://www.celess.cn");
|
||||||
// 本地调试时的跨域
|
// 本地调试时的跨域
|
||||||
|
if (!"prod".equals(activeModel)) {
|
||||||
config.addAllowedOrigin("http://localhost:4200");
|
config.addAllowedOrigin("http://localhost:4200");
|
||||||
config.addAllowedOrigin("http://127.0.0.1:4200");
|
config.addAllowedOrigin("http://127.0.0.1:4200");
|
||||||
|
}
|
||||||
config.addAllowedHeader("*");
|
config.addAllowedHeader("*");
|
||||||
config.addAllowedMethod("OPTIONS");
|
config.addAllowedMethod("OPTIONS");
|
||||||
config.addAllowedMethod("GET");
|
config.addAllowedMethod("GET");
|
||||||
config.addAllowedMethod("POST");
|
config.addAllowedMethod("POST");
|
||||||
config.addAllowedMethod("PUT");
|
config.addAllowedMethod("PUT");
|
||||||
config.addAllowedMethod("DELETE");
|
config.addAllowedMethod("DELETE");
|
||||||
|
config.addExposedHeader("Authorization");
|
||||||
config.setAllowCredentials(true);
|
config.setAllowCredentials(true);
|
||||||
config.setMaxAge(10800L);
|
config.setMaxAge(10800L);
|
||||||
source.registerCorsConfiguration("/**", config);
|
source.registerCorsConfiguration("/**", config);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class DruidConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public DruidDataSource druidDataSource() {
|
public DruidDataSource druidDataSource() {
|
||||||
DruidDataSource dataSource = new DruidDataSource();
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
dataSource.setDriverClassName(driverClassName);
|
||||||
// 数据库基本信息
|
// 数据库基本信息
|
||||||
dataSource.setUrl(dbUrl);
|
dataSource.setUrl(dbUrl);
|
||||||
dataSource.setUsername(username);
|
dataSource.setUsername(username);
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
@Override
|
@Override
|
||||||
@Bean
|
@Bean
|
||||||
public KeyGenerator keyGenerator() {
|
public KeyGenerator keyGenerator() {
|
||||||
return new KeyGenerator() {
|
return (target, method, params) -> {
|
||||||
@Override
|
|
||||||
public Object generate(Object target, Method method, Object... params) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String name = target.getClass().getName();
|
String name = target.getClass().getName();
|
||||||
sb.append(name.substring(name.lastIndexOf(".") + 1));
|
sb.append(name.substring(name.lastIndexOf(".") + 1));
|
||||||
@@ -43,7 +41,6 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
sb.append("-").append(obj.toString());
|
sb.append("-").append(obj.toString());
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import springfox.documentation.builders.ApiInfoBuilder;
|
|||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.PathSelectors;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
import springfox.documentation.service.ApiInfo;
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.service.Contact;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
@@ -25,7 +26,7 @@ public class SwaggerConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public Docket createRestApi() {
|
public Docket createRestApi() {
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
.enable("dev".equals(environment))
|
.enable(!"prod".equals(environment))
|
||||||
.apiInfo(apiInfo())
|
.apiInfo(apiInfo())
|
||||||
.select()
|
.select()
|
||||||
.apis(RequestHandlerSelectors.basePackage("cn.celess.blog"))
|
.apis(RequestHandlerSelectors.basePackage("cn.celess.blog"))
|
||||||
@@ -37,7 +38,7 @@ public class SwaggerConfig {
|
|||||||
return new ApiInfoBuilder()
|
return new ApiInfoBuilder()
|
||||||
.title("小海博客的APi")
|
.title("小海博客的APi")
|
||||||
.description("小海博客的APi")
|
.description("小海博客的APi")
|
||||||
.contact("小海")
|
.contact(new Contact("小海", "https://www.celess.cn", "a@celess.cn"))
|
||||||
.version("1.0")
|
.version("1.0")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package cn.celess.blog.configuration.filter;
|
package cn.celess.blog.configuration.filter;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.service.UserService;
|
||||||
import cn.celess.blog.util.JwtUtil;
|
import cn.celess.blog.util.JwtUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
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;
|
||||||
@@ -21,6 +21,11 @@ import java.io.IOException;
|
|||||||
* @Description: 鉴权拦截器
|
* @Description: 鉴权拦截器
|
||||||
*/
|
*/
|
||||||
public class AuthenticationFilter implements HandlerInterceptor {
|
public class AuthenticationFilter implements HandlerInterceptor {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AuthenticationFilter.class);
|
||||||
|
private static final String USER_PREFIX = "/user";
|
||||||
|
private static final String ADMIN_PREFIX = "/admin";
|
||||||
|
private static final String ROLE_ADMIN = "admin";
|
||||||
|
private static final String ROLE_USER = "user";
|
||||||
@Autowired
|
@Autowired
|
||||||
JwtUtil jwtUtil;
|
JwtUtil jwtUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -28,13 +33,6 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AuthenticationFilter.class);
|
|
||||||
|
|
||||||
private static final String USER_PREFIX = "/user";
|
|
||||||
private static final String ADMIN_PREFIX = "/admin";
|
|
||||||
private static final String ROLE_ADMIN = "admin";
|
|
||||||
private static final String ROLE_USER = "user";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
@@ -58,11 +56,19 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
|||||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
||||||
}
|
}
|
||||||
String email = jwtUtil.getUsernameFromToken(jwtStr);
|
String email = jwtUtil.getUsernameFromToken(jwtStr);
|
||||||
if (!redisUtil.hasKey(email + "-login") || jwtUtil.isTokenExpired(jwtStr)) {
|
if (jwtUtil.isTokenExpired(jwtStr)) {
|
||||||
// 登陆过期
|
// 登陆过期
|
||||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
||||||
}
|
}
|
||||||
|
if (!redisUtil.hasKey(email + "-login")) {
|
||||||
|
return writeResponse(ResponseEnum.LOGOUT, response, request);
|
||||||
|
}
|
||||||
String role = userService.getUserRoleByEmail(email);
|
String role = userService.getUserRoleByEmail(email);
|
||||||
|
if (role.equals(ROLE_USER) || role.equals(ROLE_ADMIN)) {
|
||||||
|
// 更新token
|
||||||
|
String token = jwtUtil.updateTokenDate(jwtStr);
|
||||||
|
response.setHeader("Authorization", token);
|
||||||
|
}
|
||||||
if (role.equals(ROLE_ADMIN)) {
|
if (role.equals(ROLE_ADMIN)) {
|
||||||
// admin
|
// admin
|
||||||
return true;
|
return true;
|
||||||
@@ -78,7 +84,7 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
|||||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
try {
|
try {
|
||||||
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
||||||
response.getWriter().println(JSONObject.fromObject(ResponseUtil.response(e, null)));
|
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class MultipleSubmitFilter implements HandlerInterceptor {
|
|||||||
// 请求参数和路径均相同 且请求时间间隔小于 WAIT_TIME
|
// 请求参数和路径均相同 且请求时间间隔小于 WAIT_TIME
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
Response result = new Response(ResponseEnum.FAILURE.getCode(), "重复请求", null, System.currentTimeMillis());
|
Response result = new Response(ResponseEnum.FAILURE.getCode(), "重复请求", null);
|
||||||
response.getWriter().println(result.toString());
|
response.getWriter().println(result.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class SessionListener implements HttpSessionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sessionCreated(HttpSessionEvent se) {
|
public void sessionCreated(HttpSessionEvent se) {
|
||||||
// TODO : can move 'visit' api to here
|
|
||||||
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
|
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
|
||||||
// 10s for debug
|
// 10s for debug
|
||||||
// se.getSession().setMaxInactiveInterval(10);
|
// se.getSession().setMaxInactiveInterval(10);
|
||||||
@@ -44,9 +43,7 @@ public class SessionListener implements HttpSessionListener {
|
|||||||
sb.append("\t登录情况 => ");
|
sb.append("\t登录情况 => ");
|
||||||
String email = (String) se.getSession().getAttribute("email");
|
String email = (String) se.getSession().getAttribute("email");
|
||||||
sb.append(email == null ? "游客访问" : email);
|
sb.append(email == null ? "游客访问" : email);
|
||||||
visitDetail.forEach((s, integer) -> {
|
visitDetail.forEach((s, integer) -> sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]"));
|
||||||
sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]");
|
|
||||||
});
|
|
||||||
log.info(sb.toString());
|
log.info(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import cn.celess.blog.entity.model.ArticleModel;
|
|||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import cn.celess.blog.service.ArticleService;
|
import cn.celess.blog.service.ArticleService;
|
||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
|
||||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -25,6 +25,8 @@ public class ArticleController {
|
|||||||
SitemapGenerateUtil sitemapGenerateUtil;
|
SitemapGenerateUtil sitemapGenerateUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisUserUtil redisUserUtil;
|
RedisUserUtil redisUserUtil;
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String activeModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建一篇文章
|
* 新建一篇文章
|
||||||
@@ -35,8 +37,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(activeModel)) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(articleModel);
|
}
|
||||||
|
return Response.success(articleModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +52,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(activeModel)) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(delete);
|
}
|
||||||
|
return Response.success(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,8 +67,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(activeModel)) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(update);
|
}
|
||||||
|
return Response.success(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,13 +88,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 +107,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 +119,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 +136,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 +151,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.service.CategoryService;
|
import cn.celess.blog.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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Comment;
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.request.CommentReq;
|
import cn.celess.blog.entity.request.CommentReq;
|
||||||
import cn.celess.blog.service.CommentService;
|
import cn.celess.blog.service.CommentService;
|
||||||
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.*;
|
||||||
|
|
||||||
@@ -26,76 +24,96 @@ public class CommentController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/user/comment/create")
|
@PostMapping("/user/comment/create")
|
||||||
public Response addOne(@RequestBody CommentReq reqBody) {
|
public Response addOne(@RequestBody CommentReq reqBody) {
|
||||||
return ResponseUtil.success(commentService.create(reqBody));
|
return Response.success(commentService.create(reqBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/user/comment/del")
|
@DeleteMapping("/user/comment/del")
|
||||||
public Response delete(@RequestParam("id") long id) {
|
public Response delete(@RequestParam("id") long id) {
|
||||||
return ResponseUtil.success(commentService.delete(id));
|
return Response.success(commentService.delete(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/user/comment/update")
|
@PutMapping("/user/comment/update")
|
||||||
public Response update(@RequestBody CommentReq reqBody) {
|
public Response update(@RequestBody CommentReq reqBody) {
|
||||||
return ResponseUtil.success(commentService.update(reqBody));
|
return Response.success(commentService.update(reqBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的一级评论
|
* 获取所有的评论
|
||||||
*
|
*
|
||||||
* @param articleId 文章id
|
* @param pagePath pagePath
|
||||||
* @param count 单页数据量
|
* @param count 单页数据量
|
||||||
* @param page 页码
|
* @param page 页码
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
@GetMapping("/comments")
|
@GetMapping("/comments/{pagePath}/{pid}")
|
||||||
public Response commentsOfArticle(@RequestParam("articleId") long articleId,
|
public Response commentsOfArticle(@PathVariable("pagePath") String pagePath, @PathVariable(value = "pid") long pid,
|
||||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||||
return ResponseUtil.success(commentService.retrievePageByArticle(articleId, -1, page, count));
|
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获取数据
|
* 通过pid获取数据
|
||||||
*
|
*
|
||||||
* @param pid
|
* @param pagePath pagePath
|
||||||
* @param count
|
* @param count count
|
||||||
* @param page
|
* @param page page
|
||||||
* @return
|
* @return Response
|
||||||
*/
|
*/
|
||||||
@GetMapping("/comment/pid/{pid}")
|
@GetMapping("/comment/pagePath/{pagePath}")
|
||||||
public Response retrievePage(@PathVariable("pid") long pid,
|
public Response retrievePage(@PathVariable("pagePath") String pagePath,
|
||||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||||
return ResponseUtil.success(commentService.retrievePageByPid(pid, page, count));
|
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,
|
||||||
*
|
|
||||||
* @param count
|
|
||||||
* @param page
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/leaveMsg")
|
|
||||||
public Response retrievePageOfLeaveMsg(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
|
||||||
return ResponseUtil.success(commentService.retrievePageByTypeAndPid(false, -1, page, count));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/admin/comment/type/{type}")
|
|
||||||
public Response retrievePageAdmin(
|
|
||||||
@PathVariable("type") int isComment,
|
|
||||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||||
return ResponseUtil.success(commentService.retrievePageByType(1 == isComment, page, count));
|
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("/user/comment/type/{type}")
|
@GetMapping("/admin/comment/pagePath/{pagePath}")
|
||||||
public Response retrievePageByAuthor(
|
public Response adminComment(@PathVariable("pagePath") String pagePath,
|
||||||
@PathVariable(value = "type") int isComment,
|
|
||||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||||
return ResponseUtil.success(commentService.retrievePageByAuthor(1 == isComment, page, count));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,26 +6,27 @@ import cn.celess.blog.entity.model.QiniuResponse;
|
|||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.service.CountService;
|
import cn.celess.blog.service.CountService;
|
||||||
import cn.celess.blog.service.QiniuService;
|
import cn.celess.blog.service.QiniuService;
|
||||||
|
import cn.celess.blog.util.HttpUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
|
||||||
import cn.celess.blog.util.VeriCodeUtil;
|
import cn.celess.blog.util.VeriCodeUtil;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
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.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -36,7 +37,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @date : 2019/04/02 22:03
|
* @date : 2019/04/02 22:03
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
public class Other {
|
public class CommonController {
|
||||||
public static final Logger logger = LoggerFactory.getLogger(Object.class);
|
public static final Logger logger = LoggerFactory.getLogger(Object.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -54,11 +55,10 @@ public class Other {
|
|||||||
Map<String, Long> countMap = new HashMap<>();
|
Map<String, Long> countMap = new HashMap<>();
|
||||||
countMap.put("articleCount", countService.getArticleCount());
|
countMap.put("articleCount", countService.getArticleCount());
|
||||||
countMap.put("commentCount", countService.getCommentCount());
|
countMap.put("commentCount", countService.getCommentCount());
|
||||||
countMap.put("leaveMsgCount", countService.getLeaveMessageCount());
|
|
||||||
countMap.put("categoryCount", countService.getCategoriesCount());
|
countMap.put("categoryCount", countService.getCategoriesCount());
|
||||||
countMap.put("tagCount", countService.getTagsCount());
|
countMap.put("tagCount", countService.getTagsCount());
|
||||||
countMap.put("visitorCount", countService.getVisitorCount());
|
countMap.put("visitorCount", countService.getVisitorCount());
|
||||||
return ResponseUtil.success(countMap);
|
return Response.success(countMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,12 +73,13 @@ public class Other {
|
|||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
Enumeration<String> headerNames = request.getHeaderNames();
|
Enumeration<String> headerNames = request.getHeaderNames();
|
||||||
String str = null;
|
String str = null;
|
||||||
while ((str = headerNames.nextElement()) != null) {
|
while (headerNames.hasMoreElements()) {
|
||||||
|
str = headerNames.nextElement();
|
||||||
map.put(str, request.getHeader(str));
|
map.put(str, request.getHeader(str));
|
||||||
}
|
}
|
||||||
map.put("sessionID", request.getSession().getId());
|
map.put("sessionID", request.getSession().getId());
|
||||||
map.put("request.getRemoteAddr()", request.getRemoteAddr());
|
map.put("request.getRemoteAddr()", request.getRemoteAddr());
|
||||||
return ResponseUtil.success(map);
|
return Response.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,10 +122,10 @@ public class Other {
|
|||||||
if (code.equals(codeStr)) {
|
if (code.equals(codeStr)) {
|
||||||
request.getSession().removeAttribute("code");
|
request.getSession().removeAttribute("code");
|
||||||
request.getSession().setAttribute("verImgCodeStatus", true);
|
request.getSession().setAttribute("verImgCodeStatus", true);
|
||||||
return ResponseUtil.success("验证成功");
|
return Response.success("验证成功");
|
||||||
} else {
|
} else {
|
||||||
request.getSession().removeAttribute("code");
|
request.getSession().removeAttribute("code");
|
||||||
return ResponseUtil.failure("验证失败,请重新获取验证码");
|
return Response.failure("验证失败,请重新获取验证码");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,12 +135,11 @@ public class Other {
|
|||||||
* FUCK !!!
|
* FUCK !!!
|
||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/imgUpload")
|
@PostMapping("/imgUpload")
|
||||||
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
||||||
int uploadTimes = 0;
|
int uploadTimes = 0;
|
||||||
if (uploadTimesStr != null) {
|
if (uploadTimesStr != null) {
|
||||||
@@ -149,68 +149,41 @@ public class Other {
|
|||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||||
}
|
}
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setContentType("text/html");
|
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 0);
|
||||||
jsonObject.put("message", "上传失败,请选择文件");
|
map.put("message", "上传失败,请选择文件");
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
|
assert fileName != null;
|
||||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 1);
|
||||||
jsonObject.put("message", "上传成功");
|
map.put("message", "上传成功");
|
||||||
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
map.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 0);
|
||||||
jsonObject.put("message", "上传失败,请上传图片文件");
|
map.put("message", "上传失败,请上传图片文件");
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/bingPic")
|
@GetMapping("/bingPic")
|
||||||
public Response bingPic() {
|
public Response bingPic() {
|
||||||
StringBuffer sb = new StringBuffer();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
JsonNode root;
|
||||||
try {
|
try {
|
||||||
//建立URL
|
root = mapper.readTree(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||||
URL url = new URL("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN");
|
} catch (IOException e) {
|
||||||
|
return Response.failure(null);
|
||||||
//打开http
|
|
||||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
urlConnection.setDoInput(true);
|
|
||||||
urlConnection.setRequestMethod("GET");
|
|
||||||
urlConnection.connect();
|
|
||||||
|
|
||||||
//获得输入
|
|
||||||
InputStream inputStream = urlConnection.getInputStream();
|
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
||||||
|
|
||||||
//将bufferReader的值给放到buffer里
|
|
||||||
String str = null;
|
|
||||||
while ((str = bufferedReader.readLine()) != null) {
|
|
||||||
sb.append(str);
|
|
||||||
}
|
}
|
||||||
//关闭bufferReader和输入流
|
JsonNode images = root.get("images").elements().next();
|
||||||
bufferedReader.close();
|
return Response.success("https://cn.bing.com" + images.get("url").asText());
|
||||||
inputStreamReader.close();
|
|
||||||
inputStream.close();
|
|
||||||
//断开连接
|
|
||||||
urlConnection.disconnect();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return ResponseUtil.failure(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject imageObj = JSONObject.fromObject(sb.toString());
|
|
||||||
JSONArray jsonArray = imageObj.getJSONArray("images");
|
|
||||||
String imageName = jsonArray.getJSONObject(0).getString("url");
|
|
||||||
return ResponseUtil.success("https://cn.bing.com" + imageName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,18 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -37,63 +31,39 @@ public class LinksController {
|
|||||||
|
|
||||||
@PostMapping("/admin/links/create")
|
@PostMapping("/admin/links/create")
|
||||||
public Response create(@RequestBody LinkReq reqBody) {
|
public Response create(@RequestBody LinkReq reqBody) {
|
||||||
return ResponseUtil.success(partnerSiteService.create(reqBody));
|
return Response.success(partnerSiteService.create(reqBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/admin/links/del/{id}")
|
@DeleteMapping("/admin/links/del/{id}")
|
||||||
public Response del(@PathVariable("id") long id) {
|
public Response del(@PathVariable("id") long id) {
|
||||||
return ResponseUtil.success(partnerSiteService.del(id));
|
return Response.success(partnerSiteService.del(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/admin/links/update")
|
@PutMapping("/admin/links/update")
|
||||||
public Response update(@RequestBody LinkReq reqBody) {
|
public Response update(@RequestBody LinkReq reqBody) {
|
||||||
return ResponseUtil.success(partnerSiteService.update(reqBody));
|
return Response.success(partnerSiteService.update(reqBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/links")
|
@GetMapping("/links")
|
||||||
public Response allForOpen() {
|
public Response allForOpen() {
|
||||||
List<PartnerSite> sites = new ArrayList<>();
|
List<PartnerSite> sites = partnerSiteService.findAll().stream().peek(partnerSite -> partnerSite.setOpen(null)).collect(Collectors.toList());
|
||||||
for (PartnerSite p : partnerSiteService.findAll()) {
|
return Response.success(sites);
|
||||||
if (p.getOpen()) {
|
|
||||||
//隐藏open字段
|
|
||||||
p.setOpen(null);
|
|
||||||
sites.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ResponseUtil.success(sites);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin/links")
|
@GetMapping("/admin/links")
|
||||||
public Response all(@RequestParam("page") int page,
|
public Response all(@RequestParam("page") int page,
|
||||||
@RequestParam("count") int count) {
|
@RequestParam("count") int count,
|
||||||
return ResponseUtil.success(partnerSiteService.PartnerSitePages(page, count));
|
@RequestParam(value = "deleted", required = false) Boolean deleted) {
|
||||||
|
return Response.success(partnerSiteService.partnerSitePages(page, count, deleted));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/apply")
|
@PostMapping("/apply")
|
||||||
public Response apply(@RequestParam("name") String name,
|
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
||||||
@RequestParam("url") String url) {
|
return Response.success(partnerSiteService.apply(linkApplyReq));
|
||||||
// TODO :: 弃用发送邮件的方式。
|
|
||||||
if (name == null || name.replaceAll(" ", "").isEmpty()) {
|
|
||||||
return ResponseUtil.response(ResponseEnum.PARAMETERS_ERROR, null);
|
|
||||||
}
|
}
|
||||||
if (!RegexUtil.urlMatch(url)) {
|
|
||||||
return ResponseUtil.response(ResponseEnum.PARAMETERS_URL_ERROR, null);
|
|
||||||
}
|
|
||||||
String applyTimeStr = redisUtil.get(request.getRemoteAddr() + "-Apply");
|
|
||||||
int applyTime = 0;
|
|
||||||
if (applyTimeStr != null) {
|
|
||||||
applyTime = Integer.parseInt(applyTimeStr);
|
|
||||||
}
|
|
||||||
if (applyTime == 10) {
|
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "申请次数已达10次,请2小时后重试");
|
|
||||||
}
|
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
|
||||||
message.setSubject("友链申请:" + name);
|
|
||||||
message.setTo("a@celess.cn");
|
|
||||||
message.setText("name:" + name + "\nurl:" + url + "\n" + DateFormatUtil.getNow());
|
|
||||||
Boolean send = mailService.send(message);
|
|
||||||
redisUtil.setEx(request.getRemoteAddr() + "-Apply", applyTime + 1 + "", 2, TimeUnit.HOURS);
|
|
||||||
return send ? ResponseUtil.success("") : ResponseUtil.failure("");
|
|
||||||
|
|
||||||
|
@PostMapping("/reapply")
|
||||||
|
public Response reapply(@RequestParam("key") String key) {
|
||||||
|
return Response.success(partnerSiteService.reapply(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.Tag;
|
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.TagModel;
|
||||||
import cn.celess.blog.service.TagService;
|
import cn.celess.blog.service.TagService;
|
||||||
import cn.celess.blog.util.ResponseUtil;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
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.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -24,47 +23,37 @@ public class TagController {
|
|||||||
|
|
||||||
@PostMapping("/admin/tag/create")
|
@PostMapping("/admin/tag/create")
|
||||||
public Response addOne(@RequestParam("name") String name) {
|
public Response addOne(@RequestParam("name") String name) {
|
||||||
return ResponseUtil.success(tagService.create(name));
|
return Response.success(tagService.create(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/admin/tag/del")
|
@DeleteMapping("/admin/tag/del")
|
||||||
public Response delOne(@RequestParam("id") long id) {
|
public Response delOne(@RequestParam("id") long id) {
|
||||||
return ResponseUtil.success(tagService.delete(id));
|
return Response.success(tagService.delete(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PutMapping("/admin/tag/update")
|
@PutMapping("/admin/tag/update")
|
||||||
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
||||||
return ResponseUtil.success(tagService.update(id, name));
|
return Response.success(tagService.update(id, name));
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/tag/id/{id}")
|
|
||||||
public Response retrieveOneById(@PathVariable("id") long id) {
|
|
||||||
return ResponseUtil.success(tagService.retrieveOneById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/tag/name/{name}")
|
|
||||||
public Response retrieveOneByName(@PathVariable("name") String name) {
|
|
||||||
return ResponseUtil.success(tagService.retrieveOneByName(name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tags")
|
@GetMapping("/tags")
|
||||||
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
||||||
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
||||||
return ResponseUtil.success(tagService.retrievePage(page, count));
|
return Response.success(tagService.retrievePage(page, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tags/nac")
|
@GetMapping("/tags/nac")
|
||||||
public Response getTagNameAndCount() {
|
public Response getTagNameAndCount() {
|
||||||
List<JSONObject> nameAndCount = new ArrayList<>();
|
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||||
List<TagModel> all = tagService.findAll();
|
List<TagModel> all = tagService.findAll();
|
||||||
for (TagModel t : all) {
|
for (TagModel t : all) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
jsonObject.put("name", t.getName());
|
map.put("name", t.getName());
|
||||||
jsonObject.put("size", t.getArticles() == null ? 0 : t.getArticles().size());
|
map.put("size", t.getArticles().size());
|
||||||
nameAndCount.add(jsonObject);
|
nameAndCount.add(map);
|
||||||
}
|
}
|
||||||
return ResponseUtil.success(nameAndCount);
|
return Response.success(nameAndCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import cn.celess.blog.entity.Response;
|
|||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
import cn.celess.blog.entity.request.UserReq;
|
import cn.celess.blog.entity.request.UserReq;
|
||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.service.UserService;
|
||||||
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.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -23,28 +22,28 @@ public class UserController {
|
|||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public Response login(@RequestBody LoginReq loginReq) {
|
public Response login(@RequestBody LoginReq loginReq) {
|
||||||
return ResponseUtil.success(userService.login(loginReq));
|
return Response.success(userService.login(loginReq));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/registration")
|
@PostMapping("/registration")
|
||||||
public Response registration(@RequestParam("email") String email,
|
public Response registration(@RequestParam("email") String email,
|
||||||
@RequestParam("password") String password) {
|
@RequestParam("password") String password) {
|
||||||
return ResponseUtil.success(userService.registration(email, password));
|
return Response.success(userService.registration(email, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/logout")
|
@GetMapping("/logout")
|
||||||
public Response logout() {
|
public Response logout() {
|
||||||
return ResponseUtil.success(userService.logout());
|
return Response.success(userService.logout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/user/userInfo/update")
|
@PutMapping("/user/userInfo/update")
|
||||||
public Response updateInfo(String desc, String displayName) {
|
public Response updateInfo(String desc, String displayName) {
|
||||||
return ResponseUtil.success(userService.update(desc, displayName));
|
return Response.success(userService.update(desc, displayName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/user/userInfo")
|
@GetMapping("/user/userInfo")
|
||||||
public Response getUserInfo() {
|
public Response getUserInfo() {
|
||||||
return ResponseUtil.success(userService.getUserInfoBySession());
|
return Response.success(userService.getUserInfoBySession());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +57,7 @@ public class UserController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Response upload(@RequestParam("file") MultipartFile file) throws IOException {
|
public Response upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return ResponseUtil.failure("上传失败,请选择文件");
|
return Response.failure("上传失败,请选择文件");
|
||||||
}
|
}
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||||
@@ -66,56 +65,64 @@ public class UserController {
|
|||||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||||
return (Response) userService.updateUserAavatarImg(file.getInputStream(), mime);
|
return (Response) userService.updateUserAavatarImg(file.getInputStream(), mime);
|
||||||
}
|
}
|
||||||
return ResponseUtil.failure("请上传图片文件");
|
return Response.failure("请上传图片文件");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/sendResetPwdEmail")
|
@PostMapping("/sendResetPwdEmail")
|
||||||
public Response sendResetPwdEmail(@RequestParam("email") String email) {
|
public Response sendResetPwdEmail(@RequestParam("email") String email) {
|
||||||
return ResponseUtil.success(userService.sendResetPwdEmail(email));
|
return Response.success(userService.sendResetPwdEmail(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/sendVerifyEmail")
|
@PostMapping("/sendVerifyEmail")
|
||||||
public Response sendVerifyEmail(@RequestParam("email") String email) {
|
public Response sendVerifyEmail(@RequestParam("email") String email) {
|
||||||
return ResponseUtil.success(userService.sendVerifyEmail(email));
|
return Response.success(userService.sendVerifyEmail(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/emailVerify")
|
@PostMapping("/emailVerify")
|
||||||
public Response emailVerify(@RequestParam("verifyId") String verifyId,
|
public Response emailVerify(@RequestParam("verifyId") String verifyId,
|
||||||
@RequestParam("email") String mail) {
|
@RequestParam("email") String mail) {
|
||||||
return ResponseUtil.success(userService.verifyEmail(verifyId, mail));
|
return Response.success(userService.verifyEmail(verifyId, mail));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/resetPwd")
|
@PostMapping("/resetPwd")
|
||||||
public Response resetPwd(@RequestParam("verifyId") String verifyId,
|
public Response resetPwd(@RequestParam("verifyId") String verifyId,
|
||||||
@RequestParam("email") String email,
|
@RequestParam("email") String email,
|
||||||
@RequestParam("pwd") String pwd) {
|
@RequestParam("pwd") String pwd) {
|
||||||
return ResponseUtil.success(userService.reSetPwd(verifyId, email, pwd));
|
return Response.success(userService.reSetPwd(verifyId, email, pwd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/user/setPwd")
|
||||||
|
public Response setPwd(@RequestParam("pwd") String pwd,
|
||||||
|
@RequestParam("newPwd") String newPwd,
|
||||||
|
@RequestParam("confirmPwd") String confirmPwd) {
|
||||||
|
return Response.success(userService.setPwd(pwd, newPwd, confirmPwd));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@DeleteMapping("/admin/user/delete")
|
@DeleteMapping("/admin/user/delete")
|
||||||
public Response multipleDelete(@RequestBody Integer[] ids) {
|
public Response multipleDelete(@RequestBody Integer[] ids) {
|
||||||
return ResponseUtil.success(userService.deleteUser(ids));
|
return Response.success(userService.deleteUser(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/admin/user/delete/{id}")
|
@DeleteMapping("/admin/user/delete/{id}")
|
||||||
public Response delete(@PathVariable("id") Integer id) {
|
public Response delete(@PathVariable("id") Integer id) {
|
||||||
return ResponseUtil.success(userService.deleteUser(new Integer[]{id}));
|
return Response.success(userService.deleteUser(new Integer[]{id}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/admin/user")
|
@PutMapping("/admin/user")
|
||||||
public Response updateInfoByAdmin(@RequestBody UserReq user) {
|
public Response updateInfoByAdmin(@RequestBody UserReq user) {
|
||||||
return ResponseUtil.success(userService.adminUpdate(user));
|
return Response.success(userService.adminUpdate(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin/users")
|
@GetMapping("/admin/users")
|
||||||
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count) {
|
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count, @RequestParam(name = "status", required = false) Integer status) {
|
||||||
return ResponseUtil.success(userService.getUserList(pageNum, count));
|
return Response.success(userService.getUserList(pageNum, count, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/emailStatus/{email}")
|
@GetMapping("/emailStatus/{email}")
|
||||||
public Response getEmailStatus(@PathVariable("email") String email) {
|
public Response getEmailStatus(@PathVariable("email") String email) {
|
||||||
return ResponseUtil.success(userService.getStatusOfEmail(email));
|
return Response.success(userService.getStatusOfEmail(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.service.CountService;
|
import cn.celess.blog.service.CountService;
|
||||||
import cn.celess.blog.service.VisitorService;
|
import cn.celess.blog.service.VisitorService;
|
||||||
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.*;
|
||||||
|
|
||||||
@@ -22,29 +21,29 @@ public class VisitorController {
|
|||||||
|
|
||||||
@GetMapping("/visitor/count")
|
@GetMapping("/visitor/count")
|
||||||
public Response getVisitorCount() {
|
public Response getVisitorCount() {
|
||||||
return ResponseUtil.success(countService.getVisitorCount());
|
return Response.success(countService.getVisitorCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin/visitor/page")
|
@GetMapping("/admin/visitor/page")
|
||||||
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
||||||
@RequestParam(value = "showLocation", required = false, defaultValue = "false") boolean showLocation) {
|
@RequestParam(value = "showLocation", required = false, defaultValue = "false") boolean showLocation) {
|
||||||
return ResponseUtil.success(visitorService.visitorPage(page, count, showLocation));
|
return Response.success(visitorService.visitorPage(page, count, showLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/visit")
|
@PostMapping("/visit")
|
||||||
public Response add(HttpServletRequest request) {
|
public Response add(HttpServletRequest request) {
|
||||||
return ResponseUtil.success(visitorService.addVisitor(request));
|
return Response.success(visitorService.addVisitor(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/dayVisitCount")
|
@GetMapping("/dayVisitCount")
|
||||||
public Response dayVisitCount() {
|
public Response dayVisitCount() {
|
||||||
return ResponseUtil.success(countService.getDayVisitCount());
|
return Response.success(countService.getDayVisitCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/ip/{ip}")
|
@GetMapping("/ip/{ip}")
|
||||||
public Response ipLocation(@PathVariable("ip") String ip) {
|
public Response ipLocation(@PathVariable("ip") String ip) {
|
||||||
return ResponseUtil.success(visitorService.location(ip));
|
return Response.success(visitorService.location(ip));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +54,6 @@ public class VisitorController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/ip")
|
@GetMapping("/ip")
|
||||||
public Response getIp(HttpServletRequest request) {
|
public Response getIp(HttpServletRequest request) {
|
||||||
return ResponseUtil.success(request.getRemoteAddr());
|
return Response.success(request.getRemoteAddr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.service.WebUpdateInfoService;
|
import cn.celess.blog.service.WebUpdateInfoService;
|
||||||
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.*;
|
||||||
|
|
||||||
@@ -17,31 +16,32 @@ public class WebUpdateInfoController {
|
|||||||
|
|
||||||
@PostMapping("/admin/webUpdate/create")
|
@PostMapping("/admin/webUpdate/create")
|
||||||
public Response create(@RequestParam("info") String info) {
|
public Response create(@RequestParam("info") String info) {
|
||||||
return ResponseUtil.success(webUpdateInfoService.create(info));
|
return Response.success(webUpdateInfoService.create(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/admin/webUpdate/del/{id}")
|
@DeleteMapping("/admin/webUpdate/del/{id}")
|
||||||
public Response del(@PathVariable("id") long id) {
|
public Response del(@PathVariable("id") long id) {
|
||||||
return ResponseUtil.success(webUpdateInfoService.del(id));
|
return Response.success(webUpdateInfoService.del(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/admin/webUpdate/update")
|
@PutMapping("/admin/webUpdate/update")
|
||||||
public Response update(@RequestParam("id") long id, @RequestParam("info") String info) {
|
public Response update(@RequestParam("id") long id, @RequestParam("info") String info) {
|
||||||
return ResponseUtil.success(webUpdateInfoService.update(id, info));
|
return Response.success(webUpdateInfoService.update(id, info));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/webUpdate")
|
@GetMapping("/webUpdate")
|
||||||
public Response findAll() {
|
public Response findAll() {
|
||||||
return ResponseUtil.success(webUpdateInfoService.findAll());
|
return Response.success(webUpdateInfoService.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/webUpdate/pages")
|
@GetMapping("/webUpdate/pages")
|
||||||
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
||||||
return ResponseUtil.success(webUpdateInfoService.pages(count, page));
|
return Response.success(webUpdateInfoService.pages(count, page));
|
||||||
}
|
}
|
||||||
@GetMapping("/lastestUpdateTime")
|
|
||||||
|
@GetMapping("/lastestUpdate")
|
||||||
public Response lastestUpdateTime() {
|
public Response lastestUpdateTime() {
|
||||||
return ResponseUtil.success(webUpdateInfoService.getLastestUpdateTime());
|
return Response.success(webUpdateInfoService.getLastestUpdateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
23
src/main/java/cn/celess/blog/enmu/CommentStatusEnum.java
Normal file
23
src/main/java/cn/celess/blog/enmu/CommentStatusEnum.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package cn.celess.blog.enmu;
|
||||||
|
|
||||||
|
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,27 +0,0 @@
|
|||||||
package cn.celess.blog.enmu;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: 小海
|
|
||||||
* @Date: 2019/06/29 00:00
|
|
||||||
* @Description: 文章数据模型转换的级别(响应参数的选择)
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
public enum LevelEnum {
|
|
||||||
//低级
|
|
||||||
LOW(0),
|
|
||||||
//中级
|
|
||||||
MIDDLE(1),
|
|
||||||
//另一个级别的转化
|
|
||||||
BETWEEN_M_AND_H(2),
|
|
||||||
//高级
|
|
||||||
HEIGHT(3);
|
|
||||||
|
|
||||||
private int levelCode;
|
|
||||||
|
|
||||||
LevelEnum(int levelCode) {
|
|
||||||
this.levelCode = levelCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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, "文章已存在"),
|
||||||
@@ -28,8 +30,12 @@ public enum ResponseEnum {
|
|||||||
USEREMAIL_NULL(3310, "未设置邮箱"),
|
USEREMAIL_NULL(3310, "未设置邮箱"),
|
||||||
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
||||||
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
||||||
PWD_SAME(3600, "新密码与原密码相同"),
|
PWD_SAME(3601, "新密码与原密码相同"),
|
||||||
|
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||||
|
LOGOUT(3710, "账户已注销"),
|
||||||
|
CAN_NOT_USE(3711, "账户不可用"),
|
||||||
|
PWD_WRONG(3800, "密码不正确"),
|
||||||
|
|
||||||
JWT_EXPIRED(3810, "Token过期"),
|
JWT_EXPIRED(3810, "Token过期"),
|
||||||
JWT_MALFORMED(3820, "Token格式不对"),
|
JWT_MALFORMED(3820, "Token格式不对"),
|
||||||
@@ -53,6 +59,9 @@ 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, "暂无法获取到数据"),
|
||||||
|
|
||||||
//提交更新之前,没有获取数据/,
|
//提交更新之前,没有获取数据/,
|
||||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||||
@@ -66,9 +75,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) {
|
||||||
|
|||||||
23
src/main/java/cn/celess/blog/enmu/RoleEnum.java
Normal file
23
src/main/java/cn/celess/blog/enmu/RoleEnum.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package cn.celess.blog.enmu;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
72
src/main/java/cn/celess/blog/enmu/UserAccountStatusEnum.java
Normal file
72
src/main/java/cn/celess/blog/enmu/UserAccountStatusEnum.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package cn.celess.blog.enmu;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package cn.celess.blog.entity;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -41,16 +42,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 +49,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;
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/main/java/cn/celess/blog/entity/ArticleTag.java
Normal file
26
src/main/java/cn/celess/blog/entity/ArticleTag.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 14:52
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ArticleTag {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Article article;
|
||||||
|
|
||||||
|
private TagCategory tag;
|
||||||
|
|
||||||
|
public ArticleTag(Article article, TagCategory tag) {
|
||||||
|
this.article = article;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,14 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/28 22:18
|
* @date : 2019/03/28 22:18
|
||||||
*/
|
*/
|
||||||
@Data
|
@NoArgsConstructor
|
||||||
public class Category {
|
public class Category extends TagCategory {
|
||||||
|
public Category(String name) {
|
||||||
private Long id;
|
super.setName(name);
|
||||||
|
}
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String articles;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,27 +14,21 @@ public class Comment {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
private int status;
|
||||||
* 是评论还是留言 0:评论 其他(1):留言
|
|
||||||
*/
|
|
||||||
private Boolean type;
|
|
||||||
|
|
||||||
private Long authorID;
|
private String pagePath;
|
||||||
|
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
private Long articleID;
|
|
||||||
|
|
||||||
private Date date;
|
private Date date;
|
||||||
|
|
||||||
/**
|
private User fromUser;
|
||||||
* 回应着ID 默认为顶级回复
|
|
||||||
*/
|
|
||||||
private String responseId = "";
|
|
||||||
|
|
||||||
|
private User toUser;
|
||||||
/**
|
/**
|
||||||
* 评论的父ID
|
* 评论的父ID
|
||||||
*/
|
*/
|
||||||
private Long pid;
|
private Long pid;
|
||||||
|
|
||||||
|
// private boolean delete;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,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() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.sf.json.JSONObject;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@@ -10,25 +12,54 @@ import java.io.Serializable;
|
|||||||
* @date : 2019/03/28 15:24
|
* @date : 2019/03/28 15:24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Response implements Serializable {
|
public class Response<T> implements Serializable {
|
||||||
private int code;
|
private int code;
|
||||||
private String msg;
|
private String msg;
|
||||||
private Object result;
|
private T result;
|
||||||
private long date;
|
|
||||||
|
|
||||||
public Response() {
|
public Response() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response(int code, String msg, Object result, long date) {
|
public Response(int code, String msg, T result) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.date = date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功相应
|
||||||
|
*
|
||||||
|
* @param result 结果
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public static Response success(Object result) {
|
||||||
|
return new Response(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败的响应
|
||||||
|
*
|
||||||
|
* @param result 结果
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public static Response failure(String result) {
|
||||||
|
return new Response(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他的响应
|
||||||
|
*
|
||||||
|
* @param r 枚举常量
|
||||||
|
* @param result 结果
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public static Response response(ResponseEnum r, String result) {
|
||||||
|
return new Response(r.getCode(), r.getMsg(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(this);
|
return new ObjectMapper().writeValueAsString(this);
|
||||||
return jsonObject.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/28 22:19
|
* @date : 2019/03/28 22:19
|
||||||
*/
|
*/
|
||||||
@Data
|
@NoArgsConstructor
|
||||||
public class Tag {
|
public class Tag extends TagCategory {
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
public Tag(String name) {
|
||||||
|
super.setName(name);
|
||||||
private String articles;
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/main/java/cn/celess/blog/entity/TagCategory.java
Normal file
19
src/main/java/cn/celess/blog/entity/TagCategory.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-24 14:03
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TagCategory {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Boolean category = true;
|
||||||
|
|
||||||
|
private Boolean deleted = false;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.entity;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ import java.util.Date;
|
|||||||
* @date : 2019/03/28 14:52
|
* @date : 2019/03/28 14:52
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
public class User {
|
public class User {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@@ -18,12 +20,6 @@ public class User {
|
|||||||
*/
|
*/
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户唯一标识码
|
|
||||||
*/
|
|
||||||
@JsonIgnore
|
|
||||||
private String uid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
@@ -46,15 +42,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class Visitor {
|
|||||||
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;
|
||||||
|
|||||||
@@ -17,11 +17,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,9 +1,10 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.blog.entity.model;
|
||||||
|
|
||||||
|
import cn.celess.blog.entity.Tag;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -57,40 +58,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.blog.entity.model;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Category;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,22 +19,6 @@ public class CategoryModel {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private List<Integer> articles;
|
private List<ArticleModel> articles;
|
||||||
|
private boolean deleted;
|
||||||
|
|
||||||
public CategoryModel(Category category) {
|
|
||||||
this.id = category.getId();
|
|
||||||
this.name = category.getName();
|
|
||||||
if (category.getArticles() == null || category.getArticles().length() == 0) {
|
|
||||||
articles = null;
|
|
||||||
} else {
|
|
||||||
articles = new ArrayList<>();
|
|
||||||
for (String s : category.getArticles().split(",")) {
|
|
||||||
if ("".equals(s)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
articles.add(Integer.parseInt(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package cn.celess.blog.entity.model;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -14,44 +14,31 @@ import java.util.Date;
|
|||||||
public class CommentModel {
|
public class CommentModel {
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/**
|
private UserModel fromUser;
|
||||||
* 是评论还是留言 0:评论 其他(1):留言
|
|
||||||
*/
|
|
||||||
private boolean isComment;
|
|
||||||
|
|
||||||
private String authorName;
|
private UserModel toUser;
|
||||||
|
|
||||||
private String authorAvatarImgUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内容
|
* 内容
|
||||||
*/
|
*/
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
/**
|
|
||||||
* 文章ID
|
|
||||||
*/
|
|
||||||
private long articleID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章标题
|
* 文章标题
|
||||||
*/
|
*/
|
||||||
private String articleTitle;
|
private String pagePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布日期
|
* 发布日期
|
||||||
*/
|
*/
|
||||||
private String date;
|
private String date;
|
||||||
|
|
||||||
/**
|
|
||||||
* 回应着ID 默认为顶级回复
|
|
||||||
*/
|
|
||||||
private String responseId = "";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论的父ID
|
* 评论的父ID
|
||||||
*/
|
*/
|
||||||
private long pid = -1;
|
private Long pid;
|
||||||
|
|
||||||
|
private List<CommentModel> respComment;
|
||||||
|
|
||||||
|
private int status;
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/main/java/cn/celess/blog/entity/model/PageData.java
Normal file
38
src/main/java/cn/celess/blog/entity/model/PageData.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package cn.celess.blog.entity.model;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-05-25 17:13
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PageData<T> {
|
||||||
|
|
||||||
|
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,9 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.blog.entity.model;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Tag;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,21 +19,7 @@ public class TagModel {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private List<Integer> articles;
|
private List<ArticleModel> articles;
|
||||||
|
|
||||||
public TagModel(Tag tag) {
|
private boolean deleted;
|
||||||
this.id = tag.getId();
|
|
||||||
this.name = tag.getName();
|
|
||||||
if (tag.getArticles() == null || tag.getArticles().length() == 0) {
|
|
||||||
articles = null;
|
|
||||||
} else {
|
|
||||||
articles = new ArrayList<>();
|
|
||||||
for (String s : tag.getArticles().split(",")) {
|
|
||||||
if ("".equals(s)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
articles.add(Integer.parseInt(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.celess.blog.entity.model;
|
package cn.celess.blog.entity.model;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -37,4 +38,6 @@ public class UserModel {
|
|||||||
private String role = "user";
|
private String role = "user";
|
||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
private UserAccountStatusEnum status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,6 @@ public class WebUpdateModel {
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean deleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class ArticleReq {
|
|||||||
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;
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class CommentReq {
|
public class CommentReq {
|
||||||
private Long id;
|
private Long id;
|
||||||
private Boolean comment;
|
|
||||||
private String content;
|
private String content;
|
||||||
private Long pid;
|
private long pid = -1;
|
||||||
private Long articleID;
|
private String pagePath;
|
||||||
private String responseId;
|
private long toUserId = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.celess.blog.entity.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2020/07/31 20:50
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LinkApplyReq {
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String url;
|
||||||
|
private String linkUrl;
|
||||||
|
private String desc;
|
||||||
|
private String iconPath;
|
||||||
|
}
|
||||||
@@ -11,5 +11,7 @@ public class LinkReq {
|
|||||||
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,12 +1,16 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.blog.entity.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/06/01 22:47
|
* @date : 2019/06/01 22:47
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class LoginReq {
|
public class LoginReq {
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
|
|||||||
@@ -26,12 +26,11 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class ExceptionHandle {
|
public class ExceptionHandle {
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.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}")
|
@Value("${spring.profiles.active}")
|
||||||
private String activeModel;
|
private String activeModel;
|
||||||
|
|
||||||
@@ -40,28 +39,29 @@ public class ExceptionHandle {
|
|||||||
public Response handle(Exception e) {
|
public Response handle(Exception e) {
|
||||||
//自定义错误
|
//自定义错误
|
||||||
if (e instanceof MyException) {
|
if (e instanceof MyException) {
|
||||||
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
|
MyException exception = (MyException) 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送错误信息到邮箱
|
// 发送错误信息到邮箱
|
||||||
@@ -70,7 +70,7 @@ public class ExceptionHandle {
|
|||||||
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 +83,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");
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package cn.celess.blog.exception;
|
package cn.celess.blog.exception;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/28 16:56
|
* @date : 2019/03/28 16:56
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class MyException extends RuntimeException {
|
public class MyException extends RuntimeException {
|
||||||
private int code;
|
private int code;
|
||||||
|
private Object result;
|
||||||
|
|
||||||
public MyException(int code, String msg) {
|
public MyException(int code, String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@@ -19,16 +22,20 @@ public class MyException extends RuntimeException {
|
|||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MyException(ResponseEnum e, Object result) {
|
||||||
|
super(e.getMsg());
|
||||||
|
this.code = e.getCode();
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
public MyException(ResponseEnum e, String msg) {
|
public MyException(ResponseEnum e, String msg) {
|
||||||
super(msg + e.getMsg());
|
super(msg + e.getMsg());
|
||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public MyException(ResponseEnum e, String msg, Object result) {
|
||||||
return code;
|
super(e.getMsg());
|
||||||
}
|
this.code = e.getCode();
|
||||||
|
this.result = result;
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cn.celess.blog.mapper;
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.Article;
|
||||||
import org.apache.ibatis.annotations.*;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,21 +21,15 @@ public interface ArticleMapper {
|
|||||||
|
|
||||||
int update(Article a);
|
int update(Article a);
|
||||||
|
|
||||||
int updateNextArticleId(long targetArticleID, long nextArticleID);
|
|
||||||
|
|
||||||
int updatePreArticleId(long targetArticleID, long preArticleID);
|
|
||||||
|
|
||||||
long getLastestArticleId();
|
|
||||||
|
|
||||||
Article getLastestArticle();
|
Article getLastestArticle();
|
||||||
|
|
||||||
Article findArticleById(long id);
|
Article findArticleById(long id);
|
||||||
|
|
||||||
boolean existsByTitle(String title);
|
boolean existsByTitle(String title);
|
||||||
|
|
||||||
boolean existsById(long id);
|
boolean isDeletedById(long id);
|
||||||
|
|
||||||
List<Article> findAllByAuthorId(long authorID);
|
List<Article> findAllByAuthorId(long authorId);
|
||||||
|
|
||||||
List<Article> findAllByOpen(boolean isOpen);
|
List<Article> findAllByOpen(boolean isOpen);
|
||||||
|
|
||||||
@@ -43,15 +37,15 @@ public interface ArticleMapper {
|
|||||||
|
|
||||||
List<Article> findAllByCategoryId(long id);
|
List<Article> findAllByCategoryId(long id);
|
||||||
|
|
||||||
|
List<Article> findAllByCategoryIdAndOpen(long id);
|
||||||
|
|
||||||
List<Article> findAll();
|
List<Article> findAll();
|
||||||
|
|
||||||
Article getSimpleInfo(long id);
|
Article getPreArticle(Long id);
|
||||||
|
|
||||||
List<Article> getSimpleInfoByCategory(long categoryId);
|
Article getNextArticle(Long id);
|
||||||
|
|
||||||
List<Article> getSimpleInfoByTag(List<String> idList);
|
int updateReadingNumber(long id);
|
||||||
|
|
||||||
int setReadingNumber(long number, long id);
|
|
||||||
|
|
||||||
long count();
|
long count();
|
||||||
|
|
||||||
|
|||||||
35
src/main/java/cn/celess/blog/mapper/ArticleTagMapper.java
Normal file
35
src/main/java/cn/celess/blog/mapper/ArticleTagMapper.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
|
import cn.celess.blog.entity.ArticleTag;
|
||||||
|
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);
|
||||||
|
|
||||||
|
int deleteMultiById(List<ArticleTag> articleTags);
|
||||||
|
|
||||||
|
List<ArticleTag> findArticleByTag(Long tagId);
|
||||||
|
|
||||||
|
List<ArticleTag> findArticleByTagAndOpen(Long tagId);
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
* @Date: 2019/06/30 16:19
|
* @Date: 2019/06/30 16:19
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
@@ -18,11 +18,9 @@ public interface CommentMapper {
|
|||||||
|
|
||||||
int updateContent(String content, long id);
|
int updateContent(String content, long id);
|
||||||
|
|
||||||
int updateResponder(String responder, long id);
|
|
||||||
|
|
||||||
int delete(long id);
|
int delete(long id);
|
||||||
|
|
||||||
int deleteByArticleId(long articleId);
|
int deleteByPagePath(String pagePath);
|
||||||
|
|
||||||
boolean existsById(long id);
|
boolean existsById(long id);
|
||||||
|
|
||||||
@@ -30,19 +28,17 @@ public interface CommentMapper {
|
|||||||
|
|
||||||
Comment getLastestComment();
|
Comment getLastestComment();
|
||||||
|
|
||||||
List<Comment> findAllByAuthorIDAndType(long id, boolean isComment);
|
List<Comment> findAllByFromUser(long id);
|
||||||
|
|
||||||
List<Comment> findAllByPId(long pid);
|
List<Comment> findAllByPid(long pid);
|
||||||
|
|
||||||
List<Comment> findAllByArticleID(long articleId);
|
List<Comment> findAllByPagePath(String pagePath);
|
||||||
|
|
||||||
List<Comment> findAllByArticleIDAndPId(long articleID, long pid);
|
List<Comment> findAllByPagePathAndFromUser(String pagePath, long userId);
|
||||||
|
|
||||||
List<Comment> findCommentsByTypeAndPId(boolean isComment, long pid);
|
List<Comment> findAllByPagePathAndPidAndNormal(String pagePath, long pid);
|
||||||
|
|
||||||
List<Comment> findAllByPId(int pid);
|
long countByPagePath(String pagePath);
|
||||||
|
|
||||||
List<Comment> findAllByType(boolean isComment);
|
long count();
|
||||||
|
|
||||||
long countByType(boolean isComment);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,5 +36,6 @@ public interface PartnerMapper {
|
|||||||
|
|
||||||
List<PartnerSite> findAll();
|
List<PartnerSite> findAll();
|
||||||
|
|
||||||
|
List<PartnerSite> findAll(Boolean deleted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import cn.celess.blog.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();
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,7 @@ public interface VisitorMapper {
|
|||||||
|
|
||||||
List<Visitor> findAll();
|
List<Visitor> findAll();
|
||||||
|
|
||||||
|
List<Visitor> findAllNotDeleted();
|
||||||
|
|
||||||
long count();
|
long count();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import cn.celess.blog.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();
|
||||||
|
|
||||||
Date getLastestOne();
|
List<WebUpdate> findAllNotDeleted();
|
||||||
|
|
||||||
|
WebUpdate getLastestOne();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
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.blog.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Category;
|
|
||||||
import cn.celess.blog.entity.model.CategoryModel;
|
import cn.celess.blog.entity.model.CategoryModel;
|
||||||
|
import cn.celess.blog.entity.model.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.model.CommentModel;
|
import cn.celess.blog.entity.model.CommentModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.CommentReq;
|
import cn.celess.blog.entity.request.CommentReq;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/03/29 16:58
|
* @date : 2019/03/29 16:58
|
||||||
@@ -38,64 +40,52 @@ public interface CommentService {
|
|||||||
/**
|
/**
|
||||||
* 分页获取数据
|
* 分页获取数据
|
||||||
*
|
*
|
||||||
* @param isComment true:评论 false:留言
|
* @param pagePath pagePath
|
||||||
* @param count 单页数据量
|
* @param count 单页数据量
|
||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<CommentModel> retrievePage(Boolean isComment, int page, int count);
|
PageData<CommentModel> retrievePage(String pagePath, int page, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过pid获取数据
|
* 通过pid获取数据
|
||||||
*
|
*
|
||||||
* @param pid 父id
|
* @param pid 父id
|
||||||
* @param count 单页数据量
|
|
||||||
* @param page 数据页
|
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<CommentModel> retrievePageByPid(long pid, int page, int count);
|
List<CommentModel> retrievePageByPid(long pid);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据评论者获取数据
|
* 根据评论者获取数据
|
||||||
*
|
*
|
||||||
* @param isComment true:评论 false:留言
|
* @param pagePath pagePath
|
||||||
* @param count 单页数据量
|
* @param count 单页数据量
|
||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<CommentModel> retrievePageByAuthor(Boolean isComment, int page, int count);
|
PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据文章获取数据
|
|
||||||
*
|
|
||||||
* @param articleID 文章id
|
|
||||||
* @param pid 父id
|
|
||||||
* @param count 单页数据量
|
|
||||||
* @param page 数据页
|
|
||||||
* @return 分页数据
|
|
||||||
*/
|
|
||||||
PageInfo<CommentModel> retrievePageByArticle(long articleID, long pid, int page, int count);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据数据的type和pid获取数据
|
* 根据数据的type和pid获取数据
|
||||||
*
|
*
|
||||||
* @param isComment true:评论 false:留言
|
* @param pagePath pagePath
|
||||||
* @param pid 父id
|
* @param pid 父id
|
||||||
* @param count 单页数据量
|
* @param count 单页数据量
|
||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<CommentModel> retrievePageByTypeAndPid(Boolean isComment, int pid, int page, int count);
|
PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据type获取数据
|
* 根据type获取数据
|
||||||
*
|
*
|
||||||
* @param isComment true:评论 false:留言
|
* @param pagePath pagePath
|
||||||
* @param count 单页数据量
|
* @param count 单页数据量
|
||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<CommentModel> retrievePageByType(Boolean isComment, int page, int count);
|
PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,13 +36,6 @@ public interface CountService {
|
|||||||
*/
|
*/
|
||||||
long getTagsCount();
|
long getTagsCount();
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取留言数量
|
|
||||||
*
|
|
||||||
* @return 留言数量
|
|
||||||
*/
|
|
||||||
long getLeaveMessageCount();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户量
|
* 获取用户量
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
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,8 +1,7 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Tag;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.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.blog.service;
|
||||||
|
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
import cn.celess.blog.entity.request.UserReq;
|
import cn.celess.blog.entity.request.UserReq;
|
||||||
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改用户信息
|
* 更改用户信息
|
||||||
@@ -174,4 +146,14 @@ public interface UserService {
|
|||||||
* @return true:存在 false:不存在
|
* @return true:存在 false:不存在
|
||||||
*/
|
*/
|
||||||
boolean getStatusOfEmail(String email);
|
boolean getStatusOfEmail(String email);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置密码
|
||||||
|
*
|
||||||
|
* @param pwd pwd
|
||||||
|
* @param newPwd newPwd
|
||||||
|
* @param confirmPwd confirmPwd
|
||||||
|
* @return UserModel
|
||||||
|
*/
|
||||||
|
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.VisitorModel;
|
import cn.celess.blog.entity.model.VisitorModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
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,10 +1,11 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
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
|
||||||
@@ -44,7 +45,7 @@ public interface WebUpdateInfoService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<WebUpdateModel> pages(int count, int page);
|
PageData<WebUpdateModel> pages(int count, int page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部的更新记录
|
* 获取全部的更新记录
|
||||||
@@ -58,5 +59,5 @@ public interface WebUpdateInfoService {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getLastestUpdateTime();
|
Map<String, Object> getLastestUpdateTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,32 @@
|
|||||||
package cn.celess.blog.service.serviceimpl;
|
package cn.celess.blog.service.serviceimpl;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.LevelEnum;
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import cn.celess.blog.enmu.RoleEnum;
|
||||||
import cn.celess.blog.entity.*;
|
import cn.celess.blog.entity.*;
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.*;
|
||||||
import cn.celess.blog.mapper.CategoryMapper;
|
|
||||||
import cn.celess.blog.mapper.CommentMapper;
|
|
||||||
import cn.celess.blog.mapper.TagMapper;
|
|
||||||
import cn.celess.blog.service.ArticleService;
|
import cn.celess.blog.service.ArticleService;
|
||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.service.UserService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.blog.util.ModalTrans;
|
||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
import cn.celess.blog.util.RegexUtil;
|
||||||
import cn.celess.blog.util.StringFromHtmlUtil;
|
import cn.celess.blog.util.StringFromHtmlUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.youbenzi.mdtool.tool.MDTool;
|
import com.youbenzi.mdtool.tool.MDTool;
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,8 +34,8 @@ import java.util.List;
|
|||||||
* @date : 2019/03/28 15:21
|
* @date : 2019/03/28 15:21
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class ArticleServiceImpl implements ArticleService {
|
public class ArticleServiceImpl implements ArticleService {
|
||||||
public static final Logger logger = LoggerFactory.getLogger(ArticleServiceImpl.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
@@ -50,6 +47,8 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
CommentMapper commentMapper;
|
CommentMapper commentMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
ArticleTagMapper articleTagMapper;
|
||||||
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
@@ -79,303 +78,179 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
if (reqBody.getTags() == null || reqBody.getTags().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getTags() == null || reqBody.getTags().length == 0) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
|
if (articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||||
|
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||||
|
}
|
||||||
|
// 查看是否存在已有的分类
|
||||||
|
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||||
|
if (category == null) {
|
||||||
|
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建 需要写入数据库的对象数据
|
||||||
//写入数据库的数据
|
|
||||||
Article article = new Article();
|
Article article = new Article();
|
||||||
article.setTitle(reqBody.getTitle());
|
BeanUtils.copyProperties(reqBody, article);
|
||||||
article.setOpen(reqBody.getOpen());
|
|
||||||
article.setMdContent(reqBody.getMdContent());
|
|
||||||
article.setUrl(reqBody.getUrl());
|
|
||||||
article.setType(reqBody.getType());
|
|
||||||
|
|
||||||
article.setAuthorId(redisUserUtil.get().getId());
|
article.setUser(redisUserUtil.get());
|
||||||
article.setPublishDate(new Date());
|
|
||||||
|
|
||||||
//防止出现 “null,xxx”这种情况
|
|
||||||
article.setTagsId("");
|
|
||||||
|
|
||||||
|
|
||||||
//是否需要更新上一篇文章
|
|
||||||
boolean isUpdatePreArticle = true;
|
|
||||||
|
|
||||||
Article preArticle = null;
|
|
||||||
|
|
||||||
|
|
||||||
if (articleMapper.count() == 0) {
|
|
||||||
isUpdatePreArticle = false;
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//获取最新的一条数据
|
|
||||||
preArticle = articleMapper.getLastestArticle();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isUpdatePreArticle) {
|
|
||||||
logger.info("上一篇文章的id为:" + preArticle.getId());
|
|
||||||
//设置上一篇文章的id
|
|
||||||
article.setPreArticleId(preArticle.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
//markdown->html->summary
|
//markdown->html->summary
|
||||||
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||||
//获取摘要 摘要长度为255个字符
|
//获取摘要 摘要长度为255个字符
|
||||||
String summary = str.length() > 240 ? str.substring(0, 240) + "......" : str;
|
String summary = str.length() > 240 ? str.substring(0, 240) + "......" : str;
|
||||||
|
|
||||||
//去除转换后存在的空格
|
|
||||||
String tagStr = reqBody.getTags().replaceAll(" ", "");
|
|
||||||
article.setSummary(summary);
|
article.setSummary(summary);
|
||||||
|
|
||||||
if (articleMapper.existsByTitle(article.getTitle())) {
|
article.setCategory(category);
|
||||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//将分类写入数据库
|
|
||||||
Category category1 = categoryMapper.findCategoryByName(reqBody.getCategory());
|
|
||||||
if (category1 == null) {
|
|
||||||
category1 = new Category();
|
|
||||||
category1.setArticles("");
|
|
||||||
category1.setName(reqBody.getCategory());
|
|
||||||
categoryMapper.insert(category1);
|
|
||||||
}
|
|
||||||
|
|
||||||
article.setCategoryId(category1.getId());
|
|
||||||
|
|
||||||
//文章存数据库
|
//文章存数据库
|
||||||
articleMapper.insert(article);
|
articleMapper.insert(article);
|
||||||
//获取新增的文章
|
|
||||||
|
|
||||||
if (isUpdatePreArticle) {
|
|
||||||
//更新上一篇文章的“下一篇文章ID”
|
|
||||||
articleMapper.updateNextArticleId(preArticle.getId(), article.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
//无效
|
|
||||||
// articleMapper.updatePreArticleId(article.getId(), preArticle == null ? -1 : preArticle.getId());
|
|
||||||
article.setPreArticleId(preArticle == null ? -1 : preArticle.getId());
|
|
||||||
|
|
||||||
category1.setArticles(category1.getArticles() + article.getId() + ",");
|
|
||||||
categoryMapper.update(category1);
|
|
||||||
|
|
||||||
|
|
||||||
//将标签写入数据库
|
//将标签写入数据库
|
||||||
for (String t : tagStr.split(",")) {
|
for (String tagName : reqBody.getTags()) {
|
||||||
if (t.replaceAll(" ", "").length() == 0) {
|
if (tagName.replaceAll(" ", "").length() == 0) {
|
||||||
//单个标签只含空格
|
//单个标签只含空格
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Tag tag = tagMapper.findTagByName(t);
|
Tag tag = tagMapper.findTagByName(tagName);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
tag = new Tag();
|
tag = new Tag();
|
||||||
tag.setName(t);
|
tag.setName(tagName);
|
||||||
tag.setArticles("");
|
|
||||||
tagMapper.insert(tag);
|
tagMapper.insert(tag);
|
||||||
}
|
}
|
||||||
tag.setArticles(tag.getArticles() + article.getId() + ",");
|
ArticleTag articleTag = new ArticleTag(article, tag);
|
||||||
article.setTagsId(article.getTagsId() + tag.getId() + ",");
|
articleTagMapper.insert(articleTag);
|
||||||
tagMapper.update(tag);
|
|
||||||
}
|
|
||||||
articleMapper.update(article);
|
|
||||||
return fullTransform(articleMapper.getLastestArticle());
|
|
||||||
}
|
}
|
||||||
|
Article articleFromDb = articleMapper.findArticleById(article.getId());
|
||||||
|
|
||||||
|
ArticleModel articleModel = ModalTrans.article(articleFromDb);
|
||||||
|
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(article.getId()), true));
|
||||||
|
return articleModel;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean delete(long articleID) {
|
public boolean delete(long articleId) {
|
||||||
|
Article articleForDel = articleMapper.findArticleById(articleId);
|
||||||
Article articleForDel = articleMapper.findArticleById(articleID);
|
|
||||||
|
|
||||||
if (articleForDel == null) {
|
if (articleForDel == null) {
|
||||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);//文章不存在
|
//文章不存在
|
||||||
|
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
Article preArticle = articleMapper.findArticleById(articleForDel.getPreArticleId());
|
//对访问情况进行判断 非admin 权限不可删除文章
|
||||||
Article nextArticle = articleMapper.findArticleById(articleForDel.getNextArticleId());
|
|
||||||
|
|
||||||
//对访问情况进行判断 非博主/非自己文章 拒绝访问
|
|
||||||
User user = redisUserUtil.get();
|
User user = redisUserUtil.get();
|
||||||
if (!user.getRole().contains("admin") && !articleForDel.getAuthorId().equals(user.getId())) {
|
if (!RoleEnum.ADMIN_ROLE.getRoleName().equals(user.getRole())) {
|
||||||
throw new MyException(ResponseEnum.PERMISSION_ERROR);
|
throw new MyException(ResponseEnum.PERMISSION_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除的文章处于中间位置
|
|
||||||
if (nextArticle != null && preArticle != null) {
|
|
||||||
|
|
||||||
//修改上一篇文章的“下一篇文章”y
|
|
||||||
articleMapper.updateNextArticleId(articleForDel.getPreArticleId(), articleForDel.getNextArticleId());
|
|
||||||
|
|
||||||
//修改下一篇文章的 “上一篇文章”
|
|
||||||
articleMapper.updatePreArticleId(articleForDel.getNextArticleId(), articleForDel.getPreArticleId());
|
|
||||||
}
|
|
||||||
if (preArticle == null && nextArticle != null) {
|
|
||||||
//删除的是第一篇文章
|
|
||||||
articleMapper.updatePreArticleId(nextArticle.getId(), -1);
|
|
||||||
}
|
|
||||||
if (nextArticle == null && preArticle != null) {
|
|
||||||
//删除的是最后一篇文章
|
|
||||||
articleMapper.updateNextArticleId(preArticle.getId(), -1);
|
|
||||||
}
|
|
||||||
// delete count 为删除的数据数量
|
|
||||||
int deleteCount = commentMapper.deleteByArticleId(articleID);
|
|
||||||
|
|
||||||
//删除标签中的文章id
|
|
||||||
String tag = articleForDel.getTagsId();
|
|
||||||
if (tag.length() > 0) {
|
|
||||||
String[] tags = tag.split(",");
|
|
||||||
for (String t : tags) {
|
|
||||||
if (t != null) {
|
|
||||||
//查询标签
|
|
||||||
Tag tag1 = tagMapper.findTagById(Long.parseLong(t));
|
|
||||||
//去除标签中的articleId中的待删除的文章id
|
|
||||||
String s = tag1.getArticles().replaceAll(articleForDel.getId() + ",", "");
|
|
||||||
tag1.setArticles(s);
|
|
||||||
tagMapper.update(tag1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//删除分类中的文章id
|
|
||||||
//获取文章的分类
|
|
||||||
long categoryId = articleForDel.getCategoryId();
|
|
||||||
Category category = categoryMapper.findCategoryById(categoryId);
|
|
||||||
//删除文章id
|
|
||||||
category.setArticles(category.getArticles().replaceAll(articleForDel.getId() + ",", ""));
|
|
||||||
//更新
|
|
||||||
categoryMapper.update(category);
|
|
||||||
|
|
||||||
//删除指定文章
|
//删除指定文章
|
||||||
articleMapper.delete(articleID);
|
articleMapper.delete(articleId);
|
||||||
|
|
||||||
|
//articleTagMapper.deleteByArticleId(articleId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public ArticleModel update(ArticleReq reqBody) {
|
public ArticleModel update(ArticleReq reqBody) {
|
||||||
if (reqBody == null) {
|
if (reqBody == null || reqBody.getId() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
|
// 查找数据
|
||||||
|
Article article = articleMapper.findArticleById(reqBody.getId());
|
||||||
|
|
||||||
//数据判断
|
//数据判断
|
||||||
if (reqBody.getTitle() == null || reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||||
} else if (reqBody.getMdContent() == null || reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
throw new MyException(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 MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
//转载 判断链接
|
|
||||||
if (!reqBody.getType()) {
|
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
|
||||||
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
|
article.setType(reqBody.getType());
|
||||||
|
article.setUrl(reqBody.getUrl());
|
||||||
}
|
}
|
||||||
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getCategory() != null && !reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||||
|
if (category == null) {
|
||||||
|
category = new Category();
|
||||||
|
category.setName(reqBody.getCategory());
|
||||||
|
categoryMapper.insert(category);
|
||||||
}
|
}
|
||||||
// 暂时不更新tags
|
article.setCategory(category);
|
||||||
if (reqBody.getTags() == null || reqBody.getTags().replaceAll(" ", "").isEmpty()) {
|
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//写入数据库的数据
|
//写入数据库的数据
|
||||||
Article article = new Article();
|
article.setOpen(reqBody.getOpen() == null ? article.getOpen() : reqBody.getOpen());
|
||||||
if (reqBody.getId() == null) {
|
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不能为空");
|
|
||||||
}
|
|
||||||
article.setId(reqBody.getId());
|
|
||||||
article.setTitle(reqBody.getTitle());
|
|
||||||
article.setOpen(reqBody.getOpen());
|
|
||||||
article.setMdContent(reqBody.getMdContent());
|
|
||||||
article.setUrl(reqBody.getUrl());
|
|
||||||
article.setType(reqBody.getType());
|
|
||||||
|
|
||||||
|
|
||||||
Article oldArticle = articleMapper.findArticleById(reqBody.getId());
|
|
||||||
|
|
||||||
Category category = categoryMapper.findCategoryById(oldArticle.getCategoryId());
|
|
||||||
if (!(category.getName()).equals(reqBody.getCategory())) {
|
|
||||||
//修改更新之前数据 的分类
|
|
||||||
category.setArticles(category.getArticles().replace(reqBody.getId() + ",", ""));
|
|
||||||
//更新
|
|
||||||
categoryMapper.update(category);
|
|
||||||
|
|
||||||
//更新 更新之后的分类
|
|
||||||
Category category1 = categoryMapper.findCategoryByName(reqBody.getCategory());
|
|
||||||
if (category1 == null) {
|
|
||||||
category1 = new Category();
|
|
||||||
category1.setName(reqBody.getCategory());
|
|
||||||
category1.setArticles(reqBody.getId() + ",");
|
|
||||||
categoryMapper.insert(category1);
|
|
||||||
}
|
|
||||||
article.setCategoryId(category1.getId());
|
|
||||||
} else {
|
|
||||||
article.setCategoryId(oldArticle.getCategoryId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] newTags = reqBody.getTags().split(",");
|
|
||||||
String[] tagIds = oldArticle.getTagsId().split(",");
|
|
||||||
//防止出现 ‘null2’这种情况
|
|
||||||
article.setTagsId("");
|
|
||||||
for (String t : newTags) {
|
|
||||||
Tag tag = tagMapper.findTagByName(t);
|
|
||||||
if (tag == null) {
|
|
||||||
tag = new Tag();
|
|
||||||
tag.setName(t);
|
|
||||||
tag.setArticles(oldArticle.getId() + ",");
|
|
||||||
int status = tagMapper.insert(tag);
|
|
||||||
if (status == 0) {
|
|
||||||
// 插入失败
|
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
|
||||||
}
|
|
||||||
article.setTagsId(article.getTagsId() + tag.getId() + ",");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
article.setTagsId(article.getTagsId() + tag.getId() + ",");
|
|
||||||
}
|
|
||||||
for (String tagId : tagIds) {
|
|
||||||
Tag tagById = tagMapper.findTagById(Long.parseLong(tagId));
|
|
||||||
// 在新更新的tag中是否有原有的tag
|
|
||||||
boolean isOldTag = false;
|
|
||||||
for (String s : newTags) {
|
|
||||||
if (s.equals(tagById.getName())) {
|
|
||||||
isOldTag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isOldTag) {
|
|
||||||
tagById.setArticles(tagById.getArticles().replace(oldArticle.getId() + ",", ""));
|
|
||||||
}
|
|
||||||
tagMapper.update(tagById);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// // TODO:::: tag的更新
|
|
||||||
// article.setTagsId(oldArticle.getTagsId());
|
|
||||||
|
|
||||||
|
|
||||||
article.setUpdateDate(new Date());
|
|
||||||
// TODO::::换用beansUtil
|
|
||||||
// 设置不定参数
|
|
||||||
article.setReadingNumber(oldArticle.getReadingNumber());
|
|
||||||
article.setPublishDate(oldArticle.getPublishDate());
|
|
||||||
article.setAuthorId(redisUserUtil.get().getId());
|
|
||||||
article.setPreArticleId(oldArticle.getPreArticleId());
|
|
||||||
article.setNextArticleId(oldArticle.getNextArticleId());
|
|
||||||
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||||
article.setSummary(str.length() > 240 ? str.substring(0, 240) + "......" : str);
|
article.setSummary(str.length() > 240 ? str.substring(0, 240) + "......" : str);
|
||||||
articleMapper.update(article);
|
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");
|
request.getSession().removeAttribute("article4update");
|
||||||
return fullTransform(article);
|
ArticleModel articleModel = ModalTrans.article(articleMapper.findArticleById(article.getId()));
|
||||||
|
setPreAndNextArticle(articleModel);
|
||||||
|
return articleModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArticleModel retrieveOneByID(long articleID, boolean is4update) {
|
public ArticleModel retrieveOneById(long articleId, boolean is4update) {
|
||||||
Article article = articleMapper.findArticleById(articleID);
|
Article article = articleMapper.findArticleById(articleId);
|
||||||
if (article == null) {
|
if (article == null) {
|
||||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||||
}
|
}
|
||||||
@@ -385,178 +260,109 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
throw new MyException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
throw new MyException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
article.setReadingNumber(article.getReadingNumber() + 1);
|
ArticleModel articleModel = ModalTrans.article(article);
|
||||||
|
|
||||||
if (is4update) {
|
if (is4update) {
|
||||||
//因更新而获取文章 不需要增加阅读量
|
//因更新而获取文章 不需要增加阅读量
|
||||||
request.getSession().setAttribute("article4update", article);
|
request.getSession().setAttribute("article4update", article);
|
||||||
return fullTransform(article);
|
return articleModel;
|
||||||
}
|
}
|
||||||
articleMapper.setReadingNumber(article.getReadingNumber() + 1, articleID);
|
setPreAndNextArticle(articleModel);
|
||||||
return fullTransform(article);
|
articleMapper.updateReadingNumber(articleId);
|
||||||
|
return articleModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param count 数目
|
* @param count 数目
|
||||||
* @param page 页面 默认减1
|
* @param page 页面
|
||||||
* @return
|
* @return PageInfo
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageInfo adminArticles(int count, int page) {
|
public PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted) {
|
||||||
PageHelper.startPage(page, count);
|
|
||||||
List<Article> articleList = articleMapper.findAll();
|
List<Article> articleList = articleMapper.findAll();
|
||||||
PageInfo pageInfo = new PageInfo(articleList);
|
|
||||||
pageInfo.setList(list2list(articleList, LevelEnum.BETWEEN_M_AND_H));
|
PageData<ArticleModel> pageData = new PageData<>(null, 0, count, page);
|
||||||
return pageInfo;
|
List<Article> collect;
|
||||||
|
if (deleted != null) {
|
||||||
|
collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
collect = articleList;
|
||||||
|
}
|
||||||
|
pageData.setTotal(collect.size());
|
||||||
|
List<ArticleModel> articleModels = collect.stream()
|
||||||
|
.peek(article -> article.setMdContent(null))
|
||||||
|
.map(ModalTrans::article)
|
||||||
|
.skip((page - 1) * count)
|
||||||
|
.limit(count)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
pageData.setList(articleModels);
|
||||||
|
|
||||||
|
return pageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo retrievePageForOpen(int count, int page) {
|
public PageData<ArticleModel> retrievePageForOpen(int count, int page) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Article> articleList = articleMapper.findAllByOpen(true);
|
List<Article> articleList = articleMapper.findAllByOpen(true);
|
||||||
PageInfo pageInfo = new PageInfo(articleList);
|
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<Article>(articleList));
|
||||||
pageInfo.setList(list2list(articleList, LevelEnum.MIDDLE));
|
|
||||||
return pageInfo;
|
List<ArticleModel> articleModelList = new ArrayList<>();
|
||||||
|
|
||||||
|
articleList.forEach(article -> {
|
||||||
|
ArticleModel model = ModalTrans.article(article, true);
|
||||||
|
setPreAndNextArticle(model);
|
||||||
|
articleModelList.add(model);
|
||||||
|
});
|
||||||
|
|
||||||
|
pageData.setList(articleModelList);
|
||||||
|
return pageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo findByCategory(String name, int page, int count) {
|
public PageData<ArticleModel> findByCategory(String name, int page, int count) {
|
||||||
Long idByName = categoryMapper.getIDByName(name);
|
Category category = categoryMapper.findCategoryByName(name);
|
||||||
if (idByName == null) {
|
if (category == null) {
|
||||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
}
|
}
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
PageInfo pageInfo = new PageInfo(articleMapper.getSimpleInfoByCategory(idByName));
|
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
||||||
return pageInfo;
|
|
||||||
|
List<ArticleModel> modelList = new ArrayList<>();
|
||||||
|
|
||||||
|
open.forEach(article -> {
|
||||||
|
ArticleModel model = ModalTrans.article(article, true);
|
||||||
|
model.setTags(null);
|
||||||
|
// setPreAndNextArticle(model);
|
||||||
|
model.setNextArticle(null);
|
||||||
|
model.setPreArticle(null);
|
||||||
|
modelList.add(model);
|
||||||
|
});
|
||||||
|
return new PageData<ArticleModel>(new PageInfo<Article>(open), modelList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo findByTag(String name, int page, int count) {
|
public PageData<ArticleModel> findByTag(String name, int page, int count) {
|
||||||
Tag tag = tagMapper.findTagByName(name);
|
Tag tag = tagMapper.findTagByName(name);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
||||||
}
|
}
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
String[] split = tag.getArticles().split(",");
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
||||||
List<String> list = Arrays.asList(split);
|
List<ArticleModel> modelList = new ArrayList<>();
|
||||||
List<Article> articleList = articleMapper.getSimpleInfoByTag(list);
|
articleByTag.forEach(articleTag -> {
|
||||||
PageInfo pageInfo = new PageInfo(articleList);
|
ArticleModel model = ModalTrans.article(articleTag.getArticle(), true);
|
||||||
return pageInfo;
|
model.setNextArticle(null);
|
||||||
|
model.setPreArticle(null);
|
||||||
|
modelList.add(model);
|
||||||
|
});
|
||||||
|
return new PageData<ArticleModel>(new PageInfo<ArticleTag>(articleByTag), modelList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void setPreAndNextArticle(ArticleModel articleModel) {
|
||||||
* page转换
|
if (articleModel == null) {
|
||||||
*
|
return;
|
||||||
* @param articleList 数据源
|
|
||||||
* @param level 转换级别
|
|
||||||
* @return list
|
|
||||||
*/
|
|
||||||
private List<ArticleModel> list2list(List<Article> articleList, LevelEnum level) {
|
|
||||||
List<ArticleModel> content = new ArrayList<>();
|
|
||||||
for (Article a : articleList) {
|
|
||||||
ArticleModel model;
|
|
||||||
switch (level.getLevelCode()) {
|
|
||||||
case 0:
|
|
||||||
model = simpleTransform(a);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
model = suitableTransform(a);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
model = suitableTransformForAdmin(a);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
default:
|
|
||||||
model = fullTransform(a);
|
|
||||||
}
|
}
|
||||||
content.add(model);
|
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
||||||
|
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
||||||
}
|
}
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简单的模型转换
|
|
||||||
* [id,title,summary]
|
|
||||||
*
|
|
||||||
* @param a 源数据
|
|
||||||
* @return 模型
|
|
||||||
*/
|
|
||||||
private ArticleModel simpleTransform(Article a) {
|
|
||||||
ArticleModel model = new ArticleModel();
|
|
||||||
model.setId(a.getId());
|
|
||||||
model.setTitle(a.getTitle());
|
|
||||||
model.setSummary(a.getSummary());
|
|
||||||
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 中等转换
|
|
||||||
* [id,title,summary]
|
|
||||||
* +
|
|
||||||
* [original,tags,category]
|
|
||||||
*
|
|
||||||
* @param a
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ArticleModel suitableTransform(Article a) {
|
|
||||||
ArticleModel model = simpleTransform(a);
|
|
||||||
model.setAuthorName(userService.getNameById(a.getAuthorId()));
|
|
||||||
model.setPublishDateFormat(DateFormatUtil.get(a.getPublishDate()));
|
|
||||||
model.setOriginal(a.getType());
|
|
||||||
model.setCategory(categoryMapper.getNameById(a.getCategoryId()));
|
|
||||||
String[] split = a.getTagsId().split(",");
|
|
||||||
String[] tags = new String[split.length];
|
|
||||||
for (int i = 0; i < split.length; i++) {
|
|
||||||
if (split[i] == null || "".equals(split[i])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
tags[i] = tagMapper.getNameById(Long.parseLong(split[i]));
|
|
||||||
}
|
|
||||||
model.setTags(tags);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 中等转换 for admin页面
|
|
||||||
* [id,title]
|
|
||||||
* +
|
|
||||||
* [original,UpdateDate,open,readingNumber]
|
|
||||||
*
|
|
||||||
* @param a
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ArticleModel suitableTransformForAdmin(Article a) {
|
|
||||||
ArticleModel model = simpleTransform(a);
|
|
||||||
model.setPublishDateFormat(DateFormatUtil.get(a.getPublishDate()));
|
|
||||||
model.setUpdateDateFormat(DateFormatUtil.get(a.getUpdateDate()));
|
|
||||||
model.setReadingNumber(a.getReadingNumber());
|
|
||||||
model.setOpen(a.getOpen());
|
|
||||||
model.setOriginal(a.getType());
|
|
||||||
model.setSummary(null);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全转换
|
|
||||||
* [id,title,summary,original,tags,category]
|
|
||||||
* +
|
|
||||||
* [UpdateDate,MdContent,NextArticleId,NextArticleTitle,preArticleId,preArticleTitle,open,url,readingNumber]
|
|
||||||
*
|
|
||||||
* @param a
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ArticleModel fullTransform(Article a) {
|
|
||||||
ArticleModel model = suitableTransform(a);
|
|
||||||
model.setUpdateDateFormat(DateFormatUtil.get(a.getUpdateDate()));
|
|
||||||
model.setMdContent(a.getMdContent());
|
|
||||||
model.setNextArticleId(a.getNextArticleId());
|
|
||||||
model.setNextArticleTitle(a.getNextArticleId() == -1 ? "无" : articleMapper.getTitleById(a.getNextArticleId()));
|
|
||||||
model.setPreArticleId(a.getPreArticleId());
|
|
||||||
model.setPreArticleTitle(a.getPreArticleId() == -1 ? "无" : articleMapper.getTitleById(a.getPreArticleId()));
|
|
||||||
model.setOpen(a.getOpen());
|
|
||||||
model.setUrl(a.getUrl());
|
|
||||||
model.setReadingNumber(a.getReadingNumber());
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.Article;
|
||||||
import cn.celess.blog.entity.Category;
|
import cn.celess.blog.entity.Category;
|
||||||
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
import cn.celess.blog.entity.model.CategoryModel;
|
import cn.celess.blog.entity.model.CategoryModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import cn.celess.blog.mapper.CategoryMapper;
|
import cn.celess.blog.mapper.CategoryMapper;
|
||||||
import cn.celess.blog.service.CategoryService;
|
import cn.celess.blog.service.CategoryService;
|
||||||
|
import cn.celess.blog.util.ModalTrans;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -35,46 +40,19 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
}
|
}
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
category.setName(name);
|
category.setName(name);
|
||||||
category.setArticles("");
|
|
||||||
categoryMapper.insert(category);
|
categoryMapper.insert(category);
|
||||||
return new CategoryModel(category);
|
return ModalTrans.category(category);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CategoryModel create(Category category) {
|
|
||||||
if (category == null) {
|
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
|
||||||
}
|
|
||||||
categoryMapper.insert(category);
|
|
||||||
return new CategoryModel(category);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(long id) {
|
public boolean delete(long id) {
|
||||||
Category category = categoryMapper.findCategoryById(id);
|
Category category = categoryMapper.findCategoryById(id);
|
||||||
|
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
}
|
}
|
||||||
String[] articleArray = category.getArticles().split(",");
|
|
||||||
for (int i = 0; i < articleArray.length; i++) {
|
|
||||||
if (articleArray[i] == null || "".equals(articleArray[i])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
long articleId = Long.parseLong(articleArray[i]);
|
|
||||||
Article article = articleMapper.findArticleById(articleId);
|
|
||||||
if (article == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
article.setCategoryId(-1L);
|
|
||||||
//一个 文章只对应一个分类,分类不存在则文章默认不可见
|
|
||||||
article.setOpen(false);
|
|
||||||
articleMapper.update(article);
|
|
||||||
}
|
|
||||||
return categoryMapper.delete(id) == 1;
|
return categoryMapper.delete(id) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CategoryModel update(Long id, String name) {
|
public CategoryModel update(Long id, String name) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
@@ -83,13 +61,29 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
Category category = categoryMapper.findCategoryById(id);
|
Category category = categoryMapper.findCategoryById(id);
|
||||||
category.setName(name);
|
category.setName(name);
|
||||||
categoryMapper.update(category);
|
categoryMapper.update(category);
|
||||||
return new CategoryModel(category);
|
return ModalTrans.category(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CategoryModel> retrievePage() {
|
public PageData<CategoryModel> retrievePage(int page, int count) {
|
||||||
List<CategoryModel> list = new ArrayList<>();
|
PageHelper.startPage(page, count);
|
||||||
categoryMapper.findAll().forEach(e -> list.add(new CategoryModel(e)));
|
List<Category> all = categoryMapper.findAll();
|
||||||
return list;
|
List<CategoryModel> modelList = new ArrayList<>();
|
||||||
|
all.forEach(e -> {
|
||||||
|
CategoryModel model = ModalTrans.category(e);
|
||||||
|
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(e.getId());
|
||||||
|
List<ArticleModel> articleModelList = new ArrayList<>();
|
||||||
|
allByCategoryId.forEach(article -> {
|
||||||
|
ArticleModel articleModel = ModalTrans.article(article, true);
|
||||||
|
articleModel.setPreArticle(null);
|
||||||
|
articleModel.setNextArticle(null);
|
||||||
|
articleModel.setTags(null);
|
||||||
|
articleModelList.add(articleModel);
|
||||||
|
});
|
||||||
|
model.setArticles(articleModelList);
|
||||||
|
modelList.add(model);
|
||||||
|
});
|
||||||
|
|
||||||
|
return new PageData<CategoryModel>(new PageInfo<Category>(all), modelList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
package cn.celess.blog.service.serviceimpl;
|
package cn.celess.blog.service.serviceimpl;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.CommentStatusEnum;
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Comment;
|
import cn.celess.blog.entity.Comment;
|
||||||
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.entity.model.CommentModel;
|
import cn.celess.blog.entity.model.CommentModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.CommentReq;
|
import cn.celess.blog.entity.request.CommentReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import cn.celess.blog.mapper.CommentMapper;
|
import cn.celess.blog.mapper.CommentMapper;
|
||||||
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
import cn.celess.blog.service.CommentService;
|
import cn.celess.blog.service.CommentService;
|
||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.util.ModalTrans;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
|
||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +33,7 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
CommentMapper commentMapper;
|
CommentMapper commentMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserMapper userMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -40,52 +43,43 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommentModel create(CommentReq reqBody) {
|
public CommentModel create(CommentReq reqBody) {
|
||||||
|
|
||||||
if (reqBody == null) {
|
if (reqBody == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
long authorID = redisUserUtil.get().getId();
|
User user = redisUserUtil.get();
|
||||||
Comment pComment = null;
|
Comment pComment = null;
|
||||||
if (reqBody.getPid() != null && reqBody.getPid() != -1) {
|
if (reqBody.getPid() != -1) {
|
||||||
pComment = commentMapper.findCommentById(reqBody.getPid());
|
pComment = commentMapper.findCommentById(reqBody.getPid());
|
||||||
}
|
}
|
||||||
if (reqBody.getPid() == null) {
|
|
||||||
reqBody.setPid(-1L);
|
|
||||||
}
|
|
||||||
//不是一级评论
|
//不是一级评论
|
||||||
if (reqBody.getPid() != -1 && pComment == null) {
|
if (reqBody.getPid() != -1 && pComment == null) {
|
||||||
//父评论不存在
|
//父评论不存在
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
Comment comment = new Comment();
|
Comment comment = new Comment();
|
||||||
comment.setAuthorID(authorID);
|
comment.setFromUser(user);
|
||||||
comment.setType(reqBody.getComment());
|
User userTo = new User();
|
||||||
if (reqBody.getComment()) {
|
userTo.setId(null);
|
||||||
//若为评论
|
if (reqBody.getToUserId() != -1) {
|
||||||
if (reqBody.getArticleID() <= 0) {
|
userTo = userMapper.findById(reqBody.getToUserId());
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
comment.setToUser(userTo);
|
||||||
}
|
}
|
||||||
comment.setArticleID(reqBody.getArticleID());
|
comment.setToUser(userTo);
|
||||||
} else {
|
userMapper.findById(reqBody.getToUserId());
|
||||||
comment.setArticleID(-1L);
|
BeanUtils.copyProperties(reqBody, comment);
|
||||||
}
|
|
||||||
comment.setContent(reqBody.getContent());
|
|
||||||
comment.setPid(reqBody.getPid());
|
|
||||||
comment.setDate(new Date());
|
|
||||||
comment.setResponseId("");
|
|
||||||
commentMapper.insert(comment);
|
commentMapper.insert(comment);
|
||||||
if (reqBody.getPid() != -1) {
|
return ModalTrans.comment(commentMapper.findCommentById(comment.getId()));
|
||||||
commentMapper.updateResponder(pComment.getResponseId() + comment.getId() + ",", reqBody.getPid());
|
|
||||||
}
|
|
||||||
return trans(comment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(long id) {
|
public boolean delete(long id) {
|
||||||
boolean b = commentMapper.existsById(id);
|
Comment b = commentMapper.findCommentById(id);
|
||||||
if (!b) {
|
if (b == null) {
|
||||||
throw new MyException(ResponseEnum.COMMENT_NOT_EXIST);
|
throw new MyException(ResponseEnum.COMMENT_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
if (b.getStatus() == CommentStatusEnum.DELETED.getCode()) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_IS_DELETED);
|
||||||
|
}
|
||||||
commentMapper.delete(id);
|
commentMapper.delete(id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -100,93 +94,65 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
commentMapper.updateContent(reqBody.getContent(), reqBody.getId());
|
commentMapper.updateContent(reqBody.getContent(), reqBody.getId());
|
||||||
comment.setContent(reqBody.getContent());
|
comment.setContent(reqBody.getContent());
|
||||||
}
|
}
|
||||||
if (!comment.getResponseId().equals(reqBody.getResponseId())) {
|
return ModalTrans.comment(comment);
|
||||||
commentMapper.updateResponder(reqBody.getResponseId(), reqBody.getId());
|
|
||||||
comment.setResponseId(reqBody.getResponseId());
|
|
||||||
}
|
|
||||||
return trans(comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageInfo<CommentModel> retrievePage(Boolean isComment, int page, int count) {
|
|
||||||
PageHelper.startPage(page, count);
|
|
||||||
List<Comment> commentList = commentMapper.findAllByType(isComment);
|
|
||||||
PageInfo pageInfo = new PageInfo(commentList);
|
|
||||||
pageInfo.setList(list2List(commentList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<CommentModel> retrievePageByPid(long pid, int page, int count) {
|
public PageData<CommentModel> retrievePage(String pagePath, int page, int count) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Comment> commentList = commentMapper.findAllByPId(pid);
|
List<Comment> list = commentMapper.findAllByPagePathAndPidAndNormal(pagePath, -1);
|
||||||
PageInfo pageInfo = new PageInfo(commentList);
|
return pageTrans(list);
|
||||||
pageInfo.setList(list2List(commentList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<CommentModel> retrievePageByArticle(long articleID, long pid, int page, int count) {
|
public List<CommentModel> retrievePageByPid(long pid) {
|
||||||
PageHelper.startPage(page, count);
|
List<Comment> allByPagePath = commentMapper.findAllByPid(pid);
|
||||||
List<Comment> commentList = commentMapper.findAllByArticleIDAndPId(articleID, pid);
|
List<CommentModel> commentModels = new ArrayList<>();
|
||||||
PageInfo pageInfo = new PageInfo(commentList);
|
allByPagePath.forEach(comment -> {
|
||||||
pageInfo.setList(list2List(commentList));
|
if (comment.getStatus() != CommentStatusEnum.DELETED.getCode()) {
|
||||||
return pageInfo;
|
commentModels.add(ModalTrans.comment(comment));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return commentModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<CommentModel> retrievePageByTypeAndPid(Boolean isComment, int pid, int page, int count) {
|
public PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count) {
|
||||||
|
User user = redisUserUtil.get();
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Comment> commentList = commentMapper.findCommentsByTypeAndPId(isComment, pid);
|
List<Comment> list = commentMapper.findAllByPagePathAndFromUser(pagePath, user.getId());
|
||||||
PageInfo pageInfo = new PageInfo(commentList);
|
return pageTrans(list);
|
||||||
pageInfo.setList(list2List(commentList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<CommentModel> retrievePageByAuthor(Boolean isComment, int page, int count) {
|
public PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Comment> commentList = commentMapper.findAllByAuthorIDAndType(redisUserUtil.get().getId(), isComment);
|
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||||
PageInfo pageInfo = new PageInfo(commentList);
|
return pageTrans(list, true);
|
||||||
pageInfo.setList(list2List(commentList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<CommentModel> retrievePageByType(Boolean isComment, int page, int count) {
|
public PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Comment> commentList = commentMapper.findAllByType(isComment);
|
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||||
PageInfo pageInfo = new PageInfo(commentList);
|
return pageTrans(list, true);
|
||||||
pageInfo.setList(list2List(commentList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CommentModel> list2List(List<Comment> commentList) {
|
private PageData<CommentModel> pageTrans(List<Comment> commentList) {
|
||||||
List<CommentModel> content = new ArrayList<>();
|
return pageTrans(commentList, false);
|
||||||
for (Comment c : commentList) {
|
|
||||||
content.add(trans(c));
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommentModel trans(Comment comment) {
|
private PageData<CommentModel> pageTrans(List<Comment> commentList, boolean noResponseList) {
|
||||||
CommentModel commentModel = new CommentModel();
|
PageInfo<Comment> p = PageInfo.of(commentList);
|
||||||
commentModel.setId(comment.getId());
|
List<CommentModel> modelList = new ArrayList<>();
|
||||||
commentModel.setComment(comment.getType());
|
commentList.forEach(l -> {
|
||||||
commentModel.setContent(comment.getContent());
|
CommentModel model = ModalTrans.comment(l);
|
||||||
commentModel.setArticleID(comment.getArticleID());
|
if (!noResponseList) {
|
||||||
commentModel.setDate(DateFormatUtil.get(comment.getDate()));
|
model.setRespComment(this.retrievePageByPid(model.getId()));
|
||||||
commentModel.setResponseId(comment.getResponseId());
|
|
||||||
commentModel.setPid(comment.getPid());
|
|
||||||
commentModel.setAuthorName(userService.getNameById(comment.getAuthorID()));
|
|
||||||
commentModel.setAuthorAvatarImgUrl("http://cdn.celess.cn/" + userService.getAvatarImg(comment.getAuthorID()));
|
|
||||||
|
|
||||||
if (comment.getType() && commentModel.getArticleID() > 0) {
|
|
||||||
commentModel.setArticleTitle(articleMapper.getTitleById(comment.getArticleID()));
|
|
||||||
}
|
}
|
||||||
return commentModel;
|
modelList.add(model);
|
||||||
|
});
|
||||||
|
return new PageData<CommentModel>(p, modelList);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class CountServiceImpl implements CountService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCommentCount() {
|
public long getCommentCount() {
|
||||||
return commentMapper.countByType(true);
|
return commentMapper.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,11 +47,6 @@ public class CountServiceImpl implements CountService {
|
|||||||
return tagMapper.count();
|
return tagMapper.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLeaveMessageCount() {
|
|
||||||
return commentMapper.countByType(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getUserCount() {
|
public long getUserCount() {
|
||||||
return userMapper.count();
|
return userMapper.count();
|
||||||
|
|||||||
@@ -2,18 +2,30 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.PartnerMapper;
|
import cn.celess.blog.mapper.PartnerMapper;
|
||||||
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
|
import cn.celess.blog.util.HttpUtil;
|
||||||
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
import cn.celess.blog.util.RegexUtil;
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -23,6 +35,13 @@ import java.util.List;
|
|||||||
public class PartnerSiteServiceImpl implements PartnerSiteService {
|
public class PartnerSiteServiceImpl implements PartnerSiteService {
|
||||||
@Autowired
|
@Autowired
|
||||||
PartnerMapper partnerMapper;
|
PartnerMapper partnerMapper;
|
||||||
|
@Autowired
|
||||||
|
MailService mailService;
|
||||||
|
@Autowired
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
private static final String SITE_NAME = "小海博客";
|
||||||
|
private static final String SITE_URL = "celess.cn";
|
||||||
|
private static final String SITE_EMAIL = "a@celess.cn";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartnerSite create(LinkReq reqBody) {
|
public PartnerSite create(LinkReq reqBody) {
|
||||||
@@ -51,6 +70,12 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
reqBody.setUrl("http://" + reqBody.getUrl());
|
reqBody.setUrl("http://" + reqBody.getUrl());
|
||||||
}
|
}
|
||||||
BeanUtils.copyProperties(reqBody, partnerSite);
|
BeanUtils.copyProperties(reqBody, partnerSite);
|
||||||
|
if (reqBody.getIconPath() == null) {
|
||||||
|
partnerSite.setIconPath("");
|
||||||
|
}
|
||||||
|
if (reqBody.getDesc() == null) {
|
||||||
|
partnerSite.setDesc("");
|
||||||
|
}
|
||||||
partnerMapper.insert(partnerSite);
|
partnerMapper.insert(partnerSite);
|
||||||
return partnerSite;
|
return partnerSite;
|
||||||
}
|
}
|
||||||
@@ -79,26 +104,125 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
if (!reqBody.getUrl().contains("http://") && !reqBody.getUrl().contains("https://")) {
|
if (!reqBody.getUrl().contains("http://") && !reqBody.getUrl().contains("https://")) {
|
||||||
reqBody.setUrl("http://" + reqBody.getUrl());
|
reqBody.setUrl("http://" + reqBody.getUrl());
|
||||||
}
|
}
|
||||||
|
if (reqBody.isOpen() != partnerSite.getOpen() && !partnerSite.getNotification() && !StringUtils.isEmpty(partnerSite.getEmail())) {
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setTo(partnerSite.getEmail());
|
||||||
|
smm.setText("您的友链申请,已通过");
|
||||||
|
smm.setSubject("友链申请通过");
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
partnerSite.setNotification(true);
|
||||||
|
}
|
||||||
|
BeanUtils.copyProperties(reqBody, partnerSite);
|
||||||
|
partnerMapper.update(partnerSite);
|
||||||
partnerSite.setName(reqBody.getName());
|
partnerSite.setName(reqBody.getName());
|
||||||
partnerSite.setUrl(reqBody.getUrl());
|
partnerSite.setUrl(reqBody.getUrl());
|
||||||
partnerSite.setOpen(reqBody.isOpen());
|
partnerSite.setOpen(reqBody.isOpen());
|
||||||
partnerMapper.update(partnerSite);
|
|
||||||
return partnerSite;
|
return partnerSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<PartnerSite> PartnerSitePages(int page, int count) {
|
public PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<PartnerSite> sitePage = partnerMapper.findAll();
|
List<PartnerSite> sitePage = partnerMapper.findAll(deleted);
|
||||||
PageInfo pageInfo = new PageInfo(sitePage);
|
PageInfo<PartnerSite> pageInfo = new PageInfo<PartnerSite>(sitePage);
|
||||||
return pageInfo;
|
return new PageData<>(pageInfo, sitePage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PartnerSite> findAll() {
|
public List<PartnerSite> findAll() {
|
||||||
List<PartnerSite> all = partnerMapper.findAll();
|
List<PartnerSite> all = partnerMapper.findAll();
|
||||||
|
all.forEach(partnerSite -> partnerSite.setDelete(null));
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public PartnerSite apply(LinkApplyReq linkApplyReq) {
|
||||||
|
// 空值字段
|
||||||
|
if (StringUtils.isEmpty(linkApplyReq.getName())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getUrl())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getEmail())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getLinkUrl())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
// 链接不合法
|
||||||
|
if (!RegexUtil.emailMatch(linkApplyReq.getEmail())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
|
}
|
||||||
|
if (!RegexUtil.urlMatch(linkApplyReq.getLinkUrl()) || !RegexUtil.urlMatch(linkApplyReq.getUrl())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(linkApplyReq.getIconPath()) && !RegexUtil.urlMatch(linkApplyReq.getIconPath())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
|
}
|
||||||
|
// 非强制字段 设置空
|
||||||
|
if (StringUtils.isEmpty(linkApplyReq.getIconPath())) {
|
||||||
|
linkApplyReq.setIconPath("");
|
||||||
|
}
|
||||||
|
// 抓取页面
|
||||||
|
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
|
||||||
|
if (resp == null) {
|
||||||
|
throw new MyException(ResponseEnum.CANNOT_GET_DATA);
|
||||||
|
}
|
||||||
|
PartnerSite ps = new PartnerSite();
|
||||||
|
if (resp.contains(SITE_URL)) {
|
||||||
|
//包含站点
|
||||||
|
BeanUtils.copyProperties(linkApplyReq, ps);
|
||||||
|
ps.setNotification(false);
|
||||||
|
ps.setOpen(false);
|
||||||
|
boolean exists = partnerMapper.existsByUrl(linkApplyReq.getUrl());
|
||||||
|
if (!exists) {
|
||||||
|
partnerMapper.insert(ps);
|
||||||
|
} else {
|
||||||
|
ps.setId(partnerMapper.findByUrl(linkApplyReq.getUrl()).getId());
|
||||||
|
}
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setSubject("友链申请");
|
||||||
|
smm.setText("有一条友链申请" + (exists ? ",已存在的友链链接" : "") + ",[\n" + linkApplyReq.toString() + "\n]");
|
||||||
|
smm.setTo(SITE_EMAIL);
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
} else {
|
||||||
|
// 不包含站点
|
||||||
|
String uuid;
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
if (redisUtil.hasKey(linkApplyReq.getUrl())) {
|
||||||
|
uuid = redisUtil.get(linkApplyReq.getUrl());
|
||||||
|
if (!redisUtil.hasKey(uuid)) {
|
||||||
|
redisUtil.setEx(uuid, mapper.writeValueAsString(linkApplyReq), 10, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
redisUtil.setEx(uuid, mapper.writeValueAsString(linkApplyReq), 10, TimeUnit.MINUTES);
|
||||||
|
redisUtil.setEx(linkApplyReq.getUrl(), uuid, 10, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
throw new MyException(ResponseEnum.APPLY_LINK_NO_ADD_THIS_SITE, null, uuid);
|
||||||
|
}
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public String reapply(String key) {
|
||||||
|
if (!redisUtil.hasKey(key)) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_EXPIRED);
|
||||||
|
}
|
||||||
|
String s = redisUtil.get(key);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
LinkApplyReq linkApplyReq = mapper.readValue(s, LinkApplyReq.class);
|
||||||
|
if (linkApplyReq == null) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
|
}
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setSubject("友链申请");
|
||||||
|
smm.setText("有一条未抓取到信息的友链申请,[\n" + linkApplyReq.toString() + "\n]");
|
||||||
|
smm.setTo(SITE_EMAIL);
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
redisUtil.delete(key);
|
||||||
|
redisUtil.delete(linkApplyReq.getUrl());
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class QiniuServiceImpl implements QiniuService {
|
public class QiniuServiceImpl implements QiniuService {
|
||||||
private static Configuration cfg = new Configuration(Zone.zone2());
|
private static final Configuration cfg = new Configuration(Zone.zone2());
|
||||||
private static UploadManager uploadManager;
|
private static UploadManager uploadManager;
|
||||||
private static BucketManager bucketManager;
|
private static BucketManager bucketManager;
|
||||||
private static Auth auth;
|
private static Auth auth;
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package cn.celess.blog.service.serviceimpl;
|
package cn.celess.blog.service.serviceimpl;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.ArticleTag;
|
||||||
import cn.celess.blog.entity.Tag;
|
import cn.celess.blog.entity.Tag;
|
||||||
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.TagModel;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
|
import cn.celess.blog.mapper.ArticleTagMapper;
|
||||||
import cn.celess.blog.mapper.TagMapper;
|
import cn.celess.blog.mapper.TagMapper;
|
||||||
import cn.celess.blog.service.TagService;
|
import cn.celess.blog.service.TagService;
|
||||||
|
import cn.celess.blog.util.ModalTrans;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -29,6 +34,8 @@ public class TagServiceImpl implements TagService {
|
|||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
|
@Autowired
|
||||||
|
ArticleTagMapper articleTagMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TagModel create(String name) {
|
public TagModel create(String name) {
|
||||||
@@ -39,40 +46,19 @@ public class TagServiceImpl implements TagService {
|
|||||||
Tag tag = new Tag();
|
Tag tag = new Tag();
|
||||||
tag.setName(name);
|
tag.setName(name);
|
||||||
tagMapper.insert(tag);
|
tagMapper.insert(tag);
|
||||||
return new TagModel(tag);
|
return ModalTrans.tag(tag);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TagModel create(Tag tag) {
|
|
||||||
if (tag == null) {
|
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
|
||||||
}
|
|
||||||
tagMapper.insert(tag);
|
|
||||||
return new TagModel(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean delete(long tagId) {
|
public boolean delete(long tagId) {
|
||||||
Tag tag = tagMapper.findTagById(tagId);
|
Tag tag = tagMapper.findTagById(tagId);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (tag.getArticles() == null) {
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(tagId);
|
||||||
return tagMapper.delete(tagId) == 1;
|
// 删除文章
|
||||||
}
|
articleByTag.forEach(articleTag -> articleMapper.delete(articleTag.getArticle().getId()));
|
||||||
String[] articleArray = tag.getArticles().split(",");
|
|
||||||
for (int i = 0; i < articleArray.length; i++) {
|
|
||||||
if (articleArray[i] == null || "".equals(articleArray[i])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
long articleID = Long.parseLong(articleArray[i]);
|
|
||||||
Article article = articleMapper.findArticleById(articleID);
|
|
||||||
if (article == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
article.setTagsId(article.getTagsId().replace(tagId + ",", ""));
|
|
||||||
articleMapper.update(article);
|
|
||||||
}
|
|
||||||
return tagMapper.delete(tagId) == 1;
|
return tagMapper.delete(tagId) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,47 +68,33 @@ public class TagServiceImpl implements TagService {
|
|||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
||||||
}
|
}
|
||||||
Tag tagFromDB = tagMapper.findTagById(id);
|
Tag tag = tagMapper.findTagById(id);
|
||||||
tagFromDB.setName(name);
|
tag.setName(name);
|
||||||
|
tagMapper.update(tag);
|
||||||
tagMapper.update(tagFromDB);
|
return ModalTrans.tag(tag);
|
||||||
return new TagModel(tagFromDB);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TagModel retrieveOneById(long tagId) {
|
public PageData<TagModel> retrievePage(int page, int count) {
|
||||||
Tag tag = tagMapper.findTagById(tagId);
|
|
||||||
if (tag == null) {
|
|
||||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
|
||||||
}
|
|
||||||
return new TagModel(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TagModel retrieveOneByName(String name) {
|
|
||||||
Tag tag = tagMapper.findTagByName(name);
|
|
||||||
if (tag == null) {
|
|
||||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
|
||||||
}
|
|
||||||
return new TagModel(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageInfo<TagModel> retrievePage(int page, int count) {
|
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Tag> tagList = tagMapper.findAll();
|
List<Tag> tagList = tagMapper.findAll();
|
||||||
PageInfo pageInfo = new PageInfo(tagList);
|
List<TagModel> modelList = new ArrayList<>();
|
||||||
List<TagModel> list = new ArrayList<>();
|
tagList.forEach(tag -> modelList.add(ModalTrans.tag(tag)));
|
||||||
tagList.forEach(e -> list.add(new TagModel(e)));
|
return new PageData<TagModel>(new PageInfo<Tag>(tagList), modelList);
|
||||||
pageInfo.setList(list);
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TagModel> findAll() {
|
public List<TagModel> findAll() {
|
||||||
List<TagModel> list = new ArrayList<>();
|
List<TagModel> list = new ArrayList<>();
|
||||||
tagMapper.findAll().forEach(e -> list.add(new TagModel(e)));
|
tagMapper.findAll().forEach(e -> {
|
||||||
|
TagModel model = ModalTrans.tag(e);
|
||||||
|
List<ArticleTag> articleByTagAndOpen = articleTagMapper.findArticleByTagAndOpen(e.getId());
|
||||||
|
List<ArticleModel> articleModelList = new ArrayList<>();
|
||||||
|
articleByTagAndOpen.forEach(articleTag -> articleModelList.add(ModalTrans.article(articleTag.getArticle(), true)));
|
||||||
|
model.setArticles(articleModelList);
|
||||||
|
list.add(model);
|
||||||
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package cn.celess.blog.service.serviceimpl;
|
package cn.celess.blog.service.serviceimpl;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import cn.celess.blog.enmu.RoleEnum;
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.QiniuResponse;
|
import cn.celess.blog.entity.model.QiniuResponse;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
@@ -14,8 +18,6 @@ import cn.celess.blog.service.UserService;
|
|||||||
import cn.celess.blog.util.*;
|
import cn.celess.blog.util.*;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import net.sf.json.JSONArray;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
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;
|
||||||
@@ -25,11 +27,9 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.beans.Transient;
|
import java.beans.Transient;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -74,7 +74,8 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (userMapper.existsByEmail(email)) {
|
if (userMapper.existsByEmail(email)) {
|
||||||
throw new MyException(ResponseEnum.USERNAME_HAS_EXIST);
|
throw new MyException(ResponseEnum.USERNAME_HAS_EXIST);
|
||||||
}
|
}
|
||||||
boolean b = userMapper.addUser(email, MD5Util.getMD5(password)) == 1;
|
User user = new User(email, MD5Util.getMD5(password));
|
||||||
|
boolean b = userMapper.addUser(user) == 1;
|
||||||
if (b) {
|
if (b) {
|
||||||
String verifyId = UUID.randomUUID().toString().replaceAll("-", "");
|
String verifyId = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
redisUtil.setEx(email + "-verify", verifyId, 2, TimeUnit.DAYS);
|
redisUtil.setEx(email + "-verify", verifyId, 2, TimeUnit.DAYS);
|
||||||
@@ -99,6 +100,16 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (!RegexUtil.pwdMatch(loginReq.getPassword())) {
|
if (!RegexUtil.pwdMatch(loginReq.getPassword())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User user = userMapper.findByEmail(loginReq.getEmail());
|
||||||
|
if (user == null) {
|
||||||
|
// 用户不存在
|
||||||
|
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
||||||
|
}
|
||||||
|
if (user.getStatus() != UserAccountStatusEnum.NORMAL.getCode()) {
|
||||||
|
throw new MyException(ResponseEnum.CAN_NOT_USE, UserAccountStatusEnum.get(user.getStatus()));
|
||||||
|
}
|
||||||
|
|
||||||
//获取redis缓存中登录失败次数
|
//获取redis缓存中登录失败次数
|
||||||
String s = redisUtil.get(loginReq.getEmail() + "-passwordWrongTime");
|
String s = redisUtil.get(loginReq.getEmail() + "-passwordWrongTime");
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
@@ -106,17 +117,12 @@ public class UserServiceImpl implements UserService {
|
|||||||
throw new MyException(ResponseEnum.LOGIN_LATER, loginReq.getEmail());
|
throw new MyException(ResponseEnum.LOGIN_LATER, loginReq.getEmail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
User user = null;
|
|
||||||
user = userMapper.findByEmail(loginReq.getEmail());
|
String token;
|
||||||
String token = null;
|
|
||||||
// 密码比对
|
// 密码比对
|
||||||
if (user == null) {
|
|
||||||
// 用户不存在
|
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
|
||||||
}
|
|
||||||
if (user.getPwd().equals(MD5Util.getMD5(loginReq.getPassword()))) {
|
if (user.getPwd().equals(MD5Util.getMD5(loginReq.getPassword()))) {
|
||||||
logger.info("====> {} 进行权限认证 状态:登录成功 <====", loginReq.getEmail());
|
logger.info("====> {} 进行权限认证 状态:登录成功 <====", loginReq.getEmail());
|
||||||
userMapper.updateLoginTime(loginReq.getEmail(), new Date());
|
userMapper.updateLoginTime(loginReq.getEmail());
|
||||||
redisUtil.delete(loginReq.getEmail() + "-passwordWrongTime");
|
redisUtil.delete(loginReq.getEmail() + "-passwordWrongTime");
|
||||||
// redis 标记
|
// redis 标记
|
||||||
redisUserUtil.set(user, loginReq.getIsRememberMe());
|
redisUserUtil.set(user, loginReq.getIsRememberMe());
|
||||||
@@ -137,7 +143,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
redisUtil.setEx(loginReq.getEmail() + "-passwordWrongTime", count + "", 2, TimeUnit.HOURS);
|
redisUtil.setEx(loginReq.getEmail() + "-passwordWrongTime", count + "", 2, TimeUnit.HOURS);
|
||||||
throw new MyException(ResponseEnum.LOGIN_FAILURE);
|
throw new MyException(ResponseEnum.LOGIN_FAILURE);
|
||||||
}
|
}
|
||||||
UserModel trans = trans(user);
|
UserModel trans = ModalTrans.userFullInfo(user);
|
||||||
trans.setToken(token);
|
trans.setToken(token);
|
||||||
return trans;
|
return trans;
|
||||||
|
|
||||||
@@ -164,7 +170,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
userMapper.updateInfo(desc, displayName, user.getId());
|
userMapper.updateInfo(desc, displayName, user.getId());
|
||||||
redisUserUtil.set(user);
|
redisUserUtil.set(user);
|
||||||
return trans(user);
|
return ModalTrans.userFullInfo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,20 +182,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getUserInfoByEmail(String email) {
|
|
||||||
User user = userMapper.findByEmail(email);
|
|
||||||
if (user == null) {
|
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAvatarImg(long id) {
|
|
||||||
return userMapper.getAvatarImgUrlById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object updateUserAavatarImg(InputStream is, String mime) {
|
public Object updateUserAavatarImg(InputStream is, String mime) {
|
||||||
User user = redisUserUtil.get();
|
User user = redisUserUtil.get();
|
||||||
@@ -197,13 +189,13 @@ public class UserServiceImpl implements UserService {
|
|||||||
user.setAvatarImgUrl(upload.key);
|
user.setAvatarImgUrl(upload.key);
|
||||||
userMapper.updateAvatarImgUrl(upload.key, user.getId());
|
userMapper.updateAvatarImgUrl(upload.key, user.getId());
|
||||||
redisUserUtil.set(user);
|
redisUserUtil.set(user);
|
||||||
return ResponseUtil.success(user.getAvatarImgUrl());
|
return Response.success(user.getAvatarImgUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserInfoBySession() {
|
public UserModel getUserInfoBySession() {
|
||||||
User user = redisUserUtil.get();
|
User user = redisUserUtil.get();
|
||||||
return trans(user);
|
return ModalTrans.userFullInfo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -211,18 +203,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userMapper.existsByEmail(email);
|
return userMapper.existsByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNameById(long id) {
|
|
||||||
String name = userMapper.getDisPlayName(id);
|
|
||||||
if (name == null) {
|
|
||||||
name = userMapper.getEmail(id);
|
|
||||||
if (name == null) {
|
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 找回密码
|
* 找回密码
|
||||||
*/
|
*/
|
||||||
@@ -254,7 +234,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
return "发送成功!";
|
return "发送成功!";
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
@Override
|
@Override
|
||||||
public Object sendVerifyEmail(String email) {
|
public Object sendVerifyEmail(String email) {
|
||||||
if (!RegexUtil.emailMatch(email)) {
|
if (!RegexUtil.emailMatch(email)) {
|
||||||
@@ -336,14 +315,14 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object deleteUser(Integer[] id) {
|
public Object deleteUser(Integer[] id) {
|
||||||
JSONArray status = new JSONArray();
|
List<Map<String, Object>> status = new ArrayList<>();
|
||||||
if (id == null || id.length == 0) {
|
if (id == null || id.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Integer integer : id) {
|
for (Integer integer : id) {
|
||||||
String role = userMapper.getRoleById(integer);
|
String role = userMapper.getRoleById(integer);
|
||||||
int deleteResult = 0;
|
int deleteResult = 0;
|
||||||
JSONObject deleteStatus = new JSONObject();
|
Map<String, Object> deleteStatus = new HashMap<>(3);
|
||||||
deleteStatus.put("id", integer);
|
deleteStatus.put("id", integer);
|
||||||
// 管理员账户不可删
|
// 管理员账户不可删
|
||||||
if ("admin".equals(role)) {
|
if ("admin".equals(role)) {
|
||||||
@@ -366,14 +345,11 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<UserModel> getUserList(Integer page, Integer count) {
|
public PageData<UserModel> getUserList(Integer page, Integer count, Integer status) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<User> all = userMapper.findAll();
|
List<User> all = userMapper.findAll(status);
|
||||||
PageInfo pageInfo = PageInfo.of(all);
|
List<UserModel> modelList = all.stream().map(ModalTrans::userFullInfo).collect(Collectors.toList());
|
||||||
List<UserModel> modelList = new ArrayList<>();
|
return new PageData<>(PageInfo.of(all), modelList);
|
||||||
all.forEach(user -> modelList.add(trans(user)));
|
|
||||||
pageInfo.setList(modelList);
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -402,8 +378,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
user.setPwd(MD5Util.getMD5(userReq.getPwd()));
|
user.setPwd(MD5Util.getMD5(userReq.getPwd()));
|
||||||
}
|
}
|
||||||
if (userReq.getRole() != null) {
|
if (userReq.getRole() != null) {
|
||||||
// TODO:用enum存放角色分类
|
if (RoleEnum.USER_ROLE.getRoleName().equals(userReq.getRole()) || RoleEnum.ADMIN_ROLE.getRoleName().equals(userReq.getRole())) {
|
||||||
if ("user".equals(userReq.getRole()) || "admin".equals(userReq.getRole())) {
|
|
||||||
user.setRole(userReq.getRole());
|
user.setRole(userReq.getRole());
|
||||||
} else {
|
} else {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
@@ -413,7 +388,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (!RegexUtil.emailMatch(userReq.getEmail())) {
|
if (!RegexUtil.emailMatch(userReq.getEmail())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
// TODO :: 邮件提醒
|
|
||||||
user.setEmail(userReq.getEmail());
|
user.setEmail(userReq.getEmail());
|
||||||
}
|
}
|
||||||
// 数据写入
|
// 数据写入
|
||||||
@@ -425,7 +399,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
redisUserUtil.set(user);
|
redisUserUtil.set(user);
|
||||||
}
|
}
|
||||||
logger.info("修改了用户 [id={}] 的用户的资料", userReq.getId());
|
logger.info("修改了用户 [id={}] 的用户的资料", userReq.getId());
|
||||||
return trans(user);
|
return ModalTrans.userFullInfo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -433,16 +407,17 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userMapper.existsByEmail(email);
|
return userMapper.existsByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserModel trans(User u) {
|
@Override
|
||||||
UserModel user = new UserModel();
|
public UserModel setPwd(String pwd, String newPwd, String confirmPwd) {
|
||||||
user.setId(u.getId());
|
User user = redisUserUtil.get();
|
||||||
user.setAvatarImgUrl(u.getAvatarImgUrl() == null ? null : "http://cdn.celess.cn/" + u.getAvatarImgUrl());
|
String pwd1 = userMapper.getPwd(user.getEmail());
|
||||||
user.setEmail(u.getEmail());
|
if (!MD5Util.getMD5(pwd).equals(pwd1)) {
|
||||||
user.setDesc(u.getDesc());
|
throw new MyException(ResponseEnum.PWD_WRONG);
|
||||||
user.setDisplayName(u.getDisplayName() == null ? u.getEmail() : u.getDisplayName());
|
}
|
||||||
user.setEmailStatus(u.getEmailStatus());
|
if (!newPwd.equals(confirmPwd)) {
|
||||||
user.setRecentlyLandedDate(DateFormatUtil.get(u.getRecentlyLandedDate()));
|
throw new MyException(ResponseEnum.PWD_NOT_SAME);
|
||||||
user.setRole(u.getRole());
|
}
|
||||||
return user;
|
userMapper.updatePwd(user.getEmail(), MD5Util.getMD5(newPwd));
|
||||||
|
return ModalTrans.userFullInfo(userMapper.findByEmail(user.getEmail()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Visitor;
|
import cn.celess.blog.entity.Visitor;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.VisitorModel;
|
import cn.celess.blog.entity.model.VisitorModel;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.VisitorMapper;
|
import cn.celess.blog.mapper.VisitorMapper;
|
||||||
@@ -14,7 +15,6 @@ import eu.bitwalker.useragentutils.Browser;
|
|||||||
import eu.bitwalker.useragentutils.OperatingSystem;
|
import eu.bitwalker.useragentutils.OperatingSystem;
|
||||||
import eu.bitwalker.useragentutils.UserAgent;
|
import eu.bitwalker.useragentutils.UserAgent;
|
||||||
import eu.bitwalker.useragentutils.Version;
|
import eu.bitwalker.useragentutils.Version;
|
||||||
import org.apache.commons.lang.time.DateUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.json.JsonParserFactory;
|
import org.springframework.boot.json.JsonParserFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -25,6 +25,8 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -45,12 +47,10 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<VisitorModel> visitorPage(int page, int count, boolean showLocation) {
|
public PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Visitor> visitorList = visitorMapper.findAll();
|
List<Visitor> visitorList = visitorMapper.findAll();
|
||||||
PageInfo pageInfo = new PageInfo(visitorList);
|
return new PageData<VisitorModel>(new PageInfo<Visitor>(visitorList), list2List(visitorList, showLocation));
|
||||||
pageInfo.setList(list2List(visitorList, showLocation));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,8 +68,9 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
visitor.setUa(request.getHeader("User-Agent"));
|
visitor.setUa(request.getHeader("User-Agent"));
|
||||||
//记录当日的访问
|
//记录当日的访问
|
||||||
String dayVisitCount = redisUtil.get("dayVisitCount");
|
String dayVisitCount = redisUtil.get("dayVisitCount");
|
||||||
long secondsLeftToday = 86400 - DateUtils.getFragmentInSeconds(Calendar.getInstance(), Calendar.DATE);
|
|
||||||
Date date = new Date(Calendar.YEAR);
|
LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||||
|
long secondsLeftToday = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
|
||||||
if (dayVisitCount == null) {
|
if (dayVisitCount == null) {
|
||||||
redisUtil.setEx("dayVisitCount", "1", secondsLeftToday, TimeUnit.SECONDS);
|
redisUtil.setEx("dayVisitCount", "1", secondsLeftToday, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,25 +2,33 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import cn.celess.blog.service.WebUpdateInfoService;
|
import cn.celess.blog.service.WebUpdateInfoService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.blog.util.DateFormatUtil;
|
||||||
|
import cn.celess.blog.util.HttpUtil;
|
||||||
|
import cn.celess.blog.util.ModalTrans;
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/05/12 11:43
|
* @date : 2019/05/12 11:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
||||||
@Autowired
|
@Autowired
|
||||||
WebUpdateInfoMapper webUpdateInfoMapper;
|
WebUpdateInfoMapper webUpdateInfoMapper;
|
||||||
@@ -31,11 +39,11 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
WebUpdate webUpdate = new WebUpdate(info, new Date());
|
WebUpdate webUpdate = new WebUpdate(info);
|
||||||
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new MyException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
return trans(webUpdate);
|
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -57,43 +65,51 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
}
|
}
|
||||||
webUpdate.setUpdateInfo(info);
|
webUpdate.setUpdateInfo(info);
|
||||||
webUpdateInfoMapper.update(id, info);
|
webUpdateInfoMapper.update(id, info);
|
||||||
return trans(webUpdate);
|
return ModalTrans.webUpdate(webUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<WebUpdateModel> pages(int count, int page) {
|
public PageData<WebUpdateModel> pages(int count, int page) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
||||||
PageInfo pageInfo = new PageInfo(updateList);
|
return new PageData<WebUpdateModel>(new PageInfo<WebUpdate>(updateList), list2List(updateList));
|
||||||
pageInfo.setList(list2List(updateList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WebUpdateModel> findAll() {
|
public List<WebUpdateModel> findAll() {
|
||||||
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
||||||
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
return list2List(all);
|
||||||
for (WebUpdate w : all) {
|
|
||||||
webUpdateModels.add(trans(w));
|
|
||||||
}
|
|
||||||
return webUpdateModels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLastestUpdateTime() {
|
|
||||||
return DateFormatUtil.get(webUpdateInfoMapper.getLastestOne());
|
public Map<String, Object> getLastestUpdateTime() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||||
|
map.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
||||||
|
try {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String respStr = HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1");
|
||||||
|
if (!StringUtils.isEmpty(respStr)) {
|
||||||
|
JsonNode root = mapper.readTree(respStr);
|
||||||
|
Iterator<JsonNode> elements = root.elements();
|
||||||
|
JsonNode next = elements.next();
|
||||||
|
JsonNode commit = next.get("commit");
|
||||||
|
map.put("lastCommit", commit.get("message"));
|
||||||
|
map.put("committerAuthor", commit.get("committer").get("name"));
|
||||||
|
Instant parse = Instant.parse(commit.get("committer").get("date").asText());
|
||||||
|
map.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
||||||
|
map.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + next.get("sha").asText());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("网络请求失败{}", e.getMessage());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
||||||
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
||||||
for (WebUpdate w : webUpdates) {
|
webUpdates.forEach(update -> webUpdateModels.add(ModalTrans.webUpdate(update)));
|
||||||
webUpdateModels.add(trans(w));
|
|
||||||
}
|
|
||||||
return webUpdateModels;
|
return webUpdateModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebUpdateModel trans(WebUpdate webUpdate) {
|
|
||||||
return new WebUpdateModel(webUpdate.getId(), webUpdate.getUpdateInfo(), DateFormatUtil.get(webUpdate.getUpdateTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
50
src/main/java/cn/celess/blog/util/HttpUtil.java
Normal file
50
src/main/java/cn/celess/blog/util/HttpUtil.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||||
|
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-04-23 15:51
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
public class HttpUtil {
|
||||||
|
private static final OkHttpClient CLIENT = new OkHttpClient();
|
||||||
|
|
||||||
|
public static String get(String urlStr) {
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(urlStr)
|
||||||
|
.get()
|
||||||
|
.build();
|
||||||
|
try (Response response = CLIENT.newCall(request).execute()) {
|
||||||
|
return Objects.requireNonNull(response.body()).string();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getAfterRendering(String url) {
|
||||||
|
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,17 +21,15 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class JwtUtil {
|
public class JwtUtil {
|
||||||
private static final String CLAIM_KEY_USERNAME = "sub";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 5天(毫秒)
|
* 5天(毫秒)
|
||||||
*/
|
*/
|
||||||
public static final long EXPIRATION_LONG_TIME = 432000000;
|
public static final long EXPIRATION_LONG_TIME = 432000000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 两小时(毫秒)
|
* 两小时(毫秒)
|
||||||
*/
|
*/
|
||||||
public static final long EXPIRATION_SHORT_TIME = 7200000;
|
public static final long EXPIRATION_SHORT_TIME = 7200000;
|
||||||
|
private static final String CLAIM_KEY_USERNAME = "sub";
|
||||||
/**
|
/**
|
||||||
* JWT 秘钥需自行设置不可泄露
|
* JWT 秘钥需自行设置不可泄露
|
||||||
*/
|
*/
|
||||||
|
|||||||
111
src/main/java/cn/celess/blog/util/ModalTrans.java
Normal file
111
src/main/java/cn/celess/blog/util/ModalTrans.java
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||||
|
import cn.celess.blog.entity.*;
|
||||||
|
import cn.celess.blog.entity.model.*;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,8 @@ package cn.celess.blog.util;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -31,23 +32,27 @@ public class RedisUserUtil {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User getWithOutExc() {
|
public User getWithOutExc() {
|
||||||
String token = request.getHeader("Authorization");
|
String token = request.getHeader("Authorization");
|
||||||
if (token == null || token.isEmpty()) {
|
if (token == null || token.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String email = jwtUtil.getUsernameFromToken(token);
|
String email = jwtUtil.getUsernameFromToken(token);
|
||||||
return (User) JSONObject.toBean(JSONObject.fromObject(redisUtil.get(email + "-login")), User.class);
|
return new ObjectMapper().readValue(redisUtil.get(email + "-login"), User.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User set(User user) {
|
public User set(User user) {
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
||||||
redisUtil.getExpire(user.getEmail() + "-login"), TimeUnit.MILLISECONDS);
|
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||||
|
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User set(User user, boolean isRemember) {
|
public User set(User user, boolean isRemember) {
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||||
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
request.getSession().setAttribute("email", user.getEmail());
|
request.getSession().setAttribute("email", user.getEmail());
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package cn.celess.blog.util;
|
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
|
||||||
import cn.celess.blog.entity.Response;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author : xiaohai
|
|
||||||
* @date : 2019/03/28 15:32
|
|
||||||
*/
|
|
||||||
@ResponseBody
|
|
||||||
public class ResponseUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功相应
|
|
||||||
*
|
|
||||||
* @param result 结果
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Response success(Object result) {
|
|
||||||
Response response = new Response();
|
|
||||||
response.setCode(ResponseEnum.SUCCESS.getCode());
|
|
||||||
response.setMsg(ResponseEnum.SUCCESS.getMsg());
|
|
||||||
response.setDate(System.currentTimeMillis());
|
|
||||||
response.setResult(result);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败的响应
|
|
||||||
*
|
|
||||||
* @param result 结果
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Response failure(String result) {
|
|
||||||
Response response = new Response();
|
|
||||||
response.setCode(ResponseEnum.FAILURE.getCode());
|
|
||||||
response.setMsg(ResponseEnum.FAILURE.getMsg());
|
|
||||||
response.setDate(System.currentTimeMillis());
|
|
||||||
response.setResult(result);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 其他的响应
|
|
||||||
*
|
|
||||||
* @param r 枚举常量
|
|
||||||
* @param result 结果
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Response response(ResponseEnum r, String result) {
|
|
||||||
Response response = new Response();
|
|
||||||
response.setCode(r.getCode());
|
|
||||||
response.setMsg(r.getMsg());
|
|
||||||
response.setDate(System.currentTimeMillis());
|
|
||||||
response.setResult(result);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,6 +24,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,12 +34,22 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
public class SitemapGenerateUtil {
|
public class SitemapGenerateUtil {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
@Value("${sitemap.path}")
|
@Value("${sitemap.path}")
|
||||||
private String path;
|
private String path;
|
||||||
private Map<String, String> urlList;
|
private Map<String, String> urlList;
|
||||||
|
|
||||||
@Autowired
|
private static DocumentBuilder getDocumentBuilder() {
|
||||||
ArticleMapper articleMapper;
|
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() {
|
||||||
@@ -89,24 +100,12 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ spring.datasource.url=
|
|||||||
spring.datasource.username=
|
spring.datasource.username=
|
||||||
spring.datasource.password=
|
spring.datasource.password=
|
||||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||||
|
spring.datasource.platform=mysql
|
||||||
|
# never / always / embedded
|
||||||
|
spring.datasource.initialization-mode=never
|
||||||
|
spring.datasource.sql-script-encoding=utf-8
|
||||||
|
spring.datasource.schema=classpath:sql/schema.sql
|
||||||
|
spring.datasource.data=classpath:sql/data.sql
|
||||||
|
|
||||||
|
|
||||||
################## mybatis ##################
|
################## mybatis ##################
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
server.port=8081
|
server.port=8081
|
||||||
|
|
||||||
## 七牛的密钥配置
|
# 七牛的密钥配置
|
||||||
qiniu.accessKey=
|
qiniu.accessKey=
|
||||||
qiniu.secretKey=
|
qiniu.secretKey=
|
||||||
qiniu.bucket=
|
qiniu.bucket=
|
||||||
## sitemap 存放地址
|
# sitemap 存放地址
|
||||||
sitemap.path=
|
sitemap.path=
|
||||||
## 生成JWT时候的密钥
|
# 生成JWT时候的密钥
|
||||||
jwt.secret=
|
jwt.secret=sdaniod213k123123ipoeqowekqwe
|
||||||
|
|
||||||
##spring.jpa.show-sql=false
|
##spring.jpa.show-sql=false
|
||||||
##spring.jpa.hibernate.ddl-auto=update
|
##spring.jpa.hibernate.ddl-auto=update
|
||||||
|
|
||||||
mybatis.type-handlers-package=cn.celess.blog.mapper.typehandler
|
mybatis.type-handlers-package=cn.celess.blog.mapper.typehandler
|
||||||
|
logging.level.cn.celess.blog.mapper=debug
|
||||||
# 上传单个文件的大小
|
# 上传单个文件的大小
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
# 上传文件的总大小
|
# 上传文件的总大小
|
||||||
@@ -24,10 +24,19 @@ spring.jackson.default-property-inclusion=non_null
|
|||||||
|
|
||||||
################# 数据库 ##################
|
################# 数据库 ##################
|
||||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||||
spring.datasource.url=
|
|
||||||
spring.datasource.username=
|
#h2
|
||||||
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
|
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
|
||||||
|
spring.datasource.username=sa
|
||||||
spring.datasource.password=
|
spring.datasource.password=
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|
||||||
|
|
||||||
|
spring.datasource.platform=h2
|
||||||
|
spring.datasource.sql-script-encoding=utf-8
|
||||||
|
spring.datasource.initialization-mode=ALWAYS
|
||||||
|
spring.datasource.schema=classpath:sql/schema_h2.sql
|
||||||
|
spring.datasource.data=classpath:sql/data.sql
|
||||||
|
|
||||||
|
|
||||||
################## mybatis ##################
|
################## mybatis ##################
|
||||||
@@ -49,7 +58,7 @@ server.tomcat.protocol-header = X-Forwarded-Proto
|
|||||||
|
|
||||||
|
|
||||||
############### email ##############
|
############### email ##############
|
||||||
spring.mail.host=
|
spring.mail.host=smtp.163.com
|
||||||
spring.mail.username=
|
spring.mail.username=
|
||||||
spring.mail.password=
|
spring.mail.password=
|
||||||
spring.mail.properties.mail.smtp.auth=true
|
spring.mail.properties.mail.smtp.auth=true
|
||||||
@@ -70,8 +79,8 @@ spring.mail.properties.mail.smtp.socketFactory.fallback=false
|
|||||||
spring.redis.database=1
|
spring.redis.database=1
|
||||||
# Redis服务器地址
|
# Redis服务器地址
|
||||||
spring.redis.host=127.0.0.1
|
spring.redis.host=127.0.0.1
|
||||||
# Redis服务器连接端口
|
# Redis服务器连接端口 解决端口冲突 防止使用本地的redis
|
||||||
spring.redis.port=6379
|
spring.redis.port=6380
|
||||||
# Redis服务器连接密码(默认为空)
|
# Redis服务器连接密码(默认为空)
|
||||||
spring.redis.password=
|
spring.redis.password=
|
||||||
# 连接池最大连接数(使用负值表示没有限制)
|
# 连接池最大连接数(使用负值表示没有限制)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user