作者 庄敏学
正在显示 42 个修改的文件 包含 283 行增加87 行删除
package main
import (
"context"
"flag"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"net/http"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"github.com/golang-jwt/jwt/v4/request"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler"
... ... @@ -20,27 +23,16 @@ import (
var configFile = flag.String("f", "cmd/discuss/api/etc/core.yaml", "the config file")
func main() {
// 配置加载
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
// 默认的token头 Authorization 修改未 x-token
request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{
request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) {
// Should be a bearer token
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
return tok[7:], nil
}
return tok, nil
},
}
// 初始化Domain里面的配置
domain.ProjectName = c.Name
// 系统设置
systemSetup(c)
// 服务初始化
opts := make([]rest.RunOption, 0)
// cors
opt := rest.WithCustomCors(func(header http.Header) {
header.Set("Access-Control-Allow-Headers", "*")
}, func(writer http.ResponseWriter) {
... ... @@ -49,14 +41,40 @@ func main() {
opts = append(opts, opt)
server := rest.MustNewServer(c.RestConf, opts...)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
// 数据迁移
if c.Migrate {
db.Migrate(ctx.DB)
}
// 服务启动
logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port)
server.Start()
}
func systemSetup(c config.Config) {
// 初始化Domain里面的配置
domain.ProjectName = c.Name
// 默认的token头 Authorization 修改为 x-mmm-accesstoken
request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{
request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) {
// Should be a bearer token
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
return tok[7:], nil
}
return tok, nil
},
}
// 系统错误应答包装
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) {
return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error())
})
// 系统成功应答包装
httpx.SetOkHandler(func(ctx context.Context, a any) any {
return result.Success(a)
})
}
... ...
... ... @@ -72,6 +72,12 @@ service Core {
@doc "小程序所有的定性标签"
@handler MiniAllArticleTag
get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
@doc "小程序首页数据展示"
@handler MiniShowHomePage
get /show/home_page (MiniHomePageRequest) returns (MiniHomePageRespose)
}
// 管理后台接口
... ...
... ... @@ -281,13 +281,13 @@ type (
}
MiniArticleMarkItem {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
UserId int64 `json:"userId"`
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
UserId int64 `json:"userId"`
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author SimpleUser `json:"author"` // 发布人
UpdatedAt int64 `json:"updatedAt"`
UpdatedAt int64 `json:"updatedAt"`
}
)
... ... @@ -460,4 +460,25 @@ type (
Id int64 `json:"id"` //ID
ArticleId int64 `json:"articleId"` //文章ID
}
)
//小程序端 首页数据展示
// 统计各标签下的文章数量,和已被人员阅读的数量
type (
MiniHomePageRequest {
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
MiniHomePageRespose {
Tags []ArticleTagCount `json:"tags"`
}
ArticleTagCount {
TagGroup string `json:"tagGroup"` // 标签分组
TagId int64 `json:"tagId"` // 标签id
TagImage string `json:"tagImage"` // 对应的图标
TagName string `json:"tagName"` // 标签名称
TagRemark string `json:"tagRemark"` // 标签备注
TotalArticle int `json:"totalArticle"` // 总的文章数量
ReadArticle int `json:"readArticle"` // 已读的标签数量
}
)
\ No newline at end of file
... ...
... ... @@ -84,9 +84,6 @@ type(
}
MiniUserInfoResponse {
User *UserItem `json:"user,omitempty"` // 用户信息
TotalArticle int64 `json:"totalArticle"` // 累计信息发布
TotalLoved int64 `json:"totalLoved"` // 累计收到的赞
TotalAccepted int64 `json:"totalAccepted"` // 累计被采纳
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniAllArticleTagRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleBackupSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
... ...
package article
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/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -14,7 +15,7 @@ func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleMarkListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -16,7 +16,7 @@ func MiniArticleMarkUserReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleMarkUserReadRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSetTagRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
... ...
... ... @@ -15,7 +15,7 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftDeleteMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -7,22 +7,23 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftGetMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := article.NewMiniGetArticleDraftMeLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.AuthorId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniGetArticleDraftMe(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSetUserLikeRequset
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniShowHomePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniHomePageRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniShowHomePageLogic(r.Context(), svcCtx)
resp, err := l.MiniShowHomePage(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx)
... ...
... ... @@ -15,7 +15,7 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUserLikeArticleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleCommentAtWhoRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniCreateArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewMiniCreateArticleCommentLogic(r.Context(), svcCtx)
... ...
... ... @@ -15,7 +15,7 @@ func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniDeleteArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniGetArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniListArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx)
... ...
... ... @@ -15,7 +15,7 @@ func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniTop5ArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -364,6 +364,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_tag/list/all",
Handler: article.MiniAllArticleTagHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/show/home_page",
Handler: article.MiniShowHomePageHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ...
... ... @@ -15,7 +15,7 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagEditRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
... ...
... ... @@ -15,7 +15,7 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -80,6 +81,14 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
if err != nil {
return err
}
// 定性消息通知
messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx)
err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title)
if err != nil {
return err
}
return nil
}, true)
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniShowHomePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniShowHomePageLogic {
return &MiniShowHomePageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageRespose, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -29,13 +30,13 @@ func (l *SystemDeleteLogic) SystemDelete(req *types.DepartmentGetRequest) (resp
one, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, err
return nil, xerr.NewErrMsg("数据不存在")
}
// 获取公司下的所有用户
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV(" companyId", one.CompanyId))
WithKV("companyId", one.CompanyId))
if err != nil {
return nil, err
}
... ...
... ... @@ -4,6 +4,7 @@ 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"
)
... ... @@ -26,7 +27,7 @@ func (l *SystemGetLogic) SystemGet(req *types.DepartmentGetRequest) (resp *types
var conn = l.svcCtx.DefaultDBConn()
department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, err
return nil, xerr.NewErrMsg("数据不存在")
}
resp = &types.DepartmentGetResponse{
Department: types.Department{
... ...
... ... @@ -58,7 +58,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
// 获取公司下的所有用户
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV(" companyId", one.CompanyId))
WithKV("companyId", one.CompanyId))
if err != nil {
return nil, err
}
... ... @@ -83,7 +83,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
if _, ok := newIdMap[user.Id]; ok {
var targetIndex = findIndex(user.Departments, req.Id)
if targetIndex == -1 { // 归属分组不存在,则新增
user.Departments = append(user.Departments)
user.Departments = append(user.Departments, req.Id)
_, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user)
if err != nil {
return err
... ...
... ... @@ -299,12 +299,9 @@ type MiniUserInfoRequest struct {
}
type MiniUserInfoResponse struct {
User *UserItem `json:"user,omitempty"` // 用户信息
TotalArticle int64 `json:"totalArticle"` // 累计信息发布
TotalLoved int64 `json:"totalLoved"` // 累计收到的赞
TotalAccepted int64 `json:"totalAccepted"` // 累计被采纳
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
User *UserItem `json:"user,omitempty"` // 用户信息
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
}
type MiniUserApplyJoinCompanyRequest struct {
... ... @@ -1002,6 +999,25 @@ type SystemArticleRestoreResponse struct {
ArticleId int64 `json:"articleId"` //文章ID
}
type MiniHomePageRequest struct {
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
type MiniHomePageRespose struct {
Tags []ArticleTagCount `json:"tags"`
}
type ArticleTagCount struct {
TagGroup string `json:"tagGroup"` // 标签分组
TagId int64 `json:"tagId"` // 标签id
TagImage string `json:"tagImage"` // 对应的图标
TagName string `json:"tagName"` // 标签名称
TagRemark string `json:"tagRemark"` // 标签备注
TotalArticle int `json:"totalArticle"` // 总的文章数量
ReadArticle int `json:"readArticle"` // 已读的标签数量
}
type RoleGetRequest struct {
Id int64 `path:"id"`
}
... ...
... ... @@ -53,3 +53,10 @@ func (m *ArticleAndTag) CachePrimaryKeyFunc() string {
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
// 统计所有已有标签的文章和人员已读的文章
type CountArticleTagRead struct {
TotalArticle int `gorm:"total_article"` //标签下文章的数量
ReadArticle int `gorm:"read_article"` //人员已读的文章
TagId int64 `gorm:"tag_id"` // 标签的id
}
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
... ... @@ -132,6 +133,59 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic
return to, err
}
// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) {
sqlStr := `
-- 首页统计数据
with
-- 按查看权限查询文章
-- 获取有标签的文章
-- 过滤出可展示的文章id
t_article_and_tag_2 as (
select article_and_tag.article_id , article_and_tag.tag_id
from article_and_tag
join article on article_and_tag.article_id = article.id
where article.deleted_at=0
and article.company_id =1598224576532189184
and article."show" =0
and (article.target_user =0 or article.who_read @>'[1]')
),
-- 查询人员已查看的文章
t_user_read as(
select user_read_article.article_id from user_read_article where user_read_article.user_id =1
)
-- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量
select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id
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
`
condition := []interface{}{
companyId,
fmt.Sprintf("[%d]", userId),
userId,
}
m := []*models.CountArticleTagRead{}
db := conn.DB()
result := db.Raw(sqlStr, condition...).Scan(&m)
if result.Error != nil {
return nil, result.Error
}
var dm []*domain.CountArticleTagRead
for _, val := range m {
dm = append(dm, &domain.CountArticleTagRead{
TagId: val.TagId,
TotalArticle: val.TotalArticle,
ReadArticle: val.ReadArticle,
})
}
return dm, nil
}
func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository {
return &ArticleAndTagRepository{CachedRepository: cache}
}
... ...
... ... @@ -278,34 +278,27 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor
return &ArticleRepository{CachedRepository: cache}
}
// -- 首页统计数据
// with
// -- 按查看权限查询文章
// t_article as(
// select article.id
// from article
// -- 获取有标签的文章
// -- 过滤出可展示的文章id
// t_article_and_tag_2 as (
// select article_and_tag.article_id , article_and_tag.tag_id
// from article_and_tag
// join article on article_and_tag.article_id = article.id
// where article.deleted_at=0
// and article.company_id =1598224576532189184
// and article."show" =0
// and (article.target_user =0 or article.who_read @>'[1]')
// ),
// -- 获取有标签的文章
// t_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
// 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
// ;
... ...
... ... @@ -16,10 +16,18 @@ type ArticleAndTag struct {
TagId int64 `json:"tagId"`
}
// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
type CountArticleTagRead struct {
TotalArticle int `gorm:"total_article"` //标签下文章的数量
ReadArticle int `gorm:"read_article"` //人员已读的文章
TagId int64 `gorm:"tag_id"` // 标签的id
}
type ArticleAndTagRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error)
CountArticleReadGroupByTag(ctx context.Context, con transaction.Conn, userId int64, companyId int64) ([]*CountArticleTagRead, error)
}
... ...