mirror of https://github.com/halo-dev/halo
Add additional counts to return
parent
943d8f0865
commit
4b6887acd9
|
@ -11,11 +11,17 @@ import lombok.Data;
|
|||
@Data
|
||||
public class CountOutputDTO {
|
||||
|
||||
private Long postCount;
|
||||
private long postCount;
|
||||
|
||||
private Long commentCount;
|
||||
private long commentCount;
|
||||
|
||||
private Long attachmentCount;
|
||||
private long attachmentCount;
|
||||
|
||||
private Long establishDays;
|
||||
private long establishDays;
|
||||
|
||||
private long linkCount;
|
||||
|
||||
private long visitCount;
|
||||
|
||||
private long likeCount;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import javax.persistence.Entity;
|
|||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
@Entity(name = "journal")
|
||||
@Entity(name = "Journal")
|
||||
@Where(clause = "deleted = false")
|
||||
@SQLDelete(sql = "update posts set deleted = true where id = ?")
|
||||
@DiscriminatorValue("2")
|
||||
|
|
|
@ -12,7 +12,7 @@ import javax.persistence.Entity;
|
|||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
@Entity(name = "page")
|
||||
@Entity(name = "Page")
|
||||
@Where(clause = "deleted = false")
|
||||
@SQLDelete(sql = "update posts set deleted = true where id = ?")
|
||||
@DiscriminatorValue("1")
|
||||
|
|
|
@ -11,7 +11,7 @@ import javax.persistence.Entity;
|
|||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Entity(name = "post")
|
||||
@Entity(name = "Post")
|
||||
@SQLDelete(sql = "update posts set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
@DiscriminatorValue(value = "0")
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.repository;
|
|||
import cc.ryanc.halo.model.entity.Post;
|
||||
import cc.ryanc.halo.repository.base.BasePostRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -13,4 +14,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||
*/
|
||||
public interface PostRepository extends BasePostRepository<Post>, JpaSpecificationExecutor<Post> {
|
||||
|
||||
@Query("select sum(p.visits) from Post p")
|
||||
Long countVisit();
|
||||
|
||||
@Query("select sum(p.likes) from Post p")
|
||||
Long countLike();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import cc.ryanc.halo.model.dto.post.PostMinimalOutputDTO;
|
|||
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Post;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.vo.PostDetailVO;
|
||||
import cc.ryanc.halo.model.vo.PostListVO;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
@ -131,4 +130,18 @@ public interface PostService extends CrudService<Post, Integer> {
|
|||
*/
|
||||
@NonNull
|
||||
PostDetailVO getDetailVoBy(@NonNull Integer postId);
|
||||
|
||||
/**
|
||||
* Counts visit total number.
|
||||
*
|
||||
* @return visit total number
|
||||
*/
|
||||
long countVisit();
|
||||
|
||||
/**
|
||||
* Counts like total number.
|
||||
*
|
||||
* @return like total number
|
||||
*/
|
||||
long countLike();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import cc.ryanc.halo.model.dto.post.PostMinimalOutputDTO;
|
|||
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.*;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.vo.PostDetailVO;
|
||||
import cc.ryanc.halo.model.vo.PostListVO;
|
||||
import cc.ryanc.halo.repository.PostRepository;
|
||||
|
@ -244,6 +243,16 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
return convertTo(post);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countVisit() {
|
||||
return Optional.ofNullable(postRepository.countVisit()).orElse(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countLike() {
|
||||
return Optional.ofNullable(postRepository.countLike()).orElse(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Post removeById(Integer postId) {
|
||||
|
@ -254,7 +263,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
// Remove post tags
|
||||
List<PostTag> postTags = postTagService.removeByPostId(postId);
|
||||
|
||||
log.debug("Removd post tags: [{}]", postTags);
|
||||
log.debug("Removed post tags: [{}]", postTags);
|
||||
|
||||
// Remove post categories
|
||||
List<PostCategory> postCategories = postCategoryService.removeByPostId(postId);
|
||||
|
|
|
@ -38,16 +38,20 @@ public class AdminController {
|
|||
|
||||
private final UserService userService;
|
||||
|
||||
private final LinkService linkService;
|
||||
|
||||
public AdminController(PostService postService,
|
||||
AttachmentService attachmentService,
|
||||
CommentService commentService,
|
||||
OptionService optionService,
|
||||
UserService userService) {
|
||||
UserService userService,
|
||||
LinkService linkService) {
|
||||
this.postService = postService;
|
||||
this.attachmentService = attachmentService;
|
||||
this.commentService = commentService;
|
||||
this.optionService = optionService;
|
||||
this.userService = userService;
|
||||
this.linkService = linkService;
|
||||
}
|
||||
|
||||
@GetMapping("counts")
|
||||
|
@ -58,6 +62,9 @@ public class AdminController {
|
|||
countOutputDTO.setAttachmentCount(attachmentService.count());
|
||||
countOutputDTO.setCommentCount(commentService.count());
|
||||
countOutputDTO.setEstablishDays(Long.valueOf(optionService.getByProperty(BlogProperties.WIDGET_DAYCOUNT).orElse("0")));
|
||||
countOutputDTO.setLinkCount(linkService.count());
|
||||
countOutputDTO.setVisitCount(postService.countVisit());
|
||||
countOutputDTO.setLikeCount(postService.countLike());
|
||||
return countOutputDTO;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue