作者 yangfu

公司搜索修改

@@ -55,16 +55,18 @@ type ( @@ -55,16 +55,18 @@ type (
55 Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司 55 Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
56 UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业) 56 UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
57 Code string `json:"code,optional"` // 按编码搜索 57 Code string `json:"code,optional"` // 按编码搜索
  58 + Content string `json:"content,optional"` // 按公司名/编码搜索
58 } 59 }
59 CompanySearchResponse { 60 CompanySearchResponse {
60 List []Company `json:"list"` 61 List []Company `json:"list"`
61 Total int64 `json:"total"` 62 Total int64 `json:"total"`
62 } 63 }
63 Company { 64 Company {
64 - Id int64 `json:"id,omitempty"` // 唯一标识 65 + Id int64 `json:"id,string,omitempty"` // 唯一标识
65 Name string `json:"name,omitempty"` // 名称 66 Name string `json:"name,omitempty"` // 名称
66 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字) 67 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
67 Logo string `json:"logo,omitempty"` // 公司LOGO 68 Logo string `json:"logo,omitempty"` // 公司LOGO
  69 + JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
68 } 70 }
69 ) 71 )
70 72
@@ -145,6 +145,7 @@ type( @@ -145,6 +145,7 @@ type(
145 MiniUserFollowedSearchRequest{ 145 MiniUserFollowedSearchRequest{
146 Page int `json:"page,optional"` 146 Page int `json:"page,optional"`
147 Size int `json:"size,optional"` 147 Size int `json:"size,optional"`
  148 + Name string `json:"name,optional"`
148 } 149 }
149 MiniUserFollowedSearchResponse{ 150 MiniUserFollowedSearchResponse{
150 List []*UserFollowItem `json:"users"` 151 List []*UserFollowItem `json:"users"`
@@ -40,6 +40,7 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan @@ -40,6 +40,7 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
40 if req.Page != 0 { 40 if req.Page != 0 {
41 queryOptions.WithOffsetLimit(req.Page, req.Size) 41 queryOptions.WithOffsetLimit(req.Page, req.Size)
42 } 42 }
  43 + queryOptions.WithKV("likeCodeOrName", req.Content)
43 user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId) 44 user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
44 if err != nil { 45 if err != nil {
45 return nil, xerr.NewErrMsgErr("账号有误", err) 46 return nil, xerr.NewErrMsgErr("账号有误", err)
@@ -59,14 +60,23 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan @@ -59,14 +60,23 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
59 if err != nil { 60 if err != nil {
60 return nil, xerr.NewErrMsgErr("公司列表获取失败", err) 61 return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
61 } 62 }
62 - } else { 63 + } else if req.Flag == 2 {
63 total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds)) 64 total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds))
64 if err != nil { 65 if err != nil {
65 return nil, xerr.NewErrMsgErr("公司列表获取失败", err) 66 return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
66 } 67 }
  68 + } else {
  69 + total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions)
  70 + if err != nil {
  71 + return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
  72 + }
67 } 73 }
68 lo.ForEach(companyList, func(item *domain.Company, index int) { 74 lo.ForEach(companyList, func(item *domain.Company, index int) {
69 - resp.List = append(resp.List, NewCompany(item)) 75 + company := NewCompany(item)
  76 + if lo.Contains(companyIds, company.Id) {
  77 + company.JoinedFlag = 1
  78 + }
  79 + resp.List = append(resp.List, company)
70 }) 80 })
71 resp.Total = total 81 resp.Total = total
72 return 82 return
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  9 + "strings"
9 10
10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 11 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
11 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 12 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -47,8 +48,16 @@ func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSear @@ -47,8 +48,16 @@ func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSear
47 Total: total, 48 Total: total,
48 List: make([]*types.UserFollowItem, 0), 49 List: make([]*types.UserFollowItem, 0),
49 } 50 }
  51 + for {
  52 + if offset > len(user.Follower) {
  53 + break
  54 + }
  55 + users = lo.Slice(users, offset, offset+limit)
50 lo.ForEach(users, func(item int64, index int) { 56 lo.ForEach(users, func(item int64, index int) {
51 if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil { 57 if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil {
  58 + if len(req.Name) > 0 && !strings.Contains(foundUser.Name, req.Name) {
  59 + return
  60 + }
52 var companyName = "" 61 var companyName = ""
53 if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { 62 if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
54 companyName = company.Name 63 companyName = company.Name
@@ -64,5 +73,12 @@ func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSear @@ -64,5 +73,12 @@ func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSear
64 }) 73 })
65 } 74 }
66 }) 75 })
  76 + if len(resp.List) >= limit {
  77 + break
  78 + }
  79 + req.Page += 1
  80 + offset, limit = domain.OffsetLimit(req.Page, req.Size)
  81 + }
  82 +
