classify.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. "time"
  8. "github.com/beego/beego/v2/client/orm"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. //type Classify struct {
  12. // Id int `orm:"column(id);pk"`
  13. // ClassifyName string `description:"分类名称"`
  14. // Sort int `json:"-"`
  15. // ParentId int `description:"父级分类id"`
  16. // CreateTime time.Time `description:"创建时间"`
  17. // ModifyTime time.Time `description:"修改时间"`
  18. // Abstract string `description:"栏目简介"`
  19. // Descript string `description:"分享描述"`
  20. // ReportAuthor string `description:"栏目作者"`
  21. // AuthorDescript string `description:"作者简介"`
  22. // ColumnImgUrl string `description:"栏目配图"`
  23. // HeadImgUrl string `description:"头部banner"`
  24. // AvatarImgUrl string `description:"头像"`
  25. // ReportImgUrl string `description:"报告配图"`
  26. // HomeImgUrl string `description:"首页配图"`
  27. // ClassifyLabel string `description:"分类标签"`
  28. // ShowType int `description:"展示类型:1-列表 2-专栏"`
  29. // HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  30. // VipTitle string `description:"研究员头衔"`
  31. // IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  32. // YbFiccSort int `description:"小程序FICC页排序"`
  33. // YbFiccIcon string `description:"小程序FICC页icon"`
  34. // YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  35. // YbIconUrl string `description:"小程序已购页icon"`
  36. // YbBgUrl string `description:"小程序已购详情背景图"`
  37. // YbListImg string `description:"小程序研报列表封面图"`
  38. // YbShareBgImg string `description:"小程序研报详情分享背景图"`
  39. // YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  40. // RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  41. // RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  42. // IsMassSend int `description:"1:群发,0:非群发"`
  43. // Enabled int `description:"是否可用,1可用,0禁用"`
  44. // Level int `description:"层级"`
  45. // HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  46. // ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  47. //}
  48. type Classify struct {
  49. Id int `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  50. ClassifyName string `gorm:"column:classify_name" json:"classify_name"` //`description:"分类名称"`
  51. Sort int `gorm:"column:sort" json:"sort"` //`json:"-"`
  52. ParentId int `gorm:"column:parent_id" json:"parent_id"` //`description:"父级分类id"`
  53. CreateTime time.Time `gorm:"column:create_time" json:"create_time"` //`description:"创建时间"`
  54. ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"` //`description:"修改时间"`
  55. Abstract string `gorm:"column:abstract" json:"abstract"` //`description:"栏目简介"`
  56. Descript string `gorm:"column:descript" json:"descript"` //`description:"分享描述"`
  57. ReportAuthor string `gorm:"column:report_author" json:"report_author"` //`description:"栏目作者"`
  58. AuthorDescript string `gorm:"column:author_descript" json:"author_descript"` //`description:"作者简介"`
  59. ColumnImgUrl string `gorm:"column:column_img_url" json:"column_img_url"` //`description:"栏目配图"`
  60. HeadImgUrl string `gorm:"column:head_img_url" json:"head_img_url"` //`description:"头部banner"`
  61. AvatarImgUrl string `gorm:"column:avatar_img_url" json:"avatar_img_url"` //`description:"头像"`
  62. ReportImgUrl string `gorm:"column:report_img_url" json:"report_img_url"` //`description:"报告配图"`
  63. HomeImgUrl string `gorm:"column:home_img_url" json:"home_img_url"` //`description:"首页配图"`
  64. ClassifyLabel string `gorm:"column:classify_label" json:"classify_label"` //`description:"分类标签"`
  65. ShowType int `gorm:"column:show_type" json:"show_type"` //`description:"展示类型:1-列表 2-专栏"`
  66. HasTeleconference int `gorm:"column:has_teleconference" json:"has_teleconference"` //`description:"是否有电话会:0-否 1-是"`
  67. VipTitle string `gorm:"column:vip_title" json:"vip_title"` //`description:"研究员头衔"`
  68. IsShow int `gorm:"column:is_show" json:"is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"`
  69. YbFiccSort int `gorm:"column:yb_ficc_sort" json:"yb_ficc_sort"` //`description:"小程序FICC页排序"`
  70. YbFiccIcon string `gorm:"column:yb_ficc_icon" json:"yb_ficc_icon"` // `description:"小程序FICC页icon"`
  71. YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon" json:"yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"`
  72. YbIconUrl string `gorm:"column:yb_icon_url" json:"yb_icon_url"` //`description:"小程序已购页icon"`
  73. YbBgUrl string `gorm:"column:yb_bg_url" json:"yb_bg_url"` //`description:"小程序已购详情背景图"`
  74. YbListImg string `gorm:"column:yb_list_img" json:"yb_list_img"` //`description:"小程序研报列表封面图"`
  75. YbShareBgImg string `gorm:"column:yb_share_bg_img" json:"yb_share_bg_img"` //`description:"小程序研报详情分享背景图"`
  76. YbRightBanner string `gorm:"column:yb_right_banner" json:"yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"`
  77. RelateTel int `gorm:"column:relate_tel" json:"relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"`
  78. RelateVideo int `gorm:"column:relate_video" json:"relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"`
  79. IsMassSend int `gorm:"column:is_mass_send" json:"is_mass_send"` //`description:"1:群发,0:非群发"`
  80. Enabled int `gorm:"column:enabled" json:"enabled"` //`description:"是否可用,1可用,0禁用"`
  81. Level int `gorm:"column:level" json:"level"` //`description:"层级"`
  82. HasChild int `gorm:"column:has_child" json:"has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  83. ReportDetailShowType int `gorm:"column:report_detail_show_type" json:"report_detail_show_type"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
  84. }
  85. //type ClassifyVO struct {
  86. // Id int `orm:"column(id);pk"`
  87. // ClassifyName string `description:"分类名称"`
  88. // Sort int `json:"-"`
  89. // ParentId int `description:"父级分类id"`
  90. // ClassifyLabel string `description:"分类标签"`
  91. // Enabled int `description:"是否可用,1可用,0禁用"`
  92. // Level int `description:"层级"`
  93. // Children *[]ClassifyVO
  94. //}
  95. type ClassifyVO struct {
  96. Id int `gorm:"column:id;primaryKey"`
  97. ClassifyName string `description:"分类名称"`
  98. Sort int `json:"-"`
  99. ParentId int `description:"父级分类id"`
  100. ClassifyLabel string `description:"分类标签"`
  101. Enabled int `description:"是否可用,1可用,0禁用"`
  102. Level int `description:"层级"`
  103. Children *[]ClassifyVO
  104. }
  105. type ClassifyAddReq struct {
  106. ClassifyName string `description:"分类名称"`
  107. ParentId int `description:"父级分类id,没有父级分类传0"`
  108. ChartPermissionIdList []int `description:"权限id数组"`
  109. /*Abstract string `description:"栏目简介"`
  110. Descript string `description:"分享描述"`
  111. ReportAuthor string `description:"栏目作者"`
  112. AuthorDescript string `description:"作者简介"`
  113. ColumnImgUrl string `description:"栏目配图"`
  114. ReportImgUrl string `description:"报告配图"`
  115. HeadImgUrl string `description:"头部banner"`
  116. AvatarImgUrl string `description:"头像"`
  117. HomeImgUrl string `description:"首页配图"`
  118. ClassifyLabel string `description:"分类标签"`
  119. ShowType int `description:"展示类型:1-列表 2-专栏"`
  120. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  121. VipTitle string `description:"研究员头衔"`
  122. Sort int `description:"后台排序"`
  123. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  124. YbFiccSort int `description:"小程序FICC页排序"`
  125. YbFiccIcon string `description:"小程序FICC页icon"`
  126. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  127. YbIconUrl string `description:"小程序已购页icon"`
  128. YbBgUrl string `description:"小程序已购详情背景图"`
  129. YbListImg string `description:"小程序研报列表封面图"`
  130. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  131. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  132. MenuList []*ClassifyMenuSaveReq `description:"子目录列表"`
  133. ClassifyMenuId int `description:"二级分类-子目录ID"`
  134. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  135. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`*/
  136. }
  137. func (c *Classify) Delete(childIds []int) (err error) {
  138. tx := global.DbMap[utils.DbNameReport].Begin()
  139. defer func() {
  140. if err != nil {
  141. tx.Rollback()
  142. } else {
  143. tx.Commit()
  144. }
  145. }()
  146. // 删除自身
  147. err = tx.Delete(c).Error
  148. if err != nil {
  149. return
  150. }
  151. // 删除子分类
  152. if len(childIds) > 0 {
  153. sql := `DELETE FROM classify WHERE id IN (` + utils.GetOrmInReplace(len(childIds)) + `)`
  154. err = tx.Exec(sql, childIds).Error
  155. if err != nil {
  156. return
  157. }
  158. }
  159. // 检查是否需要更新父类
  160. if c.ParentId > 0 {
  161. var count int
  162. sql := `SELECT COUNT(*) FROM classify WHERE parent_id=? `
  163. var countNull sql2.NullInt64
  164. err = tx.Raw(sql, c.ParentId).Scan(&countNull).Error
  165. if err != nil {
  166. return
  167. }
  168. if countNull.Valid {
  169. count = int(countNull.Int64)
  170. }
  171. if err != nil {
  172. return
  173. }
  174. if count == 0 {
  175. sql = `UPDATE classify SET has_child=0 WHERE id=? `
  176. err = tx.Exec(sql, c.ParentId).Error
  177. if err != nil {
  178. return
  179. }
  180. }
  181. }
  182. deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
  183. err = tx.Exec(deleteImgSql, c.Id).Error
  184. return
  185. }
  186. func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
  187. sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
  188. err = global.DbMap[utils.DbNameReport].Raw(sql, classifyName, parentId).First(&item).Error
  189. return
  190. }
  191. func GetClassifyById(classifyId int) (item *Classify, err error) {
  192. sql := `SELECT * FROM classify WHERE id=? `
  193. err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).First(&item).Error
  194. return
  195. }
  196. // 添加分类
  197. func AddClassify(item *Classify) (err error) {
  198. err = global.DbMap[utils.DbNameReport].Create(item).Error
  199. return
  200. }
  201. func GetReportCountByClassifyId(classifyId int) (count int, err error) {
  202. sql := `SELECT COUNT(1) AS count FROM report WHERE classify_id_second=? `
  203. var countNull sql2.NullInt64
  204. err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).Scan(&countNull).Error
  205. if err != nil {
  206. return
  207. }
  208. if countNull.Valid {
  209. count = int(countNull.Int64)
  210. }
  211. return
  212. }
  213. func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) {
  214. sql := `SELECT COUNT(1) as num FROM classify AS a
  215. INNER JOIN report AS b ON a.id=b.classify_id_second
  216. WHERE a.parent_id=? `
  217. var countNull sql2.NullInt64
  218. err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).Scan(&countNull).Error
  219. if err != nil {
  220. return
  221. }
  222. if countNull.Valid {
  223. count = int(countNull.Int64)
  224. }
  225. return
  226. }
  227. func GetClassifySubCountByParentId(classifyId int) (count int, err error) {
  228. sqlCount := `
  229. SELECT COUNT(1) as num FROM classify AS a
  230. WHERE a.parent_id=? `
  231. var countNull sql2.NullInt64
  232. err = global.DbMap[utils.DbNameReport].Raw(sqlCount, classifyId).Scan(&countNull).Error
  233. if err != nil {
  234. return
  235. }
  236. if countNull.Valid {
  237. count = int(countNull.Int64)
  238. }
  239. return
  240. }
  241. // 删除分类
  242. //func DeleteClassify(classifyId int) (err error) {
  243. // sql := `DELETE FROM classify WHERE id=? `
  244. // o := orm.NewOrmUsingDB("rddp")
  245. // _, err = o.Raw(sql, classifyId).Exec()
  246. // if err != nil {
  247. // return
  248. // }
  249. // deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
  250. // _, err = o.Raw(deleteImgSql, classifyId).Exec()
  251. // return
  252. //}
  253. // classifyName, abstract, descript string, parentId, classifyId int
  254. // 修改分类
  255. //func EditClassify(req *EditClassifyReq) (err error) {
  256. // o := orm.NewOrmUsingDB("rddp")
  257. // //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 = ? `
  258. // //_, 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()
  259. // sql := `UPDATE classify SET classify_name = ?,parent_id= ?,modify_time= NOW() WHERE id = ? `
  260. // _, err = o.Raw(sql, req.ClassifyName, req.ParentId, req.ClassifyId).Exec()
  261. //
  262. // return
  263. //}
  264. // ParentClassify
  265. // @Description: 获取父级分类
  266. // @author: Roc
  267. // @datetime 2024-06-18 15:03:49
  268. // @return items []*Classify
  269. // @return err error
  270. //func ParentClassify() (items []*Classify, err error) {
  271. // sql := `SELECT * FROM classify WHERE parent_id=0 order by id desc `
  272. // o := orm.NewOrmUsingDB("rddp")
  273. // _, err = o.Raw(sql).QueryRows(&items)
  274. // return
  275. //}
  276. // 根据id获取分类详情
  277. func FindByIdClassify(classifyId int) (item *Classify, err error) {
  278. sql := `SELECT * FROM classify WHERE id=? `
  279. err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).First(&item).Error
  280. return
  281. }
  282. //type ClassifyList struct {
  283. // Id int `orm:"column(id);pk"`
  284. // ClassifyName string `description:"分类名称"`
  285. // Sort int `description:"排序"`
  286. // ParentId int `description:"父级分类id"`
  287. // CreateTime time.Time `description:"创建时间"`
  288. // ModifyTime time.Time `description:"修改时间"`
  289. // Abstract string `description:"简介"`
  290. // Descript string `description:"描述"`
  291. // ClassifyLabel string `description:"分类标签"`
  292. // ShowType int `description:"展示类型:1-列表 2-专栏"`
  293. // HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  294. // IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  295. // YbFiccSort int `description:"小程序FICC页排序"`
  296. // YbFiccIcon string `description:"小程序FICC页icon"`
  297. // YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  298. // YbIconUrl string `description:"小程序已购页icon"`
  299. // YbBgUrl string `description:"小程序已购详情背景图"`
  300. // YbListImg string `description:"小程序研报列表封面图"`
  301. // YbShareBgImg string `description:"小程序研报详情分享背景图"`
  302. // YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  303. // RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  304. // RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  305. // Enabled int `description:"是否可用,1可用,0禁用"`
  306. // Child []*ClassifyList
  307. // ClassifyMenuId int `description:"二级分类-子目录ID"`
  308. // ClassifyMenuList []*ClassifyMenu
  309. // ChartPermissionIdList []int `description:"绑定的权限ID"`
  310. // Level int `description:"层级"`
  311. // HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  312. // IsEnableDelete int `description:"是否允许删除: 0-否; 1-是"`
  313. //}
  314. type ClassifyList struct {
  315. Id int `gorm:"column:id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  316. ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称"`
  317. Sort int `gorm:"column:sort"` //`description:"排序"`
  318. ParentId int `gorm:"column:parent_id"` //`description:"父级分类id"`
  319. CreateTime time.Time `gorm:"column:create_time"` //`description:"创建时间"`
  320. ModifyTime time.Time `gorm:"column:modify_time"` //`description:"修改时间"`
  321. Abstract string `gorm:"column:abstract"` //`description:"简介"`
  322. Descript string `gorm:"column:descript"` //`description:"描述"`
  323. ClassifyLabel string `gorm:"column:classify_label"` //`description:"分类标签"`
  324. ShowType int `gorm:"column:show_type"` //`description:"展示类型:1-列表 2-专栏"`
  325. HasTeleconference int `gorm:"column:has_teleconference"` //`description:"是否有电话会:0-否 1-是"`
  326. IsShow int `gorm:"column:is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"`
  327. YbFiccSort int `gorm:"column:yb_ficc_sort"` //`description:"小程序FICC页排序"`
  328. YbFiccIcon string `gorm:"column:yb_ficc_icon"` //`description:"小程序FICC页icon"`
  329. YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"`
  330. YbIconUrl string `gorm:"column:yb_icon_url"` //`description:"小程序已购页icon"`
  331. YbBgUrl string `gorm:"column:yb_bg_url"` //`description:"小程序已购详情背景图"`
  332. YbListImg string `gorm:"column:yb_list_img"` //`description:"小程序研报列表封面图"`
  333. YbShareBgImg string `gorm:"column:yb_share_bg_img"` //`description:"小程序研报详情分享背景图"`
  334. YbRightBanner string `gorm:"column:yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"`
  335. RelateTel int `gorm:"column:relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"`
  336. RelateVideo int `gorm:"column:relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"`
  337. Enabled int `gorm:"column:enabled"` //`description:"是否可用,1可用,0禁用"`
  338. Level int `gorm:"column:level"` //`description:"层级"`
  339. HasChild int `gorm:"column:has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  340. Child []*ClassifyList `gorm:"-"`
  341. ClassifyMenuId int `gorm:"-"` //`description:"二级分类-子目录ID"`
  342. ClassifyMenuList []*ClassifyMenu `gorm:"-"`
  343. ChartPermissionIdList []int `gorm:"-"` //`description:"绑定的权限ID"`
  344. IsEnableDelete int `gorm:"-" description:"是否允许删除: 0-否; 1-是"`
  345. }
  346. type ClassifyItem struct {
  347. Classify
  348. ClassifyMenuId int `description:"二级分类-子目录ID"`
  349. ClassifyMenuList []*ClassifyMenu
  350. ChartPermissionIdList []int `description:"绑定的权限ID"`
  351. Child []*ClassifyItem
  352. }
  353. type ClassifyListResp struct {
  354. List []*ClassifyList
  355. }
  356. type ClassifyPermissionListResp struct {
  357. List []*ClassifyList
  358. Paging *paging.PagingItem `description:"分页数据"`
  359. }
  360. // 获取分类列表
  361. //func GetClassifyList(keyWord string, enabled int) (items []*ClassifyList, err error) {
  362. // sql := ``
  363. // companyTypeSqlStr := ``
  364. // if enabled == 1 {
  365. // companyTypeSqlStr += ` AND enabled = 1 `
  366. // }
  367. // pars := make([]interface{}, 0)
  368. // if keyWord != "" {
  369. // sql = `SELECT * FROM (
  370. // SELECT * FROM classify
  371. // WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  372. // UNION
  373. // SELECT * FROM classify
  374. // WHERE id IN( SELECT parent_id FROM classify
  375. // WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  376. // )AS t
  377. // ORDER BY sort ASC,create_time ASC`
  378. // pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  379. // } else {
  380. // sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  381. //
  382. // sql += ` ORDER BY sort ASC, create_time ASC`
  383. // }
  384. // pars = append(pars)
  385. //
  386. // o := orm.NewOrmUsingDB("rddp")
  387. // _, err = o.Raw(sql, pars...).QueryRows(&items)
  388. // return
  389. //}
  390. //func GetClassifyListCount(keyWord, companyType string, hideDayWeek int) (count int, err error) {
  391. // sqlCount := ``
  392. //
  393. // companyTypeSqlStr := ``
  394. // if companyType == "ficc" {
  395. // companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  396. // } else if companyType == "权益" {
  397. // companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  398. // }
  399. //
  400. // pars := make([]interface{}, 0)
  401. //
  402. // if keyWord != "" {
  403. // sqlCount = `SELECT COUNT(1) AS count FROM (
  404. // SELECT * FROM classify
  405. // WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  406. // UNION
  407. // SELECT * FROM classify
  408. // WHERE id IN(SELECT parent_id FROM classify
  409. // WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  410. // )AS t `
  411. // pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  412. // } else {
  413. // sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  414. // if hideDayWeek == 1 {
  415. // sqlCount += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  416. // }
  417. // }
  418. // o := orm.NewOrmUsingDB("rddp")
  419. // err = o.Raw(sqlCount, pars...).QueryRow(&count)
  420. // return
  421. //}
  422. type CheckDeleteClassifyReq struct {
  423. ClassifyId int `description:"分类ID"`
  424. }
  425. type CheckDeleteClassifyResp struct {
  426. Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"`
  427. Msg string `description:"描述信息"`
  428. }
  429. type DeleteClassifyReq struct {
  430. ClassifyId int `description:"分类ID"`
  431. }
  432. type EditClassifyReq struct {
  433. ClassifyId int `description:"分类ID"`
  434. ClassifyAddReq
  435. }
  436. type FindByIdClassifyReq struct {
  437. ClassifyId int `description:"分类ID"`
  438. }
  439. func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  440. sql := ``
  441. pars := make([]interface{}, 0)
  442. if keyWord != "" {
  443. sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC `
  444. pars = append(pars, utils.GetLikeKeyword(keyWord))
  445. } else {
  446. sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  447. }
  448. pars = append(pars, parentId)
  449. err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
  450. return
  451. }
  452. //func GetClassifyChildByParentIds(parentId []int, keyWord string, enabled int) (items []*Classify, err error) {
  453. // parentIdLen := len(parentId)
  454. // if parentIdLen == 0 {
  455. // return
  456. // }
  457. // o := orm.NewOrmUsingDB("rddp")
  458. // sql := ``
  459. // pars := make([]interface{}, 0)
  460. // pars = append(pars, parentId)
  461. // if keyWord != "" {
  462. // sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE ? `
  463. // pars = append(pars, utils.GetLikeKeyword(keyWord))
  464. // } else {
  465. // sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) `
  466. // }
  467. //
  468. // if enabled == 1 {
  469. // sql += ` AND enabled=1 `
  470. // }
  471. // sql += ` ORDER BY create_time ASC `
  472. // _, err = o.Raw(sql, pars...).QueryRows(&items)
  473. //
  474. // return
  475. //}
  476. // EditClassifyPermissionReq 编辑分类权限请求
  477. type EditClassifyPermissionReq struct {
  478. ClassifyId int `description:"分类ID"`
  479. ChartPermissionIdList []int `description:"权限id数组"`
  480. }
  481. // GetAllClassify 获取所有分类
  482. func GetAllClassify() (list []*Classify, err error) {
  483. o := orm.NewOrmUsingDB("rddp")
  484. sql := ` SELECT * FROM classify `
  485. _, err = o.Raw(sql).QueryRows(&list)
  486. return
  487. }
  488. // GetAllClassifyWithDesc 获取所有倒序分类
  489. func GetAllClassifyWithDesc() (list []*Classify, err error) {
  490. o := orm.NewOrmUsingDB("rddp")
  491. sql := ` SELECT * FROM classify ORDER BY id DESC `
  492. _, err = o.Raw(sql).QueryRows(&list)
  493. return
  494. }
  495. // GetClassifyByKeyword 名称获取分类
  496. //func GetClassifyByKeyword(keyword string) (item Classify, err error) {
  497. // o := orm.NewOrmUsingDB("rddp")
  498. // sql := ` SELECT * FROM classify WHERE classify_name = ? LIMIT 1 `
  499. // err = o.Raw(sql, keyword).QueryRow(&item)
  500. // return
  501. //}
  502. // UpdateClassify 更新分类
  503. func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
  504. err = global.DbMap[utils.DbNameReport].Select(cols).Updates(classifyInfo).Error
  505. return
  506. }
  507. // SimpleClassifyList 简版分类列表
  508. type SimpleClassifyList struct {
  509. Id int `description:"分类ID"`
  510. ClassifyName string `description:"分类名称"`
  511. ParentId int `description:"父级ID"`
  512. Sort int `description:"排序"`
  513. Child []*SimpleClassifyList
  514. }
  515. // GetClassifyByCondition 获取分类列表
  516. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  517. sql := `SELECT * FROM classify WHERE 1 = 1 `
  518. if condition != `` {
  519. sql += condition
  520. }
  521. order := `sort ASC, create_time ASC`
  522. if orderRule != `` {
  523. order = orderRule
  524. }
  525. sql += ` ORDER BY ` + order
  526. err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
  527. return
  528. }
  529. // UpdateChildClassifyRelateSetting 更新子分类关联设置
  530. //func UpdateChildClassifyRelateSetting(parentId, relateTel, relateVideo int) (err error) {
  531. // o := orm.NewOrmUsingDB("rddp")
  532. // sql := `UPDATE classify SET relate_tel = ?, relate_video = ? WHERE parent_id = ?`
  533. // _, err = o.Raw(sql, relateTel, relateVideo, parentId).Exec()
  534. // return
  535. //}
  536. // RelateTelSecClassifyWithPermissions 关联了电话会的二级分类及权限
  537. type RelateTelSecClassifyWithPermissions struct {
  538. Id int `description:"分类ID"`
  539. ClassifyName string `description:"分类名称"`
  540. ChartPermissionIds string `description:"权限IDs"`
  541. }
  542. // UpdateClassifySortByParentId 根据父类id更新排序
  543. func UpdateClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) {
  544. sql := ` update classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
  545. if permissionId > 0 {
  546. sql += ` or ( id > ` + fmt.Sprint(permissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  547. }
  548. err = global.DbMap[utils.DbNameReport].Exec(sql, parentId, nowSort).Error
  549. return
  550. }
  551. // GetMaxSortByParentId 获取最大的排序值
  552. func (classifyInfo *Classify) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
  553. sql := `SELECT max(sort) AS sort FROM classify WHERE parent_id = ? `
  554. if utils.DbDriverName == utils.DbDriverByDm {
  555. sql = `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify WHERE parent_id = ? `
  556. }
  557. var maxNull sql2.NullInt64
  558. err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Scan(&maxNull).Error
  559. if err != nil {
  560. return
  561. }
  562. if maxNull.Valid {
  563. maxSort = int(maxNull.Int64)
  564. }
  565. return
  566. }
  567. // GetMaxSort 获取最大的排序值
  568. func (classifyInfo *Classify) GetMaxSort() (maxSort int, err error) {
  569. sql := `SELECT max(sort) AS sort FROM classify`
  570. if utils.DbDriverName == utils.DbDriverByDm {
  571. sql = `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify`
  572. }
  573. var maxNull sql2.NullInt64
  574. err = global.DbMap[utils.DbNameReport].Raw(sql).Scan(&maxNull).Error
  575. if err != nil {
  576. return
  577. }
  578. if maxNull.Valid {
  579. maxSort = int(maxNull.Int64)
  580. }
  581. return
  582. }
  583. // GetFirstClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
  584. func (classifyInfo *Classify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) {
  585. sql := `SELECT * FROM classify WHERE parent_id = ? order by sort asc, id asc limit 1`
  586. err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).First(&item).Error
  587. return
  588. }
  589. type ClassifyMoveReq struct {
  590. ClassifyId int `description:"分类ID"`
  591. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  592. NextClassifyId int `description:"下一个兄弟节点分类id"`
  593. }
  594. type ClassifySetEnabledReq struct {
  595. ClassifyId int `description:"分类ID"`
  596. Enabled int `description:"是否可用,1可用,0禁用"`
  597. }
  598. func (classifyInfo *Classify) SetEnabled(id, enabled int) (err error) {
  599. to := global.DbMap[utils.DbNameReport].Begin()
  600. defer func() {
  601. if err != nil {
  602. _ = to.Rollback()
  603. } else {
  604. _ = to.Commit()
  605. }
  606. }()
  607. sql := ` UPDATE classify SET enabled =? WHERE id = ?`
  608. err = to.Exec(sql, enabled, id).Error
  609. if err != nil {
  610. return
  611. }
  612. sql = ` UPDATE classify SET enabled =? WHERE parent_id = ?`
  613. err = to.Exec(sql, enabled, id).Error
  614. if err != nil {
  615. return
  616. }
  617. return
  618. }
  619. // GetCountClassifyChildByParentId
  620. // @Description: 获取父级分类下子分类数量
  621. // @author: Roc
  622. // @datetime 2024-06-17 10:58:46
  623. // @param parentId int
  624. // @return total int
  625. // @return err error
  626. func GetCountClassifyChildByParentId(parentId int) (total int, err error) {
  627. sql := `SELECT count(1) AS total FROM classify WHERE parent_id = ? `
  628. var countNull sql2.NullInt64
  629. err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Scan(&countNull).Error
  630. if err != nil {
  631. return
  632. }
  633. if countNull.Valid {
  634. total = int(countNull.Int64)
  635. }
  636. return
  637. }
  638. // GetClassifyListByKeyword
  639. // @Description: 获取分类列表
  640. // @author: Roc
  641. // @datetime 2024-06-19 09:49:33
  642. // @param keyWord string
  643. // @param enabled int
  644. // @return items []*ClassifyList
  645. // @return err error
  646. func GetClassifyListByKeyword(keyWord string, enabled int) (items []*ClassifyList, err error) {
  647. sql := ``
  648. pars := make([]interface{}, 0)
  649. sql = `SELECT * FROM classify WHERE 1=1 `
  650. if enabled == 1 {
  651. sql += ` AND enabled = 1 `
  652. }
  653. if keyWord != `` {
  654. sql += ` AND classify_name LIKE ? `
  655. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  656. }
  657. sql += ` ORDER BY sort ASC, create_time ASC`
  658. err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
  659. return
  660. }
  661. // GetClassifyListByParentIdList
  662. // @Description: 获取分类列表
  663. // @author: Roc
  664. // @datetime 2024-06-19 09:49:33
  665. // @param keyWord string
  666. // @param enabled int
  667. // @return items []*ClassifyList
  668. // @return err error
  669. func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*ClassifyList, err error) {
  670. num := len(parentClassifyIdList)
  671. if num <= 0 {
  672. return
  673. }
  674. sql := `SELECT * FROM classify WHERE id in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort ASC, create_time ASC`
  675. err = global.DbMap[utils.DbNameReport].Raw(sql, parentClassifyIdList).Find(&items).Error
  676. return
  677. }
  678. // GetClassifyListByIdList
  679. // @Description: 根据指标ID列表,获取分类列表
  680. // @author: Roc
  681. // @datetime 2024-06-27 15:23:57
  682. // @param classifyIdList []int
  683. // @return items []*Classify
  684. // @return err error
  685. func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error) {
  686. num := len(classifyIdList)
  687. if num <= 0 {
  688. return
  689. }
  690. sql := `SELECT * FROM classify WHERE id IN (` + utils.GetOrmInReplace(num) + `) `
  691. err = global.DbMap[utils.DbNameReport].Raw(sql, classifyIdList).Find(&items).Error
  692. return
  693. }
  694. // GetClassifyListByParentId 查询父分类下所有的子分类
  695. func GetClassifyListByParentId(parentId int) (items []*Classify, err error) {
  696. sql := `SELECT * FROM classify WHERE parent_id = ? and enabled = 1`
  697. err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Find(&items).Error
  698. return items, err
  699. }