audit_check.go 1.3 KB
package models

import (
	"time"

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

type AuditCheck struct {
	Id         int       `orm:"column(id);pk"`
	Pid        int64     `orm:"column(pid)"`
	TemplateId int64     `orm:"column(template_id)" description:"模板id"`
	Title      string    `orm:"column(title);size(100)" description:"标题"`
	Items      string    `orm:"column(items)" description:"选项数据json格式"`
	Enable     int8      `orm:"column(enable)" description:"是否有效【0:无效】【1:有效】"`
	CreateTime time.Time `orm:"column(create_time);type(timestamp)"`
}

func (t *AuditCheck) TableName() string {
	return "audit_check"
}

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

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

func GetAuditCheckBy(tpId int64) (v []*AuditCheck, err error) {
	sql := `select * from(
select id,(case when pid=0 then id else pid end) pid,title,items from audit_check where template_id=? and enable=1 
)a
order by a.pid`
	o := orm.NewOrm()
	if _, err = o.Raw(sql, tpId).QueryRows(&v); err != nil {
		if err == orm.ErrNoRows {
			err = nil
		}
		return
	}
	return
}