mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-25 06:26:35 +08:00
记录和显示最近常用的集群
This commit is contained in:
51
internal/db/models/latest_item_dao.go
Normal file
51
internal/db/models/latest_item_dao.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LatestItemType = string
|
||||
|
||||
const (
|
||||
LatestItemTypeCluster LatestItemType = "cluster"
|
||||
LatestItemTypeServer LatestItemType = "server"
|
||||
)
|
||||
|
||||
type LatestItemDAO dbs.DAO
|
||||
|
||||
func NewLatestItemDAO() *LatestItemDAO {
|
||||
return dbs.NewDAO(&LatestItemDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeLatestItems",
|
||||
Model: new(LatestItem),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*LatestItemDAO)
|
||||
}
|
||||
|
||||
var SharedLatestItemDAO *LatestItemDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedLatestItemDAO = NewLatestItemDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// IncreaseItemCount 增加数量
|
||||
func (this *LatestItemDAO) IncreaseItemCount(tx *dbs.Tx, itemType LatestItemType, itemId int64) error {
|
||||
return this.Query(tx).
|
||||
InsertOrUpdateQuickly(maps.Map{
|
||||
"itemType": itemType,
|
||||
"itemId": itemId,
|
||||
"count": 1,
|
||||
"updatedAt": time.Now().Unix(),
|
||||
}, maps.Map{
|
||||
"count": dbs.SQL("count+1"),
|
||||
"updatedAt": time.Now().Unix(),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user