edb_info_relation.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. package data_manage
  2. import (
  3. "eta/eta_api/controllers"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/excel"
  7. "eta/eta_api/models/fe_calendar"
  8. "eta/eta_api/models/sandbox"
  9. "eta/eta_api/services/data"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. // EdbInfoRelationController 指标引用管理
  15. type EdbInfoRelationController struct {
  16. controllers.BaseAuthController
  17. }
  18. // RelationEdbList
  19. // @Title 获取被引用的指标列表接口
  20. // @Description 获取被引用的指标列表接口
  21. // @Param Source query int true "来源:2:wind,34:钢联化工"
  22. // @Param ClassifyId query string false "分类ID,支持多选,用英文,隔开"
  23. // @Param SysUserId query string false "创建人,支持多选,用英文,隔开"
  24. // @Param Frequency query string false "频度,支持多选,用英文,隔开"
  25. // @Param Keyword query string false "关键词"
  26. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'RelationTime':引用日期 'RelationNum' 引用次数"
  27. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  28. // @Success 200 {object} data_manage.BaseRelationEdbInfoResp
  29. // @router /edb_info/relation/edb_list [get]
  30. func (c *EdbInfoRelationController) RelationEdbList() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. c.Data["json"] = br
  34. c.ServeJSON()
  35. }()
  36. source, _ := c.GetInt("Source")
  37. classifyId := c.GetString("ClassifyId")
  38. sysUserId := c.GetString("SysUserId")
  39. frequency := c.GetString("Frequency")
  40. keyword := c.GetString("Keyword")
  41. status := c.GetString("Status")
  42. sortParam := c.GetString("SortParam")
  43. sortType := c.GetString("SortType")
  44. switch sortParam {
  45. case "RelationTime":
  46. sortParam = " r.relation_time "
  47. case "RelationNum":
  48. sortParam = " r.relation_num "
  49. default:
  50. sortParam = " r.relation_time "
  51. }
  52. switch sortType {
  53. case "desc", "asc":
  54. default:
  55. sortType = "desc"
  56. }
  57. pageSize, _ := c.GetInt("PageSize")
  58. currentIndex, _ := c.GetInt("CurrentIndex")
  59. var startSize int
  60. if pageSize <= 0 {
  61. pageSize = utils.PageSize20
  62. }
  63. if currentIndex <= 0 {
  64. currentIndex = 1
  65. }
  66. edbType := 1 //基础指标
  67. if source == -1 { //计算指标
  68. edbType = 2
  69. source = 0
  70. }
  71. startSize = utils.StartIndex(currentIndex, pageSize)
  72. total, list, err := data.GetEdbRelationList(source, edbType, classifyId, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
  73. if err != nil && err.Error() != utils.ErrNoRow() {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  76. return
  77. }
  78. page := paging.GetPaging(currentIndex, pageSize, total)
  79. resp := data_manage.BaseRelationEdbInfoResp{
  80. Paging: page,
  81. List: list,
  82. }
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. br.Data = resp
  87. }
  88. // RelationEdbListDetail
  89. // @Title 获取引用详情接口
  90. // @Description 获取引用详情接口
  91. // @Param EdbInfoId query int true "指标ID"
  92. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  93. // @router /edb_info/relation/detail [get]
  94. func (c *EdbInfoRelationController) RelationEdbListDetail() {
  95. br := new(models.BaseResponse).Init()
  96. defer func() {
  97. c.Data["json"] = br
  98. c.ServeJSON()
  99. }()
  100. edbInfoId, _ := c.GetInt("EdbInfoId")
  101. pageSize, _ := c.GetInt("PageSize")
  102. currentIndex, _ := c.GetInt("CurrentIndex")
  103. var startSize int
  104. if pageSize <= 0 {
  105. pageSize = utils.PageSize20
  106. }
  107. if currentIndex <= 0 {
  108. currentIndex = 1
  109. }
  110. startSize = utils.StartIndex(currentIndex, pageSize)
  111. total, relationList, err := data_manage.GetEdbInfoRelationDetailList(edbInfoId, startSize, pageSize)
  112. if err != nil && err.Error() != utils.ErrNoRow() {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  115. return
  116. }
  117. list := make([]*data_manage.EdbInfoRelationDetail, 0)
  118. // 查询逻辑图
  119. sandboxIds := make([]int, 0)
  120. // 查询图库
  121. chartInfoIds := make([]int, 0)
  122. // 查询表格
  123. tableInfoIds := make([]int, 0)
  124. // 查询事件日历
  125. eventInfoIds := make([]int, 0)
  126. // 预测指标
  127. predictEdbIds := make([]int, 0)
  128. for _, v := range relationList {
  129. switch v.ReferObjectType {
  130. case utils.EDB_RELATION_SANDBOX:
  131. sandboxIds = append(sandboxIds, v.ReferObjectId)
  132. case utils.EDB_RELATION_CALENDAR:
  133. eventInfoIds = append(eventInfoIds, v.ReferObjectId)
  134. case utils.EDB_RELATION_CHART:
  135. chartInfoIds = append(chartInfoIds, v.ReferObjectId)
  136. case utils.EDB_RELATION_TABLE:
  137. tableInfoIds = append(tableInfoIds, v.ReferObjectId)
  138. case utils.EDB_RELATION_PREDICT_EDB:
  139. predictEdbIds = append(predictEdbIds, v.ReferObjectId)
  140. }
  141. }
  142. objectNameMap := make(map[string]string)
  143. if len(sandboxIds) > 0 {
  144. sandboxList, err := sandbox.GetSandboxNameByIds(sandboxIds)
  145. if err != nil && err.Error() != utils.ErrNoRow() {
  146. br.Msg = "获取失败"
  147. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  148. return
  149. }
  150. for _, v := range sandboxList {
  151. name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_SANDBOX, v.SandboxId)
  152. objectNameMap[name] = v.Name
  153. }
  154. }
  155. // 查询事件日历
  156. if len(eventInfoIds) > 0 {
  157. matterOb := new(fe_calendar.FeCalendarMatter)
  158. cond := " AND fe_calendar_matter_id in (" + utils.GetOrmInReplace(len(eventInfoIds)) + ")"
  159. pars := make([]interface{}, 0)
  160. pars = append(pars, eventInfoIds)
  161. eventList, err := matterOb.GetItemsByCondition(cond, pars, []string{}, "")
  162. if err != nil && err.Error() != utils.ErrNoRow() {
  163. br.Msg = "获取失败"
  164. br.ErrMsg = "获取事件日历数据失败,Err:" + err.Error()
  165. return
  166. }
  167. for _, v := range eventList {
  168. name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_CALENDAR, v.FeCalendarMatterId)
  169. objectNameMap[name] = fmt.Sprintf("%s, %s", v.MatterDate, v.ChartPermissionName)
  170. }
  171. }
  172. // 查询图表
  173. if len(chartInfoIds) > 0 {
  174. chartList, err := data_manage.GetChartInfoByIdList(chartInfoIds)
  175. if err != nil && err.Error() != utils.ErrNoRow() {
  176. br.Msg = "获取失败"
  177. br.ErrMsg = "获取图表数据失败,Err:" + err.Error()
  178. return
  179. }
  180. for _, v := range chartList {
  181. name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_CHART, v.ChartInfoId)
  182. objectNameMap[name] = v.ChartName
  183. }
  184. }
  185. // 查询表格名称
  186. if len(tableInfoIds) > 0 {
  187. cond := " AND excel_info_id in (" + utils.GetOrmInReplace(len(tableInfoIds)) + ")"
  188. pars := make([]interface{}, 0)
  189. pars = append(pars, tableInfoIds)
  190. tableList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars)
  191. if err != nil && err.Error() != utils.ErrNoRow() {
  192. br.Msg = "获取失败"
  193. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  194. return
  195. }
  196. // 查询父级名称
  197. excelParentName := make(map[int]string)
  198. parentIds := make([]int, 0)
  199. for _, v := range tableList {
  200. if v.ParentId > 0 {
  201. parentIds = append(parentIds, v.ParentId)
  202. }
  203. }
  204. if len(parentIds) > 0 {
  205. cond = " AND excel_info_id in (" + utils.GetOrmInReplace(len(parentIds)) + ")"
  206. pars = make([]interface{}, 0)
  207. pars = append(pars, parentIds)
  208. parentList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars)
  209. if err != nil && err.Error() != utils.ErrNoRow() {
  210. br.Msg = "获取失败"
  211. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  212. return
  213. }
  214. for _, v := range parentList {
  215. excelParentName[v.ExcelInfoId] = v.ExcelName
  216. }
  217. }
  218. for _, v := range tableList {
  219. name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_TABLE, v.ExcelInfoId)
  220. if v.ParentId > 0 {
  221. parentName := excelParentName[v.ParentId]
  222. objectNameMap[name] = fmt.Sprintf("%s_%s", parentName, v.ExcelName)
  223. } else {
  224. objectNameMap[name] = v.ExcelName
  225. }
  226. }
  227. }
  228. // 查询预测指标名称
  229. if len(predictEdbIds) > 0 {
  230. predictList, err := data_manage.GetEdbInfoByIdList(predictEdbIds)
  231. if err != nil && err.Error() != utils.ErrNoRow() {
  232. br.Msg = "获取失败"
  233. br.ErrMsg = "获取预测指标信息失败,Err:" + err.Error()
  234. return
  235. }
  236. for _, v := range predictList {
  237. name := fmt.Sprintf("%d_%d", utils.EDB_RELATION_PREDICT_EDB, v.EdbInfoId)
  238. objectNameMap[name] = v.EdbName
  239. }
  240. }
  241. for _, v := range relationList {
  242. name := fmt.Sprintf("%d_%d", v.ReferObjectType, v.ReferObjectId)
  243. referObjectName, _ := objectNameMap[name]
  244. tmp := &data_manage.EdbInfoRelationDetail{
  245. EdbInfoRelationId: v.EdbInfoRelationId,
  246. EdbInfoId: v.EdbInfoId,
  247. ReferObjectId: v.ReferObjectId,
  248. ReferObjectType: v.ReferObjectType,
  249. ReferObjectSubType: v.ReferObjectSubType,
  250. RelationTime: v.RelationTime.Format(utils.FormatDateTime),
  251. ReferObjectName: referObjectName,
  252. }
  253. switch v.ReferObjectType {
  254. case utils.EDB_RELATION_SANDBOX:
  255. tmp.ReferObjectTypeName = "逻辑图"
  256. case utils.EDB_RELATION_CALENDAR:
  257. tmp.ReferObjectTypeName = "事件日历"
  258. case utils.EDB_RELATION_CHART:
  259. switch v.ReferObjectSubType {
  260. case utils.CHART_SOURCE_DEFAULT:
  261. tmp.ReferObjectTypeName = "图库"
  262. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  263. tmp.ReferObjectTypeName = "相关性分析"
  264. case utils.CHART_SOURCE_LINE_EQUATION:
  265. tmp.ReferObjectTypeName = "拟合方程曲线"
  266. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  267. tmp.ReferObjectTypeName = "统计特征"
  268. case utils.CHART_SOURCE_CROSS_HEDGING:
  269. tmp.ReferObjectTypeName = "跨品种分析"
  270. case utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  271. tmp.ReferObjectTypeName = "商品价格曲线"
  272. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  273. tmp.ReferObjectTypeName = "区间分析"
  274. }
  275. case utils.EDB_RELATION_TABLE:
  276. switch v.ReferObjectSubType {
  277. case utils.TIME_TABLE:
  278. tmp.ReferObjectTypeName = "时间序列表格"
  279. case utils.MIXED_TABLE:
  280. tmp.ReferObjectTypeName = "混合表格"
  281. case utils.BALANCE_TABLE:
  282. tmp.ReferObjectTypeName = "平衡表"
  283. }
  284. case utils.EDB_RELATION_PREDICT_EDB:
  285. tmp.ReferObjectTypeName = "预测指标"
  286. }
  287. list = append(list, tmp)
  288. }
  289. page := paging.GetPaging(currentIndex, pageSize, total)
  290. resp := data_manage.BaseRelationEdbInfoDetailResp{
  291. Paging: page,
  292. List: list,
  293. }
  294. br.Ret = 200
  295. br.Success = true
  296. br.Msg = "获取成功"
  297. br.Data = resp
  298. }