classify.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. Enabled int `description:"是否可用,1可用,0禁用"`
  40. Level int `description:"层级"`
  41. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  42. ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  43. }
  44. func GetClassifyById(classifyId int) (item *Classify, err error) {
  45. sql := `SELECT * FROM classify WHERE id=? `
  46. o := orm.NewOrmUsingDB("rddp")
  47. err = o.Raw(sql, classifyId).QueryRow(&item)
  48. return
  49. }
  50. type ClassifyList struct {
  51. Id int `orm:"column(id);pk"`
  52. ClassifyName string `description:"分类名称"`
  53. Sort int `description:"排序"`
  54. ParentId int `description:"父级分类id"`
  55. CreateTime time.Time `description:"创建时间"`
  56. ModifyTime time.Time `description:"修改时间"`
  57. Abstract string `description:"简介"`
  58. Descript string `description:"描述"`
  59. ClassifyLabel string `description:"分类标签"`
  60. ShowType int `description:"展示类型:1-列表 2-专栏"`
  61. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  62. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  63. YbFiccSort int `description:"小程序FICC页排序"`
  64. YbFiccIcon string `description:"小程序FICC页icon"`
  65. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  66. YbIconUrl string `description:"小程序已购页icon"`
  67. YbBgUrl string `description:"小程序已购详情背景图"`
  68. YbListImg string `description:"小程序研报列表封面图"`
  69. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  70. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  71. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  72. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  73. Enabled int `description:"是否可用,1可用,0禁用"`
  74. Child []*ClassifyItem
  75. ClassifyMenuList []*ClassifyMenu
  76. }
  77. type ClassifyItem struct {
  78. Classify
  79. ClassifyMenuId int `description:"二级分类-子目录ID"`
  80. ClassifyMenuList []*ClassifyMenu
  81. }
  82. type ClassifyListResp struct {
  83. List []*ClassifyListV2
  84. }
  85. type ClassifyListV2 struct {
  86. Id int `orm:"column(id);pk"`
  87. ClassifyName string `description:"分类名称"`
  88. Sort int `description:"排序"`
  89. ParentId int `description:"父级分类id"`
  90. CreateTime time.Time `description:"创建时间"`
  91. ModifyTime time.Time `description:"修改时间"`
  92. Abstract string `description:"简介"`
  93. Descript string `description:"描述"`
  94. ClassifyLabel string `description:"分类标签"`
  95. ShowType int `description:"展示类型:1-列表 2-专栏"`
  96. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  97. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  98. YbFiccSort int `description:"小程序FICC页排序"`
  99. YbFiccIcon string `description:"小程序FICC页icon"`
  100. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  101. YbIconUrl string `description:"小程序已购页icon"`
  102. YbBgUrl string `description:"小程序已购详情背景图"`
  103. YbListImg string `description:"小程序研报列表封面图"`
  104. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  105. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  106. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  107. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  108. Enabled int `description:"是否可用,1可用,0禁用"`
  109. Child []*ClassifyListV2 `gorm:"-"`
  110. ClassifyMenuId int `description:"二级分类-子目录ID"`
  111. ClassifyMenuList []*ClassifyMenu `gorm:"-"`
  112. ChartPermissionIdList []int `description:"绑定的权限ID" gorm:"-"`
  113. Level int `description:"层级"`
  114. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  115. ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  116. }
  117. // 获取分类列表
  118. func GetClassifyList(startSize, pageSize int, keyWord, companyType string, hideDayWeek int) (items []*ClassifyList, err error) {
  119. sql := ``
  120. companyTypeSqlStr := ``
  121. if companyType == "ficc" {
  122. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  123. } else if companyType == "权益" {
  124. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  125. }
  126. if keyWord != "" {
  127. sql = `SELECT * FROM (
  128. SELECT * FROM classify
  129. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  130. UNION
  131. SELECT * FROM classify
  132. WHERE id IN(SELECT parent_id FROM classify
  133. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  134. )AS t
  135. ORDER BY sort ASC,create_time ASC
  136. LIMIT ?,? `
  137. } else {
  138. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  139. if hideDayWeek == 1 {
  140. sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  141. }
  142. sql += ` ORDER BY sort ASC, create_time ASC LIMIT ?,? `
  143. }
  144. o := orm.NewOrmUsingDB("rddp")
  145. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  146. return
  147. }
  148. func GetClassifyListCount(keyWord, companyType string, hideDayWeek int) (count int, err error) {
  149. sqlCount := ``
  150. companyTypeSqlStr := ``
  151. if companyType == "ficc" {
  152. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  153. } else if companyType == "权益" {
  154. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  155. }
  156. if keyWord != "" {
  157. sqlCount = `SELECT COUNT(1) AS count FROM (
  158. SELECT * FROM classify
  159. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  160. UNION
  161. SELECT * FROM classify
  162. WHERE id IN(SELECT parent_id FROM classify
  163. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  164. )AS t `
  165. } else {
  166. sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  167. if hideDayWeek == 1 {
  168. sqlCount += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  169. }
  170. }
  171. o := orm.NewOrmUsingDB("rddp")
  172. err = o.Raw(sqlCount).QueryRow(&count)
  173. return
  174. }
  175. type FindByIdClassifyReq struct {
  176. ClassifyId int `description:"分类ID"`
  177. }
  178. func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
  179. parentIdLen := len(parentId)
  180. if parentIdLen == 0 {
  181. return
  182. }
  183. o := orm.NewOrmUsingDB("rddp")
  184. sql := ``
  185. if keyWord != "" {
  186. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  187. } else {
  188. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) ORDER BY create_time ASC `
  189. }
  190. _, err = o.Raw(sql, parentId).QueryRows(&items)
  191. return
  192. }
  193. // GetAllClassify 获取所有分类
  194. func GetAllClassify() (list []*Classify, err error) {
  195. o := orm.NewOrmUsingDB("rddp")
  196. sql := ` SELECT * FROM classify `
  197. _, err = o.Raw(sql).QueryRows(&list)
  198. return
  199. }
  200. // SimpleClassifyList 简版分类列表
  201. type SimpleClassifyList struct {
  202. Id int `description:"分类ID"`
  203. ClassifyName string `description:"分类名称"`
  204. ParentId int `description:"父级ID"`
  205. Sort int `description:"排序"`
  206. CreateTime time.Time `description:"创建时间"`
  207. Level int `description:"层级"`
  208. Child []*SimpleClassifyList
  209. }
  210. // GetClassifyByCondition 获取分类列表
  211. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  212. o := orm.NewOrmUsingDB("rddp")
  213. sql := `SELECT * FROM classify WHERE 1 = 1 `
  214. if condition != `` {
  215. sql += condition
  216. }
  217. order := `sort ASC, create_time ASC`
  218. if orderRule != `` {
  219. order = orderRule
  220. }
  221. sql += ` ORDER BY ` + order
  222. _, err = o.Raw(sql, pars).QueryRows(&items)
  223. return
  224. }
  225. // GetAllClassifyByRelateVideo
  226. // @Description: 获取关联视频的所有分类
  227. // @author: Roc
  228. // @datetime 2024-07-12 17:19:06
  229. // @return list []*Classify
  230. // @return err error
  231. func GetAllClassifyByRelateVideo() (list []*Classify, err error) {
  232. o := orm.NewOrmUsingDB("rddp")
  233. sql := ` SELECT * FROM classify where relate_video = 1`
  234. _, err = o.Raw(sql).QueryRows(&list)
  235. return
  236. }
  237. // GetClassifyListByParentIdList
  238. // @Description: 获取分类列表
  239. // @author: Roc
  240. // @datetime 2024-06-19 09:49:33
  241. // @param keyWord string
  242. // @param enabled int
  243. // @return items []*ClassifyList
  244. // @return err error
  245. func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*Classify, err error) {
  246. num := len(parentClassifyIdList)
  247. if num <= 0 {
  248. return
  249. }
  250. sql := `SELECT * FROM classify WHERE id in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort ASC, create_time ASC`
  251. o := orm.NewOrmUsingDB("rddp")
  252. _, err = o.Raw(sql, parentClassifyIdList).QueryRows(&items)
  253. return
  254. }