节点运行日志可以按照节点ID设置为已读

This commit is contained in:
刘祥超
2022-08-25 18:26:52 +08:00
parent f4f5389ffb
commit 4cb9c85a1c
2 changed files with 25 additions and 5 deletions

View File

@@ -342,8 +342,8 @@ func (this *NodeLogDAO) CountAllUnreadNodeLogs(tx *dbs.Tx) (int64, error) {
Count()
}
// UpdateNodeLogsRead 设置日志为已读
func (this *NodeLogDAO) UpdateNodeLogsRead(tx *dbs.Tx, nodeLogIds []int64) error {
// UpdateNodeLogIdsRead 设置一组日志为已读
func (this *NodeLogDAO) UpdateNodeLogIdsRead(tx *dbs.Tx, nodeLogIds []int64) error {
for _, logId := range nodeLogIds {
err := this.Query(tx).
Pk(logId).
@@ -356,6 +356,16 @@ func (this *NodeLogDAO) UpdateNodeLogsRead(tx *dbs.Tx, nodeLogIds []int64) error
return nil
}
// UpdateNodeLogsRead 设置节点日志为已读
func (this *NodeLogDAO) UpdateNodeLogsRead(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64) error {
return this.Query(tx).
Attr("role", role).
Attr("nodeId", nodeId).
Attr("isRead", false).
Set("isRead", true).
UpdateQuickly()
}
// UpdateAllNodeLogsRead 设置所有日志为已读
func (this *NodeLogDAO) UpdateAllNodeLogsRead(tx *dbs.Tx) error {
return this.Query(tx).

View File

@@ -148,10 +148,20 @@ func (this *NodeLogService) UpdateNodeLogsRead(ctx context.Context, req *pb.Upda
}
var tx = this.NullTx()
err = models.SharedNodeLogDAO.UpdateNodeLogsRead(tx, req.NodeLogIds)
if err != nil {
return nil, err
if len(req.NodeLogIds) > 0 {
err = models.SharedNodeLogDAO.UpdateNodeLogIdsRead(tx, req.NodeLogIds)
if err != nil {
return nil, err
}
}
if req.NodeId > 0 && len(req.Role) > 0 {
err = models.SharedNodeLogDAO.UpdateNodeLogsRead(tx, req.Role, req.NodeId)
if err != nil {
return nil, err
}
}
return this.Success()
}