Skip to content

Commit

Permalink
Merge pull request #3 from li1553770945/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
li1553770945 committed Mar 14, 2024
2 parents 115ba29 + dfc202e commit 64a1628
Show file tree
Hide file tree
Showing 8 changed files with 525 additions and 21 deletions.
2 changes: 1 addition & 1 deletion biz/container/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions biz/infra/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ type HttpConfig struct {
SecretKey string `yaml:"secret_key"`
}

type TencentConfig struct {
APPID int `yaml:"app_id"`
SecretKey string `yaml:"key"`
}

type Config struct {
DatabaseConfig DatabaseConfig `yaml:"database"`
HttpConfig HttpConfig `yaml:"http"`
TencentConfig TencentConfig `yaml:"tencent"`
}

func InitConfig(path string) *Config {
Expand Down
1 change: 1 addition & 0 deletions biz/internal/service/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (s *ChatService) CreateChat(ctx context.Context, c *app.RequestContext) {
}

var chatID string
// 防止生成重复聊天id
for {
chatID = U.RandSeq(4)
_, found := s.Cache.Get(chatID)
Expand Down
32 changes: 22 additions & 10 deletions biz/internal/service/global_service/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/robfig/cron/v3"
"os"
"personal-page-be/biz/internal/constant"
"time"
)

func (s *GlobalService) DeleteFile() {
Expand All @@ -17,19 +18,30 @@ func (s *GlobalService) DeleteFile() {
if file.IsDir() {
continue
}
fileEntity, err := s.Repo.FindFileBySaveName(file.Name())
if err != nil {
panic(err)
}
if fileEntity.ID == 0 || fileEntity.Count == 0 {
filePath := fmt.Sprintf("./%s/%s", constant.FileBasePath, file.Name())
err = os.Remove(filePath)
maxRetries := 5 // 最大重试次数
waitInterval := 500 // 初始等待间隔(毫秒)

for i := 0; i < maxRetries; i++ {
fileEntity, err := s.Repo.FindFileBySaveName(file.Name())
if err != nil {
s.Logger.Error("删除文件失败" + err.Error())
} else {
s.Logger.Info(fmt.Sprintf("删除文件%s成功", file.Name()))
s.Logger.Error("查询要删除的文件失败:" + err.Error())
time.Sleep(time.Duration(waitInterval) * time.Millisecond)
waitInterval *= 2 // 指数增长等待间隔
continue
}
if fileEntity.ID == 0 || fileEntity.Count == 0 {
filePath := fmt.Sprintf("./%s/%s", constant.FileBasePath, file.Name())
err = os.Remove(filePath)
if err != nil {
s.Logger.Error("删除文件失败" + err.Error())
} else {
s.Logger.Info(fmt.Sprintf("删除文件%s成功", file.Name()))
}
}
break

}

}
}
func (s *GlobalService) StartCronDeleteFile() {
Expand Down
10 changes: 7 additions & 3 deletions biz/internal/service/user/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package user
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"personal-page-be/biz/infra/config"
"personal-page-be/biz/internal/repo"
)

type UserService struct {
Repo repo.IRepository
Repo repo.IRepository
Config *config.Config
}

type IUserService interface {
Expand All @@ -16,10 +18,12 @@ type IUserService interface {
GetUserInfo(ctx context.Context, c *app.RequestContext)
GenerateActivateCode(ctx context.Context, c *app.RequestContext)
Register(ctx context.Context, c *app.RequestContext)
GenTencentIMUserSig(ctx context.Context, c *app.RequestContext)
}

func NewUserService(repo repo.IRepository) IUserService {
func NewUserService(repo repo.IRepository, config *config.Config) IUserService {
return &UserService{
Repo: repo,
Repo: repo,
Config: config,
}
}
Loading

0 comments on commit 64a1628

Please sign in to comment.