base_from_clarksons_classify.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. // BaseFromClarksonsClassify 卓创红期原始数据分类表
  8. type BaseFromClarksonsClassify struct {
  9. BaseFromClassifyId int `orm:"column(base_from_clarksons_classify_id);pk"`
  10. ClassifyName string `description:"分类名称"`
  11. ParentId int `description:"父级id"`
  12. Level int `description:"层级"`
  13. Sort int `description:"排序字段"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. CreateTime time.Time `description:"创建时间"`
  16. }
  17. type BaseFromClarksonsClassifyItem struct {
  18. BaseFromClassifyId int `orm:"column(base_from_clarksons_classify_id);pk"`
  19. ClassifyName string `description:"分类名称"`
  20. ParentId int `description:"父级id"`
  21. Level int `description:"层级"`
  22. Sort int `description:"排序字段"`
  23. UniqueCode string `description:"唯一code"`
  24. ModifyTime time.Time `description:"修改时间"`
  25. CreateTime time.Time `description:"创建时间"`
  26. ClassifyNameEn string `description:"英文分类名称"`
  27. Children []*BaseFromClarksonsClassifyItem `description:"子分类"`
  28. }
  29. type BaseFromClarksonsClassifyMaxSort struct {
  30. BaseFromClassifyId int `description:"分类id"`
  31. MaxSort int `description:"最大排序"`
  32. }
  33. func (t *BaseFromClarksonsClassify) Add() (insertId int64, err error) {
  34. o := orm.NewOrmUsingDB("data")
  35. insertId, err = o.Insert(t)
  36. return
  37. }
  38. func (t *BaseFromClarksonsClassify) Update(cols []string) (err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. _, err = o.Update(t, cols...)
  41. return
  42. }
  43. func BatchAddClarksonsClassify(items []*BaseFromClarksonsClassify) (err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. _, err = o.InsertMulti(len(items), items)
  46. return
  47. }
  48. // 获取所有分类
  49. func GetClarksonsClassifyAll() (items []*BaseFromClarksonsClassifyItem, err error) {
  50. o := orm.NewOrmUsingDB("data")
  51. sql := ` SELECT * FROM base_from_clarksons_classify ORDER BY sort ASC, base_from_clarksons_classify_id ASC`
  52. _, err = o.Raw(sql).QueryRows(&items)
  53. return
  54. }
  55. // GetChildClarksonsClassifyListById 获取子分类列表
  56. func GetChildClarksonsClassifyListById(classifyId int) (items []*BaseFromClarksonsClassifyItem, err error) {
  57. o := orm.NewOrmUsingDB("data")
  58. sql := ` SELECT * FROM base_from_clarksons_classify WHERE parent_id=? `
  59. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  60. return
  61. }
  62. // GetChildClarksonsClassifyIdsById 获取子分类的id集合
  63. func GetChildClarksonsClassifyIdsById(classifyId int) (items []int, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. sql := ` SELECT base_from_clarksons_classify_id FROM base_from_clarksons_classify WHERE parent_id=? `
  66. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  67. return
  68. }
  69. // GetChildClarksonsClassifyMaxSortById 获取子分类最大排序
  70. func GetChildClarksonsClassifyMaxSortById(classifyId int) (sort int, err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. sql := ` SELECT MAX(sort) AS sort FROM base_from_clarksons_classify WHERE parent_id=? `
  73. err = o.Raw(sql, classifyId).QueryRow(&sort)
  74. return
  75. }
  76. // GetClarksonsClassifyCountById 获取分类数量
  77. func GetClarksonsClassifyCountById(classifyId int) (count int, err error) {
  78. o := orm.NewOrmUsingDB("data")
  79. sql := ` SELECT COUNT(*) AS count FROM base_from_clarksons_classify WHERE base_from_clarksons_classify_id=? `
  80. err = o.Raw(sql, classifyId).QueryRow(&count)
  81. return
  82. }
  83. // GetClarksonsClassifyById 通过分类id获取分类
  84. func GetClarksonsClassifyById(classifyId int) (item *BaseFromClarksonsClassify, err error) {
  85. o := orm.NewOrmUsingDB("data")
  86. sql := ` SELECT * FROM base_from_clarksons_classify WHERE base_from_clarksons_classify_id=? `
  87. err = o.Raw(sql, classifyId).QueryRow(&item)
  88. return
  89. }
  90. // GetClarksonsChildClassifyById 通过分类id获取子分类
  91. func GetClarksonsChildClassifyIdsById(classifyId int) (items []int, err error) {
  92. o := orm.NewOrmUsingDB("data")
  93. sql := ` SELECT base_from_clarksons_classify_id FROM base_from_clarksons_classify WHERE parent_id=? `
  94. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  95. return
  96. }
  97. // GetClarksonsClassifyListByIds 通过分类id获取分类列表
  98. func GetClarksonsClassifyListByIds(classifyIds []int) (items []*BaseFromClarksonsClassify, err error) {
  99. if len(classifyIds) == 0 {
  100. return
  101. }
  102. o := orm.NewOrmUsingDB("data")
  103. sql := ` SELECT * FROM base_from_clarksons_classify WHERE base_from_clarksons_classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  104. _, err = o.Raw(sql, classifyIds).QueryRows(&items)
  105. return
  106. }
  107. // GetClarksonsClassifyCountByName 通过分类名称获取分类
  108. func GetClarksonsClassifyCountByName(classifyName string) (count int, err error) {
  109. o := orm.NewOrmUsingDB("data")
  110. sql := ` SELECT COUNT(*) AS count FROM base_from_clarksons_classify WHERE 1=1`
  111. sql += ` AND classify_name=? `
  112. err = o.Raw(sql, classifyName).QueryRow(&count)
  113. return
  114. }
  115. func GetBaseFromClarksonsClassifyEnCount(classifyNameEn string, parentId int) (count int, err error) {
  116. o := orm.NewOrmUsingDB("data")
  117. sql := `SELECT COUNT(1) AS count FROM base_from_clarksons_classify WHERE classify_name_en=? AND parent_id=? `
  118. err = o.Raw(sql, classifyNameEn, parentId).QueryRow(&count)
  119. return
  120. }
  121. func GetBaseFromClarksonsClassifyCount(classifyName string, parentId int) (count int, err error) {
  122. o := orm.NewOrmUsingDB("data")
  123. sql := `SELECT COUNT(1) AS count FROM base_from_clarksons_classify WHERE classify_name=? AND parent_id=? `
  124. err = o.Raw(sql, classifyName, parentId).QueryRow(&count)
  125. return
  126. }
  127. func DeleteClarksonsClassifyById(classifyId int) (err error) {
  128. o := orm.NewOrmUsingDB("data")
  129. sql := ` DELETE FROM base_from_clarksons_classify WHERE base_from_clarksons_classify_id=? `
  130. _, err = o.Raw(sql, classifyId).Exec()
  131. return
  132. }
  133. // BatchDeleteClarksonsClassifyById 批量删除分类
  134. func BatchDeleteClarksonsClassifyById(classifyId []int) (err error) {
  135. if len(classifyId) == 0 {
  136. return
  137. }
  138. o := orm.NewOrmUsingDB("data")
  139. to, err := o.Begin()
  140. if err != nil {
  141. return
  142. }
  143. defer func() {
  144. if err != nil {
  145. _ = to.Rollback()
  146. } else {
  147. _ = to.Commit()
  148. }
  149. }()
  150. sql := ` DELETE FROM base_from_clarksons_classify WHERE base_from_clarksons_classify_id IN (` + utils.GetOrmInReplace(len(classifyId)) + `) `
  151. _, err = o.Raw(sql, classifyId).Exec()
  152. return
  153. }
  154. // DeleteClarksonsClassifyByClassifyId 根据分类id删除对应的指标分类
  155. func DeleteClarksonsClassifyByClassifyId(classifyIdList []int) (err error) {
  156. o := orm.NewOrmUsingDB("data")
  157. num := len(classifyIdList)
  158. if num <= 0 {
  159. return
  160. }
  161. //删除分类
  162. sql := `DELETE FROM base_from_clarksons_classify WHERE base_from_clarksons_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  163. _, err = o.Raw(sql, classifyIdList).Exec()
  164. return
  165. }
  166. // GetClarksonsIndexClassifyMinSort 获取最小不等于0的排序
  167. func GetClarksonsIndexClassifyMinSort(parentId int) (sort int, err error) {
  168. o := orm.NewOrmUsingDB("data")
  169. sql := `SELECT MIN(sort) FROM base_from_clarksons_classify WHERE parent_id=? AND sort <> 0 `
  170. err = o.Raw(sql, parentId).QueryRow(&sort)
  171. return
  172. }
  173. // MoveUpClarksonsIndexClassifyBySort 往上移动
  174. func MoveUpClarksonsIndexClassifyBySort(parentId, nextSort, currentSort int) (err error) {
  175. o := orm.NewOrmUsingDB("data")
  176. sql := `update base_from_clarksons_classify set sort = sort + 1 where parent_id=? and sort >= ? and sort< ?`
  177. _, err = o.Raw(sql, parentId, nextSort, currentSort).Exec()
  178. return
  179. }
  180. // MoveDownClarksonsIndexClassifyBySort 往下移动
  181. func MoveDownClarksonsIndexClassifyBySort(parentId, prevSort, currentSort int) (err error) {
  182. o := orm.NewOrmUsingDB("data")
  183. sql := `update base_from_clarksons_classify set sort = sort - 1 where parent_id=? and sort <= ? and sort> ? `
  184. _, err = o.Raw(sql, parentId, prevSort, currentSort).Exec()
  185. return
  186. }