cutego/modules/core/dao/log_dao.go

52 lines
1.2 KiB
Go
Raw Normal View History

2022-03-13 16:02:24 +08:00
package dao
import (
2023-01-18 15:40:27 +08:00
"cutego/modules/core/api/v1/request"
2023-01-18 17:21:12 +08:00
"cutego/modules/core/dataobject"
2022-03-13 16:02:24 +08:00
"cutego/pkg/common"
"cutego/pkg/page"
2023-01-18 17:09:49 +08:00
"cutego/refs"
2022-03-13 16:02:24 +08:00
"github.com/druidcaesa/gotool"
"github.com/go-xorm/xorm"
)
type LogDao struct {
}
func (d LogDao) sql(session *xorm.Session) *xorm.Session {
return session.Table("sys_log")
}
// SelectPage 分页查询数据
2023-01-18 17:21:12 +08:00
func (d LogDao) SelectPage(query request.LogQuery) ([]dataobject.SysLog, int64) {
configs := make([]dataobject.SysLog, 0)
2023-01-18 17:09:49 +08:00
session := d.sql(refs.SqlDB.NewSession())
2022-03-13 16:02:24 +08:00
if gotool.StrUtils.HasNotEmpty(query.Content) {
session.And("content like concat('%', ?, '%')", query.Content)
}
if gotool.StrUtils.HasNotEmpty(query.Uid) {
session.And("uid = ?", query.Uid)
}
total, _ := page.GetTotal(session.Clone())
err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).Find(&configs)
if err != nil {
common.ErrorLog(err)
return nil, 0
}
return configs, total
}
// Insert 添加数据
2023-01-18 17:21:12 +08:00
func (d LogDao) Insert(config dataobject.SysLog) int64 {
2023-01-18 17:09:49 +08:00
session := refs.SqlDB.NewSession()
2022-03-13 16:02:24 +08:00
session.Begin()
insert, err := session.Insert(&config)
if err != nil {
common.ErrorLog(err)
session.Rollback()
return 0
}
session.Commit()
return insert
}