2022-08-26 20:15:36 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"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-08-26 20:15:36 +08:00
|
|
|
"mayfly-go/pkg/model"
|
|
|
|
|
)
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
type configRepoImpl struct{}
|
2022-08-26 20:15:36 +08:00
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func newConfigRepo() repository.Config {
|
|
|
|
|
return new(configRepoImpl)
|
|
|
|
|
}
|
2022-08-26 20:15:36 +08:00
|
|
|
|
2023-07-01 14:34:42 +08:00
|
|
|
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
2023-08-25 19:41:52 +08:00
|
|
|
qd := gormx.NewQuery(condition).
|
|
|
|
|
Eq("key", condition.Key).
|
|
|
|
|
And("permission = 'all' OR permission LIKE ?", "%"+condition.Permission+",%").
|
|
|
|
|
WithOrderBy(orderBy...)
|
2023-07-01 14:34:42 +08:00
|
|
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
2022-08-26 20:15:36 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *configRepoImpl) Insert(config *entity.Config) {
|
2023-07-01 14:34:42 +08:00
|
|
|
biz.ErrIsNil(gormx.Insert(config), "新增系统配置失败")
|
2022-08-26 20:15:36 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *configRepoImpl) Update(config *entity.Config) {
|
2023-07-01 14:34:42 +08:00
|
|
|
biz.ErrIsNil(gormx.UpdateById(config), "更新系统配置失败")
|
2022-08-26 20:15:36 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (m *configRepoImpl) GetConfig(condition *entity.Config, cols ...string) error {
|
2023-07-01 14:34:42 +08:00
|
|
|
return gormx.GetBy(condition, cols...)
|
2022-08-26 20:15:36 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (r *configRepoImpl) GetByCondition(condition *entity.Config, cols ...string) error {
|
2023-07-01 14:34:42 +08:00
|
|
|
return gormx.GetBy(condition, cols...)
|
2022-08-26 20:15:36 +08:00
|
|
|
}
|