正在显示
18 个修改的文件
包含
448 行增加
和
39 行删除
@@ -9,3 +9,104 @@ | @@ -9,3 +9,104 @@ | ||
9 | - 持久化 - flushDataTable | 9 | - 持久化 - flushDataTable |
10 | - 导出 - url | 10 | - 导出 - url |
11 | - 删除 - delete | 11 | - 删除 - delete |
12 | +- 操作日志 - log | ||
13 | + | ||
14 | + | ||
15 | +- editDataTable params 列表 | ||
16 | + | ||
17 | +### 加载表格数据 loadDataTable - 查询 | ||
18 | + | ||
19 | +```json | ||
20 | +{ | ||
21 | + "fileId": 1, | ||
22 | + "where": [ | ||
23 | + { | ||
24 | + "field": { | ||
25 | + "index": 1, | ||
26 | + "name": "产品名称" | ||
27 | + }, | ||
28 | + "in": ["a","b"], | ||
29 | + "ex": ["c","d"], | ||
30 | + "sort": ["a","asc"] | ||
31 | + } | ||
32 | + ] | ||
33 | +} | ||
34 | +``` | ||
35 | + | ||
36 | +### 编辑表格 editDataTable | ||
37 | + | ||
38 | +```json | ||
39 | +{ | ||
40 | + "field": { | ||
41 | + "index": 1, | ||
42 | + "name": "产品名称" | ||
43 | + }, | ||
44 | + "operation": { | ||
45 | + "desc": ["拆分","按字符数"], | ||
46 | + "code": "split_by_char_number" | ||
47 | + }, | ||
48 | + "params": [] | ||
49 | +} | ||
50 | +``` | ||
51 | +精简 | ||
52 | +```json | ||
53 | +{ | ||
54 | + "field": "产品名称", | ||
55 | + "desc": ["拆分","按字符数"], | ||
56 | + "operationCode": "split_by_char_number", | ||
57 | + "params": [] | ||
58 | +} | ||
59 | +``` | ||
60 | + | ||
61 | +`params 列表` | ||
62 | + | ||
63 | + | ||
64 | +### 数据展示 | ||
65 | + | ||
66 | +```json | ||
67 | +{ | ||
68 | + "code": 0, | ||
69 | + "data": { | ||
70 | + "dataFields": [ | ||
71 | + { | ||
72 | + "index": 1, | ||
73 | + "name": "产品名称", | ||
74 | + "Type": "string" | ||
75 | + }, | ||
76 | + { | ||
77 | + "index": 2, | ||
78 | + "name": "产品数量", | ||
79 | + "Type": "number" | ||
80 | + } | ||
81 | + ], | ||
82 | + "dataRows": [ | ||
83 | + [ | ||
84 | + "素面", | ||
85 | + 200 | ||
86 | + ], | ||
87 | + [ | ||
88 | + "冻豆腐", | ||
89 | + 400 | ||
90 | + ], | ||
91 | + [ | ||
92 | + "冻豆腐1", | ||
93 | + 300 | ||
94 | + ], | ||
95 | + [ | ||
96 | + "冻豆2", | ||
97 | + "A" | ||
98 | + ] | ||
99 | + ], | ||
100 | + "total": 100, | ||
101 | + "pageNumber": 1, | ||
102 | + "inValidCells": [ | ||
103 | + { | ||
104 | + "x": 1, | ||
105 | + "y": 3, | ||
106 | + "error": "不是一个有效的数值" | ||
107 | + } | ||
108 | + ] | ||
109 | + }, | ||
110 | + "msg": "ok" | ||
111 | +} | ||
112 | +``` |
@@ -13,12 +13,12 @@ type CreateFileCommand struct { | @@ -13,12 +13,12 @@ type CreateFileCommand struct { | ||
13 | Name string `cname:"名称" json:"name" valid:"Required"` | 13 | Name string `cname:"名称" json:"name" valid:"Required"` |
14 | // 文件地址 | 14 | // 文件地址 |
15 | Url string `cname:"文件地址" json:"url" valid:"Required"` | 15 | Url string `cname:"文件地址" json:"url" valid:"Required"` |
16 | - // 文件大小 | 16 | + // 文件大小 单位KB |
17 | FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` | 17 | FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` |
18 | } | 18 | } |
19 | 19 | ||
20 | func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { | 20 | func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { |
21 | - validation.SetError("CustomValid", "未实现的自定义认证") | 21 | + |
22 | } | 22 | } |
23 | 23 | ||
24 | func (createFileCommand *CreateFileCommand) ValidateCommand() error { | 24 | func (createFileCommand *CreateFileCommand) ValidateCommand() error { |
@@ -14,7 +14,7 @@ type EditDataTableCommand struct { | @@ -14,7 +14,7 @@ type EditDataTableCommand struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { | 16 | func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + |
18 | } | 18 | } |
19 | 19 | ||
20 | func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { | 20 | func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { |
@@ -14,7 +14,7 @@ type LoadDataTableCommand struct { | @@ -14,7 +14,7 @@ type LoadDataTableCommand struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (loadDataTableCommand *LoadDataTableCommand) Valid(validation *validation.Validation) { | 16 | func (loadDataTableCommand *LoadDataTableCommand) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + |
18 | } | 18 | } |
19 | 19 | ||
20 | func (loadDataTableCommand *LoadDataTableCommand) ValidateCommand() error { | 20 | func (loadDataTableCommand *LoadDataTableCommand) ValidateCommand() error { |
@@ -14,7 +14,7 @@ type RemoveFileCommand struct { | @@ -14,7 +14,7 @@ type RemoveFileCommand struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (removeFileCommand *RemoveFileCommand) Valid(validation *validation.Validation) { | 16 | func (removeFileCommand *RemoveFileCommand) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + |
18 | } | 18 | } |
19 | 19 | ||
20 | func (removeFileCommand *RemoveFileCommand) ValidateCommand() error { | 20 | func (removeFileCommand *RemoveFileCommand) ValidateCommand() error { |
pkg/application/file/dto/datatable_dto.go
0 → 100644
1 | +package dto | ||
2 | + | ||
3 | +type DataTableDto struct { | ||
4 | + DataFields []*Field `json:"dataFields"` | ||
5 | + DataRows [][]interface{} `json:"dataRows"` | ||
6 | + Total int `json:"total"` | ||
7 | + PageNumber int `json:"pageNumber"` | ||
8 | + InValidCells []InValidCell `json:"inValidCells"` | ||
9 | +} | ||
10 | + | ||
11 | +type Field struct { | ||
12 | + // 索引序号 | ||
13 | + Index int `json:"index"` | ||
14 | + // 名称 | ||
15 | + Name string `json:"name"` | ||
16 | + // 对应数据库类型 | ||
17 | + Type string `json:"Type"` | ||
18 | +} | ||
19 | + | ||
20 | +type InValidCell struct { | ||
21 | + X int `json:"x"` | ||
22 | + Y int `json:"y"` | ||
23 | + Error string `json:"error"` | ||
24 | +} | ||
25 | + | ||
26 | +func NewDataTableDtoDemo() DataTableDto { | ||
27 | + return DataTableDto{ | ||
28 | + DataFields: []*Field{ | ||
29 | + { | ||
30 | + Index: 1, | ||
31 | + Name: "产品名称", | ||
32 | + Type: "string", | ||
33 | + }, | ||
34 | + { | ||
35 | + Index: 2, | ||
36 | + Name: "产品数量", | ||
37 | + Type: "number", | ||
38 | + }, | ||
39 | + }, | ||
40 | + DataRows: [][]interface{}{ | ||
41 | + {"素面", 200}, | ||
42 | + {"冻豆腐", 400}, | ||
43 | + {"冻豆腐1", 300}, | ||
44 | + {"冻豆2", "A"}, | ||
45 | + }, | ||
46 | + InValidCells: []InValidCell{ | ||
47 | + { | ||
48 | + X: 1, | ||
49 | + Y: 3, | ||
50 | + Error: "不是一个有效的数值", | ||
51 | + }, | ||
52 | + }, | ||
53 | + PageNumber: 1, | ||
54 | + Total: 100, | ||
55 | + } | ||
56 | +} |
pkg/application/file/query/search_file.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type SearchFileQuery struct { | ||
13 | + // 查询偏离量 | ||
14 | + // Offset int `cname:"查询偏离量" json:"offset"` | ||
15 | + // 查询限制 | ||
16 | + Limit int `cname:"查询限制" json:"limit"` | ||
17 | + // 页码 | ||
18 | + // PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
19 | + // 页数 | ||
20 | + FileName int `cname:"文件名称" json:"fileName,omitempty"` | ||
21 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
22 | + LastId int `cname:"最后一条记录ID" json:"lastId"` | ||
23 | + FileType domain.FileType `cname:"文件类型" json:"fileType" valid:"Required"` | ||
24 | +} | ||
25 | + | ||
26 | +func (cmd *SearchFileQuery) Valid(validation *validation.Validation) { | ||
27 | + cmd.Limit = cmd.PageSize | ||
28 | +} | ||
29 | + | ||
30 | +func (cmd *SearchFileQuery) ValidateQuery() error { | ||
31 | + valid := validation.Validation{} | ||
32 | + b, err := valid.Valid(cmd) | ||
33 | + if err != nil { | ||
34 | + return err | ||
35 | + } | ||
36 | + if !b { | ||
37 | + elem := reflect.TypeOf(cmd).Elem() | ||
38 | + for _, validErr := range valid.Errors { | ||
39 | + field, isExist := elem.FieldByName(validErr.Field) | ||
40 | + if isExist { | ||
41 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
42 | + } else { | ||
43 | + return fmt.Errorf(validErr.Message) | ||
44 | + } | ||
45 | + } | ||
46 | + } | ||
47 | + return nil | ||
48 | +} |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "github.com/linmadan/egglib-go/utils/tool_funs" | 6 | "github.com/linmadan/egglib-go/utils/tool_funs" |
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" |
8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto" | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" |
10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
11 | ) | 12 | ) |
@@ -29,27 +30,27 @@ func (fileService *FileService) CreateFile(createFileCommand *command.CreateFile | @@ -29,27 +30,27 @@ func (fileService *FileService) CreateFile(createFileCommand *command.CreateFile | ||
29 | defer func() { | 30 | defer func() { |
30 | transactionContext.RollbackTransaction() | 31 | transactionContext.RollbackTransaction() |
31 | }() | 32 | }() |
32 | - newFile := &domain.File{ | ||
33 | - //Name: createFileCommand.Name, | ||
34 | - //Url: createFileCommand.Url, | ||
35 | - //FileSize: createFileCommand.FileSize, | ||
36 | - } | ||
37 | - var fileRepository domain.FileRepository | ||
38 | - if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
39 | - "transactionContext": transactionContext, | ||
40 | - }); err != nil { | ||
41 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
42 | - } else { | ||
43 | - fileRepository = value | ||
44 | - } | ||
45 | - if file, err := fileRepository.Save(newFile); err != nil { | ||
46 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
47 | - } else { | ||
48 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
49 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
50 | - } | ||
51 | - return file, nil | 33 | + //newFile := &domain.File{ |
34 | + //Name: createFileCommand.Name, | ||
35 | + //Url: createFileCommand.Url, | ||
36 | + //FileSize: createFileCommand.FileSize, | ||
37 | + //} | ||
38 | + //var fileRepository domain.FileRepository | ||
39 | + //if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
40 | + // "transactionContext": transactionContext, | ||
41 | + //}); err != nil { | ||
42 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
43 | + //} else { | ||
44 | + // fileRepository = value | ||
45 | + //} | ||
46 | + //file, err := fileRepository.Save(newFile) | ||
47 | + //if err != nil { | ||
48 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
49 | + //} | ||
50 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
51 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
52 | } | 52 | } |
53 | + return struct{}{}, nil | ||
53 | } | 54 | } |
54 | 55 | ||
55 | // 编辑表格数据 | 56 | // 编辑表格数据 |
@@ -70,7 +71,7 @@ func (fileService *FileService) EditDataTable(editDataTableCommand *command.Edit | @@ -70,7 +71,7 @@ func (fileService *FileService) EditDataTable(editDataTableCommand *command.Edit | ||
70 | if err := transactionContext.CommitTransaction(); err != nil { | 71 | if err := transactionContext.CommitTransaction(); err != nil { |
71 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 72 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
72 | } | 73 | } |
73 | - return nil, nil | 74 | + return struct{}{}, nil |
74 | } | 75 | } |
75 | 76 | ||
76 | // 持久化表格数据 | 77 | // 持久化表格数据 |
@@ -188,6 +189,42 @@ func (fileService *FileService) ListFile(listFileQuery *query.ListFileQuery) (in | @@ -188,6 +189,42 @@ func (fileService *FileService) ListFile(listFileQuery *query.ListFileQuery) (in | ||
188 | } | 189 | } |
189 | } | 190 | } |
190 | 191 | ||
192 | +// 返回文件服务列表 | ||
193 | +func (fileService *FileService) SearchFile(listFileQuery *query.SearchFileQuery) (interface{}, error) { | ||
194 | + if err := listFileQuery.ValidateQuery(); err != nil { | ||
195 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
196 | + } | ||
197 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
198 | + if err != nil { | ||
199 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
200 | + } | ||
201 | + if err := transactionContext.StartTransaction(); err != nil { | ||
202 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
203 | + } | ||
204 | + defer func() { | ||
205 | + transactionContext.RollbackTransaction() | ||
206 | + }() | ||
207 | + var fileRepository domain.FileRepository | ||
208 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
209 | + "transactionContext": transactionContext, | ||
210 | + }); err != nil { | ||
211 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
212 | + } else { | ||
213 | + fileRepository = value | ||
214 | + } | ||
215 | + count, files, err := fileRepository.Find(tool_funs.SimpleStructToMap(listFileQuery)) | ||
216 | + if err != nil { | ||
217 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
218 | + } | ||
219 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
220 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
221 | + } | ||
222 | + return map[string]interface{}{ | ||
223 | + "count": count, | ||
224 | + "files": files, | ||
225 | + }, nil | ||
226 | +} | ||
227 | + | ||
191 | // 加载表格数据 | 228 | // 加载表格数据 |
192 | func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) { | 229 | func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) { |
193 | if err := loadDataTableCommand.ValidateCommand(); err != nil { | 230 | if err := loadDataTableCommand.ValidateCommand(); err != nil { |
@@ -206,7 +243,8 @@ func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.Load | @@ -206,7 +243,8 @@ func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.Load | ||
206 | if err := transactionContext.CommitTransaction(); err != nil { | 243 | if err := transactionContext.CommitTransaction(); err != nil { |
207 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 244 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
208 | } | 245 | } |
209 | - return nil, nil | 246 | + |
247 | + return dto.NewDataTableDtoDemo(), nil | ||
210 | } | 248 | } |
211 | 249 | ||
212 | // 移除文件服务 | 250 | // 移除文件服务 |
pkg/domain/enums.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +type FileType string | ||
4 | + | ||
5 | +var ( | ||
6 | + SourceFile FileType = "SourceFile" | ||
7 | + VerifiedFile FileType = "VerifiedFile" | ||
8 | + TemporaryFile FileType = "TemporaryFile" | ||
9 | +) | ||
10 | + | ||
11 | +var ( | ||
12 | + GenerateMainTable OperationType = "GenerateMainTable" // 主表生成 | ||
13 | + SpiltMainTable OperationType = "SpiltMainTable" //主表拆分 | ||
14 | + ImportData OperationType = "ImportData" //数据导入 | ||
15 | + GenerateSubTable OperationType = "GenerateSubTable" //分表生成 | ||
16 | + CopyTable OperationType = "CopyTable" //表复制 | ||
17 | + RowEdit OperationType = "RowEdit" // 编辑记录 | ||
18 | + FileUpload OperationType = "FileUpload" // 文件上传 | ||
19 | + FileVerify OperationType = "FileVerify" // 文件校验 | ||
20 | +) | ||
21 | + | ||
22 | +var ( | ||
23 | + VerifiedStepLog LogType = 1 | ||
24 | + CommonLog LogType = 2 | ||
25 | +) | ||
26 | + | ||
27 | +var ( | ||
28 | + MainTable TableType = "MainTable" | ||
29 | + SideTable TableType = "SideTable" | ||
30 | + SubTable TableType = "SubTable" | ||
31 | + ExcelTable TableType = "ExcelTable" | ||
32 | + VerifiedExcelTable TableType = "VerifiedExcelTable" | ||
33 | +) | ||
34 | + | ||
35 | +func (t FileType) ToString() string { | ||
36 | + return string(t) | ||
37 | +} | ||
38 | + | ||
39 | +type LogType int | ||
40 | + | ||
41 | +type TableType string | ||
42 | + | ||
43 | +func (t TableType) ToString() string { | ||
44 | + return string(t) | ||
45 | +} | ||
46 | + | ||
47 | +type ObjectType TableType | ||
48 | + | ||
49 | +type OperationType string | ||
50 | + | ||
51 | +func (t OperationType) ToString() string { | ||
52 | + return string(t) | ||
53 | +} |
@@ -17,11 +17,11 @@ type Table struct { | @@ -17,11 +17,11 @@ type Table struct { | ||
17 | // 数据字段序号 | 17 | // 数据字段序号 |
18 | DataFieldIndex int `json:"dataFieldIndex"` | 18 | DataFieldIndex int `json:"dataFieldIndex"` |
19 | // 主键字段 | 19 | // 主键字段 |
20 | - PK string `json:"pK"` | 20 | + PK *Field `json:"pK"` |
21 | // 数据列 | 21 | // 数据列 |
22 | - DataFields string `json:"dataFields"` | 22 | + DataFields []*Field `json:"dataFields"` |
23 | // 手动添加的列 | 23 | // 手动添加的列 |
24 | - ManualFields string `json:"manualFields"` | 24 | + ManualFields []*Field `json:"manualFields"` |
25 | // 创建时间 | 25 | // 创建时间 |
26 | CreatedAt time.Time `json:"createdAt"` | 26 | CreatedAt time.Time `json:"createdAt"` |
27 | // 更新时间 | 27 | // 更新时间 |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "github.com/go-pg/pg/v10" | 5 | "github.com/go-pg/pg/v10" |
6 | "github.com/go-pg/pg/v10/orm" | 6 | "github.com/go-pg/pg/v10/orm" |
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
8 | 9 | ||
9 | //_ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | 10 | //_ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" |
10 | "github.com/linmadan/egglib-go/persistent/pg/comment" | 11 | "github.com/linmadan/egglib-go/persistent/pg/comment" |
@@ -24,7 +25,11 @@ func init() { | @@ -24,7 +25,11 @@ func init() { | ||
24 | DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) | 25 | DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) |
25 | } | 26 | } |
26 | if !constant.DISABLE_CREATE_TABLE { | 27 | if !constant.DISABLE_CREATE_TABLE { |
27 | - for _, model := range []interface{}{} { | 28 | + for _, model := range []interface{}{ |
29 | + (*models.File)(nil), | ||
30 | + (*models.Table)(nil), | ||
31 | + (*models.Log)(nil), | ||
32 | + } { | ||
28 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 33 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
29 | Temp: false, | 34 | Temp: false, |
30 | IfNotExists: true, | 35 | IfNotExists: true, |
@@ -22,7 +22,7 @@ type File struct { | @@ -22,7 +22,7 @@ type File struct { | ||
22 | // 更新时间 | 22 | // 更新时间 |
23 | UpdatedAt time.Time `comment:"更新时间"` | 23 | UpdatedAt time.Time `comment:"更新时间"` |
24 | // 删除时间 | 24 | // 删除时间 |
25 | - DeletedAt time.Time `comment:"删除时间"` | 25 | + DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` |
26 | // 版本 | 26 | // 版本 |
27 | Version int `comment:"版本"` | 27 | Version int `comment:"版本"` |
28 | } | 28 | } |
1 | package models | 1 | package models |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
4 | 7 | ||
5 | type Table struct { | 8 | type Table struct { |
6 | tableName string `comment:"表" pg:"metadata.tables,alias:table"` | 9 | tableName string `comment:"表" pg:"metadata.tables,alias:table"` |
@@ -17,17 +20,17 @@ type Table struct { | @@ -17,17 +20,17 @@ type Table struct { | ||
17 | // 数据字段序号 | 20 | // 数据字段序号 |
18 | DataFieldIndex int `comment:"数据字段序号"` | 21 | DataFieldIndex int `comment:"数据字段序号"` |
19 | // 主键字段 | 22 | // 主键字段 |
20 | - PK string `comment:"主键字段"` | 23 | + PK *domain.Field `comment:"主键字段"` |
21 | // 数据列 | 24 | // 数据列 |
22 | - DataFields string `comment:"数据列"` | 25 | + DataFields []*domain.Field `comment:"数据列"` |
23 | // 手动添加的列 | 26 | // 手动添加的列 |
24 | - ManualFields string `comment:"手动添加的列"` | 27 | + ManualFields []*domain.Field `comment:"手动添加的列"` |
25 | // 创建时间 | 28 | // 创建时间 |
26 | CreatedAt time.Time `comment:"创建时间"` | 29 | CreatedAt time.Time `comment:"创建时间"` |
27 | // 更新时间 | 30 | // 更新时间 |
28 | UpdatedAt time.Time `comment:"更新时间"` | 31 | UpdatedAt time.Time `comment:"更新时间"` |
29 | // 删除时间 | 32 | // 删除时间 |
30 | - DeletedAt time.Time `comment:"删除时间"` | 33 | + DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` |
31 | // 版本 | 34 | // 版本 |
32 | Version int `comment:"版本"` | 35 | Version int `comment:"版本"` |
33 | } | 36 | } |
@@ -68,6 +68,8 @@ func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) | @@ -68,6 +68,8 @@ func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) | ||
68 | return file, err | 68 | return file, err |
69 | } | 69 | } |
70 | } else { | 70 | } else { |
71 | + oldVersion := file.Version | ||
72 | + file.Version += 1 | ||
71 | if _, err := tx.QueryOne( | 73 | if _, err := tx.QueryOne( |
72 | pg.Scan( | 74 | pg.Scan( |
73 | &file.FileId, | 75 | &file.FileId, |
@@ -80,7 +82,7 @@ func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) | @@ -80,7 +82,7 @@ func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) | ||
80 | &file.DeletedAt, | 82 | &file.DeletedAt, |
81 | &file.Version, | 83 | &file.Version, |
82 | ), | 84 | ), |
83 | - fmt.Sprintf("UPDATE metadata.files SET %s WHERE file_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 85 | + fmt.Sprintf("UPDATE metadata.files SET %s WHERE file_id=? and version=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
84 | file.FileId, | 86 | file.FileId, |
85 | file.FileType, | 87 | file.FileType, |
86 | file.FileInfo, | 88 | file.FileInfo, |
@@ -91,6 +93,7 @@ func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) | @@ -91,6 +93,7 @@ func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) | ||
91 | file.DeletedAt, | 93 | file.DeletedAt, |
92 | file.Version, | 94 | file.Version, |
93 | file.Identify(), | 95 | file.Identify(), |
96 | + oldVersion, | ||
94 | ); err != nil { | 97 | ); err != nil { |
95 | return file, err | 98 | return file, err |
96 | } | 99 | } |
@@ -81,6 +81,8 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -81,6 +81,8 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
81 | return table, err | 81 | return table, err |
82 | } | 82 | } |
83 | } else { | 83 | } else { |
84 | + oldVersion := table.Version | ||
85 | + table.Version += 1 | ||
84 | if _, err := tx.QueryOne( | 86 | if _, err := tx.QueryOne( |
85 | pg.Scan( | 87 | pg.Scan( |
86 | &table.TableId, | 88 | &table.TableId, |
@@ -97,7 +99,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -97,7 +99,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
97 | &table.DeletedAt, | 99 | &table.DeletedAt, |
98 | &table.Version, | 100 | &table.Version, |
99 | ), | 101 | ), |
100 | - fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 102 | + fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? and version=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
101 | table.TableId, | 103 | table.TableId, |
102 | table.TableType, | 104 | table.TableType, |
103 | table.Name, | 105 | table.Name, |
@@ -111,6 +113,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -111,6 +113,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
111 | table.UpdatedAt, | 113 | table.UpdatedAt, |
112 | table.DeletedAt, | 114 | table.DeletedAt, |
113 | table.Version, | 115 | table.Version, |
116 | + oldVersion, | ||
114 | table.Identify(), | 117 | table.Identify(), |
115 | ); err != nil { | 118 | ); err != nil { |
116 | return table, err | 119 | return table, err |
pkg/port/beego/controllers/controller.go
0 → 100644
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web/context" | ||
5 | + "github.com/linmadan/egglib-go/web/beego" | ||
6 | + "github.com/linmadan/egglib-go/web/beego/utils" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
8 | +) | ||
9 | + | ||
10 | +func ResponseGrid(c beego.BaseController, total int64, data interface{}, err error) { | ||
11 | + var response utils.JsonResponse | ||
12 | + if err != nil { | ||
13 | + response = utils.ResponseError(c.Ctx, err) | ||
14 | + } else { | ||
15 | + response = ResponseGridData(c.Ctx, total, data) | ||
16 | + } | ||
17 | + c.Data["json"] = response | ||
18 | + c.ServeJSON() | ||
19 | +} | ||
20 | + | ||
21 | +func ResponseGridData(ctx *context.Context, total int64, data interface{}) utils.JsonResponse { | ||
22 | + jsonResponse := utils.JsonResponse{} | ||
23 | + jsonResponse["code"] = 0 | ||
24 | + jsonResponse["msg"] = "ok" | ||
25 | + jsonResponse["data"] = map[string]interface{}{"grid": map[string]interface{}{ | ||
26 | + "total": total, | ||
27 | + "list": data, | ||
28 | + }} | ||
29 | + ctx.Input.SetData("outputData", jsonResponse) | ||
30 | + return jsonResponse | ||
31 | +} | ||
32 | + | ||
33 | +func Must(err error) { | ||
34 | + if err != nil { | ||
35 | + log.Logger.Error(err.Error()) | ||
36 | + } | ||
37 | +} | ||
38 | + | ||
39 | +// ParseOperateInfo 从头部解析操作对象信息 | ||
40 | +//func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo { | ||
41 | +// opt := &domain.OperateInfo{} | ||
42 | +// opt.UserId = header(c, constant.HeaderUserId) | ||
43 | +// opt.CompanyId = header(c, constant.HeaderCompanyId) | ||
44 | +// opt.OrgId = header(c, constant.HeaderOrgId) | ||
45 | +// orgIdList := c.Ctx.Input.Header(constant.HeaderOrgIds) | ||
46 | +// splitOrgIdList := strings.Split(orgIdList, constant.CUSTOMER_ACCOUNT_DELIMITER) | ||
47 | +// for i := range splitOrgIdList { | ||
48 | +// orgId, _ := strconv.Atoi(splitOrgIdList[i]) | ||
49 | +// if orgId == 0 { | ||
50 | +// continue | ||
51 | +// } | ||
52 | +// opt.OrgIds = append(opt.OrgIds, orgId) | ||
53 | +// } | ||
54 | +// return opt | ||
55 | +//} | ||
56 | +// | ||
57 | +//func header(c beego.BaseController, key string) int { | ||
58 | +// if len(c.Ctx.Input.Header(key)) == 0 { | ||
59 | +// return 0 | ||
60 | +// } | ||
61 | +// res, err := strconv.Atoi(c.Ctx.Input.Header(key)) | ||
62 | +// if err != nil { | ||
63 | +// log.Logger.Error(err.Error()) | ||
64 | +// return 0 | ||
65 | +// } | ||
66 | +// return res | ||
67 | +//} |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | 5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" |
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
8 | ) | 9 | ) |
9 | 10 | ||
10 | type FileController struct { | 11 | type FileController struct { |
@@ -59,6 +60,32 @@ func (controller *FileController) ListFile() { | @@ -59,6 +60,32 @@ func (controller *FileController) ListFile() { | ||
59 | controller.Response(data, err) | 60 | controller.Response(data, err) |
60 | } | 61 | } |
61 | 62 | ||
63 | +func (controller *FileController) SearchFile() { | ||
64 | + fileService := service.NewFileService(nil) | ||
65 | + searchFileQuery := &query.SearchFileQuery{} | ||
66 | + Must(controller.Unmarshal(searchFileQuery)) | ||
67 | + data, err := fileService.SearchFile(searchFileQuery) | ||
68 | + controller.Response(data, err) | ||
69 | +} | ||
70 | + | ||
71 | +func (controller *FileController) SearchSourceFile() { | ||
72 | + fileService := service.NewFileService(nil) | ||
73 | + searchFileQuery := &query.SearchFileQuery{} | ||
74 | + Must(controller.Unmarshal(searchFileQuery)) | ||
75 | + searchFileQuery.FileType = domain.SourceFile | ||
76 | + data, err := fileService.SearchFile(searchFileQuery) | ||
77 | + controller.Response(data, err) | ||
78 | +} | ||
79 | + | ||
80 | +func (controller *FileController) SearchVerifiedFile() { | ||
81 | + fileService := service.NewFileService(nil) | ||
82 | + searchFileQuery := &query.SearchFileQuery{} | ||
83 | + Must(controller.Unmarshal(searchFileQuery)) | ||
84 | + searchFileQuery.FileType = domain.VerifiedFile | ||
85 | + data, err := fileService.SearchFile(searchFileQuery) | ||
86 | + controller.Response(data, err) | ||
87 | +} | ||
88 | + | ||
62 | func (controller *FileController) LoadDataTable() { | 89 | func (controller *FileController) LoadDataTable() { |
63 | fileService := service.NewFileService(nil) | 90 | fileService := service.NewFileService(nil) |
64 | loadDataTableCommand := &command.LoadDataTableCommand{} | 91 | loadDataTableCommand := &command.LoadDataTableCommand{} |
@@ -11,6 +11,11 @@ func init() { | @@ -11,6 +11,11 @@ func init() { | ||
11 | web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Get:GetFile") | 11 | web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Get:GetFile") |
12 | web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile") | 12 | web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile") |
13 | web.Router("/bastion/files/", &controllers.FileController{}, "Get:ListFile") | 13 | web.Router("/bastion/files/", &controllers.FileController{}, "Get:ListFile") |
14 | + web.Router("/bastion/files/search", &controllers.FileController{}, "Post:SearchFile") | ||
15 | + web.Router("/bastion/files/search", &controllers.FileController{}, "Post:SearchFile") | ||
16 | + web.Router("/bastion/files/search-source-file", &controllers.FileController{}, "Post:SearchSourceFile") | ||
17 | + web.Router("/bastion/files/search-verified-file", &controllers.FileController{}, "Post:SearchVerifiedFile") | ||
18 | + | ||
14 | web.Router("/bastion/load-data-table", &controllers.FileController{}, "Post:LoadDataTable") | 19 | web.Router("/bastion/load-data-table", &controllers.FileController{}, "Post:LoadDataTable") |
15 | web.Router("/bastion/edit-data-table", &controllers.FileController{}, "Post:EditDataTable") | 20 | web.Router("/bastion/edit-data-table", &controllers.FileController{}, "Post:EditDataTable") |
16 | web.Router("/bastion/flush-data-table", &controllers.FileController{}, "Post:FlushDataTable") | 21 | web.Router("/bastion/flush-data-table", &controllers.FileController{}, "Post:FlushDataTable") |
-
请 注册 或 登录 后发表评论