audit_template.go 3.0 KB
package models

import (
	"fmt"
	"time"

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

type AuditTemplate struct {
	Id           int64     `orm:"column(id);pk" description:"唯一编号"`
	CompanyId    int       `orm:"column(company_id)" description:"公司id"`
	ChanceTypeId   int       `orm:"column(chance_type_id)" description:"机会类型编号"`
	Name         string    `orm:"column(name);size(20)" description:"子分类名称"`
	Doc          string    `orm:"column(doc);size(255)" description:"说明"`
	Icon         string    `orm:"column(icon);size(255)" description:"图标"`
	NoticeType   int8      `orm:"column(notice_type)" description:"通知方式"`
	NoApprover   int8      `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
	SortNum      int       `orm:"column(sort_num)" description:"自定义排序编号"`
	VisibleType  int8      `orm:"column(visible_type)" description:"可见范围  0:所有人 1:指定部门 "`
	EnableStatus int8      `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
	CreateAt     time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
	UpdateAt     time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
}

func (t *AuditTemplate) TableName() string {
	return "audit_template"
}

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

// AddAuditTemplate insert a new AuditTemplate into database and returns
// last inserted Id on success.
func AddAuditTemplate(m *AuditTemplate) (id int64, err error) {
	o := orm.NewOrm()
	id, err = o.Insert(m)
	return
}

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

// UpdateAuditTemplate updates AuditTemplate by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditTemplateById(m *AuditTemplate) (err error) {
	o := orm.NewOrm()
	v := AuditTemplate{Id: m.Id}
	// ascertain id exists in the database
	if err = o.Read(&v); err == nil {
		var num int64
		if num, err = o.Update(m); err == nil {
			fmt.Println("Number of records updated in database:", num)
		}
	}
	return
}

// DeleteAuditTemplate deletes AuditTemplate by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditTemplate(id int64) (err error) {
	o := orm.NewOrm()
	v := AuditTemplate{Id: id}
	// ascertain id exists in the database
	if err = o.Read(&v); err == nil {
		var num int64
		if num, err = o.Delete(&AuditTemplate{Id: id}); err == nil {
			fmt.Println("Number of records deleted in database:", num)
		}
	}
	return
}

func GetAuditTemplates(companyId int64, chanceType int) (v []*AuditTemplate, err error) {
	o := orm.NewOrm()
	sql := "select * from audit_template where company_id=? and chance_type_id=? and enable_status=1"
	if _, err = o.Raw(sql, companyId, chanceType).QueryRows(&v); err == nil {
		return
	}
	return
}