作者 yangfu

feat: row data edit

@@ -180,4 +180,10 @@ @@ -180,4 +180,10 @@
180 - [ ] 50W 120s 读取数据库:30s 保存文件:10s 下载:30M/500K=60S;RAR压缩 24M/500k=50S 180 - [ ] 50W 120s 读取数据库:30s 保存文件:10s 下载:30M/500K=60S;RAR压缩 24M/500k=50S
181 - [ ] 20W .. 181 - [ ] 20W ..
182 - [ ] 10W .. 182 - [ ] 10W ..
183 -- [ ] 保存单个文件、压缩 | 保存多个文件、压缩  
  183 +- [ ] 保存单个文件、压缩 | 保存多个文件、压缩
  184 +
  185 +## 讨论事项
  186 +
  187 +- [ ] 校验动作,参数模型讨论
  188 +- [ ] 校验日志错误(标红)
  189 +- [ ] 校验完毕应答实体,类型修改即使错误,也要返回修改完毕的表
@@ -2,7 +2,6 @@ package command @@ -2,7 +2,6 @@ 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 7
@@ -13,9 +12,9 @@ type FlushDataTableCommand struct { @@ -13,9 +12,9 @@ type FlushDataTableCommand struct {
13 // 文件ID 12 // 文件ID
14 FileId int `cname:"文件ID" json:"objectId" valid:"Required"` 13 FileId int `cname:"文件ID" json:"objectId" valid:"Required"`
15 // 记录数 14 // 记录数
16 - RowCount int `cname:"记录数" json:"rowCount" valid:"Required"` 15 + //RowCount int `cname:"记录数" json:"rowCount" valid:"Required"`
17 // 数据列 16 // 数据列
18 - DataFields []*domain.Field `cname:"数据列" json:"fields" valid:"Required"` 17 + //DataFields []*domain.Field `cname:"数据列" json:"fields" valid:"Required"`
19 } 18 }
20 19
21 func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) { 20 func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) {
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "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/command"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto"
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis"
9 ) 10 )
10 11
11 // FilePreview 加载表格数据 12 // FilePreview 加载表格数据
@@ -85,6 +86,12 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable @@ -85,6 +86,12 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable
85 transactionContext.RollbackTransaction() 86 transactionContext.RollbackTransaction()
86 }() 87 }()
87 88
  89 + cache := redis.NewFileCacheService()
  90 + temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(editDataTableCommand.FileId))
  91 + if err != nil {
  92 + return nil, factory.FastError(err)
  93 + }
  94 + editDataTableCommand.Fields = temporaryFile.Fields
88 editDataTableService, _ := factory.CreateEditDataTableService(transactionContext) 95 editDataTableService, _ := factory.CreateEditDataTableService(transactionContext)
89 _, err = editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest) 96 _, err = editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest)
90 if err != nil { 97 if err != nil {
@@ -112,16 +119,23 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab @@ -112,16 +119,23 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab
112 transactionContext.RollbackTransaction() 119 transactionContext.RollbackTransaction()
113 }() 120 }()
114 flushDataTableService, _ := factory.CreateFlushDataTableService(transactionContext) 121 flushDataTableService, _ := factory.CreateFlushDataTableService(transactionContext)
115 - fields := make([]*domain.Field, 0)  
116 - for _, f := range flushDataTableCommand.DataFields {  
117 - fields = append(fields, &domain.Field{  
118 - Name: f.Name,  
119 - SQLType: f.SQLType,  
120 - }) 122 + //fields := make([]*domain.Field, 0)
  123 + //for _, f := range flushDataTableCommand.DataFields {
  124 + // fields = append(fields, &domain.Field{
  125 + // Name: f.Name,
  126 + // SQLType: f.SQLType,
  127 + // })
  128 + //}
  129 +
  130 + cache := redis.NewFileCacheService()
  131 + temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(flushDataTableCommand.FileId))
  132 + if err != nil {
  133 + return nil, factory.FastError(err)
121 } 134 }
  135 +
