正在显示
12 个修改的文件
包含
179 行增加
和
23 行删除
@@ -10,13 +10,17 @@ info( | @@ -10,13 +10,17 @@ info( | ||
10 | 10 | ||
11 | // 通用接口 | 11 | // 通用接口 |
12 | @server( | 12 | @server( |
13 | - prefix: v1/common | 13 | + prefix: v1 |
14 | group: common | 14 | group: common |
15 | ) | 15 | ) |
16 | service Core { | 16 | service Core { |
17 | @doc "短信验证码" | 17 | @doc "短信验证码" |
18 | @handler commonSmsCode | 18 | @handler commonSmsCode |
19 | - post /sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne) | 19 | + post /common/sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne) |
20 | + | ||
21 | + @doc "日志查询" | ||
22 | + @handler commonGetLog | ||
23 | + get /log/:module | ||
20 | } | 24 | } |
21 | 25 | ||
22 | // 短信验证码 | 26 | // 短信验证码 |
@@ -98,7 +98,7 @@ type( | @@ -98,7 +98,7 @@ type( | ||
98 | //MyStatisticsFlag bool `json:"myStatisticsFlag"` // true:返回统计信息 false;统计信息不返回 | 98 | //MyStatisticsFlag bool `json:"myStatisticsFlag"` // true:返回统计信息 false;统计信息不返回 |
99 | } | 99 | } |
100 | MiniUserInfoResponse { | 100 | MiniUserInfoResponse { |
101 | - User *UserItem `json:"user,omitempty"` // 用户信息 | 101 | + User *UserItem `json:"user,omitempty"` // 用户信息 |
102 | Accounts []Account `json:"accounts"` // 公司账号 | 102 | Accounts []Account `json:"accounts"` // 公司账号 |
103 | Auths []Auth `json:"auths"` // 权限列表 | 103 | Auths []Auth `json:"auths"` // 权限列表 |
104 | } | 104 | } |
@@ -108,7 +108,7 @@ type( | @@ -108,7 +108,7 @@ type( | ||
108 | IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加 | 108 | IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加 |
109 | } | 109 | } |
110 | MiniUserApplyJoinCompanyResponse{ | 110 | MiniUserApplyJoinCompanyResponse{ |
111 | - | 111 | + Token string `json:"token"` // x-token |
112 | } | 112 | } |
113 | MiniUserAuditRequest{ | 113 | MiniUserAuditRequest{ |
114 | UserId int64 `json:"userId"` // 用户ID | 114 | UserId int64 `json:"userId"` // 用户ID |
@@ -160,6 +160,7 @@ type( | @@ -160,6 +160,7 @@ type( | ||
160 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 160 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
161 | CompanyName string `json:"companyName,omitempty"` // 公司名称 | 161 | CompanyName string `json:"companyName,omitempty"` // 公司名称 |
162 | CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码) | 162 | CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码) |
163 | + CompanyLogo *string `json:"companyLogo,omitempty"` // 公司LOGO | ||
163 | //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | 164 | //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID |
164 | //Roles []int64 `json:"roleId,omitempty"` // 角色 | 165 | //Roles []int64 `json:"roleId,omitempty"` // 角色 |
165 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 166 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
@@ -7,7 +7,7 @@ Timeout: 30000 | @@ -7,7 +7,7 @@ Timeout: 30000 | ||
7 | # CertFile: ./key/fjmaimaimai.com_bundle.crt | 7 | # CertFile: ./key/fjmaimaimai.com_bundle.crt |
8 | # KeyFile: ./key/fjmaimaimai.com.key | 8 | # KeyFile: ./key/fjmaimaimai.com.key |
9 | Log: | 9 | Log: |
10 | - #Mode: file | 10 | + Mode: file |
11 | Encoding: plain | 11 | Encoding: plain |
12 | Level: debug # info | 12 | Level: debug # info |
13 | MaxSize: 1 # 2MB | 13 | MaxSize: 1 # 2MB |
1 | +package common | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "path/filepath" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
10 | +) | ||
11 | + | ||
12 | +func CommonGetLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
14 | + var req struct { | ||
15 | + Module string `path:"module"` | ||
16 | + } | ||
17 | + if err := httpx.Parse(r, &req); err != nil { | ||
18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
19 | + return | ||
20 | + } | ||
21 | + path := svcCtx.Config.Log.Path | ||
22 | + if svcCtx.Config.Log.Mode != "file" { | ||
23 | + return | ||
24 | + } | ||
25 | + if path == "" { | ||
26 | + path = "logs" | ||
27 | + } | ||
28 | + if !strings.HasSuffix(req.Module, ".log") { | ||
29 | + req.Module += ".log" | ||
30 | + } | ||
31 | + handler := http.FileServer(http.Dir(path)) | ||
32 | + r.URL.Path = filepath.Join(req.Module) | ||
33 | + handler.ServeHTTP(w, r) | ||
34 | + } | ||
35 | +} |
@@ -23,11 +23,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -23,11 +23,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
23 | []rest.Route{ | 23 | []rest.Route{ |
24 | { | 24 | { |
25 | Method: http.MethodPost, | 25 | Method: http.MethodPost, |
26 | - Path: "/sms/code", | 26 | + Path: "/common/sms/code", |
27 | Handler: common.CommonSmsCodeHandler(serverCtx), | 27 | Handler: common.CommonSmsCodeHandler(serverCtx), |
28 | }, | 28 | }, |
29 | + { | ||
30 | + Method: http.MethodGet, | ||
31 | + Path: "/log/:module", | ||
32 | + Handler: common.CommonGetLogHandler(serverCtx), | ||
33 | + }, | ||
29 | }, | 34 | }, |
30 | - rest.WithPrefix("/v1/common"), | 35 | + rest.WithPrefix("/v1"), |
31 | ) | 36 | ) |
32 | 37 | ||
33 | server.AddRoutes( | 38 | server.AddRoutes( |
1 | +package common | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/core/logx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
8 | +) | ||
9 | + | ||
10 | +type CommonGetLogLogic struct { | ||
11 | + logx.Logger | ||
12 | + ctx context.Context | ||
13 | + svcCtx *svc.ServiceContext | ||
14 | +} | ||
15 | + | ||
16 | +func NewCommonGetLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommonGetLogLogic { | ||
17 | + return &CommonGetLogLogic{ | ||
18 | + Logger: logx.WithContext(ctx), | ||
19 | + ctx: ctx, | ||
20 | + svcCtx: svcCtx, | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +func (l *CommonGetLogLogic) CommonGetLog() error { | ||
25 | + // todo: add your logic here and delete this line | ||
26 | + | ||
27 | + return nil | ||
28 | +} |
1 | +package message | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
8 | + | ||
9 | + "github.com/zeromicro/go-zero/core/logx" | ||
10 | +) | ||
11 | + | ||
12 | +type MiniCommentLogic struct { | ||
13 | + logx.Logger | ||
14 | + ctx context.Context | ||
15 | + svcCtx *svc.ServiceContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewMiniCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCommentLogic { | ||
19 | + return &MiniCommentLogic{ | ||
20 | + Logger: logx.WithContext(ctx), | ||
21 | + ctx: ctx, | ||
22 | + svcCtx: svcCtx, | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +func (l *MiniCommentLogic) MiniComment(req *types.MessageRequest) (resp *types.MessageBusinessResponse, err error) { | ||
27 | + // todo: add your logic here and delete this line | ||
28 | + | ||
29 | + return | ||
30 | +} |
1 | +package message | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
8 | + | ||
9 | + "github.com/zeromicro/go-zero/core/logx" | ||
10 | +) | ||
11 | + | ||
12 | +type MiniLikeLogic struct { | ||
13 | + logx.Logger | ||
14 | + ctx context.Context | ||
15 | + svcCtx *svc.ServiceContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewMiniLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniLikeLogic { | ||
19 | + return &MiniLikeLogic{ | ||
20 | + Logger: logx.WithContext(ctx), | ||
21 | + ctx: ctx, | ||
22 | + svcCtx: svcCtx, | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +func (l *MiniLikeLogic) MiniLike(req *types.MessageRequest) (resp *types.MessageBusinessResponse, err error) { | ||
27 | + // todo: add your logic here and delete this line | ||
28 | + | ||
29 | + return | ||
30 | +} |
@@ -35,6 +35,7 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | @@ -35,6 +35,7 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | ||
35 | company *domain.Company | 35 | company *domain.Company |
36 | user *domain.User | 36 | user *domain.User |
37 | name = fmt.Sprintf("用户%s", tool.Krand(6, tool.KC_RAND_KIND_NUM)) | 37 | name = fmt.Sprintf("用户%s", tool.Krand(6, tool.KC_RAND_KIND_NUM)) |
38 | + token string | ||
38 | ) | 39 | ) |
39 | if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); err != nil { | 40 | if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); err != nil { |
40 | return nil, xerr.NewErrMsgErr("公司不存在", err) | 41 | return nil, xerr.NewErrMsgErr("公司不存在", err) |
@@ -48,12 +49,14 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | @@ -48,12 +49,14 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | ||
48 | return nil, xerr.NewErrMsgErr("申请失败", err) | 49 | return nil, xerr.NewErrMsgErr("申请失败", err) |
49 | } | 50 | } |
50 | if user != nil { | 51 | if user != nil { |
51 | - if user.AuditStatus == domain.UserAuditStatusWait { | ||
52 | - return nil, xerr.NewErrMsgErr("已申请,待审核中", err) | 52 | + token, err = generateToken(l.svcCtx, user) |
53 | + if err != nil { | ||
54 | + return nil, xerr.NewErrMsgErr("登录失败", err) | ||
53 | } | 55 | } |
54 | - if user.AuditStatus == domain.UserAuditStatusPassed { | ||
55 | - return nil, xerr.NewErrMsgErr("公司已申请", err) | 56 | + resp = &types.MiniUserApplyJoinCompanyResponse{ |
57 | + Token: token, | ||
56 | } | 58 | } |
59 | + return | ||
57 | } | 60 | } |
58 | queryOptions := domain.NewQueryOptions(). | 61 | queryOptions := domain.NewQueryOptions(). |
59 | WithOffsetLimit(1, 1). | 62 | WithOffsetLimit(1, 1). |
@@ -87,6 +90,12 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | @@ -87,6 +90,12 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | ||
87 | }, true); err != nil { | 90 | }, true); err != nil { |
88 | return nil, xerr.NewErrMsgErr("申请失败", err) | 91 | return nil, xerr.NewErrMsgErr("申请失败", err) |
89 | } | 92 | } |
90 | - resp = &types.MiniUserApplyJoinCompanyResponse{} | 93 | + token, err = generateToken(l.svcCtx, user) |
94 | + if err != nil { | ||
95 | + return nil, xerr.NewErrMsgErr("登录失败", err) | ||
96 | + } | ||
97 | + resp = &types.MiniUserApplyJoinCompanyResponse{ | ||
98 | + Token: token, | ||
99 | + } | ||
91 | return | 100 | return |
92 | } | 101 | } |
@@ -2,6 +2,7 @@ package user | @@ -2,6 +2,7 @@ package user | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "github.com/samber/lo" | ||
5 | "github.com/zeromicro/go-zero/core/collection" | 6 | "github.com/zeromicro/go-zero/core/collection" |
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" |
@@ -45,10 +46,12 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | @@ -45,10 +46,12 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | ||
45 | 46 | ||
46 | resp = &types.MiniUserInfoResponse{ | 47 | resp = &types.MiniUserInfoResponse{ |
47 | User: &types.UserItem{ | 48 | User: &types.UserItem{ |
48 | - Id: user.Id, | ||
49 | - Name: user.Name, | ||
50 | - Avatar: user.Avatar, | ||
51 | - Position: user.Position, | 49 | + Id: user.Id, |
50 | + Name: user.Name, | ||
51 | + Avatar: user.Avatar, | ||
52 | + Position: user.Position, | ||
53 | + AuditStatus: lo.ToPtr(user.AuditStatus), | ||
54 | + Enable: user.Enable, | ||
52 | }, | 55 | }, |
53 | Accounts: make([]types.Account, 0), | 56 | Accounts: make([]types.Account, 0), |
54 | Auths: make([]types.Auth, 0), | 57 | Auths: make([]types.Auth, 0), |
@@ -56,6 +59,7 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | @@ -56,6 +59,7 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | ||
56 | if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { | 59 | if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { |
57 | resp.User.CompanyName = company.Name | 60 | resp.User.CompanyName = company.Name |
58 | resp.User.CompanyCode = company.Code | 61 | resp.User.CompanyCode = company.Code |
62 | + resp.User.CompanyLogo = lo.ToPtr(company.Logo) | ||
59 | } | 63 | } |
60 | _, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed})) | 64 | _, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed})) |
61 | if err != nil { | 65 | if err != nil { |
@@ -53,13 +53,7 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res | @@ -53,13 +53,7 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res | ||
53 | if loginInfo.User == nil { | 53 | if loginInfo.User == nil { |
54 | return nil, xerr.NewErrMsgErr("用户不存在", err) | 54 | return nil, xerr.NewErrMsgErr("用户不存在", err) |
55 | } | 55 | } |
56 | - var userJwtToken = tool.UserToken{} | ||
57 | - if loginInfo.User != nil { | ||
58 | - userJwtToken.UserId = loginInfo.User.Id | ||
59 | - userJwtToken.CompanyId = loginInfo.User.CompanyId | ||
60 | - userJwtToken.ClientType = "mini" | ||
61 | - } | ||
62 | - token, err = userJwtToken.GenerateToken(l.svcCtx.Config.MiniAuth.AccessSecret, l.svcCtx.Config.MiniAuth.AccessExpire) | 56 | + token, err = generateToken(l.svcCtx, loginInfo.User) |
63 | if err != nil { | 57 | if err != nil { |
64 | return nil, xerr.NewErrMsgErr("登录失败", err) | 58 | return nil, xerr.NewErrMsgErr("登录失败", err) |
65 | } | 59 | } |
@@ -74,6 +68,20 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res | @@ -74,6 +68,20 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res | ||
74 | return | 68 | return |
75 | } | 69 | } |
76 | 70 | ||
71 | +func generateToken(svcCtx *svc.ServiceContext, user *domain.User) (token string, err error) { | ||
72 | + var userJwtToken = tool.UserToken{} | ||
73 | + if user != nil { | ||
74 | + userJwtToken.UserId = user.Id | ||
75 | + userJwtToken.CompanyId = user.CompanyId | ||
76 | + userJwtToken.ClientType = "mini" | ||
77 | + } | ||
78 | + token, err = userJwtToken.GenerateToken(svcCtx.Config.MiniAuth.AccessSecret, svcCtx.Config.MiniAuth.AccessExpire) | ||
79 | + if err != nil { | ||
80 | + return "", xerr.NewErrMsgErr("登录失败", err) | ||
81 | + } | ||
82 | + return | ||
83 | +} | ||
84 | + | ||
77 | type WxClientLogin struct { | 85 | type WxClientLogin struct { |
78 | l *MiniUserLoginLogic | 86 | l *MiniUserLoginLogic |
79 | } | 87 | } |
@@ -439,6 +439,7 @@ type MiniUserApplyJoinCompanyRequest struct { | @@ -439,6 +439,7 @@ type MiniUserApplyJoinCompanyRequest struct { | ||
439 | } | 439 | } |
440 | 440 | ||
441 | type MiniUserApplyJoinCompanyResponse struct { | 441 | type MiniUserApplyJoinCompanyResponse struct { |
442 | + Token string `json:"token"` // x-token | ||
442 | } | 443 | } |
443 | 444 | ||
444 | type MiniUserAuditRequest struct { | 445 | type MiniUserAuditRequest struct { |
@@ -498,6 +499,7 @@ type UserItem struct { | @@ -498,6 +499,7 @@ type UserItem struct { | ||
498 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 499 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
499 | CompanyName string `json:"companyName,omitempty"` // 公司名称 | 500 | CompanyName string `json:"companyName,omitempty"` // 公司名称 |
500 | CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码) | 501 | CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码) |
502 | + CompanyLogo *string `json:"companyLogo,omitempty"` // 公司LOGO | ||
501 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 503 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
502 | Name string `json:"name,omitempty"` // 名称 | 504 | Name string `json:"name,omitempty"` // 名称 |
503 | Avatar string `json:"avatar,omitempty"` // 头像 | 505 | Avatar string `json:"avatar,omitempty"` // 头像 |
-
请 注册 或 登录 后发表评论