作者 庄敏学
正在显示 30 个修改的文件 包含 1286 行增加138 行删除
... ... @@ -544,6 +544,7 @@ type (
MiniSearchArticleItem{
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
AuthorId int64 `json:"authorId"`
Author string `json:"author"` // 发布人
Avatar string `json:"avatar"`// 发布人的头像
Images []string `json:"images"`
... ...
... ... @@ -106,6 +106,7 @@ type (
CommentAtWho {
Id int64 `json:"id"`
Avatar string `json:"avatar,optional"` // 人员头像URL
Name string `json:"name,optional"`
FirstLetter string `json:"firstLetter,optional"`
}
... ... @@ -254,14 +255,14 @@ type (
// 文章里的评论列表
type (
SystemArticleCommentSearchRequest {
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
SystemArticleCommentSearchResponse {
Total int64 `json:"total"`
... ... @@ -362,10 +363,11 @@ type (
// 管理后台变更评论
type (
SystemEditCommentRequest {
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
CountAdminLove int `json:"countAdminLove,optional"`
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
Content string `json:"content,optional"`
CountAdminLove int `json:"countAdminLove,optional"`
}
SystemEditCommentResponse {
... ...
... ... @@ -55,6 +55,9 @@ service Core {
@doc "用户快讯"
@handler miniUserNews
post /mini/user/news (MiniUserNewsRequest)returns(MiniUserNewsResposne)
@doc "我关注人发布的信息"
@handler miniUserMyFollowingNews
post /mini/user/my_following_news (MiniUserNewsRequest)returns(MiniUserNewsResposne)
@doc "关注我的人"
@handler miniUserFollower
post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse)
... ...
... ... @@ -9,12 +9,13 @@ Timeout: 30000
LogRequest: true # 记录详细请求日志
Log:
#Mode: file
# Mode: file
Encoding: plain
Level: debug # info
MaxSize: 1 # 2MB
TimeFormat: 2006-01-02 15:04:05
#Rotation: size
Rotation: size
MaxContentLength: 10240
SystemAuth:
AccessSecret: digital-platform
... ...
... ... @@ -276,6 +276,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/my_following_news",
Handler: user.MiniUserMyFollowingNewsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follower",
Handler: user.MiniUserFollowerHandler(serverCtx),
},
... ...
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 MiniUserMyFollowingNewsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUserNewsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniUserMyFollowingNewsLogic(r.Context(), svcCtx)
resp, err := l.MiniUserMyFollowingNews(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -3,8 +3,10 @@ package article
import (
"context"
"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/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"
... ... @@ -14,15 +16,17 @@ import (
type MiniArticleMarkListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]*domain.User
}
func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleMarkListLogic {
return &MiniArticleMarkListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
userCache: make(map[int64]*domain.User, 0),
}
}
... ... @@ -36,10 +40,16 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar
if err != nil {
return nil, err
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.svcCtx.DefaultDBConn(), userToken.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章信息失败", err)
}
resp = &types.MiniArticleMarkListResponse{}
resp.Total = total
resp.List = make([]types.MiniArticleMarkItem, 0)
var author domain.User
for _, item := range list {
author = l.getAuthor(l.svcCtx.DefaultDBConn(), item.Author.Id)
to := types.MiniArticleMarkItem{
Id: item.Id,
CompanyId: item.CompanyId,
... ... @@ -48,10 +58,10 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar
Author: types.SimpleUser{
Id: item.Author.Id,
CompanyId: item.Author.CompanyId,
CompanyName: item.Author.Company,
Name: item.Author.Name,
Avatar: item.Author.Avatar,
Position: item.Author.Position,
CompanyName: companyInfo.Name,
Name: author.Name,
Avatar: author.Avatar,
Position: author.Position,
},
UpdatedAt: item.UpdatedAt,
}
... ... @@ -59,3 +69,15 @@ func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMar
}
return resp, nil
}
func (l *MiniArticleMarkListLogic) getAuthor(conn transaction.Conn, userid int64) domain.User {
if u, ok := l.userCache[userid]; ok {
return *u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
l.userCache[toUser.Id] = toUser
return *toUser
}
return domain.User{}
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"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"
)
... ... @@ -61,6 +62,7 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
}
articleAndTagList = append(articleAndTagList, articleAndTag)
}
tagIdList = lo.Union(tagIdList)
//更新article中的tags
articleInfo.Tags = tagIdList
// 查询可能存在的 ArticleAndTag
... ...
... ... @@ -35,15 +35,9 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext)
// 创建新文章
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查文字数量
wordNum := 0
for i := range req.Section {
num := utf8.RuneCountInString(req.Section[i])
wordNum += num
}
if wordNum >= 1000 {
return nil, xerr.NewErrMsgErr("最多只能输入1000字", err)
err = l.validateTextLimit(req)
if err != nil {
return nil, err
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
... ... @@ -181,19 +175,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
newArticle.MatchUrl[k] = v
}
//设置内容概要
if len(sectionList) > 0 {
// 截取内容 50个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
for i := range sectionList[0].Content {
if runeNumber > 50 {
break
}
runeNumber += 1
stringIndex = i
}
newArticle.Summary = sectionList[0].Content[0:stringIndex]
}
newArticle.SetSummary(sectionList)
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
... ... @@ -208,13 +190,6 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
return xerr.NewErrMsgErr("创建文章内容失败", err)
}
}
// 设置保存备份
// backup := newArticle.MakeBackup(newArticle.Author, sectionList)
// backup.Action = "新增"
// _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
// if err != nil {
// return xerr.NewErrMsgErr("创建文章内容失败", err)
// }
return nil
}, true)
if err != nil {
... ... @@ -226,3 +201,22 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
}
return
}
// validateTextLimit 验证输入文本长度
func (l *MiniCreateArticleLogic) validateTextLimit(req *types.MiniArticleCreateRequest) error {
titleWordNum := utf8.RuneCountInString(req.Title)
if titleWordNum > 64 {
return xerr.NewErrMsg("标题最多只能输入64字")
}
wordNum := 0
for i := range req.Section {
num := utf8.RuneCountInString(req.Section[i])
wordNum += num
}
if wordNum > 1000 {
return xerr.NewErrMsg("内容最多只能输入1000字")
}
return nil
}
... ...
... ... @@ -41,33 +41,36 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
if len(articleInfo.WhoRead) > 0 {
inWhoRead := false
for _, val := range articleInfo.WhoRead {
if req.UserId == int(val) {
inWhoRead = true
// 检查文章的可查看人
if articleInfo.AuthorId != int64(req.UserId) {
if len(articleInfo.WhoRead) > 0 {
inWhoRead := false
for _, val := range articleInfo.WhoRead {
if req.UserId == int(val) {
inWhoRead = true
}
}
}
if !inWhoRead {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
Id: articleInfo.Id,
Title: articleInfo.Title,
Show: int(domain.ArticleShowDisable),
if !inWhoRead {
// 文章内容不显示
// resp = &types.MiniArticleGetResponse{
// Id: articleInfo.Id,
// Title: articleInfo.Title,
// Show: int(domain.ArticleShowDisable),
// }
// return resp, nil
return nil, xerr.NewErrMsg("没有查看权限")
}
return resp, nil
}
}
if articleInfo.Show == domain.ArticleShowDisable {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
Id: articleInfo.Id,
Title: articleInfo.Title,
Show: int(domain.ArticleShowDisable),
}
return resp, nil
// resp = &types.MiniArticleGetResponse{
// Id: articleInfo.Id,
// Title: articleInfo.Title,
// Show: int(domain.ArticleShowDisable),
// }
// return resp, nil
return nil, xerr.NewErrMsg("没有查看权限")
}
queryOption := domain.NewQueryOptions().
... ... @@ -80,7 +83,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
}
//获取作者信息
author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.UserId))
author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(articleInfo.AuthorId))
var meLoveFlag int
if req.UserId > 0 {
... ...
... ... @@ -5,6 +5,7 @@ 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/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
... ... @@ -13,15 +14,17 @@ import (
type MiniSearchArticlePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]*domain.User
}
func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic {
return &MiniSearchArticlePageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
userCache: make(map[int64]*domain.User),
}
}
... ... @@ -63,11 +66,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
}
for i, val := range articleList {
author := l.getAuthor(conn, val.AuthorId)
item := types.MiniSearchArticleItem{
ArticleId: val.Id,
Title: val.Title,
Author: val.Author.Name,
Avatar: val.Author.Avatar,
AuthorId: val.AuthorId,
Author: author.Name,
Avatar: author.Avatar,
Images: []string{},
CreatedAt: val.CreatedAt,
MeReadFlag: 0,
... ... @@ -84,3 +89,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
return resp, nil
}
func (l *MiniSearchArticlePageLogic) getAuthor(conn transaction.Conn, userid int64) domain.User {
if u, ok := l.userCache[userid]; ok {
return *u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
l.userCache[toUser.Id] = toUser
return *toUser
}
return domain.User{}
}
... ...
... ... @@ -102,7 +102,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
// 删除点赞文章消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.UnLikeArticle(c, articleInfo.Id)
err = messageLogic.UnLikeArticle(c, articleInfo.Id, articleInfo.AuthorId)
if err != nil {
return err
}
... ... @@ -183,7 +183,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi
// 删除点赞评论消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.UnLikeComment(c, commentInfo.ArticleId, commentInfo.Id)
err = messageLogic.UnLikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.FromUserId)
if err != nil {
return err
}
... ...
... ... @@ -77,6 +77,8 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
})
})
article.SetSummary(articleSections)
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//保存文章
_, err = l.svcCtx.ArticleRepository.Update(ctx, c, article)
... ...
... ... @@ -2,11 +2,12 @@ package article
import (
"context"
"github.com/jinzhu/copier"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"strconv"
"unicode/utf8"
"github.com/jinzhu/copier"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"strings"
"github.com/samber/lo"
... ... @@ -85,6 +86,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
if err != nil {
return nil, err
}
//检查文章可被哪些人查看
whoRead, err := l.validateAndGetWhoRead(req, article)
if err != nil {
... ... @@ -115,19 +117,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
//文章内容
articleSections := l.getSections(req, article)
//设置内容概要
if len(req.Section) > 0 {
// 截取内容 50个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
for i := range req.Section[0].Content {
if runeNumber > 50 {
break
}
runeNumber += 1
stringIndex = i
}
article.Summary = req.Section[0].Content[0:stringIndex]
}
article.SetSummary(articleSections)
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article)
... ... @@ -198,8 +188,8 @@ func (l *SystemUpdateArticleLogic) validateTextLimit(req *types.SystemArticleUpd
num := utf8.RuneCountInString(req.Section[i].Content)
wordNum += num
}
if wordNum >= 1000 {
return xerr.NewErrMsg("最多只能输入1000字")
if wordNum > 1000 {
return xerr.NewErrMsg("内容最多只能输入1000字")
}
return nil
}
... ...
... ... @@ -40,7 +40,7 @@ func (l *MiniArticleCommentAtWhoLogic) MiniArticleCommentAtWho(req *types.MiniAr
}
var userList []*domain.User
if len(articleInfo.WhoRead) == 0 {
if articleInfo.TargetUser == domain.ArticleTargetAll {
//获取所有人
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("companyId", articleInfo.CompanyId)
_, userList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
... ... @@ -49,20 +49,21 @@ func (l *MiniArticleCommentAtWhoLogic) MiniArticleCommentAtWho(req *types.MiniAr
return resp, nil
}
} else {
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", articleInfo.WhoRead)
_, userList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
resp = &types.MiniArticleCommentAtWhoResponse{}
return resp, nil
if len(articleInfo.WhoRead) > 0 {
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", articleInfo.WhoRead)
_, userList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
resp = &types.MiniArticleCommentAtWhoResponse{}
return resp, nil
}
}
}
uList := make([]types.CommentAtWho, len(userList))
for i := range userList {
uList[i] = types.CommentAtWho{
Id: userList[i].Id,
Name: userList[i].Name,
Avatar: userList[i].Avatar,
FirstLetter: "",
}
for _, val := range userList[i].PinYinName {
... ...
... ... @@ -96,8 +96,10 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
if err != nil {
return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
}
if len(atWhoIds) != len(atWhoList) {
return nil, xerr.NewErrMsg("检查@的人员失败")
for _, val := range atWhoList {
if val.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
}
}
}
// 处理文本内容
... ...
... ... @@ -5,6 +5,7 @@ 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/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
... ... @@ -13,15 +14,17 @@ import (
type MiniTop5ArticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]types.CommentAuthor
}
func NewMiniTop5ArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniTop5ArticleCommentLogic {
return &MiniTop5ArticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
userCache: make(map[int64]types.CommentAuthor),
}
}
... ... @@ -50,9 +53,15 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5
resp = &types.MiniTop5ArticleCommentResponse{
List: make([]types.ArticleCommentItem, len(commentList)),
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取公司信息失败", err)
}
for i, val := range commentList {
item := NewArticleCommentItem(val)
item.FromUser = l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name)
item.ToUser = l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name)
if _, ok := flagMap[val.Id]; ok {
item.MeLoveFlag = 1
}
... ... @@ -70,6 +79,25 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5
return
}
func (l *MiniTop5ArticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
if u, ok := l.userCache[userid]; ok {
return u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
commentToUser := types.CommentAuthor{
Id: toUser.Id,
Name: toUser.Name,
Avatar: toUser.Avatar,
Position: toUser.Position,
Company: companyName,
}
l.userCache[toUser.Id] = commentToUser
return commentToUser
}
return types.CommentAuthor{}
}
func NewArticleCommentItem(val *domain.ArticleComment) types.ArticleCommentItem {
item := types.ArticleCommentItem{
Id: val.Id,
... ...
... ... @@ -36,7 +36,32 @@ func (l *SystemEditAticleCommentLogic) SystemEditAticleComment(req *types.System
if commetInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有操作权限")
}
{
//检查运营点赞的值
//查找对应的文章
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, commetInfo.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("没有找到对应的文章", err)
}
var maxCount int
//获取文章可以被多少人查看
if articleInfo.TargetUser == domain.ArticleTargetLimit {
maxCount = commetInfo.MaxCountAdminLove(len(articleInfo.WhoRead))
} else {
//统计全员人数
queryOption := domain.NewQueryOptions().WithCountOnly().MustWithKV("companyId", req.CompanyId)
cnt, _, err := l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取人员数据失败", err)
}
maxCount = commetInfo.MaxCountAdminLove(int(cnt))
}
if maxCount < req.CountAdminLove {
return nil, xerr.NewErrMsg("运营点数设置错误")
}
}
commetInfo.CountAdminLove = req.CountAdminLove
commetInfo.Content = req.Content
var increaseCount int
switch req.Show {
case 1:
... ... @@ -52,7 +77,7 @@ func (l *SystemEditAticleCommentLogic) SystemEditAticleComment(req *types.System
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)
... ...
... ... @@ -47,6 +47,35 @@ func (l *SystemEditAticleCommentLoveLogic) SystemEditAticleCommentLove(req *type
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
for _, commetInfo := range commetList {
//检查运营点赞的值
//查找对应的文章
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, commetInfo.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("没有找到对应的文章", err)
}
var maxCount int
//获取文章可以被多少人查看
if articleInfo.TargetUser == domain.ArticleTargetLimit {
maxCount = commetInfo.MaxCountAdminLove(len(articleInfo.WhoRead))
} else {
//统计全员人数
queryOption := domain.NewQueryOptions().WithCountOnly().MustWithKV("companyId", req.CompanyId)
cnt, _, err := l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取人员数据失败", err)
}
maxCount = commetInfo.MaxCountAdminLove(int(cnt))
}
if paramCountData, ok := paramMap[commetInfo.Id]; ok {
if maxCount < paramCountData {
return nil, xerr.NewErrMsg("运营点数设置错误")
}
}
}
// 更新运营点赞数
resp = &types.SystemEditCommentLoveResponse{}
for _, val := range commetList {
if val.CompanyId != req.CompanyId {
... ...
... ... @@ -248,13 +248,13 @@ func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64,
}
// UnLikeArticle 取消点赞文章
func (l *MiniBusinessLogic) UnLikeArticle(conn transaction.Conn, articleId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeArticle, articleId, 0)
func (l *MiniBusinessLogic) UnLikeArticle(conn transaction.Conn, articleId int64, recipientId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeArticle, articleId, 0, recipientId)
}
// UnLikeComment 取消点赞评论
func (l *MiniBusinessLogic) UnLikeComment(conn transaction.Conn, articleId int64, commentId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeComment, articleId, commentId)
func (l *MiniBusinessLogic) UnLikeComment(conn transaction.Conn, articleId int64, commentId int64, recipientId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeComment, articleId, commentId, recipientId)
}
func (l *MiniBusinessLogic) createMessage(
... ... @@ -287,14 +287,14 @@ func (l *MiniBusinessLogic) createMessage(
return nil
}
func (l *MiniBusinessLogic) deleteMessage(conn transaction.Conn, optType domain.MsgBusinessOpt, articleId int64, commentId int64) (err error) {
func (l *MiniBusinessLogic) deleteMessage(conn transaction.Conn, optType domain.MsgBusinessOpt, articleId int64, commentId int64, recipientId int64) (err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
queryOption := domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).
MustWithKV("type", domain.MsgTypeLike).
MustWithKV("optType", optType).
MustWithKV("companyId", userToken.CompanyId).
MustWithKV("recipientId", userToken.UserId).
MustWithKV("recipientId", recipientId).
MustWithKV("articleId", articleId).
MustWithKV("commentId", commentId)
... ...
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 MiniUserMyFollowingNewsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniUserMyFollowingNewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserMyFollowingNewsLogic {
return &MiniUserMyFollowingNewsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniUserMyFollowingNewsLogic) MiniUserMyFollowingNews(req *types.MiniUserNewsRequest) (resp *types.MiniUserNewsResposne, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
articles []*domain.Article
readArticles = make([]*domain.UserReadArticle, 0)
userMap = make(map[int64]*domain.User)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
var (
users = user.Following
)
if req.AuthorId > 0 {
users = []int64{req.AuthorId}
}
if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, user.Id, req.LastArticleId, req.Size); err != nil {
return nil, xerr.NewErrMsgErr("获取快讯异常", err)
}
resp = &types.MiniUserNewsResposne{
List: make([]types.UserNewsItem, 0),
}
articleIds := domain.Values(articles, func(item *domain.Article) int64 {
return item.Id
})
if len(articleIds) > 0 {
resp.LastArticleId = articleIds[len(articleIds)-1]
_, readArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithFindOnly().WithKV("articleIds", articleIds))
}
readArticlesMap := lo.KeyBy(readArticles, func(item *domain.UserReadArticle) int64 {
return item.ArticleId
})
lo.ForEach(articles, func(item *domain.Article, index int) {
newsItem := types.UserNewsItem{
NewsId: item.Id,
Type: "article",
Title: item.Title,
Summary: item.Summary,
Time: item.CreatedAt,
Images: make([]string, 0),
ReadFlag: false,
}
if author, _ := domain.LazyLoad(userMap, l.ctx, conn, item.AuthorId, l.svcCtx.UserRepository.FindOne); author != nil {
newsItem.Author = types.UserItem{
Id: author.Id,
Name: author.Name,
Avatar: lo.ToPtr(author.Avatar),
}
}
for _, img := range item.Images {
newsItem.Images = append(newsItem.Images, img.Url)
}
if _, ok := readArticlesMap[item.Id]; ok {
newsItem.ReadFlag = true
}
resp.List = append(resp.List, newsItem)
})
return
}
... ...
... ... @@ -39,15 +39,7 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
var (
users = user.Following
)
if req.AuthorId > 0 {
users = []int64{req.AuthorId}
} else {
users = append(users, user.Id)
}
if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, user.Id, req.LastArticleId, req.Size); err != nil {
if _, articles, err = l.svcCtx.ArticleRepository.FindLatestAccessibleArticle(l.ctx, conn, user.CompanyId, user.Id, req.LastArticleId, req.Size); err != nil {
return nil, xerr.NewErrMsgErr("获取快讯异常", err)
}
resp = &types.MiniUserNewsResposne{
... ... @@ -58,7 +50,7 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
})
if len(articleIds) > 0 {
resp.LastArticleId = articleIds[len(articleIds)-1]
_, readArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithKV("articleIds", articleIds))
_, readArticles, _ = l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithFindOnly().WithKV("articleIds", articleIds))
}
readArticlesMap := lo.KeyBy(readArticles, func(item *domain.UserReadArticle) int64 {
return item.ArticleId
... ...
... ... @@ -34,6 +34,7 @@ type MiniCreateArticleCommentRequest struct {
type CommentAtWho struct {
Id int64 `json:"id"`
Avatar string `json:"avatar,optional"` // 人员头像URL
Name string `json:"name,optional"`
FirstLetter string `json:"firstLetter,optional"`
}
... ... @@ -265,10 +266,11 @@ type SystemEditCommentShowResponse struct {
}
type SystemEditCommentRequest struct {
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
CountAdminLove int `json:"countAdminLove,optional"`
CompanyId int64 `json:",optional"`
Id int64 `json:"id"`
Show int `json:"show"` //[1 显示评论] [2: 隐藏评论]
Content string `json:"content,optional"`
CountAdminLove int `json:"countAdminLove,optional"`
}
type SystemEditCommentResponse struct {
... ... @@ -1315,6 +1317,7 @@ type MiniSearchArticleResponse struct {
type MiniSearchArticleItem struct {
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
AuthorId int64 `json:"authorId"`
Author string `json:"author"` // 发布人
Avatar string `json:"avatar"` // 发布人的头像
Images []string `json:"images"`
... ...
... ... @@ -164,6 +164,47 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
return total, dms, nil
}
// FindLatestAccessibleArticle 最新可访问的文章
func (repository *ArticleRepository) FindLatestAccessibleArticle(ctx context.Context, conn transaction.Conn,
companyId int64, whoRead int64, lastId int64, limit int) (int64, []*domain.Article, error) {
var (
tx = conn.DB()
ms []*models.Article
dms = make([]*domain.Article, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).
Where("company_id=?", companyId).
Where(fmt.Sprintf("author_id = %d or target_user=0 or who_read @>'[%d]'", whoRead, whoRead)).
Where("show = 1")
if lastId > 0 {
tx.Where("id < ?", lastId)
}
tx.Order("id desc")
if limit > 0 {
tx.Limit(limit)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, domain.NewQueryOptions().WithFindOnly(), &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
}
// FindAuthorsLatestArticle 作者最新的文章
func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Context, conn transaction.Conn,
companyId int64, authors []int64, whoRead int64, lastId int64, limit int) (int64, []*domain.Article, error) {
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"context"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
... ... @@ -43,6 +44,7 @@ type ArticleRepository interface {
FindAuthorsLatestFirstArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, limit int) (int64, []*Article, error)
FindAuthorsLatestFirstUnreadArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, limit int) (int64, []*Article, error)
FindAuthorsLatestArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, lastId int64, limit int) (int64, []*Article, error)
FindLatestAccessibleArticle(ctx context.Context, conn transaction.Conn, companyId int64, whoRead int64, lastId int64, limit int) (int64, []*Article, error)
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动
... ... @@ -118,6 +120,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection) *Ar
WhoReview: m.WhoReview,
Tags: m.Tags,
MatchUrl: map[string]string{},
Location: m.Location,
}
copy(b.Videos, m.Videos)
copy(b.Images, m.Images)
... ... @@ -126,3 +129,30 @@ func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection) *Ar
}
return &b
}
func (m *Article) SetSummary(sectionList []ArticleSection) {
if len(sectionList) == 0 {
return
}
//设置内容概要
// 截取内容 50个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
content := ""
for i := range sectionList {
str := strings.TrimSpace(sectionList[i].Content)
if len(str) > 0 {
content = str
break
}
}
for i := range content {
if runeNumber > 50 {
break
}
runeNumber += 1
stringIndex = i
}
m.Summary = content[0:stringIndex]
}
... ...
... ... @@ -61,7 +61,7 @@ type ArticleCommentShow struct {
CountReply int // 回复数量
CountUserLove int // 用户点赞数量
CountAdminLove int // 运营点赞数量
Show int // 评论的展示状态(0显示、1不显示)
Show int // 评论的展示状态(1显示、2不显示)
CreatedAt int64 // 评论的创建时间
}
... ... @@ -81,3 +81,14 @@ type ArticleCommentRepository interface {
CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error)
}
// 运营点数 填写的最大值
func (m *ArticleComment) MaxCountAdminLove(articleWhoRead int) int {
// 帖子的可见人数/3向上取整
x := articleWhoRead / 3 // 取商
y := articleWhoRead % 3 // 取余
if y > 0 {
x = x + 1
}
return x
}
... ...
#!/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
... ...
apiVersion: v1
kind: Service
metadata:
name: sumifcc-discuss
namespace: mmm-suplus-test
labels:
k8s-app: sumifcc-discuss
spec:
ports:
- name: "http"
port: 80
targetPort: 8081
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: sumifcc-discuss
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sumifcc-discuss
namespace: mmm-suplus-test
labels:
k8s-app: sumifcc-discuss
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: sumifcc-discuss
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
containers:
- name: sumifcc-discuss
image: 192.168.0.243:5000/mmm/sumifcc-discuss:dev
imagePullPolicy: Always
ports:
- containerPort: 8081
- containerPort: 443
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: LOG_LEVEL
value: "debug"
- name: LOG_FILE
value: "true"
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.ip
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.port
volumes:
- name: accesslogs
emptyDir: {}
... ...
-- public.article definition
-- Drop table
-- DROP TABLE public.article;
CREATE TABLE public.article(
id bigserial NOT NULL, -- ID
company_id int8 NULL, -- 公司ID
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
is_del int8 NULL, -- 是否删除
"version" int8 NULL DEFAULT 0, -- 版本
author_id int8 NULL DEFAULT 0, -- 发布人
author jsonb NULL DEFAULT '{}' ::jsonb, -- 发布人对象
title text NULL, -- 文章标题
images jsonb NULL DEFAULT '[]' ::jsonb, -- 图片
who_read jsonb NULL DEFAULT '[]' ::jsonb, -- 谁可以看
who_review jsonb NULL DEFAULT '[]' ::jsonb, -- 评论人
"location" jsonb NULL DEFAULT '{}' ::jsonb, -- 坐标
target_user int8 NULL DEFAULT 0, -- 分发方式 0 分发给所有人 1 分发给指定的人
count_love int8 NULL DEFAULT 0, -- 点赞数量
count_comment int8 NULL DEFAULT 0, -- 评论数量
"show" int8 NULL DEFAULT 1, -- 评论的展示状态(1显示、2不显示)
tags jsonb NULL DEFAULT '[]' ::jsonb, -- 标签
count_read int8 NULL DEFAULT 0, -- 已读数量
summary text NULL,
match_url jsonb NULL DEFAULT '{}' ::jsonb,
videos jsonb NULL DEFAULT '[]' ::jsonb,
CONSTRAINT article_pkey PRIMARY KEY (id)
);
CREATE INDEX article_company_id_idx ON public.article USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public.article.id IS 'ID';
COMMENT ON COLUMN public.article.company_id IS '公司ID';
COMMENT ON COLUMN public.article.created_at IS '创建时间';
COMMENT ON COLUMN public.article.updated_at IS '更新时间';
COMMENT ON COLUMN public.article.deleted_at IS '删除时间';
COMMENT ON COLUMN public.article.is_del IS '是否删除';
COMMENT ON COLUMN public.article. "version" IS '版本';
COMMENT ON COLUMN public.article.author_id IS '发布人';
COMMENT ON COLUMN public.article.author IS '发布人对象';
COMMENT ON COLUMN public.article.title IS '文章标题';
COMMENT ON COLUMN public.article.images IS '图片';
COMMENT ON COLUMN public.article.who_read IS '谁可以看';
COMMENT ON COLUMN public.article.who_review IS '评论人';
COMMENT ON COLUMN public.article. "location" IS '坐标';
COMMENT ON COLUMN public.article.target_user IS '分发方式 0 分发给所有人 1 分发给指定的人';
COMMENT ON COLUMN public.article.count_love IS '点赞数量';
COMMENT ON COLUMN public.article.count_comment IS '评论数量';
COMMENT ON COLUMN public.article. "show" IS '评论的展示状态(1显示、2不显示)';
COMMENT ON COLUMN public.article.tags IS '标签';
COMMENT ON COLUMN public.article.count_read IS '已读数量';
-- public.article_and_tag definition
-- Drop table
-- DROP TABLE public.article_and_tag;
CREATE TABLE public.article_and_tag(
id bigserial NOT NULL,
company_id int8 NULL,
created_at int8 NULL,
updated_at int8 NULL,
article_id int8 NULL,
tag_id int8 NULL,
CONSTRAINT article_and_tag_pkey PRIMARY KEY (id)
);
CREATE INDEX article_and_tag_company_id_idx ON public.article_and_tag USING btree(company_id);
-- public.article_backup definition
-- Drop table
-- DROP TABLE public.article_backup;
CREATE TABLE public.article_backup(
id bigserial NOT NULL, -- ID
company_id int8 NULL, -- 公司ID
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
is_del int8 NULL, -- 是否删除
"version" int8 NULL, -- 版本
"operator" jsonb NULL, -- 操作人
title text NULL, -- 标题
"section" jsonb NULL, -- 分段内容
images jsonb NULL, -- 图片
"action" text NULL, -- 操作
who_read jsonb NULL, -- 谁可以看
who_review jsonb NULL, -- 评论人
tags jsonb NULL, -- 标签
target_user int8 NULL, -- 分发方式 0 分发给所有人 1 分发给指定的人
article_id int8 NULL,
"location" jsonb NULL,
match_url jsonb NULL DEFAULT '{}' ::jsonb,
videos jsonb NULL DEFAULT '[]' ::jsonb,
CONSTRAINT article_backup_pkey PRIMARY KEY (id)
);
CREATE INDEX article_backup_company_id_idx ON public.article_backup USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public.article_backup.id IS 'ID';
COMMENT ON COLUMN public.article_backup.company_id IS '公司ID';
COMMENT ON COLUMN public.article_backup.created_at IS '创建时间';
COMMENT ON COLUMN public.article_backup.updated_at IS '更新时间';
COMMENT ON COLUMN public.article_backup.deleted_at IS '删除时间';
COMMENT ON COLUMN public.article_backup.is_del IS '是否删除';
COMMENT ON COLUMN public.article_backup. "version" IS '版本';
COMMENT ON COLUMN public.article_backup. "operator" IS '操作人';
COMMENT ON COLUMN public.article_backup.title IS '标题';
COMMENT ON COLUMN public.article_backup. "section" IS '分段内容';
COMMENT ON COLUMN public.article_backup.images IS '图片';
COMMENT ON COLUMN public.article_backup. "action" IS '操作';
COMMENT ON COLUMN public.article_backup.who_read IS '谁可以看';
COMMENT ON COLUMN public.article_backup.who_review IS '评论人';
COMMENT ON COLUMN public.article_backup.tags IS '标签';
COMMENT ON COLUMN public.article_backup.target_user IS '分发方式 0 分发给所有人 1 分发给指定的人';
-- public.article_comment definition
-- Drop table
-- DROP TABLE public.article_comment;
CREATE TABLE public.article_comment(
id bigserial NOT NULL, -- ID
company_id int8 NULL, -- 公司ID
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
is_del int8 NULL, -- 是否删除
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
pid int8 NULL DEFAULT 0, -- 对哪个评论进行回复
top_id int8 NULL DEFAULT 0, -- 归属于最上级的哪个评论
article_id int8 NULL DEFAULT 0, -- 文章id
section_id int8 NULL DEFAULT 0, -- 文本段落内容id
section_content text NULL, -- 引用的文章内容文本
from_user_id int8 NULL DEFAULT 0, -- 谁填写的评论
from_user jsonb NULL DEFAULT '{}' ::jsonb, -- 谁填写的评论对象
to_user_id int8 NULL DEFAULT 0, -- 回复谁的评论
to_user jsonb NULL DEFAULT '{}' ::jsonb, -- 回复谁的评论对象
"content" text NULL, -- 评论内容
count_reply int8 NULL DEFAULT 0, -- 回复数量
count_user_love int8 NULL DEFAULT 0, -- 用户点赞数量
count_admin_love int8 NULL DEFAULT 0, -- 运营点赞数量
"show" int8 NULL DEFAULT 1, -- 评论的展示状态(1显示、2不显示)
at_who jsonb NULL DEFAULT '[]' ::jsonb, -- 填写评论时@的人
match_url jsonb NULL DEFAULT '{}' ::jsonb, -- 评论内容中出现的url.
CONSTRAINT article_comment_pkey PRIMARY KEY (id)
);
CREATE INDEX article_comment_company_id_idx ON public.article_comment USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public.article_comment.id IS 'ID';
COMMENT ON COLUMN public.article_comment.company_id IS '公司ID';
COMMENT ON COLUMN public.article_comment.created_at IS '创建时间';
COMMENT ON COLUMN public.article_comment.updated_at IS '更新时间';
COMMENT ON COLUMN public.article_comment.is_del IS '是否删除';
COMMENT ON COLUMN public.article_comment.deleted_at IS '删除时间';
COMMENT ON COLUMN public.article_comment. "version" IS '版本';
COMMENT ON COLUMN public.article_comment.pid IS '对哪个评论进行回复';
COMMENT ON COLUMN public.article_comment.top_id IS '归属于最上级的哪个评论';
COMMENT ON COLUMN public.article_comment.article_id IS '文章id';
COMMENT ON COLUMN public.article_comment.section_id IS '文本段落内容id';
COMMENT ON COLUMN public.article_comment.section_content IS '引用的文章内容文本';
COMMENT ON COLUMN public.article_comment.from_user_id IS '谁填写的评论';
COMMENT ON COLUMN public.article_comment.from_user IS '谁填写的评论对象';
COMMENT ON COLUMN public.article_comment.to_user_id IS '回复谁的评论';
COMMENT ON COLUMN public.article_comment.to_user IS '回复谁的评论对象';
COMMENT ON COLUMN public.article_comment. "content" IS '评论内容';
COMMENT ON COLUMN public.article_comment.count_reply IS '回复数量';
COMMENT ON COLUMN public.article_comment.count_user_love IS '用户点赞数量';
COMMENT ON COLUMN public.article_comment.count_admin_love IS '运营点赞数量';
COMMENT ON COLUMN public.article_comment. "show" IS '评论的展示状态(1显示、2不显示)';
COMMENT ON COLUMN public.article_comment.at_who IS '填写评论时@的人';
COMMENT ON COLUMN public.article_comment.match_url IS '评论内容中出现的url.';
-- public.article_draft definition
-- Drop table
-- DROP TABLE public.article_draft;
CREATE TABLE public.article_draft(
id bigserial NOT NULL, -- ID
company_id int8 NULL, -- 公司ID
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
is_del int8 NULL, -- 是否删除
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
"template" int8 NULL, -- 填写内容时用的样板0、无 1、演绎式 2、归纳式
"content" jsonb NULL, -- 文章内容
author_id int8 NULL, -- 发布人
title text NULL, -- 文章标题
images jsonb NULL, -- 图片
who_read jsonb NULL, -- 谁可以看
who_review jsonb NULL, -- 评论人
"location" jsonb NULL, -- 坐标
match_url jsonb NULL DEFAULT '{}' ::jsonb,
CONSTRAINT article_draft_pkey PRIMARY KEY (id)
);
CREATE INDEX article_draft_company_id_idx ON public.article_draft USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public.article_draft.id IS 'ID';
COMMENT ON COLUMN public.article_draft.company_id IS '公司ID';
COMMENT ON COLUMN public.article_draft.created_at IS '创建时间';
COMMENT ON COLUMN public.article_draft.updated_at IS '更新时间';
COMMENT ON COLUMN public.article_draft.is_del IS '是否删除';
COMMENT ON COLUMN public.article_draft.deleted_at IS '删除时间';
COMMENT ON COLUMN public.article_draft. "version" IS '版本';
COMMENT ON COLUMN public.article_draft. "template" IS '填写内容时用的样板0、无 1、演绎式 2、归纳式';
COMMENT ON COLUMN public.article_draft. "content" IS '文章内容';
COMMENT ON COLUMN public.article_draft.author_id IS '发布人';
COMMENT ON COLUMN public.article_draft.title IS '文章标题';
COMMENT ON COLUMN public.article_draft.images IS '图片';
COMMENT ON COLUMN public.article_draft.who_read IS '谁可以看';
COMMENT ON COLUMN public.article_draft.who_review IS '评论人';
COMMENT ON COLUMN public.article_draft. "location" IS '坐标';
-- public.article_section definition
-- Drop table
-- DROP TABLE public.article_section;
CREATE TABLE public.article_section(
id bigserial NOT NULL, -- ID
company_id int8 NULL, -- 公司ID
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
is_del int8 NULL, -- 是否删除
"version" int8 NULL, -- 版本
article_id int8 NULL, -- 文章id
"content" text NULL, -- 文本内容
sort_by int8 NULL, -- 排序
total_comment int8 NULL, -- 评论的数量
CONSTRAINT article_section_pkey PRIMARY KEY (id)
);
CREATE INDEX article_section_article_id_idx ON public.article_section USING btree(article_id);
CREATE INDEX article_section_company_id_idx ON public.article_section USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public.article_section.id IS 'ID';
COMMENT ON COLUMN public.article_section.company_id IS '公司ID';
COMMENT ON COLUMN public.article_section.created_at IS '创建时间';
COMMENT ON COLUMN public.article_section.updated_at IS '更新时间';
COMMENT ON COLUMN public.article_section.deleted_at IS '删除时间';
COMMENT ON COLUMN public.article_section.is_del IS '是否删除';
COMMENT ON COLUMN public.article_section. "version" IS '版本';
COMMENT ON COLUMN public.article_section.article_id IS '文章id';
COMMENT ON COLUMN public.article_section. "content" IS '文本内容';
COMMENT ON COLUMN public.article_section.sort_by IS '排序';
COMMENT ON COLUMN public.article_section.total_comment IS '评论的数量';
-- public.article_tag definition
-- Drop table
-- DROP TABLE public.article_tag;
CREATE TABLE public.article_tag(
id bigserial NOT NULL, -- ID
company_id int8 NULL, -- 公司ID
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
is_del int8 NULL DEFAULT 0, -- 是否删除
"version" int8 NULL, -- 版本
image jsonb NULL, -- 图片
"name" text NULL, -- 标签名称
category text NULL, -- 标签分类
remark text NULL, -- 备注
sort_by int8 NULL DEFAULT 0,
other text NULL,
CONSTRAINT article_tag_pkey PRIMARY KEY (id)
);
CREATE INDEX article_tag_company_id_idx ON public.article_tag USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public.article_tag.id IS 'ID';
COMMENT ON COLUMN public.article_tag.company_id IS '公司ID';
COMMENT ON COLUMN public.article_tag.created_at IS '创建时间';
COMMENT ON COLUMN public.article_tag.updated_at IS '更新时间';
COMMENT ON COLUMN public.article_tag.deleted_at IS '删除时间';
COMMENT ON COLUMN public.article_tag.is_del IS '是否删除';
COMMENT ON COLUMN public.article_tag. "version" IS '版本';
COMMENT ON COLUMN public.article_tag.image IS '图片';
COMMENT ON COLUMN public.article_tag. "name" IS '标签名称';
COMMENT ON COLUMN public.article_tag.category IS '标签分类';
COMMENT ON COLUMN public.article_tag.remark IS '备注';
-- public.company definition
-- Drop table
-- DROP TABLE public.company;
CREATE TABLE public.company(
id bigserial NOT NULL, -- ID
"name" text NULL, -- 名称
code text NULL, -- 编码(搜索使用,4位字母数字)
logo text NULL, -- 公司LOGO
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
CONSTRAINT company_pkey PRIMARY KEY (id),
CONSTRAINT idx_company_code UNIQUE (code)
);
-- Column comments
COMMENT ON COLUMN public.company.id IS 'ID';
COMMENT ON COLUMN public.company. "name" IS '名称';
COMMENT ON COLUMN public.company.code IS '编码(搜索使用,4位字母数字)';
COMMENT ON COLUMN public.company.logo IS '公司LOGO';
COMMENT ON COLUMN public.company.created_at IS '创建时间';
COMMENT ON COLUMN public.company.updated_at IS '更新时间';
COMMENT ON COLUMN public.company.deleted_at IS '删除时间';
COMMENT ON COLUMN public.company. "version" IS '版本';
-- public.department definition
-- Drop table
-- DROP TABLE public.department;
CREATE TABLE public.department(
id bigserial NOT NULL,
company_id int8 NULL,
parent_id int8 NULL,
"name" text NULL,
created_at int8 NULL,
updated_at int8 NULL,
deleted_at int8 NULL,
"version" int8 NULL,
is_del int8 NULL,
CONSTRAINT department_pkey PRIMARY KEY (id)
);
-- public.message_business definition
-- Drop table
-- DROP TABLE public.message_business;
CREATE TABLE public.message_business(
id bigserial NOT NULL,
"type" int8 NULL,
opt_type int8 NULL,
company_id int8 NULL,
user_id int8 NULL,
recipient_id int8 NULL,
article_id int8 NULL,
comment_id int8 NULL,
comment_parent_id int8 NULL,
created_at int8 NULL,
updated_at int8 NULL,
deleted_at int8 NULL,
"version" int8 NULL,
is_del int8 NULL,
CONSTRAINT message_business_pkey PRIMARY KEY (id)
);
-- public.message_system definition
-- Drop table
-- DROP TABLE public.message_system;
CREATE TABLE public.message_system(
id bigserial NOT NULL,
company_id int8 NULL, -- 公司ID
recipient_id int8 NULL, -- 接收者ID
"type" int8 NULL, -- 系统分类(0待定、1业务正常通知、2业务异常通知)
title text NULL, -- 标题
"content" text NULL, -- 内容
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
is_del int8 NULL, -- 是否删除
CONSTRAINT message_system_pkey PRIMARY KEY (id)
);
-- Column comments
COMMENT ON COLUMN public.message_system.company_id IS '公司ID';
COMMENT ON COLUMN public.message_system.recipient_id IS '接收者ID';
COMMENT ON COLUMN public.message_system. "type" IS '系统分类(0待定、1业务正常通知、2业务异常通知)';
COMMENT ON COLUMN public.message_system.title IS '标题';
COMMENT ON COLUMN public.message_system. "content" IS '内容';
COMMENT ON COLUMN public.message_system.created_at IS '创建时间';
COMMENT ON COLUMN public.message_system.updated_at IS '更新时间';
COMMENT ON COLUMN public.message_system.deleted_at IS '删除时间';
COMMENT ON COLUMN public.message_system. "version" IS '版本';
COMMENT ON COLUMN public.message_system.is_del IS '是否删除';
-- public."role" definition
-- Drop table
-- DROP TABLE public."role";
CREATE TABLE public."role"(
id bigserial NOT NULL, -- ID
"name" text NULL, -- 角色名称
auths jsonb NULL, -- 角色权限列表
remark text NULL, -- 备注
users jsonb NULL, -- 绑定的用户
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
is_del int8 NULL, -- 是否删除
company_id int8 NULL, -- 公司ID
CONSTRAINT role_pkey PRIMARY KEY (id)
);
CREATE INDEX idx_role_company_id ON public.role USING btree(company_id);
-- Column comments
COMMENT ON COLUMN public."role".id IS 'ID';
COMMENT ON COLUMN public."role"."name" IS '角色名称';
COMMENT ON COLUMN public."role".auths IS '角色权限列表';
COMMENT ON COLUMN public."role".remark IS '备注';
COMMENT ON COLUMN public."role".users IS '绑定的用户';
COMMENT ON COLUMN public."role".created_at IS '创建时间';
COMMENT ON COLUMN public."role".updated_at IS '更新时间';
COMMENT ON COLUMN public."role".deleted_at IS '删除时间';
COMMENT ON COLUMN public."role"."version" IS '版本';
COMMENT ON COLUMN public."role".is_del IS '是否删除';
COMMENT ON COLUMN public."role".company_id IS '公司ID';
-- public."user" definition
-- Drop table
-- DROP TABLE public."user";
CREATE TABLE public."user"(
id bigserial NOT NULL, -- 唯一标识
company_id int8 NULL, -- 公司ID
roles jsonb NULL, -- 角色
flag int8 NULL, -- 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
"name" text NULL, -- 名称
avatar text NULL, -- 头像
phone text NULL, -- 手机号 唯一
"position" text NULL, -- 职位
"enable" int8 NULL, -- 启用状态 1:启用 2:禁用
audit_status int8 NULL, -- 审核状态 0:待审核 1:审核通过 2:拒绝
follower jsonb NULL, -- 关注我的人 (冗余)
"following" jsonb NULL, -- 我关注的人 (冗余)
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
is_del int8 NULL, -- 是否删除
departments jsonb NULL, -- 所属部门
account_from text NULL, -- 账号来源 后台新增、扫码注册
pin_yin_name text NULL, -- 拼音
audit_at int8 NULL,
CONSTRAINT user_pkey PRIMARY KEY (id)
);
CREATE INDEX idx_user_company_id ON public."user" USING btree(company_id);
CREATE INDEX idx_user_phone ON public."user" USING btree(phone);
-- Column comments
COMMENT ON COLUMN public."user".id IS '唯一标识';
COMMENT ON COLUMN public."user".company_id IS '公司ID';
COMMENT ON COLUMN public."user".roles IS '角色';
COMMENT ON COLUMN public."user".flag IS '标识 1:管理员 2:普通用户 (有绑定角色是管理员)';
COMMENT ON COLUMN public."user"."name" IS '名称';
COMMENT ON COLUMN public."user".avatar IS '头像';
COMMENT ON COLUMN public."user".phone IS '手机号 唯一';
COMMENT ON COLUMN public."user"."position" IS '职位';
COMMENT ON COLUMN public."user"."enable" IS '启用状态 1:启用 2:禁用';
COMMENT ON COLUMN public."user".audit_status IS '审核状态 0:待审核 1:审核通过 2:拒绝';
COMMENT ON COLUMN public."user".follower IS '关注我的人 (冗余)';
COMMENT ON COLUMN public."user"."following" IS '我关注的人 (冗余)';
COMMENT ON COLUMN public."user".created_at IS '创建时间';
COMMENT ON COLUMN public."user".updated_at IS '更新时间';
COMMENT ON COLUMN public."user".deleted_at IS '删除时间';
COMMENT ON COLUMN public."user"."version" IS '版本';
COMMENT ON COLUMN public."user".is_del IS '是否删除';
COMMENT ON COLUMN public."user".departments IS '所属部门';
COMMENT ON COLUMN public."user".account_from IS '账号来源 后台新增、扫码注册';
COMMENT ON COLUMN public."user".pin_yin_name IS '拼音';
-- public.user_follow definition
-- Drop table
-- DROP TABLE public.user_follow;
CREATE TABLE public.user_follow(
id bigserial NOT NULL,
created_at int8 NULL,
updated_at int8 NULL,
deleted_at int8 NULL,
"version" int8 NULL,
from_user_id int8 NULL,
to_user_id int8 NULL,
last_read_at int8 NULL,
CONSTRAINT user_follow_pkey PRIMARY KEY (id)
);
CREATE INDEX idx_user_follow_from_user_id ON public.user_follow USING btree(from_user_id);
-- public.user_love_flag definition
-- Drop table
-- DROP TABLE public.user_love_flag;
CREATE TABLE public.user_love_flag(
id bigserial NOT NULL,
article_id int8 NULL, -- 点赞文章时,文章id
comment_id int8 NULL, -- 点赞评论时,填评论id
user_id int8 NULL, -- 用户ID,谁点赞
created_at int8 NULL, -- 创建时间
updated_at int8 NULL, -- 更新时间
deleted_at int8 NULL, -- 删除时间
"version" int8 NULL, -- 版本
is_del int8 NULL, -- 是否删除
article_author int8 NULL, -- 文章作者id
comment_author int8 NULL, -- 填写评论的人员id
to_user_id int8 NULL, -- 点赞的接受人
company_id int8 NULL DEFAULT 0,
CONSTRAINT user_love_flag_pkey PRIMARY KEY (id)
);
CREATE INDEX user_love_flag_comment_id_idx ON public.user_love_flag USING btree(comment_id);
CREATE INDEX user_love_flag_user_id_idx ON public.user_love_flag USING btree(user_id);
-- Column comments
COMMENT ON COLUMN public.user_love_flag.article_id IS '点赞文章时,文章id';
COMMENT ON COLUMN public.user_love_flag.comment_id IS '点赞评论时,填评论id';
COMMENT ON COLUMN public.user_love_flag.user_id IS '用户ID,谁点赞';
COMMENT ON COLUMN public.user_love_flag.created_at IS '创建时间';
COMMENT ON COLUMN public.user_love_flag.updated_at IS '更新时间';
COMMENT ON COLUMN public.user_love_flag.deleted_at IS '删除时间';
COMMENT ON COLUMN public.user_love_flag. "version" IS '版本';
COMMENT ON COLUMN public.user_love_flag.is_del IS '是否删除';
COMMENT ON COLUMN public.user_love_flag.article_author IS '文章作者id';
COMMENT ON COLUMN public.user_love_flag.comment_author IS '填写评论的人员id';
COMMENT ON COLUMN public.user_love_flag.to_user_id IS '点赞的接受人';
-- public.user_read_article definition
-- Drop table
-- DROP TABLE public.user_read_article;
CREATE TABLE public.user_read_article(
id bigserial NOT NULL,
created_at int8 NULL,
updated_at int8 NULL,
deleted_at int8 NULL,
"version" int8 NULL,
company_id int8 NULL,
user_id int8 NULL,
article_id int8 NULL,
title text NULL,
author jsonb NULL DEFAULT '{}' ::jsonb,
is_del int8 NULL DEFAULT 0,
CONSTRAINT user_read_article_pkey PRIMARY KEY (id)
);
CREATE INDEX user_read_article_company_id_idx ON public.user_read_article USING btree(company_id);
CREATE INDEX user_read_article_user_id_idx ON public.user_read_article USING btree(user_id);
-- public.user_role definition
-- Drop table
-- DROP TABLE public.user_role;
CREATE TABLE public.user_role(
id bigserial NOT NULL,
company_id int8 NULL,
user_id int8 NULL,
role_id int8 NULL,
created_at int8 NULL,
updated_at int8 NULL,
deleted_at int8 NULL,
"version" int8 NULL,
CONSTRAINT user_role_pkey PRIMARY KEY (id)
);
-- public.user_simples definition
-- Drop table
-- DROP TABLE public.user_simples;
CREATE TABLE public.user_simples(
id bigserial NOT NULL,
"name" text NULL,
avatar text NULL,
"group" text NULL,
"position" text NULL,
CONSTRAINT user_simples_pkey PRIMARY KEY (id)
);
... ...