package cygx

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

type CygxReportSelectionLogApplyResp struct {
	ReportSelectionLogApplyId int `orm:"column(report_selection_log_apply_id);pk"`
	UserId                    int
	CreateTime                string
	Mobile                    string `description:"手机号"`
	Email                     string `description:"邮箱"`
	CompanyId                 int    `description:"公司id"`
	CompanyName               string `description:"公司名称"`
	RealName                  string `description:"用户实际名称"`
	SellerName                string `description:"所属销售"`
	RegisterPlatform          int    `description:"来源 1小程序,2:网页"`
	ArticleId                 int    `description:"报告Id"`
	IndustrialSubjectId       int    `description:"标的ID"`
	SubjectName               string `description:"标的名称"`
}

type CygxReportSelectionLogApplyListResp struct {
	List []*CygxReportSelectionLogApplyResp
}

// 获取数量
func GetCygxReportSelectionLogApplyCount(condition string, pars []interface{}) (count int, err error) {
	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_report_selection_log_apply as art WHERE 1= 1  `
	if condition != "" {
		sqlCount += condition
	}
	o := orm.NewOrmUsingDB("hz_cygx")
	err = o.Raw(sqlCount, pars).QueryRow(&count)
	return
}

// 列表
func GetCygxReportSelectionLogApplyRespList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportSelectionLogApplyResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_report_selection_log_apply as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}

	if startSize+pageSize > 0 {
		sql += ` LIMIT ?,?  `
		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	} else {
		_, err = o.Raw(sql, pars).QueryRows(&items)
	}

	return
}