67 return 83 return
68 } 84 }
@@ -3,12 +3,12 @@ package user @@ -3,12 +3,12 @@ package user
3 import ( 3 import (
4 "context" 4 "context"
5 "github.com/samber/lo" 5 "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
9 -  
10 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"  
11 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 11 + "strings"
12 12
13 "github.com/zeromicro/go-zero/core/logx" 13 "github.com/zeromicro/go-zero/core/logx"
14 ) 14 )
@@ -42,13 +42,20 @@ func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSe @@ -42,13 +42,20 @@ func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSe
42 total = int64(len(users)) 42 total = int64(len(users))
43 offset, limit = domain.OffsetLimit(req.Page, req.Size) 43 offset, limit = domain.OffsetLimit(req.Page, req.Size)
44 ) 44 )
45 - users = lo.Slice(users, offset, offset+limit)  
46 resp = &types.MiniUserFollowedSearchResponse{ 45 resp = &types.MiniUserFollowedSearchResponse{
47 Total: total, 46 Total: total,
48 List: make([]*types.UserFollowItem, 0), 47 List: make([]*types.UserFollowItem, 0),
49 } 48 }
  49 + for {
  50 + if offset > len(user.Following) {
  51 + break
  52 + }
  53 + users = lo.Slice(users, offset, offset+limit)
50 lo.ForEach(users, func(item int64, index int) { 54 lo.ForEach(users, func(item int64, index int) {
51 if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil { 55 if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil {
  56 + if len(req.Name) > 0 && !strings.Contains(foundUser.Name, req.Name) {
  57 + return
  58 + }
52 var companyName = "" 59 var companyName = ""
53 if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { 60 if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
54 companyName = company.Name 61 companyName = company.Name
@@ -64,5 +71,11 @@ func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSe @@ -64,5 +71,11 @@ func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSe
64 }) 71 })
65 } 72 }
66 }) 73 })
  74 + if len(resp.List) >= limit {
  75 + break
  76 + }
  77 + req.Page += 1
  78 + offset, limit = domain.OffsetLimit(req.Page, req.Size)
  79 + }
67 return 80 return
68 } 81 }
@@ -483,6 +483,7 @@ type UserNewsItem struct { @@ -483,6 +483,7 @@ type UserNewsItem struct {
483 type MiniUserFollowedSearchRequest struct { 483 type MiniUserFollowedSearchRequest struct {
484 Page int `json:"page,optional"` 484 Page int `json:"page,optional"`
485 Size int `json:"size,optional"` 485 Size int `json:"size,optional"`
  486 + Name string `json:"name,optional"`
486 } 487 }
487 488
488 type MiniUserFollowedSearchResponse struct { 489 type MiniUserFollowedSearchResponse struct {
@@ -716,6 +717,7 @@ type CompanySearchRequest struct { @@ -716,6 +717,7 @@ type CompanySearchRequest struct {
716 Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司 717 Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
717 UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业) 718 UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
718 Code string `json:"code,optional"` // 按编码搜索 719 Code string `json:"code,optional"` // 按编码搜索
  720 + Content string `json:"content,optional"` // 按公司名/编码搜索
719 } 721 }
720 722
721 type CompanySearchResponse struct { 723 type CompanySearchResponse struct {
@@ -724,10 +726,11 @@ type CompanySearchResponse struct { @@ -724,10 +726,11 @@ type CompanySearchResponse struct {
724 } 726 }
725 727
726 type Company struct { 728 type Company struct {
727 - Id int64 `json:"id,omitempty"` // 唯一标识 729 + Id int64 `json:"id,string,omitempty"` // 唯一标识
728 Name string `json:"name,omitempty"` // 名称 730 Name string `json:"name,omitempty"` // 名称
729 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字) 731 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
730 Logo string `json:"logo,omitempty"` // 公司LOGO 732 Logo string `json:"logo,omitempty"` // 公司LOGO
  733 + JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
731 } 734 }
732 735
733 type CompanyPositionsSearchRequest struct { 736 type CompanyPositionsSearchRequest struct {
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "fmt"
5 "github.com/jinzhu/copier" 6 "github.com/jinzhu/copier"
6 "github.com/pkg/errors" 7 "github.com/pkg/errors"
7 "github.com/tiptok/gocomm/pkg/cache" 8 "github.com/tiptok/gocomm/pkg/cache"
@@ -145,6 +146,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction. @@ -145,6 +146,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.
145 if v, ok := queryOptions["excludeIds"]; ok { 146 if v, ok := queryOptions["excludeIds"]; ok {
146 tx.Where("id not in (?)", v) 147 tx.Where("id not in (?)", v)
147 } 148 }
  149 + if v, ok := queryOptions["likeCodeOrName"]; ok {
  150 + tx.Where(fmt.Sprintf("code like '%%%v%%' or name like '%%%v%%'", v, v))
  151 + }
148 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 152 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
149 return dms, tx.Error 153 return dms, tx.Error
150 } 154 }