mysteel_chemical_classify.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package data_manage
  2. import (
  3. "eta/eta_mobile/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. IndexCode string `description:"指标编码"`
  54. ClassifyName string `description:"分类名称"`
  55. ParentId int `description:"父级id"`
  56. SysUserId int `description:"创建人id"`
  57. SysUserRealName string `description:"创建人姓名"`
  58. Level int `description:"层级"`
  59. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  60. UniqueCode string `description:"唯一编码"`
  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. // GetBaseFromMysteelChemicalClassifyByIds 根据id获取当下的分类列表数据
  80. func GetBaseFromMysteelChemicalClassifyByIds(classifyIds []int) (items []*BaseFromMysteelChemicalClassifyItems, err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := ` SELECT * FROM base_from_mysteel_chemical_classify WHERE parent_id > 0 and base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) order by sort asc,base_from_mysteel_chemical_classify_id asc`
  83. _, err = o.Raw(sql, classifyIds).QueryRows(&items)
  84. return
  85. }
  86. // GetAllBaseFromMysteelChemicalClassify 获取所有的分类列表数据
  87. func GetAllBaseFromMysteelChemicalClassify() (items []*BaseFromMysteelChemicalClassifyItems, err error) {
  88. o := orm.NewOrmUsingDB("data")
  89. sql := ` SELECT * FROM base_from_mysteel_chemical_classify WHERE parent_id <> 0 order by sort asc,base_from_mysteel_chemical_classify_id asc`
  90. _, err = o.Raw(sql).QueryRows(&items)
  91. return
  92. }
  93. type DeleteBaseFromMysteelChemicalClassifyReq struct {
  94. ClassifyId int `description:"分类id"`
  95. EdbInfoId int `description:"指标id"`
  96. }
  97. type BaseFromMysteelChemicalClassifyListResp struct {
  98. AllNodes []*BaseFromMysteelChemicalClassifyItems
  99. CanOpClassify bool `description:"是否允许操作分类"`
  100. }
  101. type BaseFromMysteelChemicalClassifySimplify struct {
  102. ClassifyId int `description:"分类id"`
  103. ClassifyName string `description:"分类名称"`
  104. ParentId int
  105. }
  106. // GetFirstBaseFromMysteelChemicalClassify 获取当前分类下,且排序数相同 的排序第一条的数据
  107. func GetFirstBaseFromMysteelChemicalClassify() (item *BaseFromMysteelChemicalClassify, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := ` SELECT * FROM base_from_mysteel_chemical_classify order by sort asc,base_from_mysteel_chemical_classify_id asc limit 1`
  110. err = o.Raw(sql).QueryRow(&item)
  111. return
  112. }
  113. // UpdateBaseFromMysteelChemicalClassifySortByClassifyId 根据分类id更新排序
  114. func UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  115. o := orm.NewOrmUsingDB("data")
  116. sql := ` update base_from_mysteel_chemical_classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
  117. if classifyId > 0 {
  118. sql += ` or ( base_from_mysteel_chemical_classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  119. }
  120. _, err = o.Raw(sql, parentId, nowSort).Exec()
  121. return
  122. }
  123. // Update 更新分类基础信息
  124. func (BaseFromMysteelChemicalClassify *BaseFromMysteelChemicalClassify) Update(cols []string) (err error) {
  125. o := orm.NewOrmUsingDB("data")
  126. _, err = o.Update(BaseFromMysteelChemicalClassify, cols...)
  127. return
  128. }
  129. // GetBaseFromMysteelChemicalClassifyMaxSort 获取分类下最大的排序数
  130. func GetBaseFromMysteelChemicalClassifyMaxSort(parentId int) (sort int, err error) {
  131. o := orm.NewOrmUsingDB("data")
  132. sql := `SELECT Max(sort) AS sort FROM base_from_mysteel_chemical_classify WHERE parent_id=? `
  133. err = o.Raw(sql, parentId).QueryRow(&sort)
  134. return
  135. }
  136. // DeleteMysteelChemicalByClassifyId 根据分类id删除对应的指标分类、指标、指标数据
  137. func DeleteMysteelChemicalByClassifyId(classifyIdList []int, mysteelChemicalIndexIdList []int) (err error) {
  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. num := len(classifyIdList)
  151. if num <= 0 {
  152. return
  153. }
  154. //删除分类
  155. sql := `DELETE FROM base_from_mysteel_chemical_classify WHERE base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  156. _, err = to.Raw(sql, classifyIdList).Exec()
  157. if err != nil {
  158. return
  159. }
  160. //删除指标
  161. sql = `DELETE FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  162. _, err = to.Raw(sql, classifyIdList).Exec()
  163. if err != nil {
  164. return
  165. }
  166. //删除指标数据
  167. indexNum := len(mysteelChemicalIndexIdList)
  168. if indexNum > 0 {
  169. sql = `DELETE FROM base_from_mysteel_chemical_data WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(indexNum) + `) `
  170. _, err = to.Raw(sql, mysteelChemicalIndexIdList).Exec()
  171. if err != nil {
  172. return
  173. }
  174. }
  175. return
  176. }
  177. // DeleteMysteelChemical 根据指标id删除对应的指标指标、指标数据
  178. func DeleteMysteelChemical(mysteelChemicalIndexId int) (err error) {
  179. o := orm.NewOrmUsingDB("data")
  180. to, err := o.Begin()
  181. if err != nil {
  182. return
  183. }
  184. defer func() {
  185. if err != nil {
  186. _ = to.Rollback()
  187. } else {
  188. _ = to.Commit()
  189. }
  190. }()
  191. //删除指标
  192. sql := `DELETE FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id = ? `
  193. _, err = to.Raw(sql, mysteelChemicalIndexId).Exec()
  194. if err != nil {
  195. return
  196. }
  197. //删除指标数据
  198. sql = `DELETE FROM base_from_mysteel_chemical_data WHERE base_from_mysteel_chemical_index_id = ? `
  199. _, err = to.Raw(sql, mysteelChemicalIndexId).Exec()
  200. if err != nil {
  201. return
  202. }
  203. return
  204. }