classify.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. package models
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type Classify struct {
  9. Id int `orm:"column(id);pk"`
  10. ClassifyName string `description:"分类名称"`
  11. Sort int `json:"-"`
  12. ParentId int `description:"父级分类id"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. Abstract string `description:"栏目简介"`
  16. Descript string `description:"分享描述"`
  17. ReportAuthor string `description:"栏目作者"`
  18. AuthorDescript string `description:"作者简介"`
  19. ColumnImgUrl string `description:"栏目配图"`
  20. HeadImgUrl string `description:"头部banner"`
  21. AvatarImgUrl string `description:"头像"`
  22. ReportImgUrl string `description:"报告配图"`
  23. HomeImgUrl string `description:"首页配图"`
  24. ClassifyLabel string `description:"分类标签"`
  25. ShowType int `description:"展示类型:1-列表 2-专栏"`
  26. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  27. VipTitle string `description:"研究员头衔"`
  28. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  29. YbFiccSort int `description:"小程序FICC页排序"`
  30. YbFiccIcon string `description:"小程序FICC页icon"`
  31. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  32. YbIconUrl string `description:"小程序已购页icon"`
  33. YbBgUrl string `description:"小程序已购详情背景图"`
  34. YbListImg string `description:"小程序研报列表封面图"`
  35. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  36. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  37. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  38. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  39. IsMassSend int `description:"1:群发,0:非群发"`
  40. }
  41. type ClassifyAddReq struct {
  42. ClassifyName string `description:"分类名称"`
  43. ParentId int `description:"父级分类id,没有父级分类传0"`
  44. Abstract string `description:"栏目简介"`
  45. Descript string `description:"分享描述"`
  46. ReportAuthor string `description:"栏目作者"`
  47. AuthorDescript string `description:"作者简介"`
  48. ColumnImgUrl string `description:"栏目配图"`
  49. ReportImgUrl string `description:"报告配图"`
  50. HeadImgUrl string `description:"头部banner"`
  51. AvatarImgUrl string `description:"头像"`
  52. HomeImgUrl string `description:"首页配图"`
  53. ClassifyLabel string `description:"分类标签"`
  54. ShowType int `description:"展示类型:1-列表 2-专栏"`
  55. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  56. VipTitle string `description:"研究员头衔"`
  57. Sort int `description:"后台排序"`
  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. MenuList []*ClassifyMenuSaveReq `description:"子目录列表"`
  68. ClassifyMenuId int `description:"二级分类-子目录ID"`
  69. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  70. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  71. }
  72. func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
  73. sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
  74. o := orm.NewOrmUsingDB("rddp")
  75. err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
  76. return
  77. }
  78. func GetClassifyById(classifyId int) (item *Classify, err error) {
  79. sql := `SELECT * FROM classify WHERE id=? `
  80. o := orm.NewOrmUsingDB("rddp")
  81. err = o.Raw(sql, classifyId).QueryRow(&item)
  82. return
  83. }
  84. // 添加分类
  85. func AddClassify(item *Classify) (err error) {
  86. o := orm.NewOrmUsingDB("rddp")
  87. id, err := o.Insert(item)
  88. if err != nil {
  89. return
  90. }
  91. item.Id = int(id)
  92. return
  93. }
  94. func GetReportCountByClassifyId(classifyId int) (count int, err error) {
  95. o := orm.NewOrmUsingDB("rddp")
  96. sql := `SELECT COUNT(1) AS count FROM report WHERE classify_id_second=? `
  97. err = o.Raw(sql, classifyId).QueryRow(&count)
  98. return
  99. }
  100. func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. sql := `SELECT COUNT(1) as num FROM classify AS a
  103. INNER JOIN report AS b ON a.id=b.classify_id_second
  104. WHERE a.parent_id=? `
  105. err = o.Raw(sql, classifyId).QueryRow(&count)
  106. return
  107. }
  108. func GetClassifySubCountByParentId(classifyId int) (count int, err error) {
  109. sqlCount := `
  110. SELECT COUNT(1) as num FROM classify AS a
  111. WHERE a.parent_id=? `
  112. o := orm.NewOrmUsingDB("rddp")
  113. err = o.Raw(sqlCount, classifyId).QueryRow(&count)
  114. return
  115. }
  116. // 删除分类
  117. func DeleteClassify(classifyId int) (err error) {
  118. sql := `DELETE FROM classify WHERE id=? `
  119. o := orm.NewOrmUsingDB("rddp")
  120. _, err = o.Raw(sql, classifyId).Exec()
  121. if err != nil {
  122. return
  123. }
  124. deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
  125. _, err = o.Raw(deleteImgSql, classifyId).Exec()
  126. return
  127. }
  128. // classifyName, abstract, descript string, parentId, classifyId int
  129. // 修改分类
  130. func EditClassify(req *EditClassifyReq) (err error) {
  131. o := orm.NewOrmUsingDB("rddp")
  132. sql := `UPDATE classify SET classify_name = ?,abstract=?, parent_id= ?,descript=?,report_author=?,author_descript=?,column_img_url=?,head_img_url=?,avatar_img_url=?,report_img_url=?,home_img_url=?,classify_label=?,show_type=?,has_teleconference=?,vip_title=?,modify_time= NOW() WHERE id = ? `
  133. _, err = o.Raw(sql, req.ClassifyName, req.Abstract, req.ParentId, req.Descript, req.ReportAuthor, req.AuthorDescript, req.ColumnImgUrl, req.HeadImgUrl, req.AvatarImgUrl, req.ReportImgUrl, req.HomeImgUrl, req.ClassifyLabel, req.ShowType, req.HasTeleconference, req.VipTitle, req.ClassifyId).Exec()
  134. return
  135. }
  136. //获取父级分类
  137. func ParentClassify() (items []*Classify, err error) {
  138. sql := `SELECT * FROM classify WHERE parent_id=0 order by id desc `
  139. o := orm.NewOrmUsingDB("rddp")
  140. _, err = o.Raw(sql).QueryRows(&items)
  141. return
  142. }
  143. // 根据id获取分类详情
  144. func FindByIdClassify(classifyId int) (item *Classify, err error) {
  145. sql := `SELECT * FROM classify WHERE id=? `
  146. o := orm.NewOrmUsingDB("rddp")
  147. err = o.Raw(sql, classifyId).QueryRow(&item)
  148. return
  149. }
  150. type ClassifyList struct {
  151. Id int `orm:"column(id);pk"`
  152. ClassifyName string `description:"分类名称"`
  153. Sort int `description:"排序"`
  154. ParentId int `description:"父级分类id"`
  155. CreateTime time.Time `description:"创建时间"`
  156. ModifyTime time.Time `description:"修改时间"`
  157. Abstract string `description:"简介"`
  158. Descript string `description:"描述"`
  159. ClassifyLabel string `description:"分类标签"`
  160. ShowType int `description:"展示类型:1-列表 2-专栏"`
  161. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  162. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  163. YbFiccSort int `description:"小程序FICC页排序"`
  164. YbFiccIcon string `description:"小程序FICC页icon"`
  165. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  166. YbIconUrl string `description:"小程序已购页icon"`
  167. YbBgUrl string `description:"小程序已购详情背景图"`
  168. YbListImg string `description:"小程序研报列表封面图"`
  169. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  170. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  171. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  172. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  173. Child []*ClassifyItem
  174. ClassifyMenuList []*ClassifyMenu
  175. }
  176. type ClassifyItem struct {
  177. Classify
  178. ClassifyMenuId int `description:"二级分类-子目录ID"`
  179. ClassifyMenuList []*ClassifyMenu
  180. }
  181. type ClassifyListResp struct {
  182. List []*ClassifyList
  183. Paging *paging.PagingItem `description:"分页数据"`
  184. }
  185. type ClassifyPermissionListResp struct {
  186. List []*ClassifyList
  187. Paging *paging.PagingItem `description:"分页数据"`
  188. }
  189. // 获取分类列表
  190. func GetClassifyList(startSize, pageSize int, keyWord, companyType string, hideDayWeek int) (items []*ClassifyList, err error) {
  191. sql := ``
  192. companyTypeSqlStr := ``
  193. if companyType == "ficc" {
  194. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  195. } else if companyType == "权益" {
  196. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  197. }
  198. if keyWord != "" {
  199. sql = `SELECT * FROM (
  200. SELECT * FROM classify
  201. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  202. UNION
  203. SELECT * FROM classify
  204. WHERE id IN(SELECT parent_id FROM classify
  205. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  206. )AS t
  207. ORDER BY sort ASC,create_time ASC
  208. LIMIT ?,? `
  209. } else {
  210. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  211. if hideDayWeek == 1 {
  212. sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  213. }
  214. sql += ` ORDER BY sort ASC, create_time ASC LIMIT ?,? `
  215. }
  216. o := orm.NewOrmUsingDB("rddp")
  217. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  218. return
  219. }
  220. func GetClassifyListCount(keyWord, companyType string, hideDayWeek int) (count int, err error) {
  221. sqlCount := ``
  222. companyTypeSqlStr := ``
  223. if companyType == "ficc" {
  224. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  225. } else if companyType == "权益" {
  226. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  227. }
  228. if keyWord != "" {
  229. sqlCount = `SELECT COUNT(1) AS count FROM (
  230. SELECT * FROM classify
  231. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  232. UNION
  233. SELECT * FROM classify
  234. WHERE id IN(SELECT parent_id FROM classify
  235. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  236. )AS t `
  237. } else {
  238. sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  239. if hideDayWeek == 1 {
  240. sqlCount += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  241. }
  242. }
  243. o := orm.NewOrmUsingDB("rddp")
  244. err = o.Raw(sqlCount).QueryRow(&count)
  245. return
  246. }
  247. type CheckDeleteClassifyReq struct {
  248. ClassifyId int `description:"分类ID"`
  249. }
  250. type CheckDeleteClassifyResp struct {
  251. Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"`
  252. Msg string `description:"描述信息"`
  253. }
  254. type DeleteClassifyReq struct {
  255. ClassifyId int `description:"分类ID"`
  256. }
  257. type EditClassifyReq struct {
  258. ClassifyId int `description:"分类ID"`
  259. ClassifyAddReq
  260. }
  261. type FindByIdClassifyReq struct {
  262. ClassifyId int `description:"分类ID"`
  263. }
  264. func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  265. o := orm.NewOrmUsingDB("rddp")
  266. sql := ``
  267. if keyWord != "" {
  268. sql = `SELECT * FROM classify WHERE parent_id=? AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  269. } else {
  270. sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  271. }
  272. _, err = o.Raw(sql, parentId).QueryRows(&items)
  273. return
  274. }
  275. func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
  276. parentIdLen := len(parentId)
  277. if parentIdLen == 0 {
  278. return
  279. }
  280. o := orm.NewOrmUsingDB("rddp")
  281. sql := ``
  282. if keyWord != "" {
  283. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  284. } else {
  285. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) ORDER BY create_time ASC `
  286. }
  287. _, err = o.Raw(sql, parentId).QueryRows(&items)
  288. return
  289. }
  290. // EditClassifyPermissionReq 编辑分类权限请求
  291. type EditClassifyPermissionReq struct {
  292. ClassifyId int `description:"分类ID"`
  293. ChartPermissionIdList []int `description:"权限id数组"`
  294. }
  295. // GetAllClassify 获取所有分类
  296. func GetAllClassify() (list []*Classify, err error) {
  297. o := orm.NewOrmUsingDB("rddp")
  298. sql := ` SELECT * FROM classify `
  299. _, err = o.Raw(sql).QueryRows(&list)
  300. return
  301. }
  302. // GetClassifyByKeyword 名称获取分类
  303. func GetClassifyByKeyword(keyword string) (item Classify, err error) {
  304. o := orm.NewOrmUsingDB("rddp")
  305. sql := ` SELECT * FROM classify WHERE classify_name = ? LIMIT 1 `
  306. err = o.Raw(sql, keyword).QueryRow(&item)
  307. return
  308. }
  309. // UpdateClassify 更新分类
  310. func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
  311. o := orm.NewOrmUsingDB("rddp")
  312. _, err = o.Update(classifyInfo, cols...)
  313. return
  314. }
  315. // SimpleClassifyList 简版分类列表
  316. type SimpleClassifyList struct {
  317. Id int `description:"分类ID"`
  318. ClassifyName string `description:"分类名称"`
  319. ParentId int `description:"父级ID"`
  320. Sort int `description:"排序"`
  321. Child []*SimpleClassifyList
  322. }
  323. // GetClassifyByCondition 获取分类列表
  324. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  325. o := orm.NewOrmUsingDB("rddp")
  326. sql := `SELECT * FROM classify WHERE 1 = 1 `
  327. if condition != `` {
  328. sql += condition
  329. }
  330. order := `sort ASC, create_time ASC`
  331. if orderRule != `` {
  332. order = orderRule
  333. }
  334. sql += ` ORDER BY ` + order
  335. _, err = o.Raw(sql, pars).QueryRows(&items)
  336. return
  337. }
  338. // UpdateChildClassifyRelateSetting 更新子分类关联设置
  339. func UpdateChildClassifyRelateSetting(parentId, relateTel, relateVideo int) (err error) {
  340. o := orm.NewOrmUsingDB("rddp")
  341. sql := `UPDATE classify SET relate_tel = ?, relate_video = ? WHERE parent_id = ?`
  342. _, err = o.Raw(sql, relateTel, relateVideo, parentId).Exec()
  343. return
  344. }
  345. // RelateTelSecClassifyWithPermissions 关联了电话会的二级分类及权限
  346. type RelateTelSecClassifyWithPermissions struct {
  347. Id int `description:"分类ID"`
  348. ClassifyName string `description:"分类名称"`
  349. ChartPermissionIds string `description:"权限IDs"`
  350. }