excel_classify.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package excel
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "fmt"
  6. "time"
  7. )
  8. type ExcelClassify struct {
  9. ExcelClassifyId int `gorm:"column:excel_classify_id;primaryKey" orm:"column(excel_classify_id);pk"` // 主键
  10. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1" gorm:"column:source"`
  11. ExcelClassifyName string `description:"分类名称" gorm:"column:excel_classify_name"`
  12. ParentId int `description:"父级id" gorm:"column:parent_id"`
  13. SysUserId int `description:"创建人id" gorm:"column:sys_user_id"`
  14. SysUserRealName string `description:"创建人姓名" gorm:"column:sys_user_real_name"`
  15. Level int `description:"层级" gorm:"column:level"`
  16. UniqueCode string `description:"唯一编码" gorm:"column:unique_code"`
  17. Sort int `description:"排序字段,越小越靠前,默认值:10" gorm:"column:sort"`
  18. IsDelete int `description:"是否删除,0:未删除;1:已删除,默认值:0" gorm:"column:is_delete"` // 修改了注释以避免混淆
  19. CreateTime time.Time `description:"创建时间" gorm:"column:create_time"`
  20. ModifyTime time.Time `description:"修改时间" gorm:"column:modify_time"`
  21. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" gorm:"column:is_join_permission"`
  22. }
  23. func (ExcelClassify) TableName() string {
  24. return "excel_classify"
  25. }
  26. func AddExcelClassify(item *ExcelClassify) (lastId int64, err error) {
  27. o := global.DmSQL["data"]
  28. err = o.Create(item).Error
  29. if err != nil {
  30. return
  31. }
  32. lastId = int64(item.ExcelClassifyId)
  33. return
  34. }
  35. func GetExcelClassifyCount(ExcelClassifyName string, parentId, source int) (count int, err error) {
  36. o := global.DmSQL["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).Scan(&count).Error
  39. return
  40. }
  41. func GetExcelClassifyById(classifyId int) (item *ExcelClassify, err error) {
  42. o := global.DmSQL["data"]
  43. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  44. err = o.Raw(sql, classifyId).First(&item).Error
  45. return
  46. }
  47. func GetExcelClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  48. num := len(classifyIdList)
  49. if num <= 0 {
  50. return
  51. }
  52. o := global.DmSQL["data"]
  53. sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetGormInReplace(num) + `) AND is_delete=0 `
  54. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  55. return
  56. }
  57. func GetExcelClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ExcelClassify, err error) {
  58. o := global.DmSQL["data"]
  59. sql := `SELECT * FROM excel_classify WHERE source = ? AND is_join_permission = ? `
  60. err = o.Raw(sql, source, isJoinPermission).Scan(&items).Error
  61. return
  62. }
  63. func GetChildClassifyById(classifyId int) (items []*ExcelClassify, err error) {
  64. o := global.DmSQL["data"]
  65. sql := `SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 `
  66. err = o.Raw(sql, classifyId).Scan(&items).Error
  67. return
  68. }
  69. func GetExcelClassifyByParentId(parentId, source int) (items []*ExcelClassifyItems, err error) {
  70. o := global.DmSQL["data"]
  71. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  72. err = o.Raw(sql, parentId, source).Scan(&items).Error
  73. return
  74. }
  75. func GetExcelClassifyBySource(source int) (items []*ExcelClassifyItems, err error) {
  76. o := global.DmSQL["data"]
  77. sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  78. err = o.Raw(sql, source).Scan(&items).Error
  79. return
  80. }
  81. func GetExcelClassifyBySourceOrderByLevel(source int) (items []*ExcelClassifyItems, err error) {
  82. o := global.DmSQL["data"]
  83. sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by level asc, sort asc,excel_classify_id asc`
  84. err = o.Raw(sql, source).Scan(&items).Error
  85. return
  86. }
  87. func GetExcelClassifyAll() (items []*ExcelClassifyItems, err error) {
  88. o := global.DmSQL["data"]
  89. sql := ` SELECT * FROM excel_classify WHERE parent_id<>0 AND is_delete=0 order by sort asc,excel_classify_id asc`
  90. err = o.Raw(sql).Scan(&items).Error
  91. return
  92. }
  93. type ExcelClassifyItems struct {
  94. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"分类id"` // 分类id
  95. ExcelInfoId int `gorm:"column:excel_info_id" description:"表格id"` // 表格id
  96. ExcelClassifyName string `gorm:"column:excel_classify_name" description:"分类名称"`
  97. ParentId int `gorm:"column:parent_id" description:"父级id"`
  98. Level int `gorm:"column:level" description:"层级"` // 层级
  99. Sort int `gorm:"column:sort" description:"排序字段,越小越靠前,默认值:10"` // 排序字段,越小越靠前,默认值:10
  100. UniqueCode string `gorm:"column:unique_code" description:"唯一编码"` // 唯一编码
  101. SysUserId int `gorm:"column:sys_user_id" description:"创建人id"` // 创建人id
  102. SysUserRealName string `gorm:"column:sys_user_real_name" description:"创建人姓名"` // 创建人姓名
  103. StartDate string `gorm:"column:start_date" description:"自定义开始日期"` // 自定义开始日期
  104. Children []*ExcelClassifyItems `gorm:"-"`
  105. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"` // 是否加入权限管控,0:不加入;1:加入;默认:0
  106. HaveOperaAuth bool `gorm:"column:have_opener_auth" description:"是否有数据权限"` // 是否有数据权限
  107. }
  108. func (ExcelClassifyItems) TableName() string {
  109. return "excel_classify_items"
  110. }
  111. func GetExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  112. o := global.DmSQL["data"]
  113. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  114. if condition != "" {
  115. sql += condition
  116. }
  117. err = o.Raw(sql, pars...).First(&item).Error
  118. return
  119. }
  120. func GetNextExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  121. o := global.DmSQL["data"]
  122. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  123. if condition != "" {
  124. sql += condition
  125. }
  126. sql += " ORDER BY sort asc , create_time ASC LIMIT 1 "
  127. err = o.Raw(sql, pars...).First(&item).Error
  128. return
  129. }
  130. func GetFirstExcelClassifyByParentId(parentId int) (item *ExcelClassify, err error) {
  131. o := global.DmSQL["data"]
  132. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 order by sort asc,excel_classify_id asc limit 1`
  133. err = o.Raw(sql, parentId).First(&item).Error
  134. return
  135. }
  136. func UpdateExcelClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  137. o := global.DmSQL["data"]
  138. sql := ` update excel_classify set sort = ` + updateSort + ` WHERE parent_id=? and source=? and sort > ? AND is_delete=0 `
  139. if classifyId > 0 {
  140. sql += ` or ( excel_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  141. }
  142. err = o.Exec(sql, parentId, source, nowSort).Error
  143. return
  144. }
  145. func (ExcelClassify *ExcelClassify) Update(cols []string) (err error) {
  146. o := global.DmSQL["data"]
  147. err = o.Model(ExcelClassify).Select(cols).Updates(ExcelClassify).Error
  148. return
  149. }
  150. func GetExcelClassifyMaxSort(parentId int, source int) (sort int, err error) {
  151. o := global.DmSQL["data"]
  152. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 `
  153. err = o.Raw(sql, parentId, source).Scan(&sort).Error
  154. return
  155. }
  156. type ExcelClassifyView struct {
  157. ExcelClassifyId int `orm:"column(excel_classify_id);pk" gorm:"column:excel_classify_id;primaryKey"` // 主键
  158. ExcelClassifyName string `description:"分类名称" gorm:"column:excel_classify_name"` // 分类名称
  159. ParentId int `description:"父级id" gorm:"column:parent_id"` // 父级id
  160. }
  161. func GetExcelClassifyViewById(classifyId int) (item *ExcelClassifyView, err error) {
  162. o := global.DmSQL["data"]
  163. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  164. err = o.Raw(sql, classifyId).First(&item).Error
  165. return
  166. }
  167. func ExcelClassifyItemBySort(p1, p2 *ExcelClassifyItems) bool {
  168. return p1.Sort < p2.Sort
  169. }
  170. func GetClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  171. num := len(classifyIdList)
  172. if num <= 0 {
  173. return
  174. }
  175. o := global.DmSQL["data"]
  176. sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetGormInReplace(num) + `) AND is_delete=0 `
  177. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  178. return
  179. }