classify.go 23 KB

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