|
@@ -9,6 +9,7 @@ import (
|
|
|
"github.com/beego/beego/v2/adapter/orm"
|
|
|
orm2 "github.com/beego/beego/v2/client/orm"
|
|
|
"github.com/beego/beego/v2/core/logs"
|
|
|
+ "strconv"
|
|
|
"sync"
|
|
|
"time"
|
|
|
)
|
|
@@ -25,6 +26,20 @@ type Bulletin struct {
|
|
|
UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` // auto_now_add 第一次保存时才设置时间
|
|
|
}
|
|
|
|
|
|
+func (ab *Bulletin) MarshalJSON() ([]byte, error) {
|
|
|
+ loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
+ type Alias Bulletin
|
|
|
+ return json.Marshal(&struct {
|
|
|
+ CreateTime string `json:"CreateTime,omitempty"`
|
|
|
+ UpdateTime string `json:"UpdateTime,omitempty"`
|
|
|
+ *Alias
|
|
|
+ }{
|
|
|
+ CreateTime: ab.CreateTime.In(loc).Format("2006-01-02 15:04:05"),
|
|
|
+ UpdateTime: ab.UpdateTime.In(loc).Format("2006-01-02 15:04:05"),
|
|
|
+ Alias: (*Alias)(ab),
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
func (n *Bulletin) TableName() string {
|
|
|
return "bulletin"
|
|
|
}
|
|
@@ -137,6 +152,7 @@ func UpdateBulletin(b Bulletin) (err error) {
|
|
|
query := o.QueryTable(new(Bulletin))
|
|
|
params := orm.Params{
|
|
|
"UpdateTime": b.UpdateTime,
|
|
|
+ "state": b.State,
|
|
|
}
|
|
|
if b.Title != "" {
|
|
|
params["Title"] = b.Title
|
|
@@ -156,7 +172,7 @@ func UpdateBulletin(b Bulletin) (err error) {
|
|
|
}
|
|
|
|
|
|
// Read_Bulletin_List 获取公告列表
|
|
|
-func Read_Bulletin_List(t_uuid string, page int, page_z int) (BulletinList []Bulletin, cnt int64) {
|
|
|
+func Read_Bulletin_List(t_uuid string, page int, page_z int, is_show string) (BulletinList []Bulletin, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
@@ -172,7 +188,10 @@ func Read_Bulletin_List(t_uuid string, page int, page_z int) (BulletinList []Bul
|
|
|
}
|
|
|
cond := orm.NewCondition()
|
|
|
cond1 := cond.And("State", 0).And("T_uuid", t_uuid)
|
|
|
-
|
|
|
+ if len(is_show) > 0 {
|
|
|
+ is_show_int, _ := strconv.Atoi(is_show)
|
|
|
+ cond1 = cond1.And("is_show", is_show_int)
|
|
|
+ }
|
|
|
//if len(T_name) > 0 {
|
|
|
// cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_user__icontains", T_name))
|
|
|
//}
|
|
@@ -210,3 +229,40 @@ func IsReadBulletin(id, t_uuid, bulletin_id string) (err error) {
|
|
|
}
|
|
|
return err
|
|
|
}
|
|
|
+func Read_Bulletin_List_Admin(t_uuid string, page int, page_z int) (BulletinList []Bulletin, cnt int64) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ // 也可以直接使用 Model 结构体作为表名
|
|
|
+
|
|
|
+ qs := o.QueryTable(new(Bulletin))
|
|
|
+ var maps []Bulletin
|
|
|
+
|
|
|
+ var offset int64
|
|
|
+ if page <= 1 {
|
|
|
+ offset = 0
|
|
|
+ } else {
|
|
|
+ offset = int64((page - 1) * page_z)
|
|
|
+ }
|
|
|
+ cond := orm.NewCondition()
|
|
|
+ cond1 := cond.And("T_uuid", t_uuid)
|
|
|
+
|
|
|
+ //if len(T_name) > 0 {
|
|
|
+ // cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_user__icontains", T_name))
|
|
|
+ //}
|
|
|
+ var err error
|
|
|
+ if page_z == 9999 {
|
|
|
+ _, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-update_time").All(&maps)
|
|
|
+ } else {
|
|
|
+ _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-update_time").All(&maps)
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ }
|
|
|
+ cnt, err = qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ }
|
|
|
+ for i, _ := range maps {
|
|
|
+ BulletinList = append(BulletinList, maps[i])
|
|
|
+ }
|
|
|
+ return BulletinList, cnt
|
|
|
+}
|