chart_classify.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. package data_manage
  2. import (
  3. "eta/eta_api/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. RootId int `description:"顶级ID"`
  24. }
  25. func AddChartClassify(item *ChartClassify) (lastId int64, err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. lastId, err = o.Insert(item)
  28. if err != nil {
  29. return
  30. }
  31. item.ChartClassifyId = int(lastId)
  32. return
  33. }
  34. type AddChartClassifyReq struct {
  35. ChartClassifyName string `description:"分类名称"`
  36. ParentId int `description:"父级id,第一级传0"`
  37. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  38. }
  39. // GetChartClassifyCount
  40. // @Description: 根据图表分类名称获取对应的数量
  41. // @author: Roc
  42. // @datetime 2024-04-16 18:13:40
  43. // @param chartClassifyName string
  44. // @param parentId int
  45. // @param source int
  46. // @return count int
  47. // @return err error
  48. func GetChartClassifyCount(chartClassifyName string, parentId, source int) (count int, err error) {
  49. o := orm.NewOrmUsingDB("data")
  50. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name=? `
  51. err = o.Raw(sql, parentId, source, chartClassifyName).QueryRow(&count)
  52. return
  53. }
  54. // GetChartClassifyEnCount
  55. // @Description: 根据图表分类英文名称获取对应的数量
  56. // @author: Roc
  57. // @datetime 2024-04-16 18:13:24
  58. // @param chartClassifyNameEn string
  59. // @param parentId int
  60. // @param source int
  61. // @return count int
  62. // @return err error
  63. func GetChartClassifyEnCount(chartClassifyNameEn string, parentId, source int) (count int, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name_en = ? `
  66. err = o.Raw(sql, parentId, source, chartClassifyNameEn).QueryRow(&count)
  67. return
  68. }
  69. type EditChartClassifyReq struct {
  70. ChartClassifyName string `description:"分类名称"`
  71. ChartClassifyId int `description:"分类id"`
  72. ParentId int `description:"父级分类id"`
  73. }
  74. func GetChartClassifyById(classifyId int) (item *ChartClassify, err error) {
  75. o := orm.NewOrmUsingDB("data")
  76. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  77. err = o.Raw(sql, classifyId).QueryRow(&item)
  78. return
  79. }
  80. func GetChartClassifyCountById(classifyId int) (count int, err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := `SELECT count(1) AS count FROM chart_classify WHERE chart_classify_id=? `
  83. err = o.Raw(sql, classifyId).QueryRow(&count)
  84. return
  85. }
  86. // EditChartClassify
  87. // @Description: 修改图表分类的名称
  88. // @author: Roc
  89. // @datetime 2024-04-16 18:12:51
  90. // @param classifyId int
  91. // @param source int
  92. // @param chartClassifyName string
  93. // @return err error
  94. func EditChartClassify(classifyId, source int, chartClassifyName string) (err error) {
  95. o := orm.NewOrmUsingDB("data")
  96. sql := `UPDATE chart_classify SET chart_classify_name=?,modify_time=NOW() WHERE chart_classify_id=? AND source = ? `
  97. _, err = o.Raw(sql, chartClassifyName, classifyId, source).Exec()
  98. return
  99. }
  100. // EditChartClassifyEn
  101. // @Description: 修改图表分类的英文名称
  102. // @author: Roc
  103. // @datetime 2024-04-16 18:12:40
  104. // @param classifyId int
  105. // @param source int
  106. // @param chartClassifyNameEn string
  107. // @return err error
  108. func EditChartClassifyEn(classifyId, source int, chartClassifyNameEn string) (err error) {
  109. o := orm.NewOrmUsingDB("data")
  110. sql := `UPDATE chart_classify SET chart_classify_name_en = ?,modify_time=NOW() WHERE chart_classify_id=? AND source = ? `
  111. _, err = o.Raw(sql, chartClassifyNameEn, classifyId, source).Exec()
  112. return
  113. }
  114. type DeleteChartClassifyReq struct {
  115. ChartClassifyId int `description:"分类id"`
  116. ChartInfoId int `description:"指标id"`
  117. }
  118. func GetChartInfoCountByClassifyId(classifyId int) (count int, err error) {
  119. o := orm.NewOrmUsingDB("data")
  120. sql := ` SELECT COUNT(1) AS count FROM chart_info AS a
  121. WHERE a.chart_classify_id IN(
  122. SELECT t.chart_classify_id FROM
  123. (
  124. SELECT rd.*
  125. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  126. (SELECT @pid := ?) pd
  127. WHERE FIND_IN_SET(parent_id, @pid) > 0
  128. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  129. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  130. )AS t
  131. ) `
  132. err = o.Raw(sql, classifyId).QueryRow(&count)
  133. return
  134. }
  135. func DeleteChartClassify(classifyId int) (err error) {
  136. o := orm.NewOrmUsingDB("data")
  137. sql := ` DELETE FROM chart_classify
  138. WHERE chart_classify_id IN(
  139. SELECT t.chart_classify_id FROM
  140. (
  141. SELECT rd.*
  142. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  143. (SELECT @pid := ?) pd
  144. WHERE FIND_IN_SET(parent_id, @pid) > 0
  145. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  146. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  147. )AS t
  148. ) `
  149. _, err = o.Raw(sql, classifyId).Exec()
  150. return
  151. }
  152. // GetChartClassifyByParentId
  153. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  154. func GetChartClassifyByParentId(parentId, source int) (items []*ChartClassifyItems, err error) {
  155. o := orm.NewOrmUsingDB("data")
  156. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = ? order by sort asc,chart_classify_id asc`
  157. _, err = o.Raw(sql, parentId, source).QueryRows(&items)
  158. return
  159. }
  160. // GetChartClassifyAll
  161. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  162. func GetChartClassifyAll(source int) (items []*ChartClassifyItems, err error) {
  163. o := orm.NewOrmUsingDB("data")
  164. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = ? order by sort asc,chart_classify_id asc`
  165. _, err = o.Raw(sql, source).QueryRows(&items)
  166. return
  167. }
  168. type ChartClassifyItems struct {
  169. ChartClassifyId int `description:"分类id"`
  170. ChartInfoId int `description:"指标id"`
  171. ChartClassifyName string
  172. ChartClassifyNameEn string
  173. ParentId int
  174. Level int `description:"层级"`
  175. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  176. UniqueCode string `description:"唯一编码"`
  177. Source int `description:"来源id"`
  178. SourceName string `description:"来源名称"`
  179. SysUserId int `description:"创建人id"`
  180. SysUserRealName string `description:"创建人姓名"`
  181. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  182. StartDate string `description:"自定义开始日期"`
  183. EndDate string `description:"自定义结束日期"`
  184. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  185. Calendar string `description:"公历/农历"`
  186. SeasonStartDate string `description:"季节性图开始日期"`
  187. SeasonEndDate string `description:"季节性图开始日期"`
  188. Children []*ChartClassifyItems
  189. Button ChartClassifyItemsButton `description:"按钮权限"`
  190. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  191. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  192. Disable bool `description:"勾选是否禁用"`
  193. }
  194. // ChartClassifyItemsButton 操作按钮
  195. type ChartClassifyItemsButton struct {
  196. AddButton bool `description:"是否可添加"`
  197. OpButton bool `description:"是否可编辑"`
  198. DeleteButton bool `description:"是否可删除"`
  199. MoveButton bool `description:"是否可移动"`
  200. }
  201. type ChartClassifyListResp struct {
  202. AllNodes []*ChartClassifyItems
  203. Language string `description:"指标的展示语言,CN:中文,EN:英文"`
  204. CanOpClassify bool `description:"是否允许操作分类"`
  205. }
  206. type ChartClassifyDeleteCheckResp struct {
  207. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  208. TipsMsg string `description:"提示信息"`
  209. }
  210. type ChartClassifyDeleteCheckReq struct {
  211. ChartClassifyId int `description:"分类id"`
  212. ChartInfoId int `description:"指标id"`
  213. }
  214. func GetChartClassifyCountByClassifyId(chartClassifyId int) (count int, err error) {
  215. o := orm.NewOrmUsingDB("data")
  216. sql := ` SELECT COUNT(1) AS count FROM (
  217. SELECT rd.*
  218. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  219. (SELECT @pid := ?) pd
  220. WHERE FIND_IN_SET(parent_id, @pid) > 0
  221. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  222. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  223. )AS t
  224. WHERE t.chart_classify_id<>? `
  225. err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&count)
  226. return
  227. }
  228. func GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
  229. o := orm.NewOrmUsingDB("data")
  230. sql := ` SELECT * FROM chart_classify WHERE 1=1 `
  231. if condition != "" {
  232. sql += condition
  233. }
  234. err = o.Raw(sql, pars).QueryRow(&item)
  235. return
  236. }
  237. // MoveChartClassifyReq 移动图表分类请求参数
  238. type MoveChartClassifyReq struct {
  239. ClassifyId int `description:"分类id"`
  240. ParentClassifyId int `description:"父级分类id"`
  241. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  242. NextClassifyId int `description:"下一个兄弟节点分类id"`
  243. ChartInfoId int `description:"图表ID, 如果图表ID有值,则移动对象为图表,否则认为移动对象分类"`
  244. PrevChartInfoId int `description:"上一个图表ID"`
  245. NextChartInfoId int `description:"下一个图表ID"`
  246. }
  247. // GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  248. func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
  249. o := orm.NewOrmUsingDB("data")
  250. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
  251. err = o.Raw(sql, parentId).QueryRow(&item)
  252. return
  253. }
  254. // GetFirstChartClassifyByParentIdAndSource 获取当前父级图表分类下的排序第一条的数据
  255. func GetFirstChartClassifyByParentIdAndSource(parentId, source int) (item *ChartClassify, err error) {
  256. o := orm.NewOrmUsingDB("data")
  257. sql := ` SELECT * FROM chart_classify WHERE parent_id=? and source = ? order by sort asc,chart_classify_id asc limit 1`
  258. err = o.Raw(sql, parentId, source).QueryRow(&item)
  259. return
  260. }
  261. // UpdateChartClassifySortByParentId 根据图表父类id更新排序
  262. func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  263. o := orm.NewOrmUsingDB("data")
  264. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  265. if classifyId > 0 {
  266. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  267. }
  268. _, err = o.Raw(sql, parentId, nowSort).Exec()
  269. return
  270. }
  271. // Update 更新图表分类基础信息
  272. func (chartClassify *ChartClassify) Update(cols []string) (err error) {
  273. o := orm.NewOrmUsingDB("data")
  274. _, err = o.Update(chartClassify, cols...)
  275. return
  276. }
  277. // GetChartClassifyMaxSort 获取图表分类下最大的排序数
  278. func GetChartClassifyMaxSort(parentId, source int) (sort int, err error) {
  279. o := orm.NewOrmUsingDB("data")
  280. sql := `SELECT Max(sort) AS sort FROM chart_classify WHERE parent_id=? AND source = ? `
  281. err = o.Raw(sql, parentId, source).QueryRow(&sort)
  282. return
  283. }
  284. type ChartClassifyView struct {
  285. ChartClassifyId int `orm:"column(chart_classify_id);pk"`
  286. ChartClassifyName string `description:"分类名称"`
  287. ParentId int `description:"父级id"`
  288. }
  289. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  290. o := orm.NewOrmUsingDB("data")
  291. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  292. err = o.Raw(sql, classifyId).QueryRow(&item)
  293. return
  294. }
  295. func GetChartClassifyByParentIdFromETA(parentId int) (items []*ChartClassifyItems, err error) {
  296. o := orm.NewOrmUsingDB("data")
  297. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = 1 order by sort asc,chart_classify_id asc`
  298. _, err = o.Raw(sql, parentId).QueryRows(&items)
  299. return
  300. }
  301. func GetChartClassifyAllFromETA() (items []*ChartClassifyItems, err error) {
  302. o := orm.NewOrmUsingDB("data")
  303. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = 1 order by sort asc,chart_classify_id asc`
  304. _, err = o.Raw(sql).QueryRows(&items)
  305. return
  306. }
  307. func GetChartClassifyTwo(source int) (items []*ChartClassifyItems, err error) {
  308. o := orm.NewOrmUsingDB("data")
  309. sql := ` SELECT * FROM chart_classify WHERE level=3 AND source = ? order by sort asc,chart_classify_id asc`
  310. _, err = o.Raw(sql, source).QueryRows(&items)
  311. return
  312. }
  313. func GetChartClassifyByLevel(level, source int) (items []*ChartClassifyItems, err error) {
  314. o := orm.NewOrmUsingDB("data")
  315. sql := ` SELECT * FROM chart_classify WHERE level=? AND source = ? order by sort asc,chart_classify_id asc`
  316. _, err = o.Raw(sql, level, source).QueryRows(&items)
  317. return
  318. }
  319. func EditChartClassifySysUser(classifyId, sysUserId int, chartClassifyName string) (err error) {
  320. o := orm.NewOrmUsingDB("data")
  321. sql := `UPDATE chart_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  322. _, err = o.Raw(sql, sysUserId, chartClassifyName, classifyId).Exec()
  323. return
  324. }
  325. func GetAllChartClassifyItemsBySource(source int) (items []*ChartClassifyItems, err error) {
  326. o := orm.NewOrmUsingDB("data")
  327. sql := ` SELECT * FROM chart_classify WHERE source = ? order by sort ASC,chart_classify_id ASC`
  328. _, err = o.Raw(sql, source).QueryRows(&items)
  329. return
  330. }
  331. // GetCrossVarietyChartClassifyBySysUserId
  332. // @Description: 根据创建人获取跨品种分析的分类
  333. // @author: Roc
  334. // @datetime 2023-11-24 14:05:43
  335. // @param sysUserId int
  336. // @return item *ChartClassify
  337. // @return err error
  338. func GetCrossVarietyChartClassifyBySysUserId(sysUserId int) (item *ChartClassify, err error) {
  339. o := orm.NewOrmUsingDB("data")
  340. sql := `SELECT * FROM chart_classify WHERE source = ? AND sys_user_id=?`
  341. err = o.Raw(sql, utils.CHART_SOURCE_CROSS_HEDGING, sysUserId).QueryRow(&item)
  342. return
  343. }
  344. // GetChartClassifyByParentIdAndName 根据父级ID和名称获取分类
  345. func GetChartClassifyByParentIdAndName(parentId int, classifyName string, classifyId int) (item *ChartClassify, err error) {
  346. o := orm.NewOrmUsingDB("data")
  347. sql := `SELECT * FROM chart_classify WHERE parent_id = ? AND chart_classify_name = ? AND chart_classify_id <> ? LIMIT 1`
  348. err = o.Raw(sql, parentId, classifyName, classifyId).QueryRow(&item)
  349. return
  350. }
  351. // GetChartClassifyByIdList
  352. // @Description: 根据分类ID列表获取分类
  353. // @author: Roc
  354. // @datetime 2024-04-01 13:21:48
  355. // @param classifyId []int
  356. // @return items []*ChartClassify
  357. // @return err error
  358. func GetChartClassifyByIdList(classifyIdList []int) (items []*ChartClassify, err error) {
  359. num := len(classifyIdList)
  360. if num <= 0 {
  361. return
  362. }
  363. o := orm.NewOrmUsingDB("data")
  364. sql := `SELECT * FROM chart_classify WHERE chart_classify_id in (` + utils.GetOrmInReplace(num) + `) `
  365. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  366. return
  367. }
  368. // GetChartClassifyBySourceAndIsJoinPermission
  369. // @Description: 根据分类类型和是否涉密获取分类列表
  370. // @author: Roc
  371. // @datetime 2024-03-29 10:30:21
  372. // @param source int
  373. // @param isJoinPermission int
  374. // @return items []*ChartClassify
  375. // @return err error
  376. func GetChartClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ChartClassify, err error) {
  377. o := orm.NewOrmUsingDB("data")
  378. sql := `SELECT * FROM chart_classify WHERE source = ? AND is_join_permission = ? `
  379. _, err = o.Raw(sql, source, isJoinPermission).QueryRows(&items)
  380. return
  381. }
  382. type ChartClassifyIdItems struct {
  383. ChartClassifyId int `description:"分类id"`
  384. ChartClassifyName string `description:"分类名称"`
  385. UniqueCode string `description:"唯一编码"`
  386. ParentId int `description:"父级分类id"`
  387. Level int `description:"层级"`
  388. RootId int `description:"顶级分类id"`
  389. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" json:"-"`
  390. HaveOperaAuth bool `description:"是否有该数据权限,默认:false"`
  391. }
  392. func GetChartClassifyByRootIdLevel(rootId, source int, orderStr string) (items []*ChartClassifyIdItems, err error) {
  393. o := orm.NewOrmUsingDB("data")
  394. sql := ` SELECT * FROM chart_classify WHERE root_id = ? AND source = ? `
  395. if orderStr != "" {
  396. sql += orderStr
  397. } else {
  398. sql += ` order by level desc, sort asc, chart_classify_id asc`
  399. }
  400. _, err = o.Raw(sql, rootId, source).QueryRows(&items)
  401. return
  402. }
  403. // UpdateChartClassifySortByParentIdAndSource 根据图表父类id更新排序
  404. func UpdateChartClassifySortByParentIdAndSource(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  405. o := orm.NewOrmUsingDB("data")
  406. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? AND source = ? `
  407. if classifyId > 0 {
  408. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  409. }
  410. _, err = o.Raw(sql, parentId, nowSort, source).Exec()
  411. return
  412. }
  413. // GetChartClassifyAllBySource 根据来源获取所有分类
  414. func GetChartClassifyAllBySource(source int) (items []*ChartClassifyItems, err error) {
  415. o := orm.NewOrmUsingDB("data")
  416. sql := ` SELECT * FROM chart_classify WHERE source = ? ORDER BY parent_id ASC, sort ASC, chart_classify_id ASC`
  417. _, err = o.Raw(sql, source).QueryRows(&items)
  418. return
  419. }
  420. // GetChartClassifyAndInfoByParentId
  421. func GetChartClassifyAndInfoByParentId(parentId int) (items []*ChartClassifyItems, err error) {
  422. o := orm.NewOrmUsingDB("data")
  423. sql := ` SELECT
  424. 0 AS chart_info_id,
  425. chart_classify_id,
  426. chart_classify_name,
  427. chart_classify_name_en,
  428. parent_id,
  429. create_time,
  430. modify_time,
  431. sys_user_id,
  432. sys_user_real_name,
  433. sort,
  434. level,
  435. unique_code,
  436. source,
  437. 0 as date_type,
  438. '' as start_date,
  439. '' as end_date,
  440. 0 as chart_type,
  441. '' as calendar,
  442. '' as season_start_date,
  443. '' as season_end_date
  444. FROM
  445. chart_classify
  446. WHERE
  447. parent_id = ? and source = 1 UNION ALL
  448. SELECT
  449. chart_info_id,
  450. chart_classify_id,
  451. chart_name AS chart_classify_name,
  452. chart_name_en AS chart_classify_name_en,
  453. 0 AS parent_id,
  454. create_time,
  455. modify_time,
  456. sys_user_id,
  457. sys_user_real_name,
  458. sort,
  459. 0 AS level,
  460. unique_code,
  461. source,
  462. date_type,
  463. start_date,
  464. end_date,
  465. chart_type,
  466. calendar,
  467. season_start_date,
  468. season_end_date
  469. FROM
  470. chart_info
  471. WHERE
  472. chart_classify_id = ? AND source = 1
  473. ORDER BY
  474. sort ASC,
  475. chart_classify_id ASC`
  476. _, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
  477. return
  478. }
  479. // GetChartClassifyAndInfoByParentId
  480. func GetChartClassifyAndInfoByParentIdForMe(parentId, adminId int) (items []*ChartClassifyItems, err error) {
  481. o := orm.NewOrmUsingDB("data")
  482. sql := ` SELECT
  483. 0 AS chart_info_id,
  484. chart_classify_id,
  485. chart_classify_name,
  486. chart_classify_name_en,
  487. parent_id,
  488. create_time,
  489. modify_time,
  490. sys_user_id,
  491. sys_user_real_name,
  492. sort,
  493. level,
  494. unique_code
  495. FROM
  496. chart_classify
  497. WHERE
  498. parent_id = ? and source = 1 UNION ALL
  499. SELECT
  500. chart_info_id,
  501. chart_classify_id,
  502. chart_name AS chart_classify_name,
  503. chart_name_en AS chart_classify_name_en,
  504. 0 AS parent_id,
  505. create_time,
  506. modify_time,
  507. sys_user_id,
  508. sys_user_real_name,
  509. sort,
  510. 0 AS level,
  511. unique_code
  512. FROM
  513. chart_info
  514. WHERE
  515. chart_classify_id = ? AND chart_type = 1 AND sys_user_id = ?
  516. ORDER BY
  517. sort ASC,
  518. chart_classify_id ASC`
  519. _, err = o.Raw(sql, parentId, parentId, adminId).QueryRows(&items)
  520. return
  521. }
  522. func GetChartClassifiesById(chartClassifyId int) (items []*ChartClassifyItems, err error) {
  523. o := orm.NewOrmUsingDB("data")
  524. sql := `
  525. SELECT *
  526. FROM chart_classify
  527. WHERE chart_classify_id = ?
  528. OR parent_id = ?
  529. OR parent_id IN (
  530. SELECT chart_classify_id
  531. FROM chart_classify
  532. WHERE parent_id = ?
  533. );`
  534. _,err = o.Raw(sql, chartClassifyId, chartClassifyId, chartClassifyId).QueryRows(&items)
  535. return
  536. }