作者 郑周

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

... ... @@ -5,4 +5,8 @@
### 可设置环境变量
- DataSource
数据库连接,样例 host=数据库IP地址 user=用户名 password=密码 dbname=数据库名 port=31543 sslmode=disable TimeZone=Asia/Shanghai
\ No newline at end of file
数据库连接,样例
``` code
host=数据库IP地址 user=用户名 password=密码 dbname=数据库名 port=31543 sslmode=disable TimeZone=Asia/Shanghai
```
\ No newline at end of file
... ...
... ... @@ -230,7 +230,7 @@ type (
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
AuthorId int64 `json:"authorId,optional"` // 用户
Author string `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
... ...
... ... @@ -42,6 +42,10 @@ service Core {
@doc "公司搜索"
@handler systemCompanySearch
post /system/company/search(CompanySearchRequest) returns (CompanySearchResponse)
@doc "公司职位搜索"
@handler systemCompanyPositionsSearch
post /system/company/positions/search(CompanyPositionsSearchRequest) returns (CompanyPositionsSearchResponse)
}
type (
... ... @@ -62,4 +66,18 @@ type (
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
}
)
// 公司职位搜索
type(
CompanyPositionsSearchRequest{
}
CompanyPositionsSearchResponse {
List []Position `json:"list"`
Total int64 `json:"total"`
}
Position{
Name string `json:"name"`
}
)
\ No newline at end of file
... ...
... ... @@ -105,6 +105,7 @@ type(
MiniUserApplyJoinCompanyRequest{
Phone string `json:"phone"`
Code string `json:"code"`
IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加
}
MiniUserApplyJoinCompanyResponse{
... ...
package company
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/company"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemCompanyPositionsSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CompanyPositionsSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := company.NewSystemCompanyPositionsSearchLogic(r.Context(), svcCtx)
resp, err := l.SystemCompanyPositionsSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -347,6 +347,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/system/company/search",
Handler: company.SystemCompanySearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/company/positions/search",
Handler: company.SystemCompanyPositionsSearchHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
... ...
... ... @@ -32,7 +32,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
WithOffsetLimit(req.Page, req.Size).
WithKV("articleId", req.ArticleId).
WithKV("topId", req.TopId).
WithKV("fromUserId", req.AuthorId).
WithKV("fromUserName", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
... ...
package company
import (
"context"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemCompanyPositionsSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemCompanyPositionsSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCompanyPositionsSearchLogic {
return &SystemCompanyPositionsSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemCompanyPositionsSearchLogic) SystemCompanyPositionsSearch(req *types.CompanyPositionsSearchRequest) (resp *types.CompanyPositionsSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
users []*domain.User
total int64
)
resp = &types.CompanyPositionsSearchResponse{
List: make([]types.Position, 0),
}
total, users, err = l.svcCtx.UserRepository.FindCompanyPositions(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithFindOnly())
if err != nil {
return nil, xerr.NewErrMsgErr("查找公司部门失败", err)
}
for _, user := range users {
resp.List = append(resp.List, types.Position{
Name: user.Position,
})
}
resp.Total = total
return
}
... ...
... ... @@ -72,9 +72,13 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini
Roles: make([]int64, 0),
Follower: make([]int64, 0),
Following: make([]int64, 0),
AccountFrom: domain.AccountFromQr,
AccountFrom: domain.AccountFromSearchJoin,
Departments: make([]int64, 0),
}
if req.IsFromQr {
user.AuditStatus = domain.UserAuditStatusPassed
user.AccountFrom = domain.AccountFromQr
}
user.WithName(name)
if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil {
return err
... ...
... ... @@ -36,14 +36,15 @@ func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest)
)
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("companyId", userToken.CompanyId)
MustWithKV("companyId", userToken.CompanyId).
MustWithKV("accountFrom", []string{domain.AccountFromSearchJoin})
if req.AuditFlag != nil && *req.AuditFlag >= 0 {
queryOptions.MustWithKV("auditStatus", []int{*req.AuditFlag})
}
if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErrMsgErr("查询审核列表失败", err)
}
resp = &types.UserSearchResponse{Total: total}
resp = &types.UserSearchResponse{Total: total, List: make([]*types.UserItem, 0)}
lo.ForEach(users, func(item *domain.User, index int) {
company, _ := domain.LazyLoad(companyMap, l.ctx, conn, item.CompanyId, l.svcCtx.CompanyRepository.FindOne)
resp.List = append(resp.List, NewUserItemSimple(item, company))
... ...
... ... @@ -29,11 +29,11 @@ func NewMiniUserNewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *types.MiniUserNewsResposne, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
articles []*domain.Article
readedArticles = make([]*domain.UserReadArticle, 0)
conn = l.svcCtx.DefaultDBConn()
user *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
articles []*domain.Article
readArticles = make([]*domain.UserReadArticle, 0)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
... ... @@ -55,9 +55,9 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
})
if len(articleIds) > 0 {
resp.LastArticleId = articleIds[len(articleIds)-1]
_, readedArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithKV("articleIds", articleIds))
_, readArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithKV("articleIds", articleIds))
}
readArticlesMap := lo.KeyBy(readedArticles, func(item *domain.UserReadArticle) int64 {
readArticlesMap := lo.KeyBy(readArticles, func(item *domain.UserReadArticle) int64 {
return item.ArticleId
})
lo.ForEach(articles, func(item *domain.Article, index int) {
... ...
... ... @@ -137,14 +137,14 @@ type SystemArticleCommentSearchMeResponse struct {
}
type SystemArticleCommentSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
AuthorId int64 `json:"authorId,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
type SystemArticleCommentSearchResponse struct {
... ... @@ -432,8 +432,9 @@ type MiniUserInfoResponse struct {
}
type MiniUserApplyJoinCompanyRequest struct {
Phone string `json:"phone"`
Code string `json:"code"`
Phone string `json:"phone"`
Code string `json:"code"`
IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加
}
type MiniUserApplyJoinCompanyResponse struct {
... ... @@ -726,6 +727,18 @@ type Company struct {
Logo string `json:"logo,omitempty"` // 公司LOGO
}
type CompanyPositionsSearchRequest struct {
}
type CompanyPositionsSearchResponse struct {
List []Position `json:"list"`
Total int64 `json:"total"`
}
type Position struct {
Name string `json:"name"`
}
type Location struct {
Longitude float64 `json:"longitude,optional"` //经度
Latitude float64 `json:"latitude,optional"` //纬度
... ...
... ... @@ -149,6 +149,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
if v, ok := queryOptions["endCreatedAt"]; ok {
tx = tx.Where("created_at < ?", v)
}
if v, ok := queryOptions["fromUserName"]; ok && v.(string) != "" {
tx = tx.Where(`from_user #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
... ...
... ... @@ -155,6 +155,9 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
if v, ok := queryOptions["auditStatus"]; ok {
tx.Where("audit_status in (?)", v)
}
if v, ok := queryOptions["accountFrom"]; ok {
tx.Where("account_from in (?)", v)
}
// 列表查询条件
if v, ok := queryOptions["likeName"]; ok {
... ... @@ -236,6 +239,41 @@ func (repository *UserRepository) FindDepartmentUsers(ctx context.Context, conn
return total, dms, nil
}
func (repository *UserRepository) FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.User, error) {
var (
tx = conn.DB()
ms []*models.User
dms = make([]*domain.User, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms)
tx.Select("distinct position")
tx.Where("company_id = ?", companyId)
tx.Where("position <> ''")
tx.Where("audit_status in (?)", domain.UserAuditStatusPassed)
tx.Where("enable = ?", domain.UserEnable)
tx.Order("position asc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *UserRepository) ModelToDomainModel(from *models.User) (*domain.User, error) {
to := &domain.User{}
err := copier.Copy(to, from)
... ...
... ... @@ -40,6 +40,7 @@ type UserRepository interface {
FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error)
FindDepartmentUsers(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error)
FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error)
}
func (m *User) Identify() interface{} {
... ... @@ -68,8 +69,9 @@ const (
)
const (
AccountFromQr = "扫码注册"
AccountFromMr = "后台新增"
AccountFromSearchJoin = "搜索添加"
AccountFromQr = "扫码注册"
AccountFromMr = "后台新增"
)
const (
... ...