作者 yangfu

refactor: optimize core

@@ -159,11 +159,11 @@ @@ -159,11 +159,11 @@
159 - [ ] 表格编辑 1 159 - [ ] 表格编辑 1
160 - [ ] 保存校验文件 (文件地址) 1 160 - [ ] 保存校验文件 (文件地址) 1
161 - [ ] 生成主表 1 161 - [ ] 生成主表 1
162 -- [ ] 表复制 (副表) 162 +- [ ] 表复制 (副表)1
163 - [ ] 追加数据 (主表、副表) 163 - [ ] 追加数据 (主表、副表)
164 - [ ] 表删除 (主表、副表)~~、分表~~ 164 - [ ] 表删除 (主表、副表)~~、分表~~
165 -- [x] ~~表拆分~~  
166 -- [x] ~~更新表结构(分表)~~ 165 +- [ ] 表拆分 1
  166 +- [ ] 更新表结构(分表)1
167 - [ ] 编辑、添加、删除表数据(副表) 1 167 - [ ] 编辑、添加、删除表数据(副表) 1
168 - [ ] 取消校验 168 - [ ] 取消校验
169 169
1 -POSTGRESQL_DB_NAME = allied_creation_dev 1 +POSTGRESQL_DB_NAME = allied_creation_test
2 POSTGRESQL_HOST = 114.55.200.59 2 POSTGRESQL_HOST = 114.55.200.59
3 POSTGRESQL_PORT = 31543 3 POSTGRESQL_PORT = 31543
4 POSTGRESQL_USER = postgres 4 POSTGRESQL_USER = postgres
@@ -9,7 +9,7 @@ HTTP_PORT = 8081 @@ -9,7 +9,7 @@ HTTP_PORT = 8081
9 ENABLE_KAFKA_LOG11 = true 9 ENABLE_KAFKA_LOG11 = true
10 HTTPS_PORT = 8143 10 HTTPS_PORT = 8143
11 ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com 11 ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com
12 -BYTE_CORE_HOST = http://220.250.41.79:8303 12 +BYTE_CORE_HOST = http://47.97.5.102:8303
13 13
14 STARROCKS_DB_NAME = character_library 14 STARROCKS_DB_NAME = character_library
15 STARROCKS_USER = root 15 STARROCKS_USER = root
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "github.com/linmadan/egglib-go/core/application" 4 "github.com/linmadan/egglib-go/core/application"
5 "github.com/linmadan/egglib-go/transaction/pg" 5 "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/domain/bytecore"  
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
9 ) 8 )
10 9
@@ -58,6 +57,6 @@ func CreateTableEditDataService(transactionContext application.TransactionContex @@ -58,6 +57,6 @@ func CreateTableEditDataService(transactionContext application.TransactionContex
58 } 57 }
59 58
60 // 字库核心 59 // 字库核心
61 -func CreateByteCoreService(transactionContext application.TransactionContext) (bytecore.ByteLibService, error) { 60 +func CreateByteCoreService(transactionContext application.TransactionContext) (domain.ByteLibService, error) {
62 return domainService.ByteCore, nil 61 return domainService.ByteCore, nil
63 } 62 }
@@ -9,7 +9,6 @@ import ( @@ -9,7 +9,6 @@ import (
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/dto"
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/application/file/query"
11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
12 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore"  
13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" 12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
14 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" 13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
15 "path/filepath" 14 "path/filepath"
@@ -295,7 +294,7 @@ func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *co @@ -295,7 +294,7 @@ func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *co
295 } 294 }
296 295
297 byteCore, _ := factory.CreateByteCoreService(transactionContext) 296 byteCore, _ := factory.CreateByteCoreService(transactionContext)
298 - _, err = byteCore.CancelFile(bytecore.ReqCancelFile{}) 297 + _, err = byteCore.CancelFile(domain.ReqCancelFile{})
299 if err != nil { 298 if err != nil {
300 return nil, factory.FastError(err) 299 return nil, factory.FastError(err)
301 } 300 }
@@ -31,7 +31,8 @@ type SearchLogCommand struct { @@ -31,7 +31,8 @@ type SearchLogCommand struct {
31 BeginTime time.Time `cname:"开始时间" json:"beginTime"` 31 BeginTime time.Time `cname:"开始时间" json:"beginTime"`
32 // 结束时间 32 // 结束时间
33 EndTime time.Time `cname:"结束时间" json:"endTime"` 33 EndTime time.Time `cname:"结束时间" json:"endTime"`
34 - 34 + // 按log_id 排序
  35 + SortByLogId string `json:"sortByLogId"`
35 Context *domain.Context 36 Context *domain.Context
36 } 37 }
37 38
@@ -19,18 +19,18 @@ type TableDetailDto struct { @@ -19,18 +19,18 @@ type TableDetailDto struct {
19 Fields []*domain.Field `json:"fields"` 19 Fields []*domain.Field `json:"fields"`
20 } 20 }
21 21
22 -func (d *TableDetailDto) Load(m *domain.Table, mainTable *domain.Table) {  
23 - d.TableId = m.TableId  
24 - d.TableType = m.TableType  
25 - d.Name = m.Name  
26 - d.ParentId = m.ParentId  
27 - if m.TableType == domain.MainTable.ToString() || m.TableType == domain.SideTable.ToString() {  
28 - d.MainTableFields = m.Fields(false) 22 +func (d *TableDetailDto) Load(table *domain.Table, mainTable *domain.Table) {
  23 + d.TableId = table.TableId
  24 + d.TableType = table.TableType
  25 + d.Name = table.Name
  26 + d.ParentId = table.ParentId
  27 + if table.TableType == domain.MainTable.ToString() || table.TableType == domain.SideTable.ToString() {
  28 + d.MainTableFields = table.Fields(false)
29 } else if mainTable != nil { 29 } else if mainTable != nil {
30 d.MainTableFields = mainTable.Fields(false) 30 d.MainTableFields = mainTable.Fields(false)
31 } 31 }
32 - d.Fields = m.Fields(false)  
33 - d.ManualFields = m.ManualFields 32 + d.Fields = table.Fields(false)
  33 + d.ManualFields = table.ManualFields
34 if len(d.ManualFields) == 0 { 34 if len(d.ManualFields) == 0 {
35 d.ManualFields = make([]*domain.Field, 0) 35 d.ManualFields = make([]*domain.Field, 0)
36 } 36 }
@@ -12,7 +12,10 @@ type TablePreviewDto struct { @@ -12,7 +12,10 @@ type TablePreviewDto struct {
12 // 名称 12 // 名称
13 Name string `json:"name"` 13 Name string `json:"name"`
14 // 数据 14 // 数据
15 - *domain.DataTable 15 + //*domain.DataTable
  16 + Fields []*domain.Field `json:"fields"`
  17 + Data interface{} `json:"grid"`
  18 + //Total int64 `json:"total"`
16 } 19 }
17 20
18 func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, objectType string) *TablePreviewDto { 21 func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, objectType string) *TablePreviewDto {
@@ -20,12 +23,8 @@ func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, obj @@ -20,12 +23,8 @@ func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, obj
20 d.TableType = m.TableType 23 d.TableType = m.TableType
21 d.ObjectType = objectType 24 d.ObjectType = objectType
22 d.Name = m.Name 25 d.Name = m.Name
23 - d.DataTable = &domain.DataTable{}  
24 d.Fields = dataTable.MatchFields(m.Fields(true)) 26 d.Fields = dataTable.MatchFields(m.Fields(true))
25 - d.Data = dataTable.Data  
26 - d.Total = dataTable.Total  
27 - if len(d.Data) == 0 {  
28 - d.Data = make([][]string, 0)  
29 - } 27 + d.Data = domain.GripData(domain.ToFieldData(m.Fields(true), dataTable.Data, false), dataTable.Total)
  28 + //d.Total = dataTable.Total
30 return d 29 return d
31 } 30 }
1 -package bytecore  
2 -  
3 -import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 1 +package domain
4 2
5 type ByteLibService interface { 3 type ByteLibService interface {
6 LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error) 4 LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error)
7 EditTable(param ReqEditDataTable) (*DataEditDataTable, error) 5 EditTable(param ReqEditDataTable) (*DataEditDataTable, error)
8 SaveTable(param ReqSaveTable) (*DataSaveTable, error) 6 SaveTable(param ReqSaveTable) (*DataSaveTable, error)
9 - GenerateTable(ctx *domain.Context, param ReqGenerateTable) (*DataGenerateTable, error) 7 + GenerateTable(ctx *Context, param ReqGenerateTable) (*DataGenerateTable, error)
10 CopyTable(param ReqCopyTable) (*DataCopyTable, error) 8 CopyTable(param ReqCopyTable) (*DataCopyTable, error)
11 AppendData(param ReqAppendData) (*DataAppendData, error) 9 AppendData(param ReqAppendData) (*DataAppendData, error)
  10 + SplitTable(param ReqSplitTable) (*DataSplitTable, error)
