作者 庄敏学
... ... @@ -14,7 +14,7 @@ func SystemAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentAddRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func SystemDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func SystemGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func SystemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func SystemUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageBusinessRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageSystemRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -14,7 +14,7 @@ func MiniMyLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniMyLikeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
... ... @@ -25,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
// 获取我的文章浏览记录
func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
... ...
... ... @@ -5,6 +5,9 @@ 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"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -25,7 +28,63 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext)
// 设置文章的定性标签
func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
//
return
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章信息失败", err)
}
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取文章信息失败")
}
tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
}
if tagInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取标签信息失败")
}
// 查询可能存在的 ArticleAndTag
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
_, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
}
// 更新article中的tags
articleInfo.Tags = []int64{tagInfo.Id}
// 额外保存一份ArticleAndTag
articleAndTag := domain.ArticleAndTag{
Id: 0,
CompanyId: articleInfo.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
ArticleId: articleInfo.Id,
TagId: tagInfo.Id,
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//清理可能存在的 ArticleAndTag
for _, v := range oldTags {
_, err = l.svcCtx.ArticleAndTagRepository.Delete(ctx, c, v)
if err != nil {
return err
}
}
// 更新article
_, err = l.svcCtx.ArticleRepository.UpdateWithVersion(ctx, c, articleInfo)
if err != nil {
return err
}
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag)
if err != nil {
return err
}
return nil
}, true)
resp = &types.MiniArticleSetTagResponse{
Id: articleAndTag.Id,
}
return resp, nil
}
... ...
... ... @@ -43,7 +43,6 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types
}
insert := &domain.Department{
Id: 0,
ParentId: 0,
CompanyId: userToken.CompanyId,
Name: req.Name,
... ...
... ... @@ -26,6 +26,7 @@ type ServiceContext struct {
ArticleRepository domain.ArticleRepository
ArticleSectionRepository domain.ArticleSectionRepository
ArticleTagRepository domain.ArticleTagRepository
ArticleAndTagRepository domain.ArticleAndTagRepository
CompanyRepository domain.CompanyRepository
CommentRepository domain.CommentRepository // 待移除
... ... @@ -59,12 +60,14 @@ 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)),
ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)),
ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)),
CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)),
ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)),
ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)),
ArticleAndTagRepository: repository.NewArticleAndTagRepository(cache.NewCachedRepository(mlCache)),
CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)),
DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)),
MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)),
... ...
... ... @@ -97,6 +97,9 @@ func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transa
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id=?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -277,3 +277,35 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c
func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository {
return &ArticleRepository{CachedRepository: cache}
}
// with
// -- 按查看权限查询文章
// t_article as(
// select article.id
// from article
// 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_article_and_tag as (
// select article_and_tag.article_id ,article_and_tag.tag_id
// from article_and_tag
// where article_and_tag.company_id =1598224576532189184
// ),
// -- 过滤出可展示的文章id
// t_article_and_tag_2 as (
// select t_article_and_tag.article_id, t_article_and_tag.tag_id
// from t_article_and_tag
// join t_article on t_article_and_tag.article_id = t_article.id
// ),
// -- 查询人员已查看的文章
// 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
... ...
... ... @@ -14,8 +14,8 @@ type ArticleBackup struct {
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
Operator UserSimple `json:"operator"` // 操作人
ArticleId int64 `json:"articleId"`
Operator UserSimple `json:"operator"` // 操作人
ArticleId int64 `json:"articleId"` //
Title string `json:"title"` // 标题
Section []ArticleSection `json:"section"` // 分段内容
Images []Image `json:"images"` // 图片
... ...
... ... @@ -29,11 +29,9 @@ type Opinion struct {
}
type UserSimple struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar,omitempty"` // 人员头像URL
// GroupId int64 `json:"groupId"` //分组id
//Group string `json:"group,omitempty"` // 人员的分组
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar,omitempty"` // 人员头像URL
Position string `json:"position,omitempty"` // 职位
Company string `json:"company,omitempty"` // 公司
CompanyId int64 `json:"companyId"`
... ...