classify.go 22 KB

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