chart_classify.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "time"
  7. )
  8. type ChartClassify struct {
  9. ChartClassifyId int `orm:"column(chart_classify_id);pk" gorm:"primaryKey" `
  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. err = global.DmSQL["data"].Create(item).Error
  27. if err != nil {
  28. return
  29. }
  30. lastId = int64(item.ChartClassifyId)
  31. return
  32. }
  33. type AddChartClassifyReq struct {
  34. ChartClassifyName string `description:"分类名称"`
  35. ParentId int `description:"父级id,第一级传0"`
  36. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  37. }
  38. // GetChartClassifyCount
  39. // @Description: 根据图表分类名称获取对应的数量
  40. // @author: Roc
  41. // @datetime 2024-04-16 18:13:40
  42. // @param chartClassifyName string
  43. // @param parentId int
  44. // @param source int
  45. // @return count int
  46. // @return err error
  47. func GetChartClassifyCount(chartClassifyName string, parentId, source int) (count int, err error) {
  48. o := global.DmSQL["data"]
  49. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name=? `
  50. err = o.Raw(sql, parentId, source, chartClassifyName).Scan(&count).Error
  51. return
  52. }
  53. // GetChartClassifyEnCount
  54. // @Description: 根据图表分类英文名称获取对应的数量
  55. // @author: Roc
  56. // @datetime 2024-04-16 18:13:24
  57. // @param chartClassifyNameEn string
  58. // @param parentId int
  59. // @param source int
  60. // @return count int
  61. // @return err error
  62. func GetChartClassifyEnCount(chartClassifyNameEn string, parentId, source int) (count int, err error) {
  63. o := global.DmSQL["data"]
  64. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name_en = ? `
  65. err = o.Raw(sql, parentId, source, chartClassifyNameEn).Scan(&count).Error
  66. return
  67. }
  68. type EditChartClassifyReq struct {
  69. ChartClassifyName string `description:"分类名称"`
  70. ChartClassifyId int `description:"分类id"`
  71. }
  72. func GetChartClassifyById(classifyId int) (item *ChartClassify, err error) {
  73. o := global.DmSQL["data"]
  74. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  75. err = o.Raw(sql, classifyId).First(&item).Error
  76. return
  77. }
  78. func GetChartClassifyCountById(classifyId int) (count int, err error) {
  79. o := global.DmSQL["data"]
  80. sql := `SELECT count(1) AS count FROM chart_classify WHERE chart_classify_id=? `
  81. err = o.Raw(sql, classifyId).Scan(&count).Error
  82. return
  83. }
  84. type DeleteChartClassifyReq struct {
  85. ChartClassifyId int `description:"分类id"`
  86. ChartInfoId int `description:"指标id"`
  87. }
  88. // GetChartClassifyByParentId
  89. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  90. func GetChartClassifyByParentId(parentId, source int) (items []*ChartClassifyItems, err error) {
  91. o := global.DmSQL["data"]
  92. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = ? order by sort asc,chart_classify_id asc`
  93. err = o.Raw(sql, parentId, source).Scan(&items).Error
  94. return
  95. }
  96. // GetChartClassifyAll
  97. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  98. func GetChartClassifyAll(source int) (items []*ChartClassifyItems, err error) {
  99. o := global.DmSQL["data"]
  100. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = ? order by sort asc,chart_classify_id asc`
  101. err = o.Raw(sql, source).Scan(&items).Error
  102. return
  103. }
  104. type ChartClassifyItems struct {
  105. ChartClassifyId int `description:"分类id"`
  106. ChartInfoId int `description:"指标id"`
  107. ChartClassifyName string
  108. ChartClassifyNameEn string
  109. ParentId int
  110. Level int `description:"层级"`
  111. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  112. UniqueCode string `description:"唯一编码"`
  113. Source int `description:"来源id"`
  114. SourceName string `description:"来源名称"`
  115. SysUserId int `description:"创建人id"`
  116. SysUserRealName string `description:"创建人姓名"`
  117. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  118. StartDate string `description:"自定义开始日期"`
  119. EndDate string `description:"自定义结束日期"`
  120. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  121. Calendar string `description:"公历/农历"`
  122. SeasonStartDate string `description:"季节性图开始日期"`
  123. SeasonEndDate string `description:"季节性图开始日期"`
  124. Children []*ChartClassifyItems `gorm:"-"`
  125. Button ChartClassifyItemsButton `gorm:"-" description:"按钮权限"`
  126. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  127. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  128. }
  129. // ChartClassifyItemsButton 操作按钮
  130. type ChartClassifyItemsButton struct {
  131. AddButton bool `description:"是否可添加"`
  132. OpButton bool `description:"是否可编辑"`
  133. DeleteButton bool `description:"是否可删除"`
  134. MoveButton bool `description:"是否可移动"`
  135. }
  136. type ChartClassifyListResp struct {
  137. AllNodes []*ChartClassifyItems
  138. Language string `description:"指标的展示语言,CN:中文,EN:英文"`
  139. CanOpClassify bool `description:"是否允许操作分类"`
  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 GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
  150. o := global.DmSQL["data"]
  151. sql := ` SELECT * FROM chart_classify WHERE 1=1 `
  152. if condition != "" {
  153. sql += condition
  154. }
  155. err = o.Raw(sql, pars...).First(&item).Error
  156. return
  157. }
  158. // MoveChartClassifyReq 移动图表分类请求参数
  159. type MoveChartClassifyReq struct {
  160. ClassifyId int `description:"分类id"`
  161. ParentClassifyId int `description:"父级分类id"`
  162. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  163. NextClassifyId int `description:"下一个兄弟节点分类id"`
  164. ChartInfoId int `description:"图表ID, 如果图表ID有值,则移动对象为图表,否则认为移动对象分类"`
  165. PrevChartInfoId int `description:"上一个图表ID"`
  166. NextChartInfoId int `description:"下一个图表ID"`
  167. }
  168. // GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  169. func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
  170. o := global.DmSQL["data"]
  171. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
  172. err = o.Raw(sql, parentId).First(&item).Error
  173. return
  174. }
  175. // GetFirstChartClassifyByParentIdAndSource 获取当前父级图表分类下的排序第一条的数据
  176. func GetFirstChartClassifyByParentIdAndSource(parentId, source int) (item *ChartClassify, err error) {
  177. o := global.DmSQL["data"]
  178. sql := ` SELECT * FROM chart_classify WHERE parent_id=? and source = ? order by sort asc,chart_classify_id asc limit 1`
  179. err = o.Raw(sql, parentId, source).First(&item).Error
  180. return
  181. }
  182. // UpdateChartClassifySortByParentId 根据图表父类id更新排序
  183. func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  184. o := global.DmSQL["data"]
  185. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  186. if classifyId > 0 {
  187. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  188. }
  189. err = o.Exec(sql, parentId, nowSort).Error
  190. return
  191. }
  192. // Update 更新图表分类基础信息
  193. func (chartClassify *ChartClassify) Update(cols []string) (err error) {
  194. err = global.DmSQL["data"].Select(cols).Updates(chartClassify).Error
  195. return
  196. }
  197. // GetChartClassifyMaxSort 获取图表分类下最大的排序数
  198. func GetChartClassifyMaxSort(parentId, source int) (sort int, err error) {
  199. o := global.DmSQL["data"]
  200. sql := `SELECT COALESCE(MAX(sort),0) AS sort FROM chart_classify WHERE parent_id=? AND source = ? `
  201. err = o.Raw(sql, parentId, source).Scan(&sort).Error
  202. return
  203. }
  204. type ChartClassifyView struct {
  205. ChartClassifyId int `orm:"column(chart_classify_id);pk" gorm:"primaryKey" `
  206. ChartClassifyName string `description:"分类名称"`
  207. ParentId int `description:"父级id"`
  208. }
  209. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  210. o := global.DmSQL["data"]
  211. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  212. err = o.Raw(sql, classifyId).First(&item).Error
  213. return
  214. }
  215. func GetChartClassifyByLevel(level, source int) (items []*ChartClassifyItems, err error) {
  216. o := global.DmSQL["data"]
  217. sql := ` SELECT * FROM chart_classify WHERE level=? AND source = ? order by sort asc,chart_classify_id asc`
  218. err = o.Raw(sql, level, source).Scan(&items).Error
  219. return
  220. }
  221. func EditChartClassifySysUser(classifyId, sysUserId int, chartClassifyName string) (err error) {
  222. o := global.DmSQL["data"]
  223. sql := `UPDATE chart_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  224. err = o.Exec(sql, sysUserId, chartClassifyName, classifyId).Error
  225. return
  226. }
  227. func GetAllChartClassifyItemsBySource(source int) (items []*ChartClassifyItems, err error) {
  228. o := global.DmSQL["data"]
  229. sql := ` SELECT * FROM chart_classify WHERE source = ? order by sort ASC,chart_classify_id ASC`
  230. err = o.Raw(sql, source).Scan(&items).Error
  231. return
  232. }
  233. // GetCrossVarietyChartClassifyBySysUserId
  234. // @Description: 根据创建人获取跨品种分析的分类
  235. // @author: Roc
  236. // @datetime 2023-11-24 14:05:43
  237. // @param sysUserId int
  238. // @return item *ChartClassify
  239. // @return err error
  240. func GetCrossVarietyChartClassifyBySysUserId(sysUserId int) (item *ChartClassify, err error) {
  241. o := global.DmSQL["data"]
  242. sql := `SELECT * FROM chart_classify WHERE source = ? AND sys_user_id=?`
  243. err = o.Raw(sql, utils.CHART_SOURCE_CROSS_HEDGING, sysUserId).First(&item).Error
  244. return
  245. }
  246. // GetChartClassifyByParentIdAndName 根据父级ID和名称获取分类
  247. func GetChartClassifyByParentIdAndName(source, parentId int, classifyName string, classifyId int) (item *ChartClassify, err error) {
  248. o := global.DmSQL["data"]
  249. sql := `SELECT * FROM chart_classify WHERE source = ? AND parent_id = ? AND chart_classify_name = ? AND chart_classify_id <> ? LIMIT 1`
  250. err = o.Raw(sql, source, parentId, classifyName, classifyId).First(&item).Error
  251. return
  252. }
  253. // GetChartClassifyByIdList
  254. // @Description: 根据分类ID列表获取分类
  255. // @author: Roc
  256. // @datetime 2024-04-01 13:21:48
  257. // @param classifyId []int
  258. // @return items []*ChartClassify
  259. // @return err error
  260. func GetChartClassifyByIdList(classifyIdList []int) (items []*ChartClassify, err error) {
  261. num := len(classifyIdList)
  262. if num <= 0 {
  263. return
  264. }
  265. o := global.DmSQL["data"]
  266. sql := `SELECT * FROM chart_classify WHERE chart_classify_id in (` + utils.GetOrmInReplace(num) + `) `
  267. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  268. return
  269. }
  270. // GetChartClassifyBySourceAndIsJoinPermission
  271. // @Description: 根据分类类型和是否涉密获取分类列表
  272. // @author: Roc
  273. // @datetime 2024-03-29 10:30:21
  274. // @param source int
  275. // @param isJoinPermission int
  276. // @return items []*ChartClassify
  277. // @return err error
  278. func GetChartClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ChartClassify, err error) {
  279. o := global.DmSQL["data"]
  280. sql := `SELECT * FROM chart_classify WHERE source = ? AND is_join_permission = ? `
  281. err = o.Raw(sql, source, isJoinPermission).Scan(&items).Error
  282. return
  283. }
  284. type ChartClassifyIdItems struct {
  285. ChartClassifyId int `description:"分类id"`
  286. ChartClassifyName string `description:"分类名称"`
  287. UniqueCode string `description:"唯一编码"`
  288. ParentId int `description:"父级分类id"`
  289. Level int `description:"层级"`
  290. RootId int `description:"顶级分类id"`
  291. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" json:"-"`
  292. HaveOperaAuth bool `description:"是否有该数据权限,默认:false"`
  293. }
  294. func GetChartClassifyByRootIdLevel(rootId, source int, orderStr string) (items []*ChartClassifyIdItems, err error) {
  295. o := global.DmSQL["data"]
  296. sql := ` SELECT * FROM chart_classify WHERE root_id = ? AND source = ? `
  297. if orderStr != "" {
  298. sql += orderStr
  299. } else {
  300. sql += ` order by level desc, sort asc, chart_classify_id asc`
  301. }
  302. err = o.Raw(sql, rootId, source).Scan(&items).Error
  303. return
  304. }
  305. // UpdateChartClassifySortByParentIdAndSource 根据图表父类id更新排序
  306. func UpdateChartClassifySortByParentIdAndSource(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  307. o := global.DmSQL["data"]
  308. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? AND source = ? `
  309. if classifyId > 0 {
  310. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  311. }
  312. err = o.Exec(sql, parentId, nowSort, source).Error
  313. return
  314. }
  315. // GetChartClassifyAllBySource 根据来源获取所有分类
  316. func GetChartClassifyAllBySource(source int) (items []*ChartClassifyItems, err error) {
  317. o := global.DmSQL["data"]
  318. sql := ` SELECT * FROM chart_classify WHERE source = ? ORDER BY parent_id ASC, sort ASC, chart_classify_id ASC`
  319. err = o.Raw(sql, source).Scan(&items).Error
  320. return
  321. }
  322. // delByIds
  323. func DeleteChartClassifyByIds(ids []int) (err error) {
  324. o := global.DmSQL["data"]
  325. sql := `DELETE FROM chart_classify WHERE chart_classify_id IN (` + utils.GetOrmInReplace(len(ids)) + `)`
  326. err = o.Exec(sql, ids).Error
  327. return
  328. }