Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复部分 bug #39

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions configure/initializer/2024.01.1/infosphere.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,23 @@ CREATE TABLE `infosphere_tag_article_relation`
`article_id` BIGINT,
`tag_id` BIGINT
) COMMENT '标签与文章关系表';

CREATE TABLE `infosphere_article_like`
(
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`ip_address` VARCHAR(255),
`user_agent` VARCHAR(255),
`create_time` DATETIME
) COMMENT '文章点赞表';

CREATE TABLE `infosphere_article_like_article_relation`
(
`like_id` BIGINT,
`article_id` BIGINT
) COMMENT '文章点赞和文章关联表';

CREATE TABLE `infosphere_article_like_user_relation`
(
`like_id` BIGINT,
`user_id` BIGINT
) COMMENT '文章点赞和用户关联表';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="layout/common/common-header::common-header(${response.data.title}, ${response.data.title})"></head>
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<div th:include="layout/common/common-navigation::common-navigation(${response.data})"></div>
Expand All @@ -21,4 +20,5 @@
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:if="${response}" th:include="layout/common/common-header::common-header('编辑文章', '编辑文章')"></head>
<head th:else th:include="layout/common/common-header::common-header('写文章', '写文章')"></head>
<div th:include="layout/common/common-script::common-script"></div>
<head th:unless="${response}" th:include="layout/common/common-header::common-header('写文章', '写文章')"></head>
<div th:include="layout/editor/md-editor-script::md-editor-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<div th:include="layout/common/common-navigation::common-navigation(null)"></div>
Expand Down Expand Up @@ -66,10 +66,12 @@
<label class="col-sm-3 col-form-label form-control-label">文章标签</label>
<div class="col-sm-9">
<div th:each="tag, index : ${tags}" class="custom-control custom-radio custom-control-inline">
<input th:id="${tag.name}" th:value="${tag.id}" th:checked="${#lists.contains(response.data?.tags.![id], tag.id)}" name="tag"
<input th:id="${tag.name}" th:value="${tag.id}"
th:checked="${response?.data?.tags != null ? #lists.contains(response.data.tags.![id], tag.id) : false}" name="tag"
class="custom-control-input" type="checkbox">
<label th:text="${tag.name}" th:for="${tag.name}" class="custom-control-label"></label>
</div>

