作者 yangfu

chore: optimize P0 case

@@ -20,11 +20,15 @@ type FileDto struct { @@ -20,11 +20,15 @@ type FileDto struct {
20 Time string `json:"time"` 20 Time string `json:"time"`
21 } 21 }
22 22
23 -func (d *FileDto) Load(f *domain.File) { 23 +func (d *FileDto) Load(f *domain.File) *FileDto {
  24 + if f == nil {
  25 + return nil
  26 + }
24 d.FileId = f.FileId 27 d.FileId = f.FileId
25 d.Name = f.FileInfo.Name 28 d.Name = f.FileInfo.Name
26 d.Url = f.FileInfo.Url 29 d.Url = f.FileInfo.Url
27 d.FileType = f.FileType 30 d.FileType = f.FileType
28 d.Ext = f.FileInfo.Ext 31 d.Ext = f.FileInfo.Ext
29 d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05") 32 d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05")
  33 + return d
30 } 34 }
@@ -10,11 +10,15 @@ import ( @@ -10,11 +10,15 @@ import (
10 10
11 type GetFileQuery struct { 11 type GetFileQuery struct {
12 // 文件ID 12 // 文件ID
13 - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` 13 + FileId int `cname:"文件ID" json:"fileId"`
  14 +
  15 + FileName string `json:"name"`
  16 +
  17 + FileType string `json:"type"`
14 } 18 }
15 19
16 func (getFileQuery *GetFileQuery) Valid(validation *validation.Validation) { 20 func (getFileQuery *GetFileQuery) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 21 +
18 } 22 }
19 23
20 func (getFileQuery *GetFileQuery) ValidateQuery() error { 24 func (getFileQuery *GetFileQuery) ValidateQuery() error {
@@ -79,7 +79,7 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman @@ -79,7 +79,7 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman
79 } 79 }
80 80
81 // 返回文件服务 81 // 返回文件服务
82 -func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (interface{}, error) { 82 +func (fileService *FileService) GetFile(ctx *domain.Context, getFileQuery *query.GetFileQuery) (interface{}, error) {
83 if err := getFileQuery.ValidateQuery(); err != nil { 83 if err := getFileQuery.ValidateQuery(); err != nil {
84 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 84 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
85 } 85 }
@@ -101,18 +101,31 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter @@ -101,18 +101,31 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter
101 } else { 101 } else {
102 fileRepository = value 102 fileRepository = value
103 } 103 }
104 - file, err := fileRepository.FindOne(map[string]interface{}{"fileId": getFileQuery.FileId})  
105 - if err != nil {  
106 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 104 + response := map[string]interface{}{
  105 + "file": nil,
107 } 106 }
108 - if file == nil {  
109 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", getFileQuery.FileId))  
110 - } else {  
111 - if err := transactionContext.CommitTransaction(); err != nil {  
112 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
113 - }  
114 - return file, nil 107 + options := map[string]interface{}{"context": ctx}
  108 + if getFileQuery.FileId > 0 {
  109 + options["fileId"] = getFileQuery.FileId
  110 + }
  111 + if len(getFileQuery.FileName) > 0 {
  112 + options["fileName"] = getFileQuery.FileName
  113 + }
  114 + if len(getFileQuery.FileType) > 0 {
  115 + options["fileType"] = getFileQuery.FileType
  116 + }
  117 + if len(options) == 0 {
  118 + return response, nil
  119 + }
  120 + file, _ := fileRepository.FindOne(options)
  121 + //if err != nil {
  122 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  123 + //}
  124 + if err := transactionContext.CommitTransaction(); err != nil {
  125 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
115 } 126 }
  127 + response["file"] = (&dto.FileDto{}).Load(file)
  128 + return response, nil
116 } 129 }
117 130
118 // 返回文件服务列表 131 // 返回文件服务列表
@@ -11,13 +11,14 @@ import ( @@ -11,13 +11,14 @@ import (
11 ) 11 )
12 12
13 type FieldOptionalValuesCommand struct { 13 type FieldOptionalValuesCommand struct {
14 - ObjectType string `cname:"对象类型" json:"objectType" valid:"Required"`  
15 - ObjectId int `cname:"对象Id标识" json:"objectId" valid:"Required"`  
16 - Field domain.Field `cname:"列" json:"field" valid:"Required"`  
17 - Match string `cname:"匹配内容" json:"match"`  
18 - PageNumber int `json:"pageNumber"`  
19 - PageSize int `json:"pageSize"`  
20 - Condition *domain.Condition `json:"condition"` 14 + ObjectType string `cname:"对象类型" json:"objectType" valid:"Required"`
  15 + ObjectId int `cname:"对象Id标识" json:"objectId" valid:"Required"`
  16 + Field domain.Field `cname:"列" json:"field" valid:"Required"`
  17 + Match string `cname:"匹配内容" json:"match"`
  18 + PageNumber int `json:"pageNumber"`
  19 + PageSize int `json:"pageSize"`
  20 + //Condition []*domain.Condition `json:"conditions"`
  21 + Where *domain.Where `json:"where"`
21 } 22 }
22 23
23 func (cmd *FieldOptionalValuesCommand) Valid(validation *validation.Validation) { 24 func (cmd *FieldOptionalValuesCommand) Valid(validation *validation.Validation) {
@@ -90,10 +90,12 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * @@ -90,10 +90,12 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
90 }, 90 },
91 }, 91 },
92 } 92 }
93 - if cmd.Condition != nil {  
94 - options.Where = append(options.Where, starrocks.Condition{  
95 - Condition: *cmd.Condition,  
96 - }) 93 + if cmd.Where != nil && len(cmd.Where.Conditions) > 0 {
  94 + for _, c := range cmd.Where.Conditions {
  95 + options.Where = append(options.Where, starrocks.Condition{
  96 + Condition: c,
  97 + })
  98 + }
97 } 99 }
98 options.AdditionOptionsByTable(table) 100 options.AdditionOptionsByTable(table)
99 options.SetOffsetLimit(cmd.PageNumber, cmd.PageSize) 101 options.SetOffsetLimit(cmd.PageNumber, cmd.PageSize)
@@ -36,7 +36,9 @@ func (controller *FileController) GetFile() { @@ -36,7 +36,9 @@ func (controller *FileController) GetFile() {
36 getFileQuery := &query.GetFileQuery{} 36 getFileQuery := &query.GetFileQuery{}
37 fileId, _ := controller.GetInt(":fileId") 37 fileId, _ := controller.GetInt(":fileId")
38 getFileQuery.FileId = fileId 38 getFileQuery.FileId = fileId
39 - data, err := fileService.GetFile(getFileQuery) 39 + getFileQuery.FileName = controller.GetString("name")
  40 + getFileQuery.FileType = controller.GetString("type")
  41 + data, err := fileService.GetFile(ParseContext(controller.BaseController), getFileQuery)
40 controller.Response(data, err) 42 controller.Response(data, err)
41 } 43 }
42 44
@@ -9,6 +9,7 @@ func init() { @@ -9,6 +9,7 @@ func init() {
9 web.Router("/data/files/", &controllers.FileController{}, "Post:CreateFile") 9 web.Router("/data/files/", &controllers.FileController{}, "Post:CreateFile")
10 web.Router("/data/files/:fileId", &controllers.FileController{}, "Put:UpdateFile") 10 web.Router("/data/files/:fileId", &controllers.FileController{}, "Put:UpdateFile")
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", &controllers.FileController{}, "Get:GetFile")
12 web.Router("/data/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile") 13 web.Router("/data/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile")
13 web.Router("/data/files/", &controllers.FileController{}, "Get:ListFile") 14 web.Router("/data/files/", &controllers.FileController{}, "Get:ListFile")
14 web.Router("/data/files/check-status", &controllers.FileController{}, "Post:CheckFileVerifyStatus") 15 web.Router("/data/files/check-status", &controllers.FileController{}, "Post:CheckFileVerifyStatus")