article_security_search_logic.go 3.1 KB
package secuirty

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type ArticleSecuritySearchLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewArticleSecuritySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleSecuritySearchLogic {
	return &ArticleSecuritySearchLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ArticleSecuritySearchLogic) ArticleSecuritySearch(req *types.ArticleSecuritySearchRequest) (resp *types.ArticleSecuritySearchResponse, err error) {
	var (
		conn      = l.svcCtx.DefaultDBConn()
		dms       []*domain.ArticleSecurity
		total     int64
		userToken = contextdata.GetUserTokenFromCtx(l.ctx)
	)

	queryOptions := domain.IndexCompanyId(userToken.CompanyId)().WithOffsetLimit(req.Page, req.Size).
		WithKV("reviewStatus", req.ReviewStatus).
		WithKV("suggest", req.Suggest).
		WithKV("contentType", req.ContentType).
		WithKV("authorName", req.AuthorName).
		WithKV("beginTime", req.BeginTime).
		WithKV("endTime", req.EndTime)

	total, dms, err = l.svcCtx.ArticleSecurityRepository.Find(l.ctx, conn, queryOptions)
	list := make([]types.ArticleSecurityItem, 0)
	for i := range dms {
		list = append(list, NewTypesArticleSecurity(dms[i], nil))
	}
	resp = &types.ArticleSecuritySearchResponse{
		List:  list,
		Total: total,
	}
	return
}

func NewDomainArticleSecurity(item types.ArticleSecurityItem) *domain.ArticleSecurity {
	return &domain.ArticleSecurity{}
}

func NewTypesArticleSecurity(item *domain.ArticleSecurity, reviewer *domain.User) types.ArticleSecurityItem {
	result := types.ArticleSecurityItem{
		Id: item.Id,
		Content: types.ContentDetailItem{
			Id:   item.ContentId,
			Type: item.ContentType,
		},
		ContentKeyWords: strings.Join(item.ContentKeyWords, ","),
		Label:           item.Label,
		Prob:            item.Prob,
		Suggest:         describeSuggest(item.Suggest),
		Author:          item.AuthorName,
		ReviewAt:        item.CreatedAt,
		ReviewStatus:    item.ReviewStatus,
		ReleaseAt:       item.CreatedAt,
		Reviewer:        "",
	}
	if reviewer != nil {
		result.Reviewer = reviewer.Name
	}
	for _, detail := range item.Detail.Detail {
		if detail.Label.String() == "0" {
			continue
		}
		result.CheckList = append(result.CheckList, types.CheckDetailItem{
			Label:   detail.Label.String(),
			Prob:    detail.Prob,
			Suggest: describeSuggest(detail.Suggest),
		})
	}
	return result
}

func describeContentType(t int) string {
	if t == domain.TypeArticle {
		return "文本-帖子"
	}
	if t == domain.TypeComment {
		return "文本-评论"
	}
	return ""
}

func describeSuggest(s string) string {
	if s == "risk" {
		return "风险"
	}
	if s == "pass" {
		return "通过"
	}
	if s == "review" {
		return "人工审核"
	}
	return ""
}