2021-06-07 17:22:07 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/internal/sys/domain/entity"
|
|
|
|
|
"mayfly-go/internal/sys/domain/repository"
|
|
|
|
|
"mayfly-go/pkg/biz"
|
2023-07-01 14:34:42 +08:00
|
|
|
"mayfly-go/pkg/gormx"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/model"
|
2021-06-07 17:22:07 +08:00
|
|
|
)
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
type accountRepoImpl struct{}
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func newAccountRepo() repository.Account {
|
|
|
|
|
return new(accountRepoImpl)
|
|
|
|
|
}
|
2021-06-07 17:22:07 +08:00
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (a *accountRepoImpl) GetAccount(condition *entity.Account, cols ...string) error {
|
2023-07-01 14:34:42 +08:00
|
|
|
return gormx.GetBy(condition, cols...)
|
2021-06-07 17:22:07 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:36:07 +08:00
|
|
|
func (a *accountRepoImpl) GetById(id uint64) *entity.Account {
|
|
|
|
|
ac := new(entity.Account)
|
|
|
|
|
if err := gormx.GetById(ac, id); err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return ac
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 14:34:42 +08:00
|
|
|
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
|
|
|
|
qd := gormx.NewQuery(new(entity.Account)).
|
|
|
|
|
Like("name", condition.Name).
|
|
|
|
|
Like("username", condition.Username)
|
|
|
|
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *accountRepoImpl) Insert(account *entity.Account) {
|
2023-07-01 14:34:42 +08:00
|
|
|
biz.ErrIsNil(gormx.Insert(account), "新增账号信息失败")
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *accountRepoImpl) Update(account *entity.Account) {
|
2023-07-01 14:34:42 +08:00
|
|
|
biz.ErrIsNil(gormx.UpdateById(account), "更新账号信息失败")
|
2021-06-07 17:22:07 +08:00
|
|
|
}
|