classify.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. pars := make([]interface{}, 0)
  199. if keyWord != "" {
  200. sql = `SELECT * FROM (
  201. SELECT * FROM classify
  202. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  203. UNION
  204. SELECT * FROM classify
  205. WHERE id IN( SELECT parent_id FROM classify
  206. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  207. )AS t
  208. ORDER BY sort ASC,create_time ASC
  209. LIMIT ?,? `
  210. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  211. } else {
  212. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  213. if hideDayWeek == 1 {
  214. sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  215. }
  216. sql += ` ORDER BY sort ASC, create_time ASC LIMIT ?,? `
  217. }
  218. pars = append(pars, startSize, pageSize)
  219. o := orm.NewOrmUsingDB("rddp")
  220. _, err = o.Raw(sql, pars...).QueryRows(&items)
  221. return
  222. }
  223. func GetClassifyListCount(keyWord, companyType string, hideDayWeek int) (count int, err error) {
  224. sqlCount := ``
  225. companyTypeSqlStr := ``
  226. if companyType == "ficc" {
  227. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  228. } else if companyType == "权益" {
  229. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  230. }
  231. pars := make([]interface{}, 0)
  232. if keyWord != "" {
  233. sqlCount = `SELECT COUNT(1) AS count FROM (
  234. SELECT * FROM classify
  235. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  236. UNION
  237. SELECT * FROM classify
  238. WHERE id IN(SELECT parent_id FROM classify
  239. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  240. )AS t `
  241. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  242. } else {
  243. sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  244. if hideDayWeek == 1 {
  245. sqlCount += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  246. }
  247. }
  248. o := orm.NewOrmUsingDB("rddp")
  249. err = o.Raw(sqlCount, pars...).QueryRow(&count)
  250. return
  251. }
  252. type CheckDeleteClassifyReq struct {
  253. ClassifyId int `description:"分类ID"`
  254. }
  255. type CheckDeleteClassifyResp struct {
  256. Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"`
  257. Msg string `description:"描述信息"`
  258. }
  259. type DeleteClassifyReq struct {
  260. ClassifyId int `description:"分类ID"`
  261. }
  262. type EditClassifyReq struct {
  263. ClassifyId int `description:"分类ID"`
  264. ClassifyAddReq
  265. }
  266. type FindByIdClassifyReq struct {
  267. ClassifyId int `description:"分类ID"`
  268. }
  269. func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  270. o := orm.NewOrmUsingDB("rddp")
  271. sql := ``
  272. pars := make([]interface{}, 0)
  273. if keyWord != "" {
  274. sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC `
  275. pars = append(pars, utils.GetLikeKeyword(keyWord))
  276. } else {
  277. sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  278. }
  279. pars = append(pars, parentId)
  280. _, err = o.Raw(sql, pars...).QueryRows(&items)
  281. return
  282. }
  283. func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
  284. parentIdLen := len(parentId)
  285. if parentIdLen == 0 {
  286. return
  287. }
  288. o := orm.NewOrmUsingDB("rddp")
  289. sql := ``
  290. pars := make([]interface{}, 0)
  291. pars = append(pars, parentId)
  292. if keyWord != "" {
  293. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE ? ORDER BY create_time ASC `
  294. pars = append(pars, utils.GetLikeKeyword(keyWord))
  295. } else {
  296. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) ORDER BY create_time ASC `
  297. }
  298. _, err = o.Raw(sql, pars...).QueryRows(&items)
  299. return
  300. }
  301. // EditClassifyPermissionReq 编辑分类权限请求
  302. type EditClassifyPermissionReq struct {
  303. ClassifyId int `description:"分类ID"`
  304. ChartPermissionIdList []int `description:"权限id数组"`
  305. }
  306. // GetAllClassify 获取所有分类
  307. func GetAllClassify() (list []*Classify, err error) {
  308. o := orm.NewOrmUsingDB("rddp")
  309. sql := ` SELECT * FROM classify `
  310. _, err = o.Raw(sql).QueryRows(&list)
  311. return
  312. }
  313. // GetClassifyByKeyword 名称获取分类
  314. func GetClassifyByKeyword(keyword string) (item Classify, err error) {
  315. o := orm.NewOrmUsingDB("rddp")
  316. sql := ` SELECT * FROM classify WHERE classify_name = ? LIMIT 1 `
  317. err = o.Raw(sql, keyword).QueryRow(&item)
  318. return
  319. }
  320. // UpdateClassify 更新分类
  321. func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
  322. o := orm.NewOrmUsingDB("rddp")
  323. _, err = o.Update(classifyInfo, cols...)
  324. return
  325. }
  326. // SimpleClassifyList 简版分类列表
  327. type SimpleClassifyList struct {
  328. Id int `description:"分类ID"`
  329. ClassifyName string `description:"分类名称"`
  330. ParentId int `description:"父级ID"`
  331. Sort int `description:"排序"`
  332. Child []*SimpleClassifyList
  333. }
  334. // GetClassifyByCondition 获取分类列表
  335. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  336. o := orm.NewOrmUsingDB("rddp")
  337. sql := `SELECT * FROM classify WHERE 1 = 1 `
  338. if condition != `` {
  339. sql += condition
  340. }
  341. order := `sort ASC, create_time ASC`
  342. if orderRule != `` {
  343. order = orderRule
  344. }
  345. sql += ` ORDER BY ` + order
  346. _, err = o.Raw(sql, pars).QueryRows(&items)
  347. return
  348. }
  349. // UpdateChildClassifyRelateSetting 更新子分类关联设置
  350. func UpdateChildClassifyRelateSetting(parentId, relateTel, relateVideo int) (err error) {
  351. o := orm.NewOrmUsingDB("rddp")
  352. sql := `UPDATE classify SET relate_tel = ?, relate_video = ? WHERE parent_id = ?`
  353. _, err = o.Raw(sql, relateTel, relateVideo, parentId).Exec()
  354. return
  355. }
  356. // RelateTelSecClassifyWithPermissions 关联了电话会的二级分类及权限
  357. type RelateTelSecClassifyWithPermissions struct {
  358. Id int `description:"分类ID"`
  359. ClassifyName string `description:"分类名称"`
  360. ChartPermissionIds string `description:"权限IDs"`
  361. }