knowledge_resource_bi_dashboard_detail.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package knowledge
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type KnowledgeResourceBiDashboardDetail struct {
  8. Id int `gorm:"column:id;primary_key"`
  9. BiDashboardDetailId int `gorm:"column:bi_dashboard_detail_id;comment:关联的BI仪表盘详情ID"`
  10. KnowledgeResourceId int `gorm:"column:knowledge_resource_id;comment:关联的知识库资源ID"`
  11. KnowledgeResourceType int `gorm:"column:knowledge_resource_type;comment:知识库资源类型:0事件库,1政策库,2观点库,3知识库"`
  12. CreateTime time.Time `gorm:"column:create_time;comment:创建时间"`
  13. }
  14. func (KnowledgeResourceBiDashboardDetail) TableName() string {
  15. return "knowledge_resource_bi_dashboard_detail"
  16. }
  17. func (k *KnowledgeResourceBiDashboardDetail) BatchAdd(items []*KnowledgeResourceBiDashboardDetail) (err error) {
  18. if len(items) == 0 {
  19. return
  20. }
  21. tx := global.DmSQL["rddp"].Begin()
  22. defer func() {
  23. if err != nil {
  24. tx.Rollback()
  25. } else {
  26. tx.Commit()
  27. }
  28. }()
  29. sql := `DELETE FROM knowledge_resource_bi_dashboard_detail WHERE bi_dashboard_detail_id =? `
  30. err = tx.Exec(sql, items[0].BiDashboardDetailId).Error
  31. if err != nil {
  32. return
  33. }
  34. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  35. return
  36. }
  37. func GetKnowledgeResourceIdsByCondition(condition string, pars []interface{}) (resourceIds []int, err error) {
  38. sql := "SELECT knowledge_resource_id FROM knowledge_resource_bi_dashboard_detail WHERE 1=1 "
  39. if condition != "" {
  40. sql += condition
  41. }
  42. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&resourceIds).Error
  43. return
  44. }