作者 tangxvhui

小程序首页数据展示

... ... @@ -314,14 +314,14 @@ type (
TagGroup []ArticleTagGroup `json:"tagGroup"`
}
ArticleTagGroup {
Group string `json:"group"`
Category string `json:"category"`
Tags []ArticleTagItem `json:"tags"`
}
ArticleTagItem {
Id int64 `json:"id"`
Group string `json:"group"`
Name string `json:"name"`
Image string `json:"image"`
Id int64 `json:"id"`
Category string `json:"category"`
Name string `json:"name"`
Image string `json:"image"`
}
)
... ... @@ -466,10 +466,11 @@ type (
UserId int64 `path:",optional"`
}
MiniHomePageRespose {
Tags []ArticleTagCount `json:"tags"`
TagCategory []string `json:"tagCategory"`
Tags []ArticleTagCount `json:"tags"`
}
ArticleTagCount {
TagGroup string `json:"tagGroup"` // 标签分组
TagCategory string `json:"tagCategory"` // 标签分组
TagId int64 `json:"tagId"` // 标签id
TagImage string `json:"tagImage"` // 对应的图标
TagName string `json:"tagName"` // 标签名称
... ...
... ... @@ -3,26 +3,27 @@ package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"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/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
// 展示小程序端首页的数据
func MiniShowHomePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniHomePageRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
// if err := httpx.Parse(r, &req); err != nil {
// httpx.ErrorCtx(r.Context(), w, err)
// return
// }
l := article.NewMiniShowHomePageLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.UserId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniShowHomePage(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -38,20 +38,20 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
for _, val := range tagList {
if m, ok := tagMap[val.Category]; ok {
m = append(m, types.ArticleTagItem{
Id: val.Id,
Group: val.Category,
Name: val.Name,
Image: val.Image.Url,
Id: val.Id,
Category: val.Category,
Name: val.Name,
Image: val.Image.Url,
})
tagMap[val.Category] = m
} else {
group = append(group, val.Category)
tagMap[val.Category] = []types.ArticleTagItem{
{
Id: val.Id,
Group: val.Category,
Name: val.Name,
Image: val.Image.Url,
Id: val.Id,
Category: val.Category,
Name: val.Name,
Image: val.Image.Url,
},
}
}
... ... @@ -61,8 +61,8 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
}
for i := range group {
resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{
Group: group[i],
Tags: tagMap[group[i]],
Category: group[i],
Tags: tagMap[group[i]],
})
}
return resp, nil
... ...
... ... @@ -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
}
... ...
... ... @@ -2,6 +2,7 @@ package article
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/xerr"
... ... @@ -71,10 +72,10 @@ func (l *SystemGetArticleLogic) SystemGetArticle(req *types.SystemArticleGetRequ
if err == nil && len(tags) > 0 {
lo.ForEach(tags, func(tag *domain.ArticleTag, index int) {
resp.Tags = append(resp.Tags, types.ArticleTagItem{
Id: tag.Id,
Group: tag.Category,
Name: tag.Name,
Image: tag.Image.Url,
Id: tag.Id,
Category: tag.Category,
Name: tag.Name,
Image: tag.Image.Url,
})
})
}
... ...
... ... @@ -849,15 +849,15 @@ type MiniAllArticleTagResponse struct {
}
type ArticleTagGroup struct {
Group string `json:"group"`
Tags []ArticleTagItem `json:"tags"`
Category string `json:"category"`
Tags []ArticleTagItem `json:"tags"`
}
type ArticleTagItem struct {
Id int64 `json:"id"`
Group string `json:"group"`
Name string `json:"name"`
Image string `json:"image"`
Id int64 `json:"id"`
Category string `json:"category"`
Name string `json:"name"`
Image string `json:"image"`
}
type SystemArticleGetRequest struct {
... ... @@ -999,11 +999,12 @@ type MiniHomePageRequest struct {
}
type MiniHomePageRespose struct {
Tags []ArticleTagCount `json:"tags"`
TagCategory []string `json:"tagCategory"`
Tags []ArticleTagCount `json:"tags"`
}
type ArticleTagCount struct {
TagGroup string `json:"tagGroup"` // 标签分组
TagCategory string `json:"tagCategory"` // 标签分组
TagId int64 `json:"tagId"` // 标签id
TagImage string `json:"tagImage"` // 对应的图标
TagName string `json:"tagName"` // 标签名称
... ...
... ... @@ -143,17 +143,17 @@ with
-- 获取有标签的文章
-- 过滤出可展示的文章id
t_article_and_tag_2 as (
select article_and_tag.article_id , article_and_tag.tag_id
select article_and_tag.article_id,article_and_tag.tag_id
from article_and_tag
join article on article_and_tag.article_id = article.id
where article.deleted_at=0
and article.company_id =1598224576532189184
and article.company_id =?
and article."show" =0
and (article.target_user =0 or article.who_read @>'[1]')
and (article.target_user =0 or article.who_read @> ?)
),
-- 查询人员已查看的文章
t_user_read as(
select user_read_article.article_id from user_read_article where user_read_article.user_id =1
select user_read_article.article_id from user_read_article where user_read_article.user_id =?
)
-- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量
select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id
... ... @@ -175,7 +175,6 @@ group by t_article_and_tag_2.tag_id
}
var dm []*domain.CountArticleTagRead
for _, val := range m {
dm = append(dm, &domain.CountArticleTagRead{
TagId: val.TagId,
... ...
... ... @@ -121,8 +121,7 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).
Where("company_id=?", companyId).
Order("id asc")
Where("company_id=?", companyId).Order("sort_by asc").Order("id asc")
if v, ok := queryOptions["name"]; ok {
tx = tx.Where("name like ?", v)
... ...