作者 郑周

Merge remote-tracking branch 'origin/dev' into dev

@@ -5,4 +5,8 @@ @@ -5,4 +5,8 @@
5 5
6 ### 可设置环境变量 6 ### 可设置环境变量
7 - DataSource 7 - DataSource
8 - 数据库连接,样例 host=数据库IP地址 user=用户名 password=密码 dbname=数据库名 port=31543 sslmode=disable TimeZone=Asia/Shanghai  
  8 + 数据库连接,样例
  9 + ``` code
  10 + host=数据库IP地址 user=用户名 password=密码 dbname=数据库名 port=31543 sslmode=disable TimeZone=Asia/Shanghai
  11 + ```
  12 +
@@ -230,7 +230,7 @@ type ( @@ -230,7 +230,7 @@ type (
230 Size int `json:"size"` 230 Size int `json:"size"`
231 ArticleId int64 `json:"articleId"` // 文章ID 231 ArticleId int64 `json:"articleId"` // 文章ID
232 TopId int64 `json:"topId,optional"` // 文章顶层ID 232 TopId int64 `json:"topId,optional"` // 文章顶层ID
233 - AuthorId int64 `json:"authorId,optional"` // 用户 233 + Author string `json:"author,optional"` // 用户
234 Show int `json:"show,optional"` // 显示状态 234 Show int `json:"show,optional"` // 显示状态
235 BeginTime int64 `json:"beginTime,optional"` // 开始时间 235 BeginTime int64 `json:"beginTime,optional"` // 开始时间
236 EndTime int64 `json:"endTime,optional"` // 结束时间 236 EndTime int64 `json:"endTime,optional"` // 结束时间
@@ -42,6 +42,10 @@ service Core { @@ -42,6 +42,10 @@ service Core {
42 @doc "公司搜索" 42 @doc "公司搜索"
43 @handler systemCompanySearch 43 @handler systemCompanySearch
44 post /system/company/search(CompanySearchRequest) returns (CompanySearchResponse) 44 post /system/company/search(CompanySearchRequest) returns (CompanySearchResponse)
  45 +
  46 + @doc "公司职位搜索"
  47 + @handler systemCompanyPositionsSearch
  48 + post /system/company/positions/search(CompanyPositionsSearchRequest) returns (CompanyPositionsSearchResponse)
45 } 49 }
46 50
47 type ( 51 type (
@@ -62,4 +66,18 @@ type ( @@ -62,4 +66,18 @@ type (
62 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字) 66 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
63 Logo string `json:"logo,omitempty"` // 公司LOGO 67 Logo string `json:"logo,omitempty"` // 公司LOGO
64 } 68 }
  69 +)
  70 +
  71 +// 公司职位搜索
  72 +type(
  73 + CompanyPositionsSearchRequest{
  74 +
  75 + }
  76 + CompanyPositionsSearchResponse {
  77 + List []Position `json:"list"`
  78 + Total int64 `json:"total"`
  79 + }
  80 + Position{
  81 + Name string `json:"name"`
  82 + }
65 ) 83 )
@@ -105,6 +105,7 @@ type( @@ -105,6 +105,7 @@ type(
105 MiniUserApplyJoinCompanyRequest{ 105 MiniUserApplyJoinCompanyRequest{
106 Phone string `json:"phone"` 106 Phone string `json:"phone"`
107 Code string `json:"code"` 107 Code string `json:"code"`
  108 + IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加
108 } 109 }
109 MiniUserApplyJoinCompanyResponse{ 110 MiniUserApplyJoinCompanyResponse{
110 111
  1 +package company
  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/company"
  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 SystemCompanyPositionsSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.CompanyPositionsSearchRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := company.NewSystemCompanyPositionsSearchLogic(r.Context(), svcCtx)
  21 + resp, err := l.SystemCompanyPositionsSearch(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
@@ -347,6 +347,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -347,6 +347,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
347 Path: "/system/company/search", 347 Path: "/system/company/search",
348 Handler: company.SystemCompanySearchHandler(serverCtx), 348 Handler: company.SystemCompanySearchHandler(serverCtx),
349 }, 349 },
  350 + {
  351 + Method: http.MethodPost,
  352 + Path: "/system/company/positions/search",
  353 + Handler: company.SystemCompanyPositionsSearchHandler(serverCtx),
  354 + },
350 }..., 355 }...,
351 ), 356 ),
352 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 357 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
@@ -32,7 +32,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types. @@ -32,7 +32,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
32 WithOffsetLimit(req.Page, req.Size). 32 WithOffsetLimit(req.Page, req.Size).
33 WithKV("articleId", req.ArticleId). 33 WithKV("articleId", req.ArticleId).
34 WithKV("topId", req.TopId). 34 WithKV("topId", req.TopId).
35 - WithKV("fromUserId", req.AuthorId). 35 + WithKV("fromUserName", req.Author).
36 WithKV("beginCreatedAt", req.BeginTime). 36 WithKV("beginCreatedAt", req.BeginTime).
37 WithKV("endCreatedAt", req.EndTime) 37 WithKV("endCreatedAt", req.EndTime)
38 total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions) 38 total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
  1 +package company
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  8 +
  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 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type SystemCompanyPositionsSearchLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewSystemCompanyPositionsSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCompanyPositionsSearchLogic {
  22 + return &SystemCompanyPositionsSearchLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *SystemCompanyPositionsSearchLogic) SystemCompanyPositionsSearch(req *types.CompanyPositionsSearchRequest) (resp *types.CompanyPositionsSearchResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  33 + users []*domain.User
  34 + total int64
  35 + )
  36 + resp = &types.CompanyPositionsSearchResponse{
  37 + List: make([]types.Position, 0),
  38 + }
  39 + total, users, err = l.svcCtx.UserRepository.FindCompanyPositions(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithFindOnly())
  40 + if err != nil {
  41 + return nil, xerr.NewErrMsgErr("查找公司部门失败", err)
  42 + }
  43 +
  44 + for _, user := range users {
  45 + resp.List = append(resp.List, types.Position{
  46 + Name: user.Position,
  47 + })
  48 + }
  49 + resp.Total = total
  50 + return
  51 +}
