package cygx

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

type CygxProductInteriorIndustrialGroupSubject struct {
	Id                  int       `orm:"column(id);pk" description:"主键ID"`
	ProductInteriorId   int       `description:"产品内测"`
	IndustrialSubjectId int       `description:"cygx_industrial_subject表的文章ID"`
	CreateTime          time.Time `description:"创建时间"`
}

// 列表
func GetProductInteriorIndustrialGroupSubjecttList(productInteriorId int) (items []*SubjectActivityGroupManagementRep, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT
			s.subject_name,
			s.industrial_subject_id 
			FROM
			cygx_product_interior_industrial_group_subject AS ag
			INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id 
			WHERE
			ag.product_interior_id = ?`
	_, err = o.Raw(sql, productInteriorId).QueryRows(&items)
	return
}

type SubjectlProductInteriorGroupResp struct {
	ProductInteriorId      int    `description:"产品内测ID"`
	IndustrialManagementId int    `description:"cygx_industrial_management表的主键ID"`
	IndustrialSubjectId    int    `description:"标的id"`
	SubjectName            string `description:"标的名称"`
}

//type IndustrialProductInteriorGroupResp struct {
//	ProductInteriorId             int    `description:"活动ID"`
//	IndustrialManagementId int    `description:"cygx_industrial_management表的主键ID"`
//	IndustrialSubjectId    int    `description:"标的id"`
//	SubjectName            string `description:"标的名称"`
//}

// 列表
func GetProductInteriorIndustrialGroupSubjectt(condition string, pars []interface{}) (items []*SubjectlProductInteriorGroupResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT
			sg.*,
			s.subject_name,
			s.industrial_management_id 
		FROM
			cygx_product_interior_industrial_group_subject AS sg
			INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id 
		WHERE
			1 = 1 ` + condition + `  GROUP BY sg.product_interior_id,sg.industrial_subject_id`
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}
