chance_self_check.go 2.4 KB
package models

import (
	"fmt"
	"time"

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

type ChanceSelfCheck struct {
	Id            int64     `orm:"column(id);pk" description:"编号"`
	UserCompanyId int64     `orm:"column(user_company_id);null" description:"提交人"`
	ChanceId      int64     `orm:"column(chance_id);null" description:"机会编号"`
	RelateId      int64     `orm:"column(relate_id)" description:"关联编号 机会编号 / 审核流程编号"`
	CheckItem     string    `orm:"column(check_item);size(50)" description:"检查项"`
	GroupId       int64     `orm:"column(group_id)" description:"分组编号(audit_check.id/pid)"`
	Answer        string    `orm:"column(answer);size(50);null" description:"回答"`
	Reason        string    `orm:"column(reason);size(200);null" description:"理由"`
	CreateAt      time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
	//UpdateAt      time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
	//Enable        int8      `orm:"column(enable);size(200);null" description:"是否有效【0:无效】【1:有效】"`
	CompanyId int64 `orm:"column(company_id);null" description:"公司编号"`
	Type      int   `orm:"column(type);null" description:"数据来源 1:提交人 2:审核人 "`
}

func (t *ChanceSelfCheck) TableName() string {
	return "chance_self_check"
}

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

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

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

// UpdateChanceSelfCheck updates ChanceSelfCheck by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceSelfCheckById(m *ChanceSelfCheck) (err error) {
	o := orm.NewOrm()
	v := ChanceSelfCheck{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
}