package models

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

type CygxIndustrialActivityGroupSubject struct {
	Id                  int       `orm:"column(id);pk" description:"主键ID"`
	ActivityId          int       `description:"活动ID"`
	IndustrialSubjectId int       `description:"cygx_industrial_subject表的文章ID"`
	Source              int       `description:"来源，1 活动，2专项调研"`
	CreateTime          time.Time `description:"创建时间"`
}

type SubjectActivityGroupManagementRep struct {
	IndustrialSubjectId int    `description:"产业id"`
	SubjectName         string `description:"标的名称"`
	ActivityId          int    `description:"活动ID"`
}

// GetCygxIndustrialActivityGroupSubjectList 获取列表
func GetCygxIndustrialActivityGroupSubjectList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupSubject, err error) {
	sql := `SELECT
			*
			FROM
			cygx_industrial_activity_group_subject
			WHERE
				1 = 1 `
	if condition != `` {
		sql += condition
	}
	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
	return
}

// 列表
func GetSubjectActivityGroupManagementListByActivityId(activityId int) (items []*SubjectActivityGroupManagementRep, err error) {
	o := orm.NewOrm()
	sql := `SELECT
			s.subject_name
			FROM
			cygx_industrial_subject  AS s
			INNER JOIN cygx_industrial_activity_group_subject AS ag ON s.industrial_subject_id = ag.industrial_subject_id 
			WHERE
			ag.activity_id = ?  AND   ag.source = 1  `
	_, err = o.Raw(sql, activityId).QueryRows(&items)
	return
}

// 列表
func GetSubjectActivityGroupManagementListByActivityIds(activityId []int) (items []*SubjectActivityGroupManagementRep, err error) {
	o := orm.NewOrm()
	sql := `SELECT
			s.subject_name,ag.activity_id
			FROM
			    cygx_industrial_activity_group_subject  AS ag
			INNER JOIN cygx_industrial_subject  AS s  ON s.industrial_subject_id = ag.industrial_subject_id 
			WHERE
			ag.activity_id  IN  (` + utils.GetOrmInReplace(len(activityId)) + `)  AND   ag.source = 1  `
	_, err = o.Raw(sql, activityId).QueryRows(&items)
	return
}
