正在显示
8 个修改的文件
包含
88 行增加
和
2 行删除
1 | +package common | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/common" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | +) | ||
10 | + | ||
11 | +func CommonGetClearCacheHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
12 | + return func(w http.ResponseWriter, r *http.Request) { | ||
13 | + l := common.NewCommonGetClearCacheLogic(r.Context(), svcCtx) | ||
14 | + err := l.CommonGetClearCache() | ||
15 | + if err != nil { | ||
16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
17 | + } else { | ||
18 | + httpx.Ok(w) | ||
19 | + } | ||
20 | + } | ||
21 | +} |
@@ -31,6 +31,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -31,6 +31,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
31 | Path: "/log/:module", | 31 | Path: "/log/:module", |
32 | Handler: common.CommonGetLogHandler(serverCtx), | 32 | Handler: common.CommonGetLogHandler(serverCtx), |
33 | }, | 33 | }, |
34 | + { | ||
35 | + Method: http.MethodGet, | ||
36 | + Path: "/clear", | ||
37 | + Handler: common.CommonGetClearCacheHandler(serverCtx), | ||
38 | + }, | ||
34 | }, | 39 | }, |
35 | rest.WithPrefix("/v1"), | 40 | rest.WithPrefix("/v1"), |
36 | ) | 41 | ) |
1 | +package common | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "fmt" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/zeromicro/go-zero/core/logx" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
11 | +) | ||
12 | + | ||
13 | +type CommonGetClearCacheLogic struct { | ||
14 | + logx.Logger | ||
15 | + ctx context.Context | ||
16 | + svcCtx *svc.ServiceContext | ||
17 | +} | ||
18 | + | ||
19 | +func NewCommonGetClearCacheLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommonGetClearCacheLogic { | ||
20 | + return &CommonGetClearCacheLogic{ | ||
21 | + Logger: logx.WithContext(ctx), | ||
22 | + ctx: ctx, | ||
23 | + svcCtx: svcCtx, | ||
24 | + } | ||
25 | +} | ||
26 | + | ||
27 | +func (l *CommonGetClearCacheLogic) CommonGetClearCache() error { | ||
28 | + var ( | ||
29 | + appName = l.svcCtx.Config.Name | ||
30 | + success int | ||
31 | + ) | ||
32 | + if strings.TrimSpace(appName) == "" { | ||
33 | + return nil | ||
34 | + } | ||
35 | + keyPattern := fmt.Sprintf("%s*", appName) | ||
36 | + list, err := l.svcCtx.Redis.Keys(keyPattern) | ||
37 | + if err != nil { | ||
38 | + return xerr.NewErrMsg(err.Error()) | ||
39 | + } | ||
40 | + for _, key := range list { | ||
41 | + if _, err = l.svcCtx.Redis.Del(key); err == nil { | ||
42 | + success++ | ||
43 | + } | ||
44 | + } | ||
45 | + logx.Infof("清理缓存:%d/%d", success, len(list)) | ||
46 | + return nil | ||
47 | +} |
@@ -57,6 +57,6 @@ func NewCompany(item *domain.Company) types.Company { | @@ -57,6 +57,6 @@ func NewCompany(item *domain.Company) types.Company { | ||
57 | Id: item.Id, | 57 | Id: item.Id, |
58 | Name: item.Name, | 58 | Name: item.Name, |
59 | Code: item.Code, | 59 | Code: item.Code, |
60 | - Logo: item.Logo, | 60 | + Logo: lo.Ternary(item.Logo != "", item.Logo, domain.DefaultCompanyLog), |
61 | } | 61 | } |
62 | } | 62 | } |
@@ -52,6 +52,9 @@ func (l *SystemUserAccountSaveLogic) SystemUserAccountSave(req *types.SystemUser | @@ -52,6 +52,9 @@ func (l *SystemUserAccountSaveLogic) SystemUserAccountSave(req *types.SystemUser | ||
52 | if err != nil { | 52 | if err != nil { |
53 | return nil, xerr.NewErrMsgErr("申请失败", err) | 53 | return nil, xerr.NewErrMsgErr("申请失败", err) |
54 | } | 54 | } |
55 | + if user != nil { | ||
56 | + return nil, xerr.NewErrMsgErr("用户手机号已存在", err) | ||
57 | + } | ||
55 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | 58 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { |
56 | user = &domain.User{ | 59 | user = &domain.User{ |
57 | CompanyId: company.Id, | 60 | CompanyId: company.Id, |
@@ -87,8 +87,12 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) ( | @@ -87,8 +87,12 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) ( | ||
87 | company.Logo = response.CurrentCompany.Logo | 87 | company.Logo = response.CurrentCompany.Logo |
88 | changed = true | 88 | changed = true |
89 | } | 89 | } |
90 | + if company.Logo == "" { | ||
91 | + company.Logo = domain.DefaultCompanyLog | ||
92 | + changed = true | ||
93 | + } | ||
90 | if changed { | 94 | if changed { |
91 | - if company, err = l.svcCtx.CompanyRepository.UpdateWithVersion(l.ctx, conn, company); err != nil { | 95 | + if company, err = l.svcCtx.CompanyRepository.Update(l.ctx, conn, company); err != nil { |
92 | return nil, xerr.NewErrMsgErr("获取用户资料失败", err) | 96 | return nil, xerr.NewErrMsgErr("获取用户资料失败", err) |
93 | } | 97 | } |
94 | } | 98 | } |
@@ -33,3 +33,5 @@ func (m *Company) Identify() interface{} { | @@ -33,3 +33,5 @@ func (m *Company) Identify() interface{} { | ||
33 | } | 33 | } |
34 | return m.Id | 34 | return m.Id |
35 | } | 35 | } |
36 | + | ||
37 | +var DefaultCompanyLog = "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231114/object/1699934114_3r7QHThtbWfEDWh7CAHSzzWytFPzsjF6.png" |
-
请 注册 或 登录 后发表评论