classify.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package models
  2. import (
  3. "eta_gn/eta_report/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. type Classify struct {
  9. Id int `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  10. ClassifyName string `gorm:"column:classify_name" json:"classify_name"` //`description:"分类名称"`
  11. Sort int `gorm:"column:sort" json:"sort"` //`json:"-"`
  12. ParentId int `gorm:"column:parent_id" json:"parent_id"` //`description:"父级分类id"`
  13. CreateTime time.Time `gorm:"column:create_time" json:"create_time"` //`description:"创建时间"`
  14. ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"` //`description:"修改时间"`
  15. Abstract string `gorm:"column:abstract" json:"abstract"` //`description:"栏目简介"`
  16. Descript string `gorm:"column:descript" json:"descript"` //`description:"分享描述"`
  17. ReportAuthor string `gorm:"column:report_author" json:"report_author"` //`description:"栏目作者"`
  18. AuthorDescript string `gorm:"column:author_descript" json:"author_descript"` //`description:"作者简介"`
  19. ColumnImgUrl string `gorm:"column:column_img_url" json:"column_img_url"` //`description:"栏目配图"`
  20. HeadImgUrl string `gorm:"column:head_img_url" json:"head_img_url"` //`description:"头部banner"`
  21. AvatarImgUrl string `gorm:"column:avatar_img_url" json:"avatar_img_url"` //`description:"头像"`
  22. ReportImgUrl string `gorm:"column:report_img_url" json:"report_img_url"` //`description:"报告配图"`
  23. HomeImgUrl string `gorm:"column:home_img_url" json:"home_img_url"` //`description:"首页配图"`
  24. ClassifyLabel string `gorm:"column:classify_label" json:"classify_label"` //`description:"分类标签"`
  25. ShowType int `gorm:"column:show_type" json:"show_type"` //`description:"展示类型:1-列表 2-专栏"`
  26. HasTeleconference int `gorm:"column:has_teleconference" json:"has_teleconference"` //`description:"是否有电话会:0-否 1-是"`
  27. VipTitle string `gorm:"column:vip_title" json:"vip_title"` //`description:"研究员头衔"`
  28. IsShow int `gorm:"column:is_show" json:"is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"`
  29. YbFiccSort int `gorm:"column:yb_ficc_sort" json:"yb_ficc_sort"` //`description:"小程序FICC页排序"`
  30. YbFiccIcon string `gorm:"column:yb_ficc_icon" json:"yb_ficc_icon"` // `description:"小程序FICC页icon"`
  31. YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon" json:"yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"`
  32. YbIconUrl string `gorm:"column:yb_icon_url" json:"yb_icon_url"` //`description:"小程序已购页icon"`
  33. YbBgUrl string `gorm:"column:yb_bg_url" json:"yb_bg_url"` //`description:"小程序已购详情背景图"`
  34. YbListImg string `gorm:"column:yb_list_img" json:"yb_list_img"` //`description:"小程序研报列表封面图"`
  35. YbShareBgImg string `gorm:"column:yb_share_bg_img" json:"yb_share_bg_img"` //`description:"小程序研报详情分享背景图"`
  36. YbRightBanner string `gorm:"column:yb_right_banner" json:"yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"`
  37. RelateTel int `gorm:"column:relate_tel" json:"relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"`
  38. RelateVideo int `gorm:"column:relate_video" json:"relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"`
  39. IsMassSend int `gorm:"column:is_mass_send" json:"is_mass_send"` //`description:"1:群发,0:非群发"`
  40. Enabled int `gorm:"column:enabled" json:"enabled"` //`description:"是否可用,1可用,0禁用"`
  41. Level int `gorm:"column:level" json:"level"` //`description:"层级"`
  42. HasChild int `gorm:"column:has_child" json:"has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  43. ReportDetailShowType int `gorm:"column:report_detail_show_type" json:"report_detail_show_type"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
  44. ClassifyType int `gorm:"column:classify_type" json:"classify_type"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
  45. IsRemind int `gorm:"column:is_remind" json:"is_remind"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
  46. RemindTime string `gorm:"column:remind_time" json:"remind_time"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
  47. ReportNum int `gorm:"column:report_num" json:"report_num"` //`description:"分类下的报告数"`
  48. LevelPath string `gorm:"column:level_path" json:"level_path"` //`description:"分类的层级路径,英文逗号分隔"`
  49. }
  50. func (m *Classify) TableName() string {
  51. return "classify"
  52. }
  53. func (m *Classify) GetItemById(id int) (item *Classify, err error) {
  54. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), "id")
  55. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  56. return
  57. }
  58. func (m *Classify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Classify, err error) {
  59. fields := strings.Join(fieldArr, ",")
  60. if len(fieldArr) == 0 {
  61. fields = `*`
  62. }
  63. order := `ORDER BY create_time DESC`
  64. if orderRule != "" {
  65. order = ` ORDER BY ` + orderRule
  66. }
  67. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  68. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  69. return
  70. }
  71. type ClassifyTreeItem struct {
  72. ClassifyId int `description:"分类ID"`
  73. ClassifyName string `description:"分类名称"`
  74. ParentId int `description:"父级ID"`
  75. Sort int `description:"排序"`
  76. Level int `description:"层级"`
  77. ClassifyType int `description:"分类类型:1-研报;2-PPT"`
  78. HasChild int `json:"-" description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  79. Children []*ClassifyTreeItem `description:"子目录"`
  80. }
  81. func (m *Classify) Format2TreeItem(origin *Classify) (item *ClassifyTreeItem) {
  82. if origin == nil {
  83. return
  84. }
  85. item = new(ClassifyTreeItem)
  86. item.ClassifyId = origin.Id
  87. item.ClassifyName = origin.ClassifyName
  88. item.ParentId = origin.ParentId
  89. item.Sort = origin.Sort
  90. item.Level = origin.Level
  91. item.ClassifyType = origin.ClassifyType
  92. item.Children = make([]*ClassifyTreeItem, 0)
  93. return
  94. }
  95. func GetClassifyById(classifyId int) (item *Classify, err error) {
  96. sql := `SELECT * FROM classify WHERE id=? `
  97. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error
  98. return
  99. }
  100. // UpdateClassify 更新分类
  101. func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
  102. err = global.DEFAULT_DmSQL.Select(cols).Updates(classifyInfo).Error
  103. return
  104. }