123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- package bi_dashboard
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type BiDashboard struct {
- BiDashboardId int `orm:"column(bi_dashboard_id);pk"` // bi看板id
- BiDashboardClassifyId int `gorm:"column:bi_dashboard_classify_id" ` // 看板分类id
- BiDashboardName string `gorm:"column:bi_dashboard_name;size:255"` // 看板名称
- SysAdminId int `gorm:"column:sys_admin_id" ` // 创建人ID
- SysAdminName string `gorm:"column:sys_admin_name;size:128" ` // 创建人姓名
- Sort int `gorm:"column:sort" ` // 排序字段
- CreateTime time.Time `gorm:"column:create_time" ` // 创建时间
- ModifyTime time.Time `gorm:"column:modify_time"` // 更新时间
- State int `gorm:"column:state"` // 状态 1:未公开; 4-待审批;5-已驳回;6-已通过
- }
- // tableName
- func (m *BiDashboard) TableName() string {
- return "bi_dashboard"
- }
- func (m *BiDashboard) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(m, cols...)
- return
- }
- // AddBiDashboard 新增看板
- func AddBiDashboard(item *BiDashboard) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- // GetShareDashboard 获取公开分享的看板
- func GetShareDashboard() (items []*BiDashboard, err error) {
- //o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM bi_dashboard WHERE 1=1 AND state = 6 `
- sql += `ORDER BY create_time DESC`
- //sql += `ORDER BY create_time DESC LIMIT ?,?`
- //_, err = o.Raw(sql).QueryRows(&items)
- //err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- func GetBiDashboardList(condition string, pars []interface{}) (items []*BiDashboard, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM bi_dashboard WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- //
- sql += `ORDER BY modify_time DESC `
- //sql += `ORDER BY create_time DESC LIMIT ?,?`
- _, err = o.Raw(sql, pars...).QueryRows(&items)
- return
- }
- // GetDashboardById 获取看板
- func GetDashboardById(id int) (item *BiDashboard, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM bi_dashboard WHERE bi_dashboard_id = ? limit 1`
- //sql += `ORDER BY create_time DESC LIMIT ?,?`
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
- // del
- func DelDashboard(id int) (err error) {
- o := orm.NewOrm()
- sql := `DELETE FROM bi_dashboard WHERE bi_dashboard_id = ?`
- _, err = o.Raw(sql, id).Exec()
- return
- }
- // BiDashboardEditingCache PPT编辑缓存信息
- type BiDashboardEditingCache struct {
- IsEditing bool `description:"是否有人编辑"`
- AdminId int `description:"编辑者ID"`
- Editor string `description:"编辑者姓名"`
- Tips string `description:"提示信息"`
- }
- // DashboardDetailResp 详情响应体
- type DashboardDetailResp struct {
- *BiDashboard
- IsGrant int `description:"是否共享,0:不是,1:是"`
- Editor BiDashboardEditingCache `description:"编辑人信息"`
- List []*BiDashboardDetail
- }
- type AddDashboardReq struct {
- List []*AddDashboardListReq
- BiDashboardName string `description:"看板名称"`
- }
- type AddDashboardListReq struct {
- Type int
- UniqueCode string
- Sort int
- }
- type EditDashboardReq struct {
- List []*AddDashboardListReq
- BiDashboardId int `description:"看板id"`
- BiDashboardName string `description:"看板名称"`
- }
- // update
- func EditDashboard(item *BiDashboard) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE bi_dashboard SET bi_dashboard_name=?,modify_time=?,state=? WHERE bi_dashboard_id=?`
- _, err = o.Raw(sql, item.BiDashboardName, time.Now(), item.State, item.BiDashboardId).Exec()
- return
- }
- type DelDashboardReq struct {
- BiDashboardId int `description:"看板id"`
- }
- func GetDashboradByIds(dashboradIds []int) (list []*BiDashboard, err error) {
- //err = global.DEFAULT_DmSQL.Table("bi_dashboard").Where("bi_dashboard_id IN ?", dashboradIds).Find(&list).Error
- return
- }
- // GetAllGrantList 获取已经有权限的看板列表
- func GetAllGrantList(sysUserId int) (list []*BiDashboard, err error) {
- sql := `SELECT a.* FROM bi_dashboard a JOIN bi_dashboard_grant b on a.bi_dashboard_id=b.bi_dashboard_id
- WHERE b.grant_admin_id=?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, sysUserId).QueryRows(&list)
- return
- }
- func SaveDashboard(item *BiDashboard) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(item)
- return
- }
- // BiDashboardEditingReq 标记编辑中请求体
- type BiDashboardEditingReq struct {
- BiDashboardId int `description:"看板主键ID"`
- Status int `description:"标记状态: 1-编辑中; 2-编辑完成"`
- }
- // GetAllMyShareList 获取我共享的看板
- func GetAllMyShareList(sysUserId int) (list []*BiDashboard, err error) {
- sql := `SELECT a.* FROM bi_dashboard a JOIN bi_dashboard_grant b on a.bi_dashboard_id=b.bi_dashboard_id
- WHERE a.sys_admin_id = ? GROUP BY a.bi_dashboard_id `
- o := orm.NewOrm()
- _, err = o.Raw(sql, sysUserId).QueryRows(&list)
- return
- }
- // getByName
- func GetDashboardByName(name string, adminId int) (item *BiDashboard, err error) {
- sql := `SELECT * FROM bi_dashboard WHERE bi_dashboard_name = ? and sys_admin_id =? limit 1`
- o := orm.NewOrm()
- err = o.Raw(sql, name, adminId).QueryRow(&item)
- return
- }
|