1、导出增加时间段
This commit is contained in:
@ -4,12 +4,15 @@ import (
|
|||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MmAlarmLogGetPageReq struct {
|
type MmAlarmLogGetPageReq struct {
|
||||||
dto.Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
MachineId string `form:"machineId" search:"type:exact;column:machine_id;table:mm_alarm_log" comment:"设备id"`
|
MachineId string `form:"machineId" search:"type:exact;column:machine_id;table:mm_alarm_log" comment:"设备id"`
|
||||||
BiosId string `form:"biosId" search:"type:exact;column:bios_id;table:mm_alarm_log" comment:"设备码"`
|
BiosId string `form:"biosId" search:"type:exact;column:bios_id;table:mm_alarm_log" comment:"设备码"`
|
||||||
|
StartTime time.Time `form:"startTime" search:"-" comment:"开始时间"`
|
||||||
|
EndTime time.Time `form:"endTime" search:"-" comment:"结束时间"`
|
||||||
MmAlarmLogOrder
|
MmAlarmLogOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,4 +98,5 @@ type MmAlarmLogExportResp struct {
|
|||||||
MachineId string `json:"machineId" comment:"设备id" excel:"设备id"`
|
MachineId string `json:"machineId" comment:"设备id" excel:"设备id"`
|
||||||
BiosId string `json:"biosId" comment:"设备码" excel:"设备码"`
|
BiosId string `json:"biosId" comment:"设备码" excel:"设备码"`
|
||||||
Content string `json:"content" comment:"内容" excel:"内容"`
|
Content string `json:"content" comment:"内容" excel:"内容"`
|
||||||
|
CreatedAt string `json:"createdAt" comment:"创建时间" excel:"时间"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,9 +28,17 @@ func (e MmAlarmLog) Export(req *dto.MmAlarmLogGetPageReq, c *gin.Context) error
|
|||||||
query = query.Where("machine_id = ?", req.MachineId)
|
query = query.Where("machine_id = ?", req.MachineId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !req.StartTime.IsZero() {
|
||||||
|
query = query.Where("created_at >= ?", req.StartTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !req.EndTime.IsZero() {
|
||||||
|
query = query.Where("created_at < ?", req.EndTime.AddDate(0, 0, 1))
|
||||||
|
}
|
||||||
|
|
||||||
err := query.
|
err := query.
|
||||||
Select("machine_id, bios_id, content").
|
Select("machine_id, bios_id, content,created_at").
|
||||||
Distinct().
|
Order("id desc").
|
||||||
Find(&datas).
|
Find(&datas).
|
||||||
Error
|
Error
|
||||||
|
|
||||||
@ -44,6 +52,7 @@ func (e MmAlarmLog) Export(req *dto.MmAlarmLogGetPageReq, c *gin.Context) error
|
|||||||
MachineId: data.MachineId,
|
MachineId: data.MachineId,
|
||||||
BiosId: data.BiosId,
|
BiosId: data.BiosId,
|
||||||
Content: data.Content,
|
Content: data.Content,
|
||||||
|
CreatedAt: data.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +73,22 @@ func (e *MmAlarmLog) GetPage(c *dto.MmAlarmLogGetPageReq, p *actions.DataPermiss
|
|||||||
var err error
|
var err error
|
||||||
var data models.MmAlarmLog
|
var data models.MmAlarmLog
|
||||||
|
|
||||||
err = e.Orm.Model(&data).
|
query := e.Orm.Model(&data).
|
||||||
Scopes(
|
Scopes(
|
||||||
cDto.MakeCondition(c.GetNeedSearch()),
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
actions.Permission(data.TableName(), p),
|
actions.Permission(data.TableName(), p),
|
||||||
).
|
)
|
||||||
|
|
||||||
|
if !c.StartTime.IsZero() {
|
||||||
|
query = query.Where("created_at >= ?", c.StartTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.EndTime.IsZero() {
|
||||||
|
query = query.Where("created_at < ?", c.EndTime.AddDate(0, 0, 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = query.
|
||||||
Find(list).Limit(-1).Offset(-1).
|
Find(list).Limit(-1).Offset(-1).
|
||||||
Count(count).Error
|
Count(count).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user