后端重构

This commit is contained in:
Yvan
2026-01-08 20:16:27 +08:00
parent 9cb6b965e0
commit f5f77b32fe
23 changed files with 1450 additions and 2 deletions
+2
View File
@@ -26,8 +26,10 @@ var ProviderSet = wire.NewSet(
system.NewExportTemplateUsecase,
system.NewAutoCodeUsecase,
system.NewAutoCodeHistoryUsecase,
system.NewAutoCodePackageUsecase,
// Example
example.NewFileUploadUsecase,
example.NewCustomerUsecase,
example.NewAttachmentCategoryUsecase,
example.NewBreakpointContinueUsecase,
)
@@ -0,0 +1,56 @@
package example
import (
"context"
)
// ExaFile 文件实体
type ExaFile struct {
ID uint
FileName string
FileMd5 string
FilePath string
ChunkTotal int
IsFinish bool
ExaFileChunk []ExaFileChunk
}
// ExaFileChunk 文件切片实体
type ExaFileChunk struct {
ID uint
ExaFileID uint
FileChunkNumber int
FileChunkPath string
}
// BreakpointContinueRepo 断点续传仓储接口
type BreakpointContinueRepo interface {
FindOrCreateFile(ctx context.Context, fileMd5, fileName string, chunkTotal int) (*ExaFile, error)
CreateFileChunk(ctx context.Context, fileID uint, fileChunkPath string, fileChunkNumber int) error
DeleteFileChunk(ctx context.Context, fileMd5, filePath string) error
}
// BreakpointContinueUsecase 断点续传用例
type BreakpointContinueUsecase struct {
repo BreakpointContinueRepo
}
// NewBreakpointContinueUsecase 创建断点续传用例
func NewBreakpointContinueUsecase(repo BreakpointContinueRepo) *BreakpointContinueUsecase {
return &BreakpointContinueUsecase{repo: repo}
}
// FindOrCreateFile 查找或创建文件记录
func (uc *BreakpointContinueUsecase) FindOrCreateFile(ctx context.Context, fileMd5, fileName string, chunkTotal int) (*ExaFile, error) {
return uc.repo.FindOrCreateFile(ctx, fileMd5, fileName, chunkTotal)
}
// CreateFileChunk 创建文件切片记录
func (uc *BreakpointContinueUsecase) CreateFileChunk(ctx context.Context, fileID uint, fileChunkPath string, fileChunkNumber int) error {
return uc.repo.CreateFileChunk(ctx, fileID, fileChunkPath, fileChunkNumber)
}
// DeleteFileChunk 删除文件切片记录
func (uc *BreakpointContinueUsecase) DeleteFileChunk(ctx context.Context, fileMd5, filePath string) error {
return uc.repo.DeleteFileChunk(ctx, fileMd5, filePath)
}
+77
View File
@@ -0,0 +1,77 @@
package system
import (
"context"
)
// SysAutoCodePackage 代码包实体
type SysAutoCodePackage struct {
ID uint
Desc string
Label string
Template string
PackageName string
Module string
}
// AutoCodePackageRepo 代码包仓储接口
type AutoCodePackageRepo interface {
Create(ctx context.Context, pkg *SysAutoCodePackage) error
Delete(ctx context.Context, id uint) error
DeleteByNames(ctx context.Context, names []string) error
All(ctx context.Context) ([]SysAutoCodePackage, error)
First(ctx context.Context, packageName, template string) (*SysAutoCodePackage, error)
FindByPackageName(ctx context.Context, packageName string) (*SysAutoCodePackage, error)
BatchCreate(ctx context.Context, pkgs []SysAutoCodePackage) error
DeleteByIDs(ctx context.Context, ids []uint) error
}
// AutoCodePackageUsecase 代码包用例
type AutoCodePackageUsecase struct {
repo AutoCodePackageRepo
}
// NewAutoCodePackageUsecase 创建代码包用例
func NewAutoCodePackageUsecase(repo AutoCodePackageRepo) *AutoCodePackageUsecase {
return &AutoCodePackageUsecase{repo: repo}
}
// Create 创建包
func (uc *AutoCodePackageUsecase) Create(ctx context.Context, pkg *SysAutoCodePackage) error {
return uc.repo.Create(ctx, pkg)
}
// Delete 删除包
func (uc *AutoCodePackageUsecase) Delete(ctx context.Context, id uint) error {
return uc.repo.Delete(ctx, id)
}
// DeleteByNames 根据名称删除包
func (uc *AutoCodePackageUsecase) DeleteByNames(ctx context.Context, names []string) error {
return uc.repo.DeleteByNames(ctx, names)
}
// All 获取所有包
func (uc *AutoCodePackageUsecase) All(ctx context.Context) ([]SysAutoCodePackage, error) {
return uc.repo.All(ctx)
}
// First 查询包
func (uc *AutoCodePackageUsecase) First(ctx context.Context, packageName, template string) (*SysAutoCodePackage, error) {
return uc.repo.First(ctx, packageName, template)
}
// FindByPackageName 根据包名查询
func (uc *AutoCodePackageUsecase) FindByPackageName(ctx context.Context, packageName string) (*SysAutoCodePackage, error) {
return uc.repo.FindByPackageName(ctx, packageName)
}
// BatchCreate 批量创建
func (uc *AutoCodePackageUsecase) BatchCreate(ctx context.Context, pkgs []SysAutoCodePackage) error {
return uc.repo.BatchCreate(ctx, pkgs)
}
// DeleteByIDs 根据ID批量删除
func (uc *AutoCodePackageUsecase) DeleteByIDs(ctx context.Context, ids []uint) error {
return uc.repo.DeleteByIDs(ctx, ids)
}