fix: ne_state table issue

This commit is contained in:
2024-04-29 18:11:33 +08:00
parent 1b531a8c01
commit a1d12bd0f3
2 changed files with 25 additions and 6 deletions

View File

@@ -1453,6 +1453,15 @@ func XormDeleteDataByWhere(where, table string) (int64, error) {
return affected, nil
}
func XormDeleteDataByWhereNoSession(where, table string) (int64, error) {
affected, err := DbClient.XEngine.Table(table).Where(where).Delete()
if err != nil {
log.Error("Failed to Delete:", err)
return 0, err
}
return affected, nil
}
func XormDeleteDataById(id int, table string) (int64, error) {
log.Debug("XormDeleteDataByWhere processing... ")

View File

@@ -25,8 +25,9 @@ type BarProcessor struct {
type BarParams struct {
Duration int `json:"duration"`
TableName string `json:"tableName"`
ColName string `json:"colName"` // column name of time string
Extras string `json:"extras"` // extras condition for where
ColName string `json:"colName"` // column name of time string
Extras string `json:"extras"` // extras condition for where
SessFlag bool `json:"sessFlag"` // session flag, true: session model, false: no session
}
func (s *BarProcessor) Execute(data any) (any, error) {
@@ -74,10 +75,19 @@ func (s *BarProcessor) Execute(data any) (any, error) {
where = fmt.Sprintf("NOW()>ADDDATE(`%s`,interval %d day) and %s", params.ColName, params.Duration, params.Extras)
}
affected, err := dborm.XormDeleteDataByWhere(where, params.TableName)
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
return nil, err
var affected int64 = 0
if params.SessFlag {
affected, err = dborm.XormDeleteDataByWhere(where, params.TableName)
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
return nil, err
}
} else {
affected, err = dborm.XormDeleteDataByWhereNoSession(where, params.TableName)
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
return nil, err
}
}
// 返回结果,用于记录执行结果