作者 yangfu
正在显示 28 个修改的文件 包含 939 行增加8 行删除
FROM golang:1.19-alpine as builder
# Define the project name | 定义项目名称
ARG PROJECT=core
WORKDIR /build
COPY . .
RUN go env -w GO111MODULE=on \
&& go env -w GOPROXY=https://goproxy.cn,direct \
&& go env -w CGO_ENABLED=0 \
&& go env \
&& go mod tidy \
&& cd cmd/discuss/api \
&& go build -ldflags="-s -w" -o /build/api/${PROJECT} ${PROJECT}.go
FROM alpine:latest
# Define the project name | 定义项目名称
ARG PROJECT=core
# Define the config file name | 定义配置文件名
ARG CONFIG_FILE=core.yaml
# Define the author | 定义作者
ARG AUTHOR=785409885@qq.com
LABEL org.opencontainers.image.authors=${AUTHOR}
WORKDIR /app
ENV PROJECT=${PROJECT}
ENV CONFIG_FILE=${CONFIG_FILE}
COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/discuss/api/etc/${CONFIG_FILE} ./etc/
EXPOSE 8080
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
... ... @@ -56,6 +56,21 @@ service Core {
@handler SystemArticleCommentSearch
post /article_comment/search (SystemArticleCommentSearchRequest) returns (SystemArticleCommentSearchResponse)
@doc "管理后台查看所有的评论"
@handler SystemListAticleComment
post /article_comment/list (SystemListCommentRequest)returns (SystemListCommentResponse)
@doc "管理后台评论的详情"
@handler SystemGetAticleComment
get /article_comment/:id (SystemGetCommentRequest)returns (SystemGetCommentResponse)
@doc "管理后台变更评论的显示状态"
@handler SystemEditAticleCommentShow
post /article_comment/edit_show (SystemEditCommentShowRequest)returns (SystemEditCommentShowResponse)
@doc "管理后台变更评论"
@handler SystemEditAticleComment
post /article_comment/edit (SystemEditCommentRequest)returns (SystemEditCommentResponse)
}
//评论的填写人
... ... @@ -240,3 +255,90 @@ type (
Show int `json:"show"` // 显示状态
}
)
// 管理后台 评论管理列表
type (
SystemListCommentRequest {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间
ArticleTitle string `json:"articleTitle,optional"` //
Content string `json:"content,optional"` //
}
SystemListCommentResponse {
Total int `json:"total"`
List []SystemCommentItem `json:"list"`
}
SystemCommentItem {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
CreatedAt int64 `json:"createdAt"` //评论的填写时间
Content string `json:"content"` //评论的内容
Show int `json:"show"` //是否展示 [1显示] [2不显示]
CountReply int `json:"countReplay"` //回复数量
CountUserLove int `json:"countUserLove"` //用户点赞数量
CountAdminLove int `json:"countAdminLove"` //运营点赞数量
}
)
// 管理后台获取评论详情
type (
SystemGetCommentRequest {
CompanyId int64 `path:",optional"`
Id int64 `path:"id"`
}
SystemGetCommentResponse {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
CreatedAt int64 `json:"createdAt"` //评论的填写时间
SectionContent string `json:"sectionContent"` //引用的段落内容
Content string `json:"content"` // 评论的内容
Show int `json:"show"` //是否展示 [1显示] [2不显示]
CountReply int `json:"countReplay"` //回复数量
CountUserLove int `json:"countUserLove"` //用户点赞数量
CountAdminLove int `json:"countAdminLove"` //运营点赞数量
}
)
// 管理后台单独设置评论显示隐藏状态
type (
SystemEditCommentShowRequest {
CompanyId int64 `json:",optional"`
Id []int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
}
SystemEditCommentShowResponse {
Id []int64 `json:"id"`
}
)
// 管理后台变更评论
type (
SystemEditCommentRequest {
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
CountAdminLove int `json:"countAdminLove,optional"`
}
SystemEditCommentResponse {
Id int64 `json:"id"`
}
)
\ No newline at end of file
... ...
... ... @@ -4,6 +4,8 @@ Port: 8081
Verbose: true
Migrate: false
Timeout: 30000
# CertFile: ./key/fjmaimaimai.com_bundle.crt
# KeyFile: ./key/fjmaimaimai.com.key
Log:
#Mode: file
Encoding: plain
... ...
... ... @@ -16,7 +16,7 @@ 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)
result.HttpResult(r, w, nil, err)
return
}
... ...
package comment
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -14,7 +15,7 @@ func SystemArticleCommentSearchHandler(svcCtx *svc.ServiceContext) http.HandlerF
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleCommentSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
package comment
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -14,7 +15,7 @@ func SystemArticleCommentSearchMeHandler(svcCtx *svc.ServiceContext) http.Handle
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleCommentSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
package comment
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"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 SystemEditAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemEditCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := comment.NewSystemEditAticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.SystemEditAticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package comment
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"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 SystemEditAticleCommentShowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemEditCommentShowRequest
if err := httpx.Parse(r, &req); err != nil {
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewSystemEditAticleCommentShowLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.SystemEditAticleCommentShow(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package comment
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"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 SystemGetAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemGetCommentRequest
if err := httpx.Parse(r, &req); err != nil {
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewSystemGetAticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.SystemGetAticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package comment
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"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 SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemListCommentRequest
if err := httpx.Parse(r, &req); err != nil {
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewSystemListAticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.SystemListAticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -69,6 +69,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_comment/search",
Handler: comment.SystemArticleCommentSearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/list",
Handler: comment.SystemListAticleCommentHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_comment/:id",
Handler: comment.SystemGetAticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/edit_show",
Handler: comment.SystemEditAticleCommentShowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/edit",
Handler: comment.SystemEditAticleCommentHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
... ...
... ... @@ -38,6 +38,12 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini
return nil, xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
resp = &types.MiniDeleteArticleCommentResponse{
Id: commetInfo.Id,
}
return resp, nil
}
commetInfo.Show = domain.CommentShowDisable
// 变更回复数量
... ...
... ... @@ -25,6 +25,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
}
}
// 小程序端获取 根据文章id 获取评论列表
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
// 先获取最顶层的评论
var conn = l.svcCtx.DefaultDBConn()
... ...
package comment
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/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemEditAticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemEditAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentLogic {
return &SystemEditAticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 管理后台变更评论的设置
func (l *SystemEditAticleCommentLogic) SystemEditAticleComment(req *types.SystemEditCommentRequest) (resp *types.SystemEditCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
if commetInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有操作权限")
}
commetInfo.CountAdminLove = req.CountAdminLove
var increaseCount int
switch req.Show {
case 1:
// 设置为显示评论
if commetInfo.Show != domain.CommentShowEnable {
commetInfo.Show = domain.CommentShowEnable
increaseCount = 1
}
case 2:
// 设置为隐藏评论
if commetInfo.Show != domain.CommentShowDisable {
commetInfo.Show = domain.CommentShowDisable
increaseCount = -1
}
}
commetInfo.Show = domain.CommentShowEnable
// 变更回复数量
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
if err != nil {
return err
}
if increaseCount != 0 {
// 增加上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.Pid)
if err != nil {
return err
}
}
// 增加最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.TopId)
if err != nil {
return err
}
}
// 增加加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.SectionId)
if err != nil {
return err
}
}
// 增加文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.ArticleId)
if err != nil {
return err
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
resp = &types.SystemEditCommentResponse{
Id: commetInfo.Id,
}
return resp, nil
}
... ...
package comment
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/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemEditAticleCommentShowLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemEditAticleCommentShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentShowLogic {
return &SystemEditAticleCommentShowLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 管理后台,单独设置评论的隐藏显示
func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *types.SystemEditCommentShowRequest) (resp *types.SystemEditCommentShowResponse, err error) {
resp = &types.SystemEditCommentShowResponse{
Id: []int64{},
}
if req.Show == 1 {
for _, val := range req.Id {
err = l.enableShow(val, req.CompanyId)
if err != nil {
err = xerr.NewErrMsgErr("操作失败,刷新重试", err)
} else {
resp.Id = append(resp.Id, val)
}
}
}
if req.Show == 2 {
for _, val := range req.Id {
err = l.disableShow(val, req.CompanyId)
if err != nil {
err = xerr.NewErrMsgErr("操作失败,刷新重试", err)
} else {
resp.Id = append(resp.Id, val)
}
}
}
if err != nil {
return resp, err
}
return
}
func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyId int64) error {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.CompanyId != companyId {
return xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
return nil
}
commetInfo.Show = domain.CommentShowDisable
// 变更回复数量
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
if err != nil {
return err
}
}
// 减少最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId)
if err != nil {
return err
}
}
//减少加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
if err != nil {
return err
}
}
// 减少文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
return nil
}
func (l *SystemEditAticleCommentShowLogic) enableShow(commentId int64, companyId int64) error {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.CompanyId != companyId {
return xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowEnable {
return nil
}
commetInfo.Show = domain.CommentShowEnable
// 变更回复数量
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
if err != nil {
return err
}
// 增加上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, commetInfo.Pid)
if err != nil {
return err
}
}
// 增加最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, commetInfo.TopId)
if err != nil {
return err
}
}
//增加加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, 1, commetInfo.SectionId)
if err != nil {
return err
}
}
// 增加文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, commetInfo.ArticleId)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
return nil
}
... ...
package comment
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/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemGetAticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemGetAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemGetAticleCommentLogic {
return &SystemGetAticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGetCommentRequest) (resp *types.SystemGetCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论详情失败", err)
}
if commentInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
resp = &types.SystemGetCommentResponse{
Id: commentInfo.Id,
Pid: commentInfo.Pid,
TopId: commentInfo.TopId,
ArticleId: commentInfo.ArticleId,
ArticleTitle: "",
FromUserId: commentInfo.FromUserId,
FromUser: types.CommentAuthor{
Id: commentInfo.FromUserId,
Name: commentInfo.FromUser.Name,
Avatar: commentInfo.FromUser.Avatar,
Position: commentInfo.FromUser.Position,
Company: commentInfo.FromUser.Company,
},
CreatedAt: commentInfo.CreatedAt,
SectionContent: commentInfo.SectionContent,
Content: commentInfo.Content,
Show: int(commentInfo.Show),
CountReply: commentInfo.CountReply,
CountUserLove: commentInfo.CountUserLove,
CountAdminLove: commentInfo.CountAdminLove,
}
return resp, nil
}
... ...
package comment
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/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemListAticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic {
return &SystemListAticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 管理后台评论列表
func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.SystemListCommentRequest) (resp *types.SystemListCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size,
req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show,
)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论列表失败", err)
}
resp = &types.SystemListCommentResponse{
Total: cnt,
List: make([]types.SystemCommentItem, len(commentList)),
}
for i, val := range commentList {
resp.List[i] = types.SystemCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArticleTitle: val.ArticleTitle,
FromUserId: val.FromUserId,
FromUser: types.CommentAuthor{
Id: val.FromUser.Id,
Name: val.FromUser.Name,
Avatar: val.FromUser.Avatar,
Position: val.FromUser.Position,
Company: val.FromUser.Company,
},
CreatedAt: val.CreatedAt,
Content: val.Content,
Show: val.Show,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
CountAdminLove: val.CountAdminLove,
}
}
return resp, nil
}
... ...
... ... @@ -3,6 +3,8 @@ package user
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"
... ... @@ -10,7 +12,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -94,3 +95,10 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (
}
return
}
// 后台登录时 ,检查/设置公司的初始数据
func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
// TODO 初始设置文章标签
return nil
}
... ...
... ... @@ -168,6 +168,83 @@ type SystemArticleCommentSearchItem struct {
Show int `json:"show"` // 显示状态
}
type SystemListCommentRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间
ArticleTitle string `json:"articleTitle,optional"` //
Content string `json:"content,optional"` //
}
type SystemListCommentResponse struct {
Total int `json:"total"`
List []SystemCommentItem `json:"list"`
}
type SystemCommentItem struct {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
CreatedAt int64 `json:"createdAt"` //评论的填写时间
Content string `json:"content"` //评论的内容
Show int `json:"show"` //是否展示 [1显示] [2不显示]
CountReply int `json:"countReplay"` //回复数量
CountUserLove int `json:"countUserLove"` //用户点赞数量
CountAdminLove int `json:"countAdminLove"` //运营点赞数量
}
type SystemGetCommentRequest struct {
CompanyId int64 `path:",optional"`
Id int64 `path:"id"`
}
type SystemGetCommentResponse struct {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
CreatedAt int64 `json:"createdAt"` //评论的填写时间
SectionContent string `json:"sectionContent"` //引用的段落内容
Content string `json:"content"` // 评论的内容
Show int `json:"show"` //是否展示 [1显示] [2不显示]
CountReply int `json:"countReplay"` //回复数量
CountUserLove int `json:"countUserLove"` //用户点赞数量
CountAdminLove int `json:"countAdminLove"` //运营点赞数量
}
type SystemEditCommentShowRequest struct {
CompanyId int64 `json:",optional"`
Id []int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
}
type SystemEditCommentShowResponse struct {
Id []int64 `json:"id"`
}
type SystemEditCommentRequest struct {
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
CountAdminLove int `json:"countAdminLove,optional"`
}
type SystemEditCommentResponse struct {
Id int64 `json:"id"`
}
type MessageSystemRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ...
... ... @@ -70,3 +70,18 @@ func (m *ArticleComment) CachePrimaryKeyFunc() string {
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
type ArticleCommentShow struct {
Id int64 //评论id
Pid int64
TopId int64
ArticleTitle string //文章标题
FromUserId int64 // 评论填写人的id
FromUser domain.UserSimple `gorm:"type:jsonb;serializer:json"`
Content string // 评论内容
CountReply int // 回复数量
CountUserLove int // 用户点赞数量
CountAdminLove int // 运营点赞数量
Show int // 评论的展示状态(0显示、1不显示)
CreatedAt int64 // 评论的创建时间
}
... ...
... ... @@ -325,6 +325,98 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
}
return dms, nil
}
func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserName string, show int) (int, []*domain.ArticleCommentShow, error) {
if size <= 0 {
size = 20
}
if page <= 0 {
page = 1
}
where := " and article_comment.company_id=? "
condition := []interface{}{companyId}
if len(articleTitle) > 0 {
where += ` and article.title like ? `
condition = append(condition, "%"+articleTitle+"%")
}
if len(contentLike) > 0 {
where += ` and article_comment."content" like ? `
condition = append(condition, "%"+contentLike+"%")
}
if len(fromUserName) > 0 {
where += ` and article_comment.from_user ->>'name' like ? `
condition = append(condition, "%"+fromUserName+"%")
}
if show > 0 {
where += ` and article_comment."show" =? `
condition = append(condition, show)
}
if topId >= 0 {
where += ` and article_comment."top_id"= ? `
condition = append(condition, topId)
}
countSql := `select
count(*)
from article_comment
join article on article.id = article_comment.article_id
where 1=1 ` + where
var cnt int
db := conn.DB()
result := db.Raw(countSql, condition...).Scan(&cnt)
if result.Error != nil {
return 0, nil, result.Error
}
dataSql := `select
article.title as article_title ,
article_comment.id ,
article_comment.pid,
article_comment.top_id,
article_comment.from_user_id ,
article_comment.from_user,
article_comment."content" ,
article_comment.created_at ,
article_comment.count_reply ,
article_comment.count_user_love ,
article_comment.count_admin_love ,
article_comment."show"
from article_comment
join article on article.id = article_comment.article_id
where 1=1` + where + ` order by article_comment.id desc limit ? offset ? `
condition = append(condition, size, (page-1)*size)
ms := []models.ArticleCommentShow{}
result = db.Raw(dataSql, condition...).Scan(&ms)
if result.Error != nil {
return 0, nil, result.Error
}
d := []*domain.ArticleCommentShow{}
for _, val := range ms {
d = append(d, &domain.ArticleCommentShow{
ArticleTitle: val.ArticleTitle,
Id: val.Id,
FromUserId: val.FromUserId,
FromUser: val.FromUser,
Content: val.Content,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
CountAdminLove: val.CountAdminLove,
Show: val.Show,
CreatedAt: val.CreatedAt,
})
}
return cnt, d, nil
}
func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository {
return &ArticleCommentRepository{CachedRepository: cache}
}
... ...
... ... @@ -435,7 +435,7 @@ func (repository *ArticleRepository) CustomSearchBy(ctx context.Context, conn tr
tx = tx.Where("article_and_tag.tag_id=?", tagId)
} else if len(tagCategory) > 0 {
tx = tx.Joins(`join article_and_tag on article.id = article_and_tag.article_id`)
tx = tx.Where(`article_and_tag.tag_id =any(select article_tag.id from article_tag where category =%s )`, tagCategory)
tx = tx.Where(`article_and_tag.tag_id =any(select article_tag.id from article_tag where category =? )`, tagCategory)
}
if len(titleLike) > 0 {
tx = tx.Where("article.title like ?", "%"+titleLike+"%")
... ...
... ... @@ -33,6 +33,8 @@ func (repository *ArticleTagRepository) Insert(ctx context.Context, conn transac
}
// func (repository *ArticleTagRepository) CreateInBatches
func (repository *ArticleTagRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleTag) (*domain.ArticleTag, error) {
var (
err error
... ...
... ... @@ -50,6 +50,21 @@ func (show CommentShow) Named() string {
return ""
}
type ArticleCommentShow struct {
Id int64 // 评论id
Pid int64
TopId int64
ArticleTitle string // 文章标题
FromUserId int64 // 评论填写人的id
FromUser UserSimple // 评论填写人
Content string // 评论内容
CountReply int // 回复数量
CountUserLove int // 用户点赞数量
CountAdminLove int // 运营点赞数量
Show int // 评论的展示状态(0显示、1不显示)
CreatedAt int64 // 评论的创建时间
}
type ArticleCommentRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
... ... @@ -60,4 +75,7 @@ type ArticleCommentRepository interface {
IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error //点赞数量变动
IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error // 评论回复数量变动
Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error)
// 特定的查询
CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserName string, show int) (int, []*ArticleCommentShow, error)
}
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
if [ "$?" == "0" ];then
echo "sumifcc-discuss service install success!"
else
echo "sumifcc-discuss service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
if [ "$?" == "0" ];then
echo "sumifcc-discuss deployment install success!"
else
echo "sumifcc-discuss deployment install fail!"
fi
else
kubectl delete -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
done
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
done
kubectl create -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
if [ "$?" == "0" ];then
echo "sumifcc-discuss service update success!"
else
echo "sumifcc-discuss service update fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
if [ "$?" == "0" ];then
echo "sumifcc-discuss deployment update success!"
else
echo "sumifcc-discuss deployment update fail!"
fi
fi
\ No newline at end of file
... ...
... ... @@ -10,7 +10,7 @@ type Auth struct {
}
type Config struct {
DB struct {
DataSource string
DataSource string `json:",env=DataSource"`
} `json:",optional"`
Cache cache.CacheConf `json:",optional"`
DTM DTM `json:",optional"`
... ...