mysteel_chemical_classify.go 11 KB

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