mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 04:50:25 +08:00
节点日志增加是否已读标记
This commit is contained in:
@@ -75,6 +75,7 @@ func (this *NodeLogDAO) CreateLog(tx *dbs.Tx, nodeRole nodeconfigs.NodeRole, nod
|
|||||||
op.Day = timeutil.FormatTime("Ymd", createdAt)
|
op.Day = timeutil.FormatTime("Ymd", createdAt)
|
||||||
op.Hash = hash
|
op.Hash = hash
|
||||||
op.Count = 1
|
op.Count = 1
|
||||||
|
op.IsRead = !(level == "error" || level == "warning")
|
||||||
err = this.Save(tx, op)
|
err = this.Save(tx, op)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -94,9 +95,20 @@ func (this *NodeLogDAO) DeleteExpiredLogs(tx *dbs.Tx, days int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountNodeLogs 计算节点日志数量
|
// CountNodeLogs 计算节点日志数量
|
||||||
func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx, role string, nodeId int64, serverId int64, originId int64, dayFrom string, dayTo string, keyword string, level string) (int64, error) {
|
func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx,
|
||||||
query := this.Query(tx).
|
role string,
|
||||||
Attr("role", role)
|
nodeId int64,
|
||||||
|
serverId int64,
|
||||||
|
originId int64,
|
||||||
|
dayFrom string,
|
||||||
|
dayTo string,
|
||||||
|
keyword string,
|
||||||
|
level string,
|
||||||
|
isUnread bool) (int64, error) {
|
||||||
|
query := this.Query(tx)
|
||||||
|
if len(role) > 0 {
|
||||||
|
query.Attr("role", role)
|
||||||
|
}
|
||||||
if nodeId > 0 {
|
if nodeId > 0 {
|
||||||
query.Attr("nodeId", nodeId)
|
query.Attr("nodeId", nodeId)
|
||||||
} else {
|
} else {
|
||||||
@@ -128,6 +140,9 @@ func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx, role string, nodeId int64, ser
|
|||||||
if len(level) > 0 {
|
if len(level) > 0 {
|
||||||
query.Attr("level", level)
|
query.Attr("level", level)
|
||||||
}
|
}
|
||||||
|
if isUnread {
|
||||||
|
query.Attr("isRead", 0)
|
||||||
|
}
|
||||||
|
|
||||||
return query.Count()
|
return query.Count()
|
||||||
}
|
}
|
||||||
@@ -144,10 +159,13 @@ func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx,
|
|||||||
keyword string,
|
keyword string,
|
||||||
level string,
|
level string,
|
||||||
fixedState configutils.BoolState,
|
fixedState configutils.BoolState,
|
||||||
|
isUnread bool,
|
||||||
offset int64,
|
offset int64,
|
||||||
size int64) (result []*NodeLog, err error) {
|
size int64) (result []*NodeLog, err error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx)
|
||||||
Attr("role", role)
|
if len(role) > 0 {
|
||||||
|
query.Attr("role", role)
|
||||||
|
}
|
||||||
if nodeId > 0 {
|
if nodeId > 0 {
|
||||||
query.Attr("nodeId", nodeId)
|
query.Attr("nodeId", nodeId)
|
||||||
} else {
|
} else {
|
||||||
@@ -186,6 +204,9 @@ func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx,
|
|||||||
if len(level) > 0 {
|
if len(level) > 0 {
|
||||||
query.Attr("level", level)
|
query.Attr("level", level)
|
||||||
}
|
}
|
||||||
|
if isUnread {
|
||||||
|
query.Attr("isRead", 0)
|
||||||
|
}
|
||||||
_, err = query.
|
_, err = query.
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Limit(size).
|
Limit(size).
|
||||||
@@ -224,3 +245,24 @@ func (this *NodeLogDAO) UpdateNodeLogFixed(tx *dbs.Tx, logId int64) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllUnreadNodeLogs 计算未读的日志数量
|
||||||
|
func (this *NodeLogDAO) CountAllUnreadNodeLogs(tx *dbs.Tx) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Attr("isRead", false).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeLogsRead 设置日志为已读
|
||||||
|
func (this *NodeLogDAO) UpdateNodeLogsRead(tx *dbs.Tx, nodeLogIds []int64) error {
|
||||||
|
for _, logId := range nodeLogIds {
|
||||||
|
err := this.Query(tx).
|
||||||
|
Pk(logId).
|
||||||
|
Set("isRead", true).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type NodeLog struct {
|
|||||||
Hash string `field:"hash"` // 信息内容Hash
|
Hash string `field:"hash"` // 信息内容Hash
|
||||||
Count uint32 `field:"count"` // 重复次数
|
Count uint32 `field:"count"` // 重复次数
|
||||||
IsFixed uint8 `field:"isFixed"` // 是否已处理
|
IsFixed uint8 `field:"isFixed"` // 是否已处理
|
||||||
|
IsRead uint8 `field:"isRead"` // 是否已读
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeLogOperator struct {
|
type NodeLogOperator struct {
|
||||||
@@ -31,6 +32,7 @@ type NodeLogOperator struct {
|
|||||||
Hash interface{} // 信息内容Hash
|
Hash interface{} // 信息内容Hash
|
||||||
Count interface{} // 重复次数
|
Count interface{} // 重复次数
|
||||||
IsFixed interface{} // 是否已处理
|
IsFixed interface{} // 是否已处理
|
||||||
|
IsRead interface{} // 是否已读
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeLogOperator() *NodeLogOperator {
|
func NewNodeLogOperator() *NodeLogOperator {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (this *NodeLogService) CountNodeLogs(ctx context.Context, req *pb.CountNode
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
count, err := models.SharedNodeLogDAO.CountNodeLogs(tx, req.Role, req.NodeId, req.ServerId, req.OriginId, req.DayFrom, req.DayTo, req.Keyword, req.Level)
|
count, err := models.SharedNodeLogDAO.CountNodeLogs(tx, req.Role, req.NodeId, req.ServerId, req.OriginId, req.DayFrom, req.DayTo, req.Keyword, req.Level, req.IsUnread)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ func (this *NodeLogService) ListNodeLogs(ctx context.Context, req *pb.ListNodeLo
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
logs, err := models.SharedNodeLogDAO.ListNodeLogs(tx, req.Role, req.NodeId, req.ServerId, req.OriginId, req.AllServers, req.DayFrom, req.DayTo, req.Keyword, req.Level, types.Int8(req.FixedState), req.Offset, req.Size)
|
logs, err := models.SharedNodeLogDAO.ListNodeLogs(tx, req.Role, req.NodeId, req.ServerId, req.OriginId, req.AllServers, req.DayFrom, req.DayTo, req.Keyword, req.Level, types.Int8(req.FixedState), req.IsUnread, req.Offset, req.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -105,3 +105,33 @@ func (this *NodeLogService) FixNodeLog(ctx context.Context, req *pb.FixNodeLogRe
|
|||||||
|
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllUnreadNodeLogs 计算未读的日志数量
|
||||||
|
func (this *NodeLogService) CountAllUnreadNodeLogs(ctx context.Context, req *pb.CountAllUnreadNodeLogsRequest) (*pb.RPCCountResponse, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
count, err := models.SharedNodeLogDAO.CountAllUnreadNodeLogs(tx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.SuccessCount(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeLogsRead 设置日志为已读
|
||||||
|
func (this *NodeLogService) UpdateNodeLogsRead(ctx context.Context, req *pb.UpdateNodeLogsReadRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
err = models.SharedNodeLogDAO.UpdateNodeLogsRead(tx, req.NodeLogIds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user