</div>
</div>
</div>
Expand All @@ -84,7 +86,7 @@
</div>
</div>
</body>
</div>
<div th:include="layout/common/common-script::common-script"></div>
<script th:inline="javascript">
/*<![CDATA[*/
$('.btn-publish').click(function () {
Expand Down
5 changes: 1 addition & 4 deletions core/infosphere-server/src/main/resources/viewer/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<!-- 引入 header -->
<head th:include="layout/common/common-header::common-header('首页', '首页')"></head>
<!-- 引入 script 脚本 -->
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<!-- 引入 navigation 菜单栏 -->
<div th:include="layout/common/common-navigation::common-navigation(null)"></div>
<div class="main-content row position-relative pb-5">
<div class="col-xl-9 docs-content pb-5">
Expand All @@ -17,4 +13,5 @@
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="layout/common/common-header::common-header('我的文章', '我的文章')"></head>
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<!-- 引入 navigation 菜单栏 -->
Expand All @@ -15,4 +14,5 @@
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="layout/common/common-header::common-header('最热文章', '最热文章')"></head>
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<!-- 引入 navigation 菜单栏 -->
<div th:include="layout/common/common-navigation::common-navigation(null)"></div>
<div class="main-content row position-relative pb-5">
<div class="col-xl-9 docs-content pb-5">
Expand All @@ -15,4 +13,5 @@
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="layout/common/common-header::common-header('推荐文章', '推荐文章')"></head>
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<!-- 引入 navigation 菜单栏 -->
Expand All @@ -15,4 +14,5 @@
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
<!-- 基本信息 -->
<div class="col-md-8">
<div th:text="${#dates.format(details.createTime,'yyyy年MM月dd日 HH:mm:ss')} + ' 发布'"></div>
<div th:if="${details.published}">
<div th:text="${'阅读数: ' + details.viewCount}"></div>
<div class="actions">
<a th:if="${details.published}" class="action-item" data-toggle="tooltip" data-placement="top" title="点赞数">
<i data-feather="heart" style="margin-top: -3px;"></i>
<span th:text="${details.likeCount}"></span>
</a>
<a th:if="${details.published}" class="action-item ml-2" data-toggle="tooltip" data-placement="top" title="阅读数">
<i data-feather="eye" style="margin-top: -3px;"></i>
<span th:text="${details.viewCount}"></span>
</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<script th:src="@{/static/js/entity/user.js}"></script>
<script th:src="@{/static/js/entity/article.js}"></script>

<!-- 第三方依赖 -->
<script th:src="@{/static/js/common/popover.js}"></script>
<script th:src="@{/static/js/common/tooltip.js}"></script>

<!-- 通知组件 -->
<div th:include="layout/common/common-notify::common-notify"></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div th:fragment="md-editor-script">
<link rel="stylesheet" th:href="@{/static/css/vender/editor-md/editor.min.css}">

<script th:src="@{/static/js/vender/jquery/jquery.min.js}"></script>
<script th:src="@{/static/js/vender/editor-md/editor.min.js}"></script>
<script th:src="@{/static/js/entity/editor.js}"></script>
<script th:src="@{/static/js/entity/editor-config.js}"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<div th:fragment="md-editor(content, spaces, tags, types)">
<div th:include="layout/editor/md-editor-script::md-editor-script"></div>
<div id="infosphere-editor"></div>
<script th:inline="javascript">
/*<![CDATA[*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,42 @@
<span class="badge badge-danger badge-pill">警告</span>
<span class="alert-content">暂无数据,请注册用户或登录发表文章。</span>
</div>
<div th:else th:each="article, index : ${response}" class="card shadow-none mt-3">
<div class="p-3 d-flex">
<div class="icon icon-shape rounded-circle text-white mr-4">
<img th:if="${article.user.avatar}" class="avatar rounded-circle avatar-sm" th:src="${article.user.avatar}" th:alt="${article.user.avatar}"/>
<span th:unless="${article.user.avatar}" th:text="${article.user.username.substring(0, 2)}" class="avatar bg-primary text-white rounded-circle avatar-sm"></span>
<div th:unless="${response.size() == 0}" th:each="article, index : ${response}" class="shadow-none mt-3">
<div class="card hover-shadow-lg">
<div class="card-body py-4">
<small th:text="${article.createTime}" class="d-block text-sm mb-2"></small>
<a th:target="_blank" th:href="@{'/viewer/article/' + ${article.code}}" th:text="${article.title}" class="h5 lh-150"></a>
<p th:text="${#strings.length(article.content) > 200 ? article.content.substring(0, 200) + '...' : article.content}" class="mt-3 mb-0 lh-170"></p>
</div>
<div class="col-sm-10">
<span class="h6">
<a th:target="_blank" th:href="@{'/viewer/article/' + ${article.code}}" th:text="${article.title}"></a>
</span>
<div class="text-sm text-muted mb-0 p-2" th:text="${#strings.length(article.content) > 200 ? article.content.substring(0, 200) + '...' : article.content}"></div>
<div class="infosphere-example pb-0 pb-b0" style="border-bottom: 0 solid #e2e8f0;">
<div class="tab-example-result pb-0">
<a th:each="tag, index : ${article.tags}" th:text="${tag.name}" th:href="@{'/viewer/tag/' + ${tag.code}}" class="badge badge-primary"></a>
<div class="card-footer border-0 delimiter-top">
<div class="row align-items-center">
<div class="col-auto">
<span class="avatar avatar-sm bg-primary rounded-circle">
<img th:if="${article.user.avatar}" class="avatar rounded-circle avatar-sm" th:src="${article.user.avatar}" th:alt="${article.user.avatar}"/>
<span th:unless="${article.user.avatar}" th:text="${article.user.username.substring(0, 2)}"
class="avatar bg-primary text-white rounded-circle avatar-sm"></span>
</span>
<span th:text="${article.user.username}" class="text-sm mb-0 avatar-content"></span>
</div>
<div class="infosphere-example pb-0 pb-b0" style="border-bottom: 0 solid #e2e8f0;">
<div class="tab-example-result pb-0">
<a th:each="tag, index : ${article.tags}" th:text="${tag.name}" th:href="@{'/viewer/tag/' + ${tag.code}}" class="badge badge-primary"></a>
</div>
</div>
<div class="col text-right text-right">
<div class="actions">
<a th:if="${article.published}" class="action-item" data-toggle="tooltip" data-placement="top" title="点赞数">
<i data-feather="heart" style="margin-top: -3px;"></i>
<span th:text="${article.likeCount}"></span>
</a>
<a th:if="${article.published}" class="action-item ml-2" data-toggle="tooltip" data-placement="top" title="阅读数">
<i data-feather="eye" style="margin-top: -3px;"></i>
<span th:text="${article.viewCount}"></span>
</a>
</div>
</div>
</div>
</div>
<div th:if="${article.published}">
<div th:text="${'阅读数: ' + article.viewCount}"></div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="layout/common/common-header::common-header('标签', '标签')"></head>
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<div th:include="layout/common/common-navigation::common-navigation(null)"></div>
Expand Down Expand Up @@ -49,4 +48,5 @@
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="layout/common/common-header::common-header(${tag.name}, ${tag.name})"></head>
<div th:include="layout/common/common-script::common-script"></div>
<body class="docs loader">
<div class="container-fluid container-docs">
<div th:include="layout/common/common-navigation::common-navigation(null)"></div>
Expand All @@ -16,4 +15,5 @@ <h6 th:text="${'以下是 [' + tag.name + '] 相关的文章'}"></h6>
</div>
</div>
</body>
<div th:include="layout/common/common-script::common-script"></div>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ public class ArticleEntity
"LEFT JOIN infosphere_article_access_article_relation aar ON aar.article_id = aa.id " +
"WHERE aa.id = id)")
private Long viewCount;

@Formula(value = "(SELECT COUNT(al.id) " +
"FROM infosphere_article_like al " +
"LEFT JOIN infosphere_article_access_article_relation aar ON aar.article_id = al.id " +
"WHERE al.id = id)")
private Long likeCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.devlive.infosphere.service.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import java.time.Instant;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "infosphere_article_like")
@EntityListeners(value = AuditingEntityListener.class)
public class ArticleLikeEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "ip_address")
private String address;

@Column(name = "user_agent")
private String agent;

@Column(name = "create_time")
@CreatedDate
private Instant createTime;

@ManyToOne
@JoinTable(name = "infosphere_article_like_article_relation",
joinColumns = @JoinColumn(name = "like_id"),
inverseJoinColumns = @JoinColumn(name = "article_id"))
private ArticleEntity article;

@ManyToOne
@JoinTable(name = "infosphere_article_like_user_relation",
joinColumns = @JoinColumn(name = "like_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
private UserEntity user;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface ArticleRepository
@Query("SELECT a " +
"FROM ArticleEntity a " +
"JOIN a.tags t " +
"WHERE t IN :tags")
"WHERE t IN :tags " +
"AND a.published = true ")
Page<ArticleEntity> findAllByTags(@Param("tags") Set<TagEntity> tags, Pageable pageable);
}
Loading