Compare commits
4 Commits
7380f783ee
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fae09f42f | |||
| 7db42c6c30 | |||
| 304c458436 | |||
| b7afe9496a |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -65,4 +65,5 @@ Desktop.ini
|
|||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
application-prod.yml
|
application-prod.yml
|
||||||
application-dev.yml
|
application-dev.yml
|
||||||
.env
|
.env
|
||||||
|
/.idea/.cache/.Apifox_Helper/.toolWindow.db
|
||||||
|
|||||||
1
.idea/data_source_mapping.xml
generated
1
.idea/data_source_mapping.xml
generated
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="DataSourcePerFileMappings">
|
<component name="DataSourcePerFileMappings">
|
||||||
|
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/bb8330e4-9a89-4978-ad63-ad6402096c16/console.sql" value="bb8330e4-9a89-4978-ad63-ad6402096c16" />
|
||||||
<file url="file://$PROJECT_DIR$/sql/createTable.sql" value="bb8330e4-9a89-4978-ad63-ad6402096c16" />
|
<file url="file://$PROJECT_DIR$/sql/createTable.sql" value="bb8330e4-9a89-4978-ad63-ad6402096c16" />
|
||||||
<file url="file://$PROJECT_DIR$/weblog-module-common/src/main/java/com/hanserwei/common/domain/dataobject/Category.java" value="bb8330e4-9a89-4978-ad63-ad6402096c16" />
|
<file url="file://$PROJECT_DIR$/weblog-module-common/src/main/java/com/hanserwei/common/domain/dataobject/Category.java" value="bb8330e4-9a89-4978-ad63-ad6402096c16" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ COMMENT ON COLUMN t_user.is_deleted IS '逻辑删除:FALSE:未删除 TRUE:
|
|||||||
CREATE TABLE t_user_role
|
CREATE TABLE t_user_role
|
||||||
(
|
(
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
username VARCHAR(60) NOT NULL,
|
username VARCHAR(60) NOT NULL,
|
||||||
role_name VARCHAR(60) NOT NULL, -- 重命名为 role_name 避免关键字冲突
|
role_name VARCHAR(60) NOT NULL, -- 重命名为 role_name 避免关键字冲突
|
||||||
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ CREATE TABLE t_category
|
|||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
-- 分类名称:VARCHAR(60) NOT NULL DEFAULT '',同时是 UNIQUE 约束
|
-- 分类名称:VARCHAR(60) NOT NULL DEFAULT '',同时是 UNIQUE 约束
|
||||||
"name" VARCHAR(60) NOT NULL DEFAULT '',
|
"name" VARCHAR(60) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
-- 创建时间
|
-- 创建时间
|
||||||
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||||
@@ -72,7 +72,7 @@ CREATE TABLE t_category
|
|||||||
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||||
|
|
||||||
-- 逻辑删除标志位:tinyint(2) NOT NULL DEFAULT '0',改为 BOOLEAN
|
-- 逻辑删除标志位:tinyint(2) NOT NULL DEFAULT '0',改为 BOOLEAN
|
||||||
is_deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
is_deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
-- UNIQUE KEY uk_name (`name`)
|
-- UNIQUE KEY uk_name (`name`)
|
||||||
CONSTRAINT uk_name UNIQUE ("name")
|
CONSTRAINT uk_name UNIQUE ("name")
|
||||||
@@ -95,4 +95,228 @@ CREATE TRIGGER set_t_category_update_time
|
|||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION set_update_time();
|
EXECUTE FUNCTION set_update_time();
|
||||||
-- ====================================================================================================================
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- 1. 创建表结构
|
||||||
|
CREATE TABLE t_tag
|
||||||
|
(
|
||||||
|
-- id: 使用 BIG SERIAL,自动创建序列,性能优异
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
|
-- name: 保持 VARCHAR(60),但在 PG 中 TEXT 和 VARCHAR 性能一样,
|
||||||
|
-- 这里为了保留原表 "60字符限制" 的业务逻辑,继续使用 VARCHAR(60)
|
||||||
|
name VARCHAR(60) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- create_time: 使用带时区的时间戳,更标准严谨
|
||||||
|
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
-- update_time: 同上
|
||||||
|
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
-- is_deleted: 使用原生 BOOLEAN 类型,存储效率高且语义明确
|
||||||
|
is_deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
|
-- 约束:显式命名约束,方便后续维护(如报错时能看到具体约束名)
|
||||||
|
CONSTRAINT uk_tag_name UNIQUE (name)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 2. 创建普通索引
|
||||||
|
-- 对应 MySQL 的 KEY `idx_create_time`
|
||||||
|
CREATE INDEX idx_tag_create_time ON t_tag (create_time);
|
||||||
|
|
||||||
|
-- 3. 添加注释 (PostgresSQL 标准方式)
|
||||||
|
COMMENT ON TABLE t_tag IS '文章标签表';
|
||||||
|
COMMENT ON COLUMN t_tag.id IS '标签id';
|
||||||
|
COMMENT ON COLUMN t_tag.name IS '标签名称';
|
||||||
|
COMMENT ON COLUMN t_tag.create_time IS '创建时间';
|
||||||
|
COMMENT ON COLUMN t_tag.update_time IS '最后一次更新时间';
|
||||||
|
COMMENT ON COLUMN t_tag.is_deleted IS '逻辑删除标志位:FALSE:未删除 TRUE:已删除';
|
||||||
|
|
||||||
|
-- 4. 应用自动更新时间戳触发器 (体现 PostgresSQL 强大的过程语言优势)
|
||||||
|
-- 前提:您之前已经执行过 CREATE FUNCTION set_update_time() ...
|
||||||
|
CREATE TRIGGER set_t_tag_update_time
|
||||||
|
BEFORE UPDATE
|
||||||
|
ON t_tag
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION set_update_time();
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
CREATE TABLE t_blog_settings
|
||||||
|
(
|
||||||
|
-- id: 使用 BIG SERIAL 自动管理序列
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
|
-- logo: 图片路径可能很长,使用 TEXT 替代 VARCHAR(120),无性能损耗
|
||||||
|
logo TEXT NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- name: 博客名称通常较短,保留 VARCHAR 限制也是一种合理的业务约束
|
||||||
|
name VARCHAR(60) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- author: 作者名同上
|
||||||
|
author VARCHAR(20) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- introduction: 介绍语可能会变长,使用 TEXT 更灵活
|
||||||
|
introduction TEXT NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- avatar: 头像路径,使用 TEXT
|
||||||
|
avatar TEXT NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- 下面的主页链接:原 MySQL 定义 varchar(60) 风险很高,
|
||||||
|
-- 现在的 URL 很容易超过 60 字符,PG 使用 TEXT 完美解决
|
||||||
|
github_homepage TEXT NOT NULL DEFAULT '',
|
||||||
|
csdn_homepage TEXT NOT NULL DEFAULT '',
|
||||||
|
gitee_homepage TEXT NOT NULL DEFAULT '',
|
||||||
|
zhihu_homepage TEXT NOT NULL DEFAULT ''
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 添加注释
|
||||||
|
COMMENT ON TABLE t_blog_settings IS '博客设置表';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.id IS 'id';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.logo IS '博客Logo';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.name IS '博客名称';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.author IS '作者名';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.introduction IS '介绍语';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.avatar IS '作者头像';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.github_homepage IS 'GitHub 主页访问地址';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.csdn_homepage IS 'CSDN 主页访问地址';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.gitee_homepage IS 'Gitee 主页访问地址';
|
||||||
|
COMMENT ON COLUMN t_blog_settings.zhihu_homepage IS '知乎主页访问地址';
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
CREATE TABLE t_article
|
||||||
|
(
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
|
-- 标题:保持限制,适合作为索引或列表显示
|
||||||
|
title VARCHAR(120) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- 封面:使用 TEXT,不再担心 URL 超长
|
||||||
|
cover TEXT NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- 摘要:使用 TEXT,不再受 160 字限制,前端截取即可
|
||||||
|
summary TEXT DEFAULT '',
|
||||||
|
|
||||||
|
-- 阅读量:使用 INTEGER 配合 CHECK 约束模拟 unsigned
|
||||||
|
read_num INTEGER NOT NULL DEFAULT 1 CHECK (read_num >= 0),
|
||||||
|
|
||||||
|
-- 时间与逻辑删除
|
||||||
|
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
is_deleted BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 索引
|
||||||
|
CREATE INDEX idx_article_create_time ON t_article (create_time);
|
||||||
|
|
||||||
|
-- 自动更新时间戳触发器
|
||||||
|
CREATE TRIGGER set_t_article_update_time
|
||||||
|
BEFORE UPDATE
|
||||||
|
ON t_article
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION set_update_time();
|
||||||
|
|
||||||
|
-- 注释
|
||||||
|
COMMENT ON TABLE t_article IS '文章表';
|
||||||
|
COMMENT ON COLUMN t_article.read_num IS '被阅读次数 (>=0)';
|
||||||
|
COMMENT ON COLUMN t_article.cover IS '文章封面';
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
CREATE TABLE t_article_content
|
||||||
|
(
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
|
-- 外键关联字段
|
||||||
|
article_id BIGINT NOT NULL,
|
||||||
|
|
||||||
|
-- 正文:PG 的 TEXT 能够容纳海量文字
|
||||||
|
content TEXT,
|
||||||
|
|
||||||
|
-- 显式外键约束:确保 article_id 必须存在于 t_article 表中
|
||||||
|
-- ON DELETE CASCADE: 如果物理删除了 t_article,对应的内容也会被自动删除
|
||||||
|
CONSTRAINT fk_article_content_article_id
|
||||||
|
FOREIGN KEY (article_id)
|
||||||
|
REFERENCES t_article (id)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 索引
|
||||||
|
CREATE INDEX idx_article_content_article_id ON t_article_content (article_id);
|
||||||
|
|
||||||
|
-- 注释
|
||||||
|
COMMENT ON TABLE t_article_content IS '文章内容表';
|
||||||
|
COMMENT ON COLUMN t_article_content.content IS '教程正文';
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
CREATE TABLE t_article_category_rel
|
||||||
|
(
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
|
-- 文章 ID:添加外键,删除文章时自动删除此关联
|
||||||
|
article_id BIGINT NOT NULL,
|
||||||
|
|
||||||
|
-- 分类 ID:添加外键,删除分类时... (通常分类不轻易删,或者策略不同,这里设为级联删除)
|
||||||
|
category_id BIGINT NOT NULL,
|
||||||
|
|
||||||
|
-- 约束:保证 article_id 唯一 (对应 MySQL 的 UNIQUE KEY)
|
||||||
|
CONSTRAINT uni_article_category_rel_article_id UNIQUE (article_id),
|
||||||
|
|
||||||
|
-- 外键定义
|
||||||
|
CONSTRAINT fk_rel_cat_article
|
||||||
|
FOREIGN KEY (article_id)
|
||||||
|
REFERENCES t_article (id)
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
|
||||||
|
CONSTRAINT fk_rel_cat_category
|
||||||
|
FOREIGN KEY (category_id)
|
||||||
|
REFERENCES t_category (id)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 索引:category_id 需要索引以便反向查询(查询某分类下有哪些文章)
|
||||||
|
CREATE INDEX idx_rel_cat_category_id ON t_article_category_rel (category_id);
|
||||||
|
|
||||||
|
-- 注释
|
||||||
|
COMMENT ON TABLE t_article_category_rel IS '文章所属分类关联表';
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
-- ====================================================================================================================
|
||||||
|
CREATE TABLE t_article_tag_rel
|
||||||
|
(
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
|
||||||
|
article_id BIGINT NOT NULL,
|
||||||
|
tag_id BIGINT NOT NULL,
|
||||||
|
|
||||||
|
-- 外键定义:级联删除
|
||||||
|
CONSTRAINT fk_rel_tag_article
|
||||||
|
FOREIGN KEY (article_id)
|
||||||
|
REFERENCES t_article (id)
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
|
||||||
|
CONSTRAINT fk_rel_tag_tag
|
||||||
|
FOREIGN KEY (tag_id)
|
||||||
|
REFERENCES t_tag (id)
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
|
||||||
|
-- ⚡ 优化:防止同一篇文章被打上重复的标签
|
||||||
|
CONSTRAINT uk_article_tag_rel_unique_pair UNIQUE (article_id, tag_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 索引
|
||||||
|
CREATE INDEX idx_rel_tag_article_id ON t_article_tag_rel (article_id);
|
||||||
|
CREATE INDEX idx_rel_tag_tag_id ON t_article_tag_rel (tag_id);
|
||||||
|
|
||||||
|
-- 注释
|
||||||
|
COMMENT ON TABLE t_article_tag_rel IS '文章对应标签关联表';
|
||||||
|
-- ====================================================================================================================
|
||||||
-- ====================================================================================================================
|
-- ====================================================================================================================
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.hanserwei.admin.controller;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.article.*;
|
||||||
|
import com.hanserwei.admin.service.AdminArticleService;
|
||||||
|
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||||
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理端文章控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/article")
|
||||||
|
public class AdminArticleController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminArticleService articleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布文章
|
||||||
|
*/
|
||||||
|
@PostMapping("/publish")
|
||||||
|
@ApiOperationLog(description = "文章发布")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
public Response<?> publishArticle(@RequestBody @Validated PublishArticleReqVO publishArticleReqVO) {
|
||||||
|
return articleService.publishArticle(publishArticleReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文章
|
||||||
|
*/
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@ApiOperationLog(description = "文章删除")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
public Response<?> deleteArticle(@RequestBody @Validated DeleteArticleReqVO deleteArticleReqVO) {
|
||||||
|
return articleService.deleteArticle(deleteArticleReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文章分页数据
|
||||||
|
*/
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperationLog(description = "查询文章分页数据")
|
||||||
|
public PageResponse<FindArticlePageListRspVO> findArticlePageList(@RequestBody @Validated FindArticlePageListReqVO findArticlePageListReqVO) {
|
||||||
|
return articleService.findArticlePageList(findArticlePageListReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文章详情
|
||||||
|
*/
|
||||||
|
@PostMapping("/detail")
|
||||||
|
@ApiOperationLog(description = "查询文章详情")
|
||||||
|
public Response<FindArticleDetailRspVO> findArticleDetail(@RequestBody @Validated FindArticleDetailReqVO findArticlePageListReqVO) {
|
||||||
|
return articleService.findArticleDetail(findArticlePageListReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新文章
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationLog(description = "更新文章")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
public Response<?> updateArticle(@RequestBody @Validated UpdateArticleReqVO updateArticleReqVO) {
|
||||||
|
return articleService.updateArticle(updateArticleReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.hanserwei.admin.controller;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.setting.FindBlogSettingsRspVO;
|
||||||
|
import com.hanserwei.admin.model.vo.setting.UpdateBlogSettingsReqVO;
|
||||||
|
import com.hanserwei.admin.service.AdminBlogSettingsService;
|
||||||
|
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理端博客设置控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/blog/settings")
|
||||||
|
public class AdminBlogSettingsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminBlogSettingsService blogSettingsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客基础信息修改
|
||||||
|
*/
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperationLog(description = "博客基础信息修改")
|
||||||
|
public Response<?> updateBlogSettings(@RequestBody @Validated UpdateBlogSettingsReqVO updateBlogSettingsReqVO) {
|
||||||
|
return blogSettingsService.updateBlogSettings(updateBlogSettingsReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取博客设置详情
|
||||||
|
*/
|
||||||
|
@PostMapping("/detail")
|
||||||
|
@ApiOperationLog(description = "获取博客设置详情")
|
||||||
|
public Response<FindBlogSettingsRspVO> findDetail() {
|
||||||
|
return blogSettingsService.findDetail();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.hanserwei.admin.controller;
|
package com.hanserwei.admin.controller;
|
||||||
|
|
||||||
import com.hanserwei.admin.model.vo.AddCategoryReqVO;
|
import com.hanserwei.admin.model.vo.category.*;
|
||||||
import com.hanserwei.admin.model.vo.DeleteCategoryReqVO;
|
|
||||||
import com.hanserwei.admin.model.vo.FindCategoryPageListReqVO;
|
|
||||||
import com.hanserwei.admin.model.vo.FindCategoryPageListRspVO;
|
|
||||||
import com.hanserwei.admin.service.AdminCategoryService;
|
import com.hanserwei.admin.service.AdminCategoryService;
|
||||||
import com.hanserwei.common.aspect.ApiOperationLog;
|
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||||
import com.hanserwei.common.model.vo.SelectRspVO;
|
import com.hanserwei.common.model.vo.SelectRspVO;
|
||||||
@@ -11,10 +8,7 @@ import com.hanserwei.common.utils.PageResponse;
|
|||||||
import com.hanserwei.common.utils.Response;
|
import com.hanserwei.common.utils.Response;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -64,4 +58,13 @@ public class AdminCategoryController {
|
|||||||
return adminCategoryService.findCategorySelectList();
|
return adminCategoryService.findCategorySelectList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类ID查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/category/find/{id}")
|
||||||
|
@ApiOperationLog(description = "根据分类ID查询")
|
||||||
|
public Response<FindCategoryByIdRspVO> findCategoryById(@PathVariable Long id) {
|
||||||
|
return adminCategoryService.findCategoryById(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.hanserwei.admin.controller;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.file.UploadFileRspVO;
|
||||||
|
import com.hanserwei.admin.service.AdminFileService;
|
||||||
|
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理端文件控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin")
|
||||||
|
public class AdminFileController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminFileService fileService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传
|
||||||
|
*/
|
||||||
|
@PostMapping("/file/upload")
|
||||||
|
@ApiOperationLog(description = "文件上传")
|
||||||
|
public Response<UploadFileRspVO> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||||
|
return fileService.uploadFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.hanserwei.admin.controller;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.tag.*;
|
||||||
|
import com.hanserwei.admin.service.AdminTagService;
|
||||||
|
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||||
|
import com.hanserwei.common.model.vo.SelectRspVO;
|
||||||
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理端标签控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin")
|
||||||
|
public class AdminTagController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminTagService adminTagService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加标签
|
||||||
|
*/
|
||||||
|
@PostMapping("/tag/add")
|
||||||
|
@ApiOperationLog(description = "添加标签")
|
||||||
|
public Response<?> addTag(@RequestBody @Validated AddTagReqVO addTagReqVO) {
|
||||||
|
return adminTagService.addTag(addTagReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签分页数据获取
|
||||||
|
*/
|
||||||
|
@PostMapping("/tag/list")
|
||||||
|
@ApiOperationLog(description = "标签分页数据获取")
|
||||||
|
public PageResponse<FindTagPageListRspVO> findTagList(@RequestBody @Validated FindTagPageListReqVO findTagPageListReqVO) {
|
||||||
|
return adminTagService.findTagList(findTagPageListReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标签
|
||||||
|
*/
|
||||||
|
@PostMapping("/tag/delete")
|
||||||
|
@ApiOperationLog(description = "删除标签")
|
||||||
|
public Response<?> deleteTag(@RequestBody @Validated DeleteTagReqVO deleteTagReqVO) {
|
||||||
|
return adminTagService.deleteTag(deleteTagReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签模糊查询
|
||||||
|
*/
|
||||||
|
@PostMapping("/tag/search")
|
||||||
|
@ApiOperationLog(description = "标签模糊查询")
|
||||||
|
public Response<List<SelectRspVO>> searchTag(@RequestBody @Validated SearchTagReqVO searchTagReqVO) {
|
||||||
|
return adminTagService.searchTag(searchTagReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID列表获取标签
|
||||||
|
*/
|
||||||
|
@PostMapping("/tag/list/ids")
|
||||||
|
@ApiOperationLog(description = "根据ID列表获取标签")
|
||||||
|
public Response<List<FindTagsByIdsRspVO>> findTagsByIds(@RequestBody @Validated FindTagsByIdsReqVO findTagsByIdsReqVO) {
|
||||||
|
return adminTagService.findTagsByIds(findTagsByIdsReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.hanserwei.admin.controller;
|
package com.hanserwei.admin.controller;
|
||||||
|
|
||||||
import com.hanserwei.admin.model.vo.FindUserInfoRspVO;
|
import com.hanserwei.admin.model.vo.user.FindUserInfoRspVO;
|
||||||
import com.hanserwei.admin.model.vo.UpdateAdminUserPasswordReqVO;
|
import com.hanserwei.admin.model.vo.user.UpdateAdminUserPasswordReqVO;
|
||||||
import com.hanserwei.admin.service.AdminUserService;
|
import com.hanserwei.admin.service.AdminUserService;
|
||||||
import com.hanserwei.common.aspect.ApiOperationLog;
|
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||||
import com.hanserwei.common.utils.Response;
|
import com.hanserwei.common.utils.Response;
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class DeleteArticleReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "文章 ID 不能为空")
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindArticleDetailReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章 ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "文章 ID 不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindArticleDetailRspVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章 ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章封面
|
||||||
|
*/
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类 ID
|
||||||
|
*/
|
||||||
|
private Long categoryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签 ID 集合
|
||||||
|
*/
|
||||||
|
private List<Long> tagIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摘要
|
||||||
|
*/
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import com.hanserwei.common.model.BasePageQuery;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindArticlePageListReqVO extends BasePageQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布的起始日期
|
||||||
|
*/
|
||||||
|
private LocalDate startDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布的结束日期
|
||||||
|
*/
|
||||||
|
private LocalDate endDate;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindArticlePageListRspVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章 ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章封面
|
||||||
|
*/
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 发布文章请求参数
|
||||||
|
*/
|
||||||
|
public class PublishArticleReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文章标题不能为空")
|
||||||
|
@Length(min = 1, max = 40, message = "文章标题字数需大于 1 小于 40")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章内容
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文章内容不能为空")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章封面图片URL
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文章封面不能为空")
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章摘要
|
||||||
|
*/
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章分类ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "文章分类不能为空")
|
||||||
|
private Long categoryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标签列表
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "文章标签不能为空")
|
||||||
|
private List<String> tags;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.article;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新文章请求参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class UpdateArticleReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "文章 ID 不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文章标题不能为空")
|
||||||
|
@Length(min = 1, max = 40, message = "文章标题字数需大于 1 小于 40")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章内容
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文章内容不能为空")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章封面图片URL
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文章封面不能为空")
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章摘要
|
||||||
|
*/
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章分类ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "文章分类不能为空")
|
||||||
|
private Long categoryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标签列表
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "文章标签不能为空")
|
||||||
|
private List<String> tags;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hanserwei.admin.model.vo;
|
package com.hanserwei.admin.model.vo.category;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hanserwei.admin.model.vo;
|
package com.hanserwei.admin.model.vo.category;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.category;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindCategoryByIdRspVO {
|
||||||
|
/**
|
||||||
|
* 分类 ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 分类名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hanserwei.admin.model.vo;
|
package com.hanserwei.admin.model.vo.category;
|
||||||
|
|
||||||
import com.hanserwei.common.model.BasePageQuery;
|
import com.hanserwei.common.model.BasePageQuery;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hanserwei.admin.model.vo;
|
package com.hanserwei.admin.model.vo.category;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.file;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class UploadFileRspVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件的访问链接
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.setting;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询博客设置响应 VO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindBlogSettingsRspVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客 Logo
|
||||||
|
*/
|
||||||
|
private String logo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作者名称
|
||||||
|
*/
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客介绍
|
||||||
|
*/
|
||||||
|
private String introduction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作者头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GitHub 主页地址
|
||||||
|
*/
|
||||||
|
private String githubHomepage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CSDN 主页地址
|
||||||
|
*/
|
||||||
|
private String csdnHomepage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gitee 主页地址
|
||||||
|
*/
|
||||||
|
private String giteeHomepage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 知乎主页地址
|
||||||
|
*/
|
||||||
|
private String zhihuHomepage;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.setting;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新博客设置请求 VO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class UpdateBlogSettingsReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客 LOGO
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "博客 LOGO 不能为空")
|
||||||
|
private String logo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "博客名称不能为空")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客作者
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "博客作者不能为空")
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客介绍语
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "博客介绍语不能为空")
|
||||||
|
private String introduction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客头像
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "博客头像不能为空")
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GitHub 主页
|
||||||
|
*/
|
||||||
|
private String githubHomepage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CSDN 主页
|
||||||
|
*/
|
||||||
|
private String csdnHomepage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gitee 主页
|
||||||
|
*/
|
||||||
|
private String giteeHomepage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 知乎主页
|
||||||
|
*/
|
||||||
|
private String zhihuHomepage;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class AddTagReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签集合
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "标签集合 不能为空")
|
||||||
|
private List<String> tags;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class DeleteTagReqVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签 ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "标签 ID 不能为空")
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import com.hanserwei.common.model.BasePageQuery;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindTagPageListReqVO extends BasePageQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建的起始日期
|
||||||
|
*/
|
||||||
|
private LocalDate startDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建的结束日期
|
||||||
|
*/
|
||||||
|
private LocalDate endDate;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindTagPageListRspVO {
|
||||||
|
/**
|
||||||
|
* 标签 ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FindTagsByIdsReqVO {
|
||||||
|
/**
|
||||||
|
* 标签 ID 集合
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "标签 ID 集合不能为空")
|
||||||
|
private List<Long> tagIds;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class FindTagsByIdsRspVO {
|
||||||
|
/**
|
||||||
|
* 标签 ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 标签名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.hanserwei.admin.model.vo.tag;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SearchTagReqVO {
|
||||||
|
|
||||||
|
@NotEmpty(message = "标签查询关键词不能为空!")
|
||||||
|
private String key;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hanserwei.admin.model.vo;
|
package com.hanserwei.admin.model.vo.user;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hanserwei.admin.model.vo;
|
package com.hanserwei.admin.model.vo.user;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.hanserwei.admin.service;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.article.*;
|
||||||
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
|
||||||
|
public interface AdminArticleService {
|
||||||
|
/**
|
||||||
|
* 发布文章
|
||||||
|
*
|
||||||
|
* @param publishArticleReqVO 文章发布参数
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
|
Response<?> publishArticle(PublishArticleReqVO publishArticleReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文章
|
||||||
|
*
|
||||||
|
* @param deleteArticleReqVO 删除文章参数
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
|
Response<?> deleteArticle(DeleteArticleReqVO deleteArticleReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文章分页数据
|
||||||
|
*
|
||||||
|
* @param findArticlePageListReqVO 查询文章分页请求参数
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
|
PageResponse<FindArticlePageListRspVO> findArticlePageList(FindArticlePageListReqVO findArticlePageListReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文章详情
|
||||||
|
*
|
||||||
|
* @param findArticleDetailReqVO 查询文章详情参数
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
|
Response<FindArticleDetailRspVO> findArticleDetail(FindArticleDetailReqVO findArticleDetailReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新文章
|
||||||
|
*
|
||||||
|
* @param updateArticleReqVO 更新文章参数
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
|
Response<?> updateArticle(UpdateArticleReqVO updateArticleReqVO);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.hanserwei.admin.service;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.setting.FindBlogSettingsRspVO;
|
||||||
|
import com.hanserwei.admin.model.vo.setting.UpdateBlogSettingsReqVO;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
|
||||||
|
public interface AdminBlogSettingsService {
|
||||||
|
/**
|
||||||
|
* 更新博客设置信息
|
||||||
|
*
|
||||||
|
* @param updateBlogSettingsReqVO 博客设置信息
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
|
Response<?> updateBlogSettings(UpdateBlogSettingsReqVO updateBlogSettingsReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取博客设置详情
|
||||||
|
*
|
||||||
|
* @return 博客设置详情
|
||||||
|
*/
|
||||||
|
Response<FindBlogSettingsRspVO> findDetail();
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.hanserwei.admin.service;
|
package com.hanserwei.admin.service;
|
||||||
|
|
||||||
import com.hanserwei.admin.model.vo.AddCategoryReqVO;
|
import com.hanserwei.admin.model.vo.category.*;
|
||||||
import com.hanserwei.admin.model.vo.DeleteCategoryReqVO;
|
|
||||||
import com.hanserwei.admin.model.vo.FindCategoryPageListReqVO;
|
|
||||||
import com.hanserwei.admin.model.vo.FindCategoryPageListRspVO;
|
|
||||||
import com.hanserwei.common.model.vo.SelectRspVO;
|
import com.hanserwei.common.model.vo.SelectRspVO;
|
||||||
import com.hanserwei.common.utils.PageResponse;
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
import com.hanserwei.common.utils.Response;
|
import com.hanserwei.common.utils.Response;
|
||||||
@@ -40,6 +37,13 @@ public interface AdminCategoryService {
|
|||||||
*
|
*
|
||||||
* @return Select 列表数据
|
* @return Select 列表数据
|
||||||
*/
|
*/
|
||||||
Response<List<SelectRspVO>> findCategorySelectList();
|
Response<List<SelectRspVO>> findCategorySelectList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类 ID 查询分类
|
||||||
|
*
|
||||||
|
* @param id 分类 ID
|
||||||
|
* @return 查询结果
|
||||||
|
*/
|
||||||
|
Response<FindCategoryByIdRspVO> findCategoryById(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.hanserwei.admin.service;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.file.UploadFileRspVO;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
public interface AdminFileService {
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 访问地址
|
||||||
|
*/
|
||||||
|
Response<UploadFileRspVO> uploadFile(MultipartFile file);
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.hanserwei.admin.service;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.tag.*;
|
||||||
|
import com.hanserwei.common.model.vo.SelectRspVO;
|
||||||
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface AdminTagService {
|
||||||
|
/**
|
||||||
|
* 添加标签
|
||||||
|
*
|
||||||
|
* @param addTagReqVO 添加标签请求参数
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
Response<?> addTag(AddTagReqVO addTagReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签分页数据获取
|
||||||
|
*
|
||||||
|
* @param findTagPageListReqVO 标签分页数据获取请求参数
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
PageResponse<FindTagPageListRspVO> findTagList(FindTagPageListReqVO findTagPageListReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标签
|
||||||
|
*
|
||||||
|
* @param deleteTagReqVO 删除标签请求参数
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
Response<?> deleteTag(DeleteTagReqVO deleteTagReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签下拉列表数据获取
|
||||||
|
*
|
||||||
|
* @param searchTagReqVO 搜索标签请求参数
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
Response<List<SelectRspVO>> searchTag(SearchTagReqVO searchTagReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 ID 列表获取标签
|
||||||
|
*
|
||||||
|
* @param findTagsByIdsReqVO 根据 ID 列表获取标签请求参数
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
Response<List<FindTagsByIdsRspVO>> findTagsByIds(FindTagsByIdsReqVO findTagsByIdsReqVO);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.hanserwei.admin.service;
|
package com.hanserwei.admin.service;
|
||||||
|
|
||||||
import com.hanserwei.admin.model.vo.FindUserInfoRspVO;
|
import com.hanserwei.admin.model.vo.user.FindUserInfoRspVO;
|
||||||
import com.hanserwei.admin.model.vo.UpdateAdminUserPasswordReqVO;
|
import com.hanserwei.admin.model.vo.user.UpdateAdminUserPasswordReqVO;
|
||||||
import com.hanserwei.common.utils.Response;
|
import com.hanserwei.common.utils.Response;
|
||||||
|
|
||||||
public interface AdminUserService {
|
public interface AdminUserService {
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package com.hanserwei.admin.service.impl;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.article.*;
|
||||||
|
import com.hanserwei.admin.service.AdminArticleService;
|
||||||
|
import com.hanserwei.common.domain.dataobject.*;
|
||||||
|
import com.hanserwei.common.domain.repository.*;
|
||||||
|
import com.hanserwei.common.enums.ResponseCodeEnum;
|
||||||
|
import com.hanserwei.common.exception.BizException;
|
||||||
|
import com.hanserwei.common.utils.PageHelper;
|
||||||
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class AdminArticleServiceImpl implements AdminArticleService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ArticleRepository articleRepository;
|
||||||
|
@Resource
|
||||||
|
private ArticleTagRelRepository articleTagRelRepository;
|
||||||
|
@Resource
|
||||||
|
private ArticleCategoryRelRepository articleCategoryRelRepository;
|
||||||
|
@Resource
|
||||||
|
private ArticleContentRepository articleContentRepository;
|
||||||
|
@Resource
|
||||||
|
private CategoryRepository categoryRepository;
|
||||||
|
@Resource
|
||||||
|
private TagRepository tagRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Response<?> publishArticle(PublishArticleReqVO publishArticleReqVO) {
|
||||||
|
Article article = new Article();
|
||||||
|
BeanUtils.copyProperties(publishArticleReqVO, article);
|
||||||
|
Article saved = articleRepository.save(article);
|
||||||
|
// 拿到保存后的文章id
|
||||||
|
Long articleId = saved.getId();
|
||||||
|
ArticleContent articleContent = ArticleContent.builder()
|
||||||
|
.articleId(articleId)
|
||||||
|
.content(publishArticleReqVO.getContent())
|
||||||
|
.build();
|
||||||
|
articleContentRepository.save(articleContent);
|
||||||
|
// 处理分类
|
||||||
|
Long categoryId = publishArticleReqVO.getCategoryId();
|
||||||
|
categoryRepository.findById(categoryId)
|
||||||
|
.ifPresentOrElse(p -> {
|
||||||
|
ArticleCategoryRel articleCategoryRel = ArticleCategoryRel.builder()
|
||||||
|
.articleId(articleId)
|
||||||
|
.categoryId(categoryId)
|
||||||
|
.build();
|
||||||
|
articleCategoryRelRepository.save(articleCategoryRel);
|
||||||
|
}, () -> {
|
||||||
|
log.warn("==>文章分类不存在: {}", categoryId);
|
||||||
|
throw new BizException(ResponseCodeEnum.CATEGORY_NOT_EXISTED);
|
||||||
|
});
|
||||||
|
// 保存标签
|
||||||
|
List<String> tags = publishArticleReqVO.getTags();
|
||||||
|
insertTags(articleId, tags);
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Response<?> deleteArticle(DeleteArticleReqVO deleteArticleReqVO) {
|
||||||
|
Long id = deleteArticleReqVO.getId();
|
||||||
|
articleRepository.deleteById(id);
|
||||||
|
articleCategoryRelRepository.deleteByArticleId(id);
|
||||||
|
articleTagRelRepository.deleteByArticleId(id);
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResponse<FindArticlePageListRspVO> findArticlePageList(FindArticlePageListReqVO findArticlePageListReqVO) {
|
||||||
|
return PageHelper.findPageList(
|
||||||
|
articleRepository,
|
||||||
|
findArticlePageListReqVO,
|
||||||
|
findArticlePageListReqVO.getTitle(),
|
||||||
|
"title",
|
||||||
|
findArticlePageListReqVO.getStartDate(),
|
||||||
|
findArticlePageListReqVO.getEndDate(),
|
||||||
|
article -> FindArticlePageListRspVO.builder()
|
||||||
|
.id(article.getId())
|
||||||
|
.title(article.getTitle())
|
||||||
|
.cover(article.getCover())
|
||||||
|
.createTime(LocalDateTime.ofInstant(article.getCreateTime(), ZoneId.systemDefault()))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<FindArticleDetailRspVO> findArticleDetail(FindArticleDetailReqVO findArticleDetailReqVO) {
|
||||||
|
Long id = findArticleDetailReqVO.getId();
|
||||||
|
Article article = articleRepository.findById(id)
|
||||||
|
.orElseThrow(() -> {
|
||||||
|
log.warn("==>文章不存在: {}", id);
|
||||||
|
return new BizException(ResponseCodeEnum.ARTICLE_NOT_EXIST);
|
||||||
|
});
|
||||||
|
// 文章正文详情
|
||||||
|
ArticleContent articleContent = articleContentRepository.findByArticleId(id);
|
||||||
|
// 所属分类
|
||||||
|
ArticleCategoryRel articleCategoryRel = articleCategoryRelRepository.findByArticleId(id);
|
||||||
|
// 对应标签集合
|
||||||
|
List<ArticleTagRel> articleTagRelList = articleTagRelRepository.findByArticleId(id);
|
||||||
|
List<Long> tags = articleTagRelList.stream().map(ArticleTagRel::getTagId).toList();
|
||||||
|
// 封装响应结果
|
||||||
|
FindArticleDetailRspVO findArticleDetailRspVO = new FindArticleDetailRspVO();
|
||||||
|
BeanUtils.copyProperties(article, findArticleDetailRspVO);
|
||||||
|
findArticleDetailRspVO.setTagIds(tags);
|
||||||
|
findArticleDetailRspVO.setCategoryId(articleCategoryRel.getCategoryId());
|
||||||
|
findArticleDetailRspVO.setContent(articleContent.getContent());
|
||||||
|
return Response.success(findArticleDetailRspVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Response<?> updateArticle(UpdateArticleReqVO updateArticleReqVO) {
|
||||||
|
Long id = updateArticleReqVO.getId();
|
||||||
|
Article article = articleRepository.findById(id)
|
||||||
|
.orElseThrow(() -> {
|
||||||
|
log.warn("==>欲更新的文章不存在: {}", id);
|
||||||
|
return new BizException(ResponseCodeEnum.ARTICLE_NOT_EXIST);
|
||||||
|
});
|
||||||
|
BeanUtils.copyProperties(updateArticleReqVO, article);
|
||||||
|
// 更新文章正文
|
||||||
|
ArticleContent articleContent = articleContentRepository.findByArticleId(id);
|
||||||
|
articleContent.setContent(updateArticleReqVO.getContent());
|
||||||
|
articleContentRepository.save(articleContent);
|
||||||
|
// 更新分类
|
||||||
|
Long categoryId = updateArticleReqVO.getCategoryId();
|
||||||
|
// 验证该ID的分类是否存在
|
||||||
|
categoryRepository.findById(categoryId).orElseThrow(() -> {
|
||||||
|
log.warn("==>欲更新的文章其分类不存在: {}", categoryId);
|
||||||
|
return new BizException(ResponseCodeEnum.CATEGORY_NOT_EXISTED);
|
||||||
|
});
|
||||||
|
// 先删除关联的分类记录,再插入新的关联记录
|
||||||
|
articleCategoryRelRepository.deleteByArticleId(id);
|
||||||
|
ArticleCategoryRel articleCategoryRel = ArticleCategoryRel.builder()
|
||||||
|
.articleId(id)
|
||||||
|
.categoryId(categoryId)
|
||||||
|
.build();
|
||||||
|
articleCategoryRelRepository.save(articleCategoryRel);
|
||||||
|
// 删除该文章的标签关联
|
||||||
|
articleTagRelRepository.deleteByArticleId(id);
|
||||||
|
insertTags(id, updateArticleReqVO.getTags());
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入标签
|
||||||
|
*
|
||||||
|
* @param articleId 文章ID
|
||||||
|
* @param tags 标签列表(可能是ID字符串或标签名称)
|
||||||
|
*/
|
||||||
|
private void insertTags(Long articleId, List<String> tags) {
|
||||||
|
if (CollectionUtils.isEmpty(tags)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String tagStr : tags) {
|
||||||
|
Long tagId;
|
||||||
|
|
||||||
|
// 判断是否为数字ID
|
||||||
|
try {
|
||||||
|
tagId = Long.parseLong(tagStr);
|
||||||
|
// 验证该ID的标签是否存在
|
||||||
|
Optional<Tag> tagOptional = tagRepository.findById(tagId);
|
||||||
|
if (tagOptional.isEmpty()) {
|
||||||
|
log.warn("==>标签ID不存在: {}", tagId);
|
||||||
|
throw new BizException(ResponseCodeEnum.TAG_NOT_EXISTED);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 不是数字,说明是新标签名称,需要先保存标签
|
||||||
|
Tag newTag = Tag.builder()
|
||||||
|
.name(tagStr)
|
||||||
|
.build();
|
||||||
|
Tag savedTag = tagRepository.save(newTag);
|
||||||
|
tagId = savedTag.getId();
|
||||||
|
log.info("==>新增标签: {}, ID: {}", tagStr, tagId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存文章-标签关联关系
|
||||||
|
ArticleTagRel articleTagRel = ArticleTagRel.builder()
|
||||||
|
.articleId(articleId)
|
||||||
|
.tagId(tagId)
|
||||||
|
.build();
|
||||||
|
articleTagRelRepository.save(articleTagRel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.hanserwei.admin.service.impl;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.setting.FindBlogSettingsRspVO;
|
||||||
|
import com.hanserwei.admin.model.vo.setting.UpdateBlogSettingsReqVO;
|
||||||
|
import com.hanserwei.admin.service.AdminBlogSettingsService;
|
||||||
|
import com.hanserwei.common.domain.dataobject.BlogSettings;
|
||||||
|
import com.hanserwei.common.domain.repository.BlogSettingsRepository;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AdminBlogSettingsServiceImpl implements AdminBlogSettingsService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BlogSettingsRepository blogSettingsRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<?> updateBlogSettings(UpdateBlogSettingsReqVO updateBlogSettingsReqVO) {
|
||||||
|
// 保存或更新博客设置
|
||||||
|
blogSettingsRepository.findById(1L)
|
||||||
|
.ifPresentOrElse(existingSettings -> {
|
||||||
|
// 如果存在,则更新现有记录
|
||||||
|
BeanUtils.copyProperties(updateBlogSettingsReqVO, existingSettings);
|
||||||
|
blogSettingsRepository.saveAndFlush(existingSettings);
|
||||||
|
}, () -> {
|
||||||
|
// 如果不存在,则创建新记录
|
||||||
|
BlogSettings blogSettings = new BlogSettings();
|
||||||
|
BeanUtils.copyProperties(updateBlogSettingsReqVO, blogSettings);
|
||||||
|
blogSettings.setId(1L);
|
||||||
|
blogSettingsRepository.saveAndFlush(blogSettings);
|
||||||
|
});
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<FindBlogSettingsRspVO> findDetail() {
|
||||||
|
return blogSettingsRepository.findById(1L)
|
||||||
|
.map(e -> {
|
||||||
|
FindBlogSettingsRspVO findBlogSettingsRspVO = new FindBlogSettingsRspVO();
|
||||||
|
BeanUtils.copyProperties(e, findBlogSettingsRspVO);
|
||||||
|
return Response.success(findBlogSettingsRspVO);
|
||||||
|
})
|
||||||
|
.orElse(Response.success(null));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +1,32 @@
|
|||||||
package com.hanserwei.admin.service.impl;
|
package com.hanserwei.admin.service.impl;
|
||||||
|
|
||||||
import com.hanserwei.admin.model.vo.AddCategoryReqVO;
|
import com.hanserwei.admin.model.vo.category.*;
|
||||||
import com.hanserwei.admin.model.vo.DeleteCategoryReqVO;
|
|
||||||
import com.hanserwei.admin.model.vo.FindCategoryPageListReqVO;
|
|
||||||
import com.hanserwei.admin.model.vo.FindCategoryPageListRspVO;
|
|
||||||
import com.hanserwei.admin.service.AdminCategoryService;
|
import com.hanserwei.admin.service.AdminCategoryService;
|
||||||
|
import com.hanserwei.common.domain.dataobject.ArticleCategoryRel;
|
||||||
import com.hanserwei.common.domain.dataobject.Category;
|
import com.hanserwei.common.domain.dataobject.Category;
|
||||||
|
import com.hanserwei.common.domain.repository.ArticleCategoryRelRepository;
|
||||||
import com.hanserwei.common.domain.repository.CategoryRepository;
|
import com.hanserwei.common.domain.repository.CategoryRepository;
|
||||||
import com.hanserwei.common.enums.ResponseCodeEnum;
|
import com.hanserwei.common.enums.ResponseCodeEnum;
|
||||||
import com.hanserwei.common.exception.BizException;
|
import com.hanserwei.common.exception.BizException;
|
||||||
import com.hanserwei.common.model.vo.SelectRspVO;
|
import com.hanserwei.common.model.vo.SelectRspVO;
|
||||||
|
import com.hanserwei.common.utils.PageHelper;
|
||||||
import com.hanserwei.common.utils.PageResponse;
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
import com.hanserwei.common.utils.Response;
|
import com.hanserwei.common.utils.Response;
|
||||||
import io.jsonwebtoken.lang.Strings;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.persistence.criteria.Predicate;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AdminCategoryServiceImpl implements AdminCategoryService {
|
public class AdminCategoryServiceImpl implements AdminCategoryService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CategoryRepository categoryRepository;
|
private CategoryRepository categoryRepository;
|
||||||
|
@Resource
|
||||||
|
private ArticleCategoryRelRepository articleCategoryRelRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<?> addCategory(AddCategoryReqVO addCategoryReqVO) {
|
public Response<?> addCategory(AddCategoryReqVO addCategoryReqVO) {
|
||||||
@@ -53,53 +45,33 @@ public class AdminCategoryServiceImpl implements AdminCategoryService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResponse<FindCategoryPageListRspVO> findCategoryList(FindCategoryPageListReqVO findCategoryPageListReqVO) {
|
public PageResponse<FindCategoryPageListRspVO> findCategoryList(FindCategoryPageListReqVO findCategoryPageListReqVO) {
|
||||||
Long current = findCategoryPageListReqVO.getCurrent();
|
return PageHelper.findPageList(
|
||||||
Long size = findCategoryPageListReqVO.getSize();
|
categoryRepository,
|
||||||
|
findCategoryPageListReqVO,
|
||||||
Pageable pageable = PageRequest.of(current.intValue() - 1,
|
findCategoryPageListReqVO.getName(),
|
||||||
size.intValue(),
|
findCategoryPageListReqVO.getStartDate(),
|
||||||
Sort.by(Sort.Direction.DESC, "createTime"));
|
findCategoryPageListReqVO.getEndDate(),
|
||||||
|
category -> FindCategoryPageListRspVO.builder()
|
||||||
// 构建查询条件
|
|
||||||
Specification<Category> specification = (root, query, criteriaBuilder) -> {
|
|
||||||
List<Predicate> predicates = new ArrayList<>();
|
|
||||||
String name = findCategoryPageListReqVO.getName();
|
|
||||||
if (Strings.hasText(name)) {
|
|
||||||
predicates.add(
|
|
||||||
criteriaBuilder.like(root.get("name"), "%" + name.trim() + "%")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (Objects.nonNull(findCategoryPageListReqVO.getStartDate())){
|
|
||||||
predicates.add(
|
|
||||||
criteriaBuilder.greaterThanOrEqualTo(root.get("createTime"), findCategoryPageListReqVO.getStartDate())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (Objects.nonNull(findCategoryPageListReqVO.getEndDate())) {
|
|
||||||
predicates.add(
|
|
||||||
criteriaBuilder.lessThan(root.get("createTime"), findCategoryPageListReqVO.getEndDate().plusDays(1).atStartOfDay())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
|
||||||
};
|
|
||||||
|
|
||||||
Page<Category> categoryDOPage = categoryRepository.findAll(specification, pageable);
|
|
||||||
|
|
||||||
List<FindCategoryPageListRspVO> vos = categoryDOPage.getContent().stream()
|
|
||||||
.map(category -> FindCategoryPageListRspVO.builder()
|
|
||||||
.id(category.getId())
|
.id(category.getId())
|
||||||
.name(category.getName())
|
.name(category.getName())
|
||||||
.createTime(LocalDateTime.ofInstant(category.getCreateTime(), ZoneId.systemDefault()))
|
.createTime(LocalDateTime.ofInstant(category.getCreateTime(), ZoneId.systemDefault()))
|
||||||
.build())
|
.build()
|
||||||
.collect(Collectors.toList());
|
);
|
||||||
|
|
||||||
return PageResponse.success(categoryDOPage, vos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<?> deleteCategory(DeleteCategoryReqVO deleteCategoryReqVO) {
|
public Response<?> deleteCategory(DeleteCategoryReqVO deleteCategoryReqVO) {
|
||||||
Long id = deleteCategoryReqVO.getId();
|
List<ArticleCategoryRel> articleTagRelList = articleCategoryRelRepository.findByCategoryId((deleteCategoryReqVO.getId()));
|
||||||
categoryRepository.deleteById(id);
|
if (!CollectionUtils.isEmpty(articleTagRelList)) {
|
||||||
return Response.success();
|
throw new BizException(ResponseCodeEnum.CATEGORY_HAS_ARTICLE);
|
||||||
|
}
|
||||||
|
return categoryRepository.findById(deleteCategoryReqVO.getId())
|
||||||
|
.map(tag -> {
|
||||||
|
tag.setIsDeleted(true);
|
||||||
|
categoryRepository.save(tag);
|
||||||
|
return Response.success();
|
||||||
|
})
|
||||||
|
.orElse(Response.fail(ResponseCodeEnum.CATEGORY_NOT_EXIST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,7 +79,7 @@ public class AdminCategoryServiceImpl implements AdminCategoryService {
|
|||||||
List<Category> categoryList = categoryRepository.findAll();
|
List<Category> categoryList = categoryRepository.findAll();
|
||||||
// DO 转 VO
|
// DO 转 VO
|
||||||
List<SelectRspVO> selectRspVOS = null;
|
List<SelectRspVO> selectRspVOS = null;
|
||||||
if (!CollectionUtils.isEmpty(categoryList)){
|
if (!CollectionUtils.isEmpty(categoryList)) {
|
||||||
selectRspVOS = categoryList.stream()
|
selectRspVOS = categoryList.stream()
|
||||||
.map(category -> SelectRspVO.builder()
|
.map(category -> SelectRspVO.builder()
|
||||||
.label(category.getName())
|
.label(category.getName())
|
||||||
@@ -117,4 +89,14 @@ public class AdminCategoryServiceImpl implements AdminCategoryService {
|
|||||||
}
|
}
|
||||||
return Response.success(selectRspVOS);
|
return Response.success(selectRspVOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<FindCategoryByIdRspVO> findCategoryById(Long id) {
|
||||||
|
Category category = categoryRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new BizException(ResponseCodeEnum.CATEGORY_NOT_EXIST));
|
||||||
|
return Response.success(FindCategoryByIdRspVO.builder()
|
||||||
|
.id(category.getId())
|
||||||
|
.name(category.getName())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.hanserwei.admin.service.impl;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.file.UploadFileRspVO;
|
||||||
|
import com.hanserwei.admin.service.AdminFileService;
|
||||||
|
import com.hanserwei.admin.utils.RustfsUtils;
|
||||||
|
import com.hanserwei.common.enums.ResponseCodeEnum;
|
||||||
|
import com.hanserwei.common.exception.BizException;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class AdminFileServiceImpl implements AdminFileService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RustfsUtils rustfsUtils;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<UploadFileRspVO> uploadFile(MultipartFile file) {
|
||||||
|
try {
|
||||||
|
// 上传文件
|
||||||
|
String url = rustfsUtils.uploadFile(file);
|
||||||
|
return Response.success(UploadFileRspVO.builder().url(url).build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("==> 上传文件异常:{} ...", e.getMessage());
|
||||||
|
throw new BizException(ResponseCodeEnum.FILE_UPLOAD_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.hanserwei.admin.service.impl;
|
||||||
|
|
||||||
|
import com.hanserwei.admin.model.vo.tag.*;
|
||||||
|
import com.hanserwei.admin.service.AdminTagService;
|
||||||
|
import com.hanserwei.common.domain.dataobject.ArticleTagRel;
|
||||||
|
import com.hanserwei.common.domain.dataobject.Tag;
|
||||||
|
import com.hanserwei.common.domain.repository.ArticleTagRelRepository;
|
||||||
|
import com.hanserwei.common.domain.repository.TagRepository;
|
||||||
|
import com.hanserwei.common.enums.ResponseCodeEnum;
|
||||||
|
import com.hanserwei.common.exception.BizException;
|
||||||
|
import com.hanserwei.common.model.vo.SelectRspVO;
|
||||||
|
import com.hanserwei.common.utils.PageHelper;
|
||||||
|
import com.hanserwei.common.utils.PageResponse;
|
||||||
|
import com.hanserwei.common.utils.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AdminTagServiceImpl implements AdminTagService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TagRepository tagRepository;
|
||||||
|
@Resource
|
||||||
|
private ArticleTagRelRepository articleTagRelRepository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加标签
|
||||||
|
*
|
||||||
|
* @param addTagReqVO 添加标签请求对象
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Response<?> addTag(AddTagReqVO addTagReqVO) {
|
||||||
|
// 获取标签列表
|
||||||
|
List<String> tagList = addTagReqVO.getTags();
|
||||||
|
|
||||||
|
// 对标签进行清洗:去除空格、过滤空字符串、去重
|
||||||
|
List<String> names = tagList.stream()
|
||||||
|
.map(String::trim) // 去除首尾空格
|
||||||
|
.filter(s -> !s.isEmpty()) // 过滤空字符串
|
||||||
|
.distinct() // 去重
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 查询数据库中已存在的标签名称
|
||||||
|
List<String> exists = tagRepository.findByNameIn(names).stream()
|
||||||
|
.map(Tag::getName)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 筛选出需要新建的标签,并构建标签对象
|
||||||
|
List<Tag> toCreate = names.stream()
|
||||||
|
.filter(n -> !exists.contains(n)) // 过滤掉已存在的标签
|
||||||
|
.map(n -> Tag.builder().name(n).build()) // 构建标签对象
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 批量保存新标签到数据库
|
||||||
|
if (!toCreate.isEmpty()) {
|
||||||
|
tagRepository.saveAllAndFlush(toCreate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResponse<FindTagPageListRspVO> findTagList(FindTagPageListReqVO findTagPageListReqVO) {
|
||||||
|
return PageHelper.findPageList(
|
||||||
|
tagRepository,
|
||||||
|
findTagPageListReqVO,
|
||||||
|
findTagPageListReqVO.getName(),
|
||||||
|
findTagPageListReqVO.getStartDate(),
|
||||||
|
findTagPageListReqVO.getEndDate(),
|
||||||
|
tag -> FindTagPageListRspVO.builder()
|
||||||
|
.id(tag.getId())
|
||||||
|
.name(tag.getName())
|
||||||
|
.createTime(LocalDateTime.ofInstant(tag.getCreateTime(), ZoneId.systemDefault()))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<?> deleteTag(DeleteTagReqVO deleteTagReqVO) {
|
||||||
|
// 检查是否有关联的文章
|
||||||
|
List<ArticleTagRel> articleTagRelsList = articleTagRelRepository.findByTagId(deleteTagReqVO.getId());
|
||||||
|
if (!articleTagRelsList.isEmpty()) {
|
||||||
|
throw new BizException(ResponseCodeEnum.TAG_HAS_ARTICLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagRepository.findById(deleteTagReqVO.getId())
|
||||||
|
.map(tag -> {
|
||||||
|
tag.setIsDeleted(true);
|
||||||
|
tagRepository.save(tag);
|
||||||
|
return Response.success();
|
||||||
|
})
|
||||||
|
.orElse(Response.fail(ResponseCodeEnum.TAG_NOT_EXIST));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<List<SelectRspVO>> searchTag(SearchTagReqVO searchTagReqVO) {
|
||||||
|
// 使用模糊查询获取标签列表
|
||||||
|
List<Tag> tags = tagRepository.findByNameContaining(searchTagReqVO.getKey());
|
||||||
|
|
||||||
|
// 将标签转换为下拉列表格式
|
||||||
|
List<SelectRspVO> vos = tags.stream()
|
||||||
|
.map(tag -> SelectRspVO.builder()
|
||||||
|
.label(tag.getName())
|
||||||
|
.value(tag.getId())
|
||||||
|
.build())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return Response.success(vos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<List<FindTagsByIdsRspVO>> findTagsByIds(FindTagsByIdsReqVO findTagsByIdsReqVO) {
|
||||||
|
List<Tag> tags = tagRepository.queryAllByIdIn(findTagsByIdsReqVO.getTagIds());
|
||||||
|
List<FindTagsByIdsRspVO> vos = tags.stream()
|
||||||
|
.map(tag -> FindTagsByIdsRspVO.builder()
|
||||||
|
.id(tag.getId())
|
||||||
|
.name(tag.getName())
|
||||||
|
.build())
|
||||||
|
.toList();
|
||||||
|
return Response.success(vos);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.hanserwei.admin.service.impl;
|
package com.hanserwei.admin.service.impl;
|
||||||
|
|
||||||
import com.hanserwei.admin.model.vo.FindUserInfoRspVO;
|
import com.hanserwei.admin.model.vo.user.FindUserInfoRspVO;
|
||||||
import com.hanserwei.admin.model.vo.UpdateAdminUserPasswordReqVO;
|
import com.hanserwei.admin.model.vo.user.UpdateAdminUserPasswordReqVO;
|
||||||
import com.hanserwei.admin.service.AdminUserService;
|
import com.hanserwei.admin.service.AdminUserService;
|
||||||
import com.hanserwei.common.domain.repository.UserRepository;
|
import com.hanserwei.common.domain.repository.UserRepository;
|
||||||
import com.hanserwei.common.enums.ResponseCodeEnum;
|
import com.hanserwei.common.enums.ResponseCodeEnum;
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
package com.hanserwei.admin.utils;
|
||||||
|
|
||||||
|
import com.hanserwei.common.config.RustfsProperties;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import software.amazon.awssdk.core.sync.RequestBody;
|
||||||
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
|
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class RustfsUtils {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RustfsProperties rustfsProperties;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private S3Client s3Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 访问地址
|
||||||
|
* @throws Exception 异常
|
||||||
|
*/
|
||||||
|
public String uploadFile(MultipartFile file) throws Exception {
|
||||||
|
// 判断文件是否为空
|
||||||
|
if (file == null || file.getSize() == 0) {
|
||||||
|
log.error("==> 上传文件异常:文件大小为空 ...");
|
||||||
|
throw new RuntimeException("文件大小不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件的原始名称
|
||||||
|
String originalFileName = file.getOriginalFilename();
|
||||||
|
// 文件的 Content-Type
|
||||||
|
String contentType = file.getContentType();
|
||||||
|
|
||||||
|
// 生成存储对象的名称(将 UUID 字符串中的 - 替换成空字符串)
|
||||||
|
String key = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
// 获取文件的后缀,如 .jpg
|
||||||
|
String suffix = null;
|
||||||
|
if (originalFileName != null) {
|
||||||
|
suffix = originalFileName.substring(originalFileName.lastIndexOf("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拼接上文件后缀,即为要存储的文件名
|
||||||
|
String objectName = String.format("%s%s", key, suffix);
|
||||||
|
|
||||||
|
log.info("==> 开始上传文件至 Rustfs, ObjectName: {}", objectName);
|
||||||
|
|
||||||
|
// 上传文件至 Rustfs
|
||||||
|
PutObjectRequest putObjectRequest = PutObjectRequest.builder()
|
||||||
|
.key(objectName)
|
||||||
|
.bucket(rustfsProperties.getBucketName())
|
||||||
|
.contentType(contentType)
|
||||||
|
.contentLength(file.getSize())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(file.getInputStream(), file.getSize()));
|
||||||
|
|
||||||
|
// 返回文件的访问链接
|
||||||
|
String url = String.format("%s/%s/%s", rustfsProperties.getEndpoint(), rustfsProperties.getBucketName(), objectName);
|
||||||
|
log.info("==> 上传文件至 Rustfs 成功,访问路径: {}", url);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ dependencies {
|
|||||||
api("org.springframework.boot:spring-boot-starter-web")
|
api("org.springframework.boot:spring-boot-starter-web")
|
||||||
api("org.springframework.boot:spring-boot-starter-security")
|
api("org.springframework.boot:spring-boot-starter-security")
|
||||||
api("org.springframework.boot:spring-boot-starter-aop")
|
api("org.springframework.boot:spring-boot-starter-aop")
|
||||||
|
api("software.amazon.awssdk:s3:2.40.1")
|
||||||
|
|
||||||
runtimeOnly("org.postgresql:postgresql")
|
runtimeOnly("org.postgresql:postgresql")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.hanserwei.common.config;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||||
|
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||||
|
import software.amazon.awssdk.regions.Region;
|
||||||
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RustfsClientConfig {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RustfsProperties rustfsProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public S3Client s3Client() {
|
||||||
|
return S3Client.builder()
|
||||||
|
.endpointOverride(URI.create(rustfsProperties.getEndpoint()))
|
||||||
|
.region(Region.US_EAST_1)
|
||||||
|
.credentialsProvider(
|
||||||
|
StaticCredentialsProvider.create(
|
||||||
|
AwsBasicCredentials.create(rustfsProperties.getAccessKey(), rustfsProperties.getSecretKey())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.forcePathStyle(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.hanserwei.common.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Data
|
||||||
|
@ConfigurationProperties(prefix = "rustfs")
|
||||||
|
public class RustfsProperties {
|
||||||
|
private String endpoint;
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String bucketName;
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.hanserwei.common.domain.dataobject;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.SQLRestriction;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_article", indexes = {
|
||||||
|
@Index(name = "idx_article_create_time", columnList = "create_time")
|
||||||
|
})
|
||||||
|
@SQLRestriction("is_deleted = false")
|
||||||
|
@SQLDelete(sql = "update t_article set is_deleted = true where id = ?")
|
||||||
|
public class Article implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 120)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String cover = "";
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String summary = "";
|
||||||
|
|
||||||
|
@Column(name = "read_num", nullable = false)
|
||||||
|
@Builder.Default
|
||||||
|
private Integer readNum = 1;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
@Column(name = "create_time", nullable = false, updatable = false)
|
||||||
|
private Instant createTime;
|
||||||
|
|
||||||
|
@UpdateTimestamp
|
||||||
|
@Column(name = "update_time", nullable = false)
|
||||||
|
private Instant updateTime;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted", nullable = false)
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean isDeleted = false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.hanserwei.common.domain.dataobject;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_article_category_rel",
|
||||||
|
indexes = {
|
||||||
|
@Index(name = "idx_rel_cat_category_id", columnList = "category_id")
|
||||||
|
})
|
||||||
|
public class ArticleCategoryRel implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章ID (Unique)
|
||||||
|
*/
|
||||||
|
@Column(name = "article_id", nullable = false, unique = true)
|
||||||
|
private Long articleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类ID
|
||||||
|
*/
|
||||||
|
@Column(name = "category_id", nullable = false)
|
||||||
|
private Long categoryId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.hanserwei.common.domain.dataobject;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_article_content", indexes = {
|
||||||
|
@Index(name = "idx_article_content_article_id", columnList = "article_id")
|
||||||
|
})
|
||||||
|
public class ArticleContent implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联 Article 的 ID
|
||||||
|
* 这里只存储 ID,不建立对象关联,以实现轻量级操作
|
||||||
|
*/
|
||||||
|
@Column(name = "article_id", nullable = false)
|
||||||
|
private Long articleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正文内容
|
||||||
|
* 映射为 TEXT 类型,支持大文本
|
||||||
|
*/
|
||||||
|
@Column(name = "content", columnDefinition = "TEXT")
|
||||||
|
private String content;
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.hanserwei.common.domain.dataobject;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_article_tag_rel",
|
||||||
|
indexes = {
|
||||||
|
@Index(name = "idx_rel_tag_article_id", columnList = "article_id"),
|
||||||
|
@Index(name = "idx_rel_tag_tag_id", columnList = "tag_id")
|
||||||
|
},
|
||||||
|
uniqueConstraints = {
|
||||||
|
// 对应数据库中的联合唯一约束
|
||||||
|
@UniqueConstraint(name = "uk_article_tag_rel_unique_pair", columnNames = {"article_id", "tag_id"})
|
||||||
|
})
|
||||||
|
public class ArticleTagRel implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章ID
|
||||||
|
*/
|
||||||
|
@Column(name = "article_id", nullable = false)
|
||||||
|
private Long articleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签ID
|
||||||
|
*/
|
||||||
|
@Column(name = "tag_id", nullable = false)
|
||||||
|
private Long tagId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.hanserwei.common.domain.dataobject;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客设置表
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_blog_settings")
|
||||||
|
public class BlogSettings implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客Logo
|
||||||
|
* 数据库类型为 TEXT,Java中映射为 String 即可
|
||||||
|
*/
|
||||||
|
@Column(name = "logo", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String logo = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客名称
|
||||||
|
*/
|
||||||
|
@Column(name = "name", length = 60, nullable = false)
|
||||||
|
@Builder.Default
|
||||||
|
private String name = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作者名
|
||||||
|
*/
|
||||||
|
@Column(name = "author", length = 20, nullable = false)
|
||||||
|
@Builder.Default
|
||||||
|
private String author = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 介绍语
|
||||||
|
*/
|
||||||
|
@Column(name = "introduction", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String introduction = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作者头像
|
||||||
|
*/
|
||||||
|
@Column(name = "avatar", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String avatar = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GitHub 主页访问地址
|
||||||
|
*/
|
||||||
|
@Column(name = "github_homepage", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String githubHomepage = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CSDN 主页访问地址
|
||||||
|
*/
|
||||||
|
@Column(name = "csdn_homepage", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String csdnHomepage = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gitee 主页访问地址
|
||||||
|
*/
|
||||||
|
@Column(name = "gitee_homepage", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String giteeHomepage = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 知乎主页访问地址
|
||||||
|
*/
|
||||||
|
@Column(name = "zhihu_homepage", nullable = false, columnDefinition = "TEXT")
|
||||||
|
@Builder.Default
|
||||||
|
private String zhihuHomepage = "";
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ import java.time.Instant;
|
|||||||
@Index(name = "idx_create_time", columnList = "create_time")
|
@Index(name = "idx_create_time", columnList = "create_time")
|
||||||
})
|
})
|
||||||
@SQLRestriction("is_deleted = false")
|
@SQLRestriction("is_deleted = false")
|
||||||
@SQLDelete(sql = "UPDATE t_category SET is_deleted = true WHERE id = ?")
|
|
||||||
public class Category implements Serializable {
|
public class Category implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.hanserwei.common.domain.dataobject;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.SQLRestriction;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_tag", indexes = {
|
||||||
|
@Index(name = "idx_tag_create_time", columnList = "create_time")
|
||||||
|
})
|
||||||
|
@SQLRestriction("is_deleted = false")
|
||||||
|
public class Tag implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 60, unique = true)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
@Column(name = "create_time", nullable = false, updatable = false)
|
||||||
|
private Instant createTime;
|
||||||
|
|
||||||
|
@UpdateTimestamp
|
||||||
|
@Column(name = "update_time", nullable = false)
|
||||||
|
private Instant updateTime;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted", nullable = false)
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean isDeleted = false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.hanserwei.common.domain.repository;
|
||||||
|
|
||||||
|
import com.hanserwei.common.domain.dataobject.ArticleCategoryRel;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ArticleCategoryRelRepository extends JpaRepository<ArticleCategoryRel, Long> {
|
||||||
|
@Modifying(flushAutomatically = true, clearAutomatically = true)
|
||||||
|
@Query("delete from ArticleCategoryRel acr where acr.articleId = :articleId")
|
||||||
|
void deleteByArticleId(@Param("articleId") Long articleId);
|
||||||
|
|
||||||
|
ArticleCategoryRel findByArticleId(Long articleId);
|
||||||
|
|
||||||
|
List<ArticleCategoryRel> findByCategoryId(Long categoryId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.hanserwei.common.domain.repository;
|
||||||
|
|
||||||
|
import com.hanserwei.common.domain.dataobject.ArticleContent;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface ArticleContentRepository extends JpaRepository<ArticleContent, Long> {
|
||||||
|
ArticleContent findByArticleId(Long articleId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.hanserwei.common.domain.repository;
|
||||||
|
|
||||||
|
import com.hanserwei.common.domain.dataobject.Article;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
public interface ArticleRepository extends JpaRepository<Article, Long>, JpaSpecificationExecutor<Article> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.hanserwei.common.domain.repository;
|
||||||
|
|
||||||
|
import com.hanserwei.common.domain.dataobject.ArticleTagRel;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ArticleTagRelRepository extends JpaRepository<ArticleTagRel, Long> {
|
||||||
|
@Modifying(flushAutomatically = true, clearAutomatically = true)
|
||||||
|
@Query("delete from ArticleTagRel atr where atr.articleId = :articleId")
|
||||||
|
void deleteByArticleId(@Param("articleId") Long articleId);
|
||||||
|
|
||||||
|
List<ArticleTagRel> findByArticleId(Long articleId);
|
||||||
|
|
||||||
|
List<ArticleTagRel> findByTagId(Long tagId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.hanserwei.common.domain.repository;
|
||||||
|
|
||||||
|
import com.hanserwei.common.domain.dataobject.BlogSettings;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface BlogSettingsRepository extends JpaRepository<BlogSettings, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,8 +5,9 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
public interface CategoryRepository extends JpaRepository<Category, Long> {
|
public interface CategoryRepository extends JpaRepository<Category, Long>, JpaSpecificationExecutor<Category> {
|
||||||
boolean existsCategoryByName(String name);
|
boolean existsCategoryByName(String name);
|
||||||
|
|
||||||
Page<Category> findAll(Specification<Category> specification, Pageable pageable);
|
Page<Category> findAll(Specification<Category> specification, Pageable pageable);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.hanserwei.common.domain.repository;
|
||||||
|
|
||||||
|
import com.hanserwei.common.domain.dataobject.Tag;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface TagRepository extends JpaRepository<Tag, Long>, JpaSpecificationExecutor<Tag> {
|
||||||
|
Collection<Tag> findByNameIn(List<String> names);
|
||||||
|
|
||||||
|
Page<Tag> findAll(Specification<Tag> specification, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据标签名称模糊查询
|
||||||
|
* @param name 标签名称关键词
|
||||||
|
* @return 标签列表
|
||||||
|
*/
|
||||||
|
List<Tag> findByNameContaining(String name);
|
||||||
|
|
||||||
|
List<Tag> queryAllByIdIn(Collection<Long> ids);
|
||||||
|
}
|
||||||
@@ -18,8 +18,15 @@ public enum ResponseCodeEnum implements BaseExceptionInterface {
|
|||||||
UNAUTHORIZED("20002", "无访问权限,请先登录!"),
|
UNAUTHORIZED("20002", "无访问权限,请先登录!"),
|
||||||
FORBIDDEN("20004", "演示账号仅支持查询操作!"),
|
FORBIDDEN("20004", "演示账号仅支持查询操作!"),
|
||||||
USER_NOT_EXIST("2005", "有户不存在!"),
|
USER_NOT_EXIST("2005", "有户不存在!"),
|
||||||
CATEGORY_NAME_IS_EXISTED("20005", "该分类已存在,请勿重复添加!")
|
CATEGORY_NAME_IS_EXISTED("20005", "该分类已存在,请勿重复添加!"),
|
||||||
;
|
TAG_NOT_EXIST("20006", "标签不存在!"),
|
||||||
|
CATEGORY_NOT_EXIST("20007", "分类不存在!"),
|
||||||
|
FILE_UPLOAD_FAILED("20008", "上传文件失败!"),
|
||||||
|
CATEGORY_NOT_EXISTED("20009", "提交的分类不存在!"),
|
||||||
|
TAG_NOT_EXISTED("20010", "标签ID不存在或已删除!"),
|
||||||
|
ARTICLE_NOT_EXIST("20011", "文章不存在!"),
|
||||||
|
TAG_HAS_ARTICLE("20012", "该标签有关联文章,无法删除!"),
|
||||||
|
CATEGORY_HAS_ARTICLE("20013","该分类下有关联文章,无法删除!" );
|
||||||
|
|
||||||
// 异常码
|
// 异常码
|
||||||
private final String errorCode;
|
private final String errorCode;
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package com.hanserwei.common.utils;
|
||||||
|
|
||||||
|
import com.hanserwei.common.model.BasePageQuery;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询工具类
|
||||||
|
* 用于抽取通用的分页查询逻辑
|
||||||
|
*/
|
||||||
|
public class PageHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行带条件的分页查询
|
||||||
|
*
|
||||||
|
* @param repository JPA Repository
|
||||||
|
* @param pageQuery 分页查询参数
|
||||||
|
* @param searchText 搜索文本(用于模糊查询)
|
||||||
|
* @param searchField 搜索字段名称(如 "name"、"title" 等)
|
||||||
|
* @param startDate 开始日期
|
||||||
|
* @param endDate 结束日期
|
||||||
|
* @param converter DO 到 VO 的转换函数
|
||||||
|
* @param <T> 实体类型
|
||||||
|
* @param <R> 响应VO类型
|
||||||
|
* @return 分页响应
|
||||||
|
*/
|
||||||
|
public static <T, R> PageResponse<R> findPageList(
|
||||||
|
JpaSpecificationExecutor<T> repository,
|
||||||
|
BasePageQuery pageQuery,
|
||||||
|
String searchText,
|
||||||
|
String searchField,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate,
|
||||||
|
Function<T, R> converter) {
|
||||||
|
|
||||||
|
// 构建分页参数
|
||||||
|
Pageable pageable = PageRequest.of(
|
||||||
|
pageQuery.getCurrent().intValue() - 1,
|
||||||
|
pageQuery.getSize().intValue(),
|
||||||
|
Sort.by(Sort.Direction.DESC, "createTime")
|
||||||
|
);
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
Specification<T> specification = (root, query, criteriaBuilder) -> {
|
||||||
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
|
||||||
|
// 搜索文本模糊查询
|
||||||
|
if (StringUtils.hasText(searchText) && StringUtils.hasText(searchField)) {
|
||||||
|
predicates.add(
|
||||||
|
criteriaBuilder.like(root.get(searchField), "%" + searchText.trim() + "%")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始日期查询
|
||||||
|
if (Objects.nonNull(startDate)) {
|
||||||
|
predicates.add(
|
||||||
|
criteriaBuilder.greaterThanOrEqualTo(root.get("createTime"), startDate)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 结束日期查询
|
||||||
|
if (Objects.nonNull(endDate)) {
|
||||||
|
predicates.add(
|
||||||
|
criteriaBuilder.lessThan(root.get("createTime"), endDate.plusDays(1).atStartOfDay())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||||
|
};
|
||||||
|
|
||||||
|
// 执行查询
|
||||||
|
Page<T> page = repository.findAll(specification, pageable);
|
||||||
|
|
||||||
|
// DO 转 VO
|
||||||
|
List<R> vos = page.getContent().stream()
|
||||||
|
.map(converter)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return PageResponse.success(page, vos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行带条件的分页查询(使用默认字段名 "name")
|
||||||
|
*
|
||||||
|
* @param repository JPA Repository
|
||||||
|
* @param pageQuery 分页查询参数
|
||||||
|
* @param name 名称(用于模糊查询)
|
||||||
|
* @param startDate 开始日期
|
||||||
|
* @param endDate 结束日期
|
||||||
|
* @param converter DO 到 VO 的转换函数
|
||||||
|
* @param <T> 实体类型
|
||||||
|
* @param <R> 响应VO类型
|
||||||
|
* @return 分页响应
|
||||||
|
*/
|
||||||
|
public static <T, R> PageResponse<R> findPageList(
|
||||||
|
JpaSpecificationExecutor<T> repository,
|
||||||
|
BasePageQuery pageQuery,
|
||||||
|
String name,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate,
|
||||||
|
Function<T, R> converter) {
|
||||||
|
return findPageList(repository, pageQuery, name, "name", startDate, endDate, converter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,58 +44,64 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
// 1. 从请求头中获取 Authorization
|
// 1. 从请求头中获取 Authorization
|
||||||
String header = request.getHeader("Authorization");
|
String header = request.getHeader("Authorization");
|
||||||
|
|
||||||
// 2. 校验头格式 (必须以 Bearer 开头)
|
String requestURI = request.getRequestURI();
|
||||||
if (StringUtils.startsWith(header, "Bearer ")) {
|
log.info("Request URI: {}", requestURI);
|
||||||
String token = StringUtils.substring(header, 7);
|
if (requestURI.startsWith("/admin")) {
|
||||||
log.info("JWT Token: {}", token);
|
// 2. 校验头格式 (必须以 Bearer 开头)
|
||||||
if (StringUtils.isNotBlank(token)) {
|
if (header != null && header.startsWith("Bearer ")) {
|
||||||
try {
|
String token = StringUtils.substring(header, 7);
|
||||||
// 3. 解析 Token (核心步骤)
|
log.info("JWT Token: {}", token);
|
||||||
// 注意:JwtTokenHelper.parseToken 方法内部已经处理了 JWT 格式校验和过期校验,
|
if (StringUtils.isNotBlank(token)) {
|
||||||
// 并将 JJWT 异常转换为了 Spring Security 的 AuthenticationException 抛出。
|
try {
|
||||||
Jws<Claims> claimsJws = jwtTokenHelper.parseToken(token);
|
// 3. 解析 Token (核心步骤)
|
||||||
|
// 注意:JwtTokenHelper.parseToken 方法内部已经处理了 JWT 格式校验和过期校验,
|
||||||
|
// 并将 JJWT 异常转换为了 Spring Security 的 AuthenticationException 抛出。
|
||||||
|
Jws<Claims> claimsJws = jwtTokenHelper.parseToken(token);
|
||||||
|
|
||||||
// 4. 获取用户名
|
// 4. 获取用户名
|
||||||
// JJWT 0.12+ 建议使用 getPayload() 替代 getBody()
|
// JJWT 0.12+ 建议使用 getPayload() 替代 getBody()
|
||||||
// 在 Helper 中生成 Token 时使用的是 .subject(username),所以这里取 Subject
|
// 在 Helper 中生成 Token 时使用的是 .subject(username),所以这里取 Subject
|
||||||
String username = claimsJws.getPayload().getSubject();
|
String username = claimsJws.getPayload().getSubject();
|
||||||
|
|
||||||
// 5. 组装认证信息 (如果当前上下文没有认证信息)
|
// 5. 组装认证信息 (如果当前上下文没有认证信息)
|
||||||
if (StringUtils.isNotBlank(username) && Objects.isNull(SecurityContextHolder.getContext().getAuthentication())) {
|
if (StringUtils.isNotBlank(username) && Objects.isNull(SecurityContextHolder.getContext().getAuthentication())) {
|
||||||
|
|
||||||
// 查询数据库获取用户完整信息 (包含权限)
|
// 查询数据库获取用户完整信息 (包含权限)
|
||||||
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
|
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
|
||||||
|
|
||||||
// 构建 Spring Security 的认证 Token
|
// 构建 Spring Security 的认证 Token
|
||||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
|
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
|
||||||
userDetails,
|
userDetails,
|
||||||
null,
|
null,
|
||||||
userDetails.getAuthorities()
|
userDetails.getAuthorities()
|
||||||
);
|
);
|
||||||
|
|
||||||
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
||||||
|
|
||||||
// 6. 将认证信息存入 SecurityContext
|
// 6. 将认证信息存入 SecurityContext
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
|
}
|
||||||
|
} catch (AuthenticationException e) {
|
||||||
|
// 7. 异常处理
|
||||||
|
// 捕获 JwtTokenHelper 抛出的 BadCredentialsException 或 CredentialsExpiredException
|
||||||
|
// 如果 Token 存在但是无效/过期,直接交给 EntryPoint 处理响应 (通常返回 401)
|
||||||
|
// 并 return 结束当前过滤器,不再往下执行
|
||||||
|
authenticationEntryPoint.commence(request, response, e);
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 处理其他未预料到的异常
|
||||||
|
log.error("JWT处理过程中发生未知错误", e);
|
||||||
|
authenticationEntryPoint.commence(request, response, new AuthenticationException("系统内部认证错误") {
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} catch (AuthenticationException e) {
|
|
||||||
// 7. 异常处理
|
|
||||||
// 捕获 JwtTokenHelper 抛出的 BadCredentialsException 或 CredentialsExpiredException
|
|
||||||
// 如果 Token 存在但是无效/过期,直接交给 EntryPoint 处理响应 (通常返回 401)
|
|
||||||
// 并 return 结束当前过滤器,不再往下执行
|
|
||||||
authenticationEntryPoint.commence(request, response, e);
|
|
||||||
return;
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 处理其他未预料到的异常
|
|
||||||
log.error("JWT处理过程中发生未知错误", e);
|
|
||||||
authenticationEntryPoint.commence(request, response, new AuthenticationException("系统内部认证错误") {
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 8. 放行请求 (如果没有 Token 或者 Token 校验通过,继续执行下一个过滤器)
|
// 8. 放行请求 (如果没有 Token 或者 Token 校验通过,继续执行下一个过滤器)
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
|
} else {
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ public class JwtTokenHelper implements InitializingBean {
|
|||||||
*/
|
*/
|
||||||
public String generateToken(String username) {
|
public String generateToken(String username) {
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
Instant expireTime = now.plus(1, ChronoUnit.HOURS);
|
Instant expireTime = now.plus(30, ChronoUnit.DAYS);
|
||||||
|
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.header().add("type", "JWT").and() // 推荐添加 header
|
.header().add("type", "JWT").and() // 推荐添加 header
|
||||||
|
|||||||
Reference in New Issue
Block a user