作者 yangfu

chore: optimize P0 case

... ... @@ -20,11 +20,15 @@ type FileDto struct {
Time string `json:"time"`
}
func (d *FileDto) Load(f *domain.File) {
func (d *FileDto) Load(f *domain.File) *FileDto {
if f == nil {
return nil
}
d.FileId = f.FileId
d.Name = f.FileInfo.Name
d.Url = f.FileInfo.Url
d.FileType = f.FileType
d.Ext = f.FileInfo.Ext
d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05")
return d
}
... ...
... ... @@ -10,11 +10,15 @@ import (
type GetFileQuery struct {
// 文件ID
FileId int `cname:"文件ID" json:"fileId" valid:"Required"`
FileId int `cname:"文件ID" json:"fileId"`
FileName string `json:"name"`
FileType string `json:"type"`
}
func (getFileQuery *GetFileQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getFileQuery *GetFileQuery) ValidateQuery() error {
... ...
... ... @@ -79,7 +79,7 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman
}
// 返回文件服务
func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (interface{}, error) {
func (fileService *FileService) GetFile(ctx *domain.Context, getFileQuery *query.GetFileQuery) (interface{}, error) {
if err := getFileQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -101,18 +101,31 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter
} else {
fileRepository = value
}
file, err := fileRepository.FindOne(map[string]interface{}{"fileId": getFileQuery.FileId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
response := map[string]interface{}{
"file": nil,
}
if file == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", getFileQuery.FileId))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return file, nil
options := map[string]interface{}{"context": ctx}
if getFileQuery.FileId > 0 {
options["fileId"] = getFileQuery.FileId
}
if len(getFileQuery.FileName) > 0 {
options["fileName"] = getFileQuery.FileName
}
if len(getFileQuery.FileType) > 0 {
options["fileType"] = getFileQuery.FileType
}
if len(options) == 0 {
return response, nil
}
file, _ := fileRepository.FindOne(options)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
response["file"] = (&dto.FileDto{}).Load(file)
return response, nil
}
// 返回文件服务列表
... ...
... ... @@ -11,13 +11,14 @@ import (
)
type FieldOptionalValuesCommand struct {
ObjectType string `cname:"对象类型" json:"objectType" valid:"Required"`
ObjectId int `cname:"对象Id标识" json:"objectId" valid:"Required"`
Field domain.Field `cname:"列" json:"field" valid:"Required"`
Match string `cname:"匹配内容" json:"match"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
Condition *domain.Condition `json:"condition"`
ObjectType string `cname:"对象类型" json:"objectType" valid:"Required"`
ObjectId int `cname:"对象Id标识" json:"objectId" valid:"Required"`
Field domain.Field `cname:"列" json:"field" valid:"Required"`
Match string `cname:"匹配内容" json:"match"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
//Condition []*domain.Condition `json:"conditions"`
Where *domain.Where `json:"where"`
}
func (cmd *FieldOptionalValuesCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -90,10 +90,12 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
},
},
}
if cmd.Condition != nil {
options.Where = append(options.Where, starrocks.Condition{
Condition: *cmd.Condition,
})
if cmd.Where != nil && len(cmd.Where.Conditions) > 0 {
for _, c := range cmd.Where.Conditions {
options.Where = append(options.Where, starrocks.Condition{
Condition: c,
})
}
}
options.AdditionOptionsByTable(table)
options.SetOffsetLimit(cmd.PageNumber, cmd.PageSize)
... ...
... ... @@ -36,7 +36,9 @@ func (controller *FileController) GetFile() {
getFileQuery := &query.GetFileQuery{}
fileId, _ := controller.GetInt(":fileId")
getFileQuery.FileId = fileId
data, err := fileService.GetFile(getFileQuery)
getFileQuery.FileName = controller.GetString("name")
getFileQuery.FileType = controller.GetString("type")
data, err := fileService.GetFile(ParseContext(controller.BaseController), getFileQuery)
controller.Response(data, err)
}
... ...
... ... @@ -9,6 +9,7 @@ func init() {
web.Router("/data/files/", &controllers.FileController{}, "Post:CreateFile")
web.Router("/data/files/:fileId", &controllers.FileController{}, "Put:UpdateFile")
web.Router("/data/files/:fileId", &controllers.FileController{}, "Get:GetFile")
web.Router("/data/files", &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")
... ...