chart_classify.go 13 KB

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