作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -32,5 +32,5 @@ ENV CONFIG_FILE=${CONFIG_FILE}
COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/discuss/api/etc/${CONFIG_FILE} ./etc/
EXPOSE 8080
EXPOSE 8081
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
syntax = "v1"
import "core/common.api"
import "core/comment.api"
import "core/message.api"
import "core/article_tag.api"
... ...
syntax = "v1"
info(
title: "天联鹰蜓"
desc: "天联鹰蜓"
author: "email"
email: "email"
version: "v1"
)
// 通用接口
@server(
prefix: v1/common
group: common
)
service Core {
@doc "短信验证码"
@handler commonSmsCode
post /sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne)
}
// 短信验证码
type(
CommonSmsCodeRequest{
Phone string `json:"phone"`
}
CommonSmsCodeResposne{
}
)
\ No newline at end of file
... ...
... ... @@ -16,15 +16,19 @@ info(
service Core {
@doc "系统消息"
@handler miniSystem
post /mini/message/system (MessageSystemRequest) returns (MessageSystemResponse)
post /mini/message/system (MessageRequest) returns (MessageSystemResponse)
@doc "业务消息"
@handler miniBusiness
post /mini/message/business (MessageBusinessRequest) returns (MessageBusinessResponse)
@doc "评论消息"
@handler miniComment
post /mini/message/comment (MessageRequest) returns (MessageBusinessResponse)
@doc "点赞消息"
@handler miniLike
post /mini/message/like (MessageRequest) returns (MessageBusinessResponse)
}
type (
MessageSystemRequest {
MessageRequest {
Page int `json:"page"`
Size int `json:"size"`
}
... ... @@ -40,11 +44,6 @@ type (
CreatedAt int64 `json:"createdAt"` // 创建时间
}
MessageBusinessRequest {
Type int `json:"type"`
Page int `json:"page"`
Size int `json:"size"`
}
MessageBusinessResponse {
List []MessageBusinessItem `json:"list"`
Total int64 `json:"total"`
... ...
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 CommonSmsCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CommonSmsCodeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := common.NewCommonSmsCodeLogic(r.Context(), svcCtx)
resp, err := l.CommonSmsCode(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package message
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
... ... @@ -10,16 +11,16 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func MiniCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageBusinessRequest
var req types.MessageRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
resp, err := l.MiniBusiness(&req)
resp, err := l.MiniBusiness(&req, domain.MsgTypeReply)
result.HttpResult(r, w, resp, err)
}
}
... ...
package message
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"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/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"
)
func MiniLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
resp, err := l.MiniBusiness(&req, domain.MsgTypeLike)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -12,7 +12,7 @@ import (
func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageSystemRequest
var req types.MessageRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
... ...
... ... @@ -6,6 +6,7 @@ import (
article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article"
comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
common "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/common"
company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company"
department "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/department"
message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message"
... ... @@ -22,6 +23,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/sms/code",
Handler: common.CommonSmsCodeHandler(serverCtx),
},
},
rest.WithPrefix("/v1/common"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article_comment",
Handler: comment.MiniCreateArticleCommentHandler(serverCtx),
},
... ... @@ -104,8 +116,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/message/business",
Handler: message.MiniBusinessHandler(serverCtx),
Path: "/mini/message/comment",
Handler: message.MiniCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/like",
Handler: message.MiniLikeHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
... ...
package common
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/smslib"
"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 CommonSmsCodeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCommonSmsCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommonSmsCodeLogic {
return &CommonSmsCodeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CommonSmsCodeLogic) CommonSmsCode(req *types.CommonSmsCodeRequest) (resp *types.CommonSmsCodeResposne, err error) {
_, err = l.svcCtx.SmsService.SendSmsCode(l.ctx, smslib.RequestSendSmsCode{
Phone: req.Phone,
})
if err != nil {
return nil, xerr.NewErrMsgErr(err.Error(), err)
}
resp = &types.CommonSmsCodeResposne{}
return
}
... ...
... ... @@ -26,10 +26,9 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
}
}
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType domain.MsgBusinessType) (resp *types.MessageBusinessResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
var msgType = req.Type
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
... ... @@ -100,8 +99,8 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
if len(companyIds) > 0 {
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
WithKV("ids", companyIds).
WithKV("limit", len(companyIds)))
if err != nil {
return nil, err
}
... ...
... ... @@ -25,7 +25,7 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy
}
}
func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) {
func (l *MiniSystemLogic) MiniSystem(req *types.MessageRequest) (resp *types.MessageSystemResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
... ...
... ... @@ -87,15 +87,16 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *
authSet := collection.NewSet()
for _, role := range roles {
for _, auth := range role.Auths {
if !authSet.Contains(auth) {
authSet.Add(auth)
if item := role.GetAuth(auth); item != nil {
resp.Auths = append(resp.Auths, types.Auth{
Id: item.Id,
Name: item.Name,
Code: item.Code,
})
}
if authSet.Contains(auth) {
continue
}
authSet.Add(auth)
if item := role.GetAuth(auth); item != nil {
resp.Auths = append(resp.Auths, types.Auth{
Id: item.Id,
Name: item.Name,
Code: item.Code,
})
}
}
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"github.com/silenceper/wechat/v2/cache"
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/smslib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
... ... @@ -121,6 +122,9 @@ func (c WxClientLogin) PhoneSmsCodeLogin(phone string, code string) (*domain.Log
users []*domain.User
err error
)
if _, err = c.l.svcCtx.SmsService.CheckSmsCode(c.l.ctx, smslib.RequestCheckSmsCode{Phone: phone, Code: code}); err != nil {
return nil, xerr.NewErrMsgErr(err.Error(), err)
}
conn := c.l.svcCtx.DefaultDBConn()
_, users, err = c.l.svcCtx.UserRepository.Find(c.l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", phone).
... ...
... ... @@ -10,9 +10,11 @@ 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/smslib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/database"
"gorm.io/gorm"
"time"
)
type ServiceContext struct {
... ... @@ -39,6 +41,7 @@ type ServiceContext struct {
UserRepository domain.UserRepository
ApiAuthService authlib.ApiAuthService
SmsService smslib.SMSService
LoginStatusCheck rest.Middleware
}
... ... @@ -57,6 +60,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
DB: db,
Redis: redis,
ApiAuthService: apiAuth,
SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)},
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
... ...
// Code generated by goctl. DO NOT EDIT.
package types
type CommonSmsCodeRequest struct {
Phone string `json:"phone"`
}
type CommonSmsCodeResposne struct {
}
type CommentAuthor struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
... ... @@ -172,7 +179,7 @@ type SystemListCommentRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId,optional"` // 评论的顶层ID
TopId int64 `json:"topId,optional"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
... ... @@ -245,7 +252,7 @@ type SystemEditCommentResponse struct {
Id int64 `json:"id"`
}
type MessageSystemRequest struct {
type MessageRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
... ... @@ -263,12 +270,6 @@ type MessageSystemItem struct {
CreatedAt int64 `json:"createdAt"` // 创建时间
}
type MessageBusinessRequest struct {
Type int `json:"type"`
Page int `json:"page"`
Size int `json:"size"`
}
type MessageBusinessResponse struct {
List []MessageBusinessItem `json:"list"`
Total int64 `json:"total"`
... ...
... ... @@ -24,5 +24,8 @@ type HttpError struct {
}
func (e HttpError) Error() string {
if e.Base.Code > 0 && e.Base.Msg != "" {
return e.Base.Msg
}
return fmt.Sprintf("HttpError code:%d msg:%s", e.Base.Code, e.Base.Msg)
}
... ...
package smslib
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway"
"net/http"
)
type SMSService struct {
gateway.Service
}
func (svc *SMSService) SendSmsCode(ctx context.Context, request RequestSendSmsCode) (*DataSendSmsCode, error) {
var result DataSendSmsCode
if err := svc.Do(ctx, "/service/sendSms", http.MethodPost, request, &result); err != nil {
return nil, err
}
return &result, nil
}
func (svc *SMSService) CheckSmsCode(ctx context.Context, request RequestCheckSmsCode) (*DataCheckSmsCode, error) {
var result DataCheckSmsCode
if err := svc.Do(ctx, "/service/checkSmsCode", http.MethodPost, request, &result); err != nil {
return nil, err
}
return &result, nil
}
... ...
package smslib
type (
RequestSendSmsCode struct {
Phone string `json:"phone"`
}
DataSendSmsCode struct {
}
)
type (
RequestCheckSmsCode struct {
Phone string `json:"phone"`
Code string `json:"code"`
}
DataCheckSmsCode struct {
}
)
... ...