package cygx

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

type CygxActivityMeetingHistory struct {
	Id           int       `orm:"column(id);pk"`
	ActivityId   int       `description:"活动ID "`
	StopTime     int       `description:"停留时间 "`
	AdminId      int       `description:"销售/管理员ID"`
	RealName     string    `description:"销售/管理员姓名"`
	CreateTime   time.Time `description:"创建时间"`
	RoleTypeCode string    `description:"角色编码"`
}

type CygxActivityMeetingHistoryAddReq struct {
	ActivityId int `description:"活动ID "`
	StopTime   int `description:"停留时间 "`
}

type CygxActivityMeetingHistoryResp struct {
	Id         int    `orm:"column(id);pk"`
	ActivityId int    `description:"活动ID "`
	AdminId    int    `description:"销售/管理员ID"`
	RealName   string `description:"销售/管理员姓名"`
	StopTime   int    `description:"停留时间 "`
	CreateTime string `description:"创建时间"`
}

type CygxActivityMeetingHistoryListResp struct {
	List []*CygxActivityMeetingHistoryResp
}

// 新增
func AddCygxActivityMeetingHistory(item *CygxActivityMeetingHistory) (err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	_, err = o.Insert(item)
	return
}

// 获取列表
func GetCygxActivityMeetingHistoryLlist(activityId int) (items []*CygxActivityMeetingHistoryResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := ` SELECT * FROM cygx_activity_meeting_history WHERE  activity_id=  ? AND  role_type_code IN ('rai_seller','rai_group')   ORDER BY id DESC   `
	_, err = o.Raw(sql, activityId).QueryRows(&items)
	return
}

// 获取最新详情
func GetCygxActivityMeetingHistoryNew(activityId, adminId int) (item *CygxActivityMeetingHistory, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_activity_meeting_history  WHERE activity_id=? AND admin_id = ? ORDER BY id DESC LIMIT 1 `
	err = o.Raw(sql, activityId, adminId).QueryRow(&item)
	return
}

// 更新阅读时间
func UpdateActivityMeetingHistoryTime(stipTime, id int) (err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := ` UPDATE cygx_activity_meeting_history SET  stop_time=?   WHERE id=?`
	_, err = o.Raw(sql, stipTime, id).Exec()
	return
}
