english_classify.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // UpdateEnglishClassifySortByParentId 根据父类id更新排序
  7. func UpdateEnglishClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) {
  8. o := orm.NewOrmUsingDB("rddp")
  9. sql := ` update english_classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
  10. if permissionId > 0 {
  11. sql += ` or ( id > ` + fmt.Sprint(permissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  12. }
  13. _, err = o.Raw(sql, parentId, nowSort).Exec()
  14. return
  15. }
  16. // GetMaxSortByParentId 获取最大的排序值
  17. func (classifyInfo *EnglishClassify) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
  18. o := orm.NewOrmUsingDB("rddp")
  19. sql := `SELECT max(sort) AS sort FROM english_classify WHERE parent_id = ? `
  20. err = o.Raw(sql, parentId).QueryRow(&maxSort)
  21. return
  22. }
  23. // GetMaxSort 获取最大的排序值
  24. func (classifyInfo *EnglishClassify) GetMaxSort() (maxSort int, err error) {
  25. o := orm.NewOrmUsingDB("rddp")
  26. sql := `SELECT max(sort) AS sort FROM english_classify`
  27. err = o.Raw(sql).QueryRow(&maxSort)
  28. return
  29. }
  30. // GetFirstClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
  31. func (classifyInfo *EnglishClassify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) {
  32. o := orm.NewOrmUsingDB("rddp")
  33. sql := `SELECT * FROM english_classify WHERE parent_id = ? order by sort asc, id asc limit 1`
  34. err = o.Raw(sql, parentId).QueryRow(&item)
  35. return
  36. }
  37. type EnglishClassifyMoveReq struct {
  38. ClassifyId int `description:"分类ID"`
  39. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  40. NextClassifyId int `description:"下一个兄弟节点分类id"`
  41. }
  42. type EnClassifyAddReq struct {
  43. EnPermissions []int `description:"权限IDs"`
  44. ClassifyName string `description:"分类名称"`
  45. ParentId int `description:"父级分类id"`
  46. }
  47. type EnClassifyEditReq struct {
  48. ClassifyId int `description:"分类ID"`
  49. EnClassifyAddReq
  50. }