package models

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

type CygxXzsChooseCategoryZhouqi struct {
	Id          int       `orm:"column(id);pk"`
	UserId      int       `description:"用户ID"`
	Mobile      string    `description:"手机号"`
	Email       string    `description:"邮箱"`
	CompanyId   int       `description:"公司id"`
	CompanyName string    `description:"公司名称"`
	RealName    string    `description:"用户实际名称"`
	CategoryId  int       `description:"cygx_zhouqi_article_map 表主键"`
	CreateTime  time.Time `description:"创建时间"`
	ModifyTime  time.Time `description:"更新时间"`
	FollowType  int       `description:"1,重点关注，3不感兴趣，0默认接受推送"`
}

// 根据手机号获取用户关注的产业
func GetCygxXzsChooseCategoryZhouqiList(mobile string) (items []*CygxXzsChooseCategoryZhouqi, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_xzs_choose_category_zhouqi WHERE mobile = ?`
	_, err = o.Raw(sql, mobile).QueryRows(&items)
	return
}

// 列表
func GetCygxXzsChooseCategoryZhouqiListFollowType(categoryName, seriesName string, followType int) (items []*CygxXzsChooseCategoryZhouqi, err error) {
	o := orm.NewOrm()
	sql := `SELECT
	f.* 
FROM
	cygx_zhouqi_article_map AS m
	INNER JOIN cygx_xzs_choose_category_zhouqi AS f ON f.category_id = m.category_id 
WHERE
	1 = 1 
	AND ( m.match_type_name = ? OR m.series_name = ? ) 
	AND follow_type = ?  `
	_, err = o.Raw(sql, categoryName, seriesName, followType).QueryRows(&items)
	return
}