@@ -72,9 +72,13 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini @@ -72,9 +72,13 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini
72 Roles: make([]int64, 0), 72 Roles: make([]int64, 0),
73 Follower: make([]int64, 0), 73 Follower: make([]int64, 0),
74 Following: make([]int64, 0), 74 Following: make([]int64, 0),
75 - AccountFrom: domain.AccountFromQr, 75 + AccountFrom: domain.AccountFromSearchJoin,
76 Departments: make([]int64, 0), 76 Departments: make([]int64, 0),
77 } 77 }
  78 + if req.IsFromQr {
  79 + user.AuditStatus = domain.UserAuditStatusPassed
  80 + user.AccountFrom = domain.AccountFromQr
  81 + }
78 user.WithName(name) 82 user.WithName(name)
79 if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil { 83 if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil {
80 return err 84 return err
@@ -36,14 +36,15 @@ func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest) @@ -36,14 +36,15 @@ func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest)
36 ) 36 )
37 queryOptions := domain.NewQueryOptions(). 37 queryOptions := domain.NewQueryOptions().
38 WithOffsetLimit(req.Page, req.Size). 38 WithOffsetLimit(req.Page, req.Size).
39 - MustWithKV("companyId", userToken.CompanyId) 39 + MustWithKV("companyId", userToken.CompanyId).
  40 + MustWithKV("accountFrom", []string{domain.AccountFromSearchJoin})
