package cygx

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

// 报名
type CygxActivityOfflineMeetingDetail struct {
	Id          int       `orm:"column(id);pk"`
	UserId      int       `description:"用户id"`
	ActivityId  int       `description:"活动ID"`
	CreateTime  time.Time `description:"创建时间"`
	Mobile      string    `description:"手机号"`
	Email       string    `description:"邮箱号"`
	CompanyId   int       `description:"公司ID"`
	CompanyName string    `description:"公司名称"`
	IsMeeting   int       `description:"是否到会  1.是 ，0否"`
	IsAirborne  int       `description:"是否属于空降  1.是 ，0否"`
	SigninTime  string    `description:"签到时间"`
}

// 预约外呼列表
func GetOfflineMeetingList(condition string) (items []*CygxActivitySignupList, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT s.* ,
			( SELECT COUNT( 1 ) FROM cygx_activity_signup AS a WHERE a.activity_id = s.activity_id AND a.user_id = s.user_id AND a.do_fail_type = 0 ) AS channel
			FROM cygx_activity_offline_meeting_detail  as s 
			 WHERE 1 =1 ` + condition
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

// 预约外呼列表
func GetOfflineMeetingListByUser(meetingUids string, activityId int) (items []*CygxActivityOfflineMeetingDetail, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT s.* FROM cygx_activity_offline_meeting_detail  as s  WHERE activity_id = ? AND user_id IN  (` + meetingUids + `)`
	_, err = o.Raw(sql, activityId).QueryRows(&items)
	return
}

// 预约外呼列表
func GetOfflineMeetingListByYidong(condition string) (items []*CygxActivitySignupList, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := ` SELECT * FROM cygx_activity_signup as s  WHERE  1= 1 AND s.yidong_examine_status != 2 ` + condition
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

func GetOfflineMeetingDetailListCompanyIdStr(companyIdStr string) (item []*CygxActivityMeetDetailLog, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_activity_offline_meeting_detail WHERE company_id IN (` + companyIdStr + `)`
	_, err = o.Raw(sql).QueryRows(&item)
	return
}
