classify.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. package models
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  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. Enabled int `description:"是否可用,1可用,0禁用"`
  42. Level int `description:"层级"`
  43. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  44. ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  45. }
  46. type ClassifyAddReq struct {
  47. ClassifyName string `description:"分类名称"`
  48. ParentId int `description:"父级分类id,没有父级分类传0"`
  49. ChartPermissionIdList []int `description:"权限id数组"`
  50. /*Abstract string `description:"栏目简介"`
  51. Descript string `description:"分享描述"`
  52. ReportAuthor string `description:"栏目作者"`
  53. AuthorDescript string `description:"作者简介"`
  54. ColumnImgUrl string `description:"栏目配图"`
  55. ReportImgUrl string `description:"报告配图"`
  56. HeadImgUrl string `description:"头部banner"`
  57. AvatarImgUrl string `description:"头像"`
  58. HomeImgUrl string `description:"首页配图"`
  59. ClassifyLabel string `description:"分类标签"`
  60. ShowType int `description:"展示类型:1-列表 2-专栏"`
  61. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  62. VipTitle string `description:"研究员头衔"`
  63. Sort int `description:"后台排序"`
  64. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  65. YbFiccSort int `description:"小程序FICC页排序"`
  66. YbFiccIcon string `description:"小程序FICC页icon"`
  67. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  68. YbIconUrl string `description:"小程序已购页icon"`
  69. YbBgUrl string `description:"小程序已购详情背景图"`
  70. YbListImg string `description:"小程序研报列表封面图"`
  71. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  72. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  73. MenuList []*ClassifyMenuSaveReq `description:"子目录列表"`
  74. ClassifyMenuId int `description:"二级分类-子目录ID"`
  75. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  76. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`*/
  77. }
  78. func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
  79. sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
  80. o := orm.NewOrmUsingDB("rddp")
  81. err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
  82. return
  83. }
  84. func GetClassifyById(classifyId int) (item *Classify, err error) {
  85. sql := `SELECT * FROM classify WHERE id=? `
  86. o := orm.NewOrmUsingDB("rddp")
  87. err = o.Raw(sql, classifyId).QueryRow(&item)
  88. return
  89. }
  90. // 添加分类
  91. func AddClassify(item *Classify) (err error) {
  92. o := orm.NewOrmUsingDB("rddp")
  93. id, err := o.Insert(item)
  94. if err != nil {
  95. return
  96. }
  97. item.Id = int(id)
  98. return
  99. }
  100. func GetReportCountByClassifyId(classifyId int) (count int, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. sql := `SELECT COUNT(1) AS count FROM report WHERE classify_id_second=? `
  103. err = o.Raw(sql, classifyId).QueryRow(&count)
  104. return
  105. }
  106. func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) {
  107. o := orm.NewOrmUsingDB("rddp")
  108. sql := `SELECT COUNT(1) as num FROM classify AS a
  109. INNER JOIN report AS b ON a.id=b.classify_id_second
  110. WHERE a.parent_id=? `
  111. err = o.Raw(sql, classifyId).QueryRow(&count)
  112. return
  113. }
  114. func GetClassifySubCountByParentId(classifyId int) (count int, err error) {
  115. sqlCount := `
  116. SELECT COUNT(1) as num FROM classify AS a
  117. WHERE a.parent_id=? `
  118. o := orm.NewOrmUsingDB("rddp")
  119. err = o.Raw(sqlCount, classifyId).QueryRow(&count)
  120. return
  121. }
  122. // 删除分类
  123. func DeleteClassify(classifyId int) (err error) {
  124. sql := `DELETE FROM classify WHERE id=? `
  125. o := orm.NewOrmUsingDB("rddp")
  126. _, err = o.Raw(sql, classifyId).Exec()
  127. if err != nil {
  128. return
  129. }
  130. deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
  131. _, err = o.Raw(deleteImgSql, classifyId).Exec()
  132. return
  133. }
  134. // classifyName, abstract, descript string, parentId, classifyId int
  135. // 修改分类
  136. func EditClassify(req *EditClassifyReq) (err error) {
  137. o := orm.NewOrmUsingDB("rddp")
  138. //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 = ? `
  139. //_, 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()
  140. sql := `UPDATE classify SET classify_name = ?,parent_id= ?,modify_time= NOW() WHERE id = ? `
  141. _, err = o.Raw(sql, req.ClassifyName, req.ParentId, req.ClassifyId).Exec()
  142. return
  143. }
  144. // ParentClassify
  145. // @Description: 获取父级分类
  146. // @author: Roc
  147. // @datetime 2024-06-18 15:03:49
  148. // @return items []*Classify
  149. // @return err error
  150. func ParentClassify() (items []*Classify, err error) {
  151. sql := `SELECT * FROM classify WHERE parent_id=0 order by id desc `
  152. o := orm.NewOrmUsingDB("rddp")
  153. _, err = o.Raw(sql).QueryRows(&items)
  154. return
  155. }
  156. // 根据id获取分类详情
  157. func FindByIdClassify(classifyId int) (item *Classify, err error) {
  158. sql := `SELECT * FROM classify WHERE id=? `
  159. o := orm.NewOrmUsingDB("rddp")
  160. err = o.Raw(sql, classifyId).QueryRow(&item)
  161. return
  162. }
  163. type ClassifyList struct {
  164. Id int `orm:"column(id);pk"`
  165. ClassifyName string `description:"分类名称"`
  166. Sort int `description:"排序"`
  167. ParentId int `description:"父级分类id"`
  168. CreateTime time.Time `description:"创建时间"`
  169. ModifyTime time.Time `description:"修改时间"`
  170. Abstract string `description:"简介"`
  171. Descript string `description:"描述"`
  172. ClassifyLabel string `description:"分类标签"`
  173. ShowType int `description:"展示类型:1-列表 2-专栏"`
  174. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  175. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  176. YbFiccSort int `description:"小程序FICC页排序"`
  177. YbFiccIcon string `description:"小程序FICC页icon"`
  178. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  179. YbIconUrl string `description:"小程序已购页icon"`
  180. YbBgUrl string `description:"小程序已购详情背景图"`
  181. YbListImg string `description:"小程序研报列表封面图"`
  182. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  183. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  184. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  185. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  186. Enabled int `description:"是否可用,1可用,0禁用"`
  187. Child []*ClassifyList
  188. ClassifyMenuId int `description:"二级分类-子目录ID"`
  189. ClassifyMenuList []*ClassifyMenu
  190. ChartPermissionIdList []int `description:"绑定的权限ID"`
  191. Level int `description:"层级"`
  192. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  193. }
  194. type ClassifyItem struct {
  195. Classify
  196. ClassifyMenuId int `description:"二级分类-子目录ID"`
  197. ClassifyMenuList []*ClassifyMenu
  198. ChartPermissionIdList []int `description:"绑定的权限ID"`
  199. Child []*ClassifyItem
  200. }
  201. type ClassifyListResp struct {
  202. List []*ClassifyList
  203. }
  204. type ClassifyPermissionListResp struct {
  205. List []*ClassifyList
  206. Paging *paging.PagingItem `description:"分页数据"`
  207. }
  208. // 获取分类列表
  209. func GetClassifyList(keyWord string, enabled int) (items []*ClassifyList, err error) {
  210. sql := ``
  211. companyTypeSqlStr := ``
  212. if enabled == 1 {
  213. companyTypeSqlStr += ` AND enabled = 1 `
  214. }
  215. pars := make([]interface{}, 0)
  216. if keyWord != "" {
  217. sql = `SELECT * FROM (
  218. SELECT * FROM classify
  219. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  220. UNION
  221. SELECT * FROM classify
  222. WHERE id IN( SELECT parent_id FROM classify
  223. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  224. )AS t
  225. ORDER BY sort ASC,create_time ASC`
  226. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  227. } else {
  228. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  229. sql += ` ORDER BY sort ASC, create_time ASC`
  230. }
  231. pars = append(pars)
  232. o := orm.NewOrmUsingDB("rddp")
  233. _, err = o.Raw(sql, pars...).QueryRows(&items)
  234. return
  235. }
  236. func GetClassifyListCount(keyWord, companyType string, hideDayWeek int) (count int, err error) {
  237. sqlCount := ``
  238. companyTypeSqlStr := ``
  239. if companyType == "ficc" {
  240. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  241. } else if companyType == "权益" {
  242. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  243. }
  244. pars := make([]interface{}, 0)
  245. if keyWord != "" {
  246. sqlCount = `SELECT COUNT(1) AS count FROM (
  247. SELECT * FROM classify
  248. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  249. UNION
  250. SELECT * FROM classify
  251. WHERE id IN(SELECT parent_id FROM classify
  252. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  253. )AS t `
  254. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  255. } else {
  256. sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  257. if hideDayWeek == 1 {
  258. sqlCount += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  259. }
  260. }
  261. o := orm.NewOrmUsingDB("rddp")
  262. err = o.Raw(sqlCount, pars...).QueryRow(&count)
  263. return
  264. }
  265. type CheckDeleteClassifyReq struct {
  266. ClassifyId int `description:"分类ID"`
  267. }
  268. type CheckDeleteClassifyResp struct {
  269. Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"`
  270. Msg string `description:"描述信息"`
  271. }
  272. type DeleteClassifyReq struct {
  273. ClassifyId int `description:"分类ID"`
  274. }
  275. type EditClassifyReq struct {
  276. ClassifyId int `description:"分类ID"`
  277. ClassifyAddReq
  278. }
  279. type FindByIdClassifyReq struct {
  280. ClassifyId int `description:"分类ID"`
  281. }
  282. func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  283. o := orm.NewOrmUsingDB("rddp")
  284. sql := ``
  285. pars := make([]interface{}, 0)
  286. if keyWord != "" {
  287. sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC `
  288. pars = append(pars, utils.GetLikeKeyword(keyWord))
  289. } else {
  290. sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  291. }
  292. pars = append(pars, parentId)
  293. _, err = o.Raw(sql, pars...).QueryRows(&items)
  294. return
  295. }
  296. func GetClassifyChildByParentIds(parentId []int, keyWord string, enabled int) (items []*Classify, err error) {
  297. parentIdLen := len(parentId)
  298. if parentIdLen == 0 {
  299. return
  300. }
  301. o := orm.NewOrmUsingDB("rddp")
  302. sql := ``
  303. pars := make([]interface{}, 0)
  304. pars = append(pars, parentId)
  305. if keyWord != "" {
  306. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE ? `
  307. pars = append(pars, utils.GetLikeKeyword(keyWord))
  308. } else {
  309. sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) `
  310. }
  311. if enabled == 1 {
  312. sql += ` AND enabled=1 `
  313. }
  314. sql += ` ORDER BY create_time ASC `
  315. _, err = o.Raw(sql, pars...).QueryRows(&items)
  316. return
  317. }
  318. // EditClassifyPermissionReq 编辑分类权限请求
  319. type EditClassifyPermissionReq struct {
  320. ClassifyId int `description:"分类ID"`
  321. ChartPermissionIdList []int `description:"权限id数组"`
  322. }
  323. // GetAllClassify 获取所有分类
  324. func GetAllClassify() (list []*Classify, err error) {
  325. o := orm.NewOrmUsingDB("rddp")
  326. sql := ` SELECT * FROM classify `
  327. _, err = o.Raw(sql).QueryRows(&list)
  328. return
  329. }
  330. // GetClassifyByKeyword 名称获取分类
  331. func GetClassifyByKeyword(keyword string) (item Classify, err error) {
  332. o := orm.NewOrmUsingDB("rddp")
  333. sql := ` SELECT * FROM classify WHERE classify_name = ? LIMIT 1 `
  334. err = o.Raw(sql, keyword).QueryRow(&item)
  335. return
  336. }
  337. // UpdateClassify 更新分类
  338. func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
  339. o := orm.NewOrmUsingDB("rddp")
  340. _, err = o.Update(classifyInfo, cols...)
  341. return
  342. }
  343. // SimpleClassifyList 简版分类列表
  344. type SimpleClassifyList struct {
  345. Id int `description:"分类ID"`
  346. ClassifyName string `description:"分类名称"`
  347. ParentId int `description:"父级ID"`
  348. Sort int `description:"排序"`
  349. Child []*SimpleClassifyList
  350. }
  351. // GetClassifyByCondition 获取分类列表
  352. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  353. o := orm.NewOrmUsingDB("rddp")
  354. sql := `SELECT * FROM classify WHERE 1 = 1 `
  355. if condition != `` {
  356. sql += condition
  357. }
  358. order := `sort ASC, create_time ASC`
  359. if orderRule != `` {
  360. order = orderRule
  361. }
  362. sql += ` ORDER BY ` + order
  363. _, err = o.Raw(sql, pars).QueryRows(&items)
  364. return
  365. }
  366. // UpdateChildClassifyRelateSetting 更新子分类关联设置
  367. func UpdateChildClassifyRelateSetting(parentId, relateTel, relateVideo int) (err error) {
  368. o := orm.NewOrmUsingDB("rddp")
  369. sql := `UPDATE classify SET relate_tel = ?, relate_video = ? WHERE parent_id = ?`
  370. _, err = o.Raw(sql, relateTel, relateVideo, parentId).Exec()
  371. return
  372. }
  373. // RelateTelSecClassifyWithPermissions 关联了电话会的二级分类及权限
  374. type RelateTelSecClassifyWithPermissions struct {
  375. Id int `description:"分类ID"`
  376. ClassifyName string `description:"分类名称"`
  377. ChartPermissionIds string `description:"权限IDs"`
  378. }
  379. // UpdateClassifySortByParentId 根据父类id更新排序
  380. func UpdateClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) {
  381. o := orm.NewOrmUsingDB("rddp")
  382. sql := ` update classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
  383. if permissionId > 0 {
  384. sql += ` or ( id > ` + fmt.Sprint(permissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  385. }
  386. _, err = o.Raw(sql, parentId, nowSort).Exec()
  387. return
  388. }
  389. // GetMaxSortByParentId 获取最大的排序值
  390. func (classifyInfo *Classify) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
  391. o := orm.NewOrmUsingDB("rddp")
  392. sql := `SELECT max(sort) AS sort FROM classify WHERE parent_id = ? `
  393. err = o.Raw(sql, parentId).QueryRow(&maxSort)
  394. return
  395. }
  396. // GetMaxSort 获取最大的排序值
  397. func (classifyInfo *Classify) GetMaxSort() (maxSort int, err error) {
  398. o := orm.NewOrmUsingDB("rddp")
  399. sql := `SELECT max(sort) AS sort FROM classify`
  400. err = o.Raw(sql).QueryRow(&maxSort)
  401. return
  402. }
  403. // GetFirstClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
  404. func (classifyInfo *Classify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) {
  405. o := orm.NewOrmUsingDB("rddp")
  406. sql := `SELECT * FROM classify WHERE parent_id = ? order by sort asc, id asc limit 1`
  407. err = o.Raw(sql, parentId).QueryRow(&item)
  408. return
  409. }
  410. type ClassifyMoveReq struct {
  411. ClassifyId int `description:"分类ID"`
  412. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  413. NextClassifyId int `description:"下一个兄弟节点分类id"`
  414. }
  415. type ClassifySetEnabledReq struct {
  416. ClassifyId int `description:"分类ID"`
  417. Enabled int `description:"是否可用,1可用,0禁用"`
  418. }
  419. func (classifyInfo *Classify) SetEnabled(id, enabled int) (err error) {
  420. o := orm.NewOrmUsingDB("rddp")
  421. to, err := o.Begin()
  422. if err != nil {
  423. return
  424. }
  425. defer func() {
  426. if err != nil {
  427. _ = to.Rollback()
  428. } else {
  429. _ = to.Commit()
  430. }
  431. }()
  432. sql := ` UPDATE classify SET enabled =? WHERE id = ?`
  433. _, err = to.Raw(sql, enabled, id).Exec()
  434. if err != nil {
  435. return
  436. }
  437. sql = ` UPDATE classify SET enabled =? WHERE parent_id = ?`
  438. _, err = to.Raw(sql, enabled, id).Exec()
  439. if err != nil {
  440. return
  441. }
  442. return
  443. }
  444. // GetCountClassifyChildByParentId
  445. // @Description: 获取父级分类下子分类数量
  446. // @author: Roc
  447. // @datetime 2024-06-17 10:58:46
  448. // @param parentId int
  449. // @return total int
  450. // @return err error
  451. func GetCountClassifyChildByParentId(parentId int) (total int, err error) {
  452. o := orm.NewOrmUsingDB("rddp")
  453. sql := `SELECT count(1) AS total FROM classify WHERE parent_id = ? `
  454. err = o.Raw(sql, parentId).QueryRow(&total)
  455. return
  456. }
  457. // GetClassifyListByKeyword
  458. // @Description: 获取分类列表
  459. // @author: Roc
  460. // @datetime 2024-06-19 09:49:33
  461. // @param keyWord string
  462. // @param enabled int
  463. // @return items []*ClassifyList
  464. // @return err error
  465. func GetClassifyListByKeyword(keyWord string, enabled int) (items []*ClassifyList, err error) {
  466. sql := ``
  467. pars := make([]interface{}, 0)
  468. sql = `SELECT * FROM classify WHERE 1=1 `
  469. if enabled == 1 {
  470. sql += ` AND enabled = 1 `
  471. }
  472. if keyWord != `` {
  473. sql += ` AND classify_name LIKE ? `
  474. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  475. }
  476. sql += ` ORDER BY sort ASC, create_time ASC`
  477. o := orm.NewOrmUsingDB("rddp")
  478. _, err = o.Raw(sql, pars...).QueryRows(&items)
  479. return
  480. }
  481. // GetClassifyListByParentIdList
  482. // @Description: 获取分类列表
  483. // @author: Roc
  484. // @datetime 2024-06-19 09:49:33
  485. // @param keyWord string
  486. // @param enabled int
  487. // @return items []*ClassifyList
  488. // @return err error
  489. func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*ClassifyList, err error) {
  490. num := len(parentClassifyIdList)
  491. if num <= 0 {
  492. return
  493. }
  494. sql := `SELECT * FROM classify WHERE id in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort ASC, create_time ASC`
  495. o := orm.NewOrmUsingDB("rddp")
  496. _, err = o.Raw(sql, parentClassifyIdList).QueryRows(&items)
  497. return
  498. }
  499. // GetClassifyListByIdList
  500. // @Description: 根据指标ID列表,获取分类列表
  501. // @author: Roc
  502. // @datetime 2024-06-27 15:23:57
  503. // @param classifyIdList []int
  504. // @return items []*Classify
  505. // @return err error
  506. func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error) {
  507. num := len(classifyIdList)
  508. if num <= 0 {
  509. return
  510. }
  511. sql := `SELECT * FROM classify WHERE id IN (` + utils.GetOrmInReplace(num) + `) `
  512. o := orm.NewOrmUsingDB("rddp")
  513. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  514. return
  515. }