chart_classify.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/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. }
  20. func AddChartClassify(item *ChartClassify) (lastId int64, err error) {
  21. o := orm.NewOrm()
  22. o.Using("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 int) (count int, err error) {
  32. o := orm.NewOrm()
  33. o.Using("data")
  34. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND chart_classify_name=? `
  35. err = o.Raw(sql, parentId, chartClassifyName).QueryRow(&count)
  36. return
  37. }
  38. type EditChartClassifyReq struct {
  39. ChartClassifyName string `description:"分类名称"`
  40. ChartClassifyId int `description:"分类名称"`
  41. }
  42. func GetChartClassifyById(classifyId int) (item *ChartClassify, err error) {
  43. o := orm.NewOrm()
  44. o.Using("data")
  45. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  46. err = o.Raw(sql, classifyId).QueryRow(&item)
  47. return
  48. }
  49. func GetChartClassifyCountById(classifyId int) (count int, err error) {
  50. o := orm.NewOrm()
  51. o.Using("data")
  52. sql := `SELECT count(1) AS count FROM chart_classify WHERE chart_classify_id=? `
  53. err = o.Raw(sql, classifyId).QueryRow(&count)
  54. return
  55. }
  56. func EditChartClassify(classifyId int, chartClassifyName string) (err error) {
  57. o := orm.NewOrm()
  58. o.Using("data")
  59. sql := `UPDATE chart_classify SET chart_classify_name=?,modify_time=NOW() WHERE chart_classify_id=? `
  60. _, err = o.Raw(sql, chartClassifyName, classifyId).Exec()
  61. return
  62. }
  63. type DeleteChartClassifyReq struct {
  64. ChartClassifyId int `description:"分类id"`
  65. ChartInfoId int `description:"指标id"`
  66. }
  67. func GetChartInfoCountByClassifyId(classifyId int) (count int, err error) {
  68. o := orm.NewOrm()
  69. o.Using("data")
  70. sql := ` SELECT COUNT(1) AS count FROM chart_info AS a
  71. WHERE a.chart_classify_id IN(
  72. SELECT t.chart_classify_id FROM
  73. (
  74. SELECT rd.*
  75. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  76. (SELECT @pid := ?) pd
  77. WHERE FIND_IN_SET(parent_id, @pid) > 0
  78. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  79. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  80. )AS t
  81. ) `
  82. err = o.Raw(sql, classifyId).QueryRow(&count)
  83. return
  84. }
  85. func DeleteChartClassify(classifyId int) (err error) {
  86. o := orm.NewOrm()
  87. o.Using("data")
  88. sql := ` DELETE FROM chart_classify
  89. WHERE chart_classify_id IN(
  90. SELECT t.chart_classify_id FROM
  91. (
  92. SELECT rd.*
  93. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  94. (SELECT @pid := ?) pd
  95. WHERE FIND_IN_SET(parent_id, @pid) > 0
  96. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  97. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  98. )AS t
  99. ) `
  100. _, err = o.Raw(sql, classifyId).Exec()
  101. return
  102. }
  103. func GetChartClassifyByParentId(parentId int) (items []*ChartClassifyItems, err error) {
  104. o := orm.NewOrm()
  105. o.Using("data")
  106. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc`
  107. _, err = o.Raw(sql, parentId).QueryRows(&items)
  108. return
  109. }
  110. func GetChartClassifyAll() (items []*ChartClassifyItems, err error) {
  111. o := orm.NewOrm()
  112. o.Using("data")
  113. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 order by sort asc,chart_classify_id asc`
  114. _, err = o.Raw(sql).QueryRows(&items)
  115. return
  116. }
  117. type ChartClassifyItems struct {
  118. ChartClassifyId int `description:"分类id"`
  119. ChartInfoId int `description:"指标id"`
  120. ChartClassifyName string
  121. ParentId int
  122. Level int `description:"层级"`
  123. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  124. UniqueCode string `description:"唯一编码"`
  125. Source int `description:"来源id"`
  126. SourceName string `description:"来源名称"`
  127. SysUserId int `description:"创建人id"`
  128. SysUserRealName string `description:"创建人姓名"`
  129. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  130. StartDate string `description:"自定义开始日期"`
  131. EndDate string `description:"自定义结束日期"`
  132. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  133. Calendar string `description:"公历/农历"`
  134. SeasonStartDate string `description:"季节性图开始日期"`
  135. SeasonEndDate string `description:"季节性图开始日期"`
  136. Children []*ChartClassifyItems
  137. }
  138. type ChartClassifyListResp struct {
  139. AllNodes []*ChartClassifyItems
  140. }
  141. type ChartClassifyDeleteCheckResp struct {
  142. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  143. TipsMsg string `description:"提示信息"`
  144. }
  145. type ChartClassifyDeleteCheckReq struct {
  146. ChartClassifyId int `description:"分类id"`
  147. ChartInfoId int `description:"指标id"`
  148. }
  149. func GetChartClassifyCountByClassifyId(chartClassifyId int) (count int, err error) {
  150. o := orm.NewOrm()
  151. o.Using("data")
  152. sql := ` SELECT COUNT(1) AS count FROM (
  153. SELECT rd.*
  154. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  155. (SELECT @pid := ?) pd
  156. WHERE FIND_IN_SET(parent_id, @pid) > 0
  157. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  158. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  159. )AS t
  160. WHERE t.chart_classify_id<>? `
  161. err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&count)
  162. return
  163. }
  164. func GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
  165. o := orm.NewOrm()
  166. o.Using("data")
  167. sql := ` SELECT * FROM chart_classify WHERE 1=1 `
  168. if condition != "" {
  169. sql += condition
  170. }
  171. err = o.Raw(sql, pars).QueryRow(&item)
  172. return
  173. }
  174. // MoveChartClassifyReq 移动图表分类请求参数
  175. type MoveChartClassifyReq struct {
  176. ClassifyId int `description:"分类id"`
  177. ParentClassifyId int `description:"父级分类id"`
  178. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  179. NextClassifyId int `description:"下一个兄弟节点分类id"`
  180. }
  181. // GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  182. func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
  183. o := orm.NewOrm()
  184. o.Using("data")
  185. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
  186. err = o.Raw(sql, parentId).QueryRow(&item)
  187. return
  188. }
  189. // UpdateChartClassifySortByParentId 根据图表父类id更新排序
  190. func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  191. o := orm.NewOrm()
  192. o.Using("data")
  193. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  194. if classifyId > 0 {
  195. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  196. }
  197. _, err = o.Raw(sql, parentId, nowSort).Exec()
  198. return
  199. }
  200. // Update 更新图表分类基础信息
  201. func (chartClassify *ChartClassify) Update(cols []string) (err error) {
  202. o := orm.NewOrm()
  203. o.Using("data")
  204. _, err = o.Update(chartClassify, cols...)
  205. return
  206. }
  207. // GetChartClassifyMaxSort 获取图表分类下最大的排序数
  208. func GetChartClassifyMaxSort(parentId int) (sort int, err error) {
  209. o := orm.NewOrm()
  210. o.Using("data")
  211. sql := `SELECT Max(sort) AS sort FROM chart_classify WHERE parent_id=? `
  212. err = o.Raw(sql, parentId).QueryRow(&sort)
  213. return
  214. }
  215. type ChartClassifyView struct {
  216. ChartClassifyId int `orm:"column(chart_classify_id);pk"`
  217. ChartClassifyName string `description:"分类名称"`
  218. ParentId int `description:"父级id"`
  219. }
  220. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  221. o := orm.NewOrm()
  222. o.Using("data")
  223. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  224. err = o.Raw(sql, classifyId).QueryRow(&item)
  225. return
  226. }