excel_classify.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package excel
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // ExcelClassify excel表格分类
  9. type ExcelClassify struct {
  10. ExcelClassifyId int `orm:"column(excel_classify_id);pk"`
  11. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
  12. ExcelClassifyName string `description:"分类名称"`
  13. ParentId int `description:"父级id"`
  14. SysUserId int `description:"创建人id"`
  15. SysUserRealName string `description:"创建人姓名"`
  16. Level int `description:"层级"`
  17. UniqueCode string `description:"唯一编码"`
  18. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  19. IsDelete int `description:"排序字段,越小越靠前,默认值:10"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ModifyTime time.Time `description:"修改时间"`
  22. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  23. }
  24. // AddExcelClassify 添加excel分类
  25. func AddExcelClassify(item *ExcelClassify) (lastId int64, err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. lastId, err = o.Insert(item)
  28. if err != nil {
  29. return
  30. }
  31. item.ExcelClassifyId = int(lastId)
  32. return
  33. }
  34. // GetExcelClassifyCount 获取同级分类下存在同名分类的数量
  35. func GetExcelClassifyCount(ExcelClassifyName string, parentId, source int) (count int, err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. sql := `SELECT COUNT(1) AS count FROM excel_classify WHERE parent_id=? AND source = ? AND excel_classify_name=? AND is_delete=0 `
  38. err = o.Raw(sql, parentId, source, ExcelClassifyName).QueryRow(&count)
  39. return
  40. }
  41. func GetExcelClassifyById(classifyId int) (item *ExcelClassify, err error) {
  42. o := orm.NewOrmUsingDB("data")
  43. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  44. err = o.Raw(sql, classifyId).QueryRow(&item)
  45. return
  46. }
  47. // GetExcelClassifyByIdList
  48. // @Description: 根据分类id列表获取所有分类信息
  49. // @author: Roc
  50. // @datetime 2024-04-07 16:24:04
  51. // @param classifyIdList []int
  52. // @return items []*ExcelClassify
  53. // @return err error
  54. func GetExcelClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  55. num := len(classifyIdList)
  56. if num <= 0 {
  57. return
  58. }
  59. o := orm.NewOrmUsingDB("data")
  60. sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetOrmInReplace(num) + `) AND is_delete=0 `
  61. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  62. return
  63. }
  64. // GetExcelClassifyBySourceAndIsJoinPermission
  65. // @Description: 根据分类id列表获取所有分类信息
  66. // @author: Roc
  67. // @datetime 2024-04-07 16:24:04
  68. // @param classifyIdList []int
  69. // @return items []*ExcelClassify
  70. // @return err error
  71. func GetExcelClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ExcelClassify, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. sql := `SELECT * FROM excel_classify WHERE source = ? AND is_join_permission = ? `
  74. _, err = o.Raw(sql, source, isJoinPermission).QueryRows(&items)
  75. return
  76. }
  77. func GetChildClassifyById(classifyId int) (items []*ExcelClassify, err error) {
  78. o := orm.NewOrmUsingDB("data")
  79. sql := `SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 `
  80. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  81. return
  82. }
  83. func GetExcelClassifyByParentId(parentId, source int) (items []*ExcelClassifyItems, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  86. _, err = o.Raw(sql, parentId, source).QueryRows(&items)
  87. return
  88. }
  89. func GetExcelClassifyBySource(source int) (items []*ExcelClassifyItems, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  92. _, err = o.Raw(sql, source).QueryRows(&items)
  93. return
  94. }
  95. func GetExcelClassifyBySourceOrderByLevel(source int) (items []*ExcelClassifyItems, err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by level asc, sort asc,excel_classify_id asc`
  98. _, err = o.Raw(sql, source).QueryRows(&items)
  99. return
  100. }
  101. func GetExcelClassifyAll() (items []*ExcelClassifyItems, err error) {
  102. o := orm.NewOrmUsingDB("data")
  103. sql := ` SELECT * FROM excel_classify WHERE parent_id<>0 AND is_delete=0 order by sort asc,excel_classify_id asc`
  104. _, err = o.Raw(sql).QueryRows(&items)
  105. return
  106. }
  107. type ExcelClassifyItems struct {
  108. ExcelClassifyId int `description:"分类id"`
  109. ExcelInfoId int `description:"表格id"`
  110. ExcelClassifyName string
  111. ParentId int
  112. Level int `description:"层级"`
  113. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  114. UniqueCode string `description:"唯一编码"`
  115. SysUserId int `description:"创建人id"`
  116. SysUserRealName string `description:"创建人姓名"`
  117. StartDate string `description:"自定义开始日期"`
  118. Children []*ExcelClassifyItems
  119. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  120. HaveOperaAuth bool `description:"是否有数据权限"`
  121. }
  122. func GetExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  123. o := orm.NewOrmUsingDB("data")
  124. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  125. if condition != "" {
  126. sql += condition
  127. }
  128. err = o.Raw(sql, pars).QueryRow(&item)
  129. return
  130. }
  131. // GetNextExcelClassifyByCondition 获取下一个分类
  132. func GetNextExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  133. o := orm.NewOrmUsingDB("data")
  134. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  135. if condition != "" {
  136. sql += condition
  137. }
  138. sql += " ORDER BY sort asc , create_time ASC LIMIT 1 "
  139. err = o.Raw(sql, pars).QueryRow(&item)
  140. return
  141. }
  142. // GetFirstExcelClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  143. func GetFirstExcelClassifyByParentId(parentId int) (item *ExcelClassify, err error) {
  144. o := orm.NewOrmUsingDB("data")
  145. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 order by sort asc,excel_classify_id asc limit 1`
  146. err = o.Raw(sql, parentId).QueryRow(&item)
  147. return
  148. }
  149. // UpdateExcelClassifySortByParentId 根据图表父类id更新排序
  150. func UpdateExcelClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  151. o := orm.NewOrmUsingDB("data")
  152. sql := ` update excel_classify set sort = ` + updateSort + ` WHERE parent_id=? and source=? and sort > ? AND is_delete=0 `
  153. if classifyId > 0 {
  154. sql += ` or ( excel_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  155. }
  156. _, err = o.Raw(sql, parentId, source, nowSort).Exec()
  157. return
  158. }
  159. // Update 更新图表分类基础信息
  160. func (ExcelClassify *ExcelClassify) Update(cols []string) (err error) {
  161. o := orm.NewOrmUsingDB("data")
  162. _, err = o.Update(ExcelClassify, cols...)
  163. return
  164. }
  165. // GetExcelClassifyMaxSort 获取图表分类下最大的排序数
  166. func GetExcelClassifyMaxSort(parentId int, source int) (sort int, err error) {
  167. o := orm.NewOrmUsingDB("data")
  168. sql := `SELECT Max(sort) AS sort FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 `
  169. err = o.Raw(sql, parentId, source).QueryRow(&sort)
  170. return
  171. }
  172. type ExcelClassifyView struct {
  173. ExcelClassifyId int `orm:"column(excel_classify_id);pk"`
  174. ExcelClassifyName string `description:"分类名称"`
  175. ParentId int `description:"父级id"`
  176. }
  177. func GetExcelClassifyViewById(classifyId int) (item *ExcelClassifyView, err error) {
  178. o := orm.NewOrmUsingDB("data")
  179. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  180. err = o.Raw(sql, classifyId).QueryRow(&item)
  181. return
  182. }
  183. // ExcelClassifyItemBySort 自定义比较函数,按年龄从小到大排序
  184. func ExcelClassifyItemBySort(p1, p2 *ExcelClassifyItems) bool {
  185. return p1.Sort < p2.Sort
  186. }
  187. // GetClassifyByIdList
  188. // @Description: 根据分类ID列表获取分类列表
  189. // @author: Roc
  190. // @datetime 2024-04-02 19:40:30
  191. // @param classifyIdList []int
  192. // @return items []*ExcelClassify
  193. // @return err error
  194. func GetClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  195. num := len(classifyIdList)
  196. if num <= 0 {
  197. return
  198. }
  199. o := orm.NewOrmUsingDB("data")
  200. sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetOrmInReplace(num) + `) AND is_delete=0 `
  201. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  202. return
  203. }