From fa8d86fd28741c05c2743ab5a4c1097989b1d93c Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Fri, 15 Nov 2024 10:40:02 +0800 Subject: [PATCH] add save price --- src/dao/egg_energy_price_dao.go | 1 + src/implement/egg_energy_price_implement.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dao/egg_energy_price_dao.go b/src/dao/egg_energy_price_dao.go index 84c5f1b..8663f27 100644 --- a/src/dao/egg_energy_price_dao.go +++ b/src/dao/egg_energy_price_dao.go @@ -6,4 +6,5 @@ type EggEnergyPriceDao interface { //TODO:: You can add specific method definitions here EggEnergyPriceList(startAt string, endAt string, hour string) ([]model.EggEnergyPrice, error) EggEnergyPriceGetLastOne() (*model.EggEnergyPrice, bool, error) + EggEnergyPriceInsert(eggEnergyPrice *model.EggEnergyPrice) (int64, error) } diff --git a/src/implement/egg_energy_price_implement.go b/src/implement/egg_energy_price_implement.go index cba2d42..1ee7605 100644 --- a/src/implement/egg_energy_price_implement.go +++ b/src/implement/egg_energy_price_implement.go @@ -31,9 +31,17 @@ func (e EggEnergyPriceDb) EggEnergyPriceList(startAt string, endAt string, hour func (e EggEnergyPriceDb) EggEnergyPriceGetLastOne() (*model.EggEnergyPrice, bool, error) { var m model.EggEnergyPrice - exist, err := e.Db.Desc("id").Get(&m) + exist, err := e.Db.OrderBy("date").OrderBy("hour").Get(&m) if err != nil { return nil, false, zhios_order_relate_logx.Error(err.Error()) } return &m, exist, nil } + +func (e EggEnergyPriceDb) EggEnergyPriceInsert(eggEnergyPrice *model.EggEnergyPrice) (int64, error) { + _, err := e.Db.InsertOne(eggEnergyPrice) + if err != nil { + return 0, err + } + return eggEnergyPrice.Id, nil +}