logarchivelistlogic.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Code scaffolded by goctl. Safe to edit.
  2. // goctl 1.10.2
  3. package systemlog
  4. import (
  5. "context"
  6. "udeServer/internal/apierr"
  7. "udeServer/internal/log"
  8. udeModel "udeServer/internal/model"
  9. "udeServer/internal/svc"
  10. "udeServer/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type LogArchiveListLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. // 归档列表
  19. func NewLogArchiveListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogArchiveListLogic {
  20. return &LogArchiveListLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. // LogArchiveList pages the archive records with optional filters.
  27. func (l *LogArchiveListLogic) LogArchiveList(req *types.LogArchiveListReq) (*types.LogArchiveListResp, error) {
  28. page, pageSize := normalizePage(req.Page, req.PageSize)
  29. f := udeModel.LogArchiveFilter{
  30. ArchiveName: req.ArchiveName,
  31. ArchivedBy: req.ArchivedBy,
  32. ArchivedStartTime: req.ArchivedStartTime,
  33. ArchivedEndTime: req.ArchivedEndTime,
  34. }
  35. list, total, err := l.svcCtx.LogArchiveRecordModel.FindPage(l.ctx, page, pageSize, f)
  36. if err != nil {
  37. log.RecordError(l.ctx, err)
  38. return nil, apierr.New(500, "查询归档分页列表失败")
  39. }
  40. logArchives := make([]types.LogArchive, len(list))
  41. for i := range list {
  42. logArchives[i] = ConvertToLogArchive(&list[i])
  43. }
  44. return &types.LogArchiveListResp{
  45. Total: total,
  46. LogArchives: logArchives,
  47. }, nil
  48. }