excel_classify.go 8.8 KB

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