12 DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error) 11 DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error)
13 CancelFile(param ReqCancelFile) (*DataCancelFile, error) 12 CancelFile(param ReqCancelFile) (*DataCancelFile, error)
14 EditTableData(param ReqEditTableData) (*DataEditTableData, error) 13 EditTableData(param ReqEditTableData) (*DataEditTableData, error)
@@ -20,7 +19,7 @@ type ( @@ -20,7 +19,7 @@ type (
20 FileName string `json:"file_name"` 19 FileName string `json:"file_name"`
21 Url string `json:"url"` 20 Url string `json:"url"`
22 Ext string `json:"ext"` 21 Ext string `json:"ext"`
23 - domain.Where 22 + Where
24 OriginalTableId string `json:"originalTableId"` 23 OriginalTableId string `json:"originalTableId"`
25 IsFromOriginalTable bool `json:"isFromOriginalTable"` 24 IsFromOriginalTable bool `json:"isFromOriginalTable"`
26 TableFileUrl string `json:"tableFileUrl"` 25 TableFileUrl string `json:"tableFileUrl"`
@@ -42,26 +41,46 @@ type ( @@ -42,26 +41,46 @@ type (
42 InValidCells []InValidCell `json:"inValidCells"` 41 InValidCells []InValidCell `json:"inValidCells"`
43 } 42 }
44 43
45 - Field struct {  
46 - // 索引序号  
47 - Index int `json:"index"`  
48 - // 名称  
49 - Name string `json:"name"`  
50 - // 对应数据库类型  
51 - Type string `json:"sqlType"`  
52 - } 44 + //Field struct {
  45 + // // 索引序号
  46 + // Index int `json:"index"`
  47 + // // 名称
  48 + // Name string `json:"name"`
  49 + // // 对应数据库类型
  50 + // Type string `json:"sqlType"`
  51 + //}
53 52
54 InValidCell struct { 53 InValidCell struct {
55 - X int `json:"x"`  
56 - Y int `json:"y"`  
57 - Error string `json:"error"` 54 + Col string `json:"col"`
  55 + Index int `json:"index"`
  56 + Err string `json:"err"`
58 } 57 }
59 ) 58 )
60 59
  60 +func NewInValidCells(fields Fields, mapData []map[string]string) []InValidCell {
  61 + inValidCells := make([]InValidCell, 0)
  62 + mapField := fields.ToMap()
  63 + for index, m := range mapData {
  64 + for k, v := range m {
  65 + if field, ok := mapField[k]; ok && len(v) > 0 {
  66 + _, err := ValueToType(v, field.SQLType)
  67 + if err != nil {
  68 + inValidCells = append(inValidCells, InValidCell{
  69 + Col: field.Name,
  70 + Index: index,
  71 + Err: err.Error(),
  72 + })
  73 + }
  74 + }
  75 + }
  76 + }
  77 + return inValidCells
  78 +}
  79 +