40 if req.AuditFlag != nil && *req.AuditFlag >= 0 { 41 if req.AuditFlag != nil && *req.AuditFlag >= 0 {
41 queryOptions.MustWithKV("auditStatus", []int{*req.AuditFlag}) 42 queryOptions.MustWithKV("auditStatus", []int{*req.AuditFlag})
42 } 43 }
43 if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil { 44 if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil {
44 return nil, xerr.NewErrMsgErr("查询审核列表失败", err) 45 return nil, xerr.NewErrMsgErr("查询审核列表失败", err)
45 } 46 }
46 - resp = &types.UserSearchResponse{Total: total} 47 + resp = &types.UserSearchResponse{Total: total, List: make([]*types.UserItem, 0)}
47 lo.ForEach(users, func(item *domain.User, index int) { 48 lo.ForEach(users, func(item *domain.User, index int) {
48 company, _ := domain.LazyLoad(companyMap, l.ctx, conn, item.CompanyId, l.svcCtx.CompanyRepository.FindOne) 49 company, _ := domain.LazyLoad(companyMap, l.ctx, conn, item.CompanyId, l.svcCtx.CompanyRepository.FindOne)
49 resp.List = append(resp.List, NewUserItemSimple(item, company)) 50 resp.List = append(resp.List, NewUserItemSimple(item, company))
@@ -29,11 +29,11 @@ func NewMiniUserNewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini @@ -29,11 +29,11 @@ func NewMiniUserNewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
29 29
30 func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *types.MiniUserNewsResposne, err error) { 30 func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *types.MiniUserNewsResposne, err error) {
31 var ( 31 var (
32 - conn = l.svcCtx.DefaultDBConn()  
33 - user *domain.User  
34 - userToken = contextdata.GetUserTokenFromCtx(l.ctx)  
35 - articles []*domain.Article  
36 - readedArticles = make([]*domain.UserReadArticle, 0) 32 + conn = l.svcCtx.DefaultDBConn()
  33 + user *domain.User
  34 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  35 + articles []*domain.Article
  36 + readArticles = make([]*domain.UserReadArticle, 0)
37 ) 37 )
38 if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { 38 if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
39 return nil, xerr.NewErrMsgErr("用户不存在", err) 39 return nil, xerr.NewErrMsgErr("用户不存在", err)
@@ -55,9 +55,9 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * @@ -55,9 +55,9 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
55 }) 55 })
56 if len(articleIds) > 0 { 56 if len(articleIds) > 0 {
57 resp.LastArticleId = articleIds[len(articleIds)-1] 57 resp.LastArticleId = articleIds[len(articleIds)-1]
58 - _, readedArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithKV("articleIds", articleIds)) 58 + _, readArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithKV("articleIds", articleIds))
59 } 59 }
60 - readArticlesMap := lo.KeyBy(readedArticles, func(item *domain.UserReadArticle) int64 { 60 + readArticlesMap := lo.KeyBy(readArticles, func(item *domain.UserReadArticle) int64 {
61 return item.ArticleId 61 return item.ArticleId
62 }) 62 })
63 lo.ForEach(articles, func(item *domain.Article, index int) { 63 lo.ForEach(articles, func(item *domain.Article, index int) {
@@ -137,14 +137,14 @@ type SystemArticleCommentSearchMeResponse struct { @@ -137,14 +137,14 @@ type SystemArticleCommentSearchMeResponse struct {
137 } 137 }
138 138
139 type SystemArticleCommentSearchRequest struct { 139 type SystemArticleCommentSearchRequest struct {
140 - Page int `json:"page"`  
141 - Size int `json:"size"`  
142 - ArticleId int64 `json:"articleId"` // 文章ID  
143 - TopId int64 `json:"topId,optional"` // 文章顶层ID  
144 - AuthorId int64 `json:"authorId,optional"` // 用户  
145 - Show int `json:"show,optional"` // 显示状态  
146 - BeginTime int64 `json:"beginTime,optional"` // 开始时间  
147 - EndTime int64 `json:"endTime,optional"` // 结束时间 140 + Page int `json:"page"`
  141 + Size int `json:"size"`
  142 + ArticleId int64 `json:"articleId"` // 文章ID
  143 + TopId int64 `json:"topId,optional"` // 文章顶层ID
  144 + Author string `json:"author,optional"` // 用户
  145 + Show int `json:"show,optional"` // 显示状态
  146 + BeginTime int64 `json:"beginTime,optional"` // 开始时间
  147 + EndTime int64 `json:"endTime,optional"` // 结束时间
148 } 148 }
149 149
150 type SystemArticleCommentSearchResponse struct { 150 type SystemArticleCommentSearchResponse struct {
@@ -432,8 +432,9 @@ type MiniUserInfoResponse struct { @@ -432,8 +432,9 @@ type MiniUserInfoResponse struct {
432 } 432 }
433 433
434 type MiniUserApplyJoinCompanyRequest struct { 434 type MiniUserApplyJoinCompanyRequest struct {
435 - Phone string `json:"phone"`  
436 - Code string `json:"code"` 435 + Phone string `json:"phone"`
  436 + Code string `json:"code"`
  437 + IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加
437 } 438 }
438 439
439 type MiniUserApplyJoinCompanyResponse struct { 440 type MiniUserApplyJoinCompanyResponse struct {
@@ -726,6 +727,18 @@ type Company struct { @@ -726,6 +727,18 @@ type Company struct {
726 Logo string `json:"logo,omitempty"` // 公司LOGO 727 Logo string `json:"logo,omitempty"` // 公司LOGO
727 } 728 }
728 729
  730 +type CompanyPositionsSearchRequest struct {
  731 +}
  732 +
  733 +type CompanyPositionsSearchResponse struct {
  734 + List []Position `json:"list"`
  735 + Total int64 `json:"total"`
  736 +}
  737 +
  738 +type Position struct {
  739 + Name string `json:"name"`
  740 +}
  741 +
729 type Location struct { 742 type Location struct {
730 Longitude float64 `json:"longitude,optional"` //经度 743 Longitude float64 `json:"longitude,optional"` //经度
731 Latitude float64 `json:"latitude,optional"` //纬度 744 Latitude float64 `json:"latitude,optional"` //纬度
@@ -149,6 +149,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans @@ -149,6 +149,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
149 if v, ok := queryOptions["endCreatedAt"]; ok { 149 if v, ok := queryOptions["endCreatedAt"]; ok {
150 tx = tx.Where("created_at < ?", v) 150 tx = tx.Where("created_at < ?", v)
151 } 151 }
  152 + if v, ok := queryOptions["fromUserName"]; ok && v.(string) != "" {
  153 + tx = tx.Where(`from_user #>> '{"name"}' like ?`, "%"+v.(string)+"%")
  154 + }
152 155
153 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 156 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
154 return dms, tx.Error 157 return dms, tx.Error
@@ -155,6 +155,9 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con @@ -155,6 +155,9 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
155 if v, ok := queryOptions["auditStatus"]; ok { 155 if v, ok := queryOptions["auditStatus"]; ok {
156 tx.Where("audit_status in (?)", v) 156 tx.Where("audit_status in (?)", v)
157 } 157 }
  158 + if v, ok := queryOptions["accountFrom"]; ok {
  159 + tx.Where("account_from in (?)", v)
  160 + }
158 161
159 // 列表查询条件 162 // 列表查询条件
160 if v, ok := queryOptions["likeName"]; ok { 163 if v, ok := queryOptions["likeName"]; ok {
@@ -236,6 +239,41 @@ func (repository *UserRepository) FindDepartmentUsers(ctx context.Context, conn @@ -236,6 +239,41 @@ func (repository *UserRepository) FindDepartmentUsers(ctx context.Context, conn
236 return total, dms, nil 239 return total, dms, nil
237 } 240 }
238 241
  242 +func (repository *UserRepository) FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.User, error) {
  243 + var (
  244 + tx = conn.DB()
  245 + ms []*models.User
  246 + dms = make([]*domain.User, 0)
  247 + total int64
  248 + )
  249 + queryFunc := func() (interface{}, error) {
  250 + tx = tx.Model(&ms)
  251 + tx.Select("distinct position")
  252 + tx.Where("company_id = ?", companyId)
  253 + tx.Where("position <> ''")
  254 + tx.Where("audit_status in (?)", domain.UserAuditStatusPassed)
  255 + tx.Where("enable = ?", domain.UserEnable)
  256 + tx.Order("position asc")
  257 + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
  258 + return dms, tx.Error
  259 + }
  260 + return dms, nil
  261 + }
  262 +
  263 + if _, err := repository.Query(queryFunc); err != nil {
  264 + return 0, nil, err
  265 + }
  266 +
  267 + for _, item := range ms {
  268 + if dm, err := repository.ModelToDomainModel(item); err != nil {
  269 + return 0, dms, err
  270 + } else {
  271 + dms = append(dms, dm)
  272 + }
  273 + }
  274 + return total, dms, nil
  275 +}
  276 +
239 func (repository *UserRepository) ModelToDomainModel(from *models.User) (*domain.User, error) { 277 func (repository *UserRepository) ModelToDomainModel(from *models.User) (*domain.User, error) {
240 to := &domain.User{} 278 to := &domain.User{}
241 err := copier.Copy(to, from) 279 err := copier.Copy(to, from)
@@ -40,6 +40,7 @@ type UserRepository interface { @@ -40,6 +40,7 @@ type UserRepository interface {
40 FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error) 40 FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error)
41 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error) 41 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error)
42 FindDepartmentUsers(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error) 42 FindDepartmentUsers(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error)
  43 + FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error)
43 } 44 }
44 45
45 func (m *User) Identify() interface{} { 46 func (m *User) Identify() interface{} {
@@ -68,8 +69,9 @@ const ( @@ -68,8 +69,9 @@ const (
68 ) 69 )
69 70
70 const ( 71 const (
71 - AccountFromQr = "扫码注册"  
72 - AccountFromMr = "后台新增" 72 + AccountFromSearchJoin = "搜索添加"
  73 + AccountFromQr = "扫码注册"
  74 + AccountFromMr = "后台新增"
73 ) 75 )
74 76
75 const ( 77 const (