From df7a4563820abfa6ff391fc0bac8cff7682145a7 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 24 Oct 2024 19:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/admin_bind_medium_dao.go | 8 +++++ src/implement/admin_bind_medium_implement.go | 35 ++++++++++++++++++++ src/model/admin_bind_medium.go | 13 ++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/dao/admin_bind_medium_dao.go create mode 100644 src/implement/admin_bind_medium_implement.go create mode 100644 src/model/admin_bind_medium.go diff --git a/src/dao/admin_bind_medium_dao.go b/src/dao/admin_bind_medium_dao.go new file mode 100644 index 0000000..95c66e0 --- /dev/null +++ b/src/dao/admin_bind_medium_dao.go @@ -0,0 +1,8 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/model" + +type AdminBindMediumDao interface { + FindAll(adminId int) (list []model.AdminBindMedium) + FindMediumList(mediumId []int, adminId, page, limit int) (list []model.AdminBindMedium, total int64, err error) +} diff --git a/src/implement/admin_bind_medium_implement.go b/src/implement/admin_bind_medium_implement.go new file mode 100644 index 0000000..e86b118 --- /dev/null +++ b/src/implement/admin_bind_medium_implement.go @@ -0,0 +1,35 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/dao" + "code.fnuoos.com/zhimeng/model.git/src/model" + "xorm.io/xorm" +) + +func NewAdminBindMediumDb(engine *xorm.Engine) dao.AdminBindMediumDao { + return &AdminBindMediumDb{Db: engine} +} + +type AdminBindMediumDb struct { + Db *xorm.Engine +} + +func (a AdminBindMediumDb) FindAll(adminId int) (list []model.AdminBindMedium) { + sess := a.Db.Where("admin_id=?", adminId) + err := sess.Find(&list) + if err != nil { + return nil + } + return +} +func (a AdminBindMediumDb) FindMediumList(mediumId []int, adminId, page, limit int) (list []model.AdminBindMedium, total int64, err error) { + sess := a.Db.Where("admin_id=?", adminId).Desc("id").Limit(limit, (page-1)*limit) + if len(mediumId) > 0 { + sess.In("medium_id", mediumId) + } + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +} diff --git a/src/model/admin_bind_medium.go b/src/model/admin_bind_medium.go new file mode 100644 index 0000000..fe537c4 --- /dev/null +++ b/src/model/admin_bind_medium.go @@ -0,0 +1,13 @@ +package model + +import ( + "time" +) + +type AdminBindMedium struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + AdminId int `json:"admin_id" xorm:"default 0 comment('管理员id') INT(11)"` + MediumId int `json:"medium_id" xorm:"not null default 0 comment('媒体id') INT(11)"` + CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP DATETIME"` + UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP DATETIME"` +}