mysteel_chemical_classify.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // BaseFromMysteelChemicalClassify 钢联化工分类表
  9. type BaseFromMysteelChemicalClassify struct {
  10. BaseFromMysteelChemicalClassifyId int `orm:"column(base_from_mysteel_chemical_classify_id);pk"`
  11. ClassifyName string `description:"分类名称"`
  12. ParentId int `description:"父级id"`
  13. SysUserId int `description:"创建人id"`
  14. SysUserRealName string `description:"创建人姓名"`
  15. Level int `description:"层级"`
  16. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. CreateTime time.Time `description:"创建时间"`
  19. }
  20. // AddBaseFromMysteelChemicalClassify 添加钢联化工分类
  21. func AddBaseFromMysteelChemicalClassify(item *BaseFromMysteelChemicalClassify) (lastId int64, err error) {
  22. o := orm.NewOrmUsingDB("data")
  23. lastId, err = o.Insert(item)
  24. return
  25. }
  26. // GetBaseFromMysteelChemicalClassifyCount 获取分类名称的个数
  27. func GetBaseFromMysteelChemicalClassifyCount(classifyName string, parentId int) (count int, err error) {
  28. o := orm.NewOrmUsingDB("data")
  29. sql := `SELECT COUNT(1) AS count FROM base_from_mysteel_chemical_classify WHERE classify_name=? AND parent_id=? `
  30. err = o.Raw(sql, classifyName, parentId).QueryRow(&count)
  31. return
  32. }
  33. // GetBaseFromMysteelChemicalClassifyById 通过分类id的获取分类信息
  34. func GetBaseFromMysteelChemicalClassifyById(classifyId int) (item *BaseFromMysteelChemicalClassify, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := `SELECT * FROM base_from_mysteel_chemical_classify WHERE base_from_mysteel_chemical_classify_id=? `
  37. err = o.Raw(sql, classifyId).QueryRow(&item)
  38. return
  39. }
  40. // EditBaseFromMysteelChemicalClassify 修改钢联化工分类
  41. func EditBaseFromMysteelChemicalClassify(classifyId int, classifyName string) (err error) {
  42. o := orm.NewOrmUsingDB("data")
  43. sql := `UPDATE base_from_mysteel_chemical_classify SET classify_name=?,modify_time=NOW() WHERE base_from_mysteel_chemical_classify_id=? `
  44. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  45. return
  46. }
  47. type BaseFromMysteelChemicalIndexResp struct {
  48. List []*BaseFromMysteelChemicalClassifyItems
  49. }
  50. type BaseFromMysteelChemicalClassifyItems struct {
  51. BaseFromMysteelChemicalClassifyId int `orm:"column(base_from_mysteel_chemical_classify_id)"`
  52. BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id)"`
  53. ClassifyName string `description:"分类名称"`
  54. ParentId int `description:"父级id"`
  55. SysUserId int `description:"创建人id"`
  56. SysUserRealName string `description:"创建人姓名"`
  57. Level int `description:"层级"`
  58. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  59. UniqueCode string `description:"唯一编码"`
  60. IndexCode string `description:"指标编码" json:"-"`
  61. ModifyTime time.Time `description:"修改时间"`
  62. CreateTime time.Time `description:"创建时间"`
  63. Button BaseFromMysteelChemicalClassifyItemsButton `description:"操作权限"`
  64. Children []*BaseFromMysteelChemicalClassifyItems `description:"下级"`
  65. }
  66. type BaseFromMysteelChemicalClassifyItemsButton struct {
  67. AddButton bool `description:"是否可添加"`
  68. OpButton bool `description:"是否可编辑"`
  69. DeleteButton bool `description:"是否可删除"`
  70. MoveButton bool `description:"是否可移动"`
  71. }
  72. // GetBaseFromMysteelChemicalClassifyByParentId 根据上级id获取当下的分类列表数据
  73. func GetBaseFromMysteelChemicalClassifyByParentId(parentId int) (items []*BaseFromMysteelChemicalClassifyItems, err error) {
  74. o := orm.NewOrmUsingDB("data")
  75. sql := ` SELECT * FROM base_from_mysteel_chemical_classify WHERE parent_id=? order by sort asc,base_from_mysteel_chemical_classify_id asc`
  76. _, err = o.Raw(sql, parentId).QueryRows(&items)
  77. return
  78. }
  79. // GetAllBaseFromMysteelChemicalClassify 获取所有的分类列表数据
  80. func GetAllBaseFromMysteelChemicalClassify() (items []*BaseFromMysteelChemicalClassifyItems, err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := ` SELECT * FROM base_from_mysteel_chemical_classify WHERE parent_id <> 0 order by sort asc,base_from_mysteel_chemical_classify_id asc`
  83. _, err = o.Raw(sql).QueryRows(&items)
  84. return
  85. }
  86. type DeleteBaseFromMysteelChemicalClassifyReq struct {
  87. ClassifyId int `description:"分类id"`
  88. EdbInfoId int `description:"指标id"`
  89. }
  90. type BaseFromMysteelChemicalClassifyListResp struct {
  91. AllNodes []*BaseFromMysteelChemicalClassifyItems
  92. CanOpClassify bool `description:"是否允许操作分类"`
  93. }
  94. type BaseFromMysteelChemicalClassifySimplify struct {
  95. ClassifyId int `description:"分类id"`
  96. ClassifyName string `description:"分类名称"`
  97. ParentId int
  98. }
  99. // GetFirstBaseFromMysteelChemicalClassify 获取当前分类下,且排序数相同 的排序第一条的数据
  100. func GetFirstBaseFromMysteelChemicalClassify() (item *BaseFromMysteelChemicalClassify, err error) {
  101. o := orm.NewOrmUsingDB("data")
  102. sql := ` SELECT * FROM base_from_mysteel_chemical_classify order by sort asc,base_from_mysteel_chemical_classify_id asc limit 1`
  103. err = o.Raw(sql).QueryRow(&item)
  104. return
  105. }
  106. // UpdateBaseFromMysteelChemicalClassifySortByClassifyId 根据分类id更新排序
  107. func UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := ` update base_from_mysteel_chemical_classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
  110. if classifyId > 0 {
  111. sql += ` or ( base_from_mysteel_chemical_classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  112. }
  113. _, err = o.Raw(sql, parentId, nowSort).Exec()
  114. return
  115. }
  116. // Update 更新分类基础信息
  117. func (BaseFromMysteelChemicalClassify *BaseFromMysteelChemicalClassify) Update(cols []string) (err error) {
  118. o := orm.NewOrmUsingDB("data")
  119. _, err = o.Update(BaseFromMysteelChemicalClassify, cols...)
  120. return
  121. }
  122. // GetBaseFromMysteelChemicalClassifyMaxSort 获取分类下最大的排序数
  123. func GetBaseFromMysteelChemicalClassifyMaxSort(parentId int) (sort int, err error) {
  124. o := orm.NewOrmUsingDB("data")
  125. sql := `SELECT Max(sort) AS sort FROM base_from_mysteel_chemical_classify WHERE parent_id=? `
  126. err = o.Raw(sql, parentId).QueryRow(&sort)
  127. return
  128. }
  129. // DeleteMysteelChemicalByClassifyId 根据分类id删除对应的指标分类、指标、指标数据
  130. func DeleteMysteelChemicalByClassifyId(classifyIdList []int, mysteelChemicalIndexIdList []int) (err error) {
  131. o := orm.NewOrmUsingDB("data")
  132. to, err := o.Begin()
  133. if err != nil {
  134. return
  135. }
  136. defer func() {
  137. if err != nil {
  138. _ = to.Rollback()
  139. } else {
  140. _ = to.Commit()
  141. }
  142. }()
  143. num := len(classifyIdList)
  144. if num <= 0 {
  145. return
  146. }
  147. //删除分类
  148. sql := `DELETE FROM base_from_mysteel_chemical_classify WHERE base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  149. _, err = to.Raw(sql, classifyIdList).Exec()
  150. if err != nil {
  151. return
  152. }
  153. //删除指标
  154. sql = `DELETE FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  155. _, err = to.Raw(sql, classifyIdList).Exec()
  156. if err != nil {
  157. return
  158. }
  159. //删除指标数据
  160. indexNum := len(mysteelChemicalIndexIdList)
  161. if indexNum > 0 {
  162. sql = `DELETE FROM base_from_mysteel_chemical_data WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(indexNum) + `) `
  163. _, err = to.Raw(sql, mysteelChemicalIndexIdList).Exec()
  164. if err != nil {
  165. return
  166. }
  167. }
  168. return
  169. }
  170. // DeleteMysteelChemical 根据指标id删除对应的指标指标、指标数据
  171. func DeleteMysteelChemical(mysteelChemicalIndexId int) (err error) {
  172. o := orm.NewOrmUsingDB("data")
  173. to, err := o.Begin()
  174. if err != nil {
  175. return
  176. }
  177. defer func() {
  178. if err != nil {
  179. _ = to.Rollback()
  180. } else {
  181. _ = to.Commit()
  182. }
  183. }()
  184. //删除指标
  185. sql := `DELETE FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id = ? `
  186. _, err = to.Raw(sql, mysteelChemicalIndexId).Exec()
  187. if err != nil {
  188. return
  189. }
  190. //删除指标数据
  191. sql = `DELETE FROM base_from_mysteel_chemical_data WHERE base_from_mysteel_chemical_index_id = ? `
  192. _, err = to.Raw(sql, mysteelChemicalIndexId).Exec()
  193. if err != nil {
  194. return
  195. }
  196. return
  197. }