作者 yangfu

feat: check file status

package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CheckFileVerifyStatusCommand struct {
// 文件ID
FileId int `cname:"文件ID" json:"objectId" valid:"Required"`
}
func (cmd *CheckFileVerifyStatusCommand) Valid(validation *validation.Validation) {
}
func (cmd *CheckFileVerifyStatusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -54,10 +54,10 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman
// 文件名相同进行替换
if oldFile, findOldFileErr := fileRepository.FindOne(map[string]interface{}{
"context": ctx,
"fileName": fileInfo.Name,
"context": ctx,
"fileName": fileInfo.Name,
"fileType": domain.SourceFile.ToString(),
}); oldFile != nil && findOldFileErr == nil {
}); oldFile != nil && findOldFileErr == nil {
oldFile.FileInfo = fileInfo
oldFile.UpdatedAt = time.Now()
newFile = oldFile
... ... @@ -319,6 +319,40 @@ func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *co
return struct{}{}, nil
}
// CheckFileVerifyStatus 检查文件校验状态
func (fileService *FileService) CheckFileVerifyStatus(ctx *domain.Context, cmd *command.CheckFileVerifyStatusCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
fileRepository, file, err := factory.FastPgFile(transactionContext, cmd.FileId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var res = struct {
ExistVerifyFile bool `json:"existVerifyFile"`
}{}
_, verifyFiles, findErr := fileRepository.Find(map[string]interface{}{"context": ctx, "fileType": domain.VerifiedFile.ToString(), "sourceFileId": file.SourceFileId})
if findErr == nil && len(verifyFiles) > 0 {
res.ExistVerifyFile = true
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return res, nil
}
func NewFileService(options map[string]interface{}) *FileService {
newFileService := &FileService{}
return newFileService
... ...
... ... @@ -2,11 +2,12 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"reflect"
"strings"
"time"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
... ... @@ -23,6 +24,8 @@ type SearchLogCommand struct {
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 对象名称
ObjectName string `cname:"页数" json:"objectName,omitempty"`
Year int `cname:"年" json:"year,omitempty"`
Month int `cname:"月" json:"month,omitempty"`
... ... @@ -49,6 +52,9 @@ func (cmd *SearchLogCommand) Valid(validation *validation.Validation) {
cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), cmd.Day, 0, 0, 0, 0, time.Local)
cmd.EndTime = cmd.BeginTime.AddDate(0, 0, 1)
}
if cmd.PageNumber == 0 {
cmd.PageNumber = 1
}
}
func (cmd *SearchLogCommand) ValidateCommand() error {
... ...
... ... @@ -16,10 +16,11 @@ func KeyTemporaryFileInfo(fileId int) string {
}
type TemporaryFileInfo struct {
FileId int `json:"fileId"`
FileType string `json:"fileType"`
Total int `json:"total"`
Fields []*domain.Field `json:"fields"`
OriginalFileId int `json:"originalFileId"`
FileId int `json:"fileId"`
FileType string `json:"fileType"`
Total int `json:"total"`
Fields []*domain.Field `json:"fields"`
// 编辑表错误,有错误不允许保存成校验文件
// 行记录错误
// 列类型有错误
... ... @@ -147,6 +148,7 @@ func NewFileCacheService() *FileCacheService {
}
type FileCacheOptions struct {
//OriginalFileId int
RemoveConvertTypeErrors []ConvertTypeError
AddConvertTypeErrors []ConvertTypeError
}
... ... @@ -165,6 +167,12 @@ func WithAddConvertTypeErrors(errors []ConvertTypeError) FileCacheOptionsFunc {
}
}
//func WithOriginalFileId(originalFileId int) FileCacheOptionsFunc {
// return func(o *FileCacheOptions) {
// o.OriginalFileId = originalFileId
// }
//}
func NewFileCacheOptions(options ...FileCacheOptionsFunc) *FileCacheOptions {
option := &FileCacheOptions{}
for i := range options {
... ...
... ... @@ -135,6 +135,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6
WhereContext(query, queryOptions)
query.SetWhereByQueryOption(" log_type = ?", "logType")
query.SetWhereByQueryOption(" source_id = ?", "sourceId")
query.SetWhereByQueryOption("object_name = ?", "objectName")
if v, ok := queryOptions["inSourceId"]; ok && len(v.([]int)) > 0 {
query.Where("source_id in (?)", pg.In(v.([]int)))
}
... ... @@ -155,7 +156,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6
query.SetWhereByQueryOption(" created_at < ?", "endTime")
}
SetOffsetAndLimit(query,queryOptions,20)
SetOffsetAndLimit(query, queryOptions, 20)
if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("log_id", v.(string))
} else {
... ...
... ... @@ -145,3 +145,11 @@ func (controller *FileController) CancelVerifyingFile() {
data, err := fileService.CancelVerifyingFile(ParseContext(controller.BaseController), cmd)
controller.Response(data, err)
}
func (controller *FileController) CheckFileVerifyStatus() {
fileService := service.NewFileService(nil)
cmd := &command.CheckFileVerifyStatusCommand{}
controller.Unmarshal(cmd)
data, err := fileService.CheckFileVerifyStatus(ParseContext(controller.BaseController), cmd)
controller.Response(data, err)
}
... ...
... ... @@ -11,6 +11,7 @@ func init() {
web.Router("/data/files/:fileId", &controllers.FileController{}, "Get:GetFile")
web.Router("/data/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile")
web.Router("/data/files/", &controllers.FileController{}, "Get:ListFile")
web.Router("/data/files/check-status", &controllers.FileController{}, "Post:CheckFileVerifyStatus")
web.Router("/data/files/search", &controllers.FileController{}, "Post:SearchFile")
web.Router("/data/files/search-source-file", &controllers.FileController{}, "Post:SearchSourceFile")
web.Router("/data/files/search-verified-file", &controllers.FileController{}, "Post:SearchVerifiedFile")
... ...