61 // https://github.com/go-gota/gota 类似pandas的数据处理包 80 // https://github.com/go-gota/gota 类似pandas的数据处理包
62 // https://github.com/gonum/gonum 81 // https://github.com/gonum/gonum
63 82
64 -func (table DataLoadDataTable) Filter(where domain.Where) *DataLoadDataTable { 83 +func (table DataLoadDataTable) Filter(where Where) *DataLoadDataTable {
65 begin := (where.PageNumber - 1) * where.PageSize 84 begin := (where.PageNumber - 1) * where.PageSize
66 if begin < 0 { 85 if begin < 0 {
67 begin = 0 86 begin = 0
@@ -115,7 +134,7 @@ type ( @@ -115,7 +134,7 @@ type (
115 ReqGenerateTable struct { 134 ReqGenerateTable struct {
116 FileId int 135 FileId int
117 FileUrl string 136 FileUrl string
118 - Table *domain.Table 137 + Table *Table
119 } 138 }
120 139
121 DataGenerateTable struct { 140 DataGenerateTable struct {
@@ -125,6 +144,8 @@ type ( @@ -125,6 +144,8 @@ type (
125 144
126 type ( 145 type (
127 ReqCopyTable struct { 146 ReqCopyTable struct {
  147 + Table *Table
  148 + CopyToTable *Table
128 } 149 }
129 150
130 DataCopyTable struct { 151 DataCopyTable struct {
@@ -133,9 +154,13 @@ type ( @@ -133,9 +154,13 @@ type (
133 154
134 type ( 155 type (
135 ReqAppendData struct { 156 ReqAppendData struct {
  157 + FileId int
  158 + FileUrl string
  159 + Table *Table
136 } 160 }
137 161
138 DataAppendData struct { 162 DataAppendData struct {
  163 + AppendCount int `json:"appendCount"`
139 } 164 }
140 ) 165 )
141 166
@@ -148,6 +173,16 @@ type ( @@ -148,6 +173,16 @@ type (
148 ) 173 )
149 174
150 type ( 175 type (
  176 + ReqSplitTable struct {
  177 + FromTable *Table
  178 + ToSubTable *Table
  179 + }
  180 +
  181 + DataSplitTable struct {
  182 + }
  183 +)
  184 +
  185 +type (
151 ReqCancelFile struct { 186 ReqCancelFile struct {
152 } 187 }
153 188
@@ -168,14 +203,35 @@ type ColumnSchema struct { @@ -168,14 +203,35 @@ type ColumnSchema struct {
168 ColumnType string `json:"columnType"` 203 ColumnType string `json:"columnType"`
169 } 204 }
170 205
171 -func ToFields(fields []*domain.Field) []*Field { 206 +func ToFields(fields []*Field) []*Field {
172 result := make([]*Field, 0) 207 result := make([]*Field, 0)
173 for _, f := range fields { 208 for _, f := range fields {
174 result = append(result, &Field{ 209 result = append(result, &Field{
175 Index: f.Index, 210 Index: f.Index,
176 Name: f.Name, 211 Name: f.Name,
177 - Type: f.SQLType, 212 + SQLType: f.SQLType,
178 }) 213 })
179 } 214 }
180 return result 215 return result
181 } 216 }
  217 +
  218 +//func ToFieldData(fields []*Field, data [][]string, byteName bool) []map[string]string {
  219 +// var result = make([]map[string]string, 0)
  220 +// var key string
  221 +// for _, d := range data {
  222 +// var item = make(map[string]string)
  223 +// for j, f := range fields {
  224 +// key = f.Name
  225 +// if byteName {
  226 +// key = f.Name
  227 +// }
  228 +// if len(d) >= j {
  229 +// item[key] = d[j]
  230 +// } else {
  231 +// item[key] = ""
  232 +// }
  233 +// }
  234 +// result = append(result, item)
  235 +// }
  236 +// return result
  237 +//}
@@ -152,16 +152,53 @@ func ValueToType(value string, sqlType string) (interface{}, error) { @@ -152,16 +152,53 @@ func ValueToType(value string, sqlType string) (interface{}, error) {
152 toTypeVal = value 152 toTypeVal = value
153 case Int.ToString(): 153 case Int.ToString():
154 toTypeVal, err = numberString.Int() 154 toTypeVal, err = numberString.Int()
  155 + if err != nil {
  156 + err = fmt.Errorf("[%v]不是有效的数值类型", value)
  157 + }
155 case Float.ToString(): 158 case Float.ToString():
156 toTypeVal, err = numberString.Float64() 159 toTypeVal, err = numberString.Float64()
  160 + err = fmt.Errorf("[%v]不是有效的浮点数类型", value)
157 case Date.ToString(): 161 case Date.ToString():
158 toTypeVal, err = xtime.Parse(value) 162 toTypeVal, err = xtime.Parse(value)
  163 + err = fmt.Errorf("[%v]不是有效的日期类型", value)
159 return nil, nil 164 return nil, nil
160 case Datetime.ToString(): 165 case Datetime.ToString():
161 toTypeVal, err = xtime.Parse(value) 166 toTypeVal, err = xtime.Parse(value)
  167 + err = fmt.Errorf("[%v]不是有效的时间类型", value)
162 return nil, nil 168 return nil, nil
163 default: 169 default:
164 return nil, fmt.Errorf("unknow sql type :%v", sqlType) 170 return nil, fmt.Errorf("unknow sql type :%v", sqlType)
165 } 171 }
166 return toTypeVal, err 172 return toTypeVal, err
167 } 173 }
  174 +
  175 +func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]string {
  176 + var result = make([]map[string]string, 0)
  177 + var key string
  178 + for _, d := range data {
  179 + var item = make(map[string]string)
  180 + for j, f := range fields {
  181 + key = f.SQLName
  182 + if byName {
  183 + key = f.Name
  184 + }
  185 + if len(d) >= j {
  186 + item[key] = d[j]
  187 + } else {
  188 + item[key] = ""
  189 + }
  190 + }
  191 + result = append(result, item)
  192 + }
  193 + return result
  194 +}
  195 +
  196 +func GripData(data []map[string]string, total int64) map[string]interface{} {
  197 + if len(data) == 0 {
  198 + data = make([]map[string]string, 0)
  199 + }
  200 + return map[string]interface{}{
  201 + "list": data,
  202 + "total": total,
  203 + }
  204 +}
@@ -51,6 +51,7 @@ func (file *File) UpdateFileUrl(url string) { @@ -51,6 +51,7 @@ func (file *File) UpdateFileUrl(url string) {
51 if url == file.FileInfo.Url { 51 if url == file.FileInfo.Url {
52 return 52 return
53 } 53 }
  54 + file.FileInfo.Ext = filepath.Ext(url)
54 file.FileInfo.Url = url 55 file.FileInfo.Url = url
55 } 56 }
56 57
@@ -56,9 +56,13 @@ func (table *Table) Identify() interface{} { @@ -56,9 +56,13 @@ func (table *Table) Identify() interface{} {
56 return table.TableId 56 return table.TableId
57 } 57 }
58 58
  59 +func (table *Table) TableIdString() string {
  60 + return fmt.Sprintf("%v", table.TableId)
  61 +}
  62 +
59 func (table *Table) WithContext(ctx *Context) *Table { 63 func (table *Table) WithContext(ctx *Context) *Table {
60 rand.Seed(time.Now().Unix()) 64 rand.Seed(time.Now().Unix())
61 - table.SQLName = fmt.Sprintf("%v_t%v_c%v", table.SQLName, rand.Intn(10000), ctx.CompanyId) 65 + table.SQLName = fmt.Sprintf("%v_t%v_c%v", table.SQLName, rand.Intn(1000000), ctx.CompanyId)
62 table.Context = ctx 66 table.Context = ctx
63 return table 67 return table
64 } 68 }
@@ -27,6 +27,7 @@ type BaseServiceGateway struct { @@ -27,6 +27,7 @@ type BaseServiceGateway struct {
27 ReadWriteTimeout time.Duration 27 ReadWriteTimeout time.Duration
28 host string 28 host string
29 Interceptor func(msg string) 29 Interceptor func(msg string)
  30 + ServiceName string
30 } 31 }
31 32
32 type Request struct { 33 type Request struct {
@@ -58,7 +59,7 @@ func (gateway BaseServiceGateway) CreateRequest(url string, method string) *http @@ -58,7 +59,7 @@ func (gateway BaseServiceGateway) CreateRequest(url string, method string) *http
58 func (gateway BaseServiceGateway) GetResponseData(result Response, data interface{}) error { 59 func (gateway BaseServiceGateway) GetResponseData(result Response, data interface{}) error {
59 err := json.Unmarshal(result.Data, data) 60 err := json.Unmarshal(result.Data, data)
60 if err != nil { 61 if err != nil {
61 - return NewErrCodeMsg(JsonUnMarshError, err.Error()) 62 + return NewErrCodeMsg(gateway.ServiceName, JsonUnMarshError, err.Error())
62 } 63 }
63 return nil 64 return nil
64 } 65 }
@@ -108,7 +109,7 @@ func (gateway BaseServiceGateway) DoRequest(requestParam Request, val interface{ @@ -108,7 +109,7 @@ func (gateway BaseServiceGateway) DoRequest(requestParam Request, val interface{
108 return err 109 return err
109 } 110 }
110 if result.Code != 0 && len(result.Msg) > 0 { 111 if result.Code != 0 && len(result.Msg) > 0 {
111 - return NewErrCodeMsg(result.Code, result.Msg) 112 + return NewErrCodeMsg(gateway.ServiceName, result.Code, result.Msg)
112 } 113 }
113 return gateway.GetResponseData(result, val) 114 return gateway.GetResponseData(result, val)
114 } 115 }
@@ -3,7 +3,7 @@ package bytelib @@ -3,7 +3,7 @@ package bytelib
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/beego/beego/v2/core/logs" 5 "github.com/beego/beego/v2/core/logs"
6 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" 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" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
8 "time" 8 "time"
9 ) 9 )
@@ -11,7 +11,6 @@ import ( @@ -11,7 +11,6 @@ import (
11 // ApiByteLib 字库底层接口 11 // ApiByteLib 字库底层接口
12 type ApiByteLib struct { 12 type ApiByteLib struct {
13 api.BaseServiceGateway 13 api.BaseServiceGateway
14 - baseUrL string  
15 } 14 }
16 15
17 func NewApiByteLib(host string) *ApiByteLib { 16 func NewApiByteLib(host string) *ApiByteLib {
@@ -22,6 +21,7 @@ func NewApiByteLib(host string) *ApiByteLib { @@ -22,6 +21,7 @@ func NewApiByteLib(host string) *ApiByteLib {
22 //log.Logger.Info(msg) 21 //log.Logger.Info(msg)
23 logs.Debug(msg) 22 logs.Debug(msg)
24 } 23 }
  24 + gt.ServiceName = "【字库核心】"
25 return &ApiByteLib{ 25 return &ApiByteLib{
26 BaseServiceGateway: gt, 26 BaseServiceGateway: gt,
27 } 27 }
@@ -29,7 +29,7 @@ func NewApiByteLib(host string) *ApiByteLib { @@ -29,7 +29,7 @@ func NewApiByteLib(host string) *ApiByteLib {
29 29
30 // 加载数据 30 // 加载数据
31 31
32 -func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { 32 +func (gateway ApiByteLib) LoadDataTable(param domain.ReqLoadDataTable) (*domain.DataLoadDataTable, error) {
33 url := gateway.Host() + "/checkout-tables/query" 33 url := gateway.Host() + "/checkout-tables/query"
34 method := "post" 34 method := "post"
35 var data DataCheckoutTables 35 var data DataCheckoutTables
@@ -44,7 +44,7 @@ func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytec @@ -44,7 +44,7 @@ func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytec
44 } 44 }
45 45
46 // EditTable 编辑表格 46 // EditTable 编辑表格
47 -func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) { 47 +func (gateway ApiByteLib) EditTable(param domain.ReqEditDataTable) (*domain.DataEditDataTable, error) {
48 url := gateway.Host() + "/checkout-tables/pre-proccess" 48 url := gateway.Host() + "/checkout-tables/pre-proccess"
49 method := "post" 49 method := "post"
50 var data DataCheckoutTables 50 var data DataCheckoutTables
@@ -55,13 +55,13 @@ func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore. @@ -55,13 +55,13 @@ func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.
55 } 55 }
56 56
57 response := ToDataLoadDataTable(data) 57 response := ToDataLoadDataTable(data)
58 - return &bytecore.DataEditDataTable{ 58 + return &domain.DataEditDataTable{
59 DataLoadDataTable: *response, 59 DataLoadDataTable: *response,
60 }, nil 60 }, nil
61 } 61 }
62 62
63 // SaveTable 保存校验文件 (文件地址) 63 // SaveTable 保存校验文件 (文件地址)
64 -func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) { 64 +func (gateway ApiByteLib) SaveTable(param domain.ReqSaveTable) (*domain.DataSaveTable, error) {
65 url := gateway.Host() + "/checkout-tables/save" 65 url := gateway.Host() + "/checkout-tables/save"
66 method := "post" 66 method := "post"
67 var data ResponseCheckoutTablesSave 67 var data ResponseCheckoutTablesSave
@@ -72,14 +72,14 @@ func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.Data @@ -72,14 +72,14 @@ func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.Data
72 if err != nil { 72 if err != nil {
73 return nil, err 73 return nil, err
74 } 74 }
75 - var response = &bytecore.DataSaveTable{ 75 + var response = &domain.DataSaveTable{
76 Url: data.CheckoutTableUrl, 76 Url: data.CheckoutTableUrl,
77 } 77 }
78 return response, nil 78 return response, nil
79 } 79 }
80 80
81 // GenerateTable 生成主表 81 // GenerateTable 生成主表
82 -func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { 82 +func (gateway ApiByteLib) GenerateTable(param domain.ReqGenerateTable) (*domain.DataGenerateTable, error) {
83 url := gateway.Host() + "/checkout-tables/generate-master-table" 83 url := gateway.Host() + "/checkout-tables/generate-master-table"
84 method := "post" 84 method := "post"
85 var data DataCheckoutTablesGenerateMasterTable 85 var data DataCheckoutTablesGenerateMasterTable
@@ -88,41 +88,83 @@ func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytec @@ -88,41 +88,83 @@ func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytec
88 if err != nil { 88 if err != nil {
89 return nil, err 89 return nil, err
90 } 90 }
91 - var response = bytecore.DataGenerateTable{ 91 + var response = domain.DataGenerateTable{
92 TableName: data.MasterTableName, 92 TableName: data.MasterTableName,
93 } 93 }
94 return &response, nil 94 return &response, nil
95 } 95 }
96 96
97 // CopyTable 表复制 97 // CopyTable 表复制
98 -func (gateway ApiByteLib) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) {  
99 - url := gateway.Host() + "/table/copy" 98 +func (gateway ApiByteLib) CopyTable(param domain.ReqCopyTable) (*domain.DataCopyTable, error) {
  99 + var url string
100 method := "post" 100 method := "post"
101 - var data bytecore.DataCopyTable  
102 - err := gateway.FastDoRequest(url, method, param, &data) 101 + var data TableAppendResponse
  102 + var request interface{}
  103 + var copyRequest = NewCopyTableRequest(param)
  104 + switch param.Table.TableType {
  105 + case domain.MainTable.ToString():
  106 + request = CopyMasterTableRequest{
  107 + MasterTableId: intToString(param.Table.TableId),
  108 + CopyTableRequest: copyRequest,
  109 + }
  110 + url = gateway.Host() + "/master-tables/copy"
  111 + case domain.SubTable.ToString():
  112 + request = CopyMasterTableRequest{
  113 + MasterTableId: intToString(param.Table.TableId),
  114 + CopyTableRequest: copyRequest,
  115 + }
  116 + url = gateway.Host() + "/master-tables/copy"
  117 + case domain.SideTable.ToString():
  118 + request = CopyReplicationTableRequest{
  119 + ReplicationTableId: intToString(param.Table.TableId),
  120 + CopyTableRequest: copyRequest,
  121 + }
  122 + url = gateway.Host() + "/replication-tables/copy"
  123 + }
  124 +
  125 + err := gateway.FastDoRequest(url, method, request, &data)
103 if err != nil { 126 if err != nil {
104 return nil, err 127 return nil, err
105 } 128 }
106 - return &data, nil 129 + return &domain.DataCopyTable{}, nil
107 } 130 }
108 131
109 // AppendData 追加数据 132 // AppendData 追加数据
110 -func (gateway ApiByteLib) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) {  
111 - url := gateway.Host() + "/table/append" 133 +func (gateway ApiByteLib) AppendData(param domain.ReqAppendData) (*domain.DataAppendData, error) {
  134 + var url string
112 method := "post" 135 method := "post"
113 - var data bytecore.DataAppendData  
114 - err := gateway.FastDoRequest(url, method, param, &data) 136 + var data TableAppendResponse
  137 + var request interface{}
  138 + var appendRequest = NewTableAppendRequest(param)
  139 + switch param.Table.TableType {
  140 + case domain.MainTable.ToString():
  141 + request = MasterTablesAppendRequest{
  142 + MasterTableId: intToString(param.Table.TableId),
  143 + TableAppendRequest: appendRequest,
  144 + }
  145 + url = gateway.Host() + "/master-tables/append"
  146 + case domain.SideTable.ToString():
  147 + request = ReplicationTablesAppendRequest{
  148 + ReplicationTableId: intToString(param.Table.TableId),
  149 + TableAppendRequest: appendRequest,
  150 + }
  151 + url = gateway.Host() + "/replication-tables/append"
  152 + }
  153 +
  154 + err := gateway.FastDoRequest(url, method, request, &data)
115 if err != nil { 155 if err != nil {
116 return nil, err 156 return nil, err
117 } 157 }
118 - return &data, nil 158 + return &domain.DataAppendData{
  159 + AppendCount: data.AppendCount,
  160 + }, nil
119 } 161 }
120 162
121 // DeleteTable 表删除 (主表、副表、分表) 163 // DeleteTable 表删除 (主表、副表、分表)
122 -func (gateway ApiByteLib) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) { 164 +func (gateway ApiByteLib) DeleteTable(param domain.ReqDeleteTable) (*domain.DataDeleteTable, error) {
123 url := gateway.Host() + "/table/delete" 165 url := gateway.Host() + "/table/delete"
124 method := "post" 166 method := "post"
125 - var data bytecore.DataDeleteTable 167 + var data domain.DataDeleteTable
126 err := gateway.FastDoRequest(url, method, param, &data) 168 err := gateway.FastDoRequest(url, method, param, &data)
127 if err != nil { 169 if err != nil {
128 return nil, err 170 return nil, err
@@ -131,10 +173,10 @@ func (gateway ApiByteLib) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore. @@ -131,10 +173,10 @@ func (gateway ApiByteLib) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.
131 } 173 }
132 174
133 // CancelFile 表删除 (主表、副表、分表) 175 // CancelFile 表删除 (主表、副表、分表)
134 -func (gateway ApiByteLib) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) { 176 +func (gateway ApiByteLib) CancelFile(param domain.ReqCancelFile) (*domain.DataCancelFile, error) {
135 url := gateway.Host() + "/table/cancel-file" 177 url := gateway.Host() + "/table/cancel-file"
136 method := "post" 178 method := "post"
137 - var data bytecore.DataCancelFile 179 + var data domain.DataCancelFile
138 err := gateway.FastDoRequest(url, method, param, &data) 180 err := gateway.FastDoRequest(url, method, param, &data)
139 if err != nil { 181 if err != nil {
140 return nil, err 182 return nil, err
@@ -143,14 +185,41 @@ func (gateway ApiByteLib) CancelFile(param bytecore.ReqCancelFile) (*bytecore.Da @@ -143,14 +185,41 @@ func (gateway ApiByteLib) CancelFile(param bytecore.ReqCancelFile) (*bytecore.Da
143 } 185 }
144 186
145 // 表拆分 187 // 表拆分
  188 +func (gateway ApiByteLib) SplitTable(param domain.ReqSplitTable) (*domain.DataSplitTable, error) {
  189 + var url string
  190 + method := "post"
  191 + var data TableAppendResponse
  192 + var request interface{}
  193 + var splitRequest = NewSplitTableRequest(param)
  194 + switch param.FromTable.TableType {
  195 + case domain.MainTable.ToString():
  196 + request = SplitMasterTableRequest{
  197 + MasterTableId: intToString(param.FromTable.TableId),
  198 + SplitTableRequest: splitRequest,
  199 + }
  200 + url = gateway.Host() + "/master-tables/split"
  201 + case domain.SideTable.ToString():
  202 + request = SplitReplicationTableRequest{
  203 + ReplicationTableId: intToString(param.FromTable.TableId),
  204 + SplitTableRequest: splitRequest,
  205 + }
  206 + url = gateway.Host() + "/replication-tables/split"
  207 + }
  208 +
  209 + err := gateway.FastDoRequest(url, method, request, &data)
  210 + if err != nil {
  211 + return nil, err
  212 + }
  213 + return &domain.DataSplitTable{}, nil
  214 +}
146 215
147 // 更新表结构(分表) 216 // 更新表结构(分表)
148 217
149 // EditTableData 编辑、添加、删除表数据(副表) 218 // EditTableData 编辑、添加、删除表数据(副表)
150 -func (gateway ApiByteLib) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) { 219 +func (gateway ApiByteLib) EditTableData(param domain.ReqEditTableData) (*domain.DataEditTableData, error) {
151 url := gateway.Host() + "/table/cancel-file" 220 url := gateway.Host() + "/table/cancel-file"
152 method := "post" 221 method := "post"
153 - var data bytecore.DataEditTableData 222 + var data domain.DataEditTableData
154 err := gateway.FastDoRequest(url, method, param, &data) 223 err := gateway.FastDoRequest(url, method, param, &data)
155 if err != nil { 224 if err != nil {
156 return nil, err 225 return nil, err
1 package bytelib 1 package bytelib
2 2
3 -import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" 3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  5 +)
4 6
5 type ApiByteLibService interface { 7 type ApiByteLibService interface {
6 - EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) 8 + EditTable(param domain.ReqEditDataTable) (*domain.DataEditDataTable, error)
7 } 9 }
@@ -3,14 +3,14 @@ package bytelib @@ -3,14 +3,14 @@ package bytelib
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
6 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" 6 + "strconv"
7 ) 7 )
8 8
9 type RequestCheckoutTablesQuery struct { 9 type RequestCheckoutTablesQuery struct {
10 OriginalTableId string `json:"originalTableId"` 10 OriginalTableId string `json:"originalTableId"`
11 IsFromOriginalTable bool `json:"isFromOriginalTable"` 11 IsFromOriginalTable bool `json:"isFromOriginalTable"`
12 TableFileUrl string `json:"tableFileUrl"` 12 TableFileUrl string `json:"tableFileUrl"`
13 - ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` 13 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
14 PageNumber int `json:"pageNumber"` 14 PageNumber int `json:"pageNumber"`
15 PageSize int `json:"pageSize"` 15 PageSize int `json:"pageSize"`
16 QueryParameters map[string]interface{} `json:"queryParameters"` 16 QueryParameters map[string]interface{} `json:"queryParameters"`
@@ -19,7 +19,7 @@ type RequestCheckoutTablesQuery struct { @@ -19,7 +19,7 @@ type RequestCheckoutTablesQuery struct {
19 19
20 type DataCheckoutTables struct { 20 type DataCheckoutTables struct {
21 OriginalTableId string `json:"originalTableId"` 21 OriginalTableId string `json:"originalTableId"`
22 - ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` 22 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
23 PageNumber int `json:"pageNumber"` 23 PageNumber int `json:"pageNumber"`
24 PageSize int `json:"pageSize"` 24 PageSize int `json:"pageSize"`
25 DataCount int `json:"dataCount"` 25 DataCount int `json:"dataCount"`
@@ -27,7 +27,7 @@ type DataCheckoutTables struct { @@ -27,7 +27,7 @@ type DataCheckoutTables struct {
27 AbnormalProccessIndexes [][]interface{} `json:"abnormalProccessIndexes"` 27 AbnormalProccessIndexes [][]interface{} `json:"abnormalProccessIndexes"`
28 } 28 }
29 29
30 -func NewRequestCheckoutTablesQuery(param bytecore.ReqLoadDataTable) RequestCheckoutTablesQuery { 30 +func NewRequestCheckoutTablesQuery(param domain.ReqLoadDataTable) RequestCheckoutTablesQuery {
31 return RequestCheckoutTablesQuery{ 31 return RequestCheckoutTablesQuery{
32 OriginalTableId: param.OriginalTableId, 32 OriginalTableId: param.OriginalTableId,
33 IsFromOriginalTable: param.IsFromOriginalTable, 33 IsFromOriginalTable: param.IsFromOriginalTable,
@@ -42,7 +42,7 @@ func NewRequestCheckoutTablesQuery(param bytecore.ReqLoadDataTable) RequestCheck @@ -42,7 +42,7 @@ func NewRequestCheckoutTablesQuery(param bytecore.ReqLoadDataTable) RequestCheck
42 42
43 type RequestCheckoutTablesPreProccess struct { 43 type RequestCheckoutTablesPreProccess struct {
44 OriginalTableId string `json:"originalTableId"` 44 OriginalTableId string `json:"originalTableId"`
45 - ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` 45 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
46 PreProccessColumnNames []string `json:"preProccessColumnNames"` 46 PreProccessColumnNames []string `json:"preProccessColumnNames"`
47 PreProccessActionName string `json:"preProccessActionName"` 47 PreProccessActionName string `json:"preProccessActionName"`
48 PreProccessActionParameterValues map[string]string `json:"preProccessActionParameterValues"` 48 PreProccessActionParameterValues map[string]string `json:"preProccessActionParameterValues"`
@@ -52,7 +52,7 @@ type RequestCheckoutTablesPreProccess struct { @@ -52,7 +52,7 @@ type RequestCheckoutTablesPreProccess struct {
52 SortParameters map[string]interface{} `json:"sortParameters"` 52 SortParameters map[string]interface{} `json:"sortParameters"`
53 } 53 }
54 54
55 -func NewRequestCheckoutTablesPreProccess(param bytecore.ReqEditDataTable) RequestCheckoutTablesPreProccess { 55 +func NewRequestCheckoutTablesPreProccess(param domain.ReqEditDataTable) RequestCheckoutTablesPreProccess {
56 req := RequestCheckoutTablesPreProccess{ 56 req := RequestCheckoutTablesPreProccess{
57 OriginalTableId: fmt.Sprintf("%v", param.FileId), 57 OriginalTableId: fmt.Sprintf("%v", param.FileId),
58 ColumnSchemas: FieldsToColumnSchemas(param.Fields), 58 ColumnSchemas: FieldsToColumnSchemas(param.Fields),
@@ -79,23 +79,23 @@ type ResponseCheckoutTablesSave struct { @@ -79,23 +79,23 @@ type ResponseCheckoutTablesSave struct {
79 CheckoutTableUrl string `json:"checkoutTableUrl"` 79 CheckoutTableUrl string `json:"checkoutTableUrl"`
80 } 80 }
81 81
82 -func FieldsToColumnSchemas(fields []*bytecore.Field) []bytecore.ColumnSchema {  
83 - result := make([]bytecore.ColumnSchema, 0) 82 +func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
  83 + result := make([]domain.ColumnSchema, 0)
84 84
85 for _, f := range fields { 85 for _, f := range fields {
86 - result = append(result, bytecore.ColumnSchema{ 86 + result = append(result, domain.ColumnSchema{
87 ColumnName: f.Name, 87 ColumnName: f.Name,
88 - ColumnType: f.Type, 88 + ColumnType: f.SQLType,
89 }) 89 })
90 } 90 }
91 return result 91 return result
92 } 92 }
93 93
94 -func DomainFieldsToColumnSchemas(fields []*domain.Field) []bytecore.ColumnSchema {  
95 - result := make([]bytecore.ColumnSchema, 0) 94 +func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
  95 + result := make([]domain.ColumnSchema, 0)
96 96
97 for _, f := range fields { 97 for _, f := range fields {
98 - result = append(result, bytecore.ColumnSchema{ 98 + result = append(result, domain.ColumnSchema{
99 ColumnName: f.Name, 99 ColumnName: f.Name,
100 ColumnType: f.SQLType, 100 ColumnType: f.SQLType,
101 }) 101 })
@@ -103,17 +103,18 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []bytecore.ColumnSchema @@ -103,17 +103,18 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []bytecore.ColumnSchema
103 return result 103 return result
104 } 104 }
105 105
106 -func ToDataLoadDataTable(data DataCheckoutTables) *bytecore.DataLoadDataTable {  
107 - response := &bytecore.DataLoadDataTable{ 106 +func ToDataLoadDataTable(data DataCheckoutTables) *domain.DataLoadDataTable {
  107 + response := &domain.DataLoadDataTable{
108 PageNumber: data.PageNumber, 108 PageNumber: data.PageNumber,
109 Data: data.ShowData, 109 Data: data.ShowData,
110 Total: data.DataCount, 110 Total: data.DataCount,
111 } 111 }
112 for i, f := range data.ColumnSchemas { 112 for i, f := range data.ColumnSchemas {
113 - response.Fields = append(response.Fields, &bytecore.Field{ 113 + response.Fields = append(response.Fields, &domain.Field{
114 Index: i + 1, 114 Index: i + 1,
115 Name: f.ColumnName, 115 Name: f.ColumnName,
116 - Type: f.ColumnType, 116 + SQLName: f.ColumnName,
  117 + SQLType: f.ColumnType,
117 }) 118 })
118 } 119 }
119 return response 120 return response
@@ -123,7 +124,7 @@ type ( @@ -123,7 +124,7 @@ type (
123 RequestCheckoutTablesGenerateMasterTable struct { 124 RequestCheckoutTablesGenerateMasterTable struct {
124 OriginalTableId string `json:"originalTableId"` 125 OriginalTableId string `json:"originalTableId"`
125 CheckoutTableFileUrl string `json:"checkoutTableFileUrl"` 126 CheckoutTableFileUrl string `json:"checkoutTableFileUrl"`
126 - ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` 127 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
127 MasterTableName string `json:"masterTableName"` 128 MasterTableName string `json:"masterTableName"`
128 FieldSchemas []FieldSchema `json:"fieldSchemas"` 129 FieldSchemas []FieldSchema `json:"fieldSchemas"`
129 KeyFieldEnNames []string `json:"keyFieldEnNames"` 130 KeyFieldEnNames []string `json:"keyFieldEnNames"`
@@ -140,7 +141,7 @@ type ( @@ -140,7 +141,7 @@ type (
140 } 141 }
141 ) 142 )
142 143
143 -func NewRequestCheckoutTablesGenerateMasterTable(param bytecore.ReqGenerateTable) RequestCheckoutTablesGenerateMasterTable { 144 +func NewRequestCheckoutTablesGenerateMasterTable(param domain.ReqGenerateTable) RequestCheckoutTablesGenerateMasterTable {
144 request := RequestCheckoutTablesGenerateMasterTable{ 145 request := RequestCheckoutTablesGenerateMasterTable{
145 OriginalTableId: fmt.Sprintf("%v", param.FileId), 146 OriginalTableId: fmt.Sprintf("%v", param.FileId),
146 CheckoutTableFileUrl: param.FileUrl, 147 CheckoutTableFileUrl: param.FileUrl,
@@ -160,7 +161,7 @@ func ToFieldSchemas(fields []*domain.Field) []FieldSchema { @@ -160,7 +161,7 @@ func ToFieldSchemas(fields []*domain.Field) []FieldSchema {
160 FieldEnName: f.SQLName, 161 FieldEnName: f.SQLName,
161 FieldType: f.SQLType, 162 FieldType: f.SQLType,
162 FieldDescription: f.Description, 163 FieldDescription: f.Description,
163 - IsAllowNull: false, 164 + IsAllowNull: true,
164 }) 165 })
165 } 166 }
166 return result 167 return result
@@ -173,3 +174,116 @@ func ToFieldSchemaEnNames(fields []*domain.Field) []string { @@ -173,3 +174,116 @@ func ToFieldSchemaEnNames(fields []*domain.Field) []string {
173 } 174 }
174 return result 175 return result
175 } 176 }
  177 +
  178 +type (
  179 + TableAppendRequest struct {
  180 + //MasterTableId string `json:"masterTableId"`
  181 + OriginalTableId string `json:"originalTableId"`
  182 + CheckoutTableFileUrl string `json:"checkoutTableFileUrl"`
  183 + DatabaseTableName string `json:"databaseTableName"`
  184 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
  185 + FieldSchemas []FieldSchema `json:"fieldSchemas"`
  186 + }
  187 +
  188 + MasterTablesAppendRequest struct {
  189 + MasterTableId string `json:"masterTableId"`
  190 + TableAppendRequest
  191 + }
  192 +
  193 + ReplicationTablesAppendRequest struct {
  194 + ReplicationTableId string `json:"replicationTableId"`
  195 + TableAppendRequest
  196 + }
  197 + TableAppendResponse struct {
  198 + AppendCount int `json:"appendCount"`
  199 + }
  200 +)
  201 +
  202 +func NewTableAppendRequest(param domain.ReqAppendData) TableAppendRequest {
  203 + return TableAppendRequest{
  204 + OriginalTableId: intToString(param.FileId),
  205 + CheckoutTableFileUrl: param.FileUrl,
  206 + DatabaseTableName: param.Table.SQLName,
  207 + ColumnSchemas: DomainFieldsToColumnSchemas(param.Table.DataFields),
  208 + FieldSchemas: ToFieldSchemas(param.Table.DataFields),
  209 + }
  210 +}
  211 +
  212 +func intToString(i int) string {
  213 + return strconv.Itoa(i)
  214 +}
  215 +
  216 +type (
  217 + CopyTableRequest struct {
  218 + DatabaseTableName string `json:"databaseTableName"`
  219 + /*
  220 + //"master" ->从主表复制 "split" ->从分表复制
  221 + //"replication" ->不用传,后面会去掉,现在线上的要先传下
  222 + */
  223 + DatabaseTableType string `json:"databaseTableType"`
  224 + ReplicationTableName string `json:"replicationTableName"`
  225 + FieldSchemas []FieldSchema `json:"fieldSchemas"`
  226 + KeyFieldEnNames []string `json:"keyFieldEnNames"`
  227 + }
  228 +
  229 + CopyTableResponse struct{}
  230 +
  231 + CopyMasterTableRequest struct {
  232 + MasterTableId string `json:"masterTableId"`
  233 + CopyTableRequest
  234 + }
  235 +
  236 + CopyReplicationTableRequest struct {
  237 + ReplicationTableId string `json:"replicationTableId"`
  238 + CopyTableRequest
  239 + }
  240 +)
  241 +
  242 +func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest {
  243 + var tableType string
  244 + switch param.Table.TableType {
  245 + case domain.MainTable.ToString():
  246 + tableType = "master"
  247 + case domain.SubTable.ToString():
  248 + tableType = "split"
  249 + case domain.SideTable.ToString():
  250 + tableType = "replication"
  251 + }
  252 + return CopyTableRequest{
  253 + DatabaseTableName: param.Table.SQLName,
  254 + DatabaseTableType: tableType,
  255 + ReplicationTableName: param.CopyToTable.SQLName,
  256 + FieldSchemas: ToFieldSchemas(param.CopyToTable.DataFields),
  257 + KeyFieldEnNames: []string{param.Table.PK.SQLName},
  258 + }
  259 +}
  260 +
  261 +type (
  262 + SplitTableRequest struct {
  263 + DatabaseTableName string `json:"databaseTableName"`
  264 + SplitTableName string `json:"splitTableName"`
  265 + DatabaseTableFieldSchemas []FieldSchema `json:"databaseTableFieldSchemas"`
  266 + SplitTableFieldSchemas []FieldSchema `json:"splitTableFieldSchemas"`
  267 + }
  268 +
  269 + SplitTableResponse struct{}
  270 +
  271 + SplitMasterTableRequest struct {
  272 + MasterTableId string `json:"masterTableId"`
  273 + SplitTableRequest
  274 + }
  275 +
  276 + SplitReplicationTableRequest struct {
  277 + ReplicationTableId string `json:"replicationTableId"`
  278 + SplitTableRequest
  279 + }
  280 +)
  281 +
  282 +func NewSplitTableRequest(param domain.ReqSplitTable) SplitTableRequest {
  283 + return SplitTableRequest{
  284 + DatabaseTableName: param.FromTable.SQLName,
  285 + SplitTableName: param.ToSubTable.SQLName,
  286 + DatabaseTableFieldSchemas: ToFieldSchemas(param.FromTable.DataFields),
  287 + SplitTableFieldSchemas: ToFieldSchemas(param.ToSubTable.DataFields),
  288 + }
  289 +}
@@ -7,17 +7,19 @@ var ( @@ -7,17 +7,19 @@ var (
7 ) 7 )
8 8
9 type ErrCodeMsg struct { 9 type ErrCodeMsg struct {
  10 + Service string
10 Code int 11 Code int
11 Msg string 12 Msg string
12 } 13 }
13 14
14 func (e ErrCodeMsg) Error() string { 15 func (e ErrCodeMsg) Error() string {
15 - return fmt.Sprintf("错误码:%v 错误信息:%v", e.Code, e.Msg) 16 + return fmt.Sprintf("%v 错误码:%v;错误信息:%v", e.Service, e.Code, e.Msg)
16 } 17 }
17 18
18 -func NewErrCodeMsg(code int, msg string) ErrCodeMsg { 19 +func NewErrCodeMsg(service string, code int, msg string) ErrCodeMsg {
19 return ErrCodeMsg{ 20 return ErrCodeMsg{
20 Code: code, 21 Code: code,
21 Msg: msg, 22 Msg: msg,
  23 + Service: service,
22 } 24 }
23 } 25 }
@@ -5,20 +5,19 @@ import ( @@ -5,20 +5,19 @@ import (
5 "github.com/beego/beego/v2/client/httplib" 5 "github.com/beego/beego/v2/client/httplib"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
8 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore"  
9 "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/api/bytelib"
10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
11 ) 10 )
12 11
13 type ByteCoreService struct { 12 type ByteCoreService struct {
14 - TempDataTable map[int]*bytecore.DataLoadDataTable 13 + TempDataTable map[int]*domain.DataLoadDataTable
15 } 14 }
16 15
17 -var ByteCore bytecore.ByteLibService = &WrapByteCoreService{} //&ByteCoreService{} 16 +var ByteCore domain.ByteLibService = &WrapByteCoreService{} //&ByteCoreService{}
18 17
19 -var _ bytecore.ByteLibService = (*ByteCoreService)(nil) 18 +var _ domain.ByteLibService = (*ByteCoreService)(nil)
20 19
21 -func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { 20 +func (ptr *ByteCoreService) LoadDataTable(param domain.ReqLoadDataTable) (*domain.DataLoadDataTable, error) {
22 if v, ok := ptr.load(param.FileId); ok { 21 if v, ok := ptr.load(param.FileId); ok {
23 return v.Filter(param.Where), nil 22 return v.Filter(param.Where), nil
24 } 23 }
@@ -39,89 +38,94 @@ func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*byt @@ -39,89 +38,94 @@ func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*byt
39 } 38 }
40 cols := importer.Reader().Header().Columns 39 cols := importer.Reader().Header().Columns
41 40
42 - var response = &bytecore.DataLoadDataTable{ 41 + var response = &domain.DataLoadDataTable{
43 FileId: param.FileId, 42 FileId: param.FileId,
44 Fields: columnToField(cols), 43 Fields: columnToField(cols),
45 Data: data, 44 Data: data,
46 Total: len(data), 45 Total: len(data),
47 PageNumber: param.PageNumber, 46 PageNumber: param.PageNumber,
48 - InValidCells: make([]bytecore.InValidCell, 0), 47 + InValidCells: make([]domain.InValidCell, 0),
49 } 48 }
50 49
51 ptr.save(param.FileId, response) 50 ptr.save(param.FileId, response)
52 return response.Filter(param.Where), nil 51 return response.Filter(param.Where), nil
53 } 52 }
54 53
55 -func (ptr *ByteCoreService) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) { 54 +func (ptr *ByteCoreService) EditTable(param domain.ReqEditDataTable) (*domain.DataEditDataTable, error) {
56 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 55 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
57 return apiByteLib.EditTable(param) 56 return apiByteLib.EditTable(param)
58 } 57 }
59 58
60 -func (ptr *ByteCoreService) save(fileId int, dataTable *bytecore.DataLoadDataTable) { 59 +func (ptr *ByteCoreService) save(fileId int, dataTable *domain.DataLoadDataTable) {
61 // Once 60 // Once
62 if ptr.TempDataTable == nil { 61 if ptr.TempDataTable == nil {
63 - ptr.TempDataTable = make(map[int]*bytecore.DataLoadDataTable) 62 + ptr.TempDataTable = make(map[int]*domain.DataLoadDataTable)
64 } 63 }
65 ptr.TempDataTable[fileId] = dataTable 64 ptr.TempDataTable[fileId] = dataTable
66 } 65 }
67 66
68 -func (ptr *ByteCoreService) load(fileId int) (*bytecore.DataLoadDataTable, bool) { 67 +func (ptr *ByteCoreService) load(fileId int) (*domain.DataLoadDataTable, bool) {
69 v, ok := ptr.TempDataTable[fileId] 68 v, ok := ptr.TempDataTable[fileId]
70 return v, ok 69 return v, ok
71 } 70 }
72 71
73 -func columnToField(cols []string) []*bytecore.Field {  
74 - var fields []*bytecore.Field 72 +func columnToField(cols []string) []*domain.Field {
  73 + var fields []*domain.Field
75 for i, col := range cols { 74 for i, col := range cols {
76 - fields = append(fields, &bytecore.Field{ 75 + fields = append(fields, &domain.Field{
77 Name: col, 76 Name: col,
78 Index: i + 1, 77 Index: i + 1,
79 - Type: "string", 78 + SQLType: domain.String.ToString(),
80 }) 79 })
81 } 80 }
82 return fields 81 return fields
83 } 82 }
84 83
85 -func (ptr *ByteCoreService) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) { 84 +func (ptr *ByteCoreService) SaveTable(param domain.ReqSaveTable) (*domain.DataSaveTable, error) {
86 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 85 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
87 return apiByteLib.SaveTable(param) 86 return apiByteLib.SaveTable(param)
88 } 87 }
89 88
90 -func (ptr *ByteCoreService) GenerateTable(ctx *domain.Context, param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { 89 +func (ptr *ByteCoreService) GenerateTable(ctx *domain.Context, param domain.ReqGenerateTable) (*domain.DataGenerateTable, error) {
91 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 90 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
92 return apiByteLib.GenerateTable(param) 91 return apiByteLib.GenerateTable(param)
93 } 92 }
94 93
95 -func (ptr *ByteCoreService) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) { 94 +func (ptr *ByteCoreService) CopyTable(param domain.ReqCopyTable) (*domain.DataCopyTable, error) {
96 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 95 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
97 return apiByteLib.CopyTable(param) 96 return apiByteLib.CopyTable(param)
98 } 97 }
99 98
100 -func (ptr *ByteCoreService) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) { 99 +func (ptr *ByteCoreService) AppendData(param domain.ReqAppendData) (*domain.DataAppendData, error) {
101 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 100 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
102 return apiByteLib.AppendData(param) 101 return apiByteLib.AppendData(param)
103 } 102 }
104 103
105 -func (ptr *ByteCoreService) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) { 104 +func (ptr *ByteCoreService) DeleteTable(param domain.ReqDeleteTable) (*domain.DataDeleteTable, error) {
106 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 105 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
107 return apiByteLib.DeleteTable(param) 106 return apiByteLib.DeleteTable(param)
108 } 107 }
109 108
110 -func (ptr *ByteCoreService) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) { 109 +func (ptr *ByteCoreService) CancelFile(param domain.ReqCancelFile) (*domain.DataCancelFile, error) {
111 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 110 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
112 return apiByteLib.CancelFile(param) 111 return apiByteLib.CancelFile(param)
113 } 112 }
114 113
115 -func (ptr *ByteCoreService) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) { 114 +func (ptr *ByteCoreService) EditTableData(param domain.ReqEditTableData) (*domain.DataEditTableData, error) {
116 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 115 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
117 return apiByteLib.EditTableData(param) 116 return apiByteLib.EditTableData(param)
118 } 117 }
119 118
  119 +func (ptr *ByteCoreService) SplitTable(param domain.ReqSplitTable) (*domain.DataSplitTable, error) {
  120 + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
  121 + return apiByteLib.SplitTable(param)
  122 +}
  123 +
120 ////////////// 124 //////////////
121 // 字库核心 125 // 字库核心
122 ////////////// 126 //////////////
123 127
124 -func CreateByteCoreService() (bytecore.ByteLibService, error) { 128 +func CreateByteCoreService() (domain.ByteLibService, error) {
125 return ByteCore, nil 129 return ByteCore, nil
126 } 130 }
127 131
@@ -129,11 +133,11 @@ type WrapByteCoreService struct { @@ -129,11 +133,11 @@ type WrapByteCoreService struct {
129 ByteCoreService 133 ByteCoreService
130 } 134 }
131 135
132 -func (ptr *WrapByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { 136 +func (ptr *WrapByteCoreService) LoadDataTable(param domain.ReqLoadDataTable) (*domain.DataLoadDataTable, error) {
133 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) 137 apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
134 return apiByteLib.LoadDataTable(param) 138 return apiByteLib.LoadDataTable(param)
135 } 139 }
136 140
137 -func (ptr *WrapByteCoreService) GenerateTable(ctx *domain.Context, param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {  
138 - return nil, nil  
139 -} 141 +//func (ptr *WrapByteCoreService) GenerateTable(ctx *domain.Context, param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {
  142 +// return nil, nil
  143 +//}
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "fmt" 4 "fmt"
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/domain/bytecore"  
8 "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"
9 ) 8 )
10 9
@@ -34,12 +33,12 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR @@ -34,12 +33,12 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR
34 } 33 }
35 // 通知底层进行文件表编辑 34 // 通知底层进行文件表编辑
36 35
37 - response, err := ByteCore.EditTable(bytecore.ReqEditDataTable{ 36 + response, err := ByteCore.EditTable(domain.ReqEditDataTable{
38 FileId: file.FileId, 37 FileId: file.FileId,
39 PageNumber: req.Where.PageNumber, 38 PageNumber: req.Where.PageNumber,
40 PageSize: req.Where.PageSize, 39 PageSize: req.Where.PageSize,
41 - Fields: bytecore.ToFields(req.Fields),  
42 - ProcessFields: bytecore.ToFields(req.ProcessFields), 40 + Fields: domain.ToFields(req.Fields),
  41 + ProcessFields: domain.ToFields(req.ProcessFields),
43 Action: req.Action, 42 Action: req.Action,
44 Params: req.Params, 43 Params: req.Params,
45 }) 44 })
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "github.com/linmadan/egglib-go/utils/tool_funs" 7 "github.com/linmadan/egglib-go/utils/tool_funs"
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/domain/bytecore"  
10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao"
11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" 11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
@@ -32,7 +31,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * @@ -32,7 +31,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *
32 // New Table 31 // New Table
33 table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) 32 table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx)
34 // 通知底层保存、进行回调 33 // 通知底层保存、进行回调
35 - response, _ := ByteCore.SaveTable(bytecore.ReqSaveTable{FileId: fileId}) 34 + response, _ := ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId})
36 if err != nil { 35 if err != nil {
37 return nil, err 36 return nil, err
38 } 37 }
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "fmt" 4 "fmt"
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/domain/bytecore"  
8 "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"
9 ) 8 )
10 9
@@ -44,7 +43,7 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i @@ -44,7 +43,7 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i
44 return nil, err 43 return nil, err
45 } 44 }
46 45
47 - if _, err = ByteCore.GenerateTable(ctx, bytecore.ReqGenerateTable{FileId: fileId, FileUrl: file.FileInfo.Url, Table: table}); err != nil { 46 + if _, err = ByteCore.GenerateTable(ctx, domain.ReqGenerateTable{FileId: fileId, FileUrl: file.FileInfo.Url, Table: mainTable}); err != nil {
48 return nil, err 47 return nil, err
49 } 48 }
50 return struct{}{}, nil 49 return struct{}{}, nil
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "fmt" 4 "fmt"
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/domain/bytecore"  
8 "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"
9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
10 ) 9 )
@@ -37,7 +36,7 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie @@ -37,7 +36,7 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie
37 36
38 // Load Data From Excel(python api) 37 // Load Data From Excel(python api)
39 byteCore, _ := CreateByteCoreService() 38 byteCore, _ := CreateByteCoreService()
40 - response, err := byteCore.LoadDataTable(bytecore.ReqLoadDataTable{ 39 + response, err := byteCore.LoadDataTable(domain.ReqLoadDataTable{
41 FileId: file.FileId, 40 FileId: file.FileId,
42 FileName: file.FileInfo.Name, 41 FileName: file.FileInfo.Name,
43 Url: file.FileInfo.Url, 42 Url: file.FileInfo.Url,
@@ -54,10 +53,31 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie @@ -54,10 +53,31 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie
54 if err != nil { 53 if err != nil {
55 return nil, err 54 return nil, err
56 } 55 }
57 - response.ObjectType = domain.ObjectFile  
58 - response.FileId = file.FileId  
59 - response.TableType = domain.ExcelTable.ToString()  
60 - return response, nil 56 + var responseDto = &FilePreviewDto{}
  57 + responseDto.Load(file.FileId, response)
  58 + return responseDto, nil
  59 +}
  60 +
  61 +type FilePreviewDto struct {
  62 + ObjectId int `json:"objectId"`
  63 + ObjectType string `json:"objectType"`
  64 + TableType string `json:"tableType"`
  65 + Fields []*domain.Field `json:"fields"`
  66 + Data interface{} `json:"grid"`
  67 + PageNumber int `json:"pageNumber"`
  68 + InValidCells []domain.InValidCell `json:"inValidCells"`
  69 +}
  70 +
  71 +func (d *FilePreviewDto) Load(fileId int, m *domain.DataLoadDataTable) {
  72 + d.ObjectId = fileId
  73 + d.ObjectType = domain.ObjectFile
  74 + d.TableType = domain.ExcelTable.ToString()
  75 + d.Fields = m.Fields
  76 +
  77 + mapData := domain.ToFieldData(m.Fields, m.Data, true)
  78 + d.Data = domain.GripData(mapData, int64(m.Total))
  79 + d.PageNumber = m.PageNumber
  80 + d.InValidCells = domain.NewInValidCells(m.Fields, mapData)
61 } 81 }
62 82
63 func (ptr *PreviewDataTableService) GetFileId() int { 83 func (ptr *PreviewDataTableService) GetFileId() int {
@@ -154,6 +154,7 @@ type SubTableEditLog struct { @@ -154,6 +154,7 @@ type SubTableEditLog struct {
154 154
155 func (l *SubTableEditLog) Content() string { 155 func (l *SubTableEditLog) Content() string {
156 var msg string 156 var msg string
  157 + msg = "分表编辑 "
157 msg += l.makeMsg("删除字段", l.Delete) 158 msg += l.makeMsg("删除字段", l.Delete)
158 msg += l.makeMsg("保留字段", l.Reserve) 159 msg += l.makeMsg("保留字段", l.Reserve)
159 msg += l.makeMsg("添加字段", l.Add) 160 msg += l.makeMsg("添加字段", l.Add)
@@ -45,7 +45,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl @@ -45,7 +45,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl
45 table.DataFields = dataFields 45 table.DataFields = dataFields
46 table.ManualFields = manualFields 46 table.ManualFields = manualFields
47 table.ParentId = parentTableId 47 table.ParentId = parentTableId
48 - table.SQLName = mainTable.SQLName // 主表名跟分表名相同 48 + //table.SQLName = mainTable.SQLName // 主表名跟分表名相同
49 reserves, deletes, adds := domain.FieldsChange(table.Fields(false), fields) 49 reserves, deletes, adds := domain.FieldsChange(table.Fields(false), fields)
50 50
51 if err = domain.ValidFields(fields); err != nil { 51 if err = domain.ValidFields(fields); err != nil {
@@ -71,5 +71,8 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl @@ -71,5 +71,8 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl
71 } 71 }
72 72
73 // 通知底层 73 // 通知底层
  74 + if _, err = ByteCore.SplitTable(domain.ReqSplitTable{FromTable: mainTable, ToSubTable: table}); err != nil {
  75 + return nil, err
  76 + }
74 return table, nil 77 return table, nil
75 } 78 }
@@ -59,7 +59,9 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int, @@ -59,7 +59,9 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int,
59 } 59 }
60 60
61 // 通知底层进行追加数据 61 // 通知底层进行追加数据
62 - 62 + if _, err = ByteCore.AppendData(domain.ReqAppendData{Table: table, FileId: fileId, FileUrl: file.FileInfo.Url}); err != nil {
  63 + return nil, err
  64 + }
63 return map[string]interface{}{ 65 return map[string]interface{}{
64 "result": fmt.Sprintf("源数据%v条,成功追加%v条;", excelTable.RowCount, excelTable.RowCount), 66 "result": fmt.Sprintf("源数据%v条,成功追加%v条;", excelTable.RowCount, excelTable.RowCount),
65 }, nil 67 }, nil
@@ -51,5 +51,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab @@ -51,5 +51,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
51 } 51 }
52 52
53 // 通知底层 53 // 通知底层
  54 + if _, err = ByteCore.CopyTable(domain.ReqCopyTable{Table: table, CopyToTable: sideTable}); err != nil {
  55 + return nil, err
  56 + }
54 return nil, nil 57 return nil, nil
55 } 58 }
@@ -68,11 +68,14 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl @@ -68,11 +68,14 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl
68 } 68 }
69 69
70 // 通知底层 70 // 通知底层
  71 + //if _, err = ByteCore.SplitTable(domain.ReqSplitTable{FromTable: mainTable, ToSubTable: table}); err != nil {
  72 + // return nil, err
  73 + //}
