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"
|
|
|
|
|
"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 {
|
2021-06-07 17:22:07 +08:00
|
|
|
return model.GetBy(condition, cols...)
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 12:31:32 +08:00
|
|
|
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
2021-07-28 18:03:19 +08:00
|
|
|
sql := "SELECT * FROM t_sys_account "
|
|
|
|
|
username := condition.Username
|
2023-06-01 12:31:32 +08:00
|
|
|
values := make([]any, 0)
|
2021-07-28 18:03:19 +08:00
|
|
|
if username != "" {
|
2022-10-31 18:39:52 +08:00
|
|
|
sql = sql + " WHERE username LIKE ?"
|
|
|
|
|
values = append(values, "%"+username+"%")
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
2022-10-31 18:39:52 +08:00
|
|
|
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *accountRepoImpl) Insert(account *entity.Account) {
|
2021-07-28 18:03:19 +08:00
|
|
|
biz.ErrIsNil(model.Insert(account), "新增账号信息失败")
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *accountRepoImpl) Update(account *entity.Account) {
|
2021-07-28 18:03:19 +08:00
|
|
|
biz.ErrIsNil(model.UpdateById(account), "更新账号信息失败")
|
2021-06-07 17:22:07 +08:00
|
|
|
}
|