123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package bi_dashboard
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type BiDashboardGrant struct {
- GrantId int `orm:"column(grant_id);pk"` // 授权id
- BiDashboardId int `gorm:"column:bi_dashboard_id" ` // 看板id
- GrantAdminId int `gorm:"column:grant_admin_id"` // 授权的用户id
- CreateTime time.Time `gorm:"column:create_time"` // 授权时间
- }
- // tableName
- func (m *BiDashboardGrant) TableName() string {
- return "bi_dashboard_grant"
- }
- // GrantDashboardReq 分配看板权限
- type GrantDashboardReq struct {
- BiDashboardId int `description:"看板id" `
- AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
- }
- // MultiAddDashboardGrant 批量添加授权记录
- func MultiAddDashboardGrant(boardId int, list []*BiDashboardGrant) (err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- sql := "DELETE from bi_dashboard_grant where bi_dashboard_id=?"
- _, err = to.Raw(sql, boardId).Exec()
- if err != nil {
- return
- }
- // 新增授权记录
- if len(list) > 0 {
- _, tmpErr := to.InsertMulti(len(list), list)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- }
- return
- }
- // PublicDashboardReq 设置公共看板权限
- type PublicDashboardReq struct {
- BiDashboardId int `description:"看板id" `
- }
- // del
- func DeleteDashboardGrant(biDashboardId int) (err error) {
- //return global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Delete(&BiDashboardGrant{}).Error
- o := orm.NewOrm()
- _, err = o.Raw("DELETE from bi_dashboard_grant where bi_dashboard_id=?", biDashboardId).Exec()
- return
- }
- // get
- func GetDashboardGrantInfo(biDashboardId int) (list []*BiDashboardGrant, err error) {
- //return list, global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Find(&list).Error
- o := orm.NewOrm()
- _, err = o.Raw("SELECT * FROM bi_dashboard_grant where bi_dashboard_id=?", biDashboardId).QueryRows(&list)
- return
- }
|