package System

import (
	"fmt"
	"github.com/beego/beego/v2/adapter/orm"
	"time"
)

type News struct {
	Id         int       `orm:"column(ID);size(11);auto;pk"`
	Admin_uuid string    `orm:"size(256);null"`                                        //
	News_Title string    `orm:"size(256);null"`                                        // 标题
	News_Url   string    `orm:"size(256);null"`                                        // 地址
	News_Tag   int       `orm:"size(2);null"`                                          //  标记 1 未阅读
	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
}

func (t *News) TableName() string {
	return "news" // 数据库名称   // ************** 替换 FormulaList **************
}

func init() {
	//注册模型
	orm.RegisterModel(new(News))

}

// 获取 ById
func Read_AdminNews_all_1(Admin_uuid string) (r []News) {
	o := orm.NewOrm()
	qs := o.QueryTable(new(News))
	qs.Filter("Admin_uuid", Admin_uuid).Filter("News_Tag", 1).All(&r)
	return r
}

// 修改 排序
func Update_AdminNews_News_Tag_2(Id int) (err error) {
	o := orm.NewOrm()
	v := News{Id: Id}

	if err = o.Read(&v, "Id", "Admin_uuid"); err == nil {
		var num int64
		v.News_Tag = 2
		if num, err = o.Update(&v, "News_Tag"); err == nil {
			fmt.Println("Number of records updated in database:", num)
		}
	}

	return
}
