From b036c2909d832230ae890a873ea5b6264ec5e1a2 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 4 Nov 2024 14:16:51 +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_agent_dao.go | 9 +++++ src/implement/admin_bind_agent_implement.go | 44 +++++++++++++++++++++ src/model/admin_bind_agent.go | 13 ++++++ 3 files changed, 66 insertions(+) create mode 100644 src/dao/admin_bind_agent_dao.go create mode 100644 src/implement/admin_bind_agent_implement.go create mode 100644 src/model/admin_bind_agent.go diff --git a/src/dao/admin_bind_agent_dao.go b/src/dao/admin_bind_agent_dao.go new file mode 100644 index 0000000..dd0fee6 --- /dev/null +++ b/src/dao/admin_bind_agent_dao.go @@ -0,0 +1,9 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/model" + +type AdminBindAgentDao interface { + FindAll(adminId int) (list []model.AdminBindAgent) + FindAgentList(agentId string, adminId, page, limit int) (list []model.AdminBindAgent, total int64, err error) + GetAdminByAgentId(adminId, agentId int) (list *model.AdminBindAgent) +} diff --git a/src/implement/admin_bind_agent_implement.go b/src/implement/admin_bind_agent_implement.go new file mode 100644 index 0000000..9b46c3d --- /dev/null +++ b/src/implement/admin_bind_agent_implement.go @@ -0,0 +1,44 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/dao" + "code.fnuoos.com/zhimeng/model.git/src/model" + "strings" + "xorm.io/xorm" +) + +func NewAdminBindAgentDb(engine *xorm.Engine) dao.AdminBindAgentDao { + return &AdminBindAgentDb{Db: engine} +} + +type AdminBindAgentDb struct { + Db *xorm.Engine +} + +func (a AdminBindAgentDb) FindAll(adminId int) (list []model.AdminBindAgent) { + sess := a.Db.Where("admin_id=?", adminId) + err := sess.Find(&list) + if err != nil { + return nil + } + return +} +func (a AdminBindAgentDb) GetAdminByAgentId(adminId, agentId int) (list *model.AdminBindAgent) { + sess := a.Db.Where("agent_id=? and admin_id=?", agentId, adminId) + get, err := sess.Get(&list) + if get == false || err != nil { + return nil + } + return +} +func (a AdminBindAgentDb) FindAgentList(agentId string, adminId, page, limit int) (list []model.AdminBindAgent, total int64, err error) { + sess := a.Db.Where("admin_id=?", adminId).Desc("id").Limit(limit, (page-1)*limit) + if agentId != "" { + sess.In("agent_id", strings.Split(agentId, ",")) + } + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +} diff --git a/src/model/admin_bind_agent.go b/src/model/admin_bind_agent.go new file mode 100644 index 0000000..981340f --- /dev/null +++ b/src/model/admin_bind_agent.go @@ -0,0 +1,13 @@ +package model + +import ( + "time" +) + +type AdminBindAgent struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + AdminId int `json:"admin_id" xorm:"default 0 comment('管理员id') INT(11)"` + AgentId int `json:"agent_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"` +}