|
@@ -209,21 +209,35 @@ func HandleApiIndex(indexCodes []string) (errMsg string, err error) {
|
|
|
|
|
|
func tranformData(dataResp *models.MySteelChemicalApiResp) (items [][]*models.BaseFromMysteelChemicalData, err error) {
|
|
|
for _, v := range dataResp.Data {
|
|
|
+ tmpNewDataMap := make(map[string]int64)
|
|
|
+ tmpDateDataMap := make(map[string]*models.BaseFromMysteelChemicalData)
|
|
|
tmpDataItems := make([]*models.BaseFromMysteelChemicalData, 0)
|
|
|
for _, vv := range v.DataList {
|
|
|
tmpData := new(models.BaseFromMysteelChemicalData)
|
|
|
tmpData.IndexCode = vv.IndexCode
|
|
|
+ // 如果存在多条数据,则取发布时间最新的数据
|
|
|
+ pub, ok := tmpNewDataMap[vv.DataDate]
|
|
|
+ if !ok {
|
|
|
+ tmpNewDataMap[vv.DataDate] = vv.PublishTime
|
|
|
+ tmpData.Value = strconv.FormatFloat(vv.DataValue, 'f', -1, 64)
|
|
|
+ } else {
|
|
|
+ if pub < vv.PublishTime {
|
|
|
+ tmpNewDataMap[vv.DataDate] = vv.PublishTime
|
|
|
+ tmpData = tmpDateDataMap[vv.DataDate]
|
|
|
+ tmpData.Value = strconv.FormatFloat(vv.DataValue, 'f', -1, 64)
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
dataDate, er := time.Parse(utils.FormatDate, vv.DataDate)
|
|
|
if er != nil {
|
|
|
err = er
|
|
|
return
|
|
|
}
|
|
|
tmpData.DataTime = dataDate
|
|
|
- // vv.DataValue 保留两位小数
|
|
|
- tmpData.Value = strconv.FormatFloat(vv.DataValue, 'f', -1, 64)
|
|
|
tmpData.CreateTime = time.Now()
|
|
|
tmpData.ModifyTime = time.Now()
|
|
|
tmpDataItems = append(tmpDataItems, tmpData)
|
|
|
+ tmpDateDataMap[vv.DataDate] = tmpData
|
|
|
}
|
|
|
items = append(items, tmpDataItems)
|
|
|
}
|