package cygx

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

type CygxAdvice struct {
	AdviceId      int    `description:"优化建议id"`
	UserId        int    `description:"用户id"`
	UserRealName  string `description:"姓名"`
	CompanyId     int    `description:"公司id"`
	CompanyName   string `description:"公司名称"`
	SalesRealName string `description:"所属销售"`
	Advice        string `description:"优化建议"`
	AdviceImgUrl  string `description:"图片，多张用#分割"`
	CreateTime    string `description:"访谈时间"`
	Mobile        string `description:"手机号"`
	Email         string `description:"邮箱"`
}

type AdviceListResp struct {
	Paging *paging.PagingItem
	List   []*CygxAdvice
}

func GetAdviceListCount(condition string, pars []interface{}) (count int, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT COUNT(1) AS count FROM cygx_advice AS a `
	if condition != "" {
		sql += condition
	}
	err = o.Raw(sql, pars).QueryRow(&count)
	return
}

func GetAdviceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxAdvice, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := ` SELECT a.*  FROM cygx_advice AS a `
	if condition != "" {
		sql += condition
	}
	sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}
