diff --git a/app/task/svc/svc_egg_energy_auto_record_price.go b/app/task/svc/svc_egg_energy_auto_record_price.go index 10e7a98..e1bdfb4 100644 --- a/app/task/svc/svc_egg_energy_auto_record_price.go +++ b/app/task/svc/svc_egg_energy_auto_record_price.go @@ -28,7 +28,7 @@ func EggEnergyAutoRecordPrices(engine *xorm.Engine) { // 1. 获取最后一条记录 priceDb := implement.NewEggEnergyPriceDb(engine) - lastPrice, has, err := priceDb.EggEnergyPriceGetLastOne() + lastPrice, err := priceDb.EggEnergyPriceGetOneByParams(dateNowStr, now.Hour()) if err != nil { fmt.Println("EggEnergyAutoRecordPrices_ERR:::::", err.Error()) return @@ -45,27 +45,25 @@ func EggEnergyAutoRecordPrices(engine *xorm.Engine) { defer cb() // 释放锁 } - if has { + if lastPrice.Date == dateNowStr && lastPrice.Hour == hourNowStr { // 3. 当前时间已经有记录 更新价格 - if lastPrice.Date == dateNowStr && lastPrice.Hour == hourNowStr { - lastPrice.Price = eggEnergyCoreData.NowPrice - _, err2 := priceDb.EggEnergyPriceUpdate(lastPrice) - if err2 != nil { - fmt.Println("SaveEggEnergyPrice_ERR:::::", err2.Error()) - return - } - } else { - // 4. 保存当前价格 - priceData := model.EggEnergyPrice{ - Price: eggEnergyCoreData.NowPrice, - Date: dateNowStr, - Hour: hourNowStr, - } - _, err2 := priceDb.EggEnergyPriceInsert(&priceData) - if err2 != nil { - fmt.Println("SaveEggEnergyPrice_ERR:::::", err2.Error()) - return - } + lastPrice.Price = eggEnergyCoreData.NowPrice + _, err2 := priceDb.EggEnergyPriceUpdate(lastPrice) + if err2 != nil { + fmt.Println("SaveEggEnergyPrice_ERR:::::", err2.Error()) + return + } + } else { + // 4. 当前时间还没有记录 保存当前价格 + priceData := model.EggEnergyPrice{ + Price: eggEnergyCoreData.NowPrice, + Date: dateNowStr, + Hour: hourNowStr, + } + _, err2 := priceDb.EggEnergyPriceInsert(&priceData) + if err2 != nil { + fmt.Println("SaveEggEnergyPrice_ERR:::::", err2.Error()) + return } } return