71 return struct{}{}, nil 74 return struct{}{}, nil
72 } 75 }
73 76
74 -func MappingFields(table *domain.Table, fields []*domain.Field) []*domain.Field {  
75 - tableFields := table.Fields(false) 77 +func MappingFields(mainTable *domain.Table, fields []*domain.Field) []*domain.Field {
  78 + tableFields := mainTable.Fields(false)
76 tableFieldsMap := (domain.Fields)(tableFields).ToMap() 79 tableFieldsMap := (domain.Fields)(tableFields).ToMap()
77 for i := range fields { 80 for i := range fields {
78 f := fields[i] 81 f := fields[i]
@@ -85,8 +88,8 @@ func MappingFields(table *domain.Table, fields []*domain.Field) []*domain.Field @@ -85,8 +88,8 @@ func MappingFields(table *domain.Table, fields []*domain.Field) []*domain.Field
85 fields[i].Flag = v.Flag 88 fields[i].Flag = v.Flag
86 } else { 89 } else {
87 if f.Flag == domain.ManualField && f.Index == 0 { 90 if f.Flag == domain.ManualField && f.Index == 0 {
88 - table.DataFieldIndex += 1  
89 - fields[i] = DataField(f.Name, f.SQLType, domain.ManualField, table.DataFieldIndex) 91 + mainTable.DataFieldIndex += 1
  92 + fields[i] = DataField(f.Name, f.SQLType, domain.ManualField, mainTable.DataFieldIndex)
90 fields[i].Description = f.Description 93 fields[i].Description = f.Description
91 } 94 }
92 } 95 }
@@ -165,7 +165,11 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 @@ -165,7 +165,11 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6
165 } 165 }
166 166
167 query.SetOffsetAndLimit(20) 167 query.SetOffsetAndLimit(20)
  168 + if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 {
  169 + query.SetOrderDirect("log_id", v.(string))
  170 + } else {
168 query.SetOrderDirect("log_id", "ASC") 171 query.SetOrderDirect("log_id", "ASC")
  172 + }
