package contract

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

type ContractTemplate struct {
	ContractTemplateId int       `orm:"column(contract_template_id);pk"`
	ProductId          int       `description:"产品id"`
	Title              string    `description:"标题"`
	Url                string    `description:"模板地址"`
	Html               string    `description:"html模板"`
	PdfHtml            string    `description:"生成pdf的html模板"`
	WordConfig         string    `description:"生成word的json配置"`
	ContentConfig      string    `description:"合同中一些特定区域的文字展示配置;json格式"`
	CreateTime         time.Time `description:"创建时间"`
}

func GetContractTemplateMapByProductId(productId int) (items []*ContractTemplate, err error) {
	var condition string
	pars := make([]interface{}, 0)
	if productId > 0 {
		condition += `AND product_id = ? `
		pars = append(pars, productId)
	}
	o := orm.NewOrm()
	sql := ` SELECT * FROM contract_template WHERE 1=1 `
	sql += condition
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}

//根据模板id获取模板信息
func GetContractTemplateByTemplateId(templateId int) (item *ContractTemplate, err error) {
	o := orm.NewOrm()
	sql := ` SELECT * FROM contract_template WHERE contract_template_id=? `
	err = o.Raw(sql, templateId).QueryRow(&item)
	return
}