作者 tangxvhui
... ... @@ -29,12 +29,13 @@ func NewMiniCompanySearchJoinedLogic(ctx context.Context, svcCtx *svc.ServiceCon
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
conn = l.svcCtx.DefaultDBConn()
companyList []*domain.Company
total int64
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
user *domain.User
companyJoinedList []int64
companyJoiningList []int64
)
queryOptions := domain.NewQueryOptions()
if req.Page != 0 {
... ... @@ -53,15 +54,22 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
WithFindOnly())
lo.ForEach(users, func(item *domain.User, index int) {
companyIds = append(companyIds, item.CompanyId)
companyJoinedList = append(companyJoinedList, item.CompanyId)
})
_, users, _ = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", user.Phone).
MustWithKV("auditStatus", []int{domain.UserAuditStatusWait}).
WithFindOnly())
lo.ForEach(users, func(item *domain.User, index int) {
companyJoiningList = append(companyJoiningList, item.CompanyId)
})
if req.Flag == 1 {
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyIds))
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyJoinedList))
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
} else if req.Flag == 2 {
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds))
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyJoinedList))
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
}
... ... @@ -73,9 +81,13 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
}
lo.ForEach(companyList, func(item *domain.Company, index int) {
company := NewCompany(item)
if lo.Contains(companyIds, company.Id) {
company.JoinedFlag = 2
if lo.Contains(companyJoinedList, company.Id) {
company.JoinedFlag = 1
}
if lo.Contains(companyJoiningList, company.Id) {
company.JoinedFlag = 0
}
resp.List = append(resp.List, company)
})
resp.Total = total
... ...
... ... @@ -171,8 +171,8 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).
Where("company_id=?", companyId).
Where("author_id in (?)", authors).
Where(fmt.Sprintf("target_user=0 or who_read @>'[%d]'", whoRead)).
Where("author_id in (?)", append(authors, whoRead)). // 包含自己的文章
Where(fmt.Sprintf("author_id = %d or target_user=0 or who_read @>'[%d]'", whoRead, whoRead)).
Where("show = 1")
if lastId > 0 {
tx.Where("id < ?", lastId)
... ...