作者 yangfu

公司搜索

@@ -257,7 +257,7 @@ @@ -257,7 +257,7 @@
257 }, 257 },
258 "v1/mini/company/search": { 258 "v1/mini/company/search": {
259 "post": { 259 "post": {
260 - "summary": "公司搜索", 260 + "summary": "公司搜索(公开的)",
261 "operationId": "miniCompanySearch", 261 "operationId": "miniCompanySearch",
262 "responses": { 262 "responses": {
263 "200": { 263 "200": {
@@ -283,6 +283,34 @@ @@ -283,6 +283,34 @@
283 ] 283 ]
284 } 284 }
285 }, 285 },
  286 + "v1/mini/company/search-joined": {
  287 + "post": {
  288 + "summary": "搜索已加入的公司",
  289 + "operationId": "miniCompanySearchJoined",
  290 + "responses": {
  291 + "200": {
  292 + "description": "A successful response.",
  293 + "schema": {
  294 + "$ref": "#/definitions/CompanySearchResponse"
  295 + }
  296 + }
  297 + },
  298 + "parameters": [
  299 + {
  300 + "name": "body",
  301 + "in": "body",
  302 + "required": true,
  303 + "schema": {
  304 + "$ref": "#/definitions/CompanySearchRequest"
  305 + }
  306 + }
  307 + ],
  308 + "requestBody": {},
  309 + "tags": [
  310 + "company"
  311 + ]
  312 + }
  313 + },
286 "v1/mini/message/business": { 314 "v1/mini/message/business": {
287 "post": { 315 "post": {
288 "summary": "业务消息", 316 "summary": "业务消息",
@@ -1022,6 +1050,34 @@ @@ -1022,6 +1050,34 @@
1022 ] 1050 ]
1023 } 1051 }
1024 }, 1052 },
  1053 + "v1/system/user/info": {
  1054 + "post": {
  1055 + "summary": "系统用户信息",
  1056 + "operationId": "systemUserInfo",
  1057 + "responses": {
  1058 + "200": {
  1059 + "description": "A successful response.",
  1060 + "schema": {
  1061 + "$ref": "#/definitions/SystemUserInfoResponse"
  1062 + }
  1063 + }
  1064 + },
  1065 + "parameters": [
  1066 + {
  1067 + "name": "body",
  1068 + "in": "body",
  1069 + "required": true,
  1070 + "schema": {
  1071 + "$ref": "#/definitions/SystemUserInfoRequest"
  1072 + }
  1073 + }
  1074 + ],
  1075 + "requestBody": {},
  1076 + "tags": [
  1077 + "user"
  1078 + ]
  1079 + }
  1080 + },
1025 "v1/user/mylike": { 1081 "v1/user/mylike": {
1026 "post": { 1082 "post": {
1027 "summary": "我点赞的文章或评论", 1083 "summary": "我点赞的文章或评论",
@@ -1300,21 +1356,22 @@ @@ -1300,21 +1356,22 @@
1300 "type": "integer", 1356 "type": "integer",
1301 "format": "int32" 1357 "format": "int32"
1302 }, 1358 },
  1359 + "flag": {
  1360 + "type": "integer",
  1361 + "format": "int32",
  1362 + "description": " 1:用户已加入的 2:用户未加入的公司"
  1363 + },
1303 "userId": { 1364 "userId": {
1304 "type": "integer", 1365 "type": "integer",
1305 "format": "int64", 1366 "format": "int64",
1306 - "description": " 按用户搜索" 1367 + "description": " 按用户搜索(用户所加入的企业)"
1307 }, 1368 },
1308 "code": { 1369 "code": {
1309 "type": "string", 1370 "type": "string",
1310 "description": " 按编码搜索" 1371 "description": " 按编码搜索"
1311 } 1372 }
1312 }, 1373 },
1313 - "title": "CompanySearchRequest",  
1314 - "required": [  
1315 - "page",  
1316 - "size"  
1317 - ] 1374 + "title": "CompanySearchRequest"
1318 }, 1375 },
1319 "CompanySearchResponse": { 1376 "CompanySearchResponse": {
1320 "type": "object", 1377 "type": "object",
@@ -2998,6 +3055,40 @@ @@ -2998,6 +3055,40 @@
2998 "list" 3055 "list"
2999 ] 3056 ]
3000 }, 3057 },
  3058 + "SystemUserInfoRequest": {
  3059 + "type": "object",
  3060 + "title": "SystemUserInfoRequest"
  3061 + },
  3062 + "SystemUserInfoResponse": {
  3063 + "type": "object",
  3064 + "properties": {
  3065 + "userId": {
  3066 + "type": "integer",
  3067 + "format": "int64"
  3068 + },
  3069 + "userName": {
  3070 + "type": "string"
  3071 + },
  3072 + "avatar": {
  3073 + "type": "string"
  3074 + },
  3075 + "companyId": {
  3076 + "type": "integer",
  3077 + "format": "int64"
  3078 + },
  3079 + "companyName": {
  3080 + "type": "string"
  3081 + }
  3082 + },
  3083 + "title": "SystemUserInfoResponse",
  3084 + "required": [
  3085 + "userId",
  3086 + "userName",
  3087 + "avatar",
  3088 + "companyId",
  3089 + "companyName"
  3090 + ]
  3091 + },
