Browse Source

update

master
shenjiachi 2 days ago
parent
commit
68116a19c0
1 changed files with 19 additions and 21 deletions
  1. +19
    -21
      app/task/svc/svc_egg_energy_auto_record_price.go

+ 19
- 21
app/task/svc/svc_egg_energy_auto_record_price.go View File

@@ -28,7 +28,7 @@ func EggEnergyAutoRecordPrices(engine *xorm.Engine) {


// 1. 获取最后一条记录 // 1. 获取最后一条记录
priceDb := implement.NewEggEnergyPriceDb(engine) priceDb := implement.NewEggEnergyPriceDb(engine)
lastPrice, has, err := priceDb.EggEnergyPriceGetLastOne()
lastPrice, err := priceDb.EggEnergyPriceGetOneByParams(dateNowStr, now.Hour())
if err != nil { if err != nil {
fmt.Println("EggEnergyAutoRecordPrices_ERR:::::", err.Error()) fmt.Println("EggEnergyAutoRecordPrices_ERR:::::", err.Error())
return return
@@ -45,27 +45,25 @@ func EggEnergyAutoRecordPrices(engine *xorm.Engine) {
defer cb() // 释放锁 defer cb() // 释放锁
} }


if has {
if lastPrice.Date == dateNowStr && lastPrice.Hour == hourNowStr {
// 3. 当前时间已经有记录 更新价格 // 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 return


Loading…
Cancel
Save