package day_new

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// 企业微信群消息拉取日志表
type WeworkMsgLog struct {
	Id         uint64    `orm:"column(id);pk;auto" description:"自增ID"`
	Seq        uint64    `orm:"column(seq)" description:"本次请求获取消息记录开始的seq值。首次访问填写0"`
	Limit      int       `orm:"column(limit)" description:"一次调用限制的limit值，不能超过1000"`
	Total      int       `orm:"column(total)" description:"实际拉取到的消息数"`
	ReqResult  int8      `orm:"column(req_result)" description:"请求结果：1成功，2失败"`
	CreateTime time.Time `orm:"column(create_time)" description:"创建时间"`
	ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
}
func (w *WeworkMsgLog) TableName() string {
	return "wework_msg_log"
}

// AddMsgReqLog 新增调用记录
func AddMsgReqLog(item *WeworkMsgLog) (err error) {
	o := orm.NewOrm()
	_, err = o.Insert(item)
	return
}

// GetLasReqLog 获取最近一次成功调用记录
func GetLasReqLog() (item *WeworkMsgLog, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM wework_msg_log WHERE req_result = 1 order by id desc`
	err = o.Raw(sql).QueryRow(&item)
	return
}

