mirror of https://github.com/halo-dev/halo
complete list latest logs service
parent
5a1327ade7
commit
00d0670ac6
|
@ -0,0 +1,46 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import cc.ryanc.halo.model.entity.Log;
|
||||
import cc.ryanc.halo.model.enums.LogType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class LogOutputDTO implements OutputConverter<LogOutputDTO, Log> {
|
||||
|
||||
/**
|
||||
* Log id.
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 日志标识
|
||||
*/
|
||||
private String logKey;
|
||||
|
||||
/**
|
||||
* 日志事件类型
|
||||
*/
|
||||
private LogType type;
|
||||
|
||||
/**
|
||||
* 日志内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 操作 IP
|
||||
*/
|
||||
private String ipAddress;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
private Date createTime;
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.dto.LogOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Log;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* Log service.
|
||||
|
@ -10,4 +12,11 @@ import cc.ryanc.halo.service.base.CrudService;
|
|||
*/
|
||||
public interface LogService extends CrudService<Log, Long> {
|
||||
|
||||
/**
|
||||
* Lists latest logs.
|
||||
*
|
||||
* @param top top number must not be less than 0
|
||||
* @return a page of latest logs
|
||||
*/
|
||||
Page<LogOutputDTO> listLatest(int top);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.dto.LogOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Log;
|
||||
import cc.ryanc.halo.repository.LogRepository;
|
||||
import cc.ryanc.halo.service.LogService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* LogService implementation class
|
||||
|
@ -21,4 +26,15 @@ public class LogServiceImpl extends AbstractCrudService<Log, Long> implements Lo
|
|||
super(logRepository);
|
||||
this.logRepository = logRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<LogOutputDTO> listLatest(int top) {
|
||||
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||
|
||||
// Build page request
|
||||
PageRequest latestPageable = PageRequest.of(0, top, Sort.by(Sort.Direction.DESC, "createTime"));
|
||||
|
||||
// List all
|
||||
return listAll(latestPageable).map(log -> new LogOutputDTO().convertFrom(log));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.admin;
|
|||
import cc.ryanc.halo.model.dto.PostSimpleOutputDTO;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.LogService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -26,12 +27,16 @@ public class AdminController {
|
|||
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
private final LogService logService;
|
||||
|
||||
public AdminController(PostService postService,
|
||||
CommentService commentService,
|
||||
AttachmentService attachmentService) {
|
||||
AttachmentService attachmentService,
|
||||
LogService logService) {
|
||||
this.postService = postService;
|
||||
this.commentService = commentService;
|
||||
this.attachmentService = attachmentService;
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +55,7 @@ public class AdminController {
|
|||
model.addAttribute("attachmentsCount", attachmentService.count());
|
||||
|
||||
model.addAttribute("latestPosts", postPage.getContent());
|
||||
model.addAttribute("latestLogs", logService.listLatest(10).getContent());
|
||||
return "admin/admin_index";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue