bi_dashboard.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package bi_dashboard
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. type BiDashboard struct {
  7. BiDashboardId int `gorm:"primaryKey;autoIncrement;column:bi_dashboard_id"` // 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. err = global.DEFAULT_DmSQL.Model(m).Select(cols).Updates(m).Error
  23. return
  24. }
  25. // AddBiDashboard 新增看板
  26. func AddBiDashboard(item *BiDashboard) (lastId int64, err error) {
  27. err = global.DEFAULT_DmSQL.Create(item).Error
  28. lastId = int64(item.BiDashboardId)
  29. return
  30. }
  31. func GetBiDashboardList(condition string, pars []interface{}) (items []*BiDashboard, err error) {
  32. sql := `SELECT * FROM bi_dashboard WHERE 1=1 `
  33. if condition != "" {
  34. sql += condition
  35. }
  36. //
  37. sql += `ORDER BY modify_time DESC `
  38. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  39. return
  40. }
  41. // GetDashboardById 获取看板
  42. func GetDashboardById(id int) (item *BiDashboard, err error) {
  43. sql := `SELECT * FROM bi_dashboard WHERE bi_dashboard_id = ? limit 1`
  44. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  45. return
  46. }
  47. // del
  48. func DelDashboard(id int) (err error) {
  49. return global.DEFAULT_DmSQL.Delete(&BiDashboard{BiDashboardId: id}).Error
  50. }
  51. // BiDashboardEditingCache PPT编辑缓存信息
  52. type BiDashboardEditingCache struct {
  53. IsEditing bool `description:"是否有人编辑"`
  54. AdminId int `description:"编辑者ID"`
  55. Editor string `description:"编辑者姓名"`
  56. Tips string `description:"提示信息"`
  57. }
  58. // DashboardDetailResp 详情响应体
  59. type DashboardDetailResp struct {
  60. *BiDashboard
  61. IsGrant int `description:"是否共享,0:不是,1:是"`
  62. Editor BiDashboardEditingCache `description:"编辑人信息"`
  63. List []*BiDashboardDetail
  64. }
  65. type AddDashboardReq struct {
  66. List []*AddDashboardListReq
  67. BiDashboardName string `description:"看板名称"`
  68. }
  69. type AddDashboardListReq struct {
  70. Type int
  71. UniqueCode string
  72. Sort int
  73. }
  74. type EditDashboardReq struct {
  75. List []*AddDashboardListReq
  76. BiDashboardId int `description:"看板id"`
  77. BiDashboardName string `description:"看板名称"`
  78. }
  79. // update
  80. func EditDashboard(item *BiDashboard) (err error) {
  81. return global.DEFAULT_DmSQL.Model(item).Updates(item).Error
  82. }
  83. type DelDashboardReq struct {
  84. BiDashboardId int `description:"看板id"`
  85. }
  86. // GetAllGrantList 获取已经有权限的看板列表
  87. func GetAllGrantList(sysUserId int) (list []*BiDashboard, err error) {
  88. sql := `SELECT a.* FROM bi_dashboard a JOIN bi_dashboard_grant b on a.bi_dashboard_id=b.bi_dashboard_id
  89. WHERE b.grant_admin_id=?`
  90. err = global.DEFAULT_DmSQL.Raw(sql, sysUserId).Find(&list).Error
  91. return
  92. }
  93. func SaveDashboard(item *BiDashboard) (err error) {
  94. return global.DEFAULT_DmSQL.Save(item).Error
  95. }
  96. // BiDashboardEditingReq 标记编辑中请求体
  97. type BiDashboardEditingReq struct {
  98. BiDashboardId int `description:"看板主键ID"`
  99. Status int `description:"标记状态: 1-编辑中; 2-编辑完成"`
  100. }
  101. // GetAllMyShareList 获取我共享的看板
  102. func GetAllMyShareList(sysUserId int) (list []*BiDashboard, err error) {
  103. sql := `SELECT a.* FROM bi_dashboard a JOIN bi_dashboard_grant b on a.bi_dashboard_id=b.bi_dashboard_id
  104. WHERE a."sys_admin_id" = ? GROUP BY a."bi_dashboard_id" ,"bi_dashboard_classify_id" ,"bi_dashboard_name" ,"sys_admin_id" ,
  105. "sys_admin_name" ,"sort" ,a."create_time" ,a."modify_time" ,"state" `
  106. err = global.DEFAULT_DmSQL.Raw(sql, sysUserId).Find(&list).Error
  107. return
  108. }
  109. // getByName
  110. func GetDashboardByName(name string) (item *BiDashboard, err error) {
  111. sql := `SELECT * FROM bi_dashboard WHERE bi_dashboard_name = ? limit 1`
  112. err = global.DEFAULT_DmSQL.Raw(sql, name).First(&item).Error
  113. return
  114. }