edb_info_relation.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/controllers"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/data_manage"
  6. "eta_gn/eta_api/models/data_manage/excel"
  7. "eta_gn/eta_api/models/fe_calendar"
  8. "eta_gn/eta_api/models/sandbox"
  9. "eta_gn/eta_api/services/data"
  10. "eta_gn/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. type EdbInfoRelationController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @router /edb_info/relation/edb_list [get]
  18. func (c *EdbInfoRelationController) RelationEdbList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. c.Data["json"] = br
  22. c.ServeJSON()
  23. }()
  24. source, _ := c.GetInt("Source")
  25. classifyId := c.GetString("ClassifyId")
  26. sysUserId := c.GetString("SysUserId")
  27. frequency := c.GetString("Frequency")
  28. keyword := c.GetString("Keyword")
  29. status := c.GetString("Status")
  30. sortParam := c.GetString("SortParam")
  31. sortType := c.GetString("SortType")
  32. switch sortParam {
  33. case "RelationTime":
  34. sortParam = " r.relation_time "
  35. case "RelationNum":
  36. sortParam = " r.relation_num "
  37. default:
  38. sortParam = " r.relation_time "
  39. }
  40. switch sortType {
  41. case "desc", "asc":
  42. default:
  43. sortType = "desc"
  44. }
  45. pageSize, _ := c.GetInt("PageSize")
  46. currentIndex, _ := c.GetInt("CurrentIndex")
  47. var startSize int
  48. if pageSize <= 0 {
  49. pageSize = utils.PageSize20
  50. }
  51. if currentIndex <= 0 {
  52. currentIndex = 1
  53. }
  54. edbType := 1 //基础指标
  55. if source == -1 { //计算指标
  56. edbType = 2
  57. source = 0
  58. }
  59. startSize = utils.StartIndex(currentIndex, pageSize)
  60. total, list, err := data.GetEdbRelationList(source, edbType, classifyId, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
  61. if err != nil && !utils.IsErrNoRow(err) {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  64. return
  65. }
  66. page := paging.GetPaging(currentIndex, pageSize, total)
  67. resp := data_manage.BaseRelationEdbInfoResp{
  68. Paging: page,
  69. List: list,
  70. }
  71. br.Ret = 200
  72. br.Success = true
  73. br.Msg = "获取成功"
  74. br.Data = resp
  75. }
  76. // @router /edb_info/relation/detail [get]
  77. func (c *EdbInfoRelationController) RelationEdbListDetail() {
  78. br := new(models.BaseResponse).Init()
  79. defer func() {
  80. c.Data["json"] = br
  81. c.ServeJSON()
  82. }()
  83. edbInfoId, _ := c.GetInt("EdbInfoId")
  84. pageSize, _ := c.GetInt("PageSize")
  85. currentIndex, _ := c.GetInt("CurrentIndex")
  86. var startSize int
  87. if pageSize <= 0 {
  88. pageSize = utils.PageSize20
  89. }
  90. if currentIndex <= 0 {
  91. currentIndex = 1
  92. }
  93. startSize = utils.StartIndex(currentIndex, pageSize)
  94. total, relationList, err := data_manage.GetEdbInfoRelationDetailList(edbInfoId, startSize, pageSize)
  95. if err != nil && !utils.IsErrNoRow(err) {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  98. return
  99. }
  100. list := make([]*data_manage.EdbInfoRelationDetail, 0)
  101. sandboxIds := make([]int, 0)
  102. chartInfoIds := make([]int, 0)
  103. tableInfoIds := make([]int, 0)
  104. eventInfoIds := make([]int, 0)
  105. for _, v := range relationList {
  106. switch v.ReferObjectType {
  107. case utils.EDB_RELATION_SANDBOX:
  108. sandboxIds = append(sandboxIds, v.ReferObjectId)
  109. case utils.EDB_RELATION_CALENDAR:
  110. eventInfoIds = append(eventInfoIds, v.ReferObjectId)
  111. case utils.EDB_RELATION_CHART:
  112. chartInfoIds = append(chartInfoIds, v.ReferObjectId)
  113. case utils.EDB_RELATION_TABLE:
  114. tableInfoIds = append(tableInfoIds, v.ReferObjectId)
  115. }
  116. }
  117. objectNameMap := make(map[int]string)
  118. if len(sandboxIds) > 0 {
  119. sandboxList, err := sandbox.GetSandboxNameByIds(sandboxIds)
  120. if err != nil && !utils.IsErrNoRow(err) {
  121. br.Msg = "获取失败"
  122. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  123. return
  124. }
  125. for _, v := range sandboxList {
  126. objectNameMap[v.SandboxId] = v.Name
  127. }
  128. }
  129. if len(eventInfoIds) > 0 {
  130. matterOb := new(fe_calendar.FeCalendarMatter)
  131. cond := " AND fe_calendar_matter_id in (" + utils.GetOrmInReplace(len(eventInfoIds)) + ")"
  132. pars := make([]interface{}, 0)
  133. pars = append(pars, eventInfoIds)
  134. eventList, err := matterOb.GetItemsByCondition(cond, pars, []string{}, "")
  135. if err != nil && !utils.IsErrNoRow(err) {
  136. br.Msg = "获取失败"
  137. br.ErrMsg = "获取事件日历数据失败,Err:" + err.Error()
  138. return
  139. }
  140. for _, v := range eventList {
  141. objectNameMap[v.FeCalendarMatterId] = fmt.Sprintf("%s, %s", v.MatterDate, v.ChartPermissionName)
  142. }
  143. }
  144. if len(chartInfoIds) > 0 {
  145. chartList, err := data_manage.GetChartInfoByIdList(chartInfoIds)
  146. if err != nil && !utils.IsErrNoRow(err) {
  147. br.Msg = "获取失败"
  148. br.ErrMsg = "获取图表数据失败,Err:" + err.Error()
  149. return
  150. }
  151. for _, v := range chartList {
  152. objectNameMap[v.ChartInfoId] = v.ChartName
  153. }
  154. }
  155. if len(tableInfoIds) > 0 {
  156. cond := " AND excel_info_id in (" + utils.GetOrmInReplace(len(tableInfoIds)) + ")"
  157. pars := make([]interface{}, 0)
  158. pars = append(pars, tableInfoIds)
  159. tableList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars)
  160. if err != nil && !utils.IsErrNoRow(err) {
  161. br.Msg = "获取失败"
  162. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  163. return
  164. }
  165. excelParentName := make(map[int]string)
  166. parentIds := make([]int, 0)
  167. for _, v := range tableList {
  168. if v.ParentId > 0 {
  169. parentIds = append(parentIds, v.ParentId)
  170. }
  171. }
  172. if len(parentIds) > 0 {
  173. cond = " AND excel_info_id in (" + utils.GetOrmInReplace(len(parentIds)) + ")"
  174. pars = make([]interface{}, 0)
  175. pars = append(pars, parentIds)
  176. parentList, err := excel.GetNoContentExcelInfoListByConditionNoPage(cond, pars)
  177. if err != nil && !utils.IsErrNoRow(err) {
  178. br.Msg = "获取失败"
  179. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  180. return
  181. }
  182. for _, v := range parentList {
  183. excelParentName[v.ExcelInfoId] = v.ExcelName
  184. }
  185. }
  186. for _, v := range tableList {
  187. if v.ParentId > 0 {
  188. parentName := excelParentName[v.ParentId]
  189. objectNameMap[v.ExcelInfoId] = fmt.Sprintf("%s_%s", parentName, v.ExcelName)
  190. } else {
  191. objectNameMap[v.ExcelInfoId] = v.ExcelName
  192. }
  193. }
  194. }
  195. for _, v := range relationList {
  196. referObjectName, _ := objectNameMap[v.ReferObjectId]
  197. tmp := &data_manage.EdbInfoRelationDetail{
  198. EdbInfoRelationId: v.EdbInfoRelationId,
  199. EdbInfoId: v.EdbInfoId,
  200. ReferObjectId: v.ReferObjectId,
  201. ReferObjectType: v.ReferObjectType,
  202. ReferObjectSubType: v.ReferObjectSubType,
  203. RelationTime: v.RelationTime.Format(utils.FormatDateTime),
  204. ReferObjectName: referObjectName,
  205. }
  206. switch v.ReferObjectType {
  207. case utils.EDB_RELATION_SANDBOX:
  208. tmp.ReferObjectTypeName = "逻辑图"
  209. case utils.EDB_RELATION_CALENDAR:
  210. tmp.ReferObjectTypeName = "事件日历"
  211. case utils.EDB_RELATION_CHART:
  212. switch v.ReferObjectSubType {
  213. case utils.CHART_SOURCE_DEFAULT:
  214. tmp.ReferObjectTypeName = "图库"
  215. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  216. tmp.ReferObjectTypeName = "相关性分析"
  217. case utils.CHART_SOURCE_LINE_EQUATION:
  218. tmp.ReferObjectTypeName = "拟合方程曲线"
  219. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  220. tmp.ReferObjectTypeName = "统计特征"
  221. case utils.CHART_SOURCE_CROSS_HEDGING:
  222. tmp.ReferObjectTypeName = "跨品种分析"
  223. case utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  224. tmp.ReferObjectTypeName = "商品价格曲线"
  225. }
  226. case utils.EDB_RELATION_TABLE:
  227. switch v.ReferObjectSubType {
  228. case utils.TIME_TABLE:
  229. tmp.ReferObjectTypeName = "时间序列表格"
  230. case utils.MIXED_TABLE:
  231. tmp.ReferObjectTypeName = "混合表格"
  232. case utils.BALANCE_TABLE:
  233. tmp.ReferObjectTypeName = "平衡表"
  234. }
  235. }
  236. list = append(list, tmp)
  237. }
  238. page := paging.GetPaging(currentIndex, pageSize, total)
  239. resp := data_manage.BaseRelationEdbInfoDetailResp{
  240. Paging: page,
  241. List: list,
  242. }
  243. br.Ret = 200
  244. br.Success = true
  245. br.Msg = "获取成功"
  246. br.Data = resp
  247. }