crm.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package xiangyu
  2. import (
  3. "eta/eta_bridge/global"
  4. "eta/eta_bridge/models/index"
  5. "eta/eta_bridge/services/xiangyu"
  6. "eta/eta_bridge/utils"
  7. "fmt"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strings"
  10. "time"
  11. )
  12. // PostGetIndexData
  13. // @Description: 获取数据
  14. // @author: Roc
  15. // @datetime 2024-05-14 17:23:39
  16. // @param data xiangyu.PostGetIndexDataParamReq
  17. // @return dataResp xiangyu.CrmDataResp
  18. // @return err error
  19. // @return errMsg string
  20. func PostGetIndexData(data xiangyu.PostGetIndexDataParamReq) (dataResp index.GetBusinessDataResp, err error, errMsg string) {
  21. errMsgList := make([]string, 0)
  22. defer func() {
  23. if len(errMsgList) > 0 {
  24. tips := "PostGetIndexData-获取CRM数据失败, ErrMsg:\n" + strings.Join(errMsgList, "\n")
  25. global.FILE_LOG.Error(tips)
  26. }
  27. }()
  28. dataResp = index.GetBusinessDataResp{
  29. List: make([]index.PushBusinessIndex, 0),
  30. }
  31. errMsg = `获取失败`
  32. resp, err := xiangyu.PostGetCrmData(data)
  33. if err != nil {
  34. return
  35. }
  36. dataResp.Paging = paging.GetPaging(resp.PageNum, resp.PageSize, resp.TotalNum)
  37. // 列表数据
  38. businessIndexMap := make(map[string]index.PushBusinessIndex)
  39. //index.PushBusinessIndex
  40. for _, v := range resp.Rows {
  41. tmpDate, tmpErr := time.ParseInLocation(utils.FormatDateUnSpace, v.DataDt, time.Local)
  42. if tmpErr != nil {
  43. errMsgList = append(errMsgList, fmt.Sprintf("指标日期转换失败,指标编码:%s;日期:%s", v.AssetCd, v.DataDt))
  44. continue
  45. }
  46. frequency := handleXyFrequency(v.FrequencyName)
  47. if frequency == `` {
  48. errMsgList = append(errMsgList, fmt.Sprintf("指标频度异常,指标编码:%s;日期:%s", v.AssetCd, v.FrequencyName))
  49. continue
  50. }
  51. businessIndex, ok := businessIndexMap[v.AssetCd]
  52. //
  53. if !ok {
  54. dataList := make([]index.AddBusinessData, 0)
  55. businessIndex = index.PushBusinessIndex{
  56. IndexCode: v.AssetCd,
  57. IndexName: v.AssetName,
  58. Unit: v.UnitName,
  59. Frequency: frequency,
  60. SourceName: v.DataSourceType,
  61. Remark: "",
  62. DetailDataCreateTime: v.DetailDataStockInTime,
  63. DataList: dataList,
  64. }
  65. }
  66. businessIndex.DataList = append(businessIndex.DataList, index.AddBusinessData{
  67. Value: v.Price,
  68. Date: tmpDate.Format(utils.FormatDate),
  69. })
  70. businessIndexMap[v.AssetCd] = businessIndex
  71. }
  72. // 将处理后的指标返回
  73. for _, v := range businessIndexMap {
  74. dataResp.List = append(dataResp.List, v)
  75. }
  76. return
  77. }
  78. // handleXyFrequency
  79. // @Description: 处理象屿频度问题
  80. // @author: Roc
  81. // @datetime 2024-05-14 18:15:28
  82. // @param frequencyName string
  83. // @return frequency string
  84. func handleXyFrequency(frequencyName string) (frequency string) {
  85. switch frequencyName {
  86. case "季度", "半年度", "年度", "日度", "周度", "旬度", "月度 ":
  87. frequency = frequencyName
  88. case "每天", "每交易日":
  89. frequency = "日度"
  90. }
  91. return
  92. }