excel_classify.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ExcelClassify excel表格分类
  8. type ExcelClassify struct {
  9. ExcelClassifyId int `orm:"column(excel_classify_id);pk"`
  10. ExcelClassifyName string `description:"分类名称"`
  11. ParentId int `description:"父级id"`
  12. SysUserId int `description:"创建人id"`
  13. SysUserRealName string `description:"创建人姓名"`
  14. Level int `description:"层级"`
  15. UniqueCode string `description:"唯一编码"`
  16. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  17. IsDelete int `description:"排序字段,越小越靠前,默认值:10"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. }
  21. // AddExcelClassify 添加excel分类
  22. func AddExcelClassify(item *ExcelClassify) (lastId int64, err error) {
  23. o := orm.NewOrmUsingDB("data")
  24. lastId, err = o.Insert(item)
  25. return
  26. }
  27. // GetExcelClassifyCount 获取同级分类下存在同名分类的数量
  28. func GetExcelClassifyCount(ExcelClassifyName string, parentId int) (count int, err error) {
  29. o := orm.NewOrmUsingDB("data")
  30. sql := `SELECT COUNT(1) AS count FROM excel_classify WHERE parent_id=? AND excel_classify_name=? AND is_delete=0 `
  31. err = o.Raw(sql, parentId, ExcelClassifyName).QueryRow(&count)
  32. return
  33. }
  34. func GetExcelClassifyById(classifyId int) (item *ExcelClassify, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  37. err = o.Raw(sql, classifyId).QueryRow(&item)
  38. return
  39. }
  40. func GetExcelClassifyByParentId(parentId int) (items []*ExcelClassifyItems, err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 order by sort asc,excel_classify_id asc`
  43. _, err = o.Raw(sql, parentId).QueryRows(&items)
  44. return
  45. }
  46. func GetExcelClassifyAll() (items []*ExcelClassifyItems, err error) {
  47. o := orm.NewOrmUsingDB("data")
  48. sql := ` SELECT * FROM excel_classify WHERE parent_id<>0 AND is_delete=0 order by sort asc,excel_classify_id asc`
  49. _, err = o.Raw(sql).QueryRows(&items)
  50. return
  51. }
  52. type ExcelClassifyItems struct {
  53. ExcelClassifyId int `description:"分类id"`
  54. ExcelInfoId int `description:"表格id"`
  55. ExcelClassifyName string
  56. ParentId int
  57. Level int `description:"层级"`
  58. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  59. UniqueCode string `description:"唯一编码"`
  60. SysUserId int `description:"创建人id"`
  61. SysUserRealName string `description:"创建人姓名"`
  62. StartDate string `description:"自定义开始日期"`
  63. Children []*ExcelClassifyItems
  64. }
  65. func GetExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  68. if condition != "" {
  69. sql += condition
  70. }
  71. err = o.Raw(sql, pars).QueryRow(&item)
  72. return
  73. }
  74. // GetNextExcelClassifyByCondition 获取下一个分类
  75. func GetNextExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  76. o := orm.NewOrmUsingDB("data")
  77. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  78. if condition != "" {
  79. sql += condition
  80. }
  81. sql += " ORDER BY sort asc , create_time ASC LIMIT 1 "
  82. err = o.Raw(sql, pars).QueryRow(&item)
  83. return
  84. }
  85. // GetFirstExcelClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  86. func GetFirstExcelClassifyByParentId(parentId int) (item *ExcelClassify, err error) {
  87. o := orm.NewOrmUsingDB("data")
  88. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 order by sort asc,excel_classify_id asc limit 1`
  89. err = o.Raw(sql, parentId).QueryRow(&item)
  90. return
  91. }
  92. // UpdateExcelClassifySortByParentId 根据图表父类id更新排序
  93. func UpdateExcelClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  94. o := orm.NewOrmUsingDB("data")
  95. sql := ` update excel_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? AND is_delete=0 `
  96. if classifyId > 0 {
  97. sql += ` or ( excel_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  98. }
  99. _, err = o.Raw(sql, parentId, nowSort).Exec()
  100. return
  101. }
  102. // Update 更新图表分类基础信息
  103. func (ExcelClassify *ExcelClassify) Update(cols []string) (err error) {
  104. o := orm.NewOrmUsingDB("data")
  105. _, err = o.Update(ExcelClassify, cols...)
  106. return
  107. }
  108. // GetExcelClassifyMaxSort 获取图表分类下最大的排序数
  109. func GetExcelClassifyMaxSort(parentId int) (sort int, err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. sql := `SELECT Max(sort) AS sort FROM excel_classify WHERE parent_id=? AND is_delete=0 `
  112. err = o.Raw(sql, parentId).QueryRow(&sort)
  113. return
  114. }
  115. type ExcelClassifyView struct {
  116. ExcelClassifyId int `orm:"column(excel_classify_id);pk"`
  117. ExcelClassifyName string `description:"分类名称"`
  118. ParentId int `description:"父级id"`
  119. }
  120. func GetExcelClassifyViewById(classifyId int) (item *ExcelClassifyView, err error) {
  121. o := orm.NewOrmUsingDB("data")
  122. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  123. err = o.Raw(sql, classifyId).QueryRow(&item)
  124. return
  125. }