chance_revise_log.go 2.0 KB
package models

import (
	"encoding/json"
	"time"

	"github.com/astaxie/beego/orm"
)

type ChanceReviseLog struct {
	Id             int64     `orm:"column(id);pk" description:"id 主键"`
	ChanceId       int64     `orm:"column(chance_id)" description:"机会编号"`
	UserCompanyId  int64     `orm:"column(user_company_id);null" description:"用户编号 编辑机会的人"`
	Data           string    `orm:"column(data);null" description:"机会数据"`
	CreateAt       time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
	AuditFlowLogId int64     `orm:"column(audit_flow_log_id);null" description:"表audit_flow_log.id "`
}

func (t *ChanceReviseLog) TableName() string {
	return "chance_revise_log"
}

func init() {
	orm.RegisterModel(new(ChanceReviseLog))
}

type ReviseContentsItem struct {
	Content string `json:"content"`
}

type ChanceReviseLogData struct {
	ReviseContents []ReviseContentsItem `json:"reviseContents"`
	Speechs        []ChanceDataSpeechs  `json:"speechs"`
	Pictures       []ChanceDataImage    `json:"pictures"`
	Videos         []ChanceDataVideos   `json:"videos"`
}

// GetChanceReviseLogById retrieves ChanceReviseLog by Id. Returns error if
// Id doesn't exist
func GetChanceReviseLogById(id int64) (v *ChanceReviseLog, err error) {
	o := orm.NewOrm()
	v = &ChanceReviseLog{Id: id}
	if err = o.Read(v); err == nil {
		return v, nil
	}
	return nil, err
}

func GetChanceReviseLogData(flowLogId int64) (*ChanceReviseLog, *ChanceReviseLogData, error) {
	o := orm.NewOrm()
	var (
		err error
	)
	reviseLog := &ChanceReviseLog{}
	err = o.QueryTable(&ChanceReviseLog{}).
		Filter("audit_flow_log_id", flowLogId).
		One(reviseLog)
	if err != nil {
		return nil, nil, err
	}
	reviseLogData := &ChanceReviseLogData{
		ReviseContents: make([]ReviseContentsItem, 0),
		Speechs:        make([]ChanceDataSpeechs, 0),
		Pictures:       make([]ChanceDataImage, 0),
		Videos:         make([]ChanceDataVideos, 0),
	}
	json.Unmarshal([]byte(reviseLog.Data), reviseLogData)
	return reviseLog, reviseLogData, err
}