From 096006feefca5cd87c104201c011f7529c0eaf4d Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Tue, 12 Nov 2024 15:32:38 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=9F=A5=E8=AF=A2=E5=88=86=E7=BA=A2?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E3=80=81=E7=A4=BE=E5=8C=BA=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/egg_energy_community_dividends_dao.go | 1 + ...nergy_community_dividends_with_user_dao.go | 2 ++ ...gg_energy_community_dividends_implement.go | 23 +++++++++++++++++ ...community_dividends_with_user_implement.go | 25 ++++++++++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/dao/egg_energy_community_dividends_dao.go b/src/dao/egg_energy_community_dividends_dao.go index 4a9e62e..02d6d71 100644 --- a/src/dao/egg_energy_community_dividends_dao.go +++ b/src/dao/egg_energy_community_dividends_dao.go @@ -4,5 +4,6 @@ import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" type EggEnergyCommunityDividendsDao interface { //TODO:: You can add specific method definitions here + EggEnergyCommunityDividendsFindAndCount(page, limit int, startAt, endAt string, startNums, endNums int64) ([]*model.EggEnergyCommunityDividends, int64, error) EggEnergyCommunityDividendsInsert(EggEnergyCommunityDividends *model.EggEnergyCommunityDividends) (int, error) } diff --git a/src/dao/egg_energy_community_dividends_with_user_dao.go b/src/dao/egg_energy_community_dividends_with_user_dao.go index ed9a424..bdfa775 100644 --- a/src/dao/egg_energy_community_dividends_with_user_dao.go +++ b/src/dao/egg_energy_community_dividends_with_user_dao.go @@ -5,4 +5,6 @@ import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" type EggEnergyCommunityDividendsWithUserDao interface { //TODO:: You can add specific method definitions here EggEnergyCommunityDividendsWithUserInsert(EggEnergyCommunityDividendsWithUser *model.EggEnergyCommunityDividendsWithUser) (int, error) + EggEnergyCommunityDividendsWithUserFindAndCount(page, limit int, uid int64) ([]*model.EggEnergyCommunityDividendsWithUser, int64, error) + EggEnergyCommunityDividendsWithUserExist(uid int64) (bool, error) } diff --git a/src/implement/egg_energy_community_dividends_implement.go b/src/implement/egg_energy_community_dividends_implement.go index 96a254e..16be221 100644 --- a/src/implement/egg_energy_community_dividends_implement.go +++ b/src/implement/egg_energy_community_dividends_implement.go @@ -3,6 +3,7 @@ package implement import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -14,6 +15,28 @@ type EggEnergyCommunityDividendsDb struct { Db *xorm.Engine } +func (e EggEnergyCommunityDividendsDb) EggEnergyCommunityDividendsFindAndCount(page, limit int, startAt, endAt string, startNums, endNums int64) ([]*model.EggEnergyCommunityDividends, int64, error) { + var m []*model.EggEnergyCommunityDividends + session := e.Db.Where("") + if startAt != "" { + session = session.And("create_at > ?", startAt) + } + if endAt != "" { + session = session.And("create_at < ?", endAt) + } + if startNums != 0 { + session = session.And("nums > ?", startNums) + } + if endNums != 0 { + session = session.And("nums < ?", endNums) + } + total, err := session.Limit(limit, (page-1)*limit).FindAndCount(&m) + if err != nil { + return nil, 0, zhios_order_relate_logx.Error(err.Error()) + } + return m, total, nil +} + func (e EggEnergyCommunityDividendsDb) EggEnergyCommunityDividendsInsert(EggEnergyCommunityDividends *model.EggEnergyCommunityDividends) (int, error) { _, err := e.Db.InsertOne(EggEnergyCommunityDividends) if err != nil { diff --git a/src/implement/egg_energy_community_dividends_with_user_implement.go b/src/implement/egg_energy_community_dividends_with_user_implement.go index be878c8..4a4510c 100644 --- a/src/implement/egg_energy_community_dividends_with_user_implement.go +++ b/src/implement/egg_energy_community_dividends_with_user_implement.go @@ -3,6 +3,7 @@ package implement import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -17,7 +18,29 @@ type EggEnergyCommunityDividendsWithUserDb struct { func (e EggEnergyCommunityDividendsWithUserDb) EggEnergyCommunityDividendsWithUserInsert(EggEnergyCommunityDividendsWithUser *model.EggEnergyCommunityDividendsWithUser) (int, error) { _, err := e.Db.InsertOne(EggEnergyCommunityDividendsWithUser) if err != nil { - return 0, err + return 0, zhios_order_relate_logx.Error(err.Error()) } return EggEnergyCommunityDividendsWithUser.Id, nil } + +func (e EggEnergyCommunityDividendsWithUserDb) EggEnergyCommunityDividendsWithUserFindAndCount(page, limit int, uid int64) ([]*model.EggEnergyCommunityDividendsWithUser, int64, error) { + var m []*model.EggEnergyCommunityDividendsWithUser + session := e.Db.Where("") + if uid > 0 { + session = session.And("uid=?", uid) + } + total, err := session.Limit(limit, (page-1)*limit).FindAndCount(&m) + if err != nil { + return nil, 0, zhios_order_relate_logx.Error(err.Error()) + } + return m, total, nil +} + +func (e EggEnergyCommunityDividendsWithUserDb) EggEnergyCommunityDividendsWithUserExist(uid int64) (bool, error) { + var m model.EggEnergyCommunityDividendsWithUser + has, err := e.Db.Where("uid=?", uid).Exist(&m) + if err != nil { + return false, zhios_order_relate_logx.Error(err.Error()) + } + return has, nil +}