package roadshow

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

type RsCalendarMeetingUserResp struct {
	RsCalendarMeetingUserId int    `description:"参会名单主键ID"`
	RealName                string `description:"用户实际名称"`
	Position                string `description:"职位"`
}

type RsCalendarMeetingUser struct {
	RsCalendarMeetingUserId int       `orm:"column(rs_calendar_meeting_user_id);pk" description:"主键ID"`
	RsCalendarId            int       `description:"日程ID"`
	UserId                  int       `description:"用户ID"`
	Mobile                  string    `description:"手机号"`
	Email                   string    `description:"邮箱"`
	CompanyId               int       `description:"公司ID"`
	CompanyName             string    `description:"公司名称"`
	RealName                string    `description:"用户实际名称"`
	Position                string    `description:"职位"`
	AdminId                 int       `description:"管理员ID"`
	AdminName               string    `description:"管理员姓名"`
	StartDate               string    `description:"开始日期"`
	EndDate                 string    `description:"结束日期"`
	StartTime               string    `description:"开始时间"`
	EndTime                 string    `description:"结束时间"`
	CreateTime              time.Time `description:"结束时间"`
}

// 列表
func GetRsCalendarMeetingUserList(condition string, pars []interface{}) (items []*RsCalendarMeetingUser, err error) {
	o := orm.NewOrmUsingDB("weekly_report")
	sql := `SELECT
    		art.rs_calendar_id,
			art.user_id,
			art.real_name,
			art.mobile,
			art.email,
			art.company_id,
			art.company_name,
			rs.start_time,
			rs.start_date
	FROM rs_calendar_meeting_user as  art 
         inner join  rs_calendar_researcher as  rs ON rs.rs_calendar_id = art.rs_calendar_id
         WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}

type RsCalendarResearcher struct {
	RsCalendarResearcherId int    `orm:"column(rs_calendar_researcher_id);pk"`
	RsCalendarId           int    `description:"日历活动id"`
	ResearcherId           int    `description:"研究员id"`
	ResearcherName         string `description:"研究员名称"`
	StartDate              string `description:"开始日期"`
	EndDate                string `description:"结束日期"`
	StartTime              string `description:"开始时间"`
	EndTime                string `description:"结束时间"`
	StartWeek              string `description:"开始日期对应周"`
	EndWeek                string `description:"结束日期对应周"`
	CreateTime             time.Time
	ModifyTime             time.Time
	Status                 int       `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
	RefuseReason           string    `description:"拒绝理由"`
	RefuseTime             time.Time `description:"拒绝时间"`
	DeleteReason           string    `description:"删除理由"`
	DeleteTime             time.Time `description:"删除时间"`
	ApproveTime            time.Time `description:"接受时间"`
	IsSynced               int       `description:"是否与上海同步 0:未同步 1:已同步"`
	ResearcherSort         int       `description:"研究员新增排序"`
	UnionCode              string    `description:"公开会议联合编码"`
}

// 根据多个路演ID获取研究员信息
func GetRsCalendarResearcherListByIds(rsCalendarIds []int) (item []*RsCalendarResearcher, err error) {
	if len(rsCalendarIds) == 0 {
		return
	}
	o := orm.NewOrmUsingDB("weekly_report")
	sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id IN (` + utils.GetOrmInReplace(len(rsCalendarIds)) + `) `
	_, err = o.Raw(sql, rsCalendarIds).QueryRows(&item)
	return
}
