...
|
...
|
@@ -5,7 +5,10 @@ import ( |
|
|
|
|
|
"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/xerr"
|
|
|
|
|
|
"github.com/samber/lo"
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -24,7 +27,46 @@ func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) * |
|
|
}
|
|
|
|
|
|
func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageRespose, err error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
// 获取所有的标签
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
queryOption := domain.NewQueryOptions().WithFindOnly()
|
|
|
_, allTags, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取标签列表失败", err)
|
|
|
}
|
|
|
// 获取统计数据
|
|
|
countData, err := l.svcCtx.ArticleAndTagRepository.CountArticleReadGroupByTag(l.ctx, conn, req.UserId, req.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取文章汇总数量失败", err)
|
|
|
}
|
|
|
countDataMap := map[int64]*domain.CountArticleTagRead{}
|
|
|
for _, val := range countData {
|
|
|
countDataMap[val.TagId] = val
|
|
|
}
|
|
|
|
|
|
return
|
|
|
tagCategory := []string{}
|
|
|
tagCount := []types.ArticleTagCount{}
|
|
|
for _, val := range allTags {
|
|
|
tagCategory = append(tagCategory, val.Category)
|
|
|
m := types.ArticleTagCount{
|
|
|
TagCategory: val.Category,
|
|
|
TagId: val.Id,
|
|
|
TagImage: val.Image.Url,
|
|
|
TagName: val.Name,
|
|
|
TagRemark: val.Remark,
|
|
|
TotalArticle: 0,
|
|
|
ReadArticle: 0,
|
|
|
}
|
|
|
if count, ok := countDataMap[val.Id]; ok {
|
|
|
m.TotalArticle = count.TotalArticle
|
|
|
m.ReadArticle = count.ReadArticle
|
|
|
}
|
|
|
tagCount = append(tagCount, m)
|
|
|
}
|
|
|
tagCategory = lo.Uniq(tagCategory)
|
|
|
resp = &types.MiniHomePageRespose{
|
|
|
TagCategory: tagCategory,
|
|
|
Tags: tagCount,
|
|
|
}
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|