excel_classify.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. // 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. type ExcelClassify struct {
  25. ExcelClassifyId int `gorm:"column:excel_classify_id;primaryKey" orm:"column(excel_classify_id);pk"` // 主键
  26. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1" gorm:"column:source"`
  27. ExcelClassifyName string `description:"分类名称" gorm:"column:excel_classify_name"`
  28. ParentId int `description:"父级id" gorm:"column:parent_id"`
  29. SysUserId int `description:"创建人id" gorm:"column:sys_user_id"`
  30. SysUserRealName string `description:"创建人姓名" gorm:"column:sys_user_real_name"`
  31. Level int `description:"层级" gorm:"column:level"`
  32. UniqueCode string `description:"唯一编码" gorm:"column:unique_code"`
  33. Sort int `description:"排序字段,越小越靠前,默认值:10" gorm:"column:sort"`
  34. IsDelete int `description:"是否删除,0:未删除;1:已删除,默认值:0" gorm:"column:is_delete"` // 修改了注释以避免混淆
  35. CreateTime time.Time `description:"创建时间" gorm:"column:create_time"`
  36. ModifyTime time.Time `description:"修改时间" gorm:"column:modify_time"`
  37. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" gorm:"column:is_join_permission"`
  38. }
  39. // TableName 设置模型对应的表名
  40. func (ExcelClassify) TableName() string {
  41. return "excel_classify"
  42. }
  43. // AddExcelClassify 添加excel分类
  44. // func AddExcelClassify(item *ExcelClassify) (lastId int64, err error) {
  45. // o := orm.NewOrmUsingDB("data")
  46. // lastId, err = o.Insert(item)
  47. // if err != nil {
  48. // return
  49. // }
  50. // item.ExcelClassifyId = int(lastId)
  51. // return
  52. // }
  53. func AddExcelClassify(item *ExcelClassify) (lastId int64, err error) {
  54. o := global.DmSQL["data"]
  55. err = o.Create(item).Error
  56. if err != nil {
  57. return
  58. }
  59. lastId = int64(item.ExcelClassifyId)
  60. return
  61. }
  62. // GetExcelClassifyCount 获取同级分类下存在同名分类的数量
  63. //
  64. // func GetExcelClassifyCount(ExcelClassifyName string, parentId, source int) (count int, err error) {
  65. // o := orm.NewOrmUsingDB("data")
  66. // sql := `SELECT COUNT(1) AS count FROM excel_classify WHERE parent_id=? AND source = ? AND excel_classify_name=? AND is_delete=0 `
  67. // err = o.Raw(sql, parentId, source, ExcelClassifyName).QueryRow(&count)
  68. // return
  69. // }
  70. func GetExcelClassifyCount(ExcelClassifyName string, parentId, source int) (count int, err error) {
  71. o := global.DmSQL["data"]
  72. sql := `SELECT COUNT(1) AS count FROM excel_classify WHERE parent_id=? AND source = ? AND excel_classify_name=? AND is_delete=0 `
  73. err = o.Raw(sql, parentId, source, ExcelClassifyName).Scan(&count).Error
  74. return
  75. }
  76. // func GetExcelClassifyById(classifyId int) (item *ExcelClassify, err error) {
  77. // o := orm.NewOrmUsingDB("data")
  78. // sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  79. // err = o.Raw(sql, classifyId).QueryRow(&item)
  80. // return
  81. // }
  82. func GetExcelClassifyById(classifyId int) (item *ExcelClassify, err error) {
  83. o := global.DmSQL["data"]
  84. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  85. err = o.Raw(sql, classifyId).First(&item).Error
  86. return
  87. }
  88. // GetExcelClassifyByIdList
  89. // @Description: 根据分类id列表获取所有分类信息
  90. // @author: Roc
  91. // @datetime 2024-04-07 16:24:04
  92. // @param classifyIdList []int
  93. // @return items []*ExcelClassify
  94. // @return err error
  95. // func GetExcelClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  96. // num := len(classifyIdList)
  97. // if num <= 0 {
  98. // return
  99. // }
  100. // o := orm.NewOrmUsingDB("data")
  101. // sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetOrmInReplace(num) + `) AND is_delete=0 `
  102. // _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  103. // return
  104. // }
  105. // GetExcelClassifyByIdList
  106. // @Description: 根据分类id列表获取所有分类信息
  107. // @author: zqbao
  108. // @datetime 2024-04-07 16:24:04
  109. // @param classifyIdList []int
  110. // @return items []*ExcelClassify
  111. // @return err error
  112. func GetExcelClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  113. num := len(classifyIdList)
  114. if num <= 0 {
  115. return
  116. }
  117. o := global.DmSQL["data"]
  118. sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetGormInReplace(num) + `) AND is_delete=0 `
  119. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  120. return
  121. }
  122. // GetExcelClassifyBySourceAndIsJoinPermission
  123. // @Description: 根据分类id列表获取所有分类信息
  124. // @author: Roc
  125. // @datetime 2024-04-07 16:24:04
  126. // @param classifyIdList []int
  127. // @return items []*ExcelClassify
  128. // @return err error
  129. // func GetExcelClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ExcelClassify, err error) {
  130. // o := orm.NewOrmUsingDB("data")
  131. // sql := `SELECT * FROM excel_classify WHERE source = ? AND is_join_permission = ? `
  132. // _, err = o.Raw(sql, source, isJoinPermission).QueryRows(&items)
  133. // return
  134. // }
  135. // GetExcelClassifyBySourceAndIsJoinPermission
  136. // @Description: 根据分类id列表获取所有分类信息
  137. // @author: zqbao
  138. // @datetime 2024-04-07 16:24:04
  139. // @param classifyIdList []int
  140. // @return items []*ExcelClassify
  141. // @return err error
  142. func GetExcelClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ExcelClassify, err error) {
  143. o := global.DmSQL["data"]
  144. sql := `SELECT * FROM excel_classify WHERE source = ? AND is_join_permission = ? `
  145. err = o.Raw(sql, source, isJoinPermission).Scan(&items).Error
  146. return
  147. }
  148. // func GetChildClassifyById(classifyId int) (items []*ExcelClassify, err error) {
  149. // o := orm.NewOrmUsingDB("data")
  150. // sql := `SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 `
  151. // _, err = o.Raw(sql, classifyId).QueryRows(&items)
  152. // return
  153. // }
  154. func GetChildClassifyById(classifyId int) (items []*ExcelClassify, err error) {
  155. o := global.DmSQL["data"]
  156. sql := `SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 `
  157. err = o.Raw(sql, classifyId).Scan(&items).Error
  158. return
  159. }
  160. func GetExcelClassifyByParentId(parentId, source int) (items []*ExcelClassifyItems, err error) {
  161. o := global.DmSQL["data"]
  162. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  163. err = o.Raw(sql, parentId, source).Scan(&items).Error
  164. return
  165. }
  166. // func GetExcelClassifyBySource(source int) (items []*ExcelClassifyItems, err error) {
  167. // o := orm.NewOrmUsingDB("data")
  168. // sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  169. // _, err = o.Raw(sql, source).QueryRows(&items)
  170. // return
  171. // }
  172. func GetExcelClassifyBySource(source int) (items []*ExcelClassifyItems, err error) {
  173. o := global.DmSQL["data"]
  174. sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by sort asc,excel_classify_id asc`
  175. err = o.Raw(sql, source).Scan(&items).Error
  176. return
  177. }
  178. // func GetExcelClassifyBySourceOrderByLevel(source int) (items []*ExcelClassifyItems, err error) {
  179. // o := orm.NewOrmUsingDB("data")
  180. // sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by level asc, sort asc,excel_classify_id asc`
  181. // _, err = o.Raw(sql, source).QueryRows(&items)
  182. // return
  183. // }
  184. func GetExcelClassifyBySourceOrderByLevel(source int) (items []*ExcelClassifyItems, err error) {
  185. o := global.DmSQL["data"]
  186. sql := ` SELECT * FROM excel_classify WHERE source = ? AND is_delete=0 order by level asc, sort asc,excel_classify_id asc`
  187. err = o.Raw(sql, source).Scan(&items).Error
  188. return
  189. }
  190. func GetExcelClassifyAll() (items []*ExcelClassifyItems, err error) {
  191. o := global.DmSQL["data"]
  192. sql := ` SELECT * FROM excel_classify WHERE parent_id<>0 AND is_delete=0 order by sort asc,excel_classify_id asc`
  193. err = o.Raw(sql).Scan(&items).Error
  194. return
  195. }
  196. // type ExcelClassifyItems struct {
  197. // ExcelClassifyId int `description:"分类id"`
  198. // ExcelInfoId int `description:"表格id"`
  199. // ExcelClassifyName string
  200. // ParentId int
  201. // Level int `description:"层级"`
  202. // Sort int `description:"排序字段,越小越靠前,默认值:10"`
  203. // UniqueCode string `description:"唯一编码"`
  204. // SysUserId int `description:"创建人id"`
  205. // SysUserRealName string `description:"创建人姓名"`
  206. // StartDate string `description:"自定义开始日期"`
  207. // Children []*ExcelClassifyItems
  208. // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  209. // HaveOperaAuth bool `description:"是否有数据权限"`
  210. // }
  211. type ExcelClassifyItems struct {
  212. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"分类id"` // 分类id
  213. ExcelInfoId int `gorm:"column:excel_info_id" description:"表格id"` // 表格id
  214. ExcelClassifyName string `gorm:"column:excel_classify_name" description:"分类名称"`
  215. ParentId int `gorm:"column:parent_id" description:"父级id"`
  216. Level int `gorm:"column:level" description:"层级"` // 层级
  217. Sort int `gorm:"column:sort" description:"排序字段,越小越靠前,默认值:10"` // 排序字段,越小越靠前,默认值:10
  218. UniqueCode string `gorm:"column:unique_code" description:"唯一编码"` // 唯一编码
  219. SysUserId int `gorm:"column:sys_user_id" description:"创建人id"` // 创建人id
  220. SysUserRealName string `gorm:"column:sys_user_real_name" description:"创建人姓名"` // 创建人姓名
  221. StartDate string `gorm:"column:start_date" description:"自定义开始日期"` // 自定义开始日期
  222. Children []*ExcelClassifyItems `gorm:"-"`
  223. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"` // 是否加入权限管控,0:不加入;1:加入;默认:0
  224. HaveOperaAuth bool `gorm:"column:have_opener_auth" description:"是否有数据权限"` // 是否有数据权限
  225. }
  226. // TableName 设置模型对应的表名
  227. func (ExcelClassifyItems) TableName() string {
  228. return "excel_classify_items"
  229. }
  230. func GetExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  231. o := global.DmSQL["data"]
  232. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  233. if condition != "" {
  234. sql += condition
  235. }
  236. err = o.Raw(sql, pars...).First(&item).Error
  237. return
  238. }
  239. // GetNextExcelClassifyByCondition 获取下一个分类
  240. // func GetNextExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  241. // o := orm.NewOrmUsingDB("data")
  242. // sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  243. // if condition != "" {
  244. // sql += condition
  245. // }
  246. // sql += " ORDER BY sort asc , create_time ASC LIMIT 1 "
  247. // err = o.Raw(sql, pars).QueryRow(&item)
  248. // return
  249. // }
  250. func GetNextExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
  251. o := global.DmSQL["data"]
  252. sql := ` SELECT * FROM excel_classify WHERE 1=1 AND is_delete=0 `
  253. if condition != "" {
  254. sql += condition
  255. }
  256. sql += " ORDER BY sort asc , create_time ASC LIMIT 1 "
  257. err = o.Raw(sql, pars...).First(&item).Error
  258. return
  259. }
  260. // GetFirstExcelClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  261. // func GetFirstExcelClassifyByParentId(parentId int) (item *ExcelClassify, err error) {
  262. // o := orm.NewOrmUsingDB("data")
  263. // sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 order by sort asc,excel_classify_id asc limit 1`
  264. // err = o.Raw(sql, parentId).QueryRow(&item)
  265. // return
  266. // }
  267. func GetFirstExcelClassifyByParentId(parentId int) (item *ExcelClassify, err error) {
  268. o := global.DmSQL["data"]
  269. sql := ` SELECT * FROM excel_classify WHERE parent_id=? AND is_delete=0 order by sort asc,excel_classify_id asc limit 1`
  270. err = o.Raw(sql, parentId).First(&item).Error
  271. return
  272. }
  273. // UpdateExcelClassifySortByParentId 根据图表父类id更新排序
  274. // func UpdateExcelClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  275. // o := orm.NewOrmUsingDB("data")
  276. // sql := ` update excel_classify set sort = ` + updateSort + ` WHERE parent_id=? and source=? and sort > ? AND is_delete=0 `
  277. // if classifyId > 0 {
  278. // sql += ` or ( excel_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  279. // }
  280. // _, err = o.Raw(sql, parentId, source, nowSort).Exec()
  281. // return
  282. // }
  283. func UpdateExcelClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  284. o := global.DmSQL["data"]
  285. sql := ` update excel_classify set sort = ` + updateSort + ` WHERE parent_id=? and source=? and sort > ? AND is_delete=0 `
  286. if classifyId > 0 {
  287. sql += ` or ( excel_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  288. }
  289. err = o.Exec(sql, parentId, source, nowSort).Error
  290. return
  291. }
  292. // Update 更新图表分类基础信息
  293. // func (ExcelClassify *ExcelClassify) Update(cols []string) (err error) {
  294. // o := orm.NewOrmUsingDB("data")
  295. // _, err = o.Update(ExcelClassify, cols...)
  296. // return
  297. // }
  298. func (ExcelClassify *ExcelClassify) Update(cols []string) (err error) {
  299. o := global.DmSQL["data"]
  300. err = o.Model(ExcelClassify).Select(cols).Updates(ExcelClassify).Error
  301. return
  302. }
  303. // GetExcelClassifyMaxSort 获取图表分类下最大的排序数
  304. // func GetExcelClassifyMaxSort(parentId int, source int) (sort int, err error) {
  305. // o := orm.NewOrmUsingDB("data")
  306. // sql := `SELECT Max(sort) AS sort FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 `
  307. // err = o.Raw(sql, parentId, source).QueryRow(&sort)
  308. // return
  309. // }
  310. func GetExcelClassifyMaxSort(parentId int, source int) (sort int, err error) {
  311. o := global.DmSQL["data"]
  312. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM excel_classify WHERE parent_id=? AND source = ? AND is_delete=0 `
  313. err = o.Raw(sql, parentId, source).Scan(&sort).Error
  314. return
  315. }
  316. // type ExcelClassifyView struct {
  317. // ExcelClassifyId int `orm:"column(excel_classify_id);pk"`
  318. // ExcelClassifyName string `description:"分类名称"`
  319. // ParentId int `description:"父级id"`
  320. // }
  321. type ExcelClassifyView struct {
  322. ExcelClassifyId int `orm:"column(excel_classify_id);pk" gorm:"column:excel_classify_id;primaryKey"` // 主键
  323. ExcelClassifyName string `description:"分类名称" gorm:"column:excel_classify_name"` // 分类名称
  324. ParentId int `description:"父级id" gorm:"column:parent_id"` // 父级id
  325. }
  326. // func GetExcelClassifyViewById(classifyId int) (item *ExcelClassifyView, err error) {
  327. // o := orm.NewOrmUsingDB("data")
  328. // sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  329. // err = o.Raw(sql, classifyId).QueryRow(&item)
  330. // return
  331. // }
  332. func GetExcelClassifyViewById(classifyId int) (item *ExcelClassifyView, err error) {
  333. o := global.DmSQL["data"]
  334. sql := `SELECT * FROM excel_classify WHERE excel_classify_id=? AND is_delete=0 `
  335. err = o.Raw(sql, classifyId).First(&item).Error
  336. return
  337. }
  338. // ExcelClassifyItemBySort 自定义比较函数,按年龄从小到大排序
  339. func ExcelClassifyItemBySort(p1, p2 *ExcelClassifyItems) bool {
  340. return p1.Sort < p2.Sort
  341. }
  342. // GetClassifyByIdList
  343. // @Description: 根据分类ID列表获取分类列表
  344. // @author: Roc
  345. // @datetime 2024-04-02 19:40:30
  346. // @param classifyIdList []int
  347. // @return items []*ExcelClassify
  348. // @return err error
  349. func GetClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  350. num := len(classifyIdList)
  351. if num <= 0 {
  352. return
  353. }
  354. o := global.DmSQL["data"]
  355. sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetGormInReplace(num) + `) AND is_delete=0 `
  356. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  357. return
  358. }
  359. // func GetClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err error) {
  360. // num := len(classifyIdList)
  361. // if num <= 0 {
  362. // return
  363. // }
  364. // o := orm.NewOrmUsingDB("data")
  365. // sql := `SELECT * FROM excel_classify WHERE excel_classify_id in (` + utils.GetOrmInReplace(num) + `) AND is_delete=0 `
  366. // _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  367. // return
  368. // }