chart_classify.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  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. // GetChartClassifyBySource 获取图表分类列表
  169. func GetChartClassifyBySource(source int) (items []*ChartClassifyItems, err error) {
  170. o := orm.NewOrmUsingDB("data")
  171. sql := ` SELECT * FROM chart_classify WHERE source = ? ORDER BY level ASC,chart_classify_id ASC`
  172. _, err = o.Raw(sql, source).QueryRows(&items)
  173. return
  174. }
  175. type ChartClassifyItems struct {
  176. ChartClassifyId int `description:"分类id"`
  177. ChartInfoId int `description:"指标id"`
  178. ChartClassifyName string
  179. ChartClassifyNameEn string
  180. ParentId int
  181. Level int `description:"层级"`
  182. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  183. UniqueCode string `description:"唯一编码"`
  184. Source int `description:"来源id"`
  185. SourceName string `description:"来源名称"`
  186. SysUserId int `description:"创建人id"`
  187. SysUserRealName string `description:"创建人姓名"`
  188. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  189. StartDate string `description:"自定义开始日期"`
  190. EndDate string `description:"自定义结束日期"`
  191. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  192. Calendar string `description:"公历/农历"`
  193. SeasonStartDate string `description:"季节性图开始日期"`
  194. SeasonEndDate string `description:"季节性图开始日期"`
  195. Children []*ChartClassifyItems
  196. Button ChartClassifyItemsButton `description:"按钮权限"`
  197. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  198. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  199. Disable bool `description:"勾选是否禁用"`
  200. }
  201. // ChartClassifyItemsButton 操作按钮
  202. type ChartClassifyItemsButton struct {
  203. AddButton bool `description:"是否可添加"`
  204. OpButton bool `description:"是否可编辑"`
  205. DeleteButton bool `description:"是否可删除"`
  206. MoveButton bool `description:"是否可移动"`
  207. }
  208. type ChartClassifyListResp struct {
  209. AllNodes []*ChartClassifyItems
  210. Language string `description:"指标的展示语言,CN:中文,EN:英文"`
  211. CanOpClassify bool `description:"是否允许操作分类"`
  212. }
  213. type ChartClassifyDeleteCheckResp struct {
  214. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  215. TipsMsg string `description:"提示信息"`
  216. }
  217. type ChartClassifyDeleteCheckReq struct {
  218. ChartClassifyId int `description:"分类id"`
  219. ChartInfoId int `description:"指标id"`
  220. }
  221. func GetChartClassifyCountByClassifyId(chartClassifyId int) (count int, err error) {
  222. o := orm.NewOrmUsingDB("data")
  223. sql := ` SELECT COUNT(1) AS count FROM (
  224. SELECT rd.*
  225. FROM (SELECT * FROM chart_classify WHERE parent_id IS NOT NULL) rd,
  226. (SELECT @pid := ?) pd
  227. WHERE FIND_IN_SET(parent_id, @pid) > 0
  228. AND @pid := CONCAT(@pid, ',', chart_classify_id)
  229. UNION SELECT * FROM chart_classify WHERE chart_classify_id = @pid
  230. )AS t
  231. WHERE t.chart_classify_id<>? `
  232. err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&count)
  233. return
  234. }
  235. func GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
  236. o := orm.NewOrmUsingDB("data")
  237. sql := ` SELECT * FROM chart_classify WHERE 1=1 `
  238. if condition != "" {
  239. sql += condition
  240. }
  241. err = o.Raw(sql, pars).QueryRow(&item)
  242. return
  243. }
  244. // MoveChartClassifyReq 移动图表分类请求参数
  245. type MoveChartClassifyReq struct {
  246. ClassifyId int `description:"分类id"`
  247. ParentClassifyId int `description:"父级分类id"`
  248. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  249. NextClassifyId int `description:"下一个兄弟节点分类id"`
  250. ChartInfoId int `description:"图表ID, 如果图表ID有值,则移动对象为图表,否则认为移动对象分类"`
  251. PrevChartInfoId int `description:"上一个图表ID"`
  252. NextChartInfoId int `description:"下一个图表ID"`
  253. }
  254. // GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  255. func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
  256. o := orm.NewOrmUsingDB("data")
  257. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
  258. err = o.Raw(sql, parentId).QueryRow(&item)
  259. return
  260. }
  261. // GetFirstChartClassifyByParentIdAndSource 获取当前父级图表分类下的排序第一条的数据
  262. func GetFirstChartClassifyByParentIdAndSource(parentId, source int) (item *ChartClassify, err error) {
  263. o := orm.NewOrmUsingDB("data")
  264. sql := ` SELECT * FROM chart_classify WHERE parent_id=? and source = ? order by sort asc,chart_classify_id asc limit 1`
  265. err = o.Raw(sql, parentId, source).QueryRow(&item)
  266. return
  267. }
  268. // UpdateChartClassifySortByParentId 根据图表父类id更新排序
  269. func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  270. o := orm.NewOrmUsingDB("data")
  271. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  272. if classifyId > 0 {
  273. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  274. }
  275. _, err = o.Raw(sql, parentId, nowSort).Exec()
  276. return
  277. }
  278. // Update 更新图表分类基础信息
  279. func (chartClassify *ChartClassify) Update(cols []string) (err error) {
  280. o := orm.NewOrmUsingDB("data")
  281. _, err = o.Update(chartClassify, cols...)
  282. return
  283. }
  284. // GetChartClassifyMaxSort 获取图表分类下最大的排序数
  285. func GetChartClassifyMaxSort(parentId, source int) (sort int, err error) {
  286. o := orm.NewOrmUsingDB("data")
  287. sql := `SELECT Max(sort) AS sort FROM chart_classify WHERE parent_id=? AND source = ? `
  288. err = o.Raw(sql, parentId, source).QueryRow(&sort)
  289. return
  290. }
  291. type ChartClassifyView struct {
  292. ChartClassifyId int `orm:"column(chart_classify_id);pk"`
  293. ChartClassifyName string `description:"分类名称"`
  294. ParentId int `description:"父级id"`
  295. }
  296. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  297. o := orm.NewOrmUsingDB("data")
  298. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  299. err = o.Raw(sql, classifyId).QueryRow(&item)
  300. return
  301. }
  302. func GetChartClassifyByParentIdFromETA(parentId int) (items []*ChartClassifyItems, err error) {
  303. o := orm.NewOrmUsingDB("data")
  304. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = 1 order by sort asc,chart_classify_id asc`
  305. _, err = o.Raw(sql, parentId).QueryRows(&items)
  306. return
  307. }
  308. func GetChartClassifyAllFromETA() (items []*ChartClassifyItems, err error) {
  309. o := orm.NewOrmUsingDB("data")
  310. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = 1 order by sort asc,chart_classify_id asc`
  311. _, err = o.Raw(sql).QueryRows(&items)
  312. return
  313. }
  314. func GetChartClassifyTwo(source int) (items []*ChartClassifyItems, err error) {
  315. o := orm.NewOrmUsingDB("data")
  316. sql := ` SELECT * FROM chart_classify WHERE level=3 AND source = ? order by sort asc,chart_classify_id asc`
  317. _, err = o.Raw(sql, source).QueryRows(&items)
  318. return
  319. }
  320. func GetChartClassifyByLevel(level, source int) (items []*ChartClassifyItems, err error) {
  321. o := orm.NewOrmUsingDB("data")
  322. sql := ` SELECT * FROM chart_classify WHERE level=? AND source = ? order by sort asc,chart_classify_id asc`
  323. _, err = o.Raw(sql, level, source).QueryRows(&items)
  324. return
  325. }
  326. func EditChartClassifySysUser(classifyId, sysUserId int, chartClassifyName string) (err error) {
  327. o := orm.NewOrmUsingDB("data")
  328. sql := `UPDATE chart_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  329. _, err = o.Raw(sql, sysUserId, chartClassifyName, classifyId).Exec()
  330. return
  331. }
  332. func GetAllChartClassifyItemsBySource(source int) (items []*ChartClassifyItems, err error) {
  333. o := orm.NewOrmUsingDB("data")
  334. sql := ` SELECT * FROM chart_classify WHERE source = ? order by sort ASC,chart_classify_id ASC`
  335. _, err = o.Raw(sql, source).QueryRows(&items)
  336. return
  337. }
  338. // GetCrossVarietyChartClassifyBySysUserId
  339. // @Description: 根据创建人获取跨品种分析的分类
  340. // @author: Roc
  341. // @datetime 2023-11-24 14:05:43
  342. // @param sysUserId int
  343. // @return item *ChartClassify
  344. // @return err error
  345. func GetCrossVarietyChartClassifyBySysUserId(sysUserId int) (item *ChartClassify, err error) {
  346. o := orm.NewOrmUsingDB("data")
  347. sql := `SELECT * FROM chart_classify WHERE source = ? AND sys_user_id=?`
  348. err = o.Raw(sql, utils.CHART_SOURCE_CROSS_HEDGING, sysUserId).QueryRow(&item)
  349. return
  350. }
  351. // GetChartClassifyByParentIdAndName 根据父级ID和名称获取分类
  352. func GetChartClassifyByParentIdAndName(parentId int, classifyName string, classifyId int) (item *ChartClassify, err error) {
  353. o := orm.NewOrmUsingDB("data")
  354. sql := `SELECT * FROM chart_classify WHERE parent_id = ? AND chart_classify_name = ? AND chart_classify_id <> ? LIMIT 1`
  355. err = o.Raw(sql, parentId, classifyName, classifyId).QueryRow(&item)
  356. return
  357. }
  358. // GetChartClassifyByIdList
  359. // @Description: 根据分类ID列表获取分类
  360. // @author: Roc
  361. // @datetime 2024-04-01 13:21:48
  362. // @param classifyId []int
  363. // @return items []*ChartClassify
  364. // @return err error
  365. func GetChartClassifyByIdList(classifyIdList []int) (items []*ChartClassify, err error) {
  366. num := len(classifyIdList)
  367. if num <= 0 {
  368. return
  369. }
  370. o := orm.NewOrmUsingDB("data")
  371. sql := `SELECT * FROM chart_classify WHERE chart_classify_id in (` + utils.GetOrmInReplace(num) + `) `
  372. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  373. return
  374. }
  375. // GetChartClassifyBySourceAndIsJoinPermission
  376. // @Description: 根据分类类型和是否涉密获取分类列表
  377. // @author: Roc
  378. // @datetime 2024-03-29 10:30:21
  379. // @param source int
  380. // @param isJoinPermission int
  381. // @return items []*ChartClassify
  382. // @return err error
  383. func GetChartClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ChartClassify, err error) {
  384. o := orm.NewOrmUsingDB("data")
  385. sql := `SELECT * FROM chart_classify WHERE source = ? AND is_join_permission = ? `
  386. _, err = o.Raw(sql, source, isJoinPermission).QueryRows(&items)
  387. return
  388. }
  389. type ChartClassifyIdItems struct {
  390. ChartClassifyId int `description:"分类id"`
  391. ChartClassifyName string `description:"分类名称"`
  392. UniqueCode string `description:"唯一编码"`
  393. ParentId int `description:"父级分类id"`
  394. Level int `description:"层级"`
  395. RootId int `description:"顶级分类id"`
  396. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" json:"-"`
  397. HaveOperaAuth bool `description:"是否有该数据权限,默认:false"`
  398. }
  399. func GetChartClassifyByRootIdLevel(rootId, source int, orderStr string) (items []*ChartClassifyIdItems, err error) {
  400. o := orm.NewOrmUsingDB("data")
  401. sql := ` SELECT * FROM chart_classify WHERE root_id = ? AND source = ? `
  402. if orderStr != "" {
  403. sql += orderStr
  404. } else {
  405. sql += ` order by level desc, sort asc, chart_classify_id asc`
  406. }
  407. _, err = o.Raw(sql, rootId, source).QueryRows(&items)
  408. return
  409. }
  410. // UpdateChartClassifySortByParentIdAndSource 根据图表父类id更新排序
  411. func UpdateChartClassifySortByParentIdAndSource(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  412. o := orm.NewOrmUsingDB("data")
  413. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? AND source = ? `
  414. if classifyId > 0 {
  415. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  416. }
  417. _, err = o.Raw(sql, parentId, nowSort, source).Exec()
  418. return
  419. }
  420. // GetChartClassifyAllBySource 根据来源获取所有分类
  421. func GetChartClassifyAllBySource(source int) (items []*ChartClassifyItems, err error) {
  422. o := orm.NewOrmUsingDB("data")
  423. sql := ` SELECT * FROM chart_classify WHERE source = ? ORDER BY parent_id ASC, sort ASC, chart_classify_id ASC`
  424. _, err = o.Raw(sql, source).QueryRows(&items)
  425. return
  426. }
  427. // GetChartClassifyIdListByAdminId
  428. // @Description: 根据用户id和指标类型获取其关联的所有指标分类id列表
  429. // @author: Roc
  430. // @datetime 2024-09-11 15:52:48
  431. // @param adminId int
  432. // @param source int
  433. // @return chartClassifyIdList []int
  434. // @return err error
  435. func GetChartClassifyIdListByAdminId(adminId, source int) (chartClassifyIdList []int, err error) {
  436. o := orm.NewOrmUsingDB("data")
  437. sql := ` SELECT chart_classify_id FROM chart_info WHERE sys_user_id = ? AND source = ?`
  438. pars := []interface{}{adminId, source}
  439. sql += ` group by chart_classify_id `
  440. _, err = o.Raw(sql, pars).QueryRows(&chartClassifyIdList)
  441. return
  442. }
  443. // GetChartClassifyAndInfoByParentId
  444. func GetChartClassifyAndInfoByParentId(parentId int) (items []*ChartClassifyItems, err error) {
  445. o := orm.NewOrmUsingDB("data")
  446. sql := ` SELECT
  447. 0 AS chart_info_id,
  448. chart_classify_id,
  449. chart_classify_name,
  450. chart_classify_name_en,
  451. parent_id,
  452. create_time,
  453. modify_time,
  454. sys_user_id,
  455. sys_user_real_name,
  456. sort,
  457. level,
  458. unique_code,
  459. source,
  460. 0 as date_type,
  461. '' as start_date,
  462. '' as end_date,
  463. 0 as chart_type,
  464. '' as calendar,
  465. '' as season_start_date,
  466. '' as season_end_date
  467. FROM
  468. chart_classify
  469. WHERE
  470. parent_id = ? and source = 1 UNION ALL
  471. SELECT
  472. chart_info_id,
  473. chart_classify_id,
  474. chart_name AS chart_classify_name,
  475. chart_name_en AS chart_classify_name_en,
  476. 0 AS parent_id,
  477. create_time,
  478. modify_time,
  479. sys_user_id,
  480. sys_user_real_name,
  481. sort,
  482. 0 AS level,
  483. unique_code,
  484. source,
  485. date_type,
  486. start_date,
  487. end_date,
  488. chart_type,
  489. calendar,
  490. season_start_date,
  491. season_end_date
  492. FROM
  493. chart_info
  494. WHERE
  495. chart_classify_id = ? AND source = 1
  496. ORDER BY
  497. sort ASC,
  498. chart_classify_id ASC`
  499. _, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
  500. return
  501. }
  502. // GetChartClassifyAndInfoByParentId
  503. func GetChartClassifyAndInfoByParentIdForMe(parentId, adminId int) (items []*ChartClassifyItems, err error) {
  504. o := orm.NewOrmUsingDB("data")
  505. sql := ` SELECT
  506. 0 AS chart_info_id,
  507. chart_classify_id,
  508. chart_classify_name,
  509. chart_classify_name_en,
  510. parent_id,
  511. create_time,
  512. modify_time,
  513. sys_user_id,
  514. sys_user_real_name,
  515. sort,
  516. level,
  517. unique_code
  518. FROM
  519. chart_classify
  520. WHERE
  521. parent_id = ? and source = 1 UNION ALL
  522. SELECT
  523. chart_info_id,
  524. chart_classify_id,
  525. chart_name AS chart_classify_name,
  526. chart_name_en AS chart_classify_name_en,
  527. 0 AS parent_id,
  528. create_time,
  529. modify_time,
  530. sys_user_id,
  531. sys_user_real_name,
  532. sort,
  533. 0 AS level,
  534. unique_code
  535. FROM
  536. chart_info
  537. WHERE
  538. chart_classify_id = ? AND sys_user_id = ? AND source = 1
  539. ORDER BY
  540. sort ASC,
  541. chart_classify_id ASC`
  542. _, err = o.Raw(sql, parentId, parentId, adminId).QueryRows(&items)
  543. return
  544. }
  545. func GetChartClassifiesById(chartClassifyId int) (items []*ChartClassifyItems, err error) {
  546. o := orm.NewOrmUsingDB("data")
  547. sql := `
  548. SELECT *
  549. FROM chart_classify
  550. WHERE chart_classify_id = ?
  551. OR parent_id = ?
  552. OR parent_id IN (
  553. SELECT chart_classify_id
  554. FROM chart_classify
  555. WHERE parent_id = ?
  556. );`
  557. _, err = o.Raw(sql, chartClassifyId, chartClassifyId, chartClassifyId).QueryRows(&items)
  558. return
  559. }