chart_classify.go 16 KB

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