package company_report_permission

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

type CompanyReportPermission struct {
	CompanyReportPermissionId int64 `orm:"column(company_report_permission_id);pk"`
	CompanyId                 int
	ReportPermissionId        int
	CreatedTime               time.Time
	LastUpdatedTime           time.Time
	ChartPermissionId         int
	StartDate                 string    `description:"权限开始日期"`
	EndDate                   string    `description:"权限结束日期"`
	ProductId                 int       `description:"产品id"`
	ProductName               string    `description:"产品名称"`
	CompanyContractId         int       `description:"合同id"`
	Status                    string    `description:"'正式','试用','关闭'"`
	ModifyTime                time.Time `description:"修改时间"`
}

// GetPermissionListByCompanyIdAndProductId 根据客户id和产品id获取可用的权限列表
func GetPermissionListByCompanyIdAndProductId(companyId, productId int) (items []*CompanyReportPermission, err error) {
	sql := ` select * from company_report_permission where company_id=? and product_id =? and status in ("试用","正式","永续") `
	o := orm.NewOrm()
	_, err = o.Raw(sql, companyId, productId).QueryRows(&items)
	return
}
