作者 yangfu

邀请注册

... ... @@ -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),
... ...
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))
... ...
... ... @@ -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"` //纬度
... ...
... ... @@ -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 (
... ...