作者 yangfu

公司搜索修改

... ... @@ -55,16 +55,18 @@ type (
Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
Code string `json:"code,optional"` // 按编码搜索
Content string `json:"content,optional"` // 按公司名/编码搜索
}
CompanySearchResponse {
List []Company `json:"list"`
Total int64 `json:"total"`
}
Company {
Id int64 `json:"id,omitempty"` // 唯一标识
Id int64 `json:"id,string,omitempty"` // 唯一标识
Name string `json:"name,omitempty"` // 名称
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
}
)
... ...
... ... @@ -145,6 +145,7 @@ type(
MiniUserFollowedSearchRequest{
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Name string `json:"name,optional"`
}
MiniUserFollowedSearchResponse{
List []*UserFollowItem `json:"users"`
... ...
... ... @@ -40,6 +40,7 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
if req.Page != 0 {
queryOptions.WithOffsetLimit(req.Page, req.Size)
}
queryOptions.WithKV("likeCodeOrName", req.Content)
user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
if err != nil {
return nil, xerr.NewErrMsgErr("账号有误", err)
... ... @@ -59,14 +60,23 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
} else {
} else if req.Flag == 2 {
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds))
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
} else {
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
}
lo.ForEach(companyList, func(item *domain.Company, index int) {
resp.List = append(resp.List, NewCompany(item))
company := NewCompany(item)
if lo.Contains(companyIds, company.Id) {
company.JoinedFlag = 1
}
resp.List = append(resp.List, company)
})
resp.Total = total
return
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -47,8 +48,16 @@ func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSear
Total: total,
List: make([]*types.UserFollowItem, 0),
}
for {
if offset > len(user.Follower) {
break
}
users = lo.Slice(users, offset, offset+limit)
lo.ForEach(users, func(item int64, index int) {
if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil {
if len(req.Name) > 0 && !strings.Contains(foundUser.Name, req.Name) {
return
}
var companyName = ""
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
companyName = company.Name
... ... @@ -64,5 +73,12 @@ func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSear
})
}
})
if len(resp.List) >= limit {
break
}
req.Page += 1
offset, limit = domain.OffsetLimit(req.Page, req.Size)
}
return
}
... ...
... ... @@ -3,12 +3,12 @@ package user
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -42,13 +42,20 @@ func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSe
total = int64(len(users))
offset, limit = domain.OffsetLimit(req.Page, req.Size)
)
users = lo.Slice(users, offset, offset+limit)
resp = &types.MiniUserFollowedSearchResponse{
Total: total,
List: make([]*types.UserFollowItem, 0),
}
for {
if offset > len(user.Following) {
break
}
users = lo.Slice(users, offset, offset+limit)
lo.ForEach(users, func(item int64, index int) {
if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil {
if len(req.Name) > 0 && !strings.Contains(foundUser.Name, req.Name) {
return
}
var companyName = ""
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
companyName = company.Name
... ... @@ -64,5 +71,11 @@ func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSe
})
}
})
if len(resp.List) >= limit {
break
}
req.Page += 1
offset, limit = domain.OffsetLimit(req.Page, req.Size)
}
return
}
... ...
... ... @@ -483,6 +483,7 @@ type UserNewsItem struct {
type MiniUserFollowedSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Name string `json:"name,optional"`
}
type MiniUserFollowedSearchResponse struct {
... ... @@ -716,6 +717,7 @@ type CompanySearchRequest struct {
Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
Code string `json:"code,optional"` // 按编码搜索
Content string `json:"content,optional"` // 按公司名/编码搜索
}
type CompanySearchResponse struct {
... ... @@ -724,10 +726,11 @@ type CompanySearchResponse struct {
}
type Company struct {
Id int64 `json:"id,omitempty"` // 唯一标识
Id int64 `json:"id,string,omitempty"` // 唯一标识
Name string `json:"name,omitempty"` // 名称
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
}
type CompanyPositionsSearchRequest struct {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -145,6 +146,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["excludeIds"]; ok {
tx.Where("id not in (?)", v)
}
if v, ok := queryOptions["likeCodeOrName"]; ok {
tx.Where(fmt.Sprintf("code like '%%%v%%' or name like '%%%v%%'", v, v))
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...