package yb

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

// PriceDriven 价格驱动表
type PriceDriven struct {
	PriceDrivenId int `orm:"column(price_driven_id);pk" description:"价格驱动ID"`
	//ChartPermissionId   int       `json:"chart_permission_id" description:"品种权限ID"`
	VarietyTagId        int       `json:"variety_tag_id" description:"标签ID"`
	VarietyTagName      string    `json:"variety_tag_name" description:"标签名称"`
	MainVariable        string    `json:"main_variable" description:"关键变量"`
	CoreDrivenType      int       `json:"core_driven_type" description:"核心驱动类型 0-多 1-空"`
	CoreDrivenContent   string    `json:"core_driven_content" description:"核心驱动内容"`
	CoreContent         string    `json:"core_content" description:"核心内容"`
	LastUpdateAdminId   int       `json:"last_update_admin_id" description:"最后更新人ID"`
	LastUpdateAdminName string    `json:"last_update_admin_name" description:"最后更新人名称"`
	ThsMsgState         int       `json:"ths_msg_state" description:"同花顺推送状态:0-未推送 1-已推送"`
	TemplateMsgState    int       `json:"template_msg_state" description:"模板消息推送状态:0-未推送 1-已推送"`
	PublishState        int       `json:"publish_state" description:"发布状态:0-未发布 1-已发布"`
	SendThsMsgTime      time.Time `json:"last_ths_msg_time" description:"最后推送同花顺客群消息时间"`
	SendTemplateMsgTime time.Time `json:"last_template_msg_time" description:"最后推送模板消息时间"`
	CreateTime          time.Time `json:"create_time" description:"创建时间"`
	ModifyTime          time.Time `json:"modify_time" description:"更新时间"`
}

// TableName 表名变更
func (priceDrivenInfo *PriceDriven) TableName() string {
	return "yb_price_driven"
}

// Add 新增
func (priceDrivenInfo *PriceDriven) Add() (err error) {
	o := orm.NewOrmUsingDB("weekly")
	id, err := o.Insert(priceDrivenInfo)
	if err != nil {
		return
	}
	priceDrivenInfo.PriceDrivenId = int(id)
	return
}

// Update 更新
func (priceDrivenInfo *PriceDriven) Update(cols []string) (err error) {
	o := orm.NewOrmUsingDB("weekly")
	_, err = o.Update(priceDrivenInfo, cols...)
	return
}

// PriceDrivenSaveLog 价格驱动保存记录表
type PriceDrivenSaveLog struct {
	Id            int `orm:"column(id);pk"`
	PriceDrivenId int `json:"price_driven_id" description:"价格驱动ID"`
	//ChartPermissionId int       `json:"chart_permission_id" description:"品种权限ID"`
	VarietyTagId      int       `json:"variety_tag_id" description:"标签ID"`
	MainVariable      string    `json:"main_variable" description:"关键变量"`
	CoreDrivenType    int       `json:"core_driven_type" description:"核心驱动类型 0-多 1-空"`
	CoreDrivenContent string    `json:"core_driven_content" description:"核心驱动内容"`
	CoreContent       string    `json:"core_content" description:"核心内容"`
	AdminId           int       `json:"admin_id" description:"更新人ID"`
	AdminName         string    `json:"admin_name" description:"更新人名称"`
	CreateTime        time.Time `json:"create_time" description:"创建时间"`
}

// TableName 表名变更
func (priceDrivenSaveLogInfo *PriceDrivenSaveLog) TableName() string {
	return "yb_price_driven_save_log"
}

// Add 新增保存记录
func (priceDrivenSaveLogInfo *PriceDrivenSaveLog) Add() (err error) {
	o := orm.NewOrmUsingDB("weekly")
	lastId, err := o.Insert(priceDrivenSaveLogInfo)
	if err != nil {
		return
	}
	priceDrivenSaveLogInfo.PriceDrivenId = int(lastId)
	return
}