169 if count, err := query.SelectAndCount(); err != nil { 173 if count, err := query.SelectAndCount(); err != nil {
170 return 0, logs, err 174 return 0, logs, err
171 } else { 175 } else {
@@ -48,7 +48,7 @@ func init() { @@ -48,7 +48,7 @@ func init() {
48 } 48 }
49 49
50 web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) 50 web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
51 - web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) // CreateRequestLogFilter(true) 51 + web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(true)) // filters.CreateRequstLogFilter(Logger)
52 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) 52 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false))
53 } 53 }
54 54
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/log/command" 5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/log/command"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/log/query" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/log/query"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/log/service" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/log/service"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
8 ) 9 )
9 10
10 type LogController struct { 11 type LogController struct {
@@ -68,6 +69,17 @@ func (controller *LogController) SearchLog() { @@ -68,6 +69,17 @@ func (controller *LogController) SearchLog() {
68 ResponseGrid(controller.BaseController, total, data, err) 69 ResponseGrid(controller.BaseController, total, data, err)
69 } 70 }
70 71
  72 +func (controller *LogController) TableOperateLog() {
  73 + logService := service.NewLogService(nil)
  74 + cmd := &command.SearchLogCommand{}
  75 + controller.Unmarshal(cmd)
  76 + cmd.LogType = domain.CommonLog.ToString()
  77 + cmd.SortByLogId = "DESC"
  78 + cmd.Context = ParseContext(controller.BaseController)
  79 + total, data, err := logService.SearchLog(cmd)
  80 + ResponseGrid(controller.BaseController, total, data, err)
  81 +}
  82 +
71 func (controller *LogController) VerifiedStepLog() { 83 func (controller *LogController) VerifiedStepLog() {
72 logService := service.NewLogService(nil) 84 logService := service.NewLogService(nil)
73 cmd := &command.SearchLogCommand{} 85 cmd := &command.SearchLogCommand{}
@@ -12,5 +12,6 @@ func init() { @@ -12,5 +12,6 @@ func init() {
12 web.Router("/data/logs/:logId", &controllers.LogController{}, "Delete:RemoveLog") 12 web.Router("/data/logs/:logId", &controllers.LogController{}, "Delete:RemoveLog")
13 web.Router("/data/logs/", &controllers.LogController{}, "Get:ListLog") 13 web.Router("/data/logs/", &controllers.LogController{}, "Get:ListLog")
14 web.Router("/data/logs/search", &controllers.LogController{}, "Post:SearchLog") 14 web.Router("/data/logs/search", &controllers.LogController{}, "Post:SearchLog")
  15 + web.Router("/data/logs/table-operate-Log", &controllers.LogController{}, "Post:TableOperateLog")
15 web.Router("/data/logs/verified-step-Log", &controllers.LogController{}, "Post:VerifiedStepLog") 16 web.Router("/data/logs/verified-step-Log", &controllers.LogController{}, "Post:VerifiedStepLog")
16 } 17 }