chart_classify.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type ChartClassify struct {
  8. ChartClassifyId int `orm:"column(chart_classify_id);pk"`
  9. ChartClassifyName string `description:"分类名称"`
  10. ParentId int `description:"父级id"`
  11. HasData int `description:"是否含有指标数据"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. SysUserId int `description:"创建人id"`
  15. SysUserRealName string `description:"创建人姓名"`
  16. Level int `description:"层级"`
  17. UniqueCode string `description:"唯一编码"`
  18. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  19. Source int `description:"1:ETA图库;2:商品价格曲线"`
  20. }
  21. func AddChartClassify(item *ChartClassify) (lastId int64, err error) {
  22. o := orm.NewOrmUsingDB("data")
  23. lastId, err = o.Insert(item)
  24. return
  25. }
  26. type AddChartClassifyReq struct {
  27. ChartClassifyName string `description:"分类名称"`
  28. ParentId int `description:"父级id,第一级传0"`
  29. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  30. }
  31. func GetChartClassifyCount(chartClassifyName string, parentId, source int) (count int, err error) {
  32. o := orm.NewOrmUsingDB("data")
  33. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name=? `
  34. err = o.Raw(sql, parentId, source, chartClassifyName).QueryRow(&count)
  35. return
  36. }
  37. type EditChartClassifyReq struct {
  38. ChartClassifyName string `description:"分类名称"`
  39. ChartClassifyId int `description:"分类id"`
  40. }
  41. func GetChartClassifyById(classifyId int) (item *ChartClassify, err error) {
  42. o := orm.NewOrmUsingDB("data")
  43. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  44. err = o.Raw(sql, classifyId).QueryRow(&item)
  45. return
  46. }
  47. func GetChartClassifyCountById(classifyId int) (count int, err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := `SELECT count(1) AS count FROM chart_classify WHERE chart_classify_id=? `
  50. err = o.Raw(sql, classifyId).QueryRow(&count)
  51. return
  52. }
  53. func EditChartClassify(classifyId, source int, chartClassifyName string) (err error) {
  54. o := orm.NewOrmUsingDB("data")
  55. sql := `UPDATE chart_classify SET chart_classify_name=?,modify_time=NOW() WHERE chart_classify_id=? AND source = ? `
  56. _, err = o.Raw(sql, chartClassifyName, classifyId, source).Exec()
  57. return
  58. }
  59. type DeleteChartClassifyReq struct {
  60. ChartClassifyId int `description:"分类id"`
  61. ChartInfoId int `description:"指标id"`
  62. }
  63. func GetChartInfoCountByClassifyId(classifyId int) (count int, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. sql := ` SELECT COUNT(1) AS count FROM chart_info AS a
  66. WHERE a.chart_classify_id IN(
  67. SELECT t.chart_classify_id FROM
  68. (
  69. SELECT rd.*
  70. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  71. (SELECT @pid := ?) pd
  72. WHERE FIND_IN_SET(parent_id, @pid) > 0
  73. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  74. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  75. )AS t
  76. ) `
  77. err = o.Raw(sql, classifyId).QueryRow(&count)
  78. return
  79. }
  80. func DeleteChartClassify(classifyId int) (err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := ` DELETE FROM chart_classify
  83. WHERE chart_classify_id IN(
  84. SELECT t.chart_classify_id FROM
  85. (
  86. SELECT rd.*
  87. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  88. (SELECT @pid := ?) pd
  89. WHERE FIND_IN_SET(parent_id, @pid) > 0
  90. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  91. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  92. )AS t
  93. ) `
  94. _, err = o.Raw(sql, classifyId).Exec()
  95. return
  96. }
  97. // GetChartClassifyByParentId
  98. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  99. func GetChartClassifyByParentId(parentId, source int) (items []*ChartClassifyItems, err error) {
  100. o := orm.NewOrmUsingDB("data")
  101. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = ? order by sort asc,chart_classify_id asc`
  102. _, err = o.Raw(sql, parentId, source).QueryRows(&items)
  103. return
  104. }
  105. // GetChartClassifyAll
  106. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  107. func GetChartClassifyAll(source int) (items []*ChartClassifyItems, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = ? order by sort asc,chart_classify_id asc`
  110. _, err = o.Raw(sql, source).QueryRows(&items)
  111. return
  112. }
  113. type ChartClassifyItems struct {
  114. ChartClassifyId int `description:"分类id"`
  115. ChartInfoId int `description:"指标id"`
  116. ChartClassifyName string
  117. ChartClassifyNameEn string
  118. ParentId int
  119. Level int `description:"层级"`
  120. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  121. UniqueCode string `description:"唯一编码"`
  122. Source int `description:"来源id"`
  123. SourceName string `description:"来源名称"`
  124. SysUserId int `description:"创建人id"`
  125. SysUserRealName string `description:"创建人姓名"`
  126. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  127. StartDate string `description:"自定义开始日期"`
  128. EndDate string `description:"自定义结束日期"`
  129. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  130. Calendar string `description:"公历/农历"`
  131. SeasonStartDate string `description:"季节性图开始日期"`
  132. SeasonEndDate string `description:"季节性图开始日期"`
  133. Children []*ChartClassifyItems
  134. Button ChartClassifyItemsButton `description:"按钮权限"`
  135. }
  136. // ChartClassifyItemsButton 操作按钮
  137. type ChartClassifyItemsButton struct {
  138. AddButton bool `description:"是否可添加"`
  139. OpButton bool `description:"是否可编辑"`
  140. DeleteButton bool `description:"是否可删除"`
  141. MoveButton bool `description:"是否可移动"`
  142. }
  143. type ChartClassifyListResp struct {
  144. AllNodes []*ChartClassifyItems
  145. Language string `description:"指标的展示语言,CN:中文,EN:英文"`
  146. CanOpClassify bool `description:"是否允许操作分类"`
  147. }
  148. type ChartClassifyDeleteCheckResp struct {
  149. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  150. TipsMsg string `description:"提示信息"`
  151. }
  152. type ChartClassifyDeleteCheckReq struct {
  153. ChartClassifyId int `description:"分类id"`
  154. ChartInfoId int `description:"指标id"`
  155. }
  156. func GetChartClassifyCountByClassifyId(chartClassifyId int) (count int, err error) {
  157. o := orm.NewOrmUsingDB("data")
  158. sql := ` SELECT COUNT(1) AS count FROM (
  159. SELECT rd.*
  160. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  161. (SELECT @pid := ?) pd
  162. WHERE FIND_IN_SET(parent_id, @pid) > 0
  163. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  164. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  165. )AS t
  166. WHERE t.chart_classify_id<>? `
  167. err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&count)
  168. return
  169. }
  170. func GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
  171. o := orm.NewOrmUsingDB("data")
  172. sql := ` SELECT * FROM chart_classify WHERE 1=1 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. err = o.Raw(sql, pars).QueryRow(&item)
  177. return
  178. }
  179. // MoveChartClassifyReq 移动图表分类请求参数
  180. type MoveChartClassifyReq struct {
  181. ClassifyId int `description:"分类id"`
  182. ParentClassifyId int `description:"父级分类id"`
  183. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  184. NextClassifyId int `description:"下一个兄弟节点分类id"`
  185. }
  186. // GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  187. func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
  188. o := orm.NewOrmUsingDB("data")
  189. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
  190. err = o.Raw(sql, parentId).QueryRow(&item)
  191. return
  192. }
  193. // UpdateChartClassifySortByParentId 根据图表父类id更新排序
  194. func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  195. o := orm.NewOrmUsingDB("data")
  196. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  197. if classifyId > 0 {
  198. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  199. }
  200. _, err = o.Raw(sql, parentId, nowSort).Exec()
  201. return
  202. }
  203. // Update 更新图表分类基础信息
  204. func (chartClassify *ChartClassify) Update(cols []string) (err error) {
  205. o := orm.NewOrmUsingDB("data")
  206. _, err = o.Update(chartClassify, cols...)
  207. return
  208. }
  209. // GetChartClassifyMaxSort 获取图表分类下最大的排序数
  210. func GetChartClassifyMaxSort(parentId, source int) (sort int, err error) {
  211. o := orm.NewOrmUsingDB("data")
  212. sql := `SELECT Max(sort) AS sort FROM chart_classify WHERE parent_id=? AND source = ? `
  213. err = o.Raw(sql, parentId, source).QueryRow(&sort)
  214. return
  215. }
  216. type ChartClassifyView struct {
  217. ChartClassifyId int `orm:"column(chart_classify_id);pk"`
  218. ChartClassifyName string `description:"分类名称"`
  219. ParentId int `description:"父级id"`
  220. }
  221. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  222. o := orm.NewOrmUsingDB("data")
  223. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  224. err = o.Raw(sql, classifyId).QueryRow(&item)
  225. return
  226. }
  227. func GetChartClassifyByParentIdFromETA(parentId int) (items []*ChartClassifyItems, err error) {
  228. o := orm.NewOrmUsingDB("data")
  229. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = 1 order by sort asc,chart_classify_id asc`
  230. _, err = o.Raw(sql, parentId).QueryRows(&items)
  231. return
  232. }
  233. func GetChartClassifyAllFromETA() (items []*ChartClassifyItems, err error) {
  234. o := orm.NewOrmUsingDB("data")
  235. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = 1 order by sort asc,chart_classify_id asc`
  236. _, err = o.Raw(sql).QueryRows(&items)
  237. return
  238. }
  239. func GetChartClassifyTwo(source int) (items []*ChartClassifyItems, err error) {
  240. o := orm.NewOrmUsingDB("data")
  241. sql := ` SELECT * FROM chart_classify WHERE level=3 AND source = ? order by sort asc,chart_classify_id asc`
  242. _, err = o.Raw(sql, source).QueryRows(&items)
  243. return
  244. }
  245. func GetChartClassifyByLevel(level, source int) (items []*ChartClassifyItems, err error) {
  246. o := orm.NewOrmUsingDB("data")
  247. sql := ` SELECT * FROM chart_classify WHERE level=? AND source = ? order by sort asc,chart_classify_id asc`
  248. _, err = o.Raw(sql, level, source).QueryRows(&items)
  249. return
  250. }
  251. func EditChartClassifySysUser(classifyId, sysUserId int, chartClassifyName string) (err error) {
  252. o := orm.NewOrmUsingDB("data")
  253. sql := `UPDATE chart_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  254. _, err = o.Raw(sql, sysUserId, chartClassifyName, classifyId).Exec()
  255. return
  256. }
  257. func GetAllChartClassifyItemsBySource(source int) (items []*ChartClassifyItems, err error) {
  258. o := orm.NewOrmUsingDB("data")
  259. sql := ` SELECT * FROM chart_classify WHERE source = ? order by sort ASC,chart_classify_id ASC`
  260. _, err = o.Raw(sql, source).QueryRows(&items)
  261. return
  262. }