package models

import (
	"time"

	"github.com/beego/beego/v2/client/orm"
)

type UserChangeRecord struct {
	UserChangeRecordId int       `orm:"pk" description:"id"`
	UserId             int       `description:"用户id"`
	SysUserId          int       `description:"系统用户id"`
	Content            string    `description:"内容"`
	CreateTime         time.Time `description:"创建时间"`
}

func (u *UserChangeRecord) Insert() (err error) {
	u.CreateTime = time.Now()
	o := orm.NewOrm()
	_, err = o.Insert(u)
	return
}
func UserChangeRecordMultiInsert(list []*UserChangeRecord) (err error) {
	o := orm.NewOrm()
	_, err = o.InsertMulti(500, list)
	return
}

func GetUserChangeRecordListById(userId int) (items []*UserChangeRecord, err error) {
	sql := `SELECT * FROM user_change_record WHERE user_id=? ORDER BY create_time DESC `
	o := orm.NewOrm()
	_, err = o.Raw(sql, userId).QueryRows(&items)
	return
}

func GetUserChangeRecordCount() (count int, err error) {
	sql := `SELECT COUNT(*) AS count FROM user_change_record `
	o := orm.NewOrm()
	err = o.Raw(sql).QueryRow(&count)
	return
}
