package cygx

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

type CygxRaiServeCompany struct {
	ServeCompanyId    int       `comment:"ServeCompanyId 主键ID"`
	CompanyId         int       `comment:"公司ID"`
	CompanyName       string    `comment:"公司名称"`
	CreateTime        time.Time `comment:"创建时间"`
	Money             float64   `comment:"合同金额"`
	ServeCoverageRate string    `comment:"近四周服务覆盖率"`
	SellerId          int       `comment:"所属销售id"`
	SellerName        string    `comment:"所属销售名称"`
	StartDate         string    `comment:"开始日期"`
	EndDate           string    `comment:"结束日期"`
	ShareSeller       string    `comment:"共享销售"`
	ShareSellerId     int       `comment:"共享销售员id"`
	Status            string    `comment:"客户状态"`
	PermissionName    string    `comment:"权限名"`
	IsUserMaker       int       `comment:"近四周之内是否包含决策人"`
}

type CygxRaiServeCompanyResp struct {
	CompanyId         int     `comment:"公司ID"`
	CompanyName       string  `comment:"公司名称"`
	IsUserMaker       int     `description:"近四周之内是否包含决策人互动过 ，0否，1是"`
	Money             float64 `comment:"合同金额"`
	ServeCoverageRate string  `comment:"近四周服务覆盖率"`
	SellerId          int     `comment:"所属销售id"`
	SellerName        string  `comment:"所属销售名称"`
	StartDate         string  `comment:"开始日期"`
	EndDate           string  `comment:"结束日期"`
	ShareSeller       string  `comment:"共享销售"`
	ShareSellerId     int     `comment:"共享销售员id"`
	Status            string  `comment:"客户状态"`
	PermissionName    string  `comment:"权限名"`
	ThisWeekAmount    float64 `comment:"本周互动量"`
	LastWeekAmount    float64 `comment:"上周互动量"`
	TwoWeekAmount     float64 `comment:"上上周互动量"`
	ThreeWeekAmount   float64 `comment:"上三周互动量"`
}

type CygxRaiServeCompanyListResp struct {
	Paging *paging.PagingItem `description:"分页数据"`
	List   []*CygxRaiServeCompanyResp
}

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

// 列表
func GetCygxRaiServeCompanyList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxRaiServeCompany, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_rai_serve_company as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	sql += ` LIMIT ?,?`
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}
