package models
|
|
import (
|
"basic.com/valib/logc.git"
|
"errors"
|
"gorm.io/gorm"
|
"time"
|
)
|
|
type RuleServerLog logc.RuleServerLog
|
|
type RuleServerLogQuery struct {
|
TimeStart string `json:"timeStart" example:"2020-01-02 15:04:05"` // 开始时间,不传为结束时间前一个小时
|
TimeEnd string `json:"timeEnd" example:"2020-01-02 16:00:00"` // 结束时间,不传为当前时间
|
TaskName string `json:"taskName" example:"pollcontrol"` // 任务名字
|
State string `json:"state" example:"state"` // 状态
|
FuzzySearch string `json:"fuzzySearch" example:"hasfkll-12348nzsf2-1248njzlsud"` // 模糊查询
|
Page int `json:"page" example:"2"` // 操作结果
|
PageSize int `json:"pageSize" example:"10"` // 分页大小
|
}
|
|
func (RuleServerLog) TableName() string {
|
return "t_rule_server_log"
|
}
|
|
func (a *RuleServerLog) Insert() error {
|
var count int64 = 0
|
result := db.Table(a.TableName()).Where("id=?", a.ID).Count(&count)
|
if count > 0 {
|
err := db.Table(a.TableName()).Where("id=?", a.ID).Update("state", a.State).Error
|
return err
|
}
|
|
result = db.Table(a.TableName()).Create(&a)
|
|
return result.Error
|
}
|
|
func (a *RuleServerLog) TotalSuccessIncrement() error {
|
var count int64 = 0
|
db.Table(a.TableName()).Where("id=?", a.ID).Count(&count)
|
if count > 0 {
|
return db.Table(a.TableName()).Where("id=?", a.ID).Update("totalSuccess", gorm.Expr("totalSuccess + 1")).Update("lastSendDate", time.Now().Format("2006-01-02 15:04:05")).Error
|
}
|
|
return errors.New("record not found")
|
}
|
|
func (a *RuleServerLog) TotalFailureIncrement() error {
|
var count int64 = 0
|
db.Table(a.TableName()).Where("id=?", a.ID).Count(&count)
|
if count > 0 {
|
return db.Table(a.TableName()).Where("id=?", a.ID).Update("totalFailure", gorm.Expr("totalFailure + 1")).Update("lastSendDate", time.Now().Format("2006-01-02 15:04:05")).Error
|
}
|
return errors.New("record not found")
|
}
|
|
func (a *RuleServerLog) TotalCachedSet() error {
|
var count int64 = 0
|
db.Table(a.TableName()).Where("id=?", a.ID).Count(&count)
|
if count > 0 {
|
return db.Table(a.TableName()).Where("id=?", a.ID).Update("totalCached", a.TotalCached).Update("lastSendDate", time.Now().Format("2006-01-02 15:04:05")).Error
|
}
|
return errors.New("record not found")
|
}
|
|
func (a *RuleServerLog) LastStateSet() error {
|
var count int64 = 0
|
db.Table(a.TableName()).Where("id=?", a.ID).Count(&count)
|
if count > 0 {
|
return db.Table(a.TableName()).Where("id=?", a.ID).Update("lastSendState", a.LastSendState).Update("lastSendDate", time.Now().Format("2006-01-02 15:04:05")).Error
|
}
|
|
return errors.New("record not found")
|
}
|
|
func (a *RuleServerLog) ReduceFailure() error {
|
var count int64 = 0
|
db.Table(a.TableName()).Where("id=?", a.ID).Count(&count)
|
if count > 0 {
|
return db.Table(a.TableName()).Where("id=?", a.ID).Update("totalFailure", gorm.Expr("totalFailure - 1")).Update("totalSuccess", gorm.Expr("totalSuccess + 1")).Update("lastSendDate", time.Now().Format("2006-01-02 15:04:05")).Error
|
}
|
|
return errors.New("record not found")
|
}
|