作者 tangxvhui
正在显示 45 个修改的文件 包含 792 行增加161 行删除
... ... @@ -14,13 +14,29 @@ info(
group: common
)
service Core {
@doc "日志查询"
@handler commonGetLog
get /log/:module
}
// 通用接口
@server(
prefix: v1
middleware: LogRequest
group: common
)
service Core {
@doc "短信验证码"
@handler commonSmsCode
post /common/sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne)
@doc "日志查询"
@handler commonGetLog
get /log/:module
@doc "微信二维码"
@handler miniQrcodeInvite
post /mini/qrcode (MiniQrCodeRequest)
@doc "清理缓存"
@handler commonGetClearCache
get /clear
}
// 短信验证码
... ... @@ -31,4 +47,11 @@ type(
CommonSmsCodeResposne{
}
)
type(
MiniQrCodeRequest{
Page string `json:"page"` // 微信页面入口
Scene string `json:"scene"` // 参数
}
)
\ No newline at end of file
... ...
... ... @@ -52,19 +52,20 @@ type (
MessageBusinessItem {
Id int64 `json:"id"`
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、2针对评论、3针对圆桌)
OptType int `json:"optType"` // 操作类型(1针对文章或段落、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收者ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
DiscussionId int64 `json:"discussionId"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
// CommentId int64 `json:"commentId"` // 评论ID
// DiscussionId int64 `json:"discussionId"` // 圆桌ID
// DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
// Content string `json:"content"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
User *SimpleUser `json:"user"` // 操作人
Article *SimpleArticle `json:"article"` // 文章
Comment *SimpleComment `json:"comment"` // 评论(不一定是自己,可能是被人@到)
Comment *SimpleComment `json:"comment"` // 评论
CommentParent *SimpleComment `json:"commentParent"` // 被回复的评论
}
SimpleUser {
... ...
... ... @@ -30,6 +30,9 @@ service Core {
@doc "角色列表搜索"
@handler systemSearchRole
post /system/role/search (RoleSearchRequest) returns (RoleSearchResponse)
@doc "角色权限列表"
@handler systemGetRoleAuths
get /system/role/auths
}
type (
... ...
... ... @@ -34,6 +34,9 @@ service Core {
@doc "用户信息"
@handler miniUserInfo
post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse)
@doc "编辑用户信息"
@handler miniEditUserInfo
post /mini/user/info/edit (MiniEditUserInfoRequest) returns (MiniEditUserInfoResponse)
@doc "用户统计"
@handler miniUserStatistics
post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
... ... @@ -79,6 +82,15 @@ service Core {
}
type(
MiniEditUserInfoRequest{
Avatar *string `json:"avatar"`
}
MiniEditUserInfoResponse{
}
)
type(
MiniUserLoginRequest {
LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
... ... @@ -246,14 +258,15 @@ type (
}
SimpleComment {
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本
CountReply int `json:"countReply"` // 用户回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
}
MiniBeLikedRequest{
Page int `json:"page"`
Size int `json:"size"`
... ... @@ -340,9 +353,10 @@ type(
ItemFlag int `json:"itemFlag"` //0:默认查询所有 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
}
UserStatisticsResponse{
TotalArticle int `json:"totalArticle"`
TotalComment int `json:"totalComment"`
TotalLoved int `json:"totalLoved"`
TotalArticle int `json:"totalArticle"` // 累计发布文章
TotalComment int `json:"totalComment"` // 累计发布评论
TotalLoved int `json:"totalLoved"` // 累计赞别人
TotalBeLoved int `json:"totalBeLoved"` // 累计收到的赞
}
StatisticsItem{
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
... ...
package common
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/common"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
func CommonGetClearCacheHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := common.NewCommonGetClearCacheLogic(r.Context(), svcCtx)
err := l.CommonGetClearCache()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
}
}
... ...
package common
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/common"
"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 MiniQrcodeInviteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniQrCodeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := common.NewMiniQrcodeInviteLogic(r.Context(), svcCtx)
resp, err := l.MiniQrcodeInvite(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package role
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
func SystemGetRoleAuthsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := role.NewSystemGetRoleAuthsLogic(r.Context(), svcCtx)
resp, err := l.SystemGetRoleAuths()
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -22,11 +22,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/common/sms/code",
Handler: common.CommonSmsCodeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: common.CommonGetLogHandler(serverCtx),
... ... @@ -41,6 +36,30 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/common/sms/code",
Handler: common.CommonSmsCodeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/qrcode",
Handler: common.MiniQrcodeInviteHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/clear",
Handler: common.CommonGetClearCacheHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article_comment",
Handler: comment.MiniCreateArticleCommentHandler(serverCtx),
},
... ... @@ -212,6 +231,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/info/edit",
Handler: user.MiniEditUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/statistics",
Handler: user.MiniUserStatisticsHandler(serverCtx),
},
... ... @@ -569,6 +593,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/system/role/search",
Handler: role.SystemSearchRoleHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/system/role/auths",
Handler: role.SystemGetRoleAuthsHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
... ...
package user
import (
"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 MiniEditUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniEditUserInfoRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniEditUserInfoLogic(r.Context(), svcCtx)
resp, err := l.MiniEditUserInfo(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -357,7 +357,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ
// 创建点赞消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.LikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.FromUserId)
err = messageLogic.LikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.Pid, commentInfo.FromUserId)
if err != nil {
return err
}
... ...
... ... @@ -205,9 +205,9 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
atAllIds = append(atAllIds, atWhoIds...)
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
if pComment != nil {
err = messageLogic.CommentReply(c, pComment.ArticleId, pComment.SectionId, pComment.Id, req.Content, atAllIds) // 对评论回复
err = messageLogic.CommentReply(c, req.ArtitcleId, newComment.Id, pComment.Id, atAllIds) // 对评论回复
} else {
err = messageLogic.CommentArticle(c, req.ArtitcleId, req.SectionId, req.Content, atAllIds) // 对文章回复
err = messageLogic.CommentArticle(c, req.ArtitcleId, newComment.Id, atAllIds) // 对文章回复
}
if err != nil {
return err
... ...
package common
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
type CommonGetClearCacheLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCommonGetClearCacheLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommonGetClearCacheLogic {
return &CommonGetClearCacheLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CommonGetClearCacheLogic) CommonGetClearCache() error {
var (
appName = l.svcCtx.Config.Name
success int
)
if strings.TrimSpace(appName) == "" {
return nil
}
keyPattern := fmt.Sprintf("%s*", appName)
list, err := l.svcCtx.Redis.Keys(keyPattern)
if err != nil {
return xerr.NewErrMsg(err.Error())
}
for _, key := range list {
if _, err = l.svcCtx.Redis.Del(key); err == nil {
success++
}
}
logx.Infof("清理缓存:%d/%d", success, len(list))
return nil
}
... ...
package common
import (
"context"
"encoding/json"
"fmt"
"github.com/samber/lo"
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/openlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
"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 MiniQrcodeInviteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniQrcodeInviteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniQrcodeInviteLogic {
return &MiniQrcodeInviteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniQrcodeInviteLogic) MiniQrcodeInvite(req *types.MiniQrCodeRequest) (resp interface{}, err error) {
var (
q = l.svcCtx.MiniProgram.GetQRCode()
cacheData = fmt.Sprintf("%s?%s", req.Page, req.Scene)
cacheKey = fmt.Sprintf("%s:qrcode:%s", l.svcCtx.Config.Name, tool.Md5ByString(cacheData))
ok bool
qrcodeCache QrcodeCache
)
// 从缓存获取
if ok, err = l.svcCtx.Redis.ExistsCtx(l.ctx, cacheKey); ok && err == nil {
tmpCacheData, _ := l.svcCtx.Redis.Get(cacheKey)
if err = json.Unmarshal([]byte(tmpCacheData), &qrcodeCache); err == nil {
if qrcodeCache.CacheData == cacheData {
return MiniQrCodeResponse{
Path: qrcodeCache.QrcodeUrl,
}, nil
}
}
}
var data []byte
data, err = q.GetWXACodeUnlimit(qrcode.QRCoder{
Page: req.Page,
Path: req.Page,
Scene: req.Scene,
CheckPath: lo.ToPtr(false),
EnvVersion: "release",
})
if err != nil {
return nil, xerr.NewErr(err)
}
var result *openlib.DataPutFile
result, err = l.svcCtx.OpenApiService.PutFile(l.ctx, openlib.RequestPutFile{
File: data,
})
if err != nil {
return nil, xerr.NewErr(err)
}
if result == nil || len(*result) == 0 || (*result)[0].Path == "" {
return nil, xerr.NewErr(fmt.Errorf("上传失败"))
}
// 设置缓存
jsonData, err := json.Marshal(QrcodeCache{
CacheData: cacheData,
QrcodeUrl: (*result)[0].Path,
})
l.svcCtx.Redis.Set(cacheKey, string(jsonData))
return MiniQrCodeResponse{
Path: (*result)[0].Path,
}, err
}
type MiniQrCodeResponse struct {
Path string `json:"path"`
}
type QrcodeCache struct {
CacheData string
QrcodeUrl string
}
... ...
... ... @@ -57,6 +57,6 @@ func NewCompany(item *domain.Company) types.Company {
Id: item.Id,
Name: item.Name,
Code: item.Code,
Logo: item.Logo,
Logo: lo.Ternary(item.Logo != "", item.Logo, domain.DefaultCompanyLog),
}
}
... ...
... ... @@ -50,8 +50,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
var userIdMap = map[int64]*domain.User{}
var articleIdMap = map[int64]*domain.Article{}
var commentIdMap = map[int64]*domain.ArticleComment{}
//var discussionIdMap = map[int64]int{}
//var discussionOpinionIdMap = map[int64]int{}
for _, item := range list {
if item.CompanyId != 0 {
companyIdMap[item.CompanyId] = nil
... ... @@ -65,19 +64,15 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
if item.CommentId != 0 {
commentIdMap[item.CommentId] = nil
}
//if item.DiscussionId != 0 {
// discussionIdMap[item.DiscussionId] = 0
//}
//if item.DiscussionOpinionId != 0 {
// discussionOpinionIdMap[item.DiscussionOpinionId] = 0
//}
if item.CommentParentId != 0 {
commentIdMap[item.CommentParentId] = nil
}
}
var companyIds = make([]int64, 0) // 公司ID
var userIds = make([]int64, 0) // 用户ID
var articleIds = make([]int64, 0) // 文章ID
var commentIds = make([]int64, 0) // 评论ID
//var discussionIds = make([]int64, 0) // 讨论ID 暂时搁置
//var discussionOpinionIds = make([]int64, 0) // 观点ID
var commentIds = make([]int64, 0) // 评论ID(包含回复的评论)
for k, _ := range companyIdMap {
companyIds = append(companyIds, k)
}
... ... @@ -90,12 +85,6 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
for k, _ := range commentIdMap {
commentIds = append(commentIds, k)
}
//for k, _ := range discussionIdMap {
// discussionIds = append(discussionIds, k)
//}
//for k, _ := range discussionOpinionIdMap {
// discussionOpinionIds = append(discussionOpinionIds, k)
//}
// 获取公司
if len(companyIds) > 0 {
... ... @@ -166,13 +155,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
UserId: item.UserId,
RecipientId: item.RecipientId,
ArticleId: item.ArticleId,
CommentId: item.CommentId,
//DiscussionId: item.DiscussionId,
//DiscussionOpinionId: item.DiscussionOpinionId,
Content: item.Content,
CreatedAt: item.CreatedAt,
CreatedAt: item.CreatedAt,
}
// 发布者
if v, ok := userIdMap[item.UserId]; ok && v != nil {
to.User = &types.SimpleUser{
Id: v.Id,
... ... @@ -187,6 +173,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
}
}
// 文章
if v, ok := articleIdMap[item.ArticleId]; ok && v != nil {
to.Article = &types.SimpleArticle{
Id: v.Id,
... ... @@ -197,13 +184,41 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
}
}
// 评论
if v, ok := commentIdMap[item.CommentId]; ok && v != nil {
to.Comment = &types.SimpleComment{
Id: v.Id,
Content: v.Content,
CountLove: v.CountUserLove,
CountComment: v.CountReply,
Show: int(v.Show),
Id: v.Id,
Content: v.Content,
Show: int(v.Show),
CountReply: v.CountReply,
CountUserLove: v.CountUserLove,
MatchUrl: v.MatchUrl,
}
to.Comment.AtWho = make([]types.CommentAtWho, 0)
for _, who := range v.AtWho {
to.Comment.AtWho = append(to.Comment.AtWho, types.CommentAtWho{
Id: who.Id,
Name: who.Name,
})
}
}
// 被回复的评论
if v, ok := commentIdMap[item.CommentParentId]; ok && v != nil {
to.CommentParent = &types.SimpleComment{
Id: v.Id,
Content: v.Content,
Show: int(v.Show),
CountReply: v.CountReply,
CountUserLove: v.CountUserLove,
MatchUrl: v.MatchUrl,
}
to.CommentParent.AtWho = make([]types.CommentAtWho, 0)
for _, who := range v.AtWho {
to.CommentParent.AtWho = append(to.CommentParent.AtWho, types.CommentAtWho{
Id: who.Id,
Name: who.Name,
})
}
}
... ... @@ -213,23 +228,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
}
// CommentArticle 评论文章
func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, sectionId int64, content string, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, sectionId, 0, content, at)
func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, commentId int64, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, commentId, 0, at)
}
// CommentReply 评论回复
func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, content string, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, sectionId, commentId, content, at)
func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, commentParentId int64, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, commentParentId, at)
}
// LikeArticle 点赞文章
func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, 0, "", []int64{at})
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, 0, []int64{at})
}
// LikeComment 点赞评论
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, 0, commentId, "", []int64{at})
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, commentParentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, commentParentId, []int64{at})
}
// UnLikeArticle 取消点赞文章
... ... @@ -247,24 +262,22 @@ func (l *MiniBusinessLogic) createMessage(
msgType domain.MsgBusinessType,
optType domain.MsgBusinessOpt,
articleId int64,
sectionId int64,
commentId int64,
content string,
commentParentId int64,
at []int64) (err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
// 评论中携带了 @其他用户
for i := range at {
var msg = &domain.MessageBusiness{
Type: msgType,
OptType: optType,
CompanyId: userToken.CompanyId,
UserId: userToken.UserId,
RecipientId: at[i],
ArticleId: articleId,
SectionId: sectionId,
CommentId: commentId,
Content: content,
Type: msgType,
OptType: optType,
CompanyId: userToken.CompanyId,
UserId: userToken.UserId,
RecipientId: at[i],
ArticleId: articleId,
CommentId: commentId,
CommentParentId: commentParentId,
}
msg, err = l.svcCtx.MessageBusinessRepository.Insert(l.ctx, conn, msg)
if err != nil {
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
type SystemGetRoleAuthsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemGetRoleAuthsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemGetRoleAuthsLogic {
return &SystemGetRoleAuthsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemGetRoleAuthsLogic) SystemGetRoleAuths() (interface{}, error) {
return map[string]interface{}{
"list": domain.Auths,
}, nil
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniEditUserInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniEditUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniEditUserInfoLogic {
return &MiniEditUserInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniEditUserInfoLogic) MiniEditUserInfo(req *types.MiniEditUserInfoRequest) (resp *types.MiniEditUserInfoResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
if err != nil {
return nil, err
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
user.Avatar = *req.Avatar
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("更新头像失败", err)
}
resp = &types.MiniEditUserInfoResponse{}
return
}
... ...
... ... @@ -107,11 +107,19 @@ func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, company *d
if comment != nil {
item.Comment = &types.SimpleComment{
Id: comment.Id,
Content: comment.Content,
CountLove: comment.CountUserLove,
CountComment: comment.CountReply,
Show: int(comment.Show),
Id: comment.Id,
Content: comment.Content,
Show: int(comment.Show),
CountReply: comment.CountReply,
CountUserLove: comment.CountUserLove,
MatchUrl: comment.MatchUrl,
}
item.Comment.AtWho = make([]types.CommentAtWho, 0)
for _, who := range comment.AtWho {
item.Comment.AtWho = append(item.Comment.AtWho, types.CommentAtWho{
Id: who.Id,
Name: who.Name,
})
}
}
... ...
... ... @@ -107,11 +107,19 @@ func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, company *doma
if comment != nil {
item.Comment = &types.SimpleComment{
Id: comment.Id,
Content: comment.Content,
CountLove: comment.CountUserLove,
CountComment: comment.CountReply,
Show: int(comment.Show),
Id: comment.Id,
Content: comment.Content,
Show: int(comment.Show),
CountReply: comment.CountReply,
CountUserLove: comment.CountUserLove,
MatchUrl: comment.MatchUrl,
}
item.Comment.AtWho = make([]types.CommentAtWho, 0)
for _, who := range comment.AtWho {
item.Comment.AtWho = append(item.Comment.AtWho, types.CommentAtWho{
Id: who.Id,
Name: who.Name,
})
}
}
... ...
... ... @@ -52,6 +52,9 @@ func (l *SystemUserAccountSaveLogic) SystemUserAccountSave(req *types.SystemUser
if err != nil {
return nil, xerr.NewErrMsgErr("申请失败", err)
}
if user != nil {
return nil, xerr.NewErrMsgErr("用户手机号已存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
user = &domain.User{
CompanyId: company.Id,
... ...
... ... @@ -87,8 +87,12 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (
company.Logo = response.CurrentCompany.Logo
changed = true
}
if company.Logo == "" {
company.Logo = domain.DefaultCompanyLog
changed = true
}
if changed {
if company, err = l.svcCtx.CompanyRepository.UpdateWithVersion(l.ctx, conn, company); err != nil {
if company, err = l.svcCtx.CompanyRepository.Update(l.ctx, conn, company); err != nil {
return nil, xerr.NewErrMsgErr("获取用户资料失败", err)
}
}
... ... @@ -112,55 +116,55 @@ func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
if cnt == 0 {
articleTags := []*domain.ArticleTag{
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_01.png", Width: 0, Height: 0},
Name: "紧急重要", Category: "紧急重要", Remark: "优先解决", SortBy: 1,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_04.png", Width: 0, Height: 0},
Name: "不紧急不重要", Category: "紧急重要", Remark: "给别人做", SortBy: 2,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_03.png", Width: 0, Height: 0},
Name: "紧急不重要", Category: "紧急重要", Remark: "有空再做", SortBy: 3,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_02.png", Width: 0, Height: 0},
Name: "不紧急重要", Category: "紧急重要", Remark: "制定计划去做", SortBy: 4,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_03.png", Width: 0, Height: 0},
Name: "大机会高风险", Category: "机会风险", Remark: "谨慎考虑专项讨论", SortBy: 5,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_02.png", Width: 0, Height: 0},
Name: "大机会中风险", Category: "机会风险", Remark: "加大关注值得尝试", SortBy: 6,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_01.png", Width: 0, Height: 0},
Name: "大机会低风险", Category: "机会风险", Remark: "全员投入抓紧落实", SortBy: 7,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_04.png", Width: 0, Height: 0},
Name: "中机会高风险", Category: "机会风险", Remark: "专人跟踪成立项目", SortBy: 8,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_05.png", Width: 0, Height: 0},
Name: "中机会中风险", Category: "机会风险", Remark: "讨论落实", SortBy: 9,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_06.png", Width: 0, Height: 0},
Name: "中机会低风险", Category: "机会风险", Remark: "解决问题多手准备", SortBy: 10,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_07.png", Width: 0, Height: 0},
Name: "小机会高风险", Category: "机会风险", Remark: "有空看看", SortBy: 11,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_08.png", Width: 0, Height: 0},
Name: "小机会中风险", Category: "机会风险", Remark: "持续监控做好控制", SortBy: 12,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_09.png", Width: 0, Height: 0},
Name: "小机会低风险", Category: "机会风险", Remark: "全员警戒马上解决", SortBy: 13,
},
}
... ...
... ... @@ -35,6 +35,7 @@ func (l *SystemUserStatisticsLogic) SystemUserStatistics(req *types.UserStatisti
TotalArticle: s.TotalArticle,
TotalComment: s.TotalComment,
TotalLoved: s.TotalLoved,
TotalBeLoved: s.TotalBeLoved,
}
return
}
... ... @@ -57,8 +58,13 @@ func StatisticsItems(ctx context.Context, svcCtx *svc.ServiceContext, companyId,
}
if (itemFlag & TotalLoved) > 0 {
var total int64
total, _, _ = svcCtx.UserLoveFlagRepository.Find(ctx, conn, domain.IndexCompanyId(companyId)().WithCountOnly().MustWithKV("userId", userId))
s.TotalComment = int(total)
total, _, _ = svcCtx.UserLoveFlagRepository.Find(ctx, conn, domain.IndexCompanyId(0)().WithCountOnly().MustWithKV("userId", userId))
s.TotalLoved = int(total)
}
if (itemFlag & TotalBeLoved) > 0 {
var total int64
total, _, _ = svcCtx.UserLoveFlagRepository.Find(ctx, conn, domain.IndexCompanyId(0)().WithCountOnly().MustWithKV("toUserId", userId))
s.TotalBeLoved = int(total)
}
return
}
... ... @@ -67,12 +73,14 @@ type Statistics struct {
TotalArticle int `json:"totalArticle"`
TotalComment int `json:"totalComment"`
TotalLoved int `json:"totalLoved"`
TotalBeLoved int `json:"totalBeLoved"`
}
const (
TotalArticle = 1
TotalComment = 2
TotalLoved = 4
TotalArticle = 1 // 累计发布文章
TotalComment = 2 // 累计发布评论
TotalLoved = 4 // 累计赞别人
TotalBeLoved = 8 // 累计收到的赞
)
func NewStatisticsItem(itemFlag int, value float64) types.StatisticsItem {
... ...
package svc
import (
"github.com/silenceper/wechat/v2"
minicache "github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/miniprogram"
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/rest"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config"
... ... @@ -10,6 +14,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/openlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/smslib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/database"
... ... @@ -43,6 +48,9 @@ type ServiceContext struct {
ApiAuthService authlib.ApiAuthService
SmsService smslib.SMSService
OpenApiService openlib.OpenApiService
MiniProgram *miniprogram.MiniProgram
LoginStatusCheck rest.Middleware
LogRequest rest.Middleware
... ... @@ -57,14 +65,21 @@ func NewServiceContext(c config.Config) *ServiceContext {
apiAuth := authlib.ApiAuthService{
Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout),
}
miniProgram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
AppID: c.Wechat.AppID,
AppSecret: c.Wechat.AppSecret,
Cache: minicache.NewMemory(),
})
return &ServiceContext{
Config: c,
DB: db,
Redis: redis,
ApiAuthService: apiAuth,
SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)},
OpenApiService: openlib.OpenApiService{Service: gateway.NewService("开发接口服务", "https://mmm-open-api-test.fjmaimaimai.com", time.Second*5)},
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
MiniProgram: miniProgram,
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
... ...
... ... @@ -8,6 +8,11 @@ type CommonSmsCodeRequest struct {
type CommonSmsCodeResposne struct {
}
type MiniQrCodeRequest struct {
Page string `json:"page"` // 微信页面入口
Scene string `json:"scene"` // 参数
}
type CommentAuthor struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
... ... @@ -281,21 +286,18 @@ type MessageBusinessResponse struct {
}
type MessageBusinessItem struct {
Id int64 `json:"id"`
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收者ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
DiscussionId int64 `json:"discussionId"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
User *SimpleUser `json:"user"` // 操作人
Article *SimpleArticle `json:"article"` // 文章
Comment *SimpleComment `json:"comment"` // 评论(不一定是自己,可能是被人@到)
Id int64 `json:"id"`
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章或段落、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收者ID
ArticleId int64 `json:"articleId"` // 文章ID
CreatedAt int64 `json:"createdAt"` // 创建时间
User *SimpleUser `json:"user"` // 操作人
Article *SimpleArticle `json:"article"` // 文章
Comment *SimpleComment `json:"comment"` // 评论
CommentParent *SimpleComment `json:"commentParent"` // 被回复的评论
}
type SimpleUser struct {
... ... @@ -411,6 +413,13 @@ type TagOptionValue struct {
Value int64 `json:"value"` // 标签ID
}
type MiniEditUserInfoRequest struct {
Avatar *string `json:"avatar"`
}
type MiniEditUserInfoResponse struct {
}
type MiniUserLoginRequest struct {
LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
... ... @@ -589,11 +598,13 @@ type MyLikeItem struct {
}
type SimpleComment struct {
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本
CountReply int `json:"countReply"` // 用户回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
}
type MiniBeLikedRequest struct {
... ... @@ -635,9 +646,10 @@ type UserStatisticsRequest struct {
}
type UserStatisticsResponse struct {
TotalArticle int `json:"totalArticle"`
TotalComment int `json:"totalComment"`
TotalLoved int `json:"totalLoved"`
TotalArticle int `json:"totalArticle"` // 累计发布文章
TotalComment int `json:"totalComment"` // 累计发布评论
TotalLoved int `json:"totalLoved"` // 累计赞别人
TotalBeLoved int `json:"totalBeLoved"` // 累计收到的赞
}
type StatisticsItem struct {
... ...
... ... @@ -10,21 +10,20 @@ import (
// MessageBusiness 消息中心业务
type MessageBusiness struct {
Id int64 // 唯一标识
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId,omitempty"` // 文章ID
SectionId int64 `json:"sectionId,omitempty"` // 段落ID
CommentId int64 `json:"commentId,omitempty"` // 评论ID
Content string `json:"content,omitempty"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
Id int64 // 唯一标识
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论来源ID
CommentParentId int64 `json:"commentParentId"` // 评论上级ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
//DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID
//DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID
}
... ...
... ... @@ -33,3 +33,5 @@ func (m *Company) Identify() interface{} {
}
return m.Id
}
var DefaultCompanyLog = "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231114/object/1699934114_3r7QHThtbWfEDWh7CAHSzzWytFPzsjF6.png"
... ...
... ... @@ -6,21 +6,22 @@ import (
)
type MessageBusiness struct {
Id int64 // 唯一标识
Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
SectionId int64 `json:"sectionId"` // 段落ID
CommentId int64 `json:"commentId"` // 评论ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
Id int64 // 唯一标识
Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章或段落、2针对评论、3针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论来源ID
CommentParentId int64 `json:"commentParentId"` // 评论上级ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
//SectionId int64 `json:"sectionId"` // 段落ID
//Content string `json:"content"` // 消息内容
//DiscussionId int64 `json:"discussionId"` // 圆桌ID
//DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
}
... ...
... ... @@ -52,7 +52,7 @@ type Auth struct {
}
var Auths = []Auth{
NewAuth(1001, "邀请注册", "MINI_INVITE-REGISTRATION", 0),
NewAuth(1001, "运营管理", "MINI_OPERATIONS-MANAGEMENT", 0),
NewAuth(1002, "帖子定性", "SYSTEM_POST-JUDGMENT", 0),
//NewAuth(1003, "圆桌判定", "SYSTEM_STUDENT-MANAGE", 0),
//NewAuth(1004, "圆桌运营", "SYSTEM_FEEDBACK-MANAGE", 0),
... ...
... ... @@ -15,8 +15,8 @@ type UserLoveFlag struct {
CommentId int64 `json:"commentId"` // 点赞评论时,填评论id
CommentAuthor int64 `json:"commentAuthor"` // 评论的填写人
ToUserId int64 `json:"toUserId"` // 点赞的接受人
UserId int64 `json:"userId"` // 点赞的人
CompanyId int64 `json:"companyId"` //
UserId int64 `json:"userId"` // 点赞人
CompanyId int64 `json:"companyId"` // 点赞人的公司
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
... ...
... ... @@ -14,7 +14,7 @@ import (
type Service struct {
Timeout time.Duration
host string
Host string
Interceptor func(msg string)
ServiceName string
service httpc.Service
... ... @@ -25,7 +25,7 @@ func NewService(name string, host string, timeout time.Duration, opts ...httpc.O
//client.Timeout = timeout
service := Service{
host: host,
Host: host,
service: httpc.NewServiceWithClient(name, client, opts...),
}
return service
... ... @@ -37,7 +37,7 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in
begin = time.Now()
body []byte
)
response, err := gateway.service.Do(ctx, method, gateway.host+url, val)
response, err := gateway.service.Do(ctx, method, gateway.Host+url, val)
defer func() {
jsonParam, _ := json.Marshal(val)
jsonData, _ := json.Marshal(result)
... ... @@ -45,7 +45,7 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in
result = err.Error()
}
if gateway.Interceptor != nil {
gateway.Interceptor(fmt.Sprintf("【网关】%v | %v%v | %v : %v \n-->> %v \n<<-- %v", time.Since(begin), gateway.host, url, strings.ToUpper(method),
gateway.Interceptor(fmt.Sprintf("【网关】%v | %v%v | %v : %v \n-->> %v \n<<-- %v", time.Since(begin), gateway.Host, url, strings.ToUpper(method),
result,
string(jsonParam),
string(jsonData),
... ... @@ -84,6 +84,62 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in
return nil
}
func (gateway Service) HandlerResponse(ctx context.Context, request *http.Request, response *http.Response, val, result interface{}) error {
var (
baseResponse = Response{}
begin = time.Now()
body []byte
err error
)
defer func() {
jsonParam, _ := json.Marshal(val)
jsonData, _ := json.Marshal(result)
if err != nil {
result = err.Error()
}
if gateway.Interceptor != nil {
gateway.Interceptor(fmt.Sprintf("【网关】%v | %v%v | %v : %v \n-->> %v \n<<-- %v", time.Since(begin), gateway.Host, request.URL.Path, request.Method,
result,
string(jsonParam),
string(jsonData),
))
}
}()
if err != nil {
return err
}
if response.StatusCode != http.StatusOK {
return HttpError{
Base: Response{
Code: response.StatusCode,
Msg: response.Status,
},
}
}
body, err = Bytes(response)
if err != nil {
return err
}
if err = json.Unmarshal(body, &baseResponse); err != nil {
return err
}
if baseResponse.Code != 0 {
return HttpError{
Base: Response{
Code: baseResponse.Code,
Msg: baseResponse.Msg,
},
}
}
if err = mapping.UnmarshalJsonBytes(baseResponse.Data, result); err != nil {
return err
}
return nil
}
func (gateway Service) GetService() httpc.Service {
return gateway.service
}
func Bytes(resp *http.Response) ([]byte, error) {
var body []byte
if resp.Body == nil {
... ...
package openlib
import (
"bytes"
"context"
"encoding/json"
"github.com/zeromicro/go-zero/core/mapping"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
)
type OpenApiService struct {
gateway.Service
}
func (svc *OpenApiService) PutFile(ctx context.Context, request RequestPutFile) (*DataPutFile, error) {
var result DataPutFile
r, _ := buildRequest(ctx, http.MethodPost, svc.Host+"/v1/vod/putObject", request)
response, err := svc.GetService().DoRequest(r)
if err != nil {
return nil, err
}
if err := svc.HandlerResponse(ctx, r, response, nil, &result); err != nil {
return nil, err
}
return &result, nil
}
func buildRequest(ctx context.Context, method, tmpUrl string, data any) (*http.Request, error) {
u, err := url.Parse(tmpUrl)
if err != nil {
return nil, err
}
var val map[string]map[string]any
if data != nil {
val, err = mapping.Marshal(data)
if err != nil {
return nil, err
}
}
var reader io.Reader
jsonVars, hasJsonBody := val["json"]
if hasJsonBody {
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
if err := enc.Encode(jsonVars); err != nil {
return nil, err
}
reader = &buf
}
req, err := http.NewRequestWithContext(ctx, method, u.String(), reader)
if err != nil {
return nil, err
}
fileVars, hasFile := val["file"]
if hasFile {
if err = fillFile(req, fileVars); err != nil {
return nil, err
}
}
if hasJsonBody {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
return req, nil
}
func fillFile(req *http.Request, val map[string]any) error {
if len(val) == 0 {
return nil
}
pr, pw := io.Pipe()
bodyWriter := multipart.NewWriter(pw)
go func() {
for k, v := range val {
fileWriter, err := bodyWriter.CreateFormFile(k, k)
if err != nil {
return
}
//fh, err := os.Open(v.(string))
//if err != nil {
// return err
//}
fh := bytes.NewBuffer(v.([]byte))
// iocopy
_, err = io.Copy(fileWriter, fh)
if err != nil {
return
}
}
bodyWriter.Close()
pw.Close()
}()
req.Header.Set("Content-Type", bodyWriter.FormDataContentType())
req.Body = ioutil.NopCloser(pr)
req.Header.Set("Transfer-Encoding", "chunked")
return nil
}
... ...
package openlib
type (
RequestPutFile struct {
File []byte `file:"file.png"`
}
DataPutFile []*DataUploadItem
DataUploadItem struct {
Host string `json:"host"`
Key string `json:"key"`
Path string `json:"path"`
FileName string `json:"fileName"`
}
)
... ...