fix(user):修正检索用户时语句中的引用问题。
This commit is contained in:
parent
2aa6939186
commit
e40ba55825
@ -6,6 +6,7 @@ import (
|
||||
"electricity_bill_calc/config"
|
||||
"electricity_bill_calc/exceptions"
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/tools"
|
||||
"fmt"
|
||||
@ -15,11 +16,16 @@ import (
|
||||
"github.com/fufuok/utils"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type _UserService struct{}
|
||||
type _UserService struct {
|
||||
l *zap.Logger
|
||||
}
|
||||
|
||||
var UserService _UserService
|
||||
var UserService = _UserService{
|
||||
l: logger.Named("Service", "User"),
|
||||
}
|
||||
|
||||
func (u _UserService) ProcessEnterpriseUserLogin(username, password string) (*model.Session, error) {
|
||||
user, err := u.findUserWithCredentialsByUsername(username)
|
||||
@ -242,6 +248,7 @@ func (u _UserService) SwitchUserState(uid string, enabled bool) error {
|
||||
return err
|
||||
}
|
||||
newStateUser := new(model.User)
|
||||
newStateUser.Id = uid
|
||||
newStateUser.Enabled = enabled
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
defer cancel()
|
||||
@ -308,14 +315,14 @@ func (_UserService) findUserWithCredentialsByUsername(username string) (*model.U
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (_UserService) findUserByUsername(username string) (*model.User, error) {
|
||||
func (u _UserService) findUserByUsername(username string) (*model.User, error) {
|
||||
if cachedUser, _ := cache.RetreiveSearch[model.User]("user", username); cachedUser != nil {
|
||||
return cachedUser, nil
|
||||
}
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
defer cancel()
|
||||
user := new(model.User)
|
||||
err := global.DB.NewSelect().Model(&user).Where("username = ?", username).Scan(ctx)
|
||||
err := global.DB.NewSelect().Model(user).Where("username = ?", username).Scan(ctx)
|
||||
if err == nil {
|
||||
cache.CacheSearch(*user, []string{fmt.Sprintf("user:%s", user.Id)}, "user", username)
|
||||
}
|
||||
@ -363,12 +370,12 @@ func (_UserService) ListUserDetail(keyword string, userType int, userState *bool
|
||||
)
|
||||
cond = cond.Model(&users).Relation("Detail")
|
||||
cacheConditions = append(cacheConditions, strconv.Itoa(page))
|
||||
cond = cond.Where("d.id <> ?", "000")
|
||||
cond = cond.Where("detail.id <> ?", "000")
|
||||
if len(keyword) != 0 {
|
||||
keywordCond := "%" + keyword + "%"
|
||||
cond = cond.WhereGroup(" and ", func(q *bun.SelectQuery) *bun.SelectQuery {
|
||||
return q.Where("u.username like ?", keywordCond).
|
||||
WhereOr("d.name like ?", keywordCond)
|
||||
WhereOr("detail.name like ?", keywordCond)
|
||||
})
|
||||
cacheConditions = append(cacheConditions, keyword)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user