作者 tangxvhui

Merge branch 'dev' into test

正在显示 46 个修改的文件 包含 625 行增加94 行删除
... ... @@ -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
}
// 短信验证码
... ... @@ -32,3 +48,10 @@ type(
}
)
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 (
... ...
... ... @@ -260,12 +260,13 @@ type (
SimpleComment {
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
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"`
... ...
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,16 +22,35 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: common.CommonGetLogHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/common/sms/code",
Handler: common.CommonSmsCodeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: common.CommonGetLogHandler(serverCtx),
Method: http.MethodPost,
Path: "/mini/qrcode",
Handler: common.MiniQrcodeInviteHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/clear",
Handler: common.CommonGetClearCacheHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/v1"),
)
... ... @@ -574,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),
... ...
... ... @@ -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,
}
// 发布者
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),
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,9 +262,8 @@ 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)
... ... @@ -262,9 +276,8 @@ func (l *MiniBusinessLogic) createMessage(
UserId: userToken.UserId,
RecipientId: at[i],
ArticleId: articleId,
SectionId: sectionId,
CommentId: commentId,
Content: content,
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
}
... ...
... ... @@ -109,9 +109,17 @@ func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, company *d
item.Comment = &types.SimpleComment{
Id: comment.Id,
Content: comment.Content,
CountLove: comment.CountUserLove,
CountComment: comment.CountReply,
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,
})
}
}
... ...
... ... @@ -109,9 +109,17 @@ func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, company *doma
item.Comment = &types.SimpleComment{
Id: comment.Id,
Content: comment.Content,
CountLove: comment.CountUserLove,
CountComment: comment.CountReply,
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,
},
}
... ...
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"` // 人员的名字
... ... @@ -283,19 +288,16 @@ type MessageBusinessResponse struct {
type MessageBusinessItem struct {
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"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
User *SimpleUser `json:"user"` // 操作人
Article *SimpleArticle `json:"article"` // 文章
Comment *SimpleComment `json:"comment"` // 评论(不一定是自己,可能是被人@到)
Comment *SimpleComment `json:"comment"` // 评论
CommentParent *SimpleComment `json:"commentParent"` // 被回复的评论
}
type SimpleUser struct {
... ... @@ -598,9 +600,11 @@ 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不显示)
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本
CountReply int `json:"countReply"` // 用户回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
}
type MiniBeLikedRequest struct {
... ...
... ... @@ -21,6 +21,7 @@ type Article struct {
Author domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 发布人
Title string // 文章标题
Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
Videos []domain.Video `gorm:"type:jsonb;serializer:json"` // 视频
WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
... ...
... ... @@ -16,10 +16,9 @@ type MessageBusiness struct {
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"` // 消息内容
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"`
... ...
... ... @@ -305,6 +305,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
Tags: from.Tags,
Summary: from.Summary,
MatchUrl: from.MatchUrl,
Videos: from.Videos,
}
return to, nil
}
... ... @@ -333,6 +334,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
Show: int(from.Show),
Summary: from.Summary,
MatchUrl: from.MatchUrl,
Videos: from.Videos,
}
// err := copier.Copy(to, from)
return to, nil
... ...
... ... @@ -18,6 +18,7 @@ type Article struct {
Author UserSimple `json:"author"` // 发布人
Title string `json:"title"` // 文章标题
Images []Image `json:"images"` // 图片
Videos []Video `json:"videos"` // 视频
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
... ...
... ... @@ -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"
... ...
... ... @@ -8,19 +8,20 @@ import (
type MessageBusiness struct {
Id int64 // 唯一标识
Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType MsgBusinessOpt `json:"optType"` // 操作类型(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"` // 消息内容
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),
... ...
... ... @@ -7,6 +7,14 @@ type Image struct {
Height int `json:"height"` // 图片高度
}
// 视频信息
type Video struct {
Url string `json:"url"` //视频文件的地址
Cover string `json:"cover"` //封面
Width int `json:"width"` //封面图片宽
Height int `json:"height"` //封面图片长
}
// 坐标位置
type Location struct {
Longitude float64 `json:"longitude"` //经度
... ...
... ... @@ -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"`
}
)
... ...