base_from_ths_hf.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package data
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/utils"
  7. "fmt"
  8. )
  9. // CheckExistThsHfEdb 校验已存在的同花顺高频指标
  10. func CheckExistThsHfEdb(stockCodes, edbCodes []string) (checkResp data_manage.ThsHfExistCheckResp, existMap map[string]bool, err error) {
  11. // 待校验的指标编码
  12. var indexCode []string
  13. prefix := utils.ThsHf
  14. for _, sv := range stockCodes {
  15. for _, ev := range edbCodes {
  16. t := fmt.Sprintf("%s%s%s", prefix, sv, ev)
  17. indexCode = append(indexCode, t)
  18. }
  19. }
  20. baseIndexes := make([]*data_manage.BaseFromThsHfIndex, 0)
  21. {
  22. ob := new(data_manage.BaseFromThsHfIndex)
  23. fields := []string{ob.Cols().PrimaryId, ob.Cols().IndexCode, ob.Cols().IndexName, ob.Cols().StockCode, ob.Cols().Indicator}
  24. list, e := ob.GetItemsByCondition(``, make([]interface{}, 0), fields, "")
  25. if e != nil {
  26. err = fmt.Errorf("获取高频指标列表失败, %v", e)
  27. return
  28. }
  29. baseIndexes = list
  30. }
  31. var existNum int
  32. existMap = make(map[string]bool)
  33. for _, bv := range baseIndexes {
  34. code := fmt.Sprintf("%s%s%s", prefix, bv.StockCode, bv.Indicator)
  35. for _, iv := range indexCode {
  36. if code != iv {
  37. continue
  38. }
  39. existMap[fmt.Sprintf("%s-%s", bv.StockCode, bv.Indicator)] = true
  40. existNum += 1
  41. checkResp.ExistIndex = append(checkResp.ExistIndex, data_manage.ThsHfExistCheckIndex{
  42. IndexId: bv.BaseFromThsHfIndexId,
  43. IndexCode: bv.IndexCode,
  44. IndexName: bv.IndexName,
  45. })
  46. break
  47. }
  48. }
  49. if existNum > 0 && existNum == len(indexCode) {
  50. checkResp.ExistAll = true
  51. }
  52. return
  53. }
  54. // GetEdbDataThsHf 获取同花顺高频数据指标
  55. func GetEdbDataThsHf(req data_manage.ThsHfSearchEdbReq) (indexes []*data_manage.ThsHfIndexWithData, err error) {
  56. param := make(map[string]interface{})
  57. param["StockCode"] = req.StockCode
  58. param["EdbCode"] = req.EdbCode
  59. param["StartTime"] = req.StartTime
  60. param["EndTime"] = req.EndTime
  61. param["Interval"] = req.Interval
  62. param["Fill"] = req.Fill
  63. param["CPS"] = req.CPS
  64. param["BaseDate"] = req.BaseDate
  65. uri := `ths/hf/edb_data`
  66. resp, e := postThsHfEdbData(param, uri)
  67. if e != nil {
  68. err = fmt.Errorf("postThsHfEdbData, %v", e)
  69. return
  70. }
  71. if resp.Ret == 200 {
  72. indexes = resp.Data
  73. }
  74. return
  75. }
  76. // postThsHfEdbData 刷新指标数据
  77. func postThsHfEdbData(param map[string]interface{}, urlStr string) (resp *data_manage.ThsHfIndexDataLibResp, err error) {
  78. postUrl := utils.EDB_LIB_URL + urlStr
  79. postData, err := json.Marshal(param)
  80. if err != nil {
  81. return
  82. }
  83. result, err := HttpPost(postUrl, string(postData), utils.ZhLangVersion, "application/json")
  84. if err != nil {
  85. return
  86. }
  87. utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  88. err = json.Unmarshal(result, &resp)
  89. if err != nil {
  90. return
  91. }
  92. return resp, nil
  93. }
  94. // BaseAddThsHf 新增数据源
  95. func BaseAddThsHf(req data_manage.ThsHfBaseAddReq) (resp *models.BaseResponse, err error) {
  96. param := make(map[string]interface{})
  97. param["StartTime"] = req.StartTime
  98. param["EndTime"] = req.EndTime
  99. param["Interval"] = req.Interval
  100. param["Fill"] = req.Fill
  101. param["CPS"] = req.CPS
  102. param["BaseDate"] = req.BaseDate
  103. param["SysAdminId"] = req.SysAdminId
  104. param["SysAdminName"] = req.SysAdminName
  105. param["ClassifyId"] = req.ClassifyId
  106. param["Unit"] = req.Unit
  107. param["IndexName"] = req.IndexName
  108. param["Frequency"] = req.Frequency
  109. param["StockCode"] = req.StockCode
  110. param["EdbCode"] = req.EdbCode
  111. uri := `ths/hf/base/add`
  112. res, e := postRefreshEdbData(param, uri)
  113. if e != nil {
  114. err = fmt.Errorf("postRefreshEdbData, %v", e)
  115. return
  116. }
  117. resp = res
  118. return
  119. }