From d19bcfaff836570bb6e1677b624593f177028f41 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 21 May 2024 15:19:20 +0800 Subject: [PATCH] update --- src/dao/happy_orchard_user_waters_dao.go | 1 + .../happy_orchard_user_seed_record_db.go | 30 ++++++++++++++----- src/implement/happy_orchard_user_waters_db.go | 16 ++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/dao/happy_orchard_user_waters_dao.go b/src/dao/happy_orchard_user_waters_dao.go index a502310..eb1e55c 100644 --- a/src/dao/happy_orchard_user_waters_dao.go +++ b/src/dao/happy_orchard_user_waters_dao.go @@ -7,4 +7,5 @@ import ( type HappyOrchardUserWatersDao interface { GetHappyOrchardUserWaters(uid int) (m *models.HappyOrchardUserWaters, err error) GetHappyOrchardUserWatersSess(uid int) (m *models.HappyOrchardUserWaters, err error) + UpdateHappyOrchardUserWaters(uid int, m *models.HappyOrchardUserWaters, forceColums ...string) (int64, error) } diff --git a/src/implement/happy_orchard_user_seed_record_db.go b/src/implement/happy_orchard_user_seed_record_db.go index a91406e..e9cd20a 100644 --- a/src/implement/happy_orchard_user_seed_record_db.go +++ b/src/implement/happy_orchard_user_seed_record_db.go @@ -7,15 +7,31 @@ import ( "xorm.io/xorm" ) -type happyOrchardUserSeedRecordDb struct { +type HappyOrchardUserSeedRecordDb struct { Db *xorm.Engine } +func (h HappyOrchardUserSeedRecordDb) UpdateHappyOrchardUserSeedRecord(m *models.HappyOrchardUserSeedRecord, forceColums ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColums != nil { + affected, err = h.Db.Where("id=?", m.Id).Cols(forceColums...).Update(m) + } else { + affected, err = h.Db.Where("id=?", m.Id).Update(m) + } + if err != nil { + return 0, err + } + return affected, nil +} + func NewHappyOrchardUserSeedRecordDb(engine *xorm.Engine) dao.HappyOrchardUserSeedRecordDao { - return &happyOrchardUserSeedRecordDb{Db: engine} + return &HappyOrchardUserSeedRecordDb{Db: engine} } -func (h happyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecord(id int) (m *models.HappyOrchardUserSeedRecord, err error) { +func (h HappyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecord(id int) (m *models.HappyOrchardUserSeedRecord, err error) { //TODO implement me m = new(models.HappyOrchardUserSeedRecord) has, err := h.Db.Where("id =?", id).Get(m) @@ -28,7 +44,7 @@ func (h happyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecord(id int) (m * return m, nil } -func (h happyOrchardUserSeedRecordDb) FindHappyOrchardUserSeedRecordByUid(uid int) (mm *[]models.HappyOrchardUserSeedRecord, err error) { +func (h HappyOrchardUserSeedRecordDb) FindHappyOrchardUserSeedRecordByUid(uid int) (mm *[]models.HappyOrchardUserSeedRecord, err error) { //TODO implement me var m []models.HappyOrchardUserSeedRecord if err := h.Db.Where("uid =?", uid).Desc("id").Find(&m); err != nil { @@ -36,7 +52,7 @@ func (h happyOrchardUserSeedRecordDb) FindHappyOrchardUserSeedRecordByUid(uid in } return &m, nil } -func (h happyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecordByUidWithState(uid, state int) (m *models.HappyOrchardUserSeedRecord, err error) { +func (h HappyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecordByUidWithState(uid, state int) (m *models.HappyOrchardUserSeedRecord, err error) { m = new(models.HappyOrchardUserSeedRecord) has, err := h.Db.Where("uid =? and state=?", uid, state).Get(m) if err != nil { @@ -47,7 +63,7 @@ func (h happyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecordByUidWithStat } return m, nil } -func (h happyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecordByUidWithStateAndId(uid, id, state int) (m *models.HappyOrchardUserSeedRecord, err error) { +func (h HappyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecordByUidWithStateAndId(uid, id, state int) (m *models.HappyOrchardUserSeedRecord, err error) { m = new(models.HappyOrchardUserSeedRecord) has, err := h.Db.Where("uid =? and state=? and id=?", uid, state, id).Get(m) if err != nil { @@ -58,7 +74,7 @@ func (h happyOrchardUserSeedRecordDb) GetHappyOrchardUserSeedRecordByUidWithStat } return m, nil } -func (h happyOrchardUserSeedRecordDb) FindHappyOrchardUserSeedRecordAll(uid, start, limit int) (mm *[]models.HappyOrchardUserSeedRecord, err error) { +func (h HappyOrchardUserSeedRecordDb) FindHappyOrchardUserSeedRecordAll(uid, start, limit int) (mm *[]models.HappyOrchardUserSeedRecord, err error) { var m []models.HappyOrchardUserSeedRecord if err := h.Db.Where("uid=?", uid).OrderBy("id desc").Limit(limit, start).Find(&m); err != nil { return nil, zhios_order_relate_logx.Error(err) diff --git a/src/implement/happy_orchard_user_waters_db.go b/src/implement/happy_orchard_user_waters_db.go index 67841b1..6c9d4ec 100644 --- a/src/implement/happy_orchard_user_waters_db.go +++ b/src/implement/happy_orchard_user_waters_db.go @@ -12,6 +12,22 @@ type HappyOrchardUserWatersDb struct { Sess *xorm.Session } +func (h HappyOrchardUserWatersDb) UpdateHappyOrchardUserWaters(uid int, m *models.HappyOrchardUserWaters, forceColums ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColums != nil { + affected, err = h.Db.Where("uid=?", uid).Cols(forceColums...).Update(m) + } else { + affected, err = h.Db.Where("uid=?", uid).Update(m) + } + if err != nil { + return 0, err + } + return affected, nil +} + func NewHappyOrchardUserWatersDb(engine *xorm.Engine) dao.HappyOrchardUserWatersDao { return &HappyOrchardUserWatersDb{Db: engine} }