bi_dashboard.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package bi_dashboard
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type BiDashboard struct {
  7. BiDashboardId int `orm:"column(bi_dashboard_id);pk"` // bi看板id
  8. BiDashboardClassifyId int `gorm:"column:bi_dashboard_classify_id" ` // 看板分类id
  9. BiDashboardName string `gorm:"column:bi_dashboard_name;size:255"` // 看板名称
  10. SysAdminId int `gorm:"column:sys_admin_id" ` // 创建人ID
  11. SysAdminName string `gorm:"column:sys_admin_name;size:128" ` // 创建人姓名
  12. Sort int `gorm:"column:sort" ` // 排序字段
  13. CreateTime time.Time `gorm:"column:create_time" ` // 创建时间
  14. ModifyTime time.Time `gorm:"column:modify_time"` // 更新时间
  15. State int `gorm:"column:state"` // 状态 1:未公开; 4-待审批;5-已驳回;6-已通过
  16. }
  17. // tableName
  18. func (m *BiDashboard) TableName() string {
  19. return "bi_dashboard"
  20. }
  21. func (m *BiDashboard) Update(cols []string) (err error) {
  22. o := orm.NewOrm()
  23. _, err = o.Update(m, cols...)
  24. return
  25. }
  26. // AddBiDashboard 新增看板
  27. func AddBiDashboard(item *BiDashboard) (lastId int64, err error) {
  28. o := orm.NewOrm()
  29. lastId, err = o.Insert(item)
  30. return
  31. }
  32. // GetShareDashboard 获取公开分享的看板
  33. func GetShareDashboard() (items []*BiDashboard, err error) {
  34. //o := orm.NewOrmUsingDB("rddp")
  35. sql := `SELECT * FROM bi_dashboard WHERE 1=1 AND state = 6 `
  36. sql += `ORDER BY create_time DESC`
  37. //sql += `ORDER BY create_time DESC LIMIT ?,?`
  38. //_, err = o.Raw(sql).QueryRows(&items)
  39. //err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
  40. return
  41. }
  42. func GetBiDashboardList(condition string, pars []interface{}) (items []*BiDashboard, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM bi_dashboard WHERE 1=1 `
  45. if condition != "" {
  46. sql += condition
  47. }
  48. //
  49. sql += `ORDER BY modify_time DESC `
  50. //sql += `ORDER BY create_time DESC LIMIT ?,?`
  51. _, err = o.Raw(sql, pars...).QueryRows(&items)
  52. return
  53. }
  54. // GetDashboardById 获取看板
  55. func GetDashboardById(id int) (item *BiDashboard, err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT * FROM bi_dashboard WHERE bi_dashboard_id = ? limit 1`
  58. //sql += `ORDER BY create_time DESC LIMIT ?,?`
  59. err = o.Raw(sql, id).QueryRow(&item)
  60. return
  61. }
  62. // del
  63. func DelDashboard(id int) (err error) {
  64. o := orm.NewOrm()
  65. sql := `DELETE FROM bi_dashboard WHERE bi_dashboard_id = ?`
  66. _, err = o.Raw(sql, id).Exec()
  67. return
  68. }
  69. // BiDashboardEditingCache PPT编辑缓存信息
  70. type BiDashboardEditingCache struct {
  71. IsEditing bool `description:"是否有人编辑"`
  72. AdminId int `description:"编辑者ID"`
  73. Editor string `description:"编辑者姓名"`
  74. Tips string `description:"提示信息"`
  75. }
  76. // DashboardDetailResp 详情响应体
  77. type DashboardDetailResp struct {
  78. *BiDashboard
  79. IsGrant int `description:"是否共享,0:不是,1:是"`
  80. Editor BiDashboardEditingCache `description:"编辑人信息"`
  81. List []*BiDashboardDetail
  82. }
  83. type AddDashboardReq struct {
  84. List []*AddDashboardListReq
  85. BiDashboardName string `description:"看板名称"`
  86. }
  87. type AddDashboardListReq struct {
  88. Type int
  89. UniqueCode string
  90. Sort int
  91. }
  92. type EditDashboardReq struct {
  93. List []*AddDashboardListReq
  94. BiDashboardId int `description:"看板id"`
  95. BiDashboardName string `description:"看板名称"`
  96. }
  97. // update
  98. func EditDashboard(item *BiDashboard) (err error) {
  99. o := orm.NewOrm()
  100. sql := `UPDATE bi_dashboard SET bi_dashboard_name=?,modify_time=?,state=? WHERE bi_dashboard_id=?`
  101. _, err = o.Raw(sql, item.BiDashboardName, time.Now(), item.State, item.BiDashboardId).Exec()
  102. return
  103. }
  104. type DelDashboardReq struct {
  105. BiDashboardId int `description:"看板id"`
  106. }
  107. func GetDashboradByIds(dashboradIds []int) (list []*BiDashboard, err error) {
  108. //err = global.DEFAULT_DmSQL.Table("bi_dashboard").Where("bi_dashboard_id IN ?", dashboradIds).Find(&list).Error
  109. return
  110. }
  111. // GetAllGrantList 获取已经有权限的看板列表
  112. func GetAllGrantList(sysUserId int) (list []*BiDashboard, err error) {
  113. sql := `SELECT a.* FROM bi_dashboard a JOIN bi_dashboard_grant b on a.bi_dashboard_id=b.bi_dashboard_id
  114. WHERE b.grant_admin_id=?`
  115. o := orm.NewOrm()
  116. _, err = o.Raw(sql, sysUserId).QueryRows(&list)
  117. return
  118. }
  119. func SaveDashboard(item *BiDashboard) (err error) {
  120. o := orm.NewOrm()
  121. _, err = o.Insert(item)
  122. return
  123. }
  124. // BiDashboardEditingReq 标记编辑中请求体
  125. type BiDashboardEditingReq struct {
  126. BiDashboardId int `description:"看板主键ID"`
  127. Status int `description:"标记状态: 1-编辑中; 2-编辑完成"`
  128. }
  129. // GetAllMyShareList 获取我共享的看板
  130. func GetAllMyShareList(sysUserId int) (list []*BiDashboard, err error) {
  131. sql := `SELECT a.* FROM bi_dashboard a JOIN bi_dashboard_grant b on a.bi_dashboard_id=b.bi_dashboard_id
  132. WHERE a.sys_admin_id = ? GROUP BY a.bi_dashboard_id `
  133. o := orm.NewOrm()
  134. _, err = o.Raw(sql, sysUserId).QueryRows(&list)
  135. return
  136. }
  137. // getByName
  138. func GetDashboardByName(name string, adminId int) (item *BiDashboard, err error) {
  139. sql := `SELECT * FROM bi_dashboard WHERE bi_dashboard_name = ? and sys_admin_id =? limit 1`
  140. o := orm.NewOrm()
  141. err = o.Raw(sql, name, adminId).QueryRow(&item)
  142. return
  143. }