package xiangyu import ( "eta/eta_bridge/global" "eta/eta_bridge/models/index" "eta/eta_bridge/services/xiangyu" "eta/eta_bridge/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "strings" "time" ) // PostGetIndexData // @Description: 获取数据 // @author: Roc // @datetime 2024-05-14 17:23:39 // @param data xiangyu.PostGetIndexDataParamReq // @return dataResp xiangyu.CrmDataResp // @return err error // @return errMsg string func PostGetIndexData(data xiangyu.PostGetIndexDataParamReq) (dataResp index.GetBusinessDataResp, err error, errMsg string) { errMsgList := make([]string, 0) defer func() { if len(errMsgList) > 0 { tips := "PostGetIndexData-获取CRM数据失败, ErrMsg:\n" + strings.Join(errMsgList, "\n") global.FILE_LOG.Error(tips) } }() dataResp = index.GetBusinessDataResp{ List: make([]index.PushBusinessIndex, 0), } errMsg = `获取失败` resp, err := xiangyu.PostGetCrmData(data) if err != nil { return } dataResp.Paging = paging.GetPaging(resp.PageNum, resp.PageSize, resp.TotalNum) // 列表数据 businessIndexMap := make(map[string]index.PushBusinessIndex) //index.PushBusinessIndex for _, v := range resp.Rows { tmpDate, tmpErr := time.ParseInLocation(utils.FormatDateUnSpace, v.DataDt, time.Local) if tmpErr != nil { errMsgList = append(errMsgList, fmt.Sprintf("指标日期转换失败,指标编码:%s;日期:%s", v.AssetCd, v.DataDt)) continue } frequency := handleXyFrequency(v.FrequencyName) if frequency == `` { errMsgList = append(errMsgList, fmt.Sprintf("指标频度异常,指标编码:%s;日期:%s", v.AssetCd, v.FrequencyName)) continue } businessIndex, ok := businessIndexMap[v.AssetCd] // if !ok { dataList := make([]index.AddBusinessData, 0) businessIndex = index.PushBusinessIndex{ IndexCode: v.AssetCd, IndexName: v.AssetName, Unit: v.UnitName, Frequency: frequency, SourceName: v.DataSourceType, Remark: "", DetailDataCreateTime: v.DetailDataStockInTime, DataList: dataList, } } businessIndex.DataList = append(businessIndex.DataList, index.AddBusinessData{ Value: v.Price, Date: tmpDate.Format(utils.FormatDate), }) businessIndexMap[v.AssetCd] = businessIndex } // 将处理后的指标返回 for _, v := range businessIndexMap { dataResp.List = append(dataResp.List, v) } return } // handleXyFrequency // @Description: 处理象屿频度问题 // @author: Roc // @datetime 2024-05-14 18:15:28 // @param frequencyName string // @return frequency string func handleXyFrequency(frequencyName string) (frequency string) { switch frequencyName { case "季度", "半年度", "年度", "日度", "周度", "旬度", "月度 ": frequency = frequencyName case "每天", "每交易日": frequency = "日度" } return }