作者 yangfu

fix: 用户按部门搜索修改

... ... @@ -531,6 +531,18 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in
queryOptions["userBaseId"] = userBase.UserBaseId
}
}
if len(listUserQuery.DepName) > 0 {
orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0)
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": listUserQuery.CompanyId, "matchOrgName": listUserQuery.DepName})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(orgs) > 0 {
queryOptions["inDepartmentIds"] = domain.Organizations(orgs).OrgIds()
}
listUserQuery.DepName = ""
delete(queryOptions, "depName")
}
if count, users, err := userRepository.Find(queryOptions); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"fmt"
"github.com/tal-tech/go-zero/core/collection"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
"strconv"
"strings"
... ... @@ -243,3 +244,13 @@ type BatchAddOrgItem struct {
// 失败理由
FailReason string `json:"failReason"`
}
type Organizations []*Org
func (list Organizations) OrgIds() []int64 {
set := collection.NewSet()
for i := range list {
set.Add(list[i].OrgId)
}
return set.KeysInt64()
}
... ...