作者 yangfu

默认公司LOGO、缓存清理

... ... @@ -21,6 +21,10 @@ service Core {
@doc "日志查询"
@handler commonGetLog
get /log/:module
@doc "清理缓存"
@handler commonGetClearCache
get /clear
}
// 短信验证码
... ...
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)
}
}
}
... ...
... ... @@ -31,6 +31,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/log/:module",
Handler: common.CommonGetLogHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/clear",
Handler: common.CommonGetClearCacheHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
... ...
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
}
... ...
... ... @@ -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),
}
}
... ...
... ... @@ -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)
}
}
... ...
... ... @@ -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"
... ...