|
|
package company
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"github.com/samber/lo"
|
|
|
"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 MiniCompanySearchJoinedLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniCompanySearchJoinedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCompanySearchJoinedLogic {
|
|
|
return &MiniCompanySearchJoinedLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) {
|
|
|
var (
|
|
|
conn = l.svcCtx.DefaultDBConn()
|
|
|
companyList []*domain.Company
|
|
|
total int64
|
|
|
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
user *domain.User
|
|
|
companyIds []int64
|
|
|
)
|
|
|
queryOptions := domain.NewQueryOptions()
|
|
|
if req.Page != 0 {
|
|
|
queryOptions.WithOffsetLimit(req.Page, req.Size)
|
|
|
}
|
|
|
user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("账号有误", err)
|
|
|
}
|
|
|
resp = &types.CompanySearchResponse{
|
|
|
List: make([]types.Company, 0),
|
|
|
}
|
|
|
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
MustWithKV("phone", user.Phone).
|
|
|
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
|
|
|
WithFindOnly())
|
|
|
lo.ForEach(users, func(item *domain.User, index int) {
|
|
|
companyIds = append(companyIds, item.CompanyId)
|
|
|
})
|
|
|
if req.Flag == 1 {
|
|
|
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyIds))
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
|
|
|
}
|
|
|
} else {
|
|
|
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds))
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
|
|
|
}
|
|
|
}
|
|
|
lo.ForEach(companyList, func(item *domain.Company, index int) {
|
|
|
resp.List = append(resp.List, NewCompany(item))
|
|
|
})
|
|
|
resp.Total = total
|
|
|
return
|
|
|
} |
...
|
...
|
|