Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
59b7be00eb | ||
|
|
2f6a9679da | ||
|
|
5b8700930b | ||
|
|
18477706d1 | ||
|
|
cd7e6b6378 | ||
|
|
d934fbe284 | ||
|
|
55589c6a59 | ||
|
|
4ab402ccf8 | ||
|
|
c74aea6c3b | ||
|
|
7c2b8d8d28 | ||
|
|
6798cae1b8 | ||
|
|
ba7a02c5c0 | ||
|
|
bd50cfc339 | ||
|
|
e282e16fd3 | ||
|
|
18366b7aa4 | ||
|
|
66dffbfefe | ||
|
|
a7cd83a6b5 | ||
|
|
0a5921b66d | ||
|
|
e04238f0c9 | ||
|
|
09cb012b14 | ||
|
|
922b83e169 | ||
|
|
1cd6e0d7c9 |
47
.github/workflows/mavenpublish.yml
vendored
Normal file
47
.github/workflows/mavenpublish.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
||||||
|
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
|
||||||
|
|
||||||
|
name: Blog backEnd CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
APPLICATION_PROPERTIES_TEST: ${{ secrets.APPLICATION_PROPERTIES_TEST }}
|
||||||
|
APPLICATION_PROPERTIES_PROD: ${{ secrets.APPLICATION_PROPERTIES_PROD }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK 1.8
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
|
||||||
|
- name: Build jar file
|
||||||
|
run: echo $APPLICATION_PROPERTIES_TEST|base64 -d > src/main/resources/application-test.properties && echo $APPLICATION_PROPERTIES_PROD|base64 -d> src/main/resources/application-prod.properties && mvn -B package --file pom.xml
|
||||||
|
|
||||||
|
- name: SCP
|
||||||
|
uses: appleboy/scp-action@master
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SSH_HOST }}
|
||||||
|
username: ${{ secrets.SSH_USERNAME }}
|
||||||
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
|
port: ${{ secrets.SSH_PORT }}
|
||||||
|
source: "target/blog-0.0.1-SNAPSHOT.jar"
|
||||||
|
target: "/www/wwwroot/api.celess.cn"
|
||||||
|
|
||||||
|
- name: Run SSH command
|
||||||
|
uses: garygrossgarten/github-action-ssh@v0.5.0
|
||||||
|
with:
|
||||||
|
command: cd /www/wwwroot/api.celess.cn && bash build.sh
|
||||||
|
host: ${{ secrets.SSH_HOST }}
|
||||||
|
username: ${{ secrets.SSH_USERNAME }}
|
||||||
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
|
port: ${{ secrets.SSH_PORT }}
|
||||||
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,8 +1,10 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*.imi
|
*.imi
|
||||||
|
*.iml
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# 本地项目的私有文件
|
# 本地项目的私有文件
|
||||||
back-end/blog-dev.sql
|
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
|
||||||
|
src/main/resources/application-test.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"
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# 小海博客后端管理系统
|
# 小海博客后端管理系统
|
||||||
   [](https://www.celess.cn)
|
   [](https://www.celess.cn)
|
||||||
## 基于Springboot的后端博客管理系统
|
## 基于Springboot的后端博客管理系统
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
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>
|
|
||||||
268
blog.sql
268
blog.sql
@@ -1,92 +1,176 @@
|
|||||||
CREATE DATABASE `blog`;
|
CREATE DATABASE `t_blog`;
|
||||||
|
|
||||||
USE blog;
|
USE t_blog;
|
||||||
|
|
||||||
CREATE TABLE `article`
|
CREATE TABLE `article`
|
||||||
(
|
(
|
||||||
`a_id` bigint(20) primary key auto_increment,
|
`a_id` bigint(20) primary key auto_increment,
|
||||||
`a_title` varchar(255) not null unique comment '文章标题',
|
`a_title` varchar(255) COLLATE utf8mb4_unicode_ci not null unique comment '文章标题',
|
||||||
`a_summary` varchar(255) not null comment '文章摘要',
|
`a_summary` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '文章摘要',
|
||||||
`a_md_content` longtext not null comment '文章Markdown内容',
|
`a_md_content` longtext COLLATE utf8mb4_unicode_ci not null comment '文章Markdown内容',
|
||||||
`a_tags_id` varchar(255) not null comment '标签id \',\'处于最尾端',
|
`a_url` tinytext default null comment '转载文章的原文链接',
|
||||||
`a_category_id` bigint(20) not null comment '分类的id',
|
`a_author_id` int not null comment '作者id',
|
||||||
`a_url` tinytext default null comment '转载文章的原文链接',
|
`a_is_original` boolean default true comment '文章是否原创',
|
||||||
`a_author_id` bigint(20) not null comment '作者id',
|
`a_reading_number` int default 0 comment '文章阅读数',
|
||||||
`a_is_open` boolean default true comment '文章是否可见',
|
`a_like` int default 0 comment '文章点赞数',
|
||||||
`a_is_original` boolean default true comment '文章是否原创',
|
`a_dislike` int default 0 comment '文章不喜欢数',
|
||||||
`next_a_id` bigint(20) default -1 comment '下篇文章id',
|
`a_category_id` int not null comment '文章分类id',
|
||||||
`pre_a_id` bigint(20) default -1 comment '前一篇文章的id',
|
`a_publish_date` datetime default CURRENT_TIMESTAMP comment '文章发布时间',
|
||||||
`a_reading_number` int default 0 comment '文章阅读数',
|
`a_update_date` datetime default null comment '文章的更新时间',
|
||||||
`a_publish_date` datetime not null comment '文章发布时间',
|
`a_is_open` boolean default true comment '文章是否可见',
|
||||||
`a_update_date` datetime default null comment '文章的更新时间'
|
`is_delete` boolean not null default false comment '该数据是否被删除'
|
||||||
) DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci,comment '文章表';
|
) DEFAULT CHARSET = utf8mb4
|
||||||
|
COLLATE utf8mb4_general_ci,comment '文章表';
|
||||||
CREATE TABLE `tag`
|
|
||||||
(
|
CREATE TABLE `article_tag`
|
||||||
`tag_id` bigint(20) primary key auto_increment,
|
(
|
||||||
`tag_name` varchar(255) unique not null,
|
`at_id` bigint(20) primary key auto_increment,
|
||||||
`articles` tinytext default null comment 'tag对应的文章id'
|
`a_id` bigint(20) not null comment '文章id',
|
||||||
) comment '标签表';
|
`t_id` bigint not null comment 'tag/category 的id',
|
||||||
|
`is_delete` boolean not null default false comment '该数据是否被删除'
|
||||||
CREATE table `category`
|
) comment '文章标签表';
|
||||||
(
|
|
||||||
`c_id` bigint(20) primary key auto_increment,
|
CREATE TABLE `tag_category`
|
||||||
`c_name` varchar(255) unique not null,
|
(
|
||||||
`articles` varchar(255) comment '分类下的文章'
|
`t_id` bigint(20) primary key auto_increment,
|
||||||
)comment '分类表';
|
`t_name` varchar(255) not null,
|
||||||
|
`is_category` boolean not null default true,
|
||||||
CREATE TABLE `comment`
|
`is_delete` boolean not null default false comment '该数据是否被删除'
|
||||||
(
|
) comment '标签和分类表';
|
||||||
`co_id` bigint(20) primary key auto_increment,
|
|
||||||
`co_article_id` bigint(20) default -1 comment '文章id',
|
CREATE TABLE `comment`
|
||||||
`is_comment` boolean default true comment '是否是评论',
|
(
|
||||||
`author_id` bigint(20) not null comment '留言者id',
|
`co_id` bigint(20) primary key auto_increment,
|
||||||
`co_content` text not null comment '评论/留言内容',
|
`co_page_path` varchar(255) not null comment '评论/留言的页面',
|
||||||
`co_date` datetime not null comment '评论/留言的日期',
|
`co_content` text COLLATE utf8mb4_unicode_ci not null comment '评论/留言内容',
|
||||||
`co_pid` bigint not null default -1 comment '评论/留言的父id',
|
`co_date` datetime not null comment '评论/留言的日期',
|
||||||
`co_response_id` tinytext
|
`co_status` tinyint not null default 0 comment '评论的状态',
|
||||||
) DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci,comment '评论/留言表';
|
`co_pid` bigint not null default -1 comment '评论/留言的父id',
|
||||||
|
`co_from_author_id` int not null comment '留言者id',
|
||||||
CREATE TABLE `links`
|
`co_to_author_id` int default null comment '父评论的作者id'
|
||||||
(
|
) DEFAULT CHARSET = utf8mb4
|
||||||
`site_id` bigint(20) primary key auto_increment,
|
COLLATE utf8mb4_general_ci,comment '评论/留言表';
|
||||||
`site_name` varchar(255) not null comment '友站名称',
|
|
||||||
`is_open` boolean default true comment '是否公开',
|
CREATE TABLE `links`
|
||||||
`site_url` varchar(255) not null comment '首页地址'
|
(
|
||||||
) comment '友站表';
|
`l_id` bigint(20) primary key auto_increment,
|
||||||
|
`l_name` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友站名称',
|
||||||
CREATE TABLE `visitor`
|
`l_is_open` boolean default true comment '是否公开',
|
||||||
(
|
`l_url` varchar(255) not null comment '首页地址',
|
||||||
`v_id` bigint(20) primary key auto_increment,
|
`l_icon_path` varchar(255) not null comment '友链的icon地址',
|
||||||
`v_date` datetime not null comment '访问时间',
|
`l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述',
|
||||||
`v_ip` varchar(255) not null comment '访客ip',
|
`is_delete` boolean not null default false comment '该数据是否被删除'
|
||||||
`v_user_agent` text comment '访客ua'
|
) comment '友站表';
|
||||||
) comment '访客表';
|
|
||||||
|
CREATE TABLE `visitor`
|
||||||
|
(
|
||||||
|
`v_id` bigint(20) primary key auto_increment,
|
||||||
CREATE TABLE IF NOT EXISTS `web_update`
|
`v_date` datetime not null comment '访问时间',
|
||||||
(
|
`v_ip` varchar(255) not null comment '访客ip',
|
||||||
`update_id` bigint(20) primary key auto_increment,
|
`v_user_agent` text comment '访客ua',
|
||||||
`update_info` varchar(255) not null comment '更新内容',
|
`is_delete` boolean not null default false comment '该数据是否被删除'
|
||||||
`update_time` datetime not null comment '更新时间'
|
) comment '访客表';
|
||||||
) comment '更新内容表';
|
|
||||||
|
CREATE TABLE `web_update`
|
||||||
create table `user`
|
(
|
||||||
(
|
`wu_id` int primary key auto_increment,
|
||||||
`u_id` int not null primary key auto_increment,
|
`wu_info` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '更新内容',
|
||||||
`u_email` varchar(50) not null,
|
`wu_time` datetime not null comment '更新时间',
|
||||||
`u_uid` varchar(40) default null comment '用户唯一标识码',
|
`is_delete` boolean not null default false comment '该数据是否被删除'
|
||||||
`u_pwd` varchar(40) not null comment '密码',
|
) comment '更新内容表';
|
||||||
`email_status` boolean default false comment '邮箱验证状态',
|
|
||||||
`u_avatar` varchar(255) comment '用户头像',
|
CREATE TABLE `user`
|
||||||
`u_desc` tinytext comment '用户的描述',
|
(
|
||||||
`recently_landed_time` datetime comment '最近的登录时间',
|
`u_id` int not null primary key auto_increment,
|
||||||
`email_verify_id` varchar(40) comment '用于找回密码或验证邮箱的id',
|
`u_email` varchar(50) not null,
|
||||||
`display_name` varchar(30) comment '展示的昵称',
|
`u_pwd` varchar(40) not null comment '密码',
|
||||||
`role` varchar(40) not null default 'user' comment '权限组',
|
`u_email_status` boolean default false comment '邮箱验证状态',
|
||||||
unique key `uni_user_id` (`u_id`),
|
`u_avatar` varchar(255) default null comment '用户头像',
|
||||||
unique key `uni_user_uid` (`u_uid`),
|
`u_desc` tinytext COLLATE utf8mb4_unicode_ci default null comment '用户的描述',
|
||||||
unique key `uni_user_email` (`u_email`)
|
`u_recently_landed_time` datetime default null comment '最近的登录时间',
|
||||||
) comment '用户表';
|
`u_display_name` varchar(30) COLLATE utf8mb4_unicode_ci default null comment '展示的昵称',
|
||||||
|
`u_role` varchar(40) not null default 'user' comment '权限组',
|
||||||
|
`status` tinyint(1) not null default 0 comment '账户状态',
|
||||||
|
unique key `uni_user_id` (`u_id`),
|
||||||
|
unique key `uni_user_email` (`u_email`)
|
||||||
|
) comment '用户表';
|
||||||
|
|
||||||
|
|
||||||
|
CREATE VIEW articleView
|
||||||
|
(articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount,
|
||||||
|
publishDate, updateDate, isOpen,
|
||||||
|
categoryId, categoryName, tagId, tagName,
|
||||||
|
authorId, userEmail, userAvatar, userDisplayName, isDelete)
|
||||||
|
as
|
||||||
|
select article.a_id as articleId,
|
||||||
|
article.a_title as title,
|
||||||
|
article.a_summary as summary,
|
||||||
|
article.a_md_content as mdContent,
|
||||||
|
article.a_url as url,
|
||||||
|
article.a_is_original as isOriginal,
|
||||||
|
article.a_reading_number as readingCount,
|
||||||
|
article.a_like as likeCount,
|
||||||
|
article.a_dislike as dislikeCount,
|
||||||
|
article.a_publish_date as publishDate,
|
||||||
|
article.a_update_date as updateDate,
|
||||||
|
article.a_is_open as isOpen,
|
||||||
|
category.t_id as categoryId,
|
||||||
|
category.t_name as categoryName,
|
||||||
|
tag.t_id as tagId,
|
||||||
|
tag.t_name as tagName,
|
||||||
|
user.u_id as authorId,
|
||||||
|
user.u_email as userEmail,
|
||||||
|
user.u_avatar as userAvatar,
|
||||||
|
user.u_display_name as userDisplayName,
|
||||||
|
article.is_delete as isDelete
|
||||||
|
from article,
|
||||||
|
tag_category as tag,
|
||||||
|
tag_category as category,
|
||||||
|
article_tag,
|
||||||
|
user
|
||||||
|
where article.a_id = article_tag.a_id
|
||||||
|
and article_tag.t_id = tag.t_id
|
||||||
|
and tag.is_category = false
|
||||||
|
and article.a_category_id = category.t_id
|
||||||
|
and category.is_category = true
|
||||||
|
and article.a_author_id = user.u_id;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE VIEW commentView
|
||||||
|
(commentId, pagePath, content, date, status, pid, toAuthorId, toAuthorEmail, toAuthorDisplayName,
|
||||||
|
toAuthorAvatar, fromAuthorId, fromAuthorEmail, fromAuthorDisplayName,
|
||||||
|
fromAuthorAvatar, isDelete)
|
||||||
|
as
|
||||||
|
select cuT.co_id as commentId,
|
||||||
|
cuT.co_page_path as pagePath,
|
||||||
|
cuT.co_content as content,
|
||||||
|
cuT.co_date as date,
|
||||||
|
cuT.co_status as status,
|
||||||
|
cuT.co_pid as pid,
|
||||||
|
cuT.co_to_author_id as toAuthorId,
|
||||||
|
cuT.toEmail as toAuthorEmail,
|
||||||
|
cuT.toDisplayName as toAuthorDisplayName,
|
||||||
|
cuT.toAvatar as toAuthorAvatar,
|
||||||
|
userFrom.u_id as fromAuthorId,
|
||||||
|
userFrom.u_email as fromAuthorEmail,
|
||||||
|
userFrom.u_display_name as fromAuthorDisplayName,
|
||||||
|
userFrom.u_avatar as fromAuthorAvatar,
|
||||||
|
cuT.is_delete as isDelete
|
||||||
|
from (select comment.co_id,
|
||||||
|
comment.co_page_path,
|
||||||
|
comment.co_content,
|
||||||
|
comment.co_date,
|
||||||
|
comment.co_status,
|
||||||
|
comment.co_pid,
|
||||||
|
comment.co_from_author_id,
|
||||||
|
comment.co_to_author_id,
|
||||||
|
userTo.u_email as toEmail,
|
||||||
|
userTo.u_display_name as toDisplayName,
|
||||||
|
userTo.u_avatar as toAvatar,
|
||||||
|
comment.is_delete
|
||||||
|
from comment
|
||||||
|
left join user userTo on (comment.co_to_author_id = userTo.u_id)
|
||||||
|
) as cuT,
|
||||||
|
user as userFrom
|
||||||
|
where cuT.co_from_author_id = userFrom.u_id;
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
||||||
// 本地调试时的跨域
|
// 本地调试时的跨域
|
||||||
config.addAllowedOrigin("http://localhost:4200");
|
if ("dev".equals(activeModel)) {
|
||||||
config.addAllowedOrigin("http://127.0.0.1:4200");
|
config.addAllowedOrigin("http://localhost: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);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
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 net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -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();
|
||||||
@@ -63,6 +61,11 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
|||||||
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
|
return writeResponse(ResponseEnum.LOGIN_EXPIRED, 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 +81,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(JSONObject.fromObject(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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ 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.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -36,7 +35,7 @@ public class ArticleController {
|
|||||||
public Response create(@RequestBody ArticleReq body) {
|
public Response create(@RequestBody ArticleReq body) {
|
||||||
ArticleModel articleModel = articleService.create(body);
|
ArticleModel articleModel = articleService.create(body);
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(articleModel);
|
return Response.success(articleModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +48,7 @@ public class ArticleController {
|
|||||||
public Response delete(@RequestParam("articleID") long articleId) {
|
public Response delete(@RequestParam("articleID") long articleId) {
|
||||||
boolean delete = articleService.delete(articleId);
|
boolean delete = articleService.delete(articleId);
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(delete);
|
return Response.success(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +61,7 @@ public class ArticleController {
|
|||||||
public Response update(@RequestBody ArticleReq body) {
|
public Response update(@RequestBody ArticleReq body) {
|
||||||
ArticleModel update = articleService.update(body);
|
ArticleModel update = articleService.update(body);
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
return ResponseUtil.success(update);
|
return Response.success(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,13 +79,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 +98,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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,7 +111,7 @@ 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));
|
return Response.success(articleService.adminArticles(count, page));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +126,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 +141,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,
|
||||||
*
|
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||||
* @param count
|
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||||
* @param page
|
String path = "";
|
||||||
* @return
|
if (pagePath.contains("article+")) {
|
||||||
*/
|
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||||
@GetMapping("/leaveMsg")
|
} else {
|
||||||
public Response retrievePageOfLeaveMsg(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
path = pagePath;
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
}
|
||||||
return ResponseUtil.success(commentService.retrievePageByTypeAndPid(false, -1, page, count));
|
if ("*".equals(pagePath)) {
|
||||||
|
path = null;
|
||||||
|
}
|
||||||
|
return Response.success(commentService.retrievePageByAuthor(path, page, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admin/comment/type/{type}")
|
@GetMapping("/admin/comment/pagePath/{pagePath}")
|
||||||
public Response retrievePageAdmin(
|
public Response adminComment(@PathVariable("pagePath") String pagePath,
|
||||||
@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) {
|
String path = "";
|
||||||
return ResponseUtil.success(commentService.retrievePageByType(1 == isComment, page, count));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/user/comment/type/{type}")
|
|
||||||
public Response retrievePageByAuthor(
|
|
||||||
@PathVariable(value = "type") int isComment,
|
|
||||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
|
||||||
return ResponseUtil.success(commentService.retrievePageByAuthor(1 == isComment, page, count));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ import cn.celess.blog.entity.request.LinkReq;
|
|||||||
import cn.celess.blog.exception.MyException;
|
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.DateFormatUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
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.mail.SimpleMailMessage;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -37,17 +36,17 @@ 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")
|
||||||
@@ -60,13 +59,13 @@ public class LinksController {
|
|||||||
sites.add(p);
|
sites.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ResponseUtil.success(sites);
|
return Response.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));
|
return Response.success(partnerSiteService.partnerSitePages(page, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/apply")
|
@PostMapping("/apply")
|
||||||
@@ -74,10 +73,10 @@ public class LinksController {
|
|||||||
@RequestParam("url") String url) {
|
@RequestParam("url") String url) {
|
||||||
// TODO :: 弃用发送邮件的方式。
|
// TODO :: 弃用发送邮件的方式。
|
||||||
if (name == null || name.replaceAll(" ", "").isEmpty()) {
|
if (name == null || name.replaceAll(" ", "").isEmpty()) {
|
||||||
return ResponseUtil.response(ResponseEnum.PARAMETERS_ERROR, null);
|
return Response.response(ResponseEnum.PARAMETERS_ERROR, null);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.urlMatch(url)) {
|
if (!RegexUtil.urlMatch(url)) {
|
||||||
return ResponseUtil.response(ResponseEnum.PARAMETERS_URL_ERROR, null);
|
return Response.response(ResponseEnum.PARAMETERS_URL_ERROR, null);
|
||||||
}
|
}
|
||||||
String applyTimeStr = redisUtil.get(request.getRemoteAddr() + "-Apply");
|
String applyTimeStr = redisUtil.get(request.getRemoteAddr() + "-Apply");
|
||||||
int applyTime = 0;
|
int applyTime = 0;
|
||||||
@@ -93,7 +92,6 @@ public class LinksController {
|
|||||||
message.setText("name:" + name + "\nurl:" + url + "\n" + DateFormatUtil.getNow());
|
message.setText("name:" + name + "\nurl:" + url + "\n" + DateFormatUtil.getNow());
|
||||||
Boolean send = mailService.send(message);
|
Boolean send = mailService.send(message);
|
||||||
redisUtil.setEx(request.getRemoteAddr() + "-Apply", applyTime + 1 + "", 2, TimeUnit.HOURS);
|
redisUtil.setEx(request.getRemoteAddr() + "-Apply", applyTime + 1 + "", 2, TimeUnit.HOURS);
|
||||||
return send ? ResponseUtil.success("") : ResponseUtil.failure("");
|
return send ? Response.success("") : Response.failure("");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ 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 net.sf.json.JSONArray;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
@@ -15,17 +15,18 @@ 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;
|
||||||
@@ -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("验证失败,请重新获取验证码");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +162,7 @@ public class Other {
|
|||||||
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);
|
jsonObject.put("success", 1);
|
||||||
jsonObject.put("message", "上传成功");
|
jsonObject.put("message", "上传成功");
|
||||||
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(jsonObject.toString());
|
||||||
@@ -175,42 +176,15 @@ public class Other {
|
|||||||
|
|
||||||
@GetMapping("/bingPic")
|
@GetMapping("/bingPic")
|
||||||
public Response bingPic() {
|
public Response bingPic() {
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
JSONObject imageObj;
|
||||||
try {
|
try {
|
||||||
//建立URL
|
imageObj = JSONObject.fromObject(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和输入流
|
|
||||||
bufferedReader.close();
|
|
||||||
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");
|
JSONArray jsonArray = imageObj.getJSONArray("images");
|
||||||
String imageName = jsonArray.getJSONObject(0).getString("url");
|
String imageName = jsonArray.getJSONObject(0).getString("url");
|
||||||
return ResponseUtil.success("https://cn.bing.com" + imageName);
|
return Response.success("https://cn.bing.com" + imageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
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 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.*;
|
||||||
@@ -24,34 +22,24 @@ 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")
|
||||||
@@ -61,10 +49,10 @@ public class TagController {
|
|||||||
for (TagModel t : all) {
|
for (TagModel t : all) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("name", t.getName());
|
jsonObject.put("name", t.getName());
|
||||||
jsonObject.put("size", t.getArticles() == null ? 0 : t.getArticles().size());
|
jsonObject.put("size", t.getArticles().size());
|
||||||
nameAndCount.add(jsonObject);
|
nameAndCount.add(jsonObject);
|
||||||
}
|
}
|
||||||
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) {
|
||||||
return ResponseUtil.success(userService.getUserList(pageNum, count));
|
return Response.success(userService.getUserList(pageNum, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,10 @@ 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, "登陆过期"),
|
||||||
|
PWD_WRONG(3800, "密码不正确"),
|
||||||
|
|
||||||
JWT_EXPIRED(3810, "Token过期"),
|
JWT_EXPIRED(3810, "Token过期"),
|
||||||
JWT_MALFORMED(3820, "Token格式不对"),
|
JWT_MALFORMED(3820, "Token格式不对"),
|
||||||
@@ -66,9 +70,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;
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/java/cn/celess/blog/enmu/UserAccountStatusEnum.java
Normal file
39
src/main/java/cn/celess/blog/enmu/UserAccountStatusEnum.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.celess.blog.enmu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
/**
|
* @date : 2019/03/28 22:18
|
||||||
* @author : xiaohai
|
*/
|
||||||
* @date : 2019/03/28 22:18
|
@NoArgsConstructor
|
||||||
*/
|
public class Category extends TagCategory {
|
||||||
@Data
|
public Category(String name) {
|
||||||
public class Category {
|
super.setName(name);
|
||||||
|
}
|
||||||
private Long id;
|
}
|
||||||
|
|
||||||
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,12 @@ public class PartnerSite {
|
|||||||
|
|
||||||
private Boolean open;
|
private Boolean open;
|
||||||
|
|
||||||
|
private String iconPath;
|
||||||
|
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
private Boolean delete = false;
|
||||||
|
|
||||||
public PartnerSite() {
|
public PartnerSite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
|
|
||||||
@@ -14,16 +15,45 @@ public class Response implements Serializable {
|
|||||||
private int code;
|
private int code;
|
||||||
private String msg;
|
private String msg;
|
||||||
private Object result;
|
private Object result;
|
||||||
private long date;
|
|
||||||
|
|
||||||
public Response() {
|
public Response() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response(int code, String msg, Object result, long date) {
|
public Response(int code, String msg, Object 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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;
|
|
||||||
|
public Tag(String name) {
|
||||||
private 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,28 @@ 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,5 @@ public class CategoryModel {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private List<Integer> articles;
|
private List<ArticleModel> articles;
|
||||||
|
|
||||||
|
|
||||||
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,6 @@ public class TagModel {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private List<Integer> articles;
|
private List<ArticleModel> articles;
|
||||||
|
|
||||||
public TagModel(Tag tag) {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -41,27 +40,27 @@ public class ExceptionHandle {
|
|||||||
//自定义错误
|
//自定义错误
|
||||||
if (e instanceof MyException) {
|
if (e instanceof MyException) {
|
||||||
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
|
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
|
||||||
return new Response(((MyException) e).getCode(), e.getMessage(), null, System.currentTimeMillis());
|
return new Response(((MyException) e).getCode(), e.getMessage(), null);
|
||||||
}
|
}
|
||||||
//请求路径不支持该方法
|
//请求路径不支持该方法
|
||||||
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 +69,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,9 @@ 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();
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文章状态为开放的文章
|
* 获取文章状态为开放的文章
|
||||||
@@ -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,8 @@
|
|||||||
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.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 +44,7 @@ public interface PartnerSiteService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<PartnerSite> PartnerSitePages(int page, int count);
|
PageData<PartnerSite> partnerSitePages(int page, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部数据
|
* 获取全部数据
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改用户信息
|
* 更改用户信息
|
||||||
@@ -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,7 +1,8 @@
|
|||||||
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 net.sf.json.JSONObject;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -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();
|
JSONObject getLastestUpdateTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,30 @@
|
|||||||
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;
|
||||||
|
|
||||||
|
|
||||||
@@ -37,8 +33,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 +46,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 +77,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);
|
Article articleFromDb = articleMapper.findArticleById(article.getId());
|
||||||
return fullTransform(articleMapper.getLastestArticle());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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);
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
}
|
||||||
|
article.setTitle(reqBody.getTitle());
|
||||||
}
|
}
|
||||||
|
if (reqBody.getMdContent() != null && !reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||||
|
article.setMdContent(reqBody.getMdContent());
|
||||||
|
}
|
||||||
|
|
||||||
//转载 判断链接
|
//转载 判断链接
|
||||||
if (!reqBody.getType()) {
|
if (reqBody.getType() != null) {
|
||||||
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
if (!reqBody.getType() && reqBody.getUrl() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
}
|
||||||
|
|
||||||
|
if (!reqBody.getType() && !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) {
|
||||||
// 暂时不更新tags
|
category = new Category();
|
||||||
if (reqBody.getTags() == null || reqBody.getTags().replaceAll(" ", "").isEmpty()) {
|
category.setName(reqBody.getCategory());
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
categoryMapper.insert(category);
|
||||||
|
}
|
||||||
|
article.setCategory(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
//写入数据库的数据
|
//写入数据库的数据
|
||||||
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 +259,101 @@ 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 页面 默认减1
|
||||||
* @return
|
* @return PageInfo
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageInfo adminArticles(int count, int page) {
|
public PageData<ArticleModel> adminArticles(int count, int page) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count, "articleId desc");
|
||||||
List<Article> articleList = articleMapper.findAll();
|
List<Article> articleList = articleMapper.findAll();
|
||||||
PageInfo pageInfo = new PageInfo(articleList);
|
PageData<ArticleModel> pageData = new PageData<ArticleModel>(new PageInfo<Article>(articleList));
|
||||||
pageInfo.setList(list2list(articleList, LevelEnum.BETWEEN_M_AND_H));
|
List<ArticleModel> articleModelList = new ArrayList<>();
|
||||||
return pageInfo;
|
articleList.forEach(article -> {
|
||||||
|
ArticleModel articleModel = ModalTrans.article(article);
|
||||||
|
articleModel.setMdContent(null);
|
||||||
|
articleModelList.add(articleModel);
|
||||||
|
});
|
||||||
|
pageData.setList(articleModelList);
|
||||||
|
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);
|
|
||||||
}
|
}
|
||||||
return content;
|
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
||||||
|
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 简单的模型转换
|
|
||||||
* [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(-1L);
|
||||||
//若为评论
|
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());
|
|
||||||
} else {
|
|
||||||
comment.setArticleID(-1L);
|
|
||||||
}
|
}
|
||||||
comment.setContent(reqBody.getContent());
|
comment.setToUser(userTo);
|
||||||
comment.setPid(reqBody.getPid());
|
userMapper.findById(reqBody.getToUserId());
|
||||||
comment.setDate(new Date());
|
BeanUtils.copyProperties(reqBody, comment);
|
||||||
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());
|
modelList.add(model);
|
||||||
commentModel.setAuthorName(userService.getNameById(comment.getAuthorID()));
|
});
|
||||||
commentModel.setAuthorAvatarImgUrl("http://cdn.celess.cn/" + userService.getAvatarImg(comment.getAuthorID()));
|
return new PageData<CommentModel>(p, modelList);
|
||||||
|
|
||||||
if (comment.getType() && commentModel.getArticleID() > 0) {
|
|
||||||
commentModel.setArticleTitle(articleMapper.getTitleById(comment.getArticleID()));
|
|
||||||
}
|
|
||||||
return commentModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,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.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
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;
|
||||||
@@ -87,16 +88,17 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<PartnerSite> PartnerSitePages(int page, int count) {
|
public PageData<PartnerSite> partnerSitePages(int page, int count) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<PartnerSite> sitePage = partnerMapper.findAll();
|
List<PartnerSite> sitePage = partnerMapper.findAll();
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,10 @@
|
|||||||
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.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;
|
||||||
@@ -26,7 +29,6 @@ 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.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -74,7 +76,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);
|
||||||
@@ -116,7 +119,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
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 +140,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 +167,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 +179,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 +186,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 +200,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 +231,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)) {
|
||||||
@@ -366,14 +342,12 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<UserModel> getUserList(Integer page, Integer count) {
|
public PageData<UserModel> getUserList(Integer page, Integer count) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<User> all = userMapper.findAll();
|
List<User> all = userMapper.findAll();
|
||||||
PageInfo pageInfo = PageInfo.of(all);
|
|
||||||
List<UserModel> modelList = new ArrayList<>();
|
List<UserModel> modelList = new ArrayList<>();
|
||||||
all.forEach(user -> modelList.add(trans(user)));
|
all.forEach(user -> modelList.add(ModalTrans.userFullInfo(user)));
|
||||||
pageInfo.setList(modelList);
|
return new PageData<UserModel>(PageInfo.of(all), modelList);
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -402,8 +376,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 +386,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 +397,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 +405,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;
|
||||||
@@ -45,12 +46,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
|
||||||
|
|||||||
@@ -2,16 +2,25 @@ 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.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.sf.json.JSONArray;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
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.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,6 +30,7 @@ import java.util.List;
|
|||||||
* @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 +41,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 +67,46 @@ 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() {
|
public JSONObject getLastestUpdateTime() {
|
||||||
return DateFormatUtil.get(webUpdateInfoMapper.getLastestOne());
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||||
|
jsonObject.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
||||||
|
try {
|
||||||
|
JSONArray array = JSONArray.fromObject(HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1"));
|
||||||
|
JSONObject object = array.getJSONObject(0);
|
||||||
|
JSONObject commit = object.getJSONObject("commit");
|
||||||
|
jsonObject.put("lastCommit", commit.getString("message"));
|
||||||
|
jsonObject.put("committerAuthor", commit.getJSONObject("committer").getString("name"));
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat();
|
||||||
|
Instant parse = Instant.parse(commit.getJSONObject("committer").getString("date"));
|
||||||
|
jsonObject.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
||||||
|
jsonObject.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + object.getString("sha"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("网络请求失败{}", e.getMessage());
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/main/java/cn/celess/blog/util/HttpUtil.java
Normal file
51
src/main/java/cn/celess/blog/util/HttpUtil.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 小海
|
||||||
|
* @Date: 2020-04-23 15:51
|
||||||
|
* @Desc:
|
||||||
|
*/
|
||||||
|
public class HttpUtil {
|
||||||
|
|
||||||
|
public static String get(String urlStr) throws IOException {
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
HttpURLConnection urlConnection = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlStr);
|
||||||
|
|
||||||
|
//打开http
|
||||||
|
urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
urlConnection.setDoInput(true);
|
||||||
|
urlConnection.setRequestMethod("GET");
|
||||||
|
urlConnection.connect();
|
||||||
|
|
||||||
|
try (
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
//断开连接
|
||||||
|
if (urlConnection != null) {
|
||||||
|
urlConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 秘钥需自行设置不可泄露
|
||||||
*/
|
*/
|
||||||
|
|||||||
109
src/main/java/cn/celess/blog/util/ModalTrans.java
Normal file
109
src/main/java/cn/celess/blog/util/ModalTrans.java
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
|
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.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,8 +41,9 @@ public class RedisUserUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public User set(User user) {
|
public User set(User user) {
|
||||||
|
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
||||||
redisUtil.getExpire(user.getEmail() + "-login"), TimeUnit.MILLISECONDS);
|
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
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,15 +206,17 @@ public class RedisUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定 key 的值
|
* 获取指定 key 的值
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String get(String key) {
|
public String get(String key) {
|
||||||
return redisTemplate.opsForValue().get(key);
|
return redisTemplate.opsForValue().get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回 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,11 +275,9 @@ 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.SECONDS 毫秒:TimeUnit.MILLISECONDS
|
||||||
* 时间单位, 天:TimeUnit.DAYS 小时:TimeUnit.HOURS 分钟:TimeUnit.MINUTES
|
|
||||||
* 秒: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) {
|
||||||
redisTemplate.opsForValue().set(key, value, timeout, unit);
|
redisTemplate.opsForValue().set(key, value, timeout, unit);
|
||||||
@@ -289,7 +288,7 @@ public class RedisUtil {
|
|||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
* @return 之前已经存在返回false,不存在返回true
|
* @return 之前已经存在返回false, 不存在返回true
|
||||||
*/
|
*/
|
||||||
public boolean setIfAbsent(String key, String value) {
|
public boolean setIfAbsent(String key, String value) {
|
||||||
return redisTemplate.opsForValue().setIfAbsent(key, value);
|
return redisTemplate.opsForValue().setIfAbsent(key, value);
|
||||||
@@ -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);
|
||||||
@@ -330,7 +328,7 @@ public class RedisUtil {
|
|||||||
* 同时设置一个或多个 key-value 对,当且仅当所有给定 key 都不存在
|
* 同时设置一个或多个 key-value 对,当且仅当所有给定 key 都不存在
|
||||||
*
|
*
|
||||||
* @param maps
|
* @param maps
|
||||||
* @return 之前已经存在返回false,不存在返回true
|
* @return 之前已经存在返回false, 不存在返回true
|
||||||
*/
|
*/
|
||||||
public boolean multiSetIfAbsent(Map<String, String> maps) {
|
public boolean multiSetIfAbsent(Map<String, String> maps) {
|
||||||
return redisTemplate.opsForValue().multiSetIfAbsent(maps);
|
return redisTemplate.opsForValue().multiSetIfAbsent(maps);
|
||||||
@@ -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,9 +719,8 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,18 +33,28 @@ 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() {
|
||||||
initList();
|
initList();
|
||||||
if ("".equals(path) || "classpath".equals(path)) {
|
if ("".equals(path) || "classpath".equals(path)) {
|
||||||
path = System.getProperty("user.dir")+"/sitemap.xml";
|
path = System.getProperty("user.dir") + "/sitemap.xml";
|
||||||
}
|
}
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
try {
|
try {
|
||||||
@@ -96,17 +106,5 @@ public class SitemapGenerateUtil {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static DocumentBuilder getDocumentBuilder() {
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder db = null;
|
|
||||||
try {
|
|
||||||
db = dbf.newDocumentBuilder();
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
server.port=8081
|
|
||||||
|
|
||||||
## 七牛的密钥配置
|
|
||||||
qiniu.accessKey=
|
|
||||||
qiniu.secretKey=
|
|
||||||
qiniu.bucket=
|
|
||||||
## sitemap 存放地址
|
|
||||||
sitemap.path=
|
|
||||||
## 生成JWT时候的密钥
|
|
||||||
jwt.secret=
|
|
||||||
|
|
||||||
##spring.jpa.show-sql=false
|
|
||||||
##spring.jpa.hibernate.ddl-auto=update
|
|
||||||
|
|
||||||
mybatis.type-handlers-package=cn.celess.blog.mapper.typehandler
|
|
||||||
|
|
||||||
# 上传单个文件的大小
|
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
|
||||||
# 上传文件的总大小
|
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
|
||||||
|
|
||||||
spring.jackson.default-property-inclusion=non_null
|
|
||||||
|
|
||||||
|
|
||||||
################# 数据库 ##################
|
|
||||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
|
||||||
spring.datasource.url=
|
|
||||||
spring.datasource.username=
|
|
||||||
spring.datasource.password=
|
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|
||||||
|
|
||||||
|
|
||||||
################## mybatis ##################
|
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
|
||||||
mybatis.type-aliases-package=cn.celess.blog.entity
|
|
||||||
|
|
||||||
|
|
||||||
pagehelper.helper-dialect=mysql
|
|
||||||
pagehelper.reasonable=true
|
|
||||||
pagehelper.support-methods-arguments=true
|
|
||||||
pagehelper.params=count=countSql
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### 用于nginx的代理 获取真实ip
|
|
||||||
server.use-forward-headers = true
|
|
||||||
server.tomcat.remote-ip-header = X-Real-IP
|
|
||||||
server.tomcat.protocol-header = X-Forwarded-Proto
|
|
||||||
|
|
||||||
|
|
||||||
############### email ##############
|
|
||||||
spring.mail.host=
|
|
||||||
spring.mail.username=
|
|
||||||
spring.mail.password=
|
|
||||||
spring.mail.properties.mail.smtp.auth=true
|
|
||||||
spring.mail.properties.mail.smtp.starttls.enable=true
|
|
||||||
spring.mail.properties.mail.smtp.starttls.required=true
|
|
||||||
spring.mail.default-encoding=UTF-8
|
|
||||||
spring.mail.port=465
|
|
||||||
spring.mail.properties.mail.smtp.socketFactory.port=465
|
|
||||||
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
|
|
||||||
spring.mail.properties.mail.smtp.socketFactory.fallback=false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
############### redis ##############
|
|
||||||
|
|
||||||
# REDIS (RedisProperties)
|
|
||||||
# Redis数据库索引(默认为0)
|
|
||||||
spring.redis.database=1
|
|
||||||
# Redis服务器地址
|
|
||||||
spring.redis.host=127.0.0.1
|
|
||||||
# Redis服务器连接端口
|
|
||||||
spring.redis.port=6379
|
|
||||||
# Redis服务器连接密码(默认为空)
|
|
||||||
spring.redis.password=
|
|
||||||
# 连接池最大连接数(使用负值表示没有限制)
|
|
||||||
spring.redis.jedis.pool.max-active=-1
|
|
||||||
# 连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
spring.redis.jedis.pool.max-wait=-1
|
|
||||||
# 连接池中的最大空闲连接
|
|
||||||
spring.redis.jedis.pool.max-idle=8
|
|
||||||
# 连接池中的最小空闲连接
|
|
||||||
spring.redis.jedis.pool.min-idle=0
|
|
||||||
# 连接超时时间(毫秒)
|
|
||||||
spring.redis.timeout=5000
|
|
||||||
|
|
||||||
@@ -2,4 +2,6 @@ spring.profiles.active=prod
|
|||||||
####七牛的配置
|
####七牛的配置
|
||||||
####cn.celess.blog.service.serviceimpl.QiniuServiceImpl
|
####cn.celess.blog.service.serviceimpl.QiniuServiceImpl
|
||||||
logging.level.cn.celess.blog=debug
|
logging.level.cn.celess.blog=debug
|
||||||
logging.level.cn.celess.blog.mapper=info
|
logging.level.cn.celess.blog.mapper=info
|
||||||
|
|
||||||
|
## 修改openSource 添加-test 文件用于测试 -prod文件用于线上发布
|
||||||
101
src/main/resources/mapper/ArticleTagMapper.xml
Normal file
101
src/main/resources/mapper/ArticleTagMapper.xml
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="cn.celess.blog.mapper.ArticleTagMapper">
|
||||||
|
|
||||||
|
<resultMap id="articleTagResultMap" type="cn.celess.blog.entity.ArticleTag">
|
||||||
|
<id column="at_id" property="id"/>
|
||||||
|
<result column="a_id" property="article.id"/>
|
||||||
|
<result column="t_id" property="tag.id"/>
|
||||||
|
<association property="article" column="a_id" resultMap="cn.celess.blog.mapper.ArticleMapper.articleResultMap"
|
||||||
|
javaType="cn.celess.blog.entity.Article">
|
||||||
|
</association>
|
||||||
|
<association property="tag" column="t_id" resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap"
|
||||||
|
javaType="cn.celess.blog.entity.TagCategory">
|
||||||
|
</association>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!--新增-->
|
||||||
|
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
||||||
|
insert into article_tag(a_id, t_id)
|
||||||
|
values (#{article.id}, #{tag.id})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!--通过主键修改数据-->
|
||||||
|
<update id="update">
|
||||||
|
update article_tag
|
||||||
|
<set>
|
||||||
|
<if test="article!=null and article.id != null">
|
||||||
|
a_id = #{article.id},
|
||||||
|
</if>
|
||||||
|
<if test="tag!=null and tag.id != null">
|
||||||
|
t_id = #{tag.id},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where at_id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!--通过主键删除-->
|
||||||
|
<delete id="deleteById">
|
||||||
|
delete
|
||||||
|
from article_tag
|
||||||
|
where at_id = #{id};
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteMultiById">
|
||||||
|
delete from article_tag where at_id in
|
||||||
|
<foreach item="item" collection="list" open="(" close=")" separator=",">
|
||||||
|
#{item.id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!--通过主键删除-->
|
||||||
|
<update id="deleteByArticleId">
|
||||||
|
delete
|
||||||
|
from article_tag
|
||||||
|
where a_id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="findAllByArticleId" resultMap="articleTagResultMap">
|
||||||
|
select *
|
||||||
|
from article_tag,
|
||||||
|
tag_category
|
||||||
|
where a_id = #{articleId}
|
||||||
|
and article_tag.t_id = tag_category.t_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="findOneById" resultMap="articleTagResultMap">
|
||||||
|
select *
|
||||||
|
from article_tag,
|
||||||
|
article,
|
||||||
|
tag_category
|
||||||
|
where article_tag.at_id = #{id}
|
||||||
|
and article_tag.a_id = article.a_id
|
||||||
|
and tag_category.t_id = article_tag.t_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="findArticleByTag" resultMap="articleTagResultMap">
|
||||||
|
select *
|
||||||
|
from tag_category,
|
||||||
|
article,
|
||||||
|
article_tag
|
||||||
|
where tag_category.t_id = #{tagId}
|
||||||
|
and is_category = false
|
||||||
|
and tag_category.t_id = article_tag.t_id
|
||||||
|
and article_tag.a_id = article.a_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="findArticleByTagAndOpen" resultMap="articleTagResultMap">
|
||||||
|
select *
|
||||||
|
from tag_category,
|
||||||
|
article,
|
||||||
|
article_tag
|
||||||
|
where tag_category.t_id = #{tagId}
|
||||||
|
and is_category = false
|
||||||
|
and tag_category.t_id = article_tag.t_id
|
||||||
|
and article.a_is_open = true
|
||||||
|
and article_tag.a_id = article.a_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -2,83 +2,92 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.celess.blog.mapper.CategoryMapper">
|
<mapper namespace="cn.celess.blog.mapper.CategoryMapper">
|
||||||
<resultMap id="categoryResultMap" type="cn.celess.blog.entity.Category">
|
<resultMap id="categoryResultMap" type="cn.celess.blog.entity.Category">
|
||||||
<id column="c_id" property="id"/>
|
<id column="t_id" property="id"/>
|
||||||
<result column="c_name" property="name"/>
|
<result column="t_name" property="name"/>
|
||||||
|
<result column="is_category" property="category"/>
|
||||||
|
<result column="is_delete" property="deleted"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert">
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into category (c_name, articles)
|
insert into tag_category (t_name, is_category)
|
||||||
values (#{name}, #{articles});
|
values (#{name}, true);
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="update">
|
<update id="update">
|
||||||
update category
|
update tag_category
|
||||||
set c_name=#{name},
|
set t_name=#{name}
|
||||||
articles=#{articles}
|
where t_id = #{id}
|
||||||
where c_id = #{id}
|
and is_category = true
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update tag_category
|
||||||
from category
|
set is_delete= true
|
||||||
where c_id = #{id}
|
where t_id = #{id}
|
||||||
</delete>
|
and is_category = true
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="findCategoryByName" resultMap="categoryResultMap">
|
<select id="findCategoryByName" resultMap="categoryResultMap">
|
||||||
select *
|
select *
|
||||||
from category
|
from tag_category
|
||||||
where c_name = #{name}
|
where t_name = #{name}
|
||||||
|
and is_category = true
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findCategoryById" resultMap="categoryResultMap">
|
<select id="findCategoryById" resultMap="categoryResultMap">
|
||||||
select *
|
select *
|
||||||
from category
|
from tag_category
|
||||||
where c_id = #{id}
|
where t_id = #{id}
|
||||||
|
and is_category = true
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAll" resultMap="categoryResultMap">
|
<select id="findAll" resultMap="categoryResultMap">
|
||||||
select *
|
select *
|
||||||
from category
|
from tag_category
|
||||||
|
where is_category = true
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getAllName" resultType="java.lang.String">
|
<select id="getAllName" resultType="java.lang.String">
|
||||||
select c_name
|
select t_name
|
||||||
from category
|
from tag_category
|
||||||
|
where is_category = true
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getNameById" resultType="java.lang.String">
|
<select id="getNameById" resultType="java.lang.String">
|
||||||
select c_name
|
select t_name
|
||||||
from category
|
from tag_category
|
||||||
where c_id = #{id}
|
where is_category = true
|
||||||
|
and t_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getIDByName" resultType="java.lang.Long">
|
<select id="getIdByName" resultType="java.lang.Long">
|
||||||
select c_id
|
select t_id
|
||||||
from category
|
from tag_category
|
||||||
where c_name = #{name}
|
where is_category = true
|
||||||
|
and t_name = #{name}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsByName" resultType="java.lang.Boolean">
|
<select id="existsByName" resultType="java.lang.Boolean">
|
||||||
SELECT EXISTS(SELECT * FROM category WHERE c_name = #{name})
|
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = true)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsById" resultType="java.lang.Boolean">
|
<select id="existsById" resultType="java.lang.Boolean">
|
||||||
SELECT EXISTS(SELECT * FROM category WHERE c_id = #{id})
|
SELECT EXISTS(SELECT * FROM tag_category WHERE t_id = #{id})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getLastestCategory" resultMap="categoryResultMap">
|
<select id="getLastestCategory" resultMap="categoryResultMap">
|
||||||
select *
|
select *
|
||||||
from category
|
from tag_category
|
||||||
order by c_id desc
|
where is_category = true
|
||||||
|
order by t_id desc
|
||||||
limit 1;
|
limit 1;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="count" resultType="java.lang.Long">
|
<select id="count" resultType="java.lang.Long">
|
||||||
select count(*)
|
select count(*)
|
||||||
from category;
|
from tag_category
|
||||||
|
where is_category = true
|
||||||
|
and is_delete = false;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -3,21 +3,42 @@
|
|||||||
<mapper namespace="cn.celess.blog.mapper.CommentMapper">
|
<mapper namespace="cn.celess.blog.mapper.CommentMapper">
|
||||||
<resultMap id="commentResultMap" type="cn.celess.blog.entity.Comment">
|
<resultMap id="commentResultMap" type="cn.celess.blog.entity.Comment">
|
||||||
<id column="co_id" property="id"/>
|
<id column="co_id" property="id"/>
|
||||||
<result column="co_article_id" property="articleID"/>
|
<result column="co_page_path" property="pagePath"/>
|
||||||
<result column="is_comment" property="type"/>
|
<result column="co_status" property="status"/>
|
||||||
<result column="author_id" property="authorID"/>
|
|
||||||
<result column="co_content" property="content"/>
|
<result column="co_content" property="content"/>
|
||||||
<result column="co_date" property="date"/>
|
<result column="co_date" property="date"/>
|
||||||
<result column="co_pid" property="pid"/>
|
<result column="co_pid" property="pid"/>
|
||||||
<result column="co_response_id" property="responseId"/>
|
<result column="co_from_author_id" property="fromUser.id"/>
|
||||||
|
<result column="co_to_author_id" property="toUser.id"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert">
|
<resultMap id="commentViewResultMap" type="cn.celess.blog.entity.Comment">
|
||||||
insert into comment (co_article_id, is_comment, author_id, co_content, co_date, co_pid)
|
<id column="commentId" property="id"/>
|
||||||
VALUES (#{articleID}, #{type}, #{authorID}, #{content}, #{date}, #{pid})
|
<result column="pagePath" property="pagePath"/>
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
<result column="status" property="status"/>
|
||||||
SELECT LAST_INSERT_ID() AS id
|
<result column="content" property="content"/>
|
||||||
</selectKey>
|
<result column="date" property="date"/>
|
||||||
|
<result column="pid" property="pid"/>
|
||||||
|
<result column="fromAuthorId" property="fromUser.id"/>
|
||||||
|
<result column="toAuthorId" property="toUser.id"/>
|
||||||
|
<association property="fromUser" column="fromAuthorId" javaType="cn.celess.blog.entity.User">
|
||||||
|
<id column="fromAuthorId" property="id"/>
|
||||||
|
<result column="fromAuthorEmail" property="email"/>
|
||||||
|
<result column="fromAuthorDisplayName" property="displayName"/>
|
||||||
|
<result column="fromAuthorAvatar" property="avatarImgUrl"/>
|
||||||
|
</association>
|
||||||
|
<association property="toUser" column="toAuthorId" javaType="cn.celess.blog.entity.User">
|
||||||
|
<id column="toAuthorId" property="id"/>
|
||||||
|
<result column="toAuthorEmail" property="email"/>
|
||||||
|
<result column="toAuthorDisplayName" property="displayName"/>
|
||||||
|
<result column="toAuthorAvatar" property="avatarImgUrl"/>
|
||||||
|
</association>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into comment (co_page_path, co_content, co_date, co_pid, co_from_author_id, co_to_author_id, is_delete)
|
||||||
|
VALUES (#{pagePath}, #{content}, now(), #{pid}, #{fromUser.id}, #{toUser.id}, false)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateContent">
|
<update id="updateContent">
|
||||||
@@ -26,73 +47,86 @@
|
|||||||
where co_id = #{id}
|
where co_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateResponder">
|
<update id="delete">
|
||||||
update comment
|
update comment
|
||||||
set co_response_id =#{responder}
|
set co_status = 3
|
||||||
where co_id = #{id}
|
where co_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
<delete id="delete">
|
|
||||||
delete
|
<update id="deleteByPagePath">
|
||||||
from comment
|
update comment
|
||||||
where co_id = #{id}
|
set co_status = 3
|
||||||
</delete>
|
where co_page_path = #{path}
|
||||||
<delete id="deleteByArticleId">
|
</update>
|
||||||
delete
|
|
||||||
from comment
|
|
||||||
where co_article_id = #{articleId}
|
|
||||||
</delete>
|
|
||||||
<select id="existsById" resultType="java.lang.Boolean">
|
<select id="existsById" resultType="java.lang.Boolean">
|
||||||
SELECT EXISTS(SELECT * FROM comment WHERE co_id = #{id})
|
SELECT EXISTS(SELECT * FROM comment WHERE co_id = #{id})
|
||||||
</select>
|
</select>
|
||||||
<select id="findCommentById" resultMap="commentResultMap">
|
|
||||||
|
<select id="findCommentById" resultMap="commentViewResultMap">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
where co_id = #{id}
|
where commentId = #{sqid}
|
||||||
</select>
|
</select>
|
||||||
<select id="findAllByAuthorIDAndType" resultMap="commentResultMap">
|
|
||||||
|
<select id="findAllByFromUser" resultMap="commentViewResultMap">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
where author_id = #{id}
|
where fromAuthorId = #{id}
|
||||||
and is_comment = #{isComment}
|
|
||||||
</select>
|
</select>
|
||||||
<select id="findAllByPId" resultMap="commentResultMap">
|
|
||||||
|
<select id="findAllByPid" resultMap="commentViewResultMap">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
where co_pid = #{pid}
|
where pid = #{pid}
|
||||||
</select>
|
</select>
|
||||||
<select id="findAllByArticleID" resultMap="commentResultMap">
|
|
||||||
|
<select id="findAllByPagePath" resultMap="commentViewResultMap" parameterType="string">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
where co_article_id = #{articleId}
|
# 无奈之举
|
||||||
|
<if test="toString() != null ">
|
||||||
|
where pagePath = #{pagePath}
|
||||||
|
</if>
|
||||||
</select>
|
</select>
|
||||||
<select id="findAllByArticleIDAndPId" resultMap="commentResultMap">
|
|
||||||
|
<select id="findAllByPagePathAndFromUser" resultMap="commentViewResultMap">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
where co_article_id = #{articleID}
|
where
|
||||||
and co_pid = #{pid}
|
<if test="pagePath != null ">
|
||||||
|
pagePath = #{pagePath} and
|
||||||
|
</if>
|
||||||
|
fromAuthorId = #{userId}
|
||||||
</select>
|
</select>
|
||||||
<select id="findCommentsByTypeAndPId" resultMap="commentResultMap">
|
|
||||||
|
<select id="findAllByPagePathAndPidAndNormal" resultMap="commentViewResultMap">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
where is_comment = #{isComment}
|
where
|
||||||
and co_pid = #{pid}
|
<if test="pagePath != null ">
|
||||||
|
pagePath = #{pagePath} and
|
||||||
|
</if>
|
||||||
|
pid = #{pid} and status = 0
|
||||||
</select>
|
</select>
|
||||||
<select id="findAllByType" resultMap="commentResultMap">
|
|
||||||
select *
|
<select id="countByPagePath" resultType="java.lang.Long">
|
||||||
from comment
|
|
||||||
where is_comment = #{isComment}
|
|
||||||
</select>
|
|
||||||
<select id="countByType" resultType="java.lang.Long">
|
|
||||||
select count(*)
|
select count(*)
|
||||||
from comment
|
from commentView
|
||||||
where is_comment = #{isComment}
|
where pagePath = #{pagePath}
|
||||||
</select>
|
</select>
|
||||||
<select id="getLastestComment" resultMap="commentResultMap">
|
|
||||||
|
<select id="getLastestComment" resultMap="commentViewResultMap">
|
||||||
select *
|
select *
|
||||||
from comment
|
from commentView
|
||||||
order by co_id desc
|
order by commentId desc
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="count" resultType="long">
|
||||||
|
select count(*)
|
||||||
|
from comment
|
||||||
|
where co_status = 0;
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -2,69 +2,71 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.celess.blog.mapper.PartnerMapper">
|
<mapper namespace="cn.celess.blog.mapper.PartnerMapper">
|
||||||
<resultMap id="partnerSiteResultMap" type="cn.celess.blog.entity.PartnerSite">
|
<resultMap id="partnerSiteResultMap" type="cn.celess.blog.entity.PartnerSite">
|
||||||
<id column="site_id" property="id"/>
|
<id column="l_id" property="id"/>
|
||||||
<result column="site_name" property="name"/>
|
<result column="l_name" property="name"/>
|
||||||
<result column="site_url" property="url"/>
|
<result column="l_url" property="url"/>
|
||||||
<result column="is_open" property="open"/>
|
<result column="l_is_open" property="open"/>
|
||||||
|
<result column="l_icon_path" property="iconPath"/>
|
||||||
|
<result column="l_desc" property="desc"/>
|
||||||
|
<result column="is_delete" property="delete"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite">
|
<insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into links (site_name, is_open, site_url)
|
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, is_delete)
|
||||||
values (#{name}, #{open}, #{url})
|
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, false)
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
|
<update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
|
||||||
update links set
|
update links set
|
||||||
<if test="name!=null">site_name=#{name},</if>
|
<if test="open!=null">l_is_open=#{open},</if>
|
||||||
<if test="url!=null">site_url=#{url},</if>
|
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
|
||||||
<if test="open!=null">is_open=#{open}</if>
|
<if test="desc!=null">l_desc=#{desc},</if>
|
||||||
where site_id=#{id}
|
<if test="url!=null">l_url=#{url},</if>
|
||||||
|
<if test="name!=null">l_name=#{name}</if>
|
||||||
|
where l_id=#{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update links
|
||||||
from links
|
set is_delete = true
|
||||||
where site_id = #{id}
|
where l_id = #{id}
|
||||||
</delete>
|
</update>
|
||||||
|
|
||||||
<select id="existsById" resultType="boolean">
|
<select id="existsById" resultType="boolean">
|
||||||
SELECT EXISTS(SELECT * FROM links WHERE site_id = #{id})
|
SELECT EXISTS(SELECT * FROM links WHERE l_id = #{id})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsByName" resultType="boolean">
|
<select id="existsByName" resultType="boolean">
|
||||||
SELECT EXISTS(SELECT * FROM links WHERE site_name = #{name})
|
SELECT EXISTS(SELECT * FROM links WHERE l_name = #{name})
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsByUrl" resultType="boolean">
|
<select id="existsByUrl" resultType="boolean">
|
||||||
SELECT EXISTS(SELECT * FROM links WHERE site_url = #{url})
|
SELECT EXISTS(SELECT * FROM links WHERE l_url = #{url})
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findById" resultMap="partnerSiteResultMap">
|
<select id="findById" resultMap="partnerSiteResultMap">
|
||||||
select *
|
select *
|
||||||
from links
|
from links
|
||||||
where site_id = #{id}
|
where l_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findByName" resultMap="partnerSiteResultMap">
|
<select id="findByName" resultMap="partnerSiteResultMap">
|
||||||
select *
|
select *
|
||||||
from links
|
from links
|
||||||
where site_name = #{name}
|
where l_name = #{name}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findByUrl" resultMap="partnerSiteResultMap">
|
<select id="findByUrl" resultMap="partnerSiteResultMap">
|
||||||
select *
|
select *
|
||||||
from links
|
from links
|
||||||
where site_url = #{url}
|
where l_url = #{url}
|
||||||
</select>
|
</select>
|
||||||
<select id="getLastest" resultMap="partnerSiteResultMap">
|
<select id="getLastest" resultMap="partnerSiteResultMap">
|
||||||
select *
|
select *
|
||||||
from links
|
from links
|
||||||
order by site_id desc
|
order by l_id desc
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||||
|
|||||||
@@ -4,68 +4,74 @@
|
|||||||
<resultMap id="userResultMap" type="cn.celess.blog.entity.User">
|
<resultMap id="userResultMap" type="cn.celess.blog.entity.User">
|
||||||
<id column="u_id" property="id"/>
|
<id column="u_id" property="id"/>
|
||||||
<result column="u_email" property="email"/>
|
<result column="u_email" property="email"/>
|
||||||
<result column="u_uid" property="uid"/>
|
|
||||||
<result column="u_pwd" property="pwd"/>
|
<result column="u_pwd" property="pwd"/>
|
||||||
<result column="email_status" property="emailStatus"/>
|
<result column="u_email_status" property="emailStatus"/>
|
||||||
<result column="u_avatar" property="avatarImgUrl"/>
|
<result column="u_avatar" property="avatarImgUrl"/>
|
||||||
<result column="u_desc" property="desc"/>
|
<result column="u_desc" property="desc"/>
|
||||||
<result column="recently_landed_time" property="recentlyLandedDate"/>
|
<result column="u_recently_landed_time" property="recentlyLandedDate"/>
|
||||||
<result column="email_verify_id" property="emailVerifyId"/>
|
<result column="u_display_name" property="displayName"/>
|
||||||
<result column="display_name" property="displayName"/>
|
<result column="u_role" property="role"/>
|
||||||
<result column="role" property="role"/>
|
<result column="status" property="status"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="addUser">
|
<insert id="addUser" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into user(u_email, u_pwd)
|
insert into user(u_email, u_pwd)
|
||||||
values (#{email}, #{pwd})
|
values (#{email}, #{pwd})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateInfo">
|
<update id="updateInfo">
|
||||||
update user set
|
update user set
|
||||||
<if test="desc!=null">`u_desc`=#{desc},</if>
|
<if test="desc!=null">u_desc=#{desc},</if>
|
||||||
<if test="displayName!=null">`display_name`=#{displayName}</if>
|
<if test="displayName!=null">u_display_name=#{displayName}</if>
|
||||||
where u_id=#{id}
|
where u_id=#{id}
|
||||||
</update>
|
</update>
|
||||||
<update id="updateLoginTime">
|
<update id="updateLoginTime">
|
||||||
update user
|
update user
|
||||||
set `recently_landed_time`=#{date}
|
set u_recently_landed_time=now()
|
||||||
where `u_email` = #{email}
|
where u_email = #{email}
|
||||||
</update>
|
</update>
|
||||||
<update id="updateAvatarImgUrl">
|
<update id="updateAvatarImgUrl">
|
||||||
update user
|
update user
|
||||||
set `u_avatar`=#{avatarImgUrl}
|
set u_avatar=#{avatarImgUrl}
|
||||||
where `u_id` = #{id}
|
where u_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
<update id="updateEmailStatus">
|
<update id="updateEmailStatus">
|
||||||
update user
|
update user
|
||||||
set `email_status`=#{status}
|
set u_email_status=#{status}
|
||||||
where `u_email` = #{email}
|
where u_email = #{email}
|
||||||
</update>
|
</update>
|
||||||
<update id="updatePwd">
|
<update id="updatePwd">
|
||||||
update user
|
update user
|
||||||
set `u_pwd`=#{pwd}
|
set u_pwd=#{pwd}
|
||||||
where `u_email` = #{email}
|
where u_email = #{email}
|
||||||
</update>
|
</update>
|
||||||
<update id="setUserRole">
|
<update id="setUserRole">
|
||||||
update user
|
update user
|
||||||
set role=#{role}
|
set u_role=#{role}
|
||||||
where u_id = #{uid}
|
where u_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
<update id="update">
|
<update id="update">
|
||||||
update user
|
update user
|
||||||
set `u_email` = #{email},
|
set u_email = #{email},
|
||||||
`u_pwd` = #{pwd},
|
u_pwd = #{pwd},
|
||||||
`email_status` = #{emailStatus},
|
u_email_status = #{emailStatus},
|
||||||
`u_desc` = #{desc},
|
u_desc = #{desc},
|
||||||
`display_name` = #{displayName},
|
u_display_name = #{displayName},
|
||||||
`role` = #{role}
|
u_avatar = #{avatarImgUrl},
|
||||||
where `u_id` = #{id}
|
u_role = #{role}
|
||||||
</update>
|
|
||||||
<delete id="delete">
|
|
||||||
delete
|
|
||||||
from user
|
|
||||||
where u_id = #{id}
|
where u_id = #{id}
|
||||||
</delete>
|
</update>
|
||||||
|
<update id="delete">
|
||||||
|
update user
|
||||||
|
set status= 2
|
||||||
|
where u_id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="lock">
|
||||||
|
update user
|
||||||
|
set status= 1
|
||||||
|
where u_id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="existsByEmail" resultType="java.lang.Boolean">
|
<select id="existsByEmail" resultType="java.lang.Boolean">
|
||||||
select exists(select * from user where u_email = #{email})
|
select exists(select * from user where u_email = #{email})
|
||||||
@@ -96,7 +102,7 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getDisPlayName" resultType="java.lang.String">
|
<select id="getDisPlayName" resultType="java.lang.String">
|
||||||
select display_name
|
select u_display_name
|
||||||
from user
|
from user
|
||||||
where u_id = #{id}
|
where u_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
@@ -107,16 +113,17 @@
|
|||||||
where u_email = #{email}
|
where u_email = #{email}
|
||||||
</select>
|
</select>
|
||||||
<select id="getRoleByEmail" resultType="java.lang.String">
|
<select id="getRoleByEmail" resultType="java.lang.String">
|
||||||
select role
|
select u_role
|
||||||
from user
|
from user
|
||||||
where u_email = #{emai}
|
where u_email = #{emai}
|
||||||
</select>
|
</select>
|
||||||
<select id="count" resultType="java.lang.Long">
|
<select id="count" resultType="java.lang.Long">
|
||||||
select count(*)
|
select count(*)
|
||||||
from user
|
from user
|
||||||
|
where status =0;
|
||||||
</select>
|
</select>
|
||||||
<select id="getRoleById" resultType="java.lang.String">
|
<select id="getRoleById" resultType="java.lang.String">
|
||||||
select role
|
select u_role
|
||||||
from user
|
from user
|
||||||
where u_id = #{id}
|
where u_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -6,23 +6,29 @@
|
|||||||
<result column="v_date" property="date"/>
|
<result column="v_date" property="date"/>
|
||||||
<result column="v_user_agent" property="ua"/>
|
<result column="v_user_agent" property="ua"/>
|
||||||
<result column="v_ip" property="ip"/>
|
<result column="v_ip" property="ip"/>
|
||||||
|
<result column="is_delete" property="delete"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert">
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into visitor (v_date, v_ip, v_user_agent)
|
insert into visitor (v_date, v_ip, v_user_agent)
|
||||||
values (#{date}, #{ip}, #{ua})
|
values (#{date}, #{ip}, #{ua})
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update visitor
|
||||||
from visitor
|
set is_delete = true
|
||||||
where v_id = #{id}
|
where v_id = #{id}
|
||||||
</delete>
|
</update>
|
||||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||||
select *
|
select *
|
||||||
from visitor order by v_id desc
|
from visitor
|
||||||
|
order by v_id desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="findAllNotDeleted" resultMap="partnerSiteResultMap">
|
||||||
|
select *
|
||||||
|
from visitor
|
||||||
|
where is_delete = false
|
||||||
|
order by v_id desc
|
||||||
</select>
|
</select>
|
||||||
<select id="count" resultType="java.lang.Long">
|
<select id="count" resultType="java.lang.Long">
|
||||||
select count(*)
|
select count(*)
|
||||||
|
|||||||
@@ -2,47 +2,54 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.celess.blog.mapper.WebUpdateInfoMapper">
|
<mapper namespace="cn.celess.blog.mapper.WebUpdateInfoMapper">
|
||||||
<resultMap id="webUpdateResultMap" type="cn.celess.blog.entity.WebUpdate">
|
<resultMap id="webUpdateResultMap" type="cn.celess.blog.entity.WebUpdate">
|
||||||
<id column="update_id" property="id"/>
|
<id column="wu_id" property="id"/>
|
||||||
<result column="update_info" property="updateInfo"/>
|
<result column="wu_info" property="updateInfo"/>
|
||||||
<result column="update_time" property="updateTime"/>
|
<result column="wu_time" property="updateTime"/>
|
||||||
|
<result column="is_delete" property="delete"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<insert id="insert" parameterType="cn.celess.blog.entity.WebUpdate">
|
|
||||||
insert into web_update(update_info, update_time)
|
<insert id="insert" parameterType="cn.celess.blog.entity.WebUpdate" useGeneratedKeys="true" keyProperty="id">
|
||||||
values (#{updateInfo}, #{updateTime})
|
insert into web_update(wu_info, wu_time, is_delete)
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
values (#{updateInfo}, now(), false)
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="update">
|
<update id="update">
|
||||||
update web_update
|
update web_update
|
||||||
set update_info=#{info}
|
set wu_info=#{info}
|
||||||
where update_id = #{id};
|
where wu_id = #{id};
|
||||||
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update web_update
|
||||||
from web_update
|
set is_delete = true
|
||||||
where update_id = #{id}
|
where wu_id = #{id}
|
||||||
</delete>
|
</update>
|
||||||
<select id="existsById" resultType="java.lang.Boolean">
|
<select id="existsById" resultType="java.lang.Boolean">
|
||||||
select EXISTS(select * from web_update where update_id = #{id})
|
select EXISTS(select * from web_update where wu_id = #{id})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findById" resultMap="webUpdateResultMap">
|
<select id="findById" resultMap="webUpdateResultMap">
|
||||||
select *
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
where update_id = #{id}
|
where wu_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAll" resultMap="webUpdateResultMap">
|
<select id="findAll" resultMap="webUpdateResultMap">
|
||||||
select *
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
|
order by wu_id desc
|
||||||
</select>
|
</select>
|
||||||
<select id="getLastestOne" resultType="date">
|
|
||||||
select update_time
|
<select id="findAllNotDeleted" resultMap="webUpdateResultMap">
|
||||||
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
order by update_id desc
|
where is_delete = false
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getLastestOne" resultMap="webUpdateResultMap">
|
||||||
|
select *
|
||||||
|
from web_update
|
||||||
|
order by wu_id desc
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -6,158 +6,180 @@
|
|||||||
<result column="a_title" property="title"/>
|
<result column="a_title" property="title"/>
|
||||||
<result column="a_summary" property="summary"/>
|
<result column="a_summary" property="summary"/>
|
||||||
<result column="a_md_content" property="mdContent"/>
|
<result column="a_md_content" property="mdContent"/>
|
||||||
<result column="a_tags_id" property="tagsId"/>
|
|
||||||
<result column="a_category_id" property="categoryId"/>
|
|
||||||
<result column="a_url" property="url"/>
|
<result column="a_url" property="url"/>
|
||||||
<result column="a_author_id" property="authorId"/>
|
<result column="a_author_id" property="user.id"/>
|
||||||
<result column="a_is_open" property="open"/>
|
<result column="a_is_open" property="open"/>
|
||||||
<result column="a_is_original" property="type"/>
|
<result column="a_is_original" property="type"/>
|
||||||
<result column="next_a_id" property="nextArticleId"/>
|
<!-- <result column="next_a_id" property="nextArticleId"/>-->
|
||||||
<result column="pre_a_id" property="preArticleId"/>
|
<!-- <result column="pre_a_id" property="preArticleId"/>-->
|
||||||
<result column="a_reading_number" property="readingNumber"/>
|
<result column="a_reading_number" property="readingNumber"/>
|
||||||
<result column="a_publish_date" property="publishDate"/>
|
<result column="a_publish_date" property="publishDate"/>
|
||||||
<result column="a_update_date" property="updateDate"/>
|
<result column="a_update_date" property="updateDate"/>
|
||||||
|
<result column="is_delete" property="deleted"/>
|
||||||
|
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
|
||||||
|
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||||
|
</association>
|
||||||
|
<collection property="tags" ofType="cn.celess.blog.entity.TagCategory"
|
||||||
|
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||||
|
</collection>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert" parameterType="cn.celess.blog.entity.Article">
|
|
||||||
insert into article (a_author_id, a_category_id, a_tags_id, a_md_content, a_publish_date,
|
<resultMap id="articleViewResultMap" type="cn.celess.blog.entity.Article">
|
||||||
|
<id column="articleId" property="id"/>
|
||||||
|
<result column="title" property="title"/>
|
||||||
|
<result column="summary" property="summary"/>
|
||||||
|
<result column="mdContent" property="mdContent"/>
|
||||||
|
<result column="url" property="url"/>
|
||||||
|
<result column="isOpen" property="open"/>
|
||||||
|
<result column="isOriginal" property="type"/>
|
||||||
|
<result column="likeCount" property="likeCount"/>
|
||||||
|
<result column="dislikeCount" property="dislikeCount"/>
|
||||||
|
<result column="readingCount" property="readingNumber"/>
|
||||||
|
<result column="publishDate" property="publishDate"/>
|
||||||
|
<result column="updateDate" property="updateDate"/>
|
||||||
|
<result column="isDelete" property="deleted"/>
|
||||||
|
<association property="category" column="categoryId" javaType="cn.celess.blog.entity.Category">
|
||||||
|
<id column="categoryId" property="id"/>
|
||||||
|
<result column="categoryName" property="name"/>
|
||||||
|
</association>
|
||||||
|
<association property="user" column="authorId" javaType="cn.celess.blog.entity.User">
|
||||||
|
<id column="authorId" property="id"/>
|
||||||
|
<result column="userEmail" property="email"/>
|
||||||
|
<result column="userAvatar" property="avatarImgUrl"/>
|
||||||
|
<result column="userDisplayName" property="displayName"/>
|
||||||
|
</association>
|
||||||
|
<collection property="tags" ofType="cn.celess.blog.entity.Tag">
|
||||||
|
<id column="tagId" property="id"/>
|
||||||
|
<result column="tagName" property="name"/>
|
||||||
|
</collection>
|
||||||
|
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.blog.entity.Article">
|
||||||
|
insert into article (a_author_id, a_category_id, a_md_content, a_is_original,
|
||||||
a_summary, a_title, a_url)
|
a_summary, a_title, a_url)
|
||||||
values (#{authorId}, #{categoryId}, #{tagsId}, #{mdContent}, #{publishDate},
|
values (#{user.id}, #{category.id}, #{mdContent}, #{type}, #{summary}, #{title}, #{url})
|
||||||
#{summary}, #{title}, #{url})
|
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update article
|
||||||
from article
|
set is_delete = true
|
||||||
where a_id = #{id}
|
where a_id = #{id}
|
||||||
</delete>
|
</update>
|
||||||
|
|
||||||
<update id="update">
|
<update id="update">
|
||||||
update article
|
update article
|
||||||
set
|
set a_update_date=now(),
|
||||||
<if test="title!=null">a_title=#{title},</if>
|
<if test="title!=null">a_title=#{title},</if>
|
||||||
<if test="mdContent!=null">a_md_content=#{mdContent},</if>
|
<if test="mdContent!=null">a_md_content=#{mdContent},</if>
|
||||||
<if test="summary!=null">a_summary=#{summary},</if>
|
<if test="summary!=null">a_summary=#{summary},</if>
|
||||||
<if test="type!=null">a_is_original=#{type},</if>
|
<if test="type!=null">a_is_original=#{type},</if>
|
||||||
<if test="url!=null">a_url=#{url},</if>
|
<if test="url!=null">a_url=#{url},</if>
|
||||||
<if test="updateDate!=null">a_update_date=#{updateDate},</if>
|
<if test="category!=null">a_category_id=#{category.id},</if>
|
||||||
<if test="categoryId!=null">a_category_id=#{categoryId},</if>
|
|
||||||
<if test="tagsId!=null">a_tags_id=#{tagsId},</if>
|
|
||||||
<if test="nextArticleId!=null">next_a_id=#{nextArticleId},</if>
|
|
||||||
<if test="preArticleId!=null">pre_a_id=#{preArticleId},</if>
|
|
||||||
<if test="open!=null">a_is_open=#{open}</if>
|
<if test="open!=null">a_is_open=#{open}</if>
|
||||||
where a_id = #{id}
|
where a_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateNextArticleId">
|
<update id="updateReadingNumber">
|
||||||
update article
|
update article
|
||||||
set next_a_id=#{nextArticleID}
|
set a_reading_number=a_reading_number + 1
|
||||||
where a_id = #{targetArticleID}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="updatePreArticleId">
|
|
||||||
update article
|
|
||||||
set pre_a_id=#{preArticleID}
|
|
||||||
where a_id = #{targetArticleID}
|
|
||||||
</update>
|
|
||||||
<update id="setReadingNumber">
|
|
||||||
update article
|
|
||||||
set a_reading_number=#{number}
|
|
||||||
where a_id = #{id}
|
where a_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<select id="getLastestArticleId" resultType="long">
|
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.blog.entity.Article">
|
||||||
select a_id
|
|
||||||
from article
|
|
||||||
order by a_id desc
|
|
||||||
limit 1
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="getLastestArticle" resultMap="articleResultMap" resultType="cn.celess.blog.entity.Article">
|
|
||||||
select *
|
select *
|
||||||
from article
|
from articleView
|
||||||
order by a_id desc
|
order by articleId desc
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="findArticleById" resultMap="articleResultMap">
|
<select id="findArticleById" resultMap="articleViewResultMap">
|
||||||
select *
|
select *
|
||||||
from article
|
from articleView
|
||||||
where a_id = #{id}
|
where articleId = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsByTitle" resultType="boolean">
|
<select id="existsByTitle" resultType="boolean">
|
||||||
SELECT EXISTS(SELECT * FROM article WHERE a_title = #{title})
|
SELECT EXISTS(SELECT * FROM article WHERE a_title = #{title})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsById" resultType="boolean">
|
<select id="isDeletedById" resultType="boolean">
|
||||||
SELECT EXISTS(SELECT * FROM article WHERE a_id = #{id})
|
select is_delete
|
||||||
|
from article
|
||||||
|
WHERE a_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAllByAuthorId" resultMap="articleResultMap">
|
<select id="findAllByAuthorId" resultMap="articleViewResultMap">
|
||||||
select *
|
select *
|
||||||
from article
|
from articleView
|
||||||
where a_author_id = #{authorID}
|
where authorId = #{authorId}
|
||||||
order by a_id desc
|
and isDelete = false
|
||||||
|
order by articleId desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAllByOpen" resultMap="articleResultMap">
|
<select id="findAllByOpen" resultMap="articleViewResultMap">
|
||||||
select *
|
select *
|
||||||
from article
|
from articleView
|
||||||
where a_is_open = #{isOpen}
|
where isOpen = #{isOpen}
|
||||||
order by a_id desc
|
and isDelete = false
|
||||||
|
order by articleId desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="getTitleById" resultType="string">
|
<select id="getTitleById" resultType="string">
|
||||||
SELECT a_title
|
SELECT title
|
||||||
from article
|
from articleView
|
||||||
where a_id = #{id}
|
where articleId = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAllByCategoryId" resultMap="articleResultMap">
|
<select id="findAllByCategoryId" resultMap="articleViewResultMap">
|
||||||
select a_id, a_title, a_summary
|
|
||||||
from article
|
|
||||||
where a_category_id = #{id}
|
|
||||||
order by a_id desc
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="findAll" resultMap="articleResultMap">
|
|
||||||
select *
|
select *
|
||||||
from article
|
from articleView
|
||||||
order by a_id desc
|
where categoryId = #{id}
|
||||||
|
and isDelete = false
|
||||||
|
order by articleId desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getSimpleInfo" resultMap="articleResultMap">
|
<select id="findAllByCategoryIdAndOpen" resultMap="articleViewResultMap">
|
||||||
select a_id, a_summary, a_title
|
select *
|
||||||
from article
|
from articleView
|
||||||
where a_id = #{id}
|
where categoryId = #{id}
|
||||||
|
and isDelete = false
|
||||||
|
and isOpen = true
|
||||||
|
order by articleId desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getSimpleInfoByCategory" resultMap="articleResultMap">
|
|
||||||
select a_id, a_summary, a_title
|
|
||||||
from article
|
|
||||||
where a_category_id = #{categoryId}
|
|
||||||
order by a_id desc
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="getSimpleInfoByTag" resultMap="articleResultMap">
|
<select id="findAll" resultMap="articleViewResultMap">
|
||||||
Select
|
select *
|
||||||
a_id, a_summary, a_title
|
from articleView
|
||||||
from article where a_id in
|
where isDelete = false
|
||||||
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
|
|
||||||
#{item}
|
|
||||||
</foreach>
|
|
||||||
order by a_id desc
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="count" resultType="long">
|
<select id="count" resultType="long">
|
||||||
select count(*)
|
select count(*)
|
||||||
from article;
|
from article
|
||||||
|
where is_delete = false;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getPreArticle" resultMap="articleViewResultMap">
|
||||||
|
select *
|
||||||
|
from articleView
|
||||||
|
where articleId = (select max(articleId)
|
||||||
|
from articleView
|
||||||
|
where articleId < #{id}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
<select id="getNextArticle" resultMap="articleViewResultMap">
|
||||||
|
select *
|
||||||
|
from articleView
|
||||||
|
where articleId = (select min(articleId)
|
||||||
|
from articleView
|
||||||
|
where articleId > #{id}
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -1,75 +1,66 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.celess.blog.mapper.TagMapper">
|
<mapper namespace="cn.celess.blog.mapper.TagMapper">
|
||||||
<resultMap id="tagResultMap" type="cn.celess.blog.entity.Tag">
|
|
||||||
<id column="tag_id" property="id"/>
|
<resultMap id="tagResultMap" type="cn.celess.blog.entity.Tag"
|
||||||
<result column="tag_name" property="name"/>
|
extends="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert">
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into tag (tag_name, articles)
|
insert into tag_category (t_name, is_category)
|
||||||
VALUES (#{name}, #{articles});
|
VALUES (#{name}, false);
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="update">
|
<update id="update">
|
||||||
update tag
|
update tag_category
|
||||||
set tag_name=#{name},
|
set t_name=#{name}
|
||||||
articles=#{articles}
|
where t_id = #{id}
|
||||||
where tag_id = #{id}
|
and is_category = false;
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update tag_category
|
||||||
from tag
|
set is_delete = true
|
||||||
where tag_id = #{id}
|
where t_id = #{id}
|
||||||
</delete>
|
and is_category = false;
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="findTagById" resultMap="tagResultMap">
|
<select id="findTagById" resultMap="tagResultMap">
|
||||||
select *
|
select *
|
||||||
from tag
|
from tag_category
|
||||||
where tag_id = #{id}
|
where t_id = #{id}
|
||||||
|
and is_category = false;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findTagByName" resultMap="tagResultMap">
|
<select id="findTagByName" resultMap="tagResultMap">
|
||||||
select *
|
select *
|
||||||
from tag
|
from tag_category
|
||||||
where tag_name = #{name}
|
where t_name = #{name}
|
||||||
|
and is_category = false;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="existsByName" resultType="boolean">
|
<select id="existsByName" resultType="boolean">
|
||||||
SELECT EXISTS(SELECT * FROM tag WHERE tag_name = #{name})
|
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = false)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getIDByName" resultType="long">
|
|
||||||
select tag_id
|
|
||||||
from tag
|
|
||||||
where tag_name = #{name}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="getNameById" resultType="string">
|
|
||||||
select tag_name
|
|
||||||
from tag
|
|
||||||
where tag_id = #{id}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
<select id="getLastestTag" resultMap="tagResultMap">
|
<select id="getLastestTag" resultMap="tagResultMap">
|
||||||
select *
|
select *
|
||||||
from tag
|
from tag_category
|
||||||
order by tag_id desc
|
where is_category = false
|
||||||
|
order by t_id desc
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAll" resultMap="tagResultMap">
|
<select id="findAll" resultMap="tagResultMap">
|
||||||
select *
|
select *
|
||||||
from tag
|
from tag_category
|
||||||
|
where is_category = false
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="count" resultType="long">
|
<select id="count" resultType="long">
|
||||||
select count(*)
|
select count(*)
|
||||||
from tag;
|
from tag_category
|
||||||
|
where is_category = false
|
||||||
|
and is_delete = false;
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -3,10 +3,11 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.Article;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
|
import cn.celess.blog.entity.Tag;
|
||||||
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.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -31,7 +32,8 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
articleReq.setTitle("test-" + UUID.randomUUID().toString());
|
articleReq.setTitle("test-" + UUID.randomUUID().toString());
|
||||||
articleReq.setMdContent("# test title");
|
articleReq.setMdContent("# test title");
|
||||||
articleReq.setCategory("随笔");
|
articleReq.setCategory("随笔");
|
||||||
articleReq.setTags("test,SpringMvc");
|
String[] tagList = {"tag", "category"};
|
||||||
|
articleReq.setTags(tagList);
|
||||||
articleReq.setOpen(true);
|
articleReq.setOpen(true);
|
||||||
articleReq.setType(true);
|
articleReq.setType(true);
|
||||||
articleReq.setUrl("http://xxxx.com");
|
articleReq.setUrl("http://xxxx.com");
|
||||||
@@ -80,13 +82,11 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertNotNull(articleModel.getCategory());
|
assertNotNull(articleModel.getCategory());
|
||||||
assertNotNull(articleModel.getPublishDateFormat());
|
assertNotNull(articleModel.getPublishDateFormat());
|
||||||
assertNotNull(articleModel.getMdContent());
|
assertNotNull(articleModel.getMdContent());
|
||||||
assertNotNull(articleModel.getNextArticleId());
|
assertNotNull(articleModel.getPreArticle());
|
||||||
assertNotNull(articleModel.getNextArticleTitle());
|
assertNull(articleModel.getNextArticle());
|
||||||
assertNotNull(articleModel.getPreArticleId());
|
|
||||||
assertNotNull(articleModel.getPreArticleTitle());
|
|
||||||
assertNotNull(articleModel.getOpen());
|
assertNotNull(articleModel.getOpen());
|
||||||
assertNotNull(articleModel.getReadingNumber());
|
assertNotNull(articleModel.getReadingNumber());
|
||||||
assertNotNull(articleModel.getAuthorName());
|
assertNotNull(articleModel.getAuthor());
|
||||||
assertNotNull(articleModel.getUrl());
|
assertNotNull(articleModel.getUrl());
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -96,11 +96,11 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete() {
|
public void delete() {
|
||||||
long articleId = articleMapper.getLastestArticleId();
|
Article article = articleMapper.getLastestArticle();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 未登录删除文章
|
// 未登录删除文章
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + articleId)
|
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
||||||
).andDo(result -> {
|
).andDo(result -> {
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
||||||
@@ -108,14 +108,14 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
});
|
});
|
||||||
// user 权限删除文章
|
// user 权限删除文章
|
||||||
String token = userLogin();
|
String token = userLogin();
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + articleId)
|
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
||||||
.header("Authorization", token))
|
.header("Authorization", token))
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(),
|
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(),
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
||||||
);
|
);
|
||||||
// admin 权限删除文章
|
// admin 权限删除文章
|
||||||
token = adminLogin();
|
token = adminLogin();
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + articleId)
|
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
||||||
.header("Authorization", token))
|
.header("Authorization", token))
|
||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
@@ -140,8 +140,8 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
articleReq.setOpen(!article.getOpen());
|
articleReq.setOpen(!article.getOpen());
|
||||||
String tag1 = randomStr(4);
|
String tag1 = randomStr(4);
|
||||||
String tag2 = randomStr(4);
|
String tag2 = randomStr(4);
|
||||||
String tag = "test," + tag1 + "," + tag2;
|
String[] tagList = {"test", tag1, tag2};
|
||||||
articleReq.setTags(tag);
|
articleReq.setTags(tagList);
|
||||||
articleReq.setTitle("test-" + article.getTitle());
|
articleReq.setTitle("test-" + article.getTitle());
|
||||||
try {
|
try {
|
||||||
// Admin 权限
|
// Admin 权限
|
||||||
@@ -160,15 +160,11 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertEquals(articleReq.getTitle(), a.getTitle());
|
assertEquals(articleReq.getTitle(), a.getTitle());
|
||||||
assertEquals(articleReq.getType(), a.getOriginal());
|
assertEquals(articleReq.getType(), a.getOriginal());
|
||||||
// Tag
|
// Tag
|
||||||
List<String> asList = Arrays.asList(a.getTags());
|
List<Tag> asList = a.getTags();
|
||||||
assertTrue(asList.contains("test"));
|
assertEquals(3, asList.size());
|
||||||
assertTrue(asList.contains(tag1));
|
|
||||||
assertTrue(asList.contains(tag2));
|
|
||||||
assertEquals(articleReq.getOpen(), a.getOpen());
|
assertEquals(articleReq.getOpen(), a.getOpen());
|
||||||
assertEquals(articleReq.getId(), a.getId());
|
assertEquals(articleReq.getId(), a.getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -207,17 +203,13 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertNotNull(a.getMdContent());
|
assertNotNull(a.getMdContent());
|
||||||
assertNotNull(a.getUrl());
|
assertNotNull(a.getUrl());
|
||||||
assertNotNull(a.getUpdateDateFormat());
|
assertNotNull(a.getUpdateDateFormat());
|
||||||
assertNotNull(a.getPreArticleId());
|
assertTrue(a.getPreArticle() != null || a.getNextArticle() != null);
|
||||||
assertNotNull(a.getPreArticleId());
|
|
||||||
assertNotNull(a.getNextArticleId());
|
|
||||||
assertNotNull(a.getNextArticleTitle());
|
|
||||||
assertNotNull(a.getReadingNumber());
|
assertNotNull(a.getReadingNumber());
|
||||||
// assertNotNull(a.getOpen());
|
|
||||||
assertNotNull(a.getOriginal());
|
assertNotNull(a.getOriginal());
|
||||||
assertNotNull(a.getPublishDateFormat());
|
assertNotNull(a.getPublishDateFormat());
|
||||||
assertNotNull(a.getCategory());
|
assertNotNull(a.getCategory());
|
||||||
assertNotNull(a.getTags());
|
assertNotNull(a.getTags());
|
||||||
assertNotNull(a.getAuthorName());
|
assertNotNull(a.getAuthor());
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -242,14 +234,12 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertNotNull(response.getResult());
|
assertNotNull(response.getResult());
|
||||||
// 判断pageInfo是否包装完全
|
// 判断pageInfo是否包装完全
|
||||||
JSONObject resultJson = JSONObject.fromObject(response.getResult());
|
JSONObject resultJson = JSONObject.fromObject(response.getResult());
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(resultJson, PageInfo.class);
|
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(resultJson, PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(5, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(5, pageInfo.getPageSize());
|
|
||||||
// 内容完整
|
// 内容完整
|
||||||
for (Object arc : pageInfo.getList()) {
|
for (Object arc : pageData.getList()) {
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(JSONObject.fromObject(arc), ArticleModel.class);
|
ArticleModel a = (ArticleModel) JSONObject.toBean(JSONObject.fromObject(arc), ArticleModel.class);
|
||||||
assertNotNull(a.getTitle());
|
assertNotNull(a.getTitle());
|
||||||
assertNotNull(a.getId());
|
assertNotNull(a.getId());
|
||||||
@@ -258,7 +248,9 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertNotNull(a.getPublishDateFormat());
|
assertNotNull(a.getPublishDateFormat());
|
||||||
assertNotNull(a.getCategory());
|
assertNotNull(a.getCategory());
|
||||||
assertNotNull(a.getTags());
|
assertNotNull(a.getTags());
|
||||||
assertNotNull(a.getAuthorName());
|
assertNotNull(a.getAuthor());
|
||||||
|
assertNull(a.getOpen());
|
||||||
|
assertNull(a.getMdContent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -299,14 +291,12 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertEquals(SUCCESS.getCode(), adminLogin.getInt(Code));
|
assertEquals(SUCCESS.getCode(), adminLogin.getInt(Code));
|
||||||
assertNotNull(adminLogin.getString(Result));
|
assertNotNull(adminLogin.getString(Result));
|
||||||
// 判断pageInfo是否包装完全
|
// 判断pageInfo是否包装完全
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(adminLogin.getJSONObject(Result), PageInfo.class);
|
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(adminLogin.getJSONObject(Result), PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
// 内容完整
|
// 内容完整
|
||||||
for (Object arc : pageInfo.getList()) {
|
for (Object arc : pageData.getList()) {
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(JSONObject.fromObject(arc), ArticleModel.class);
|
ArticleModel a = (ArticleModel) JSONObject.toBean(JSONObject.fromObject(arc), ArticleModel.class);
|
||||||
assertNotNull(a.getTitle());
|
assertNotNull(a.getTitle());
|
||||||
assertNotNull(a.getId());
|
assertNotNull(a.getId());
|
||||||
@@ -314,6 +304,9 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
assertNotNull(a.getPublishDateFormat());
|
assertNotNull(a.getPublishDateFormat());
|
||||||
assertNotNull(a.getOpen());
|
assertNotNull(a.getOpen());
|
||||||
assertNotNull(a.getReadingNumber());
|
assertNotNull(a.getReadingNumber());
|
||||||
|
assertNotNull(a.getLikeCount());
|
||||||
|
assertNotNull(a.getDislikeCount());
|
||||||
|
assertNull(a.getMdContent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -338,13 +331,11 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(jsonObject.getJSONObject(Result), PageInfo.class);
|
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(jsonObject.getJSONObject(Result), PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
for (Object arc : pageData.getList()) {
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
for (Object arc : pageInfo.getList()) {
|
|
||||||
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
||||||
assertNotEquals(0, jsonObject1.getInt("id"));
|
assertNotEquals(0, jsonObject1.getInt("id"));
|
||||||
assertNotNull(jsonObject1.getString("title"));
|
assertNotNull(jsonObject1.getString("title"));
|
||||||
@@ -373,14 +364,12 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(jsonObject.getJSONObject(Result), PageInfo.class);
|
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(jsonObject.getJSONObject(Result), PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
|
|
||||||
for (Object arc : pageInfo.getList()) {
|
for (Object arc : pageData.getList()) {
|
||||||
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
||||||
assertNotEquals(0, jsonObject1.getInt("id"));
|
assertNotEquals(0, jsonObject1.getInt("id"));
|
||||||
assertNotNull(jsonObject1.getString("title"));
|
assertNotNull(jsonObject1.getString("title"));
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class CategoryControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
String categoryName = UUID.randomUUID().toString().substring(0, 4);
|
String categoryName = randomStr(4);
|
||||||
System.out.println("categoryName: ==> " + categoryName);
|
System.out.println("categoryName: ==> " + categoryName);
|
||||||
// 未登录
|
// 未登录
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)).andExpect(status().isOk())
|
mockMvc.perform(post("/admin/category/create?name=" + categoryName)).andExpect(status().isOk())
|
||||||
@@ -84,7 +84,7 @@ public class CategoryControllerTest extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateOne() throws Exception {
|
public void updateOne() throws Exception {
|
||||||
Category category = categoryMapper.getLastestCategory();
|
Category category = categoryMapper.getLastestCategory();
|
||||||
String name = UUID.randomUUID().toString().substring(0, 4);
|
String name = randomStr(4);
|
||||||
// 未登录
|
// 未登录
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)).andExpect(status().isOk())
|
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)).andExpect(status().isOk())
|
||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
@@ -119,7 +119,7 @@ public class CategoryControllerTest extends BaseTest {
|
|||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
JSONArray jsonArray = object.getJSONObject(Result).getJSONArray("list");
|
||||||
assertNotNull(jsonArray);
|
assertNotNull(jsonArray);
|
||||||
jsonArray.forEach(o -> {
|
jsonArray.forEach(o -> {
|
||||||
CategoryModel c = (CategoryModel) JSONObject.toBean(JSONObject.fromObject(o), CategoryModel.class);
|
CategoryModel c = (CategoryModel) JSONObject.toBean(JSONObject.fromObject(o), CategoryModel.class);
|
||||||
|
|||||||
@@ -3,23 +3,18 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.Article;
|
||||||
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.request.CommentReq;
|
import cn.celess.blog.entity.request.CommentReq;
|
||||||
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.mapper.UserMapper;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
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.test.web.servlet.result.MockMvcResultHandlers;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
@@ -29,19 +24,19 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
CommentMapper commentMapper;
|
CommentMapper commentMapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
|
Article article = articleMapper.getLastestArticle();
|
||||||
CommentReq commentReq = new CommentReq();
|
CommentReq commentReq = new CommentReq();
|
||||||
// 测试留言
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setArticleID(null);
|
|
||||||
commentReq.setComment(false);
|
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(UUID.randomUUID().toString());
|
||||||
commentReq.setPid(-1L);
|
commentReq.setPid(-1L);
|
||||||
commentReq.setResponseId(null);
|
commentReq.setToUserId(-1L);
|
||||||
String token = userLogin();
|
String token = userLogin();
|
||||||
CommentModel PC = null;
|
|
||||||
mockMvc.perform(post("/user/comment/create")
|
mockMvc.perform(post("/user/comment/create")
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
.content(JSONObject.fromObject(commentReq).toString())
|
||||||
@@ -51,22 +46,19 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertEquals(commentReq.getPid().longValue(), model.getPid());
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
assertEquals(-1, model.getPid());
|
assertEquals(-1, model.getPid().longValue());
|
||||||
assertEquals(commentReq.getComment(), model.isComment());
|
|
||||||
assertEquals(commentReq.getContent(), model.getContent());
|
assertEquals(commentReq.getContent(), model.getContent());
|
||||||
assertNotNull(model.getDate());
|
assertNotNull(model.getDate());
|
||||||
assertNotNull(model.getAuthorName());
|
assertNotNull(model.getFromUser());
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
assertNull(model.getToUser());
|
||||||
});
|
});
|
||||||
|
|
||||||
Article article = articleMapper.getLastestArticle();
|
|
||||||
// 测试评论
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setArticleID(article.getId());
|
|
||||||
commentReq.setComment(true);
|
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(UUID.randomUUID().toString());
|
||||||
commentReq.setPid(-1L);
|
commentReq.setPid(-1L);
|
||||||
commentReq.setResponseId(null);
|
commentReq.setToUserId(2);
|
||||||
mockMvc.perform(post("/user/comment/create")
|
mockMvc.perform(post("/user/comment/create")
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
.content(JSONObject.fromObject(commentReq).toString())
|
||||||
@@ -77,58 +69,50 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
||||||
// 响应数据的完整性
|
// 响应数据的完整性
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertEquals(commentReq.getPid().longValue(), model.getPid());
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
assertEquals(-1, model.getPid());
|
assertEquals(-1, model.getPid().longValue());
|
||||||
assertEquals(commentReq.getComment(), model.isComment());
|
|
||||||
assertEquals(commentReq.getContent(), model.getContent());
|
assertEquals(commentReq.getContent(), model.getContent());
|
||||||
assertEquals(commentReq.getArticleID().longValue(), model.getArticleID());
|
assertEquals(commentReq.getPagePath(), "/article/" + article.getId());
|
||||||
assertNotNull(model.getDate());
|
assertNotNull(model.getDate());
|
||||||
assertNotNull(model.getAuthorName());
|
assertNotNull(model.getFromUser());
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
assertNotNull(model.getToUser());
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试二级回复
|
// 测试二级回复
|
||||||
Comment lastestComment = commentMapper.getLastestComment();
|
Comment lastestComment = commentMapper.getLastestComment();
|
||||||
commentReq.setArticleID(lastestComment.getArticleID());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setComment(lastestComment.getType());
|
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(UUID.randomUUID().toString());
|
||||||
commentReq.setPid(lastestComment.getId());
|
commentReq.setPid(lastestComment.getId());
|
||||||
commentReq.setResponseId(null);
|
|
||||||
mockMvc.perform(post("/user/comment/create")
|
mockMvc.perform(post("/user/comment/create")
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
.content(JSONObject.fromObject(commentReq).toString())
|
||||||
.header("Authorization", token)
|
.header("Authorization", token)
|
||||||
).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
||||||
// 重新获取父评论信息
|
// 重新获取父评论信息
|
||||||
Comment pCommon = commentMapper.findCommentById(lastestComment.getId());
|
Comment pCommon = commentMapper.findCommentById(lastestComment.getId());
|
||||||
assertEquals(pCommon.getId().longValue(), model.getPid());
|
assertEquals(pCommon.getId(), model.getPid());
|
||||||
// 判断父评论中是否有写入当前新增的评论的id
|
|
||||||
String[] ids = pCommon.getResponseId().split(",");
|
|
||||||
boolean contain = false;
|
|
||||||
for (String id : ids) {
|
|
||||||
if (!id.isEmpty() && Long.parseLong(id) == model.getId()) {
|
|
||||||
contain = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertTrue(contain);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteTest() throws Exception {
|
public void deleteTest() throws Exception {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
Comment c = new Comment();
|
User from = userMapper.findByEmail("zh56462271@qq.com");
|
||||||
c.setArticleID(-1L);
|
assertNotNull(from);
|
||||||
c.setType(true);
|
User to = userMapper.findByEmail("a@celess.cn");
|
||||||
c.setAuthorID(2L);
|
assertNotNull(to);
|
||||||
c.setDate(new Date());
|
|
||||||
c.setPid(-1L);
|
Comment comment = new Comment();
|
||||||
commentMapper.insert(c);
|
comment.setContent(randomStr(8));
|
||||||
Comment comment = commentMapper.getLastestComment();
|
comment.setFromUser(from);
|
||||||
|
comment.setToUser(to);
|
||||||
|
comment.setPagePath("/tags");
|
||||||
|
comment.setPid(-1L);
|
||||||
|
commentMapper.insert(comment);
|
||||||
|
comment = commentMapper.findCommentById(comment.getId());
|
||||||
// 接口测试
|
// 接口测试
|
||||||
long id = comment.getId();
|
long id = comment.getId();
|
||||||
assertNotEquals(0, id);
|
assertNotEquals(0, id);
|
||||||
@@ -140,7 +124,7 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
});
|
});
|
||||||
mockMvc.perform(delete("/user/comment/del?id=" + id).header("Authorization", token)).andDo(result -> {
|
mockMvc.perform(delete("/user/comment/del?id=" + id).header("Authorization", token)).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(COMMENT_NOT_EXIST.getCode(), object.getInt(Code));
|
assertEquals(DATA_IS_DELETED.getCode(), object.getInt(Code));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,12 +133,8 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
Comment comment = commentMapper.getLastestComment();
|
Comment comment = commentMapper.getLastestComment();
|
||||||
CommentReq commentReq = new CommentReq();
|
CommentReq commentReq = new CommentReq();
|
||||||
commentReq.setId(comment.getId());
|
commentReq.setId(comment.getId());
|
||||||
commentReq.setPid(comment.getPid());
|
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(UUID.randomUUID().toString());
|
||||||
commentReq.setArticleID(comment.getArticleID());
|
|
||||||
// 不合法数据 setResponseId
|
// 不合法数据 setResponseId
|
||||||
commentReq.setResponseId("xxxx");
|
|
||||||
commentReq.setComment(comment.getType());
|
|
||||||
mockMvc.perform(put("/user/comment/update")
|
mockMvc.perform(put("/user/comment/update")
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
.content(JSONObject.fromObject(commentReq).toString())
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||||
@@ -164,166 +144,7 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
CommentModel c = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
CommentModel c = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
||||||
assertEquals(commentReq.getContent(), c.getContent());
|
assertEquals(commentReq.getContent(), c.getContent());
|
||||||
assertEquals(commentReq.getResponseId(), c.getResponseId());
|
|
||||||
assertNotNull(c.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(c.getAuthorName());
|
|
||||||
assertNotNull(c.getDate());
|
|
||||||
assertNotEquals(0, c.getPid());
|
|
||||||
assertNotEquals(0, c.getArticleID());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void commentsOfArticle() throws Exception {
|
|
||||||
mockMvc.perform(get("/comments?articleId=3&page=1&count=10")).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertEquals(3, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getArticleTitle());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void retrievePage() throws Exception {
|
|
||||||
long pid = 17;
|
|
||||||
mockMvc.perform(get("/comment/pid/" + pid + "?articleId=3&page=1&count=10")).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertEquals(3, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getArticleTitle());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void retrievePageOfLeaveMsg() throws Exception {
|
|
||||||
mockMvc.perform(get("/leaveMsg?page=1&count=10")).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertEquals(-1, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
assertFalse(model.isComment());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void retrievePageAdmin() throws Exception {
|
|
||||||
mockMvc.perform(get("/admin/comment/type/1?page=1&count=10").header("Authorization", adminLogin())).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertNotEquals(-1, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
assertTrue(model.isComment());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
mockMvc.perform(get("/admin/comment/type/0?page=1&count=10").header("Authorization", adminLogin())).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertEquals(-1, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
assertFalse(model.isComment());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void retrievePageByAuthor() throws Exception {
|
|
||||||
mockMvc.perform(get("/user/comment/type/1?page=1&count=10").header("Authorization", userLogin())).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertNotEquals(-1, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
assertTrue(model.isComment());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
mockMvc.perform(get("/user/comment/type/0?page=1&count=10").header("Authorization", userLogin())).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(JSONObject.fromObject(o), CommentModel.class);
|
|
||||||
assertEquals(-1, model.getArticleID());
|
|
||||||
assertNotNull(model.getDate());
|
|
||||||
assertNotNull(model.getAuthorName());
|
|
||||||
assertNotNull(model.getAuthorAvatarImgUrl());
|
|
||||||
assertNotNull(model.getContent());
|
|
||||||
assertNotNull(model.getResponseId());
|
|
||||||
assertFalse(model.isComment());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
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.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.mapper.PartnerMapper;
|
import cn.celess.blog.mapper.PartnerMapper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
@@ -73,6 +74,8 @@ public class LinksControllerTest extends BaseTest {
|
|||||||
PartnerSite partnerSite = new PartnerSite();
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
||||||
partnerSite.setOpen(true);
|
partnerSite.setOpen(true);
|
||||||
|
partnerSite.setDesc("");
|
||||||
|
partnerSite.setIconPath("");
|
||||||
partnerSite.setUrl("https://www.celess.cn");
|
partnerSite.setUrl("https://www.celess.cn");
|
||||||
mapper.insert(partnerSite);
|
mapper.insert(partnerSite);
|
||||||
PartnerSite lastest = mapper.getLastest();
|
PartnerSite lastest = mapper.getLastest();
|
||||||
@@ -99,6 +102,9 @@ public class LinksControllerTest extends BaseTest {
|
|||||||
PartnerSite partnerSite = new PartnerSite();
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
||||||
partnerSite.setOpen(true);
|
partnerSite.setOpen(true);
|
||||||
|
partnerSite.setDesc("");
|
||||||
|
partnerSite.setIconPath("");
|
||||||
|
partnerSite.setDelete(false);
|
||||||
partnerSite.setUrl("https://www.celess.cn");
|
partnerSite.setUrl("https://www.celess.cn");
|
||||||
mapper.insert(partnerSite);
|
mapper.insert(partnerSite);
|
||||||
// 查数据
|
// 查数据
|
||||||
@@ -147,17 +153,15 @@ public class LinksControllerTest extends BaseTest {
|
|||||||
mockMvc.perform(get("/admin/links?page=1&count=10").header("Authorization", adminLogin())).andDo(result -> {
|
mockMvc.perform(get("/admin/links?page=1&count=10").header("Authorization", adminLogin())).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
PageData<PartnerSite> pageData = (PageData<PartnerSite>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
for (Object o : pageData.getList()) {
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(JSONObject.fromObject(o), PartnerSite.class);
|
PartnerSite site = (PartnerSite) JSONObject.toBean(JSONObject.fromObject(o), PartnerSite.class);
|
||||||
assertNotNull(site.getUrl());
|
assertNotNull(site.getUrl());
|
||||||
assertNotNull(site.getName());
|
assertNotNull(site.getName());
|
||||||
assertNotNull(site.getOpen());
|
assertNotNull(site.getOpen());
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Tag;
|
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 cn.celess.blog.mapper.TagMapper;
|
import cn.celess.blog.mapper.TagMapper;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONArray;
|
import net.sf.json.JSONArray;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -23,7 +23,7 @@ public class TagControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
String name = UUID.randomUUID().toString().substring(0, 4);
|
String name = randomStr(4);
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
mockMvc.perform(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", userLogin())).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", userLogin())).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", adminLogin())).andDo(result -> {
|
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", adminLogin())).andDo(result -> {
|
||||||
@@ -66,42 +66,11 @@ public class TagControllerTest extends BaseTest {
|
|||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(object.getJSONObject(Result));
|
||||||
TagModel t = (TagModel) JSONObject.toBean(object.getJSONObject(Result), TagModel.class);
|
TagModel t = (TagModel) JSONObject.toBean(object.getJSONObject(Result), TagModel.class);
|
||||||
assertEquals(name, t.getName());
|
assertEquals(name, t.getName());
|
||||||
StringBuilder s = new StringBuilder();
|
|
||||||
t.getArticles().forEach(e -> s.append(e).append(","));
|
|
||||||
assertEquals(tag.getArticles(), s.toString());
|
|
||||||
assertEquals(tag.getId(), t.getId());
|
assertEquals(tag.getId(), t.getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void retrieveOneById() throws Exception {
|
|
||||||
Tag tag = tagMapper.getLastestTag();
|
|
||||||
assertNotNull(tag.getId());
|
|
||||||
mockMvc.perform(get("/tag/id/" + tag.getId())).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
assertNotNull(object.getJSONObject(Result));
|
|
||||||
TagModel t = (TagModel) JSONObject.toBean(object.getJSONObject(Result), TagModel.class);
|
|
||||||
assertEquals(tag.getId(), t.getId());
|
|
||||||
assertNotNull(t.getName());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void retrieveOneByName() throws Exception {
|
|
||||||
Tag tag = tagMapper.getLastestTag();
|
|
||||||
assertNotNull(tag.getName());
|
|
||||||
mockMvc.perform(get("/tag/name/" + tag.getName())).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
assertNotNull(object.getJSONObject(Result));
|
|
||||||
TagModel t = (TagModel) JSONObject.toBean(object.getJSONObject(Result), TagModel.class);
|
|
||||||
assertEquals(tag.getName(), t.getName());
|
|
||||||
assertNotNull(t.getId());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPage() throws Exception {
|
public void getPage() throws Exception {
|
||||||
mockMvc.perform(get("/tags?page=1&count=5"))
|
mockMvc.perform(get("/tags?page=1&count=5"))
|
||||||
@@ -114,14 +83,12 @@ public class TagControllerTest extends BaseTest {
|
|||||||
assertNotNull(articlesJSON.getJSONObject(Result));
|
assertNotNull(articlesJSON.getJSONObject(Result));
|
||||||
// 判断pageInfo是否包装完全
|
// 判断pageInfo是否包装完全
|
||||||
JSONObject resultJson = JSONObject.fromObject(articlesJSON.getJSONObject(Result));
|
JSONObject resultJson = JSONObject.fromObject(articlesJSON.getJSONObject(Result));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(resultJson, PageInfo.class);
|
PageData<TagModel> pageData = (PageData<TagModel>) JSONObject.toBean(resultJson, PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(5, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(5, pageInfo.getPageSize());
|
|
||||||
// 内容完整
|
// 内容完整
|
||||||
for (Object tag : pageInfo.getList()) {
|
for (Object tag : pageData.getList()) {
|
||||||
TagModel t = (TagModel) JSONObject.toBean(JSONObject.fromObject(tag), TagModel.class);
|
TagModel t = (TagModel) JSONObject.toBean(JSONObject.fromObject(tag), TagModel.class);
|
||||||
assertNotNull(t.getId());
|
assertNotNull(t.getId());
|
||||||
assertNotNull(t.getName());
|
assertNotNull(t.getName());
|
||||||
|
|||||||
@@ -2,18 +2,21 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
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.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 cn.celess.blog.mapper.UserMapper;
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
import cn.celess.blog.util.MD5Util;
|
import cn.celess.blog.util.MD5Util;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONArray;
|
import net.sf.json.JSONArray;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
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.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -47,8 +50,7 @@ public class UserControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registration() {
|
public void registration() {
|
||||||
// 自行手动测试!
|
// ignore
|
||||||
// TODO :
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,7 +135,8 @@ public class UserControllerTest extends BaseTest {
|
|||||||
String s = UUID.randomUUID().toString();
|
String s = UUID.randomUUID().toString();
|
||||||
String email = s.substring(s.length() - 4) + "@celess.cn";
|
String email = s.substring(s.length() - 4) + "@celess.cn";
|
||||||
String pwd = MD5Util.getMD5("123456789");
|
String pwd = MD5Util.getMD5("123456789");
|
||||||
int i1 = userMapper.addUser(email, pwd);
|
User user = new User(email, pwd);
|
||||||
|
int i1 = userMapper.addUser(user);
|
||||||
if (i1 == 0) {
|
if (i1 == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -174,7 +177,8 @@ public class UserControllerTest extends BaseTest {
|
|||||||
public void updateInfoByAdmin() throws Exception {
|
public void updateInfoByAdmin() throws Exception {
|
||||||
UserReq userReq = new UserReq();
|
UserReq userReq = new UserReq();
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
||||||
userMapper.addUser(email, MD5Util.getMD5("123456789"));
|
User user = new User(email, MD5Util.getMD5("123456789"));
|
||||||
|
userMapper.addUser(user);
|
||||||
User userByDb = userMapper.findByEmail(email);
|
User userByDb = userMapper.findByEmail(email);
|
||||||
userReq.setId(userByDb.getId());
|
userReq.setId(userByDb.getId());
|
||||||
userReq.setPwd(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 10));
|
userReq.setPwd(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 10));
|
||||||
@@ -191,12 +195,12 @@ public class UserControllerTest extends BaseTest {
|
|||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
UserModel user = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
UserModel userModel = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
||||||
assertEquals(userReq.getId(), user.getId());
|
assertEquals(userReq.getId(), userModel.getId());
|
||||||
assertEquals(userReq.getRole(), user.getRole());
|
assertEquals(userReq.getRole(), userModel.getRole());
|
||||||
assertEquals(userReq.getEmail(), user.getEmail());
|
assertEquals(userReq.getEmail(), userModel.getEmail());
|
||||||
assertEquals(userReq.getDesc(), user.getDesc());
|
assertEquals(userReq.getDesc(), userModel.getDesc());
|
||||||
assertEquals(userReq.getDisplayName(), user.getDisplayName());
|
assertEquals(userReq.getDisplayName(), userModel.getDisplayName());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,14 +218,12 @@ public class UserControllerTest extends BaseTest {
|
|||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(object.getJSONObject(Result));
|
||||||
// 判断pageInfo是否包装完全
|
// 判断pageInfo是否包装完全
|
||||||
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(resultJson, PageInfo.class);
|
PageData<UserModel> pageData = (PageData<UserModel>) JSONObject.toBean(resultJson, PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
// 内容完整
|
// 内容完整
|
||||||
for (Object user : pageInfo.getList()) {
|
for (Object user : pageData.getList()) {
|
||||||
UserModel u = (UserModel) JSONObject.toBean(JSONObject.fromObject(user), UserModel.class);
|
UserModel u = (UserModel) JSONObject.toBean(JSONObject.fromObject(user), UserModel.class);
|
||||||
assertNotNull(u.getId());
|
assertNotNull(u.getId());
|
||||||
assertNotNull(u.getEmail());
|
assertNotNull(u.getEmail());
|
||||||
@@ -247,4 +249,28 @@ public class UserControllerTest extends BaseTest {
|
|||||||
assertTrue(JSONObject.fromObject(content).getBoolean(Result));
|
assertTrue(JSONObject.fromObject(content).getBoolean(Result));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setPwd() throws Exception {
|
||||||
|
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
||||||
|
assertEquals(1, userMapper.addUser(new User(email, MD5Util.getMD5("1234567890"))));
|
||||||
|
LoginReq req = new LoginReq();
|
||||||
|
req.setEmail(email);
|
||||||
|
req.setPassword("1234567890");
|
||||||
|
req.setIsRememberMe(false);
|
||||||
|
JSONObject loginReq = JSONObject.fromObject(req);
|
||||||
|
String contentAsString = mockMvc.perform(post("/login").content(loginReq.toString()).contentType("application/json")).andReturn().getResponse().getContentAsString();
|
||||||
|
assertNotNull(contentAsString);
|
||||||
|
String token = JSONObject.fromObject(contentAsString).getJSONObject(Result).getString("token");
|
||||||
|
assertNotNull(token);
|
||||||
|
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
||||||
|
param.add("pwd", "1234567890");
|
||||||
|
param.add("newPwd", "aaabbbccc");
|
||||||
|
param.add("confirmPwd", "aaabbbccc");
|
||||||
|
mockMvc.perform(post("/user/setPwd").header("Authorization", token).params(param)).andDo(result -> {
|
||||||
|
String content = result.getResponse().getContentAsString();
|
||||||
|
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
||||||
|
assertEquals(MD5Util.getMD5("aaabbbccc"), userMapper.getPwd(email));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
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 com.github.pagehelper.PageInfo;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
@@ -31,13 +32,11 @@ public class VisitorControllerTest extends BaseTest {
|
|||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(resultJson, PageInfo.class);
|
PageData<VisitorModel> pageData = (PageData<VisitorModel>) JSONObject.toBean(resultJson, PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
for (Object ver : pageData.getList()) {
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
for (Object ver : pageInfo.getList()) {
|
|
||||||
VisitorModel v = (VisitorModel) JSONObject.toBean(JSONObject.fromObject(ver), VisitorModel.class);
|
VisitorModel v = (VisitorModel) JSONObject.toBean(JSONObject.fromObject(ver), VisitorModel.class);
|
||||||
assertNotEquals(0, v.getId());
|
assertNotEquals(0, v.getId());
|
||||||
assertNotNull(v.getDate());
|
assertNotNull(v.getDate());
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
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.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONArray;
|
import net.sf.json.JSONArray;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -104,22 +104,21 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(object.getJSONObject(Result));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
PageData<WebUpdateModel> pageData = (PageData<WebUpdateModel>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
for (Object o : pageData.getList()) {
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
WebUpdateModel model = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
WebUpdateModel model = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertNotNull(model.getTime());
|
assertNotNull(model.getTime());
|
||||||
assertNotNull(model.getInfo());
|
assertNotNull(model.getInfo());
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lastestUpdateTime() throws Exception {
|
public void lastestUpdateTime() throws Exception {
|
||||||
mockMvc.perform(get("/lastestUpdateTime")).andDo(result -> assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
mockMvc.perform(get("/lastestUpdate")).andDo(result ->
|
||||||
|
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,16 @@ public class AuthorizationFilter extends BaseTest {
|
|||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void authorizationTest() throws Exception {
|
||||||
|
// 测试response中有无Authorization字段
|
||||||
|
String s = userLogin();
|
||||||
|
mockMvc.perform(get("/user/userInfo").header("Authorization", s)).andDo(result -> {
|
||||||
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
|
assertNotNull(result.getResponse().getHeader("Authorization"));
|
||||||
|
assertNotEquals(s, result.getResponse().getHeader("Authorization"));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
224
src/test/java/cn/celess/blog/mapper/ArticleMapperTest.java
Normal file
224
src/test/java/cn/celess/blog/mapper/ArticleMapperTest.java
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.*;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class ArticleMapperTest extends BaseTest {
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
@Autowired
|
||||||
|
TagMapper tagMapper;
|
||||||
|
@Autowired
|
||||||
|
ArticleTagMapper articleTagMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insert() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
assertNotNull(article.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
|
||||||
|
assertFalse(articleMapper.isDeletedById(article.getId()));
|
||||||
|
assertEquals(1, articleMapper.delete(article.getId()));
|
||||||
|
assertTrue(articleMapper.isDeletedById(article.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
String randomText = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
// 此字段不会通过insert被写入数据库而是使用插入数据的默认值 数据库中该字段默认为true
|
||||||
|
article.setOpen(true);
|
||||||
|
|
||||||
|
article.setTitle("test update " + randomText);
|
||||||
|
article.setMdContent("test update ");
|
||||||
|
article.setSummary("test update ");
|
||||||
|
article.setType(false);
|
||||||
|
article.setUrl("https://www.celess.cn");
|
||||||
|
article.getCategory().setId(2L);
|
||||||
|
article.setOpen(!article.getOpen());
|
||||||
|
articleMapper.update(article);
|
||||||
|
|
||||||
|
Article articleById = articleMapper.findArticleById(article.getId());
|
||||||
|
assertEquals(article.getTitle(), articleById.getTitle());
|
||||||
|
assertEquals(article.getMdContent(), articleById.getMdContent());
|
||||||
|
assertEquals(article.getSummary(), articleById.getSummary());
|
||||||
|
assertEquals(article.getType(), articleById.getType());
|
||||||
|
assertEquals(article.getCategory().getId(), articleById.getCategory().getId());
|
||||||
|
assertEquals(article.getOpen(), articleById.getOpen());
|
||||||
|
assertNotNull(articleById.getUpdateDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectAll() {
|
||||||
|
List<Article> list = articleMapper.findAll();
|
||||||
|
assertNotEquals(0, list.size());
|
||||||
|
list.forEach(article -> {
|
||||||
|
assertNotEquals(0, article.getTags().size());
|
||||||
|
assertNotNull(article.getId());
|
||||||
|
assertNotNull(article.getTitle());
|
||||||
|
assertNotNull(article.getSummary());
|
||||||
|
assertNotNull(article.getMdContent());
|
||||||
|
assertNotNull(article.getType());
|
||||||
|
if (!article.getType()) {
|
||||||
|
assertNotNull(article.getUrl());
|
||||||
|
}
|
||||||
|
assertNotNull(article.getReadingNumber());
|
||||||
|
assertNotNull(article.getLikeCount());
|
||||||
|
assertNotNull(article.getDislikeCount());
|
||||||
|
assertNotNull(article.getPublishDate());
|
||||||
|
assertNotNull(article.getOpen());
|
||||||
|
assertNotNull(article.getCategory());
|
||||||
|
assertNotNull(article.getUser());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateReadCount() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
Article articleById = articleMapper.findArticleById(article.getId());
|
||||||
|
assertEquals(Long.valueOf(0), articleById.getReadingNumber());
|
||||||
|
articleMapper.updateReadingNumber(articleById.getId());
|
||||||
|
articleById = articleMapper.findArticleById(article.getId());
|
||||||
|
assertEquals(Long.valueOf(1), articleById.getReadingNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLastestArticle() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
Article lastestArticle = articleMapper.getLastestArticle();
|
||||||
|
assertNotNull(lastestArticle);
|
||||||
|
assertEquals(article.getId(), lastestArticle.getId());
|
||||||
|
assertNotNull(lastestArticle.getCategory());
|
||||||
|
assertNotEquals(0, lastestArticle.getTags().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findArticleById() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
Article articleById = articleMapper.findArticleById(article.getId());
|
||||||
|
assertNotNull(articleById);
|
||||||
|
assertEquals(article.getId(), articleById.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void existsByTitle() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
assertTrue(articleMapper.existsByTitle(article.getTitle()));
|
||||||
|
assertFalse(articleMapper.existsByTitle(UUID.randomUUID().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isDeletedById() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
assertFalse(articleMapper.isDeletedById(article.getId()));
|
||||||
|
articleMapper.delete(article.getId());
|
||||||
|
assertTrue(articleMapper.isDeletedById(article.getId()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllByAuthorId() {
|
||||||
|
List<Article> allByAuthorId = articleMapper.findAllByAuthorId(1);
|
||||||
|
assertNotEquals(0, allByAuthorId.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllByOpen() {
|
||||||
|
List<Article> allByOpen = articleMapper.findAllByOpen(true);
|
||||||
|
assertNotEquals(0, allByOpen);
|
||||||
|
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
article.setOpen(false);
|
||||||
|
|
||||||
|
articleMapper.update(article);
|
||||||
|
|
||||||
|
List<Article> privateArticles = articleMapper.findAllByOpen(false);
|
||||||
|
assertTrue(privateArticles.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getTitleById() {
|
||||||
|
Article article = generateArticle().getArticle();
|
||||||
|
|
||||||
|
assertEquals(article.getTitle(), articleMapper.getTitleById(article.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllByCategoryId() {
|
||||||
|
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(1);
|
||||||
|
assertNotEquals(0, allByCategoryId.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllByCategoryIdAndOpen() {
|
||||||
|
List<Article> allByCategoryId = articleMapper.findAllByCategoryIdAndOpen(1);
|
||||||
|
assertNotEquals(0, allByCategoryId.size());
|
||||||
|
allByCategoryId.forEach(article -> assertTrue(article.getOpen()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
|
List<Article> allByCategoryId = articleMapper.findAll();
|
||||||
|
assertNotEquals(0, allByCategoryId.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void count() {
|
||||||
|
assertNotEquals(0, articleMapper.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPreArticle() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
Article preArticle = articleMapper.getPreArticle(articleTag.getArticle().getId());
|
||||||
|
assertNotNull(preArticle);
|
||||||
|
assertTrue(preArticle.getId() < articleTag.getArticle().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNextArticle() {
|
||||||
|
Article getNextArticle = articleMapper.getNextArticle(3L);
|
||||||
|
assertNotNull(getNextArticle);
|
||||||
|
assertTrue(getNextArticle.getId() > 3L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArticleTag generateArticle() {
|
||||||
|
String randomText = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
Article article = new Article();
|
||||||
|
Category category = new Category();
|
||||||
|
category.setId(1L);
|
||||||
|
article.setCategory(category);
|
||||||
|
article.setTitle(" unity test for article " + randomText);
|
||||||
|
article.setMdContent("# unity test for article");
|
||||||
|
article.setSummary("unity test for article");
|
||||||
|
|
||||||
|
Tag tag = tagMapper.findTagByName("随笔");
|
||||||
|
User user = new User();
|
||||||
|
user.setId(1L);
|
||||||
|
article.setUser(user);
|
||||||
|
article.setType(true);
|
||||||
|
|
||||||
|
articleMapper.insert(article);
|
||||||
|
|
||||||
|
ArticleTag articleTag = new ArticleTag();
|
||||||
|
articleTag.setArticle(article);
|
||||||
|
articleTag.setTag(tag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
|
||||||
|
return articleTag;
|
||||||
|
}
|
||||||
|
}
|
||||||
141
src/test/java/cn/celess/blog/mapper/ArticleTagMapperTest.java
Normal file
141
src/test/java/cn/celess/blog/mapper/ArticleTagMapperTest.java
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.*;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class ArticleTagMapperTest extends BaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ArticleMapper articleMapper;
|
||||||
|
@Autowired
|
||||||
|
ArticleTagMapper articleTagMapper;
|
||||||
|
@Autowired
|
||||||
|
TagMapper tagMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insert() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
assertNotNull(articleTag);
|
||||||
|
assertNotNull(articleTag.getArticle());
|
||||||
|
assertNotNull(articleTag.getTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() {
|
||||||
|
Tag tag = tagMapper.findTagByName("电影");
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
articleTag.setTag(tag);
|
||||||
|
|
||||||
|
articleTagMapper.update(articleTag);
|
||||||
|
|
||||||
|
ArticleTag oneById = articleTagMapper.findOneById(articleTag.getId());
|
||||||
|
assertEquals(articleTag.getArticle().getId(), oneById.getArticle().getId());
|
||||||
|
assertEquals(articleTag.getArticle().getTitle(), oneById.getArticle().getTitle());
|
||||||
|
assertEquals(articleTag.getTag().getName(), oneById.getTag().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteById() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
|
||||||
|
articleTagMapper.deleteById(articleTag.getId());
|
||||||
|
|
||||||
|
ArticleTag oneById = articleTagMapper.findOneById(articleTag.getId());
|
||||||
|
assertNull(oneById);
|
||||||
|
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteByArticleId() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
int i = articleTagMapper.deleteByArticleId(articleTag.getArticle().getId());
|
||||||
|
assertNotEquals(0, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllByArticleId() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
List<ArticleTag> allByArticleId = articleTagMapper.findAllByArticleId(articleTag.getArticle().getId());
|
||||||
|
assertEquals(1, allByArticleId.size());
|
||||||
|
|
||||||
|
List<ArticleTag> list = articleTagMapper.findAllByArticleId(5L);
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteMultiById() {
|
||||||
|
ArticleTag articleTag = new ArticleTag();
|
||||||
|
Article article = new Article();
|
||||||
|
article.setId(-1L);
|
||||||
|
Tag tag = new Tag();
|
||||||
|
tag.setId(1L);
|
||||||
|
articleTag.setArticle(article);
|
||||||
|
articleTag.setTag(tag);
|
||||||
|
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
|
||||||
|
List<ArticleTag> allByArticleId = articleTagMapper.findAllByArticleId(-1L);
|
||||||
|
assertTrue(allByArticleId.size() >= 6);
|
||||||
|
int lines = articleTagMapper.deleteMultiById(allByArticleId);
|
||||||
|
assertTrue(lines >= 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findArticleByTag() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(21L);
|
||||||
|
assertNotEquals(0, articleByTag.size());
|
||||||
|
articleByTag.forEach(articleTag1 -> assertEquals(articleTag.getTag().getName(), articleTag1.getTag().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findArticleByTagAndOpen() {
|
||||||
|
ArticleTag articleTag = generateArticle();
|
||||||
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(21L);
|
||||||
|
assertNotEquals(0, articleByTag.size());
|
||||||
|
articleByTag.forEach(articleTag1 -> assertEquals(articleTag.getTag().getName(), articleTag1.getTag().getName()));
|
||||||
|
articleByTag.forEach(articleTag1 -> assertTrue(articleTag1.getArticle().getOpen()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArticleTag generateArticle() {
|
||||||
|
String randomText = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
Article article = new Article();
|
||||||
|
Category category = new Category();
|
||||||
|
category.setId(1L);
|
||||||
|
article.setCategory(category);
|
||||||
|
article.setTitle(" unity test for article " + randomText);
|
||||||
|
article.setMdContent("# unity test for article");
|
||||||
|
article.setSummary("unity test for article");
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setId(1L);
|
||||||
|
article.setUser(user);
|
||||||
|
article.setType(true);
|
||||||
|
|
||||||
|
articleMapper.insert(article);
|
||||||
|
|
||||||
|
ArticleTag articleTag = new ArticleTag();
|
||||||
|
Tag tag = tagMapper.findTagByName("随笔");
|
||||||
|
articleTag.setArticle(article);
|
||||||
|
articleTag.setTag(tag);
|
||||||
|
articleTagMapper.insert(articleTag);
|
||||||
|
|
||||||
|
return articleTag;
|
||||||
|
}
|
||||||
|
}
|
||||||
121
src/test/java/cn/celess/blog/mapper/CategoryMapperTest.java
Normal file
121
src/test/java/cn/celess/blog/mapper/CategoryMapperTest.java
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Category;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class CategoryMapperTest extends BaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CategoryMapper categoryMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insert() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
assertNotNull(category.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
assertFalse(category.getDeleted());
|
||||||
|
int lines = categoryMapper.delete(category.getId());
|
||||||
|
assertNotEquals(0, lines);
|
||||||
|
Category categoryById = categoryMapper.findCategoryById(category.getId());
|
||||||
|
assertTrue(categoryById.getDeleted());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
category.setName(randomStr(4));
|
||||||
|
int update = categoryMapper.update(category);
|
||||||
|
assertEquals(1, update);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void existsByName() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
assertTrue(categoryMapper.existsByName(category.getName()));
|
||||||
|
assertFalse(categoryMapper.existsByName(randomStr(8)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void existsById() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
assertTrue(categoryMapper.existsById(category.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findCategoryByName() {
|
||||||
|
Category suibi = categoryMapper.findCategoryByName("随笔");
|
||||||
|
assertNotNull(suibi);
|
||||||
|
|
||||||
|
// tag 数据
|
||||||
|
Category shiro = categoryMapper.findCategoryByName("shiro");
|
||||||
|
assertNull(shiro);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findCategoryById() {
|
||||||
|
Category suibi = categoryMapper.findCategoryByName("随笔");
|
||||||
|
|
||||||
|
Category categoryById = categoryMapper.findCategoryById(suibi.getId());
|
||||||
|
|
||||||
|
assertEquals(suibi.getName(), categoryById.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
|
List<Category> all = categoryMapper.findAll();
|
||||||
|
assertNotEquals(0, all);
|
||||||
|
all.forEach(category -> assertTrue(category.getCategory()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllName() {
|
||||||
|
List<String> allName = categoryMapper.getAllName();
|
||||||
|
assertNotEquals(0, allName.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNameById() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
assertEquals(category.getName(), categoryMapper.getNameById(category.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getIdByName() {
|
||||||
|
Category category = generateCategory();
|
||||||
|
assertEquals(category.getId(), categoryMapper.getIdByName(category.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLastestCategory() {
|
||||||
|
List<Category> all = categoryMapper.findAll();
|
||||||
|
all.sort((o1, o2) -> (int) (o2.getId() - o1.getId()));
|
||||||
|
assertEquals(all.get(0).getId(), categoryMapper.getLastestCategory().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void count() {
|
||||||
|
List<Category> all = categoryMapper.findAll();
|
||||||
|
List<Category> collect = all.stream().filter(category -> !category.getDeleted()).collect(Collectors.toList());
|
||||||
|
assertEquals(collect.size(), categoryMapper.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Category generateCategory() {
|
||||||
|
Category category = new Category(randomStr(4));
|
||||||
|
|
||||||
|
categoryMapper.insert(category);
|
||||||
|
category.setDeleted(false);
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user