正在显示
7 个修改的文件
包含
98 行增加
和
2 行删除
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type CheckFileVerifyStatusCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"objectId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (cmd *CheckFileVerifyStatusCommand) Valid(validation *validation.Validation) { | ||
17 | + | ||
18 | +} | ||
19 | + | ||
20 | +func (cmd *CheckFileVerifyStatusCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(cmd) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(cmd).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
@@ -319,6 +319,40 @@ func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *co | @@ -319,6 +319,40 @@ func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *co | ||
319 | return struct{}{}, nil | 319 | return struct{}{}, nil |
320 | } | 320 | } |
321 | 321 | ||
322 | +// CheckFileVerifyStatus 检查文件校验状态 | ||
323 | +func (fileService *FileService) CheckFileVerifyStatus(ctx *domain.Context, cmd *command.CheckFileVerifyStatusCommand) (interface{}, error) { | ||
324 | + if err := cmd.ValidateCommand(); err != nil { | ||
325 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
326 | + } | ||
327 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
328 | + if err != nil { | ||
329 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
330 | + } | ||
331 | + if err := transactionContext.StartTransaction(); err != nil { | ||
332 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
333 | + } | ||
334 | + defer func() { | ||
335 | + transactionContext.RollbackTransaction() | ||
336 | + }() | ||
337 | + | ||
338 | + fileRepository, file, err := factory.FastPgFile(transactionContext, cmd.FileId) | ||
339 | + if err != nil { | ||
340 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
341 | + } | ||
342 | + var res = struct { | ||
343 | + ExistVerifyFile bool `json:"existVerifyFile"` | ||
344 | + }{} | ||
345 | + _, verifyFiles, findErr := fileRepository.Find(map[string]interface{}{"context": ctx, "fileType": domain.VerifiedFile.ToString(), "sourceFileId": file.SourceFileId}) | ||
346 | + if findErr == nil && len(verifyFiles) > 0 { | ||
347 | + res.ExistVerifyFile = true | ||
348 | + } | ||
349 | + | ||
350 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
351 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
352 | + } | ||
353 | + return res, nil | ||
354 | +} | ||
355 | + | ||
322 | func NewFileService(options map[string]interface{}) *FileService { | 356 | func NewFileService(options map[string]interface{}) *FileService { |
323 | newFileService := &FileService{} | 357 | newFileService := &FileService{} |
324 | return newFileService | 358 | return newFileService |
@@ -2,11 +2,12 @@ package command | @@ -2,11 +2,12 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
6 | "reflect" | 5 | "reflect" |
7 | "strings" | 6 | "strings" |
8 | "time" | 7 | "time" |
9 | 8 | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
10 | + | ||
10 | "github.com/beego/beego/v2/core/validation" | 11 | "github.com/beego/beego/v2/core/validation" |
11 | ) | 12 | ) |
12 | 13 | ||
@@ -23,6 +24,8 @@ type SearchLogCommand struct { | @@ -23,6 +24,8 @@ type SearchLogCommand struct { | ||
23 | PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | 24 | PageNumber int `cname:"页码" json:"pageNumber,omitempty"` |
24 | // 页数 | 25 | // 页数 |
25 | PageSize int `cname:"页数" json:"pageSize,omitempty"` | 26 | PageSize int `cname:"页数" json:"pageSize,omitempty"` |
27 | + // 对象名称 | ||
28 | + ObjectName string `cname:"页数" json:"objectName,omitempty"` | ||
26 | 29 | ||
27 | Year int `cname:"年" json:"year,omitempty"` | 30 | Year int `cname:"年" json:"year,omitempty"` |
28 | Month int `cname:"月" json:"month,omitempty"` | 31 | Month int `cname:"月" json:"month,omitempty"` |
@@ -49,6 +52,9 @@ func (cmd *SearchLogCommand) Valid(validation *validation.Validation) { | @@ -49,6 +52,9 @@ func (cmd *SearchLogCommand) Valid(validation *validation.Validation) { | ||
49 | cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), cmd.Day, 0, 0, 0, 0, time.Local) | 52 | cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), cmd.Day, 0, 0, 0, 0, time.Local) |
50 | cmd.EndTime = cmd.BeginTime.AddDate(0, 0, 1) | 53 | cmd.EndTime = cmd.BeginTime.AddDate(0, 0, 1) |
51 | } | 54 | } |
55 | + if cmd.PageNumber == 0 { | ||
56 | + cmd.PageNumber = 1 | ||
57 | + } | ||
52 | } | 58 | } |
53 | 59 | ||
54 | func (cmd *SearchLogCommand) ValidateCommand() error { | 60 | func (cmd *SearchLogCommand) ValidateCommand() error { |
@@ -16,6 +16,7 @@ func KeyTemporaryFileInfo(fileId int) string { | @@ -16,6 +16,7 @@ func KeyTemporaryFileInfo(fileId int) string { | ||
16 | } | 16 | } |
17 | 17 | ||
18 | type TemporaryFileInfo struct { | 18 | type TemporaryFileInfo struct { |
19 | + OriginalFileId int `json:"originalFileId"` | ||
19 | FileId int `json:"fileId"` | 20 | FileId int `json:"fileId"` |
20 | FileType string `json:"fileType"` | 21 | FileType string `json:"fileType"` |
21 | Total int `json:"total"` | 22 | Total int `json:"total"` |
@@ -147,6 +148,7 @@ func NewFileCacheService() *FileCacheService { | @@ -147,6 +148,7 @@ func NewFileCacheService() *FileCacheService { | ||
147 | } | 148 | } |
148 | 149 | ||
149 | type FileCacheOptions struct { | 150 | type FileCacheOptions struct { |
151 | + //OriginalFileId int | ||
150 | RemoveConvertTypeErrors []ConvertTypeError | 152 | RemoveConvertTypeErrors []ConvertTypeError |
151 | AddConvertTypeErrors []ConvertTypeError | 153 | AddConvertTypeErrors []ConvertTypeError |
152 | } | 154 | } |
@@ -165,6 +167,12 @@ func WithAddConvertTypeErrors(errors []ConvertTypeError) FileCacheOptionsFunc { | @@ -165,6 +167,12 @@ func WithAddConvertTypeErrors(errors []ConvertTypeError) FileCacheOptionsFunc { | ||
165 | } | 167 | } |
166 | } | 168 | } |
167 | 169 | ||
170 | +//func WithOriginalFileId(originalFileId int) FileCacheOptionsFunc { | ||
171 | +// return func(o *FileCacheOptions) { | ||
172 | +// o.OriginalFileId = originalFileId | ||
173 | +// } | ||
174 | +//} | ||
175 | + | ||
168 | func NewFileCacheOptions(options ...FileCacheOptionsFunc) *FileCacheOptions { | 176 | func NewFileCacheOptions(options ...FileCacheOptionsFunc) *FileCacheOptions { |
169 | option := &FileCacheOptions{} | 177 | option := &FileCacheOptions{} |
170 | for i := range options { | 178 | for i := range options { |
@@ -135,6 +135,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | @@ -135,6 +135,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | ||
135 | WhereContext(query, queryOptions) | 135 | WhereContext(query, queryOptions) |
136 | query.SetWhereByQueryOption(" log_type = ?", "logType") | 136 | query.SetWhereByQueryOption(" log_type = ?", "logType") |
137 | query.SetWhereByQueryOption(" source_id = ?", "sourceId") | 137 | query.SetWhereByQueryOption(" source_id = ?", "sourceId") |
138 | + query.SetWhereByQueryOption("object_name = ?", "objectName") | ||
138 | if v, ok := queryOptions["inSourceId"]; ok && len(v.([]int)) > 0 { | 139 | if v, ok := queryOptions["inSourceId"]; ok && len(v.([]int)) > 0 { |
139 | query.Where("source_id in (?)", pg.In(v.([]int))) | 140 | query.Where("source_id in (?)", pg.In(v.([]int))) |
140 | } | 141 | } |
@@ -155,7 +156,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | @@ -155,7 +156,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | ||
155 | query.SetWhereByQueryOption(" created_at < ?", "endTime") | 156 | query.SetWhereByQueryOption(" created_at < ?", "endTime") |
156 | } | 157 | } |
157 | 158 | ||
158 | - SetOffsetAndLimit(query,queryOptions,20) | 159 | + SetOffsetAndLimit(query, queryOptions, 20) |
159 | if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 { | 160 | if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 { |
160 | query.SetOrderDirect("log_id", v.(string)) | 161 | query.SetOrderDirect("log_id", v.(string)) |
161 | } else { | 162 | } else { |
@@ -145,3 +145,11 @@ func (controller *FileController) CancelVerifyingFile() { | @@ -145,3 +145,11 @@ func (controller *FileController) CancelVerifyingFile() { | ||
145 | data, err := fileService.CancelVerifyingFile(ParseContext(controller.BaseController), cmd) | 145 | data, err := fileService.CancelVerifyingFile(ParseContext(controller.BaseController), cmd) |
146 | controller.Response(data, err) | 146 | controller.Response(data, err) |
147 | } | 147 | } |
148 | + | ||
149 | +func (controller *FileController) CheckFileVerifyStatus() { | ||
150 | + fileService := service.NewFileService(nil) | ||
151 | + cmd := &command.CheckFileVerifyStatusCommand{} | ||
152 | + controller.Unmarshal(cmd) | ||
153 | + data, err := fileService.CheckFileVerifyStatus(ParseContext(controller.BaseController), cmd) | ||
154 | + controller.Response(data, err) | ||
155 | +} |
@@ -11,6 +11,7 @@ func init() { | @@ -11,6 +11,7 @@ func init() { | ||
11 | web.Router("/data/files/:fileId", &controllers.FileController{}, "Get:GetFile") | 11 | web.Router("/data/files/:fileId", &controllers.FileController{}, "Get:GetFile") |
12 | web.Router("/data/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile") | 12 | web.Router("/data/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile") |
13 | web.Router("/data/files/", &controllers.FileController{}, "Get:ListFile") | 13 | web.Router("/data/files/", &controllers.FileController{}, "Get:ListFile") |
14 | + web.Router("/data/files/check-status", &controllers.FileController{}, "Post:CheckFileVerifyStatus") | ||
14 | web.Router("/data/files/search", &controllers.FileController{}, "Post:SearchFile") | 15 | web.Router("/data/files/search", &controllers.FileController{}, "Post:SearchFile") |
15 | web.Router("/data/files/search-source-file", &controllers.FileController{}, "Post:SearchSourceFile") | 16 | web.Router("/data/files/search-source-file", &controllers.FileController{}, "Post:SearchSourceFile") |
16 | web.Router("/data/files/search-verified-file", &controllers.FileController{}, "Post:SearchVerifiedFile") | 17 | web.Router("/data/files/search-verified-file", &controllers.FileController{}, "Post:SearchVerifiedFile") |
-
请 注册 或 登录 后发表评论