base_from_fenwei_classify.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // BaseFromFenweiClassify 汾渭原始数据分类表
  8. type BaseFromFenweiClassify struct {
  9. ClassifyId int `orm:"column(classify_id);pk"`
  10. ClassifyName string `description:"分类名称"`
  11. ParentId int `description:"父级id"`
  12. SysUserId int `description:"创建人id"`
  13. SysUserRealName string `description:"创建人姓名"`
  14. Level int `description:"层级"`
  15. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. CreateTime time.Time `description:"创建时间"`
  18. }
  19. // GetBaseFromFenweiClassify 获取所有分类
  20. func GetBaseFromFenweiClassify() (items []*BaseFromFenweiClassify, err error) {
  21. o := orm.NewOrmUsingDB("data")
  22. sql := ` SELECT * FROM base_from_fenwei_classify ORDER BY parent_id ASC, sort ASC, classify_id ASC`
  23. _, err = o.Raw(sql).QueryRows(&items)
  24. return
  25. }
  26. // BaseFromFenweiClassifyItem 汾渭数据分类信息
  27. type BaseFromFenweiClassifyItem struct {
  28. ClassifyId int `description:"分类ID"`
  29. ClassifyName string `description:"分类名称"`
  30. ParentId int `description:"父级id"`
  31. Level int `description:"层级"`
  32. Sort int `description:"排序字段"`
  33. CreateTime string `description:"创建时间"`
  34. ModifyTime string `description:"修改时间"`
  35. Child []*BaseFromFenweiClassifyItem `description:"子分类"`
  36. }
  37. func (y *BaseFromFenweiClassify) Format2Item(origin *BaseFromFenweiClassify) (item *BaseFromFenweiClassifyItem) {
  38. if origin == nil {
  39. return
  40. }
  41. item = new(BaseFromFenweiClassifyItem)
  42. item.ClassifyId = origin.ClassifyId
  43. item.ClassifyName = origin.ClassifyName
  44. item.ParentId = origin.ParentId
  45. item.Level = origin.Level
  46. item.Sort = origin.Sort
  47. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  48. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  49. return
  50. }
  51. // GetFenweiClassifyItemByClassifyId 根据分类id查询分类信息
  52. func GetFenweiClassifyItemByClassifyId(classifyId int) (item *BaseFromFenweiClassifyItem, err error) {
  53. o := orm.NewOrmUsingDB("data")
  54. sql := ` SELECT * FROM base_from_fenwei_classify WHERE classify_id = ?`
  55. var origin BaseFromFenweiClassify
  56. err = o.Raw(sql, classifyId).QueryRow(&origin)
  57. if err != nil {
  58. return
  59. }
  60. item = origin.Format2Item(&origin)
  61. return
  62. }