|
|
@@ -0,0 +1,70 @@ |
|
|
|
package implement |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func NewUserEggEnergyAggregationDb(engine *xorm.Engine) dao.UserEggEnergyAggregationDao { |
|
|
|
return &UserEggEnergyAggregationDb{Db: engine} |
|
|
|
} |
|
|
|
|
|
|
|
type UserEggEnergyAggregationDb struct { |
|
|
|
Db *xorm.Engine |
|
|
|
} |
|
|
|
|
|
|
|
func (u UserEggEnergyAggregationDb) UserEggEnergyAggregationInsert(UserEggEnergyAggregation *model.UserEggEnergyAggregation) (int64, error) { |
|
|
|
_, err := u.Db.InsertOne(UserEggEnergyAggregation) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return UserEggEnergyAggregation.Id, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (u UserEggEnergyAggregationDb) UserEggEnergyAggregationUpdate(id interface{}, UserEggEnergyAggregation *model.UserEggEnergyAggregation, forceColums ...string) (int64, error) { |
|
|
|
var ( |
|
|
|
affected int64 |
|
|
|
err error |
|
|
|
) |
|
|
|
if forceColums != nil { |
|
|
|
affected, err = u.Db.Where("id=?", id).Cols(forceColums...).Update(UserEggEnergyAggregation) |
|
|
|
} else { |
|
|
|
affected, err = u.Db.Where("id=?", id).Update(UserEggEnergyAggregation) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affected, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (u UserEggEnergyAggregationDb) UserEggEnergyAggregationGetOneByTime(day, week, month, year int, uid int64) (*model.UserEggEnergyAggregation, error) { |
|
|
|
var m model.UserEggEnergyAggregation |
|
|
|
has, err := u.Db.Where("day = ?", day). |
|
|
|
And("week = ?", week). |
|
|
|
And("month = ?", month). |
|
|
|
And("year = ?", year). |
|
|
|
And("uid = ?", uid). |
|
|
|
Get(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if !has { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (u UserEggEnergyAggregationDb) UserEggEnergyAggregationGetLastOneByUid(uid int64) (*model.UserEggEnergyAggregation, error) { |
|
|
|
var m model.UserEggEnergyAggregation |
|
|
|
has, err := u.Db.Where("uid = ?", uid). |
|
|
|
Desc("create_at"). |
|
|
|
Get(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if !has { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |