package cygx

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

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

func GetProductInteriorIndustrialGroupManagementList(productInteriorId int) (items []*IndustrialActivityGroupManagementRep, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT
			m.chart_permission_id,
			m.industrial_management_id,
			m.industry_name 
			FROM
			cygx_product_interior_industrial_group_management AS am
			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
			WHERE
			am.product_interior_id = ? `
	_, err = o.Raw(sql, productInteriorId).QueryRows(&items)
	return
}

type IndustrialProductInteriorGroupResp struct {
	ProductInteriorId      int    `description:"产品内测"`
	IndustrialManagementId int    `description:"cygx_industrial_management表的主键ID"`
	IndustryName           string `description:"产业名称"`
}

// 列表
func GetProductInteriorIndustrialGroupManagement(condition string, pars []interface{}) (items []*IndustrialProductInteriorGroupResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT  mg.*,m.industry_name  FROM
	        cygx_product_interior_industrial_group_management AS mg
	      	 INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
			WHERE 1 = 1  ` + condition + `	 GROUP BY  mg.product_interior_id,mg.industrial_management_id`
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}
