package eta_trial

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

// QuestionnaireFillRecord 问卷填写记录表
type QuestionnaireFillRecord struct {
	RecordId   int    `orm:"column(fill_record_id);pk" description:"记录id"`
	Mobile     string `description:"手机"`
	IsFill     int    `description:"0未点过 1稍后再填 2已填写"`
	CreateTime time.Time
	ModifyTime time.Time
}

// GetQuestionnaireFillRecordCountByMobile 手机号获取问卷填写记录
func GetQuestionnaireFillRecordCountByMobile(mobile string) (item *QuestionnaireFillRecord, err error) {
	if utils.BusinessCode != utils.BusinessCodeSandbox {
		return
	}
	o := orm.NewOrm()
	sql := `SELECT * FROM questionnaire_fill_record WHERE mobile=? ORDER BY create_time DESC LIMIT 1`
	err = o.Raw(sql, mobile).QueryRow(&item)
	return
}

// AddQuestionnaireFillRecord 新增问卷填写记录
func AddQuestionnaireFillRecord(item *QuestionnaireFillRecord) (err error) {
	if utils.BusinessCode != utils.BusinessCodeSandbox {
		return
	}
	o := orm.NewOrm()
	id, err := o.Insert(item)
	if err != nil {
		return
	}
	item.RecordId = int(id)
	return
}
