classify.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type Classify struct {
  8. Id int `orm:"column(id);pk"`
  9. ClassifyName string `description:"分类名称"`
  10. Sort int `json:"-"`
  11. ParentId int `description:"父级分类id"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. Abstract string `description:"栏目简介"`
  15. Descript string `description:"分享描述"`
  16. ReportAuthor string `description:"栏目作者"`
  17. AuthorDescript string `description:"作者简介"`
  18. ColumnImgUrl string `description:"栏目配图"`
  19. HeadImgUrl string `description:"头部banner"`
  20. AvatarImgUrl string `description:"头像"`
  21. ReportImgUrl string `description:"报告配图"`
  22. HomeImgUrl string `description:"首页配图"`
  23. ClassifyLabel string `description:"分类标签"`
  24. ShowType int `description:"展示类型:1-列表 2-专栏"`
  25. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  26. VipTitle string `description:"研究员头衔"`
  27. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  28. YbFiccSort int `description:"小程序FICC页排序"`
  29. YbFiccIcon string `description:"小程序FICC页icon"`
  30. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  31. YbIconUrl string `description:"小程序已购页icon"`
  32. YbBgUrl string `description:"小程序已购详情背景图"`
  33. YbListImg string `description:"小程序研报列表封面图"`
  34. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  35. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  36. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  37. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  38. IsMassSend int `description:"1:群发,0:非群发"`
  39. }
  40. func GetClassifyById(classifyId int) (item *Classify, err error) {
  41. sql := `SELECT * FROM classify WHERE id=? `
  42. o := orm.NewOrmUsingDB("rddp")
  43. err = o.Raw(sql, classifyId).QueryRow(&item)
  44. return
  45. }
  46. type ClassifyList struct {
  47. Id int `orm:"column(id);pk"`
  48. ClassifyName string `description:"分类名称"`
  49. Sort int `description:"排序"`
  50. ParentId int `description:"父级分类id"`
  51. CreateTime time.Time `description:"创建时间"`
  52. ModifyTime time.Time `description:"修改时间"`
  53. Abstract string `description:"简介"`
  54. Descript string `description:"描述"`
  55. ClassifyLabel string `description:"分类标签"`
  56. ShowType int `description:"展示类型:1-列表 2-专栏"`
  57. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  58. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  59. YbFiccSort int `description:"小程序FICC页排序"`
  60. YbFiccIcon string `description:"小程序FICC页icon"`
  61. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  62. YbIconUrl string `description:"小程序已购页icon"`
  63. YbBgUrl string `description:"小程序已购详情背景图"`
  64. YbListImg string `description:"小程序研报列表封面图"`
  65. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  66. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  67. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  68. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  69. Enabled int `description:"是否可用,1可用,0禁用"`
  70. Child []*ClassifyItem
  71. ClassifyMenuList []*ClassifyMenu
  72. }
  73. type ClassifyItem struct {
  74. Classify
  75. ClassifyMenuId int `description:"二级分类-子目录ID"`
  76. ClassifyMenuList []*ClassifyMenu
  77. }
  78. type ClassifyListResp struct {
  79. List []*ClassifyList
  80. }
  81. // 获取分类列表
  82. func GetClassifyList(startSize, pageSize int, keyWord, companyType string, hideDayWeek int) (items []*ClassifyList, err error) {
  83. sql := ``
  84. companyTypeSqlStr := ``
  85. if companyType == "ficc" {
  86. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  87. } else if companyType == "权益" {
  88. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  89. }
  90. if keyWord != "" {
  91. sql = `SELECT * FROM (
  92. SELECT * FROM classify
  93. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  94. UNION
  95. SELECT * FROM classify
  96. WHERE id IN(SELECT parent_id FROM classify
  97. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  98. )AS t
  99. ORDER BY sort ASC,create_time ASC
  100. LIMIT ?,? `
  101. } else {
  102. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  103. if hideDayWeek == 1 {
  104. sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  105. }
  106. sql += ` ORDER BY sort ASC, create_time ASC LIMIT ?,? `
  107. }
  108. o := orm.NewOrmUsingDB("rddp")
  109. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  110. return
  111. }
  112. func GetClassifyListCount(keyWord, companyType string, hideDayWeek int) (count int, err error) {
  113. sqlCount := ``
  114. companyTypeSqlStr := ``
  115. if companyType == "ficc" {
  116. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  117. } else if companyType == "权益" {
  118. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  119. }
  120. if keyWord != "" {
  121. sqlCount = `SELECT COUNT(1) AS count FROM (
  122. SELECT * FROM classify
  123. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  124. UNION
  125. SELECT * FROM classify
  126. WHERE id IN(SELECT parent_id FROM classify
  127. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  128. )AS t `
  129. } else {
  130. sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  131. if hideDayWeek == 1 {
  132. sqlCount += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  133. }
  134. }
  135. o := orm.NewOrmUsingDB("rddp")
  136. err = o.Raw(sqlCount).QueryRow(&count)
  137. return
  138. }
  139. type FindByIdClassifyReq struct {
  140. ClassifyId int `description:"分类ID"`
  141. }
  142. func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
  143. parentIdLen := len(parentId)
  144. if parentIdLen == 0 {
  145. return
  146. }
  147. o := orm.NewOrmUsingDB("rddp")
  148. sql := ``
  149. if keyWord != "" {
  150. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  151. } else {
  152. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) ORDER BY create_time ASC `
  153. }
  154. _, err = o.Raw(sql, parentId).QueryRows(&items)
  155. return
  156. }
  157. // GetAllClassify 获取所有分类
  158. func GetAllClassify() (list []*Classify, err error) {
  159. o := orm.NewOrmUsingDB("rddp")
  160. sql := ` SELECT * FROM classify `
  161. _, err = o.Raw(sql).QueryRows(&list)
  162. return
  163. }
  164. // SimpleClassifyList 简版分类列表
  165. type SimpleClassifyList struct {
  166. Id int `description:"分类ID"`
  167. ClassifyName string `description:"分类名称"`
  168. ParentId int `description:"父级ID"`
  169. Sort int `description:"排序"`
  170. Child []*SimpleClassifyList
  171. }
  172. // GetClassifyByCondition 获取分类列表
  173. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  174. o := orm.NewOrmUsingDB("rddp")
  175. sql := `SELECT * FROM classify WHERE 1 = 1 `
  176. if condition != `` {
  177. sql += condition
  178. }
  179. order := `sort ASC, create_time ASC`
  180. if orderRule != `` {
  181. order = orderRule
  182. }
  183. sql += ` ORDER BY ` + order
  184. _, err = o.Raw(sql, pars).QueryRows(&items)
  185. return
  186. }