classify.go 16 KB

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