From eac921c929ca9db7888d66204453c49852486880 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 24 Oct 2024 19:41:05 +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 --- app/hdl/hdl_role.go | 86 +++++++++++++++++++++++++++++++++++++ app/md/admin.go | 16 +++++++ app/router/router.go | 3 ++ app/svc/svc_medium_agent.go | 30 +++++++++++++ go.mod | 2 +- 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 app/md/admin.go diff --git a/app/hdl/hdl_role.go b/app/hdl/hdl_role.go index 4ab445f..8932837 100644 --- a/app/hdl/hdl_role.go +++ b/app/hdl/hdl_role.go @@ -10,6 +10,7 @@ import ( db "code.fnuoos.com/zhimeng/model.git/src" "code.fnuoos.com/zhimeng/model.git/src/implement" "code.fnuoos.com/zhimeng/model.git/src/model" + implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement" "github.com/gin-gonic/gin" "time" ) @@ -655,3 +656,88 @@ func AdminInfo(c *gin.Context) { }, nil) return } +func RoleMediumList(c *gin.Context) { + var req md.AppletApplicationMediumListReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + engine := svc.MasterDb(c) + NewMediumDb := implement.NewMediumDb(engine) + appId := svc.GetMediumIdStr(c, req.Name, req.Account) + user := svc.GetUser(c) + list, total, _ := NewMediumDb.FindSuperAdminByMediumId(appId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + data := make([]md.AdminBindMediumListData, 0) + if len(list) > 0 { + for _, v := range list { + var tmp = md.AdminBindMediumListData{ + MediumId: utils.IntToStr(v.MediumId), + Name: v.Memo, + IsBind: "0", + Account: v.Username, + } + NewMediumListDb := implement2.NewMediumListDb(db.Db) + GetMediumList, _ := NewMediumListDb.GetMediumList(v.MediumId) + if GetMediumList != nil { + tmp.Name = GetMediumList.CompanyName + if GetMediumList.CompanyAbbreviation != "" { + tmp.Name = GetMediumList.CompanyAbbreviation + } + } + count, _ := engine.Where("medium_id=? and admin_id=?", v.MediumId, user.AdmId).Count(&model.AdminBindMedium{}) + if count > 0 { + tmp.IsBind = "1" + } + data = append(data, tmp) + } + } + res := md.AdminBindMediumListRes{ + List: data, + Total: total, + } + e.OutSuc(c, res, nil) + return +} +func RoleBindMedium(c *gin.Context) { + var req md.AdminBindMediumListSaveReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + user := svc.GetUser(c) + NewAdminBindMediumDb := implement.NewAdminBindMediumDb(svc.MasterDb(c)) + data := NewAdminBindMediumDb.GetAdminByMediumId(user.AdmId, utils.StrToInt(req.MediumId)) + if data != nil { + e.OutErr(c, 400, e.NewErr(400, "已绑定该媒体")) + return + } + tmp := model.AdminBindMedium{ + AdminId: user.AdmId, + MediumId: utils.StrToInt(req.MediumId), + CreateAt: time.Now(), + UpdateAt: time.Now(), + } + svc.MasterDb(c).Insert(&tmp) + e.OutSuc(c, "success", nil) + return +} +func RoleDelMedium(c *gin.Context) { + var req md.AdminBindMediumListSaveReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + user := svc.GetUser(c) + svc.MasterDb(c).Where("medium_id=? and admin_id=?", req.MediumId, user.AdmId).Delete(&model.AdminBindMedium{}) + e.OutSuc(c, "success", nil) + return +} diff --git a/app/md/admin.go b/app/md/admin.go new file mode 100644 index 0000000..c8fdfce --- /dev/null +++ b/app/md/admin.go @@ -0,0 +1,16 @@ +package md + +type AdminBindMediumListData struct { + MediumId string `json:"medium_id" example:"媒体id"` + Name string `json:"name" example:""` + Account string `json:"account" example:""` + IsBind string `json:"is_bind"` +} +type AdminBindMediumListRes struct { + List []AdminBindMediumListData `json:"list"` + Total int64 `json:"total"` +} + +type AdminBindMediumListSaveReq struct { + MediumId string `json:"medium_id"` +} diff --git a/app/router/router.go b/app/router/router.go index c53fb75..7f2b5c4 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -122,6 +122,9 @@ func rRole(r *gin.RouterGroup) { r.DELETE("/deleteAdmin/:adm_id", hdl.DeleteAdmin) // 删除管理员 r.GET("/adminInfo", hdl.AdminInfo) // 获取管理员信息 r.POST("/bindAdminRole", hdl.BindAdminRole) // 绑定角色 + r.POST("/mediumList", hdl.RoleMediumList) // 管理员列表-媒体列表 + r.POST("/bindMedium", hdl.RoleBindMedium) // 管理员列表-关联媒体 + r.POST("/mediumDel", hdl.RoleDelMedium) // 管理员列表-删除关联媒体 } func rAgentQualification(r *gin.RouterGroup) { diff --git a/app/svc/svc_medium_agent.go b/app/svc/svc_medium_agent.go index 75b3b85..eaa3230 100644 --- a/app/svc/svc_medium_agent.go +++ b/app/svc/svc_medium_agent.go @@ -299,3 +299,33 @@ func GetAgentInfo(c *gin.Context, mediumId int) map[string]string { } return res } + +func GetMediumIdStr(c *gin.Context, name, account string) string { + user := GetUser(c) + appId := GetMediumByAccountId(c, name, account) + appIds := []string{"-1"} + NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c)) + list := NewAdminBindMediumDb.FindAll(user.AdmId) + ids := make([]string, 0) + for _, v := range list { + appIds = append(appIds, utils.IntToStr(v.MediumId)) + ids = append(ids, utils.IntToStr(v.MediumId)) + } + if len(list) == 0 { //为空就查全部 + appIds = []string{} + } + if appId != "" { //不为空就判断 有没有在列表里面 + appIds = []string{"-1"} + ex := strings.Split(appId, ",") + for _, v := range ex { + if utils.InArr(v, ids) || len(list) == 0 { + appIds = append(appIds, v) + } + } + } + str := "" + if len(appIds) > 0 { + str = strings.Join(appIds, ",") + } + return str +} diff --git a/go.mod b/go.mod index 8ce0b83..df18579 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( require ( code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240830072333-a1980ffb256e - code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241024100823-8521ffcf1077 + code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241024113302-5f350a1a0c09 github.com/jinzhu/copier v0.4.0 )