base_from_purang_classify.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package data_manage
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. // BaseFromPurangClassify Purang原始数据分类表
  8. type BaseFromPurangClassify struct {
  9. ClassifyId int `orm:"column(classify_id);pk" gorm:"column:classify_id;primary_key"`
  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. // GetBaseFromPurangClassifyCount 获取分类名称的个数
  20. func GetBaseFromPurangClassifyCount(classifyName string, parentId int) (count int, err error) {
  21. sql := `SELECT COUNT(1) AS count FROM base_from_purang_classify WHERE classify_name=? AND parent_id=? `
  22. err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyName, parentId).Scan(&count).Error
  23. return
  24. }
  25. // GetBaseFromPurangClassifyById 通过分类id的获取分类信息
  26. func GetBaseFromPurangClassifyById(classifyId int) (item *BaseFromPurangClassify, err error) {
  27. sql := `SELECT * FROM base_from_purang_classify WHERE classify_id=? `
  28. err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).Find(&item).Error
  29. return
  30. }
  31. // GetBaseFromPurangClassifyByIds 通过分类id的获取分类信息
  32. func GetBaseFromPurangClassifyByIds(classifyIds []int) (items []*BaseFromPurangClassify, err error) {
  33. if len(classifyIds) == 0 {
  34. return
  35. }
  36. sql := `SELECT * FROM base_from_purang_classify WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) `
  37. err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyIds).Find(&items).Error
  38. return
  39. }
  40. // EditBaseFromPurangClassify 修改Purang原始数据分类
  41. func EditBaseFromPurangClassify(classifyId int, classifyName string) (err error) {
  42. sql := `UPDATE base_from_purang_classify SET classify_name=?,modify_time=NOW() WHERE classify_id=? `
  43. err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyName, classifyId).Error
  44. return
  45. }
  46. // UpdateBaseFromPurangClassifySort 修改Purang原始数据分类的排序
  47. func UpdateBaseFromPurangClassifySort(classifyId int) (err error) {
  48. sql := `UPDATE base_from_purang_classify SET sort=classify_id, modify_time=NOW() WHERE classify_id=? `
  49. err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyId).Error
  50. return
  51. }
  52. type BaseFromPurangClassifyItems struct {
  53. ClassifyId int `description:"分类ID"`
  54. BaseFromPurangIndexId int `description:"指标类型ID"`
  55. IndexCode string `description:"指标唯一编码"`
  56. ClassifyName string `description:"分类名称"`
  57. ClassifyNameEn string `description:"分类名称"`
  58. UniqueCode string `description:"分类唯一编码"`
  59. ParentId int `description:"父级id"`
  60. Level int `description:"层级"`
  61. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  62. Children []*BaseFromPurangClassifyItems `gorm:"-"`
  63. }
  64. type BaseFromPurangClassifyNameItems struct {
  65. ClassifyId int `description:"分类ID"`
  66. ClassifyName string `description:"分类名称"`
  67. ParentId int `description:"父级id"`
  68. }
  69. type BaseFromPurangClassifyResp struct {
  70. List []*BaseFromPurangClassifyItems
  71. }
  72. type BaseFromPurangClassifyNameResp struct {
  73. List []*BaseFromPurangClassifyNameItems
  74. }
  75. type BaseFromPurangClassifyItemsButton struct {
  76. AddButton bool `description:"是否可添加"`
  77. OpButton bool `description:"是否可编辑"`
  78. DeleteButton bool `description:"是否可删除"`
  79. MoveButton bool `description:"是否可移动"`
  80. }
  81. // GetBaseFromPurangClassifyByParentId 根据上级id获取当下的分类列表数据
  82. func GetBaseFromPurangClassifyByParentId(parentId int) (items []*BaseFromPurangClassifyItems, err error) {
  83. sql := ` SELECT * FROM base_from_purang_classify WHERE parent_id=? order by sort asc,classify_id asc`
  84. err = global.DbMap[utils.DbNameIndex].Raw(sql, parentId).Find(&items).Error
  85. return
  86. }
  87. // GetAllBaseFromPurangClassify 获取所有的分类列表数据
  88. func GetAllBaseFromPurangClassify() (items []*BaseFromPurangClassifyItems, err error) {
  89. sql := ` SELECT * FROM base_from_purang_classify order by parent_id asc, sort asc,classify_id asc`
  90. err = global.DbMap[utils.DbNameIndex].Raw(sql).Find(&items).Error
  91. return
  92. }
  93. type DeleteBaseFromPurangClassifyReq struct {
  94. ClassifyId int `description:"分类id"`
  95. EdbInfoId int `description:"指标id"`
  96. }
  97. type BaseFromPurangClassifyListResp struct {
  98. AllNodes []*BaseFromPurangClassifyItems
  99. CanOpClassify bool `description:"是否允许操作分类"`
  100. }
  101. type BaseFromPurangClassifySimplify struct {
  102. ClassifyId int `description:"分类id"`
  103. ClassifyName string `description:"分类名称"`
  104. ParentId int
  105. }
  106. // GetFirstBaseFromPurangClassify 获取当前分类下,且排序数相同 的排序第一条的数据
  107. func GetFirstBaseFromPurangClassify() (item *BaseFromPurangClassify, err error) {
  108. sql := ` SELECT * FROM base_from_purang_classify order by sort asc,classify_id asc limit 1`
  109. err = global.DbMap[utils.DbNameIndex].Raw(sql).First(&item).Error
  110. return
  111. }
  112. // Update 更新分类基础信息
  113. func (BaseFromPurangClassify *BaseFromPurangClassify) Update(cols []string) (err error) {
  114. err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(BaseFromPurangClassify).Error
  115. return
  116. }
  117. type AddPurangClassifyResp struct {
  118. ClassifyId int
  119. }