rank_period.go 2.2 KB
package models

import (
	"fmt"
	"time"

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

type RankPeriod struct {
	Id            int64     `orm:"column(id);auto" description:"主键"`
	CompanyId     int64     `orm:"column(company_id);null" description:"公司编号 表company.id"`
	SeasonName    string    `orm:"column(season_name);size(50);null" description:"赛季名称"`
	BeginTime     time.Time `orm:"column(begin_time);type(timestamp);null" description:"开始时间"`
	EndTime       time.Time `orm:"column(end_time);type(timestamp);null" description:"结束时间"`
	CreateAt      time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
	UpdateAt      time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
	Status        int8      `orm:"column(status);null" description:"状态 0:未开始 1:开始 2:结束 "`
	RankRangeBack string    `orm:"column(rank_range_back)" description:"赛季结束时,备份赛季参与人设置"`
	RankItemBack  string    `orm:"column(rank_item_back)" description:"赛季结束时,备份赛季评比项设置"`
}

func (t *RankPeriod) TableName() string {
	return "rank_period"
}

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

//状态 0:未开始 1:开始 2:结束
const (
	RANKPERIOD_STATUS_NOT   int8 = 0
	RANKPERIOD_STATUS_BEGIN int8 = 1
	RANKPERIOD_STATUS_END   int8 = 2
)

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

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

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