bi_dashboard_detail.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package bi_dashboard
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. type BiDashboardDetail struct {
  7. BiDashboardDetailId int `gorm:"primaryKey;autoIncrement;column:bi_dashboard_detail_id" ` // bi看板id
  8. BiDashboardId int `gorm:"column:bi_dashboard_id" ` // 看板id
  9. Type int `gorm:"column:type" ` // 1图表 2表格 3知识资源库
  10. Conf string `gorm:"column:conf" ` // 配置信息
  11. UniqueCode string `gorm:"column:unique_code;size:32;not null" ` // 报告唯一编码
  12. Sort int `gorm:"column:sort" ` // 排序字段
  13. CreateTime time.Time `gorm:"column:create_time" ` // 创建时间
  14. ModifyTime time.Time `gorm:"column:modify_time" ` // 更新时间
  15. }
  16. // tableName
  17. func (m *BiDashboardDetail) TableName() string {
  18. return "bi_dashboard_detail"
  19. }
  20. func (m *BiDashboardDetail) Insert() (err error) {
  21. return global.DEFAULT_DmSQL.Create(m).Error
  22. }
  23. func GetBiDashboardDetailById(id int) (list []*BiDashboardDetail, err error) {
  24. err = global.DEFAULT_DmSQL.Table("bi_dashboard_detail").Where("bi_dashboard_id IN ?", id).Find(&list).Error
  25. return
  26. }
  27. // GetBiDashboardDetailIdByBidashboardIdAndType 获取看板详情id
  28. func GetBiDashboardDetailIdByBidashboardIdAndType(bid int, t int) (ids []int, err error) {
  29. sql := "SELECT bi_dashboard_detail_id FROM bi_dashboard_detail WHERE bi_dashboard_id = ? AND type = ?"
  30. err = global.DEFAULT_DmSQL.Raw(sql, bid, t).Scan(&ids).Error
  31. return
  32. }
  33. // multiAdd
  34. func AddBiDashboardDetailMulti(items []*BiDashboardDetail) (err error) {
  35. return global.DEFAULT_DmSQL.CreateInBatches(items, 100).Error
  36. }
  37. // del
  38. func DeleteBiDashboardDetail(id int) (err error) {
  39. return global.DEFAULT_DmSQL.Where("bi_dashboard_id = ?", id).Delete(&BiDashboardDetail{}).Error
  40. }
  41. type MoveDashboardDetailReq struct {
  42. BiDashboardId int `description:"看板id"`
  43. BiDashboardDetailId int `description:"看板详情id"`
  44. Sort int `description:"排序"`
  45. OtherDetailId int `description:"交换的详情id"`
  46. OtherSort int `description:"交换的排序"`
  47. }
  48. // update
  49. func EditBiDashboardDetail(item *BiDashboardDetail) (err error) {
  50. return global.DEFAULT_DmSQL.Model(item).Where("bi_dashboard_detail_id = ?", item.BiDashboardDetailId).Updates(item).Error
  51. }
  52. type DelDashboardDetailReq struct {
  53. BiDashboardDetailId int `description:"看板详情id"`
  54. }
  55. // del
  56. func DeleteBiDashboardDetailByDetailId(id int) (err error) {
  57. return global.DEFAULT_DmSQL.Where("bi_dashboard_detail_id = ?", id).Delete(&BiDashboardDetail{}).Error
  58. }
  59. // GetUserIdListRelationBiDashboardDetailByCondition
  60. // @Description: 根据条件获取关联图的用户id列表
  61. // @author: Roc
  62. // @datetime 2024-12-26 10:13:47
  63. // @param condition string
  64. // @param pars []interface{}
  65. // @return total int
  66. // @return err error
  67. func GetUserIdListRelationBiDashboardDetailByCondition(condition string, pars []interface{}) (userIdList []int, err error) {
  68. sql := ` SELECT b.sys_admin_id FROM bi_dashboard_detail AS a
  69. JOIN bi_dashboard AS b on a.bi_dashboard_id = b.bi_dashboard_id WHERE 1=1 `
  70. if condition != "" {
  71. sql += condition
  72. }
  73. sql += ` GROUP BY b.sys_admin_id `
  74. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&userIdList).Error
  75. return
  76. }