作者 庄敏学
正在显示 38 个修改的文件 包含 651 行增加373 行删除
... ... @@ -75,9 +75,11 @@ service Core {
@doc "小程序首页数据展示"
@handler MiniShowHomePage
get /show/home_page (MiniHomePageRequest) returns (MiniHomePageRespose)
get /show/home_page (MiniHomePageRequest) returns (MiniHomePageResponse)
@doc "小程序首页搜索文章"
@handler MiniSearchArticlePage
post /show/search_article (MiniSearchArticleRequest) returns (MiniSearchArticleResponse)
}
// 管理后台接口
... ...
... ... @@ -53,9 +53,10 @@ type (
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Show int `json:"show"` // 评论的展示状态(1显示、2不显示)
Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
Tags []string `json:"tags"` //文章的标签
}
ArticleSection {
Id int64 `json:"id"` //段落id
... ... @@ -314,14 +315,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"`
}
)
... ... @@ -480,11 +481,12 @@ type (
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
MiniHomePageRespose {
Tags []ArticleTagCount `json:"tags"`
MiniHomePageResponse {
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"` // 标签名称
... ... @@ -492,4 +494,33 @@ type (
TotalArticle int `json:"totalArticle"` // 总的文章数量
ReadArticle int `json:"readArticle"` // 已读的标签数量
}
)
//小程序首页搜索文章
type (
MiniSearchArticleRequest {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
UserId int64 `json:",optional"`
TagGroup string `json:"tagGroup"`
TagId int64 `json:"tagId"`
BeginTime int64 `json:"beginTime"`
EndTime int `json:"endTime"`
SearchWord string `json:"searchWord"`
}
//
MiniSearchArticleResponse {
Total int `json:"total"`
List []MiniSearchArticleItem `json:"list"`
}
//
MiniSearchArticleItem{
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author string `json:"author"` // 发布人
Images []string `json:"images"`
CreatedAt int64 `json:"createdAt"`
MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读]
}
)
\ No newline at end of file
... ...
... ... @@ -33,6 +33,9 @@ service Core {
@doc "用户信息"
@handler miniUserInfo
post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse)
@doc "用户统计"
@handler miniUserStatistics
post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
@doc "用户审核列表"
@handler miniUserAuditList
post /mini/user/audit-list (UserSearchRequest)returns(UserSearchResponse)
... ... @@ -41,7 +44,10 @@ service Core {
post /mini/user/audit (MiniUserAuditRequest)
@doc "部门用户列表"
@handler miniUserDepartmentUsers
post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse)
post /mini/user/department-users (MiniUserDepartmentUsersRequest)
@doc "用户列表"
@handler miniUsersList
post /mini/user/user-list (MiniUsersListRequest)
@doc "关注我的人"
@handler miniUserFollower
post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse)
... ... @@ -105,6 +111,10 @@ type(
Departments []*Department `json:"departments"`
Users []*UserItem `json:"users"`
}
MiniUsersListRequest{
ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
}
MiniUserFollowedSearchRequest{
Page int `json:"page,optional"`
Size int `json:"size,optional"`
... ... @@ -117,6 +127,7 @@ type(
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
//DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
//Roles []int64 `json:"roleId,omitempty"` // 角色
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
... ... @@ -216,6 +227,9 @@ service Core {
@doc "用户统计"
@handler systemUserStatistics
post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
@doc "用户列表"
@handler systemUsersList
post /system/user/user-list (MiniUsersListRequest)
@doc "用户详情"
@handler systemUserGet
... ...
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"
)
func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSearchArticleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniSearchArticlePageLogic(r.Context(), svcCtx)
resp, err := l.MiniSearchArticlePage(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -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)
}
}
... ...
... ... @@ -159,6 +159,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/statistics",
Handler: user.MiniUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/audit-list",
Handler: user.MiniUserAuditListHandler(serverCtx),
},
... ... @@ -174,6 +179,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/user-list",
Handler: user.MiniUsersListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follower",
Handler: user.MiniUserFollowerHandler(serverCtx),
},
... ... @@ -217,6 +227,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: user.SystemUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/user/user-list",
Handler: user.SystemUsersListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/system/user/:id",
Handler: user.SystemUserGetHandler(serverCtx),
... ... @@ -379,6 +394,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/show/home_page",
Handler: article.MiniShowHomePageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/show/search_article",
Handler: article.MiniSearchArticlePageHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniUserStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserStatisticsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserStatisticsLogic(r.Context(), svcCtx)
resp, err := l.SystemUserStatistics(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUsersListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx)
resp, err := l.MiniAtUsersList(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUsersListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx)
resp, err := l.MiniAtUsersList(&req)
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
... ...
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"strconv"
"strings"
"text/template"
... ... @@ -9,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/samber/lo"
... ... @@ -52,13 +54,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
if len(req.Images) > 9 {
return nil, xerr.NewErrMsg("图片数量最多9张")
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
fInfo, _ := oss.GetImageInfo(val)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
Width: w,
Height: h,
})
}
... ... @@ -157,7 +162,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
CountLove: 0,
CountComment: 0,
CountRead: 0,
Show: 0,
Show: domain.ArticleShowEnable,
Tags: []int64{},
}
if len(whoRead) > 0 {
... ...
... ... @@ -38,9 +38,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
//TODO 检查可查看人
if articleInfo.Show == domain.ArticleShowDisable {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
... ... @@ -71,6 +69,14 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
meLoveFlag = 1
}
}
tags := []string{}
if len(articleInfo.Tags) > 0 {
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", articleInfo.Tags)
_, tagList, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption)
for _, val := range tagList {
tags = append(tags, val.Name)
}
}
sortBy := domain.SortArticleSection(sectionList)
sort.Sort(sortBy)
... ... @@ -111,6 +117,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
Show: int(articleInfo.Show),
Edit: 0,
MeLoveFlag: meLoveFlag,
Tags: tags,
}
if articleInfo.CreatedAt != articleInfo.UpdatedAt {
resp.Edit = 1
... ...
package article
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"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniSearchArticlePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic {
return &MiniSearchArticlePageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -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"
)
... ... @@ -23,8 +26,47 @@ 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
func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageResponse, err error) {
// 获取所有的标签
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.MiniHomePageResponse{
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,
})
})
}
... ...
... ... @@ -2,11 +2,14 @@ package article
import (
"context"
"strconv"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
... ... @@ -37,13 +40,16 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
//TODO 获取图片的尺寸大小
// 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
fInfo, _ := oss.GetImageInfo(val)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
Width: w,
Height: h,
})
}
//检查文章可被哪些人查看
... ...
... ... @@ -130,7 +130,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
CountReply: 0,
CountUserLove: 0,
CountAdminLove: 0,
Show: 0,
Show: domain.CommentShowEnable,
AtWho: []domain.UserSimple{},
}
... ...
... ... @@ -48,7 +48,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
var companyIdMap = map[int64]*domain.Company{}
var userIdMap = map[int64]*domain.User{}
var articleIdMap = map[int64]*domain.Article{}
var commentIdMap = map[int64]*domain.Comment{}
var commentIdMap = map[int64]*domain.ArticleComment{}
//var discussionIdMap = map[int64]int{}
//var discussionOpinionIdMap = map[int64]int{}
for _, item := range list {
... ... @@ -126,7 +126,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取评论
if len(commentIds) > 0 {
_, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
_, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", commentIds).
WithKV("limit", len(commentIds)))
... ... @@ -192,12 +192,12 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
}
}
if _, ok := commentIdMap[item.CommentId]; ok {
if v, ok := commentIdMap[item.CommentId]; ok {
to.Comment = &types.SimpleComment{
//Id: v.Id,
//Title: v.Title,
//CountLove: v.CountLove,
//CountComment: v.CountComment,
Id: v.Id,
Content: v.Content,
CountLove: v.CountUserLove,
CountComment: v.CountReply,
}
}
... ...
... ... @@ -3,10 +3,12 @@ package tags
import (
"context"
"fmt"
"strconv"
"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/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -41,8 +43,10 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
fInfo, _ := oss.GetImageInfo(req.Image)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
newTag := &domain.ArticleTag{
Id: 0,
CompanyId: req.CompanyId,
... ... @@ -52,8 +56,8 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
Version: 0,
Image: domain.Image{
Url: req.Image,
Width: 0,
Height: 0,
Width: w,
Height: h,
},
Name: req.Name,
Category: req.Category,
... ...
... ... @@ -3,10 +3,12 @@ package tags
import (
"context"
"fmt"
"strconv"
"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/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -52,11 +54,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("修改标签失败")
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
fInfo, _ := oss.GetImageInfo(req.Image)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
oldTag.Category = req.Category
oldTag.Image.Url = req.Image
oldTag.Image = domain.Image{
Url: req.Image,
Width: w,
Height: h,
}
oldTag.Name = req.Name
oldTag.Remark = req.Remark
oldTag.Other = req.Other
... ...
... ... @@ -46,19 +46,19 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.
var userMap = make(map[int64]*domain.User)
var articleMap = make(map[int64]*domain.Article)
var commentMap = make(map[int64]*domain.Comment)
var commentMap = make(map[int64]*domain.ArticleComment)
lo.ForEach(list, func(item *domain.UserLoveFlag, index int) {
var (
user *domain.User
article *domain.Article
comment *domain.Comment
comment *domain.ArticleComment
)
if item.CommentId != 0 { // 点赞评论
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne)
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.CommentRepository.FindOne)
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne)
} else {
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ArticleAuthor, l.svcCtx.UserRepository.FindOne)
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
... ... @@ -70,7 +70,7 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.
return
}
func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.Comment) types.MyLikeItem {
func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem {
item := types.MyLikeItem{
UserId: love.UserId,
ArticleId: love.ArticleId,
... ... @@ -101,10 +101,11 @@ func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain
if comment != nil {
item.Comment = &types.SimpleComment{
Id: comment.Id,
//Content: comment.Content,
//CountLove: comment.CountLove,
//CountComment: comment.CountComment,
Id: comment.Id,
Content: comment.Content,
CountLove: comment.CountUserLove,
CountComment: comment.CountReply,
Show: int(comment.Show),
}
}
... ...
... ... @@ -42,14 +42,21 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *
if _, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(user.CompanyId)().MustWithKV("ids", user.Roles)); err != nil {
return nil, xerr.NewErrMsgErr("角色不存在", err)
}
resp = &types.MiniUserInfoResponse{
User: &types.UserItem{
Id: user.Id,
Name: user.Name,
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
},
Accounts: make([]types.Account, 0),
Auths: make([]types.Auth, 0),
}
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
resp.User.CompanyName = company.Name
resp.User.CompanyCode = company.Code
}
_, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
if err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
... ...
package user
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"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniUserStatisticsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserStatisticsLogic {
return &MiniUserStatisticsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniUserStatisticsLogic) MiniUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package user
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 MiniAtUsersListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniAtUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniAtUsersListLogic {
return &MiniAtUsersListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest) (resp interface{}, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
article *domain.Article
users []*domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
onlyUsers []int64
)
if req.ArticleId != 0 {
if article, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId); err != nil {
return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
}
if article.TargetUser == domain.ArticleTargetLimit && len(article.WhoRead) > 0 {
onlyUsers = article.WhoRead
}
}
if _, users, err = l.svcCtx.UserRepository.FindDepartmentUsers(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithFindOnly()); err != nil {
return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
}
if len(onlyUsers) > 0 {
onlyUsersMap := lo.KeyBy(onlyUsers, func(item int64) int64 {
return item
})
users = lo.Filter(users, func(item *domain.User, index int) bool {
if _, ok := onlyUsersMap[item.Id]; ok {
return false
}
return true
})
}
var list = make([]*domain.User, 0)
lo.ForEach(users, func(item *domain.User, index int) {
list = append(list, &domain.User{
Id: item.Id,
Name: item.Name,
PinYinName: item.PinYinName,
})
})
return map[string]interface{}{
"list": list,
}, nil
}
... ...
package user
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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUsersListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUsersListLogic {
return &SystemUsersListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUsersListLogic) SystemUsersList(req *types.MiniUsersListRequest) error {
// todo: add your logic here and delete this line
return nil
}
... ...
... ... @@ -29,7 +29,6 @@ type ServiceContext struct {
ArticleAndTagRepository domain.ArticleAndTagRepository
CompanyRepository domain.CompanyRepository
CommentRepository domain.CommentRepository // 待移除
DepartmentRepository domain.DepartmentRepository
MessageBusinessRepository domain.MessageBusinessRepository
MessageSystemRepository domain.MessageSystemRepository
... ... @@ -60,7 +59,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
ApiAuthService: apiAuth,
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)),
... ...
... ... @@ -375,6 +375,11 @@ type MiniUserDepartmentUsersResponse struct {
Users []*UserItem `json:"users"`
}
type MiniUsersListRequest struct {
ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
}
type MiniUserFollowedSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
... ... @@ -389,6 +394,7 @@ type UserItem struct {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
Name string `json:"name,omitempty"` // 名称
Avatar string `json:"avatar,omitempty"` // 头像
... ... @@ -665,9 +671,10 @@ type MiniArticleGetResponse struct {
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Show int `json:"show"` // 评论的展示状态(1显示、2不显示)
Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
Tags []string `json:"tags"` //文章的标签
}
type ArticleSection struct {
... ... @@ -899,15 +906,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 {
... ... @@ -1053,12 +1060,13 @@ type MiniHomePageRequest struct {
UserId int64 `path:",optional"`
}
type MiniHomePageRespose struct {
Tags []ArticleTagCount `json:"tags"`
type MiniHomePageResponse struct {
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"` // 标签名称
... ... @@ -1067,6 +1075,32 @@ type ArticleTagCount struct {
ReadArticle int `json:"readArticle"` // 已读的标签数量
}
type MiniSearchArticleRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
UserId int64 `json:",optional"`
TagGroup string `json:"tagGroup"`
TagId int64 `json:"tagId"`
BeginTime int64 `json:"beginTime"`
EndTime int `json:"endTime"`
SearchWord string `json:"searchWord"`
}
type MiniSearchArticleResponse struct {
Total int `json:"total"`
List []MiniSearchArticleItem `json:"list"`
}
type MiniSearchArticleItem struct {
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author string `json:"author"` // 发布人
Images []string `json:"images"`
CreatedAt int64 `json:"createdAt"`
MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读]
}
type RoleGetRequest struct {
Id int64 `path:"id"`
}
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type Comment struct {
Id int64 // 唯一标识
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}
func (m *Comment) TableName() string {
return "t_comment"
}
func (m *Comment) BeforeCreate(tx *gorm.DB) (err error) {
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *Comment) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
return
}
func (m *Comment) CacheKeyFunc() string {
if m.Id == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *Comment) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*Comment); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *Comment) CachePrimaryKeyFunc() string {
if len("") == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
... ... @@ -136,24 +136,23 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic
// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) {
sqlStr := `
-- 首页统计数据
sqlStr := `-- 首页统计数据
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."show" =0
and (article.target_user =0 or article.who_read @>'[1]')
and article.company_id = ?
and article."show" = ?
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
... ... @@ -163,6 +162,7 @@ group by t_article_and_tag_2.tag_id
`
condition := []interface{}{
companyId,
domain.ArticleShowEnable,
fmt.Sprintf("[%d]", userId),
userId,
}
... ... @@ -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,
... ...
... ... @@ -279,11 +279,11 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
article_comment.id ,
(article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt
from article_comment
where top_id =0 and article_id =? and deleted_at=0 and show=0 and company_id=?
where top_id =0 and article_id =? and deleted_at=0 and show= ? and company_id=?
order by cnt desc,article_comment.id desc
limit 5 `
db := conn.DB()
rows, err := db.Raw(sql1, articleId, companyId).Rows()
rows, err := db.Raw(sql1, articleId, domain.CommentShowEnable, companyId).Rows()
if err != nil {
return nil, err
}
... ...
... ... @@ -278,27 +278,11 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor
return &ArticleRepository{CachedRepository: cache}
}
// -- 首页统计数据
// with
// -- 按查看权限查询文章
// -- 获取有标签的文章
// -- 过滤出可展示的文章id
// t_article_and_tag_2 as (
// 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."show" =0
// and (article.target_user =0 or article.who_read @>'[1]')
// ),
// -- 查询人员已查看的文章
// t_user_read as(
// select user_read_article.article_id from user_read_article where user_read_article.user_id =1
// )
// -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量
// select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id
// from t_article_and_tag_2
// left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id
// group by t_article_and_tag_2.tag_id
// ;
// select *
// from article
// join article_and_tag on article.id = article_and_tag.article_id
// where article."show" =1
// and article_and_tag.tag_id =any(select article_tag.id from article_tag where category ='分组三' )
// and article_and_tag.tag_id =0
// and article.created_at >=0 and article.created_at <=9000000000
// and article.title like '%%'
... ...
... ... @@ -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)
... ...
package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
)
type CommentRepository struct {
*cache.CachedRepository
}
func (repository *CommentRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.Comment) (*domain.Comment, error) {
var (
err error
m = &models.Comment{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *CommentRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.Comment) (*domain.Comment, error) {
var (
err error
m *models.Comment
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *CommentRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Comment) (*domain.Comment, error) {
var (
err error
m *models.Comment
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *CommentRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.Comment) (*domain.Comment, error) {
var (
tx = conn.DB()
m = &models.Comment{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *CommentRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.Comment, error) {
var (
err error
tx = conn.DB()
m = new(models.Comment)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.Comment)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *CommentRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Comment, error) {
var (
tx = conn.DB()
ms []*models.Comment
dms = make([]*domain.Comment, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *CommentRepository) ModelToDomainModel(from *models.Comment) (*domain.Comment, error) {
to := &domain.Comment{}
err := copier.Copy(to, from)
return to, err
}
func (repository *CommentRepository) DomainModelToModel(from *domain.Comment) (*models.Comment, error) {
to := &models.Comment{}
err := copier.Copy(to, from)
return to, err
}
func NewCommentRepository(cache *cache.CachedRepository) domain.CommentRepository {
return &CommentRepository{CachedRepository: cache}
}
... ... @@ -25,7 +25,7 @@ type Article struct {
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示
Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、
Tags []int64 `json:"tags"` // 定性标签
Summary string `json:"summary"` // 内容概要
// ...more
... ... @@ -60,12 +60,12 @@ func (a ArticleTarget) Named() string {
return ""
}
// 文章的展示状态(0显示、1不显示)
// 文章的展示状态(1显示,2不显示)
type ArticleShow int
const (
ArticleShowEnable ArticleShow = 0
ArticleShowDisable ArticleShow = 1
ArticleShowEnable ArticleShow = 1
ArticleShowDisable ArticleShow = 2
)
func (a ArticleShow) Named() string {
... ...
... ... @@ -27,17 +27,17 @@ type ArticleComment struct {
CountReply int `json:"countReply"` // 回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
Show CommentShow `json:"showState"` // 评论的展示状态(0显示、1不显示)
Show CommentShow `json:"showState"` // 评论的展示状态(1显示、2不显示)
AtWho []UserSimple `json:"atWho"` // 填写评论时@的人
// ...more
}
// 评论的展示状态(0显示、1不显示)
// 评论的展示状态(1显示、2不显示)
type CommentShow int
const (
CommentShowEnable CommentShow = 0
CommentShowDisable CommentShow = 1
CommentShowEnable CommentShow = 1
CommentShowDisable CommentShow = 2
)
func (show CommentShow) Named() string {
... ...
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
type Comment struct {
Id int64 // 唯一标识
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
}
type CommentRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error)
Update(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Comment, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Comment, error)
}
func (m *Comment) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
package oss
import (
"encoding/json"
"fmt"
"image"
_ "image/jpeg"
"net/http"
"strings"
"time"
)
type FileInfo struct {
FileSize struct {
Value string
}
Format struct {
Value string
}
ImageHeight struct {
Value string
}
ImageWidth struct {
Value string
}
}
func GetImageInfo(url string) (info FileInfo, err error) {
//ok := strings.HasPrefix(url, "https://timeless-world.oss-cn-shenzhen.aliyuncs.com")
ok := strings.HasPrefix(url, "http")
if !ok {
return
}
ok = strings.Contains(url, "aliyuncs")
if !ok {
return
}
apiUrl := url + `?x-oss-process=image/info`
req, err := http.NewRequest(http.MethodGet, apiUrl, nil)
if err != nil {
return info, err
}
httpclient := http.Client{
Timeout: 5 * time.Second,
}
resp, err := httpclient.Do(req)
if err != nil {
return info, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return
}
jDecoder := json.NewDecoder(resp.Body)
err = jDecoder.Decode(&info)
if err != nil {
return info, err
}
return info, nil
}
// 获取视频封面图
func GetVideoCover(videoUrl string) (coverUrl string, w int, h int, err error) {
ok := strings.HasPrefix(videoUrl, "http")
if !ok {
return
}
ok = strings.Contains(videoUrl, "aliyuncs")
if !ok {
return
}
videoUrl = videoUrl + "?x-oss-process=video/snapshot,t_100,f_jpg,m_fast"
httpclient := http.Client{
Timeout: 5 * time.Second,
}
res, err := httpclient.Get(videoUrl)
if err != nil || res.StatusCode != http.StatusOK {
return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err)
}
defer res.Body.Close()
m, _, err := image.Decode(res.Body)
if err != nil {
return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err)
}
return videoUrl, m.Bounds().Dx(), m.Bounds().Dy(), nil
}
... ...
package oss
import "testing"
func TestGetVideoCover(t *testing.T) {
cover, w, h, err := GetVideoCover("https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20230913/object/1694587897_yYfG6TYTsGMCKETxdnTEhAQjXpYGD3MB.mp4")
t.Logf("cover=%v, w=%v, h=%v, err=%v", cover, w, h, err)
}
... ...