3001 "TagCreateRequest": { 3092 "TagCreateRequest": {
3002 "type": "object", 3093 "type": "object",
3003 "properties": { 3094 "properties": {
@@ -14,7 +14,7 @@ info( @@ -14,7 +14,7 @@ info(
14 group: company 14 group: company
15 ) 15 )
16 service Core { 16 service Core {
17 - @doc "公司搜索" 17 + @doc "公司搜索(公开的)"
18 @handler miniCompanySearch 18 @handler miniCompanySearch
19 post /mini/company/search(CompanySearchRequest) returns (CompanySearchResponse) 19 post /mini/company/search(CompanySearchRequest) returns (CompanySearchResponse)
20 } 20 }
@@ -23,6 +23,18 @@ service Core { @@ -23,6 +23,18 @@ service Core {
23 @server( 23 @server(
24 prefix: v1 24 prefix: v1
25 group: company 25 group: company
  26 + jwt : MiniAuth
  27 +)
  28 +service Core {
  29 + @doc "搜索已加入的公司"
  30 + @handler miniCompanySearchJoined
  31 + post /mini/company/search-joined(CompanySearchRequest) returns (CompanySearchResponse)
  32 +}
  33 +
  34 +// 小程序接口
  35 +@server(
  36 + prefix: v1
  37 + group: company
26 jwt : SystemAuth 38 jwt : SystemAuth
27 ) 39 )
28 service Core { 40 service Core {
@@ -33,9 +45,10 @@ service Core { @@ -33,9 +45,10 @@ service Core {
33 45
34 type ( 46 type (
35 CompanySearchRequest struct{ 47 CompanySearchRequest struct{
36 - Page int `json:"page"`  
37 - Size int `json:"size"`  
38 - UserId int64 `json:"userId,optional"` // 按用户搜索 48 + Page int `json:"page,optional"`
  49 + Size int `json:"size,optional"`
  50 + Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
  51 + UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
39 Code string `json:"code,optional"` // 按编码搜索 52 Code string `json:"code,optional"` // 按编码搜索
40 } 53 }
41 CompanySearchResponse{ 54 CompanySearchResponse{
@@ -206,13 +206,26 @@ type ( @@ -206,13 +206,26 @@ type (
206 206
207 207
208 // 后台接口 208 // 后台接口
209 -//@server(  
210 -// prefix: v1  
211 -// group: user  
212 -// jwt: SystemAuth  
213 -//)  
214 -//service Core {  
215 -// @doc "系统评论"  
216 -// @handler systemUser  
217 -// get /system/user () returns ()  
218 -//}  
  209 +@server(
  210 + prefix: v1
  211 + group: user
  212 + jwt: SystemAuth
  213 +)
  214 +service Core {
  215 + @doc "系统用户信息"
  216 + @handler systemUserInfo
  217 + post /system/user/info(SystemUserInfoRequest) returns (SystemUserInfoResponse)
  218 +}
  219 +
  220 +type(
  221 + SystemUserInfoRequest{
  222 +
  223 + }
  224 + SystemUserInfoResponse{
  225 + UserId int64 `json:"userId"`
  226 + UserName string `json:"userName"`
  227 + Avatar string `json:"avatar"`
  228 + CompanyId int64 `json:"companyId"`
  229 + CompanyName string `json:"companyName"`
  230 + }
  231 +)
  1 +package company
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/company"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  11 +)
  12 +
  13 +func MiniCompanySearchJoinedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.CompanySearchRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := company.NewMiniCompanySearchJoinedLogic(r.Context(), svcCtx)
  22 + resp, err := l.MiniCompanySearchJoined(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
@@ -167,6 +167,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -167,6 +167,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
167 []rest.Route{ 167 []rest.Route{
168 { 168 {
169 Method: http.MethodPost, 169 Method: http.MethodPost,
  170 + Path: "/system/user/info",
  171 + Handler: user.SystemUserInfoHandler(serverCtx),
  172 + },
  173 + },
  174 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  175 + rest.WithPrefix("/v1"),
  176 + )
  177 +
  178 + server.AddRoutes(
  179 + []rest.Route{
  180 + {
  181 + Method: http.MethodPost,
170 Path: "/mini/company/search", 182 Path: "/mini/company/search",
171 Handler: company.MiniCompanySearchHandler(serverCtx), 183 Handler: company.MiniCompanySearchHandler(serverCtx),
172 }, 184 },
@@ -178,6 +190,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -178,6 +190,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
178 []rest.Route{ 190 []rest.Route{
179 { 191 {
180 Method: http.MethodPost, 192 Method: http.MethodPost,
  193 + Path: "/mini/company/search-joined",
  194 + Handler: company.MiniCompanySearchJoinedHandler(serverCtx),
  195 + },
  196 + },
  197 + rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
  198 + rest.WithPrefix("/v1"),
  199 + )
  200 +
  201 + server.AddRoutes(
  202 + []rest.Route{
  203 + {
  204 + Method: http.MethodPost,
181 Path: "/system/company/search", 205 Path: "/system/company/search",
182 Handler: company.SystemCompanySearchHandler(serverCtx), 206 Handler: company.SystemCompanySearchHandler(serverCtx),
183 }, 207 },
  1 +package user
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func SystemUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.SystemUserInfoRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := user.NewSystemUserInfoLogic(r.Context(), svcCtx)
  21 + resp, err := l.SystemUserInfo(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package company
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  8 + "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"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type MiniCompanySearchJoinedLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewMiniCompanySearchJoinedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCompanySearchJoinedLogic {
  23 + return &MiniCompanySearchJoinedLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + companyList []*domain.Company
  34 + total int64
  35 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  36 + user *domain.User
  37 + companyIds []int64
  38 + )
  39 + queryOptions := domain.NewQueryOptions()
  40 + if req.Page != 0 {
  41 + queryOptions.WithOffsetLimit(req.Page, req.Size)
  42 + }
  43 + user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
  44 + if err != nil {
  45 + return nil, xerr.NewErrMsgErr("账号有误", err)
  46 + }
  47 + resp = &types.CompanySearchResponse{
  48 + List: make([]types.Company, 0),
  49 + }
  50 + _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
  51 + MustWithKV("phone", user.Phone).
  52 + MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
  53 + WithFindOnly())
  54 + lo.ForEach(users, func(item *domain.User, index int) {
  55 + companyIds = append(companyIds, item.CompanyId)
  56 + })
  57 + if req.Flag == 1 {
  58 + total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyIds))
  59 + if err != nil {
  60 + return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
  61 + }
  62 + } else {
  63 + total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds))
  64 + if err != nil {
  65 + return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
  66 + }
  67 + }
  68 + lo.ForEach(companyList, func(item *domain.Company, index int) {
  69 + resp.List = append(resp.List, NewCompany(item))
  70 + })
  71 + resp.Total = total
  72 + return
  73 +}
@@ -2,9 +2,11 @@ package company @@ -2,9 +2,11 @@ package company
2 2
3 import ( 3 import (
4 "context" 4 "context"
5 - 5 + "github.com/samber/lo"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 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" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
8 10
9 "github.com/zeromicro/go-zero/core/logx" 11 "github.com/zeromicro/go-zero/core/logx"
10 ) 12 )
@@ -24,7 +26,37 @@ func NewMiniCompanySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) @@ -24,7 +26,37 @@ func NewMiniCompanySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext)
24 } 26 }
25 27
26 func (l *MiniCompanySearchLogic) MiniCompanySearch(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) { 28 func (l *MiniCompanySearchLogic) MiniCompanySearch(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) {
27 - // todo: add your logic here and delete this line  
28 - 29 + var (
  30 + conn = l.svcCtx.DefaultDBConn()
  31 + companyList []*domain.Company
  32 + total int64
  33 + )
  34 + queryOptions := domain.NewQueryOptions()
  35 + if req.Page != 0 {
  36 + queryOptions.WithOffsetLimit(req.Page, req.Size)
  37 + }
  38 + if req.Code != "" {
  39 + queryOptions.WithKV("code", req.Code)
  40 + }
  41 + total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions)
  42 + if err != nil {
  43 + return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
  44 + }
  45 + resp = &types.CompanySearchResponse{
  46 + Total: total,
  47 + List: make([]types.Company, 0),
  48 + }
  49 + lo.ForEach(companyList, func(item *domain.Company, index int) {
  50 + resp.List = append(resp.List, NewCompany(item))
  51 + })
29 return 52 return
30 } 53 }
  54 +
  55 +func NewCompany(item *domain.Company) types.Company {
  56 + return types.Company{
  57 + Id: item.Id,
  58 + Name: item.Name,
  59 + Code: item.Code,
  60 + Logo: item.Logo,
  61 + }
  62 +}
  1 +package user
  2 +
  3 +import (
  4 + "context"
  5 +
  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"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type SystemUserInfoLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSystemUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserInfoLogic {
  19 + return &SystemUserInfoLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (resp *types.SystemUserInfoResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
@@ -504,10 +504,22 @@ type SimpleComment struct { @@ -504,10 +504,22 @@ type SimpleComment struct {
504 Show int `json:"show"` // 评论的展示状态(0显示、1不显示) 504 Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
505 } 505 }
506 506
  507 +type SystemUserInfoRequest struct {
  508 +}
  509 +
  510 +type SystemUserInfoResponse struct {
  511 + UserId int64 `json:"userId"`
  512 + UserName string `json:"userName"`
  513 + Avatar string `json:"avatar"`
  514 + CompanyId int64 `json:"companyId"`
  515 + CompanyName string `json:"companyName"`
  516 +}
  517 +
507 type CompanySearchRequest struct { 518 type CompanySearchRequest struct {
508 - Page int `json:"page"`  
509 - Size int `json:"size"`  
510 - UserId int64 `json:"userId,optional"` // 按用户搜索 519 + Page int `json:"page,optional"`
  520 + Size int `json:"size,optional"`
  521 + Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
  522 + UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
511 Code string `json:"code,optional"` // 按编码搜索 523 Code string `json:"code,optional"` // 按编码搜索
512 } 524 }
513 525
@@ -142,6 +142,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction. @@ -142,6 +142,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.
142 if v, ok := queryOptions["ids"]; ok { 142 if v, ok := queryOptions["ids"]; ok {
143 tx.Where("id in (?)", v) 143 tx.Where("id in (?)", v)
144 } 144 }
  145 + if v, ok := queryOptions["excludeIds"]; ok {
  146 + tx.Where("id not in (?)", v)
  147 + }
145 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 148 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
146 return dms, tx.Error 149 return dms, tx.Error
147 } 150 }