material_classify.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package material
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. type MaterialClassify struct {
  9. ClassifyId int `orm:"column(classify_id);pk"`
  10. ClassifyName string `description:"分类名称"`
  11. ClassifyNameEn string `description:"英文分类名称"`
  12. ParentId int `description:"父级id"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. SysUserId int `description:"创建人id"`
  16. SysUserRealName string `description:"创建人姓名"`
  17. Level int `description:"层级"`
  18. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  19. LevelPath string `description:"层级路径"`
  20. }
  21. func AddMaterialClassify(item *MaterialClassify) (lastId int64, err error) {
  22. o := orm.NewOrmUsingDB("rddp")
  23. lastId, err = o.Insert(item)
  24. return
  25. }
  26. // GetMaterialClassifyByParentId
  27. func GetMaterialClassifyByParentId(parentId int) (items []*MaterialClassifyItems, err error) {
  28. o := orm.NewOrmUsingDB("rddp")
  29. sql := ` SELECT * FROM material_classify WHERE parent_id=? order by sort asc,classify_id asc`
  30. _, err = o.Raw(sql, parentId).QueryRows(&items)
  31. return
  32. }
  33. // GetMaterialClassifyAll
  34. func GetMaterialClassifyAll() (items []*MaterialClassifyItems, err error) {
  35. o := orm.NewOrmUsingDB("rddp")
  36. sql := ` SELECT * FROM material_classify WHERE parent_id<>0 order by sort asc,classify_id asc`
  37. _, err = o.Raw(sql).QueryRows(&items)
  38. return
  39. }
  40. type MaterialClassifyItems struct {
  41. ClassifyId int `orm:"column(classify_id);pk"`
  42. ClassifyName string `description:"分类名称"`
  43. ClassifyNameEn string `description:"英文分类名称"`
  44. ParentId int `description:"父级id"`
  45. CreateTime time.Time `description:"创建时间"`
  46. ModifyTime time.Time `description:"修改时间"`
  47. SysUserId int `description:"创建人id"`
  48. SysUserName string `description:"创建人姓名"`
  49. Level int `description:"层级"`
  50. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  51. Children []*MaterialClassifyItems
  52. }
  53. type MaterialClassifyListResp struct {
  54. AllNodes []*MaterialClassifyItems
  55. }
  56. type AddMaterialClassifyReq struct {
  57. ClassifyName string `description:"分类名称"`
  58. ParentId int `description:"父级id,第一级传0"`
  59. //Level int `description:"层级,第一级传0,其余传上一级的层级"`
  60. }
  61. func GetMaterialClassifyNameCount(classifyName string, parentId int) (count int, err error) {
  62. o := orm.NewOrmUsingDB("rddp")
  63. sql := `SELECT COUNT(1) AS count FROM material_classify WHERE parent_id=? AND classify_name=? `
  64. err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
  65. return
  66. }
  67. func GetMaterialClassifyNameEnCount(classifyName string, parentId int) (count int, err error) {
  68. o := orm.NewOrmUsingDB("rddp")
  69. sql := `SELECT COUNT(1) AS count FROM material_classify WHERE parent_id=? AND classify_name_en=? `
  70. err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
  71. return
  72. }
  73. func GetMaterialClassifyNameNotSelfCount(id int, classifyName string, parentId int) (count int, err error) {
  74. o := orm.NewOrmUsingDB("rddp")
  75. sql := `SELECT COUNT(1) AS count FROM material_classify WHERE classify_id !=? AND parent_id=? AND classify_name=? `
  76. err = o.Raw(sql, id, parentId, classifyName).QueryRow(&count)
  77. return
  78. }
  79. func GetMaterialClassifyNameEnNotSelfCount(id int, classifyName string, parentId int) (count int, err error) {
  80. o := orm.NewOrmUsingDB("rddp")
  81. sql := `SELECT COUNT(1) AS count FROM material_classify WHERE classify_id !=? AND parent_id=? AND classify_name_en=? `
  82. err = o.Raw(sql, id, parentId, classifyName).QueryRow(&count)
  83. return
  84. }
  85. // GetMaterialClassifyMaxSort 获取沙盘分类下最大的排序数
  86. func GetMaterialClassifyMaxSort(parentId int) (sort int, err error) {
  87. o := orm.NewOrmUsingDB("rddp")
  88. sql := `SELECT MAX(sort) AS sort FROM material_classify WHERE parent_id=? `
  89. err = o.Raw(sql, parentId).QueryRow(&sort)
  90. return
  91. }
  92. type EditMaterialClassifyReq struct {
  93. ClassifyName string `description:"分类名称"`
  94. ClassifyId int `description:"分类id"`
  95. }
  96. func GetMaterialClassifyById(classifyId int) (item *MaterialClassify, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := `SELECT * FROM material_classify WHERE classify_id=? `
  99. err = o.Raw(sql, classifyId).QueryRow(&item)
  100. return
  101. }
  102. type MaterialClassifyDeleteCheckReq struct {
  103. ClassifyId int `description:"分类id"`
  104. }
  105. type MaterialClassifyDeleteCheckResp struct {
  106. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  107. TipsMsg string `description:"提示信息"`
  108. }
  109. type DeleteMaterialClassifyReq struct {
  110. ClassifyId int `description:"分类id"`
  111. // MaterialId int `description:"素材id"`
  112. }
  113. func DeleteMaterialClassify(classifyIds []int) (err error) {
  114. o := orm.NewOrmUsingDB("rddp")
  115. sql := ` DELETE FROM material_classify WHERE classify_id IN(` + utils.GetOrmInReplace(len(classifyIds)) + `) `
  116. _, err = o.Raw(sql, classifyIds).Exec()
  117. return
  118. }
  119. // MoveMaterialClassifyReq 移动沙盘分类请求参数
  120. type MoveMaterialClassifyReq struct {
  121. ClassifyId int `description:"分类id"`
  122. //MaterialId int `description:"沙盘ID"`
  123. ParentClassifyId int `description:"目标父级分类id"`
  124. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  125. NextClassifyId int `description:"下一个兄弟节点分类id"`
  126. //PrevType int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
  127. //NextType int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
  128. }
  129. // UpdateMaterialClassifySortByParentId 根据沙盘父类id更新排序
  130. func UpdateMaterialClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  131. o := orm.NewOrmUsingDB("rddp")
  132. sql := ` update material_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  133. if classifyId > 0 {
  134. sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  135. }
  136. _, err = o.Raw(sql, parentId, nowSort).Exec()
  137. return
  138. }
  139. // GetFirstMaterialClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
  140. func GetFirstMaterialClassifyByParentId(parentId int) (item *MaterialClassify, err error) {
  141. o := orm.NewOrmUsingDB("rddp")
  142. sql := ` SELECT * FROM material_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
  143. err = o.Raw(sql, parentId).QueryRow(&item)
  144. return
  145. }
  146. // Update 更新沙盘分类基础信息
  147. func (m *MaterialClassify) Update(cols []string) (err error) {
  148. o := orm.NewOrmUsingDB("rddp")
  149. _, err = o.Update(m, cols...)
  150. return
  151. }
  152. // GetMaterialClassifyAndInfoByParentId
  153. func GetMaterialClassifyAndInfoByParentId(parentId int) (items []*MaterialClassifyItems, err error) {
  154. o := orm.NewOrmUsingDB("rddp")
  155. sql := ` SELECT *
  156. FROM
  157. material_classify
  158. WHERE
  159. parent_id = ?
  160. ORDER BY
  161. sort ASC,
  162. classify_id ASC`
  163. _, err = o.Raw(sql, parentId).QueryRows(&items)
  164. return
  165. }
  166. type SandboxLinkCheckReq struct {
  167. EdbInfoIdList []int `description:"指标id列表"`
  168. ChartInfoIdList []int `description:"图库id列表"`
  169. ReportIdList []int `description:"报告id列表"`
  170. }
  171. type SandboxLinkCheckItem struct {
  172. Id int `description:"id"`
  173. Name string `description:"名称"`
  174. UniqueCode string `description:"唯一编码"`
  175. ClassifyId int `description:"分类id"`
  176. }
  177. type SandboxLinkCheckResp struct {
  178. EdbInfoIdList []*SandboxLinkCheckItem `description:"指标id列表"`
  179. ChartInfoIdList []*SandboxLinkCheckItem `description:"图库id列表"`
  180. ReportIdList []*SandboxLinkCheckItem `description:"报告id列表"`
  181. }
  182. func GetMaterialClassifyByLevelPath(levelPath string) (items []*MaterialClassify, err error) {
  183. o := orm.NewOrmUsingDB("rddp")
  184. sql := `SELECT * FROM material_classify where level_path like "` + levelPath + `%"`
  185. _, err = o.Raw(sql).QueryRows(&items)
  186. return
  187. }