122 if _, err := flushDataTableService.Flush(ctx, flushDataTableCommand.FileId, &domain.Table{ 136 if _, err := flushDataTableService.Flush(ctx, flushDataTableCommand.FileId, &domain.Table{
123 - DataFields: fields,  
124 - RowCount: flushDataTableCommand.RowCount, 137 + DataFields: temporaryFile.Fields,
  138 + RowCount: temporaryFile.Total,
125 }); err != nil { 139 }); err != nil {
126 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 140 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
127 } 141 }
@@ -21,6 +21,10 @@ type VerifiedStepLogDto struct { @@ -21,6 +21,10 @@ type VerifiedStepLogDto struct {
21 //OperatorName string `json:"operatorName"` 21 //OperatorName string `json:"operatorName"`
22 // 创建时间 22 // 创建时间
23 CreatedAt string `json:"createdAt"` 23 CreatedAt string `json:"createdAt"`
  24 + // 错误级别
  25 + Level string `json:"level"`
  26 + // 错误信息
  27 + Error string `json:"error"`
24 } 28 }
25 29
26 func (d *VerifiedStepLogDto) Load(m *domain.Log) { 30 func (d *VerifiedStepLogDto) Load(m *domain.Log) {
@@ -32,4 +36,9 @@ func (d *VerifiedStepLogDto) Load(m *domain.Log) { @@ -32,4 +36,9 @@ func (d *VerifiedStepLogDto) Load(m *domain.Log) {
32 d.Content = m.Content 36 d.Content = m.Content
33 //d.OperatorName = m.OperatorName 37 //d.OperatorName = m.OperatorName
34 d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05") 38 d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05")
  39 + d.Level = m.Entry.Level
  40 + d.Error = m.Entry.Error
  41 + if len(d.Level) == 0 {
  42 + d.Level = domain.LevelInfo.ToString()
  43 + }
35 } 44 }
@@ -12,6 +12,7 @@ import ( @@ -12,6 +12,7 @@ import (
12 type TablePreviewCommand struct { 12 type TablePreviewCommand struct {
13 // 表Id 13 // 表Id
14 TableId int `cname:"表Id" json:"objectId" valid:"Required"` 14 TableId int `cname:"表Id" json:"objectId" valid:"Required"`
  15 + ObjectType string `json:"objectType"`
15 PageNumber int `json:"pageNumber"` 16 PageNumber int `json:"pageNumber"`
16 PageSize int `json:"pageSize"` 17 PageSize int `json:"pageSize"`
17 Where domain.Where `json:"where"` 18 Where domain.Where `json:"where"`
@@ -17,6 +17,7 @@ type RowEditCommand struct { @@ -17,6 +17,7 @@ type RowEditCommand struct {
17 RemoveList []*domain.FieldValues `json:"removeList"` 17 RemoveList []*domain.FieldValues `json:"removeList"`
18 AddList []*domain.FieldValues `json:"addList"` 18 AddList []*domain.FieldValues `json:"addList"`
19 Where domain.Where `json:"where"` 19 Where domain.Where `json:"where"`
  20 + DataList []map[string]string `json:"dataList"`
20 } 21 }
21 22
22 func (cmd *RowEditCommand) Valid(validation *validation.Validation) { 23 func (cmd *RowEditCommand) Valid(validation *validation.Validation) {
  1 +package command
  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 RowEditCommandV2 struct {
  13 + // 表Id
  14 + TableId int `cname:"表Id" json:"tableId" valid:"Required"`
  15 + PageNumber int `json:"pageNumber"`
  16 + PageSize int `json:"pageSize"`
  17 + // 数据列
  18 + UpdateList []map[string]string `json:"updateList"`
  19 + RemoveList []map[string]string `json:"removeList"`
  20 + AddList []map[string]string `json:"addList"`
  21 + Where domain.Where `json:"where"`
  22 +}
  23 +
  24 +func (cmd *RowEditCommandV2) Valid(validation *validation.Validation) {
  25 + if cmd.PageSize > 0 {
  26 + cmd.Where.PageSize = cmd.PageSize
  27 + cmd.Where.PageNumber = cmd.PageNumber
  28 + }
  29 +}
  30 +
  31 +func (cmd *RowEditCommandV2) ValidateCommand() error {
  32 + valid := validation.Validation{}
  33 + b, err := valid.Valid(cmd)
  34 + if err != nil {
  35 + return err
  36 + }
  37 + if !b {
  38 + elem := reflect.TypeOf(cmd).Elem()
  39 + for _, validErr := range valid.Errors {
  40 + field, isExist := elem.FieldByName(validErr.Field)
  41 + if isExist {
  42 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  43 + } else {
  44 + return fmt.Errorf(validErr.Message)
  45 + }
  46 + }
  47 + }
  48 + return nil
  49 +}
@@ -28,3 +28,13 @@ func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, obj @@ -28,3 +28,13 @@ func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, obj
28 //d.Total = dataTable.Total 28 //d.Total = dataTable.Total
29 return d 29 return d
30 } 30 }
  31 +
  32 +func ToFieldDataByPK(m *domain.Table, dataTable *domain.DataTable) map[string]map[string]string {
  33 + var dataListByPk = make(map[string]map[string]string)
  34 + for _, item := range domain.ToFieldData(m.Fields(true), dataTable.Data, false) {
  35 + if v, ok := item[domain.DefaultPkField]; ok {
  36 + dataListByPk[v] = item
  37 + }
  38 + }
  39 + return dataListByPk
  40 +}
1 -package service  
2 -  
3 -import (  
4 - "github.com/linmadan/egglib-go/core/application"  
5 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"  
6 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"  
7 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"  
8 -)  
9 -  
10 -func (tableService *TableService) RowEdit(ctx *domain.Context, cmd *command.RowEditCommand) (interface{}, error) {  
11 - if err := cmd.ValidateCommand(); err != nil {  
12 - return nil, application.ThrowError(application.ARG_ERROR, err.Error())  
13 - }  
14 - transactionContext, err := factory.CreateTransactionContext(nil)  
15 - if err != nil {  
16 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
17 - }  
18 - if err := transactionContext.StartTransaction(); err != nil {  
19 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
20 - }  
21 - defer func() {  
22 - transactionContext.RollbackTransaction()  
23 - }()  
24 -  
25 - editDataService, _ := factory.CreateTableEditDataService(transactionContext)  
26 - _, err = editDataService.RowEdit(ctx, domain.EditDataRequest{  
27 - TableId: cmd.TableId,  
28 - Where: cmd.Where,  
29 - UpdateList: cmd.UpdateList,  
30 - AddList: cmd.AddList,  
31 - RemoveList: cmd.RemoveList,  
32 - })  
33 - if err != nil {  
34 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
35 - }  
36 - if err := transactionContext.CommitTransaction(); err != nil {  
37 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
38 - }  
39 - return struct{}{}, nil  
40 -}  
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" 10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
  11 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" 12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis"
12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" 13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" 14 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
@@ -103,9 +104,16 @@ func (tableService *TableService) ExportDataTableV2(ctx *domain.Context, cmd *co @@ -103,9 +104,16 @@ func (tableService *TableService) ExportDataTableV2(ctx *domain.Context, cmd *co
103 defer locker.Release() 104 defer locker.Release()
104 var table *domain.Table 105 var table *domain.Table
105 //var mainTable *domain.Table 106 //var mainTable *domain.Table
106 - _, table, err = factory.FastPgTable(transactionContext, cmd.TableId)  
107 - if err != nil {  
108 - return nil, factory.FastError(err) 107 + if cmd.ObjectType == domain.ObjectDBTable {
  108 + table = domain.DBTables[cmd.TableId]
  109 + if table == nil {
  110 + return nil, factory.FastError(fmt.Errorf("表不存在"))
  111 + }
  112 + } else {
  113 + _, table, err = factory.FastPgTable(transactionContext, cmd.TableId)
  114 + if err != nil {
  115 + return nil, factory.FastError(err)
  116 + }
109 } 117 }
110 118
111 data, err := exportTableTo(ctx, cmd, table, 10000) 119 data, err := exportTableTo(ctx, cmd, table, 10000)
@@ -123,8 +131,14 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table @@ -123,8 +131,14 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table
123 var options = starrocks.QueryOptions{ 131 var options = starrocks.QueryOptions{
124 TableName: table.SQLName, 132 TableName: table.SQLName,
125 Select: table.Fields(false), 133 Select: table.Fields(false),
  134 + //Table: table,
126 } 135 }
127 - count, err := starrocks.QueryCount(options) 136 +
  137 + db := starrocks.DB
  138 + if table.TableType == domain.ObjectDBTable {
  139 + db = pg.GormDB
  140 + }
  141 + count, err := starrocks.WrapQueryCountWithDB(options, db)()
128 if err != nil { 142 if err != nil {
129 return nil, factory.FastError(err) 143 return nil, factory.FastError(err)
130 } 144 }
@@ -138,6 +152,7 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table @@ -138,6 +152,7 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table
138 //Where: cmd.Where.Conditions, 152 //Where: cmd.Where.Conditions,
139 Offset: i * blockSize, 153 Offset: i * blockSize,
140 Limit: blockSize, 154 Limit: blockSize,
  155 + Table: table,
141 } 156 }
142 options.SetCondition(cmd.Where.Conditions).SetDefaultOrder() 157 options.SetCondition(cmd.Where.Conditions).SetDefaultOrder()
143 source <- Query{ 158 source <- Query{
@@ -150,7 +165,7 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table @@ -150,7 +165,7 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table
150 // mapper 165 // mapper
151 query := item.(Query) 166 query := item.(Query)
152 var dataTable *domain.DataTable 167 var dataTable *domain.DataTable
153 - dataTable, err = starrocks.Query(query.Options, starrocks.WrapQueryFuncWithDB(starrocks.DB)) 168 + dataTable, err = starrocks.Query(query.Options, starrocks.WrapQueryFuncWithDB(db))
154 if err != nil { 169 if err != nil {
155 log.Logger.Error(err.Error(), map[string]interface{}{"mapper": query}) 170 log.Logger.Error(err.Error(), map[string]interface{}{"mapper": query})
156 return 171 return
@@ -31,10 +31,23 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * @@ -31,10 +31,23 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
31 var db *gorm.DB 31 var db *gorm.DB
32 switch cmd.ObjectType { 32 switch cmd.ObjectType {
33 case domain.ObjectFile: 33 case domain.ObjectFile:
34 - table, err = tableRepository.FindOne(map[string]interface{}{"ctx": ctx, "tableId": cmd.ObjectId}) 34 + byteCore, _ := factory.CreateByteCoreService(transactionContext)
  35 + response, err := byteCore.FieldOptionalValues(domain.ReqFieldOptionalValues{
  36 + FileId: cmd.ObjectId,
  37 + Field: &cmd.Field,
  38 + Match: cmd.Match,
  39 + Where: domain.Where{
  40 + PageNumber: cmd.PageNumber,
  41 + PageSize: cmd.PageSize,
  42 + },
  43 + })
35 if err != nil { 44 if err != nil {
36 return nil, factory.FastError(err) 45 return nil, factory.FastError(err)
37 } 46 }
  47 + return map[string]interface{}{
  48 + "values": response.Values,
  49 + "total": response.Total,
  50 + }, nil
38 case domain.ObjectMetaTable: 51 case domain.ObjectMetaTable:
39 table, err = tableRepository.FindOne(map[string]interface{}{"ctx": ctx, "tableId": cmd.ObjectId}) 52 table, err = tableRepository.FindOne(map[string]interface{}{"ctx": ctx, "tableId": cmd.ObjectId})
40 if err != nil { 53 if err != nil {
@@ -50,6 +63,7 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * @@ -50,6 +63,7 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
50 if !ok { 63 if !ok {
51 return nil, factory.FastError(fmt.Errorf("列:%v 不存在", cmd.Field.Name)) 64 return nil, factory.FastError(fmt.Errorf("列:%v 不存在", cmd.Field.Name))
52 } 65 }
  66 +
53 options := &starrocks.QueryOptions{ 67 options := &starrocks.QueryOptions{
54 TableName: table.SQLName, 68 TableName: table.SQLName,
55 Select: []*domain.Field{field}, 69 Select: []*domain.Field{field},
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
  10 +)
  11 +
  12 +func (tableService *TableService) RowEdit(ctx *domain.Context, cmd *command.RowEditCommand) (interface{}, error) {
  13 + if err := cmd.ValidateCommand(); err != nil {
  14 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  15 + }
  16 + transactionContext, err := factory.CreateTransactionContext(nil)
  17 + if err != nil {
  18 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  19 + }
  20 + if err := transactionContext.StartTransaction(); err != nil {
  21 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  22 + }
  23 + defer func() {
  24 + transactionContext.RollbackTransaction()
  25 + }()
  26 +
  27 + //editDataService, _ := factory.CreateTableEditDataService(transactionContext)
  28 + //_, err = editDataService.RowEdit(ctx, domain.EditDataRequest{
  29 + // TableId: cmd.TableId,
  30 + // Where: cmd.Where,
  31 + // UpdateList: cmd.UpdateList,
  32 + // AddList: cmd.AddList,
  33 + // RemoveList: cmd.RemoveList,
  34 + //})
  35 + if err != nil {
  36 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  37 + }
  38 + if err := transactionContext.CommitTransaction(); err != nil {
  39 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  40 + }
  41 + return struct{}{}, nil
  42 +}
  43 +
  44 +func (tableService *TableService) RowEditV2(ctx *domain.Context, cmd *command.RowEditCommandV2) (interface{}, error) {
  45 + if err := cmd.ValidateCommand(); err != nil {
  46 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  47 + }
  48 + transactionContext, err := factory.CreateTransactionContext(nil)
  49 + if err != nil {
  50 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  51 + }
  52 + if err := transactionContext.StartTransaction(); err != nil {
  53 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  54 + }
  55 + defer func() {
  56 + transactionContext.RollbackTransaction()
  57 + }()
  58 +
  59 + var table *domain.Table
  60 + _, table, err = factory.FastPgTable(transactionContext, cmd.TableId)
  61 + if err != nil {
  62 + return nil, factory.FastError(err)
  63 + }
  64 +
  65 + var options = starrocks.QueryOptions{
  66 + TableName: table.SQLName,
  67 + Select: table.Fields(true),
  68 + }
  69 + options.SetCondition(cmd.Where.Conditions).SetDefaultOrder()
  70 + options.SetOffsetLimit(cmd.Where.PageNumber, cmd.Where.PageSize)
  71 + var dataTable *domain.DataTable
  72 + dataTable, err = factory.FastDataTable(options)
  73 + if err != nil {
  74 + return nil, factory.FastError(err)
  75 + }
  76 +
  77 + editDataService, _ := factory.CreateTableEditDataService(transactionContext)
  78 + _, err = editDataService.RowEdit(ctx, domain.EditDataRequest{
  79 + TableId: cmd.TableId,
  80 + Table: table,
  81 + Where: cmd.Where,
  82 + UpdateList: MapArrayToFieldValues(cmd.UpdateList, table, dataTable, true),
  83 + AddList: MapArrayToFieldValues(cmd.AddList, table, dataTable, false),
  84 + RemoveList: MapArrayToFieldValues(cmd.RemoveList, table, dataTable, true),
  85 + })
  86 + if err != nil {
  87 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  88 + }
  89 + if err := transactionContext.CommitTransaction(); err != nil {
  90 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  91 + }
  92 + return struct{}{}, nil
  93 +}
  94 +
  95 +func MapArrayToFieldValues(list []map[string]string, table *domain.Table, dataTable *domain.DataTable, mustMatch bool) []*domain.FieldValues {
  96 + var result = make([]*domain.FieldValues, 0)
  97 + history := dto.ToFieldDataByPK(table, dataTable)
  98 + mapField := domain.Fields(table.Fields(true)).ToMapBySqlName()
  99 + for _, m := range list {
  100 + var fieldValues = &domain.FieldValues{
  101 + FieldValues: make([]*domain.FieldValue, 0),
  102 + }
  103 + matchItem, ok := history[m[domain.DefaultPkField]]
  104 + if mustMatch {
  105 + if !ok {
  106 + continue
  107 + }
  108 + }
  109 + if _, ok := m[domain.DefaultPkField]; !ok {
  110 + m[domain.DefaultPkField] = ""
  111 + }
  112 + for key, value := range m {
  113 + field, ok := mapField[key]
  114 + if !ok || field.Flag == domain.ManualField {
  115 + continue
  116 + }
  117 + fieldValue := &domain.FieldValue{
  118 + Field: field,
  119 + Value: value,
  120 + }
  121 + if mustMatch {
  122 + if oldValue, ok := matchItem[key]; ok {
  123 + fieldValue.OldValue = oldValue
  124 + }
  125 + }
  126 + fieldValues.FieldValues = append(fieldValues.FieldValues, fieldValue)
  127 + }
  128 + result = append(result, fieldValues)
  129 + }
  130 + return result
  131 +}
@@ -45,5 +45,5 @@ func init() { @@ -45,5 +45,5 @@ func init() {
45 HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) 45 HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT)
46 SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) 46 SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV)
47 PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) 47 PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON)
48 - CACHE_PREFIX = SERVICE_NAME 48 + CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV
49 } 49 }
@@ -11,6 +11,7 @@ type ByteLibService interface { @@ -11,6 +11,7 @@ type ByteLibService interface {
11 DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error) 11 DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error)
12 CancelFile(param ReqCancelFile) (*DataCancelFile, error) 12 CancelFile(param ReqCancelFile) (*DataCancelFile, error)
13 EditTableData(param ReqEditTableData) (*DataEditTableData, error) 13 EditTableData(param ReqEditTableData) (*DataEditTableData, error)
  14 + FieldOptionalValues(param ReqFieldOptionalValues) (*DataFieldOptionalValues, error)
14 } 15 }
15 16
16 type ( 17 type (
@@ -26,8 +27,8 @@ type ( @@ -26,8 +27,8 @@ type (
26 ColumnSchemas []ColumnSchema `json:"columnSchemas"` 27 ColumnSchemas []ColumnSchema `json:"columnSchemas"`
27 //PageNumber int `json:"pageNumber"` 28 //PageNumber int `json:"pageNumber"`
28 //PageSize int `json:"pageSize"` 29 //PageSize int `json:"pageSize"`
29 - QueryParameters map[string]interface{} `json:"queryParameters"`  
30 - SortParameters map[string]interface{} `json:"sortParameters"` 30 + //QueryParameters []QueryParameter `json:"queryParameters"`
  31 + SortParameters map[string]interface{} `json:"sortParameters"`
31 } 32 }
32 33
33 DataLoadDataTable struct { 34 DataLoadDataTable struct {
@@ -41,6 +42,11 @@ type ( @@ -41,6 +42,11 @@ type (
41 InValidCells []InValidCell `json:"inValidCells"` 42 InValidCells []InValidCell `json:"inValidCells"`
42 } 43 }
43 44
  45 + QueryParameter struct {
  46 + ColumnName string `json:"columnName"`
  47 + ColumnContents []string `json:"columnContents"`
  48 + IsContainContent bool `json:"isContainContent"`
  49 + }
44 //Field struct { 50 //Field struct {
45 // // 索引序号 51 // // 索引序号
46 // Index int `json:"index"` 52 // Index int `json:"index"`
@@ -183,6 +189,21 @@ type ( @@ -183,6 +189,21 @@ type (
183 ) 189 )
184 190
185 type ( 191 type (
  192 + ReqFieldOptionalValues struct {
  193 + FileId int
  194 + Field *Field
  195 + Where Where
  196 + Match string
  197 + }
  198 +
  199 + DataFieldOptionalValues struct {
  200 + Field *Field
  201 + Values []string
  202 + Total int
  203 + }
  204 +)
  205 +
  206 +type (
186 ReqCancelFile struct { 207 ReqCancelFile struct {
187 } 208 }
188 209
@@ -9,4 +9,26 @@ type Context struct { @@ -9,4 +9,26 @@ type Context struct {
9 OperatorName string `json:"operatorName"` 9 OperatorName string `json:"operatorName"`
10 // 租户 (个人、企业) 10 // 租户 (个人、企业)
11 TenantId int `json:"tenantId"` 11 TenantId int `json:"tenantId"`
  12 +
  13 + data map[string]interface{}
  14 +}
  15 +
  16 +func (c *Context) WithValue(key string, value interface{}) *Context {
  17 + if _, ok := c.data[key]; ok {
  18 + return c
  19 + }
  20 + c.data[key] = value
  21 + return c
12 } 22 }
  23 +
  24 +func (c *Context) GetValue(key string) (interface{}, bool) {
  25 + if v, ok := c.data[key]; ok {
  26 + return v, true
  27 + }
  28 + return nil, false
  29 +}
  30 +
  31 +const (
  32 + ContextWithLogLevel = "WithLogLevel"
  33 + ContextWithLogMsg = "WithLogMsg"
  34 +)
@@ -75,7 +75,8 @@ type TableEditDataService interface { @@ -75,7 +75,8 @@ type TableEditDataService interface {
75 RowEdit(ctx *Context, request EditDataRequest) (interface{}, error) 75 RowEdit(ctx *Context, request EditDataRequest) (interface{}, error)
76 } 76 }
77 type EditDataRequest struct { 77 type EditDataRequest struct {
78 - TableId int `json:"tableId"` 78 + TableId int `json:"tableId"`
  79 + Table *Table
79 UpdateList []*FieldValues `json:"updateList"` 80 UpdateList []*FieldValues `json:"updateList"`
80 RemoveList []*FieldValues `json:"removeList"` 81 RemoveList []*FieldValues `json:"removeList"`
81 AddList []*FieldValues `json:"addList"` 82 AddList []*FieldValues `json:"addList"`
@@ -210,3 +210,19 @@ const ( @@ -210,3 +210,19 @@ const (
210 ObjectMetaTable = "MetaTable" 210 ObjectMetaTable = "MetaTable"
211 ObjectDBTable = "DBTable" 211 ObjectDBTable = "DBTable"
212 ) 212 )
  213 +
  214 +type LogLevel string
  215 +
  216 +const (
  217 + LevelInfo LogLevel = "info"
  218 + LevelError LogLevel = "error"
  219 + LevelWarn LogLevel = "warn"
  220 +)
  221 +
  222 +func (t LogLevel) ToString() string {
  223 + return string(t)
  224 +}
  225 +
  226 +const (
  227 + DefaultPkField = "id"
  228 +)
@@ -45,6 +45,14 @@ func (fields Fields) ToMap() map[string]*Field { @@ -45,6 +45,14 @@ func (fields Fields) ToMap() map[string]*Field {
45 return m 45 return m
46 } 46 }
47 47
  48 +func (fields Fields) ToMapBySqlName() map[string]*Field {
  49 + m := make(map[string]*Field)
  50 + for i := range fields {
  51 + m[fields[i].SQLName] = fields[i]
  52 + }
  53 + return m
  54 +}
  55 +
48 func (fields Fields) NameArrayString() []string { 56 func (fields Fields) NameArrayString() []string {
49 m := make([]string, 0) 57 m := make([]string, 0)
50 for i := range fields { 58 for i := range fields {
@@ -104,7 +112,7 @@ func FieldsChange(oldFields []*Field, newFields []*Field) (reserve []*Field, del @@ -104,7 +112,7 @@ func FieldsChange(oldFields []*Field, newFields []*Field) (reserve []*Field, del
104 } 112 }
105 113
106 type FieldValues struct { 114 type FieldValues struct {
107 - Number int `json:"number"` 115 + Number int `json:"rowIndex"`
108 FieldValues []*FieldValue `json:"fieldValues"` 116 FieldValues []*FieldValue `json:"fieldValues"`
109 } 117 }
110 118
@@ -12,8 +12,11 @@ type LogEntry struct { @@ -12,8 +12,11 @@ type LogEntry struct {
12 Content string `json:"content"` 12 Content string `json:"content"`
13 // 操作人名称 13 // 操作人名称
14 OperatorName string `json:"operatorName"` 14 OperatorName string `json:"operatorName"`
15 -  
16 - ctx *Context `json:"-"` 15 + // 错误级别
  16 + Level string `json:"level"`
  17 + // 错误信息
  18 + Error string `json:"error"`
  19 + ctx *Context `json:"-"`
17 } 20 }
18 21
19 func (l LogEntry) Entry() LogEntry { 22 func (l LogEntry) Entry() LogEntry {
@@ -226,3 +226,22 @@ func (gateway ApiByteLib) EditTableData(param domain.ReqEditTableData) (*domain. @@ -226,3 +226,22 @@ func (gateway ApiByteLib) EditTableData(param domain.ReqEditTableData) (*domain.
226 } 226 }
227 return &data, nil 227 return &data, nil
228 } 228 }
  229 +
  230 +// FieldOptionalValues 字段可选值
  231 +func (gateway ApiByteLib) FieldOptionalValues(param domain.ReqFieldOptionalValues) (*domain.DataFieldOptionalValues, error) {
  232 + url := gateway.Host() + "/checkout-tables/filter-column-data"
  233 + method := "post"
  234 + var data CheckoutTablesFilterColumnDataResponse
  235 + request := NewCheckoutTablesFilterColumnDataRequest(param)
  236 + err := gateway.FastDoRequest(url, method, request, &data)
  237 + if err != nil {
  238 + return nil, err
  239 + }
  240 + var response = domain.DataFieldOptionalValues{
  241 + //TableName: data.MasterTableName,
  242 + Field: param.Field,
  243 + Values: data.ShowData,
  244 + Total: data.DataCount,
  245 + }
  246 + return &response, nil
  247 +}
@@ -7,14 +7,15 @@ import ( @@ -7,14 +7,15 @@ import (
7 ) 7 )
8 8
9 type RequestCheckoutTablesQuery struct { 9 type RequestCheckoutTablesQuery struct {
10 - OriginalTableId string `json:"originalTableId"`  
11 - IsFromOriginalTable bool `json:"isFromOriginalTable"`  
12 - TableFileUrl string `json:"tableFileUrl"`  
13 - ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`  
14 - PageNumber int `json:"pageNumber"`  
15 - PageSize int `json:"pageSize"`  
16 - QueryParameters map[string]interface{} `json:"queryParameters"`  
17 - SortParameters map[string]interface{} `json:"sortParameters"` 10 + OriginalTableId string `json:"originalTableId"`
  11 + IsFromOriginalTable bool `json:"isFromOriginalTable"`
  12 + TableFileUrl string `json:"tableFileUrl"`
  13 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
  14 + PageNumber int `json:"pageNumber"`
  15 + PageSize int `json:"pageSize"`
  16 + QueryParameters []domain.QueryParameter `json:"queryParameters"`
  17 + //QueryParameters map[string]interface{} `json:"queryParameters"`
  18 + SortParameters map[string]interface{} `json:"sortParameters"`
18 } 19 }
19 20
20 type DataCheckoutTables struct { 21 type DataCheckoutTables struct {
@@ -35,8 +36,10 @@ func NewRequestCheckoutTablesQuery(param domain.ReqLoadDataTable) RequestCheckou @@ -35,8 +36,10 @@ func NewRequestCheckoutTablesQuery(param domain.ReqLoadDataTable) RequestCheckou
35 ColumnSchemas: param.ColumnSchemas, 36 ColumnSchemas: param.ColumnSchemas,
36 PageNumber: param.PageNumber, 37 PageNumber: param.PageNumber,
37 PageSize: param.PageSize, 38 PageSize: param.PageSize,
38 - QueryParameters: param.QueryParameters,  
39 - SortParameters: param.SortParameters, 39 + //QueryParameters: param.QueryParameters,
  40 + QueryParameters: make([]domain.QueryParameter, 0),
  41 + //QueryParameters: make(map[string]interface{}),
  42 + SortParameters: param.SortParameters,
40 } 43 }
41 } 44 }
42 45
@@ -287,3 +290,30 @@ func NewSplitTableRequest(param domain.ReqSplitTable) SplitTableRequest { @@ -287,3 +290,30 @@ func NewSplitTableRequest(param domain.ReqSplitTable) SplitTableRequest {
287 SplitTableFieldSchemas: ToFieldSchemas(param.ToSubTable.DataFields), 290 SplitTableFieldSchemas: ToFieldSchemas(param.ToSubTable.DataFields),
288 } 291 }
289 } 292 }
  293 +
  294 +type (
  295 + CheckoutTablesFilterColumnDataRequest struct {
  296 + OriginalTableId string `json:"originalTableId"`
  297 + domain.ColumnSchema
  298 + PageNumber int `json:"pageNumber"`
  299 + PageSize int `json:"pageSize"`
  300 + FilterParameters map[string]string `json:"filterParameters"`
  301 + }
  302 + CheckoutTablesFilterColumnDataResponse struct {
  303 + DataCount int `json:"dataCount"`
  304 + ShowData []string `json:"showData"`
  305 + }
  306 +)
  307 +
  308 +func NewCheckoutTablesFilterColumnDataRequest(param domain.ReqFieldOptionalValues) CheckoutTablesFilterColumnDataRequest {
  309 + return CheckoutTablesFilterColumnDataRequest{
  310 + OriginalTableId: intToString(param.FileId),
  311 + ColumnSchema: domain.ColumnSchema{
  312 + ColumnName: param.Field.Name,
  313 + ColumnType: param.Field.SQLType,
  314 + },
  315 + PageNumber: param.Where.PageNumber,
  316 + PageSize: param.Where.PageSize,
  317 + FilterParameters: map[string]string{"keyWord": param.Match},
  318 + }
  319 +}
@@ -121,6 +121,11 @@ func (ptr *ByteCoreService) SplitTable(param domain.ReqSplitTable) (*domain.Data @@ -121,6 +121,11 @@ func (ptr *ByteCoreService) SplitTable(param domain.ReqSplitTable) (*domain.Data
121 return apiByteLib.SplitTable(param) 121 return apiByteLib.SplitTable(param)
122 } 122 }
123 123
  124 +func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalValues) (*domain.DataFieldOptionalValues, error) {
  125 + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
  126 + return apiByteLib.FieldOptionalValues(param)
  127 +}
  128 +
124 ////////////// 129 //////////////
125 // 字库核心 130 // 字库核心
126 ////////////// 131 //////////////
@@ -25,7 +25,9 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR @@ -25,7 +25,9 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR
25 var operateName string = req.Action 25 var operateName string = req.Action
26 // 日志 26 // 日志
27 if err = FastLog(ptr.transactionContext, domain.VerifiedStepLog, file.FileId, &ExcelTableEditLog{ 27 if err = FastLog(ptr.transactionContext, domain.VerifiedStepLog, file.FileId, &ExcelTableEditLog{
28 - LogEntry: domain.NewLogEntry(file.FileInfo.Name, domain.VerifiedFile.ToString(), domain.FileVerify, ctx), 28 + LogEntry: domain.NewLogEntry(file.FileInfo.Name, domain.VerifiedFile.ToString(), domain.FileVerify,
  29 + ctx.WithValue(domain.ContextWithLogLevel, domain.LevelInfo).
  30 + WithValue(domain.ContextWithLogMsg, "")),
29 ProcessFields: req.ProcessFields, 31 ProcessFields: req.ProcessFields,
30 OperateName: operateName, 32 OperateName: operateName,
31 }); err != nil { 33 }); err != nil {
@@ -46,6 +48,8 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR @@ -46,6 +48,8 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR
46 return nil, err 48 return nil, err
47 } 49 }
48 50
  51 + // 1.有修改表类型的,更新缓存数据列类型
  52 +
49 return response, nil 53 return response, nil
50 } 54 }
51 55
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis"
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
9 ) 10 )
10 11
@@ -50,12 +51,17 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie @@ -50,12 +51,17 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie
50 IsFromOriginalTable: isSourceFile, 51 IsFromOriginalTable: isSourceFile,
51 TableFileUrl: fileUrl, 52 TableFileUrl: fileUrl,
52 ColumnSchemas: bytelib.DomainFieldsToColumnSchemas(fields), 53 ColumnSchemas: bytelib.DomainFieldsToColumnSchemas(fields),
53 - QueryParameters: make(map[string]interface{}),  
54 - SortParameters: make(map[string]interface{}), 54 + //QueryParameters: make([]domain.QueryParameter, 0),
  55 + SortParameters: make(map[string]interface{}),
55 }) 56 })
56 if err != nil { 57 if err != nil {
57 return nil, err 58 return nil, err
58 } 59 }
  60 + cache := redis.NewFileCacheService()
  61 + _, err = cache.Update(redis.KeyTemporaryFileInfo(file.FileId), file, response.Fields, response.Total)
  62 + if err != nil {
  63 + return nil, err
  64 + }
59 var responseDto = &FilePreviewDto{} 65 var responseDto = &FilePreviewDto{}
60 responseDto.Load(file.FileId, response) 66 responseDto.Load(file.FileId, response)
61 return responseDto, nil 67 return responseDto, nil
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
8 "strings" 9 "strings"
9 "time" 10 "time"
10 ) 11 )
@@ -43,6 +44,13 @@ func (ptr *PGLogService) Log(logType domain.LogType, sourceId int, logEntry Log) @@ -43,6 +44,13 @@ func (ptr *PGLogService) Log(logType domain.LogType, sourceId int, logEntry Log)
43 CreatedAt: time.Now(), 44 CreatedAt: time.Now(),
44 Context: logEntry.Context(), 45 Context: logEntry.Context(),
45 } 46 }
  47 +
  48 + if v, ok := logEntry.Context().GetValue(domain.ContextWithLogLevel); ok {
  49 + log.Entry.Level = string(v.(domain.LogLevel))
  50 + }
  51 + if v, ok := logEntry.Context().GetValue(domain.ContextWithLogLevel); ok {
  52 + log.Entry.Error = v.(string)
  53 + }
46 _, err := logRepository.Save(log) 54 _, err := logRepository.Save(log)
47 return err 55 return err
48 } 56 }
@@ -207,10 +215,11 @@ type RowUpdateLog struct { @@ -207,10 +215,11 @@ type RowUpdateLog struct {
207 215
208 func (l *RowUpdateLog) Content() string { 216 func (l *RowUpdateLog) Content() string {
209 change := "" 217 change := ""
210 - index := l.Number + l.Where.Offset() 218 + //index := l.Number + l.Where.Offset()
211 for _, f := range l.FieldValue { 219 for _, f := range l.FieldValue {
212 if f.OldValue != f.Value { 220 if f.OldValue != f.Value {
213 - change += fmt.Sprintf("%v字段%v行的值从%v更改为%v;", f.Field.Name, index, f.OldValue, f.Value) 221 + //change += fmt.Sprintf("%v字段%v行的值从%v更改为%v;", f.Field.Name, index, f.OldValue, f.Value)
  222 + change += fmt.Sprintf("【%v】字段的值从“%v”更改为“%v”;", f.Field.Name, f.OldValue, f.Value)
214 } 223 }
215 } 224 }
216 if len(change) == 0 { 225 if len(change) == 0 {
@@ -222,14 +231,29 @@ func (l *RowUpdateLog) Content() string { @@ -222,14 +231,29 @@ func (l *RowUpdateLog) Content() string {
222 231
223 type RowRemoveLog struct { 232 type RowRemoveLog struct {
224 domain.LogEntry 233 domain.LogEntry
225 - FieldValue *domain.FieldValues  
226 - Where domain.Where 234 + DeleteRowCount int
  235 + Where domain.Where
227 } 236 }
228 237
229 func (l *RowRemoveLog) Content() string { 238 func (l *RowRemoveLog) Content() string {
230 - index := l.FieldValue.Number + l.Where.Offset() 239 + index := l.DeleteRowCount
231 //msg := fmt.Sprintf("删除%v行数据;筛选件:%v",index,"") 240 //msg := fmt.Sprintf("删除%v行数据;筛选件:%v",index,"")
232 msg := fmt.Sprintf("删除%v行数据;", index) 241 msg := fmt.Sprintf("删除%v行数据;", index)
  242 + filters := make([]string, 0)
  243 + inArgs := func(args []string) string {
  244 + return strings.Join(args, "、")
  245 + }
  246 + for _, c := range l.Where.Conditions {
  247 + if len(c.In) > 0 {
  248 + filters = append(filters, fmt.Sprintf("【%v】 包含 %v", c.Field.Name, inArgs(starrocks.ArrayInterfaceToString(c.In))))
  249 + }
  250 + if len(c.Ex) > 0 {
  251 + filters = append(filters, fmt.Sprintf("【%v】 不包含 %v", c.Field.Name, inArgs(starrocks.ArrayInterfaceToString(c.Ex))))
  252 + }
  253 + }
  254 + if len(filters) > 0 {
  255 + msg += "筛选件:" + strings.Join(filters, "|")
  256 + }
233 return msg 257 return msg
234 } 258 }
235 259
@@ -24,26 +24,33 @@ func NewTableEditDataService(transactionContext *pgTransaction.TransactionContex @@ -24,26 +24,33 @@ func NewTableEditDataService(transactionContext *pgTransaction.TransactionContex
24 24
25 func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.EditDataRequest) (interface{}, error) { 25 func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.EditDataRequest) (interface{}, error) {
26 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) 26 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
27 - table, err := tableRepository.FindOne(map[string]interface{}{"tableId": request.TableId})  
28 - if err != nil {  
29 - return nil, err 27 + var table *domain.Table = request.Table
  28 + var err error
  29 + if table == nil {
  30 + table, err = tableRepository.FindOne(map[string]interface{}{"tableId": request.TableId})
  31 + if err != nil {
  32 + return nil, err
  33 + }
30 } 34 }
  35 +
31 if table.TableType != domain.SideTable.ToString() { 36 if table.TableType != domain.SideTable.ToString() {
32 return nil, fmt.Errorf("副表才允许编辑数据") 37 return nil, fmt.Errorf("副表才允许编辑数据")
33 } 38 }
34 - //if table.TableType == domain.SubTable.ToString(){  
35 - // mainTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": request.TableId})  
36 - // if err != nil {  
37 - // return nil, err  
38 - // }  
39 - // table.SQLName = mainTable.SQLName  
40 - //}  
41 39
42 for _, l := range request.AddList { 40 for _, l := range request.AddList {
43 ptr.add(ctx, table, l, request.Where) 41 ptr.add(ctx, table, l, request.Where)
44 } 42 }
45 - for _, l := range request.RemoveList {  
46 - ptr.remove(ctx, table, l, request.Where) 43 + if len(request.RemoveList) > 0 {
  44 + // 日志
  45 + if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowRemoveLog{
  46 + LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx),
  47 + DeleteRowCount: len(request.RemoveList),
  48 + }); err != nil {
  49 + return nil, err
  50 + }
  51 + for _, l := range request.RemoveList {
  52 + ptr.remove(ctx, table, l, request.Where)
  53 + }
47 } 54 }
48 for _, l := range request.UpdateList { 55 for _, l := range request.UpdateList {
49 ptr.update(ctx, table, l, request.Where) 56 ptr.update(ctx, table, l, request.Where)
@@ -72,15 +79,6 @@ func (ptr *TableEditDataService) add(ctx *domain.Context, table *domain.Table, l @@ -72,15 +79,6 @@ func (ptr *TableEditDataService) add(ctx *domain.Context, table *domain.Table, l
72 func (ptr *TableEditDataService) remove(ctx *domain.Context, table *domain.Table, list *domain.FieldValues, where domain.Where) error { 79 func (ptr *TableEditDataService) remove(ctx *domain.Context, table *domain.Table, list *domain.FieldValues, where domain.Where) error {
73 var err error 80 var err error
74 81
75 - // 日志  
76 - if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowRemoveLog{  
77 - LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx),  
78 - FieldValue: list,  
79 - Where: where,  
80 - }); err != nil {  
81 - return err  
82 - }  
83 -  
84 // 删除记录 82 // 删除记录
85 if err = starrocks.Delete(starrocks.DB, table.SQLName, list.FieldValues); err != nil { 83 if err = starrocks.Delete(starrocks.DB, table.SQLName, list.FieldValues); err != nil {
86 return err 84 return err
@@ -93,7 +91,9 @@ func (ptr *TableEditDataService) update(ctx *domain.Context, table *domain.Table @@ -93,7 +91,9 @@ func (ptr *TableEditDataService) update(ctx *domain.Context, table *domain.Table
93 91
94 // 日志 92 // 日志
95 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowUpdateLog{ 93 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowUpdateLog{
96 - LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx), 94 + LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx),
  95 + FieldValue: list.FieldValues,
  96 + Number: list.Number,
97 }); err != nil { 97 }); err != nil {
98 return err 98 return err
99 } 99 }
  1 +package redis
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/utils/json"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  8 +)
  9 +
  10 +const (
  11 + TemporaryFileExpire = 3600 * 10
  12 +)
  13 +
  14 +func KeyTemporaryFileInfo(fileId int) string {
  15 + return fmt.Sprintf("%v:file:temporary:%v", constant.CACHE_PREFIX, fileId)
  16 +}
  17 +
  18 +type TemporaryFileInfo struct {
  19 + FileId int `json:"fileId"`
  20 + FileType string `json:"fileType"`
  21 + Total int `json:"total"`
  22 + Fields []*domain.Field `json:"fields"`
  23 + // 编辑表错误,有错误不允许保存成校验文件
  24 + // 行记录错误
  25 + // 列类型有错误
  26 + // 表整体错误
  27 +}
  28 +
  29 +func (f *TemporaryFileInfo) SetFile(file *domain.File) *TemporaryFileInfo {
  30 + f.FileId = file.FileId
  31 + f.FileType = file.FileType
  32 + return f
  33 +}
  34 +
  35 +func (f *TemporaryFileInfo) SetFields(fields []*domain.Field) *TemporaryFileInfo {
  36 + f.Fields = fields
  37 + return f
  38 +}
  39 +
  40 +func (f *TemporaryFileInfo) SetTotal(total int) *TemporaryFileInfo {
  41 + f.Total = total
  42 + return f
  43 +}
  44 +
  45 +type FileCacheService struct {
  46 +}
  47 +
  48 +func (s *FileCacheService) Update(key string, file *domain.File, fields []*domain.Field, total int) (*TemporaryFileInfo, error) {
  49 + ok, err := ZeroCoreRedis.Exists(key)
  50 + var response = &TemporaryFileInfo{}
  51 + if err != nil {
  52 + return response, err
  53 + }
  54 + if !ok {
  55 + response.SetFile(file).SetFields(fields).SetTotal(total)
  56 + return response, ZeroCoreRedis.Setex(key, json.MarshalToString(response), TemporaryFileExpire)
  57 + }
  58 + data, err := ZeroCoreRedis.Get(key)
  59 + if err != nil {
  60 + return nil, err
  61 + }
  62 + err = json.UnmarshalFromString(data, response)
  63 + if err != nil {
  64 + return nil, err
  65 + }
  66 + response.SetFields(fields)
  67 + err = ZeroCoreRedis.Setex(key, json.MarshalToString(response), TemporaryFileExpire)
  68 + if err != nil {
  69 + return nil, err
  70 + }
  71 + return response, err
  72 +}
  73 +
  74 +func (s *FileCacheService) Get(key string) (*TemporaryFileInfo, error) {
  75 + var response = &TemporaryFileInfo{}
  76 + ok, err := ZeroCoreRedis.Exists(key)
  77 + if err != nil {
  78 + return nil, err
  79 + }
  80 + if !ok {
  81 + return nil, fmt.Errorf("临时文件信息缓存不存在")
  82 + }
  83 + data, err := ZeroCoreRedis.Get(key)
  84 + if err != nil {
  85 + return nil, err
  86 + }
  87 + err = json.UnmarshalFromString(data, response)
  88 + if err != nil {
  89 + return nil, err
  90 + }
  91 + return response, nil
  92 +}
  93 +
  94 +func NewFileCacheService() *FileCacheService {
  95 + return &FileCacheService{}
  96 +}
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 ) 8 )
9 9
10 func KeyExportTable(ctx *domain.Context, tableId int) string { 10 func KeyExportTable(ctx *domain.Context, tableId int) string {
11 - return fmt.Sprintf("%v.lock-table.%v,%v", constant.SERVICE_ENV, tableId, ctx.OperatorId) 11 + return fmt.Sprintf("%v:lock-table:%v:%v", constant.CACHE_PREFIX, tableId, ctx.OperatorId)
12 } 12 }
13 13
14 var ZeroCoreRedis *redis.Redis 14 var ZeroCoreRedis *redis.Redis
@@ -2,6 +2,7 @@ package starrocks @@ -2,6 +2,7 @@ package starrocks
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/google/uuid"
5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
6 "gorm.io/gorm" 7 "gorm.io/gorm"
7 ) 8 )
@@ -10,7 +11,9 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { @@ -10,7 +11,9 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error {
10 value := map[string]interface{}{} 11 value := map[string]interface{}{}
11 for _, f := range fields { 12 for _, f := range fields {
12 if f.Field.Flag == domain.PKField && f.Value == "" { 13 if f.Field.Flag == domain.PKField && f.Value == "" {
13 - continue 14 + //continue
  15 + id, _ := uuid.NewUUID()
  16 + f.Value = id.String()
14 } 17 }
15 value[f.Field.SQLName] = f.TypeValue() 18 value[f.Field.SQLName] = f.TypeValue()
16 } 19 }
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "database/sql" 4 "database/sql"
5 "fmt" 5 "fmt"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
7 "gorm.io/gorm" 8 "gorm.io/gorm"
8 "reflect" 9 "reflect"
9 "strings" 10 "strings"
@@ -23,6 +24,7 @@ func Query(params QueryOptions, queryFunc func(params QueryOptions) (*sql.Rows, @@ -23,6 +24,7 @@ func Query(params QueryOptions, queryFunc func(params QueryOptions) (*sql.Rows,
23 } 24 }
24 25
25 type QueryOptions struct { 26 type QueryOptions struct {
  27 + Table *domain.Table
26 TableName string 28 TableName string
27 Select []*domain.Field 29 Select []*domain.Field
28 Where []Condition 30 Where []Condition
@@ -60,6 +62,15 @@ func (o *QueryOptions) SetDefaultOrder() *QueryOptions { @@ -60,6 +62,15 @@ func (o *QueryOptions) SetDefaultOrder() *QueryOptions {
60 } 62 }
61 // 没有排序的加一个排序,才能分页 63 // 没有排序的加一个排序,才能分页
62 if !hasOrder { 64 if !hasOrder {
  65 + if o.Table != nil {
  66 + o.Where = append(o.Where, Condition{
  67 + Condition: domain.Condition{
  68 + Field: o.Table.PK,
  69 + Order: "ASC",
  70 + },
  71 + })
  72 + return o
  73 + }
63 o.Where = append(o.Where, Condition{ 74 o.Where = append(o.Where, Condition{
64 Condition: domain.Condition{ 75 Condition: domain.Condition{
65 Field: domain.PK(), 76 Field: domain.PK(),
@@ -207,3 +218,11 @@ func WrapQueryCountWithDB(params QueryOptions, db *gorm.DB) func() (int64, error @@ -207,3 +218,11 @@ func WrapQueryCountWithDB(params QueryOptions, db *gorm.DB) func() (int64, error
207 return total, query.Error 218 return total, query.Error
208 } 219 }
209 } 220 }
  221 +
  222 +func ArrayInterfaceToString(args []interface{}) []string {
  223 + result := make([]string, 0)
  224 + for _, arg := range args {
  225 + result = append(result, utils.AssertString(arg))
  226 + }
  227 + return result
  228 +}
@@ -156,7 +156,7 @@ func (controller *TableController) AddTableStruct() { @@ -156,7 +156,7 @@ func (controller *TableController) AddTableStruct() {
156 func (controller *TableController) ExportDataTable() { 156 func (controller *TableController) ExportDataTable() {
157 tableService := service.NewTableService(nil) 157 tableService := service.NewTableService(nil)
158 cmd := &command.TablePreviewCommand{} 158 cmd := &command.TablePreviewCommand{}
159 - controller.Unmarshal(cmd) 159 + Must(controller.Unmarshal(cmd))
160 data, err := tableService.ExportDataTableV2(ParseContext(controller.BaseController), cmd) 160 data, err := tableService.ExportDataTableV2(ParseContext(controller.BaseController), cmd)
161 controller.Response(data, err) 161 controller.Response(data, err)
162 } 162 }
@@ -164,7 +164,7 @@ func (controller *TableController) ExportDataTable() { @@ -164,7 +164,7 @@ func (controller *TableController) ExportDataTable() {
164 func (controller *TableController) TablePreview() { 164 func (controller *TableController) TablePreview() {
165 tableService := service.NewTableService(nil) 165 tableService := service.NewTableService(nil)
166 cmd := &command.TablePreviewCommand{} 166 cmd := &command.TablePreviewCommand{}
167 - controller.Unmarshal(cmd) 167 + Must(controller.Unmarshal(cmd))
168 data, err := tableService.TablePreview(ParseContext(controller.BaseController), cmd) 168 data, err := tableService.TablePreview(ParseContext(controller.BaseController), cmd)
169 controller.Response(data, err) 169 controller.Response(data, err)
170 } 170 }
@@ -172,7 +172,7 @@ func (controller *TableController) TablePreview() { @@ -172,7 +172,7 @@ func (controller *TableController) TablePreview() {
172 func (controller *TableController) DBTablePreview() { 172 func (controller *TableController) DBTablePreview() {
173 tableService := service.NewTableService(nil) 173 tableService := service.NewTableService(nil)
174 cmd := &command.DBTablePreviewCommand{} 174 cmd := &command.DBTablePreviewCommand{}
175 - controller.Unmarshal(cmd) 175 + Must(controller.Unmarshal(cmd))
176 data, err := tableService.DBTablePreview(ParseContext(controller.BaseController), cmd) 176 data, err := tableService.DBTablePreview(ParseContext(controller.BaseController), cmd)
177 controller.Response(data, err) 177 controller.Response(data, err)
178 } 178 }
@@ -180,7 +180,7 @@ func (controller *TableController) DBTablePreview() { @@ -180,7 +180,7 @@ func (controller *TableController) DBTablePreview() {
180 func (controller *TableController) FieldOptionalValues() { 180 func (controller *TableController) FieldOptionalValues() {
181 tableService := service.NewTableService(nil) 181 tableService := service.NewTableService(nil)
182 cmd := &command.FieldOptionalValuesCommand{} 182 cmd := &command.FieldOptionalValuesCommand{}
183 - controller.Unmarshal(cmd) 183 + Must(controller.Unmarshal(cmd))
184 data, err := tableService.FieldOptionalValues(ParseContext(controller.BaseController), cmd) 184 data, err := tableService.FieldOptionalValues(ParseContext(controller.BaseController), cmd)
185 controller.Response(data, err) 185 controller.Response(data, err)
186 } 186 }
@@ -191,21 +191,21 @@ func (controller *TableController) Preview() { @@ -191,21 +191,21 @@ func (controller *TableController) Preview() {
191 cmd := &struct { 191 cmd := &struct {
192 ObjectType string `json:"objectType"` 192 ObjectType string `json:"objectType"`
193 }{} 193 }{}
194 - controller.Unmarshal(cmd) 194 + Must(controller.Unmarshal(cmd))
195 var data interface{} 195 var data interface{}
196 var err error 196 var err error
197 switch cmd.ObjectType { 197 switch cmd.ObjectType {
198 case domain.ObjectFile: 198 case domain.ObjectFile:
199 cmd := &filecommand.LoadDataTableCommand{} 199 cmd := &filecommand.LoadDataTableCommand{}
200 - controller.Unmarshal(cmd) 200 + Must(controller.Unmarshal(cmd))
201 data, err = fileService.FilePreview(ParseContext(controller.BaseController), cmd) 201 data, err = fileService.FilePreview(ParseContext(controller.BaseController), cmd)
202 case domain.ObjectMetaTable: 202 case domain.ObjectMetaTable:
203 cmd := &command.TablePreviewCommand{} 203 cmd := &command.TablePreviewCommand{}
204 - controller.Unmarshal(cmd) 204 + Must(controller.Unmarshal(cmd))
205 data, err = tableService.TablePreview(ParseContext(controller.BaseController), cmd) 205 data, err = tableService.TablePreview(ParseContext(controller.BaseController), cmd)
206 case domain.ObjectDBTable: 206 case domain.ObjectDBTable:
207 cmd := &command.DBTablePreviewCommand{} 207 cmd := &command.DBTablePreviewCommand{}
208 - controller.Unmarshal(cmd) 208 + Must(controller.Unmarshal(cmd))
209 data, err = tableService.DBTablePreview(ParseContext(controller.BaseController), cmd) 209 data, err = tableService.DBTablePreview(ParseContext(controller.BaseController), cmd)
210 default: 210 default:
211 211
@@ -215,8 +215,8 @@ func (controller *TableController) Preview() { @@ -215,8 +215,8 @@ func (controller *TableController) Preview() {
215 215
216 func (controller *TableController) RowEdit() { 216 func (controller *TableController) RowEdit() {
217 tableService := service.NewTableService(nil) 217 tableService := service.NewTableService(nil)
218 - cmd := &command.RowEditCommand{} 218 + cmd := &command.RowEditCommandV2{}
219 Must(controller.Unmarshal(cmd)) 219 Must(controller.Unmarshal(cmd))
220 - data, err := tableService.RowEdit(ParseContext(controller.BaseController), cmd) 220 + data, err := tableService.RowEditV2(ParseContext(controller.BaseController), cmd)
221 controller.Response(data, err) 221 controller.Response(data, err)
222 } 222 }