edb_info_relation.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. for _, v := range relationList {
  127. switch v.ReferObjectType {
  128. case utils.EDB_RELATION_SANDBOX:
  129. sandboxIds = append(sandboxIds, v.ReferObjectId)
  130. case utils.EDB_RELATION_CALENDAR:
  131. eventInfoIds = append(eventInfoIds, v.ReferObjectId)
  132. case utils.EDB_RELATION_CHART:
  133. chartInfoIds = append(chartInfoIds, v.ReferObjectId)
  134. case utils.EDB_RELATION_TABLE:
  135. tableInfoIds = append(tableInfoIds, v.ReferObjectId)
  136. }
  137. }
  138. objectNameMap := make(map[int]string)
  139. if len(sandboxIds) > 0 {
  140. sandboxList, err := sandbox.GetSandboxNameByIds(sandboxIds)
  141. if err != nil && err.Error() != utils.ErrNoRow() {
  142. br.Msg = "获取失败"
  143. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  144. return
  145. }
  146. for _, v := range sandboxList {
  147. objectNameMap[v.SandboxId] = v.Name
  148. }
  149. }
  150. // 查询事件日历
  151. if len(eventInfoIds) > 0 {
  152. matterOb := new(fe_calendar.FeCalendarMatter)
  153. cond := " AND fe_calendar_matter_id in (" + utils.GetOrmInReplace(len(eventInfoIds)) + ")"
  154. pars := make([]interface{}, 0)
  155. pars = append(pars, eventInfoIds)
  156. eventList, err := matterOb.GetItemsByCondition(cond, pars, []string{}, "")
  157. if err != nil && err.Error() != utils.ErrNoRow() {
  158. br.Msg = "获取失败"
  159. br.ErrMsg = "获取事件日历数据失败,Err:" + err.Error()
  160. return
  161. }
  162. for _, v := range eventList {
  163. objectNameMap[v.FeCalendarMatterId] = fmt.Sprintf("%s, %s", v.MatterDate, v.ChartPermissionName)
  164. }
  165. }
  166. // 查询图表
  167. if len(chartInfoIds) > 0 {
  168. chartList, err := data_manage.GetChartInfoByIdList(chartInfoIds)
  169. if err != nil && err.Error() != utils.ErrNoRow() {
  170. br.Msg = "获取失败"
  171. br.ErrMsg = "获取图表数据失败,Err:" + err.Error()
  172. return
  173. }
  174. for _, v := range chartList {
  175. objectNameMap[v.ChartInfoId] = v.ChartName
  176. }
  177. }
  178. // 查询表格名称
  179. if len(tableInfoIds) > 0 {
  180. cond := " AND excel_info_id in (" + utils.GetOrmInReplace(len(tableInfoIds)) + ")"
  181. pars := make([]interface{}, 0)
  182. pars = append(pars, tableInfoIds)
  183. tableList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars)
  184. if err != nil && err.Error() != utils.ErrNoRow() {
  185. br.Msg = "获取失败"
  186. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  187. return
  188. }
  189. // 查询父级名称
  190. excelParentName := make(map[int]string)
  191. parentIds := make([]int, 0)
  192. for _, v := range tableList {
  193. if v.ParentId > 0 {
  194. parentIds = append(parentIds, v.ParentId)
  195. }
  196. }
  197. if len(parentIds) > 0 {
  198. cond = " AND excel_info_id in (" + utils.GetOrmInReplace(len(parentIds)) + ")"
  199. pars = make([]interface{}, 0)
  200. pars = append(pars, parentIds)
  201. parentList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars)
  202. if err != nil && err.Error() != utils.ErrNoRow() {
  203. br.Msg = "获取失败"
  204. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  205. return
  206. }
  207. for _, v := range parentList {
  208. excelParentName[v.ExcelInfoId] = v.ExcelName
  209. }
  210. }
  211. for _, v := range tableList {
  212. if v.ParentId > 0 {
  213. parentName := excelParentName[v.ParentId]
  214. objectNameMap[v.ExcelInfoId] = fmt.Sprintf("%s_%s", parentName, v.ExcelName)
  215. } else {
  216. objectNameMap[v.ExcelInfoId] = v.ExcelName
  217. }
  218. }
  219. }
  220. for _, v := range relationList {
  221. referObjectName, _ := objectNameMap[v.ReferObjectId]
  222. tmp := &data_manage.EdbInfoRelationDetail{
  223. EdbInfoRelationId: v.EdbInfoRelationId,
  224. EdbInfoId: v.EdbInfoId,
  225. ReferObjectId: v.ReferObjectId,
  226. ReferObjectType: v.ReferObjectType,
  227. ReferObjectSubType: v.ReferObjectSubType,
  228. RelationTime: v.RelationTime.Format(utils.FormatDateTime),
  229. ReferObjectName: referObjectName,
  230. }
  231. switch v.ReferObjectType {
  232. case utils.EDB_RELATION_SANDBOX:
  233. tmp.ReferObjectTypeName = "逻辑图"
  234. case utils.EDB_RELATION_CALENDAR:
  235. tmp.ReferObjectTypeName = "事件日历"
  236. case utils.EDB_RELATION_CHART:
  237. switch v.ReferObjectSubType {
  238. case utils.CHART_SOURCE_DEFAULT:
  239. tmp.ReferObjectTypeName = "图库"
  240. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  241. tmp.ReferObjectTypeName = "相关性分析"
  242. case utils.CHART_SOURCE_LINE_EQUATION:
  243. tmp.ReferObjectTypeName = "拟合方程曲线"
  244. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  245. tmp.ReferObjectTypeName = "统计特征"
  246. case utils.CHART_SOURCE_CROSS_HEDGING:
  247. tmp.ReferObjectTypeName = "跨品种分析"
  248. case utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  249. tmp.ReferObjectTypeName = "商品价格曲线"
  250. }
  251. case utils.EDB_RELATION_TABLE:
  252. switch v.ReferObjectSubType {
  253. case utils.TIME_TABLE:
  254. tmp.ReferObjectTypeName = "时间序列表格"
  255. case utils.MIXED_TABLE:
  256. tmp.ReferObjectTypeName = "混合表格"
  257. case utils.BALANCE_TABLE:
  258. tmp.ReferObjectTypeName = "平衡表"
  259. }
  260. }
  261. list = append(list, tmp)
  262. }
  263. page := paging.GetPaging(currentIndex, pageSize, total)
  264. resp := data_manage.BaseRelationEdbInfoDetailResp{
  265. Paging: page,
  266. List: list,
  267. }
  268. br.Ret = 200
  269. br.Success = true
  270. br.Msg = "获取成功"
  271. br.Data = resp
  272. }