作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !2
正在显示 43 个修改的文件 包含 795 行增加294 行删除
@@ -39,9 +39,7 @@ spec: @@ -39,9 +39,7 @@ spec:
39 operator: In 39 operator: In
40 values: 40 values:
41 - cn-hangzhou.i-bp1djh1xn7taumbue1ze 41 - cn-hangzhou.i-bp1djh1xn7taumbue1ze
42 - - cn-hangzhou.i-bp1djh1xn7taumbue1zd  
43 - - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb  
44 - - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy 42 +
45 containers: 43 containers:
46 - name: character-library-metadata-bastion 44 - name: character-library-metadata-bastion
47 image: 192.168.0.243:5000/mmm/character-library-metadata-bastion:dev 45 image: 192.168.0.243:5000/mmm/character-library-metadata-bastion:dev
@@ -42,7 +42,7 @@ func (querySetService *QuerySetService) CalculateSetPreview(ctx *domain.Context, @@ -42,7 +42,7 @@ func (querySetService *QuerySetService) CalculateSetPreview(ctx *domain.Context,
42 response.ObjectType = querySet.Type 42 response.ObjectType = querySet.Type
43 response.Name = querySet.Name 43 response.Name = querySet.Name
44 response.Fields = dataTable.Fields 44 response.Fields = dataTable.Fields
45 - response.Data = domain.GripData(domain.ToFieldData(dataTable.Fields, dataTable.Data, false), int64(len(dataTable.Data))) 45 + response.Data = domain.GripData(domain.ToFieldData(dataTable.Fields, dataTable.Data, false, true), int64(len(dataTable.Data)))
46 46
47 if err := transactionContext.CommitTransaction(); err != nil { 47 if err := transactionContext.CommitTransaction(); err != nil {
48 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 48 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -494,7 +494,7 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C @@ -494,7 +494,7 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C
494 var result = make([]itemValue, 0) 494 var result = make([]itemValue, 0)
495 result = append(result, itemValue{ 495 result = append(result, itemValue{
496 Name: querySet.Name, 496 Name: querySet.Name,
497 - Value: value, 497 + Value: domain.RoundValue(value),
498 }) 498 })
499 499
500 for _, f := range q.Formula.TableFields { 500 for _, f := range q.Formula.TableFields {
@@ -511,7 +511,7 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C @@ -511,7 +511,7 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C
511 }) 511 })
512 result = append(result, itemValue{ 512 result = append(result, itemValue{
513 Name: f.FieldName, 513 Name: f.FieldName,
514 - Value: value, 514 + Value: domain.RoundValue(value),
515 }) 515 })
516 } 516 }
517 return querySet, result 517 return querySet, result
@@ -20,7 +20,10 @@ type TablePreviewCommand struct { @@ -20,7 +20,10 @@ type TablePreviewCommand struct {
20 } 20 }
21 21
22 func (cmd *TablePreviewCommand) Valid(validation *validation.Validation) { 22 func (cmd *TablePreviewCommand) Valid(validation *validation.Validation) {
23 - 23 + if cmd.UseCache && cmd.PageSize==0{
  24 + cmd.PageNumber = 1
  25 + cmd.PageSize = 10000 //默认缓存前10000条
  26 + }
24 if cmd.PageSize > 0 { 27 if cmd.PageSize > 0 {
25 cmd.Where.PageNumber = cmd.PageNumber 28 cmd.Where.PageNumber = cmd.PageNumber
26 cmd.Where.PageSize = cmd.PageSize 29 cmd.Where.PageSize = cmd.PageSize
@@ -71,7 +71,10 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * @@ -71,7 +71,10 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
71 if table.TableType == domain.SubTable.ToString() && field.Flag == domain.ManualField { 71 if table.TableType == domain.SubTable.ToString() && field.Flag == domain.ManualField {
72 return empty, nil 72 return empty, nil
73 } 73 }
74 - 74 + match := cmd.Match
  75 + if !domain.SQLType(field.SQLType).IsString() {
  76 + match = ""
  77 + }
75 options := &starrocks.QueryOptions{ 78 options := &starrocks.QueryOptions{
76 Table: table, 79 Table: table,
77 TableName: table.SQLName, 80 TableName: table.SQLName,
@@ -80,7 +83,7 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * @@ -80,7 +83,7 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
80 { 83 {
81 Condition: domain.Condition{ 84 Condition: domain.Condition{
82 Field: field, 85 Field: field,
83 - Like: cmd.Match, 86 + Like: match,
84 Order: "ASC", 87 Order: "ASC",
85 }, 88 },
86 Distinct: true, 89 Distinct: true,
@@ -107,8 +110,9 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * @@ -107,8 +110,9 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
107 if err := transactionContext.CommitTransaction(); err != nil { 110 if err := transactionContext.CommitTransaction(); err != nil {
108 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 111 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
109 } 112 }
  113 + values := dataTable.OptionalValue(cmd.Match, field.SQLType)
110 return map[string]interface{}{ 114 return map[string]interface{}{
111 - "values": dataTable.OptionalValue(),  
112 - "total": dataTable.Total, 115 + "values": values,
  116 + "total": len(values),
113 }, nil 117 }, nil
114 } 118 }
@@ -11,6 +11,9 @@ import ( @@ -11,6 +11,9 @@ import (
11 ) 11 )
12 12
13 func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command.TablePreviewCommand) (interface{}, error) { 13 func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command.TablePreviewCommand) (interface{}, error) {
  14 + if cmd.TableId == 0 {
  15 + return &dto.TablePreviewDto{}, nil
  16 + }
14 if err := cmd.ValidateCommand(); err != nil { 17 if err := cmd.ValidateCommand(); err != nil {
15 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 18 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
16 } 19 }
@@ -68,6 +71,10 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command @@ -68,6 +71,10 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command
68 if err != nil { 71 if err != nil {
69 return nil, factory.FastError(err) 72 return nil, factory.FastError(err)
70 } 73 }
  74 + // 计算项只返回第一个值
  75 + // if table.TableType==domain.CalculateItem.ToString() && dataTable!=nil && len(dataTable.Data)>0{
  76 + // dataTable.Data = dataTable.Data[:1]
  77 + // }
71 response.Load(table, dataTable, domain.ObjectMetaTable) 78 response.Load(table, dataTable, domain.ObjectMetaTable)
72 } 79 }
73 } 80 }
@@ -28,9 +28,6 @@ type ( @@ -28,9 +28,6 @@ type (
28 IsFromOriginalTable bool `json:"isFromOriginalTable"` 28 IsFromOriginalTable bool `json:"isFromOriginalTable"`
29 TableFileUrl string `json:"tableFileUrl"` 29 TableFileUrl string `json:"tableFileUrl"`
30 ColumnSchemas []ColumnSchema `json:"columnSchemas"` 30 ColumnSchemas []ColumnSchema `json:"columnSchemas"`
31 - //PageNumber int `json:"pageNumber"`  
32 - //PageSize int `json:"pageSize"`  
33 - //QueryParameters []QueryParameter `json:"queryParameters"`  
34 SortParameters map[string]interface{} `json:"sortParameters"` 31 SortParameters map[string]interface{} `json:"sortParameters"`
35 } 32 }
36 33
@@ -50,14 +47,6 @@ type ( @@ -50,14 +47,6 @@ type (
50 ColumnContents []string `json:"columnContents"` 47 ColumnContents []string `json:"columnContents"`
51 IsContainContent bool `json:"isContainContent"` 48 IsContainContent bool `json:"isContainContent"`
52 } 49 }
53 - //Field struct {  
54 - // // 索引序号  
55 - // Index int `json:"index"`  
56 - // // 名称  
57 - // Name string `json:"name"`  
58 - // // 对应数据库类型  
59 - // Type string `json:"sqlType"`  
60 - //}  
61 50
62 InValidCell struct { 51 InValidCell struct {
63 Col string `json:"col"` 52 Col string `json:"col"`
@@ -157,11 +146,6 @@ type ( @@ -157,11 +146,6 @@ type (
157 MainTable *Table 146 MainTable *Table
158 Table *Table 147 Table *Table
159 CopyToTable *Table 148 CopyToTable *Table
160 -  
161 - // 数据列  
162 - //DataFields []*Field `json:"dataFields"`  
163 - // 手动添加的列  
164 - //ManualFields []*Field `json:"manualFields"`  
165 } 149 }
166 150
167 DataCopyTable struct { 151 DataCopyTable struct {
@@ -249,32 +233,13 @@ func ToFields(fields []*Field) []*Field { @@ -249,32 +233,13 @@ func ToFields(fields []*Field) []*Field {
249 return result 233 return result
250 } 234 }
251 235
252 -//func ToFieldData(fields []*Field, data [][]string, byteName bool) []map[string]string {  
253 -// var result = make([]map[string]string, 0)  
254 -// var key string  
255 -// for _, d := range data {  
256 -// var item = make(map[string]string)  
257 -// for j, f := range fields {  
258 -// key = f.Name  
259 -// if byteName {  
260 -// key = f.Name  
261 -// }  
262 -// if len(d) >= j {  
263 -// item[key] = d[j]  
264 -// } else {  
265 -// item[key] = ""  
266 -// }  
267 -// }  
268 -// result = append(result, item)  
269 -// }  
270 -// return result  
271 -//}  
272 -  
273 type ( 236 type (
274 ReqFormulasGenerate struct { 237 ReqFormulasGenerate struct {
275 QuerySet *QuerySet 238 QuerySet *QuerySet
276 Table *Table 239 Table *Table
277 QueryComponents []*QueryComponent 240 QueryComponents []*QueryComponent
  241 + QuerySetService interface{}
  242 + Context interface{}
278 } 243 }
279 244
280 DataFormulasGenerate struct { 245 DataFormulasGenerate struct {
@@ -9,7 +9,7 @@ type Context struct { @@ -9,7 +9,7 @@ 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 - 12 + // 附加数据
13 data map[string]interface{} 13 data map[string]interface{}
14 } 14 }
15 15
1 package domain 1 package domain
2 2
  3 +import "strings"
  4 +
3 type DataTable struct { 5 type DataTable struct {
4 Fields []*Field `json:"fields"` 6 Fields []*Field `json:"fields"`
5 Data [][]string `json:"data"` 7 Data [][]string `json:"data"`
@@ -51,19 +53,28 @@ type Condition struct { @@ -51,19 +53,28 @@ type Condition struct {
51 Order string `json:"order"` 53 Order string `json:"order"`
52 } 54 }
53 55
54 -func (t *DataTable) OptionalValue() []string {  
55 - //set := make(map[string]string) 56 +func (t *DataTable) OptionalValue(args ...string) []string {
56 var values = make([]string, 0) 57 var values = make([]string, 0)
  58 + match := ""
  59 + filedType := ""
  60 + if len(args) > 0 {
  61 + match = args[0]
  62 + }
  63 + if len(args) > 1 {
  64 + filedType = args[1]
  65 + }
57 if len(t.Data) > 0 && len(t.Data[0]) == 1 { 66 if len(t.Data) > 0 && len(t.Data[0]) == 1 {
58 for i := range t.Data { 67 for i := range t.Data {
59 if len(t.Data[i]) == 0 { 68 if len(t.Data[i]) == 0 {
60 continue 69 continue
61 } 70 }
62 - //if _, ok := set[t.Data[i][0]]; ok {  
63 - // continue  
64 - //} else {  
65 - // set[t.Data[i][0]] = ""  
66 - //} 71 + if len(match) > 0 && !strings.Contains(t.Data[i][0], match) {
  72 + continue
  73 + }
  74 + if filedType == Float.ToString() {
  75 + values = append(values, RoundFieldValue(&Field{SQLType: filedType}, t.Data[i][0]))
  76 + continue
  77 + }
67 values = append(values, t.Data[i][0]) 78 values = append(values, t.Data[i][0])
68 } 79 }
69 } 80 }
@@ -85,7 +96,7 @@ func (t *DataTable) Values(f *Field) []string { @@ -85,7 +96,7 @@ func (t *DataTable) Values(f *Field) []string {
85 for i := range t.Data { 96 for i := range t.Data {
86 for j := range t.Data[i] { 97 for j := range t.Data[i] {
87 if j == index { 98 if j == index {
88 - res = append(res, t.Data[i][j]) 99 + res = append(res, RoundFieldValue(f, t.Data[i][j]))
89 break 100 break
90 } 101 }
91 } 102 }
@@ -125,6 +125,8 @@ var ( @@ -125,6 +125,8 @@ var (
125 Int SQLType = "INT" 125 Int SQLType = "INT"
126 BigInt SQLType = "BIGINT" 126 BigInt SQLType = "BIGINT"
127 Float SQLType = "FLOAT" 127 Float SQLType = "FLOAT"
  128 + DECIMALV2 SQLType = "DECIMAL(20,15)" //"DECIMALV2"
  129 + DECIMAL279 SQLType = "DECIMAL(20,15)"
128 Date SQLType = "DATE" 130 Date SQLType = "DATE"
129 Datetime SQLType = "DATETIME" 131 Datetime SQLType = "DATETIME"
130 ) 132 )
@@ -134,6 +136,7 @@ var SQLTypeMap = map[string]string{ @@ -134,6 +136,7 @@ var SQLTypeMap = map[string]string{
134 Int.ToString(): "整数", 136 Int.ToString(): "整数",
135 BigInt.ToString(): "整数", 137 BigInt.ToString(): "整数",
136 Float.ToString(): "小数", 138 Float.ToString(): "小数",
  139 + DECIMALV2.ToString(): "小数",
137 Date.ToString(): "日期", 140 Date.ToString(): "日期",
138 Datetime.ToString(): "日期时间", 141 Datetime.ToString(): "日期时间",
139 } 142 }
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/utils/xtime" 5 "github.com/linmadan/egglib-go/utils/xtime"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
  7 + "strconv"
7 "strings" 8 "strings"
8 ) 9 )
9 10
@@ -185,6 +186,16 @@ func ValueToType(value string, sqlType string) (interface{}, error) { @@ -185,6 +186,16 @@ func ValueToType(value string, sqlType string) (interface{}, error) {
185 if err != nil { 186 if err != nil {
186 err = fmt.Errorf("[%v]不是有效的浮点数类型", value) 187 err = fmt.Errorf("[%v]不是有效的浮点数类型", value)
187 } 188 }
  189 + case DECIMALV2.ToString():
  190 + toTypeVal, err = numberString.Float64()
  191 + if err != nil {
  192 + err = fmt.Errorf("[%v]不是有效的浮点数类型", value)
  193 + }
  194 + case DECIMAL279.ToString():
  195 + toTypeVal, err = numberString.Float64()
  196 + if err != nil {
  197 + err = fmt.Errorf("[%v]不是有效的浮点数类型", value)
  198 + }
188 case Date.ToString(): 199 case Date.ToString():
189 toTypeVal, err = xtime.Parse(value) 200 toTypeVal, err = xtime.Parse(value)
190 if err != nil { 201 if err != nil {
@@ -203,9 +214,13 @@ func ValueToType(value string, sqlType string) (interface{}, error) { @@ -203,9 +214,13 @@ func ValueToType(value string, sqlType string) (interface{}, error) {
203 return toTypeVal, err 214 return toTypeVal, err
204 } 215 }
205 216
206 -func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]string { 217 +func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool) []map[string]string {
207 var result = make([]map[string]string, 0) 218 var result = make([]map[string]string, 0)
208 var key string 219 var key string
  220 + var ignoreEmptyString = false
  221 + if len(configs) > 0 {
  222 + ignoreEmptyString = configs[0]
  223 + }
209 for _, d := range data { 224 for _, d := range data {
210 var item = make(map[string]string) 225 var item = make(map[string]string)
211 for j, f := range fields { 226 for j, f := range fields {
@@ -213,8 +228,12 @@ func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]str @@ -213,8 +228,12 @@ func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]str
213 if byName { 228 if byName {
214 key = f.Name 229 key = f.Name
215 } 230 }
  231 + if ignoreEmptyString && len(d[j]) == 0 {
  232 + continue
  233 + }
216 if len(d) >= j { 234 if len(d) >= j {
217 - item[key] = d[j] 235 + // 处理精度问题
  236 + item[key] = RoundFieldValue(f, d[j]) //d[j]
218 } else { 237 } else {
219 item[key] = "" 238 item[key] = ""
220 } 239 }
@@ -224,6 +243,35 @@ func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]str @@ -224,6 +243,35 @@ func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]str
224 return result 243 return result
225 } 244 }
226 245
  246 +// RoundFieldValue 字段值精度处理
  247 +func RoundFieldValue(f *Field, v string) string {
  248 + if f.SQLType == Float.ToString() {
  249 + fv, err := strconv.ParseFloat(v, 64)
  250 + if err != nil {
  251 + return v
  252 + }
  253 + return fmt.Sprintf("%v", fv)
  254 + }
  255 + return v
  256 + //if f.SQLType != DECIMALV2.ToString() {
  257 + // return v
  258 + //}
  259 + //fv, err := strconv.ParseFloat(v, 64)
  260 + //if err != nil {
  261 + // return v
  262 + //}
  263 + //fv = utils.Round(fv, 6)
  264 + //return fmt.Sprintf("%v", fv)
  265 +}
  266 +
  267 +func RoundValue(v string) string {
  268 + fv, err := strconv.ParseFloat(v, 64)
  269 + if err != nil {
  270 + return v
  271 + }
  272 + return fmt.Sprintf("%v", fv)
  273 +}
  274 +
227 func GripData(data []map[string]string, total int64) map[string]interface{} { 275 func GripData(data []map[string]string, total int64) map[string]interface{} {
228 if len(data) == 0 { 276 if len(data) == 0 {
229 data = make([]map[string]string, 0) 277 data = make([]map[string]string, 0)
@@ -250,6 +298,10 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} { @@ -250,6 +298,10 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} {
250 output := make([]interface{}, len(input)) 298 output := make([]interface{}, len(input))
251 for i, v := range input { 299 for i, v := range input {
252 if i < len(fields) { 300 if i < len(fields) {
  301 + // 处理精度问题
  302 + if fields[i].SQLType == Float.ToString() {
  303 + v = RoundFieldValue(fields[i], v)
  304 + }
253 convValue, err := ValueToType(v, fields[i].SQLType) 305 convValue, err := ValueToType(v, fields[i].SQLType)
254 if err == nil { 306 if err == nil {
255 output[i] = convValue 307 output[i] = convValue
  1 +package domain
  2 +
  3 +import (
  4 + "github.com/stretchr/testify/assert"
  5 + "testing"
  6 +)
  7 +
  8 +func TestRoundFieldValue(t *testing.T) {
  9 + floatFiled := &Field{
  10 + SQLType: Float.ToString(),
  11 + }
  12 + inputs := []struct {
  13 + v string
  14 + f *Field
  15 + want string
  16 + }{
  17 + {
  18 + v: "0.12359999999999999",
  19 + f: floatFiled,
  20 + want: "0.1236",
  21 + },
  22 + {
  23 + v: "0.12360000000000001",
  24 + f: floatFiled,
  25 + want: "0.1236",
  26 + },
  27 + {
  28 + v: "0.12359999999999995",
  29 + f: floatFiled,
  30 + want: "0.1236",
  31 + },
  32 + }
  33 + for _, input := range inputs {
  34 + got := RoundFieldValue(input.f, input.v)
  35 + assert.Equal(t, input.want, got)
  36 + }
  37 +}
1 package domain 1 package domain
2 2
3 import ( 3 import (
  4 + "path"
4 "path/filepath" 5 "path/filepath"
5 - "strings"  
6 "time" 6 "time"
7 ) 7 )
8 8
@@ -16,8 +16,6 @@ type File struct { @@ -16,8 +16,6 @@ type File struct {
16 FileInfo *FileInfo `json:"fileInfo"` 16 FileInfo *FileInfo `json:"fileInfo"`
17 // 源文件Id(FileType为TemporaryFile或VerifiedFile时有值) 17 // 源文件Id(FileType为TemporaryFile或VerifiedFile时有值)
18 SourceFileId int `json:"sourceFileId"` 18 SourceFileId int `json:"sourceFileId"`
19 - // 操作人  
20 - // Operator string `json:"operator"`  
21 // 创建时间 19 // 创建时间
22 CreatedAt time.Time `json:"createdAt"` 20 CreatedAt time.Time `json:"createdAt"`
23 // 更新时间 21 // 更新时间
@@ -60,8 +58,13 @@ func (file *File) Update(data map[string]interface{}) error { @@ -60,8 +58,13 @@ func (file *File) Update(data map[string]interface{}) error {
60 } 58 }
61 59
62 func FileName(fileName string) string { 60 func FileName(fileName string) string {
  61 + if len(fileName) == 0 {
  62 + return ""
  63 + }
63 base := filepath.Base(fileName) 64 base := filepath.Base(fileName)
64 - return strings.Split(base, ".")[0] 65 + suffix := path.Ext(fileName)
  66 + prefix := base[0 : len(base)-len(suffix)]
  67 + return prefix
65 } 68 }
66 69
67 func (file *File) CopyTo(fileType FileType, ctx *Context) *File { 70 func (file *File) CopyTo(fileType FileType, ctx *Context) *File {
@@ -78,7 +81,6 @@ func (file *File) CopyTo(fileType FileType, ctx *Context) *File { @@ -78,7 +81,6 @@ func (file *File) CopyTo(fileType FileType, ctx *Context) *File {
78 CreatedAt: time.Now(), 81 CreatedAt: time.Now(),
79 UpdatedAt: time.Now(), 82 UpdatedAt: time.Now(),
80 SourceFileId: file.FileId, 83 SourceFileId: file.FileId,
81 - //Operator: file.Operator,  
82 Context: ctx, 84 Context: ctx,
83 } 85 }
84 return t 86 return t
@@ -8,8 +8,6 @@ type FileInfo struct { @@ -8,8 +8,6 @@ type FileInfo struct {
8 Url string `json:"url"` 8 Url string `json:"url"`
9 // 文件大小 9 // 文件大小
10 FileSize int `json:"fileSize"` 10 FileSize int `json:"fileSize"`
11 - // 文件编号,以固定字符“F”+4位年+2位月+2位日+三位流水,每天编号从001开始  
12 - // FileCode string `json:"fileCode"`  
13 // 后缀扩展 11 // 后缀扩展
14 Ext string `json:"ext"` 12 Ext string `json:"ext"`
15 // 记录数 13 // 记录数
  1 +package domain
  2 +
  3 +import (
  4 + "github.com/stretchr/testify/assert"
  5 + "testing"
  6 +)
  7 +
  8 +func TestFileName(t *testing.T) {
  9 + inputs := []struct {
  10 + input string
  11 + want string
  12 + }{
  13 + {
  14 + input: "device/sdk/CMakeLists.txt",
  15 + want: "CMakeLists",
  16 + },
  17 + {
  18 + input: "",
  19 + want: "",
  20 + },
  21 + {
  22 + input: "CMakeLists.txt",
  23 + want: "CMakeLists",
  24 + },
  25 + {
  26 + input: "d:\\CMakeLists.txt",
  27 + want: "CMakeLists",
  28 + },
  29 + }
  30 +
  31 + for _, input := range inputs {
  32 + got := FileName(input.input)
  33 + assert.Equal(t, input.want, got)
  34 + }
  35 +}
@@ -45,6 +45,5 @@ func (log *Log) Identify() interface{} { @@ -45,6 +45,5 @@ func (log *Log) Identify() interface{} {
45 } 45 }
46 46
47 func (log *Log) Update(data map[string]interface{}) error { 47 func (log *Log) Update(data map[string]interface{}) error {
48 -  
49 return nil 48 return nil
50 } 49 }
@@ -2,7 +2,7 @@ package domain @@ -2,7 +2,7 @@ package domain
2 2
3 import "time" 3 import "time"
4 4
5 -// 匹配规则配置 5 +// MappingRule 匹配规则配置
6 type MappingRule struct { 6 type MappingRule struct {
7 // 匹配规则ID 7 // 匹配规则ID
8 MappingRuleId int `json:"mappingRuleId"` 8 MappingRuleId int `json:"mappingRuleId"`
@@ -53,7 +53,6 @@ type MappingField struct { @@ -53,7 +53,6 @@ type MappingField struct {
53 53
54 func NewMappingFields(all []*Field, some []*Field) []*MappingField { 54 func NewMappingFields(all []*Field, some []*Field) []*MappingField {
55 var result []*MappingField 55 var result []*MappingField
56 - //allMap :=(Fields)(all).ToMap()  
57 someMap := (Fields)(some).ToMap() 56 someMap := (Fields)(some).ToMap()
58 for _, f := range all { 57 for _, f := range all {
59 item := &MappingField{ 58 item := &MappingField{
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 "time" 8 "time"
9 ) 9 )
10 10
11 -// 查询集合 11 +// QuerySet 查询集合
12 type QuerySet struct { 12 type QuerySet struct {
13 // 查询集合ID 13 // 查询集合ID
14 QuerySetId int `json:"querySetId"` 14 QuerySetId int `json:"querySetId"`
@@ -76,7 +76,6 @@ type SelectExpr struct { // 查询表达式 @@ -76,7 +76,6 @@ type SelectExpr struct { // 查询表达式
76 FieldLeft FieldExpr `json:"fieldLeft"` 76 FieldLeft FieldExpr `json:"fieldLeft"`
77 FieldRight FieldExpr `json:"fieldRight"` // has value when type is equal to 1 77 FieldRight FieldExpr `json:"fieldRight"` // has value when type is equal to 1
78 Type string `json:"type"` // 1.拆分 2.拆方赋值 3.正常赋值 78 Type string `json:"type"` // 1.拆分 2.拆方赋值 3.正常赋值
79 - //SubGroup []SelectExpr `json:"subGroup,omitempty"`  
80 } 79 }
81 80
82 func (s SelectExpr) Equal(compare SelectExpr) bool { 81 func (s SelectExpr) Equal(compare SelectExpr) bool {
@@ -94,7 +93,6 @@ type SelectExprGroup struct { // 查询表达式 @@ -94,7 +93,6 @@ type SelectExprGroup struct { // 查询表达式
94 } 93 }
95 94
96 type FieldExpr struct { 95 type FieldExpr struct {
97 - //LabelColumns []LabelColumn `json:"labelColumns"`  
98 TableFields []TableField `json:"tableFields"` 96 TableFields []TableField `json:"tableFields"`
99 ExprHuman string `json:"exprHuman"` 97 ExprHuman string `json:"exprHuman"`
100 ExprSql string `json:"exprSql"` 98 ExprSql string `json:"exprSql"`
@@ -104,15 +102,11 @@ func (expr *FieldExpr) Complete() string { @@ -104,15 +102,11 @@ func (expr *FieldExpr) Complete() string {
104 exprSql := expr.ExprSql 102 exprSql := expr.ExprSql
105 for _, f := range expr.TableFields { 103 for _, f := range expr.TableFields {
106 sql := fmt.Sprintf("%s.%s", f.TableSqlName, f.FieldSqlName) 104 sql := fmt.Sprintf("%s.%s", f.TableSqlName, f.FieldSqlName)
107 - //zhSql := fmt.Sprintf("%s.%s", f.TableName, f.FieldSqlName)  
108 sub := fmt.Sprintf("max(%s.%s)", f.TableSqlName, f.FieldSqlName) 105 sub := fmt.Sprintf("max(%s.%s)", f.TableSqlName, f.FieldSqlName)
109 - //zhSub := fmt.Sprintf("max(%s.%s)", f.TableName, f.FieldSqlName)  
110 if strings.Contains(expr.ExprSql, fmt.Sprintf("(%s)", sql)) { 106 if strings.Contains(expr.ExprSql, fmt.Sprintf("(%s)", sql)) {
111 continue 107 continue
112 } 108 }
113 exprSql = strings.ReplaceAll(exprSql, sql, sub) 109 exprSql = strings.ReplaceAll(exprSql, sql, sub)
114 - //expr.ExprSql = strings.ReplaceAll(expr.ExprSql, sql, sub)  
115 - //expr.ExprHuman = strings.ReplaceAll(expr.ExprHuman, zhSql, zhSub)  
116 } 110 }
117 return exprSql 111 return exprSql
118 } 112 }
@@ -227,3 +221,20 @@ func SelectsExprToMapById(items []SelectExpr) map[string]SelectExpr { @@ -227,3 +221,20 @@ func SelectsExprToMapById(items []SelectExpr) map[string]SelectExpr {
227 } 221 }
228 return res 222 return res
229 } 223 }
  224 +
  225 +type QueryComponents []*QueryComponent
  226 +
  227 +func (list QueryComponents) IsEmpty(t TableType) bool {
  228 + if len(list) == 0 {
  229 + return true
  230 + }
  231 + for _, q := range list {
  232 + switch t {
  233 + case CalculateTable:
  234 + if q.Aggregation != nil && len(q.Aggregation.RowFields) == 0 && len(q.Aggregation.ValueFields) == 0 {
  235 + return true
  236 + }
  237 + }
  238 + }
  239 + return false
  240 +}
1 package domain 1 package domain
2 2
  3 +import (
  4 + "github.com/zeromicro/go-zero/core/collection"
  5 + "sort"
  6 + "strings"
  7 +)
  8 +
3 const ( 9 const (
4 CellTypeTable = "Table" 10 CellTypeTable = "Table"
5 CellTypeTableField = "TableField" 11 CellTypeTableField = "TableField"
@@ -38,24 +44,12 @@ type Location struct { @@ -38,24 +44,12 @@ type Location struct {
38 } 44 }
39 45
40 type LayoutCellData struct { 46 type LayoutCellData struct {
41 - //Table *Table `json:"table,omitempty"`  
42 - //Field *Field `json:"field,omitempty"`  
43 TableField *TableField `json:"tableField"` 47 TableField *TableField `json:"tableField"`
44 Text string `json:"text,omitempty"` 48 Text string `json:"text,omitempty"`
45 } 49 }
46 50
47 func (l *LayoutRuleItem) LayoutCells() []*LayoutCell { 51 func (l *LayoutRuleItem) LayoutCells() []*LayoutCell {
48 var cells = make([]*LayoutCell, 0) 52 var cells = make([]*LayoutCell, 0)
49 - //for i, rows := range l.Cells {  
50 - // for j, item := range rows {  
51 - // if item.Type == CellTypeNull || item.Type == "" {  
52 - // continue  
53 - // }  
54 - // item.X = i  
55 - // item.Y = j  
56 - // cells = append(cells, item)  
57 - // }  
58 - //}  
59 for _, item := range l.Cells { 53 for _, item := range l.Cells {
60 item.X = item.Position.X 54 item.X = item.Position.X
61 item.Y = item.Position.Y 55 item.Y = item.Position.Y
@@ -63,3 +57,19 @@ func (l *LayoutRuleItem) LayoutCells() []*LayoutCell { @@ -63,3 +57,19 @@ func (l *LayoutRuleItem) LayoutCells() []*LayoutCell {
63 } 57 }
64 return cells 58 return cells
65 } 59 }
  60 +
  61 +type LayoutCells []*LayoutCell
  62 +
  63 +func (cells LayoutCells) CellsRange(direction string) []int {
  64 + list := collection.NewSet()
  65 + for i := range cells {
  66 + if strings.ToLower(direction) == "x" {
  67 + list.Add(cells[i].X)
  68 + } else {
  69 + list.Add(cells[i].Y)
  70 + }
  71 + }
  72 + sortList := list.KeysInt()
  73 + sort.Ints(sortList)
  74 + return sortList
  75 +}
@@ -2,5 +2,4 @@ package domain @@ -2,5 +2,4 @@ package domain
2 2
3 type QuerySetInfo struct { 3 type QuerySetInfo struct {
4 BindTableId int // 查询集绑定的表 4 BindTableId int // 查询集绑定的表
5 - //DependentTables []int // 依赖的表  
6 } 5 }
@@ -67,16 +67,39 @@ func (table *Table) TableIdString() string { @@ -67,16 +67,39 @@ func (table *Table) TableIdString() string {
67 67
68 func (table *Table) WithContext(ctx *Context) *Table { 68 func (table *Table) WithContext(ctx *Context) *Table {
69 rand.Seed(time.Now().Unix()) 69 rand.Seed(time.Now().Unix())
70 - table.SQLName = fmt.Sprintf("%v_t%v_c%v", table.SQLName, rand.Intn(1000000), ctx.CompanyId) 70 + table.SQLName = fmt.Sprintf("%v_t%v_c%v", limitStringLen(table.SQLName, 40), rand.Intn(1000000), limitStringLen(fmt.Sprintf("%d", ctx.CompanyId), 8))
71 table.Context = ctx 71 table.Context = ctx
72 return table 72 return table
73 } 73 }
74 74
  75 +func limitStringLen(s string, l int) string {
  76 + result := s
  77 + subLength := l / 2
  78 + if len(result) > l {
  79 + result = result[:subLength] + result[len(result)-subLength:]
  80 + }
  81 + return result
  82 +}
  83 +
75 func (table *Table) WithPrefix(prefix string) *Table { 84 func (table *Table) WithPrefix(prefix string) *Table {
  85 + if strings.HasPrefix(table.SQLName, "_") {
  86 + table.SQLName = fmt.Sprintf("%v%v", strings.ToLower(prefix), table.SQLName)
  87 + return table
  88 + }
76 table.SQLName = fmt.Sprintf("%v_%v", strings.ToLower(prefix), table.SQLName) 89 table.SQLName = fmt.Sprintf("%v_%v", strings.ToLower(prefix), table.SQLName)
77 return table 90 return table
78 } 91 }
79 92
  93 +func (table *Table) ApplyDefaultModule() *Table {
  94 + if table.TableType == CalculateTable.ToString() || table.TableType == SubProcessTable.ToString() {
  95 + table.TableInfo.SetApplyOn(ModuleQuerySetCenter)
  96 + }
  97 + if table.TableType == SchemaTable.ToString() {
  98 + table.TableInfo.SetApplyOn(ModuleQuerySetCenter | ModuleCalculateCenter)
  99 + }
  100 + return table
  101 +}
  102 +
80 func (table *Table) WithParentId(parentId int) *Table { 103 func (table *Table) WithParentId(parentId int) *Table {
81 table.ParentId = parentId 104 table.ParentId = parentId
82 return table 105 return table
@@ -91,44 +114,52 @@ func (table *Table) Update(data map[string]interface{}) error { @@ -91,44 +114,52 @@ func (table *Table) Update(data map[string]interface{}) error {
91 return nil 114 return nil
92 } 115 }
93 116
94 -func (t *Table) Fields(includePK bool) []*Field { 117 +func (table *Table) Fields(includePK bool) []*Field {
95 var fields []*Field 118 var fields []*Field
96 119
97 - if includePK && t.PK != nil {  
98 - fields = append(fields, t.PK) 120 + if includePK && table.PK != nil {
  121 + fields = append(fields, table.PK)
99 } 122 }
100 - fields = append(fields, t.DataFields...)  
101 - if t.TableType == SubTable.ToString() {  
102 - fields = append(fields, t.ManualFields...) 123 + fields = append(fields, table.DataFields...)
  124 + if table.TableType == SubTable.ToString() {
  125 + fields = append(fields, table.ManualFields...)
103 } 126 }
104 - t.fields = fields 127 + table.fields = fields
105 128
106 - return t.fields 129 + return table.fields
107 } 130 }
108 131
109 -func (t *Table) MatchField(field *Field) (*Field, bool) {  
110 - if len(t.fields) == 0 {  
111 - t.fields = t.Fields(true) 132 +func (table *Table) MatchField(field *Field) (*Field, bool) {
  133 + if len(table.fields) == 0 {
  134 + table.fields = table.Fields(true)
112 } 135 }
113 - mField := (Fields)(t.fields).ToMap() 136 + mField := (Fields)(table.fields).ToMap()
114 if v, ok := mField[field.Name]; ok { 137 if v, ok := mField[field.Name]; ok {
115 return v, true 138 return v, true
116 } 139 }
117 return nil, false 140 return nil, false
118 } 141 }
119 142
120 -func (t *Table) DependencyTables() []int {  
121 - if t.TableInfo == nil { 143 +func (table *Table) DependencyTables() []int {
  144 + if table.TableInfo == nil {
122 return []int{} 145 return []int{}
123 } 146 }
124 - return t.TableInfo.DependencyTables 147 + return table.TableInfo.DependencyTables
125 } 148 }
126 149
127 -func (t *Table) AssertTableType(types ...TableType) bool { 150 +func (table *Table) AssertTableType(types ...TableType) bool {
128 for _, item := range types { 151 for _, item := range types {
129 - if t.TableType == item.ToString() { 152 + if table.TableType == item.ToString() {
130 return true 153 return true
131 } 154 }
132 } 155 }
133 return false 156 return false
134 } 157 }
  158 +
  159 +func TableTypesToStringList(list ...TableType) []string {
  160 + var result = make([]string, 0)
  161 + for _, item := range list {
  162 + result = append(result, item.ToString())
  163 + }
  164 + return result
  165 +}
  1 +package domain
  2 +
  3 +import (
  4 + "testing"
  5 +
  6 + "github.com/stretchr/testify/assert"
  7 +)
  8 +
  9 +func TestLimitStringLen(t *testing.T){
  10 + inputs:=[]struct{
  11 + input string
  12 + length int
  13 + want string
  14 + }{
  15 + {
  16 + input: "123456789",
  17 + length: 6,
  18 + want: "123789",
  19 + },
  20 + {
  21 + input: "123456789",
  22 + length: 7,
  23 + want: "123789",
  24 + },
  25 + {
  26 + input: "123456789",
  27 + length: 10,
  28 + want: "123456789",
  29 + },
  30 + {
  31 + input: "pai_xu_ce_shi_zhu_biao_fu_zhi",
  32 + length: 20,
  33 + want: "pai_xu_ce_iao_fu_zhi",
  34 + },
  35 + }
  36 + for _,input:=range inputs{
  37 + got:=limitStringLen(input.input,input.length)
  38 + assert.Equal(t,input.want,got)
  39 + }
  40 +}
1 package domain 1 package domain
2 2
3 -// 用户对象 3 +// User 用户对象
4 type User struct { 4 type User struct {
5 // 用户Id 用户唯一标识 5 // 用户Id 用户唯一标识
6 Id int `json:"id"` 6 Id int `json:"id"`
  1 +package bytelib
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  4 +
  5 +func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
  6 + result := make([]domain.ColumnSchema, 0)
  7 + for _, f := range fields {
  8 + res := domain.ColumnSchema{
  9 + ColumnName: f.Name,
  10 + ColumnType: f.SQLType,
  11 + }
  12 + if convertFiledSQLType(f.SQLType) {
  13 + res.ColumnType = domain.DECIMAL279.ToString()
  14 + }
  15 + result = append(result, res)
  16 + }
  17 + return result
  18 +}
  19 +
  20 +func ToFieldSchemas(fields []*domain.Field) []FieldSchema {
  21 + result := make([]FieldSchema, 0)
  22 + for _, f := range fields {
  23 + res := FieldSchema{
  24 + FieldZhName: f.Name,
  25 + FieldEnName: f.SQLName,
  26 + FieldType: f.SQLType,
  27 + FieldDescription: f.Description,
  28 + IsAllowNull: true,
  29 + }
  30 + if convertFiledSQLType(f.SQLType) {
  31 + res.FieldType = domain.DECIMAL279.ToString()
  32 + }
  33 + result = append(result, res)
  34 + }
  35 + return result
  36 +}
  37 +
  38 +func NewFieldSchema(f domain.TableField) FieldSchema {
  39 + var res = FieldSchema{
  40 + FieldZhName: f.FieldName,
  41 + FieldEnName: f.FieldSqlName,
  42 + FieldType: f.FieldSQLType,
  43 + FieldDescription: "",
  44 + IsAllowNull: true,
  45 + }
  46 + if convertFiledSQLType(f.FieldSQLType) {
  47 + res.FieldType = domain.DECIMAL279.ToString()
  48 + }
  49 + return res
  50 +}
  51 +
  52 +func NewFieldSchemaFromField(f *domain.Field) FieldSchema {
  53 + var res = FieldSchema{
  54 + FieldZhName: f.Name,
  55 + FieldEnName: f.SQLName,
  56 + FieldType: f.SQLType,
  57 + FieldDescription: "",
  58 + IsAllowNull: true,
  59 + }
  60 + if convertFiledSQLType(f.SQLType) {
  61 + res.FieldType = domain.DECIMAL279.ToString()
  62 + }
  63 + return res
  64 +}
  65 +
  66 +func convertFiledSQLType(sqlType string) bool {
  67 + if sqlType == domain.Float.ToString() || sqlType == domain.DECIMAL279.ToString() {
  68 + return true
  69 + }
  70 + return false
  71 +}
  72 +
  73 +func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
  74 + result := make([]domain.ColumnSchema, 0)
  75 +
  76 + for _, f := range fields {
  77 + result = append(result, domain.ColumnSchema{
  78 + ColumnName: f.Name,
  79 + ColumnType: f.SQLType,
  80 + })
  81 + }
  82 + return result
  83 +}
@@ -96,30 +96,6 @@ type ResponseCheckoutTablesSave struct { @@ -96,30 +96,6 @@ type ResponseCheckoutTablesSave struct {
96 CheckoutTableUrl string `json:"checkoutTableUrl"` 96 CheckoutTableUrl string `json:"checkoutTableUrl"`
97 } 97 }
98 98
99 -func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {  
100 - result := make([]domain.ColumnSchema, 0)  
101 -  
102 - for _, f := range fields {  
103 - result = append(result, domain.ColumnSchema{  
104 - ColumnName: f.Name,  
105 - ColumnType: f.SQLType,  
106 - })  
107 - }  
108 - return result  
109 -}  
110 -  
111 -func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {  
112 - result := make([]domain.ColumnSchema, 0)  
113 -  
114 - for _, f := range fields {  
115 - result = append(result, domain.ColumnSchema{  
116 - ColumnName: f.Name,  
117 - ColumnType: f.SQLType, // domain.String.ToString(),  
118 - })  
119 - }  
120 - return result  
121 -}  
122 -  
123 func ToDataLoadDataTable(data DataCheckoutTables) *domain.DataLoadDataTable { 99 func ToDataLoadDataTable(data DataCheckoutTables) *domain.DataLoadDataTable {
124 response := &domain.DataLoadDataTable{ 100 response := &domain.DataLoadDataTable{
125 PageNumber: data.PageNumber, 101 PageNumber: data.PageNumber,
@@ -181,28 +157,6 @@ func NewRequestCheckoutTablesGenerateMasterTable(param domain.ReqGenerateTable) @@ -181,28 +157,6 @@ func NewRequestCheckoutTablesGenerateMasterTable(param domain.ReqGenerateTable)
181 return request 157 return request
182 } 158 }
183 159
184 -func ToFieldSchemas(fields []*domain.Field) []FieldSchema {  
185 - result := make([]FieldSchema, 0)  
186 - for _, f := range fields {  
187 - result = append(result, FieldSchema{  
188 - FieldZhName: f.Name,  
189 - FieldEnName: f.SQLName,  
190 - FieldType: f.SQLType,  
191 - FieldDescription: f.Description,  
192 - IsAllowNull: true,  
193 - })  
194 - }  
195 - return result  
196 -}  
197 -  
198 -func ToFieldSchemaEnNames(fields []*domain.Field) []string {  
199 - result := make([]string, 0)  
200 - for _, f := range fields {  
201 - result = append(result, f.SQLName)  
202 - }  
203 - return result  
204 -}  
205 -  
206 type ( 160 type (
207 TableAppendRequest struct { 161 TableAppendRequest struct {
208 //MasterTableId string `json:"masterTableId"` 162 //MasterTableId string `json:"masterTableId"`
@@ -243,10 +197,6 @@ func NewTableAppendRequest(param domain.ReqAppendData) TableAppendRequest { @@ -243,10 +197,6 @@ func NewTableAppendRequest(param domain.ReqAppendData) TableAppendRequest {
243 req.SchemaMap[param.To[i].SQLName] = columnSchemas[i] 197 req.SchemaMap[param.To[i].SQLName] = columnSchemas[i]
244 } 198 }
245 } 199 }
246 - //if len(param.From) > 0 {  
247 - // req.ColumnSchemas = DomainFieldsToColumnSchemas(param.From)  
248 - // req.FieldSchemas = ToFieldSchemas(param.To)  
249 - //}  
250 return req 200 return req
251 } 201 }
252 202
@@ -162,12 +162,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon @@ -162,12 +162,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
162 } 162 }
163 if queryComponent.Aggregation != nil { 163 if queryComponent.Aggregation != nil {
164 res.DatabaseTableName = queryComponent.MasterTable.SQLName 164 res.DatabaseTableName = queryComponent.MasterTable.SQLName
165 - for i, f := range queryComponent.Aggregation.ValueFields {  
166 - tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})  
167 - if !ok {  
168 - continue  
169 - }  
170 - if i == 0 { 165 + if len(queryComponent.Aggregation.ValueFields) > 0 || len(queryComponent.Aggregation.RowFields) > 0 {
171 res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ 166 res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
172 DatabaseTableName: queryComponent.MasterTable.SQLName, 167 DatabaseTableName: queryComponent.MasterTable.SQLName,
173 FieldSchema: NewFieldSchemaFromField(&domain.Field{ 168 FieldSchema: NewFieldSchemaFromField(&domain.Field{
@@ -179,6 +174,11 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon @@ -179,6 +174,11 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
179 CalculateFieldName: "id", 174 CalculateFieldName: "id",
180 }) 175 })
181 } 176 }
  177 + for _, f := range queryComponent.Aggregation.ValueFields {
  178 + tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})
  179 + if !ok {
  180 + continue
  181 + }
182 res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ 182 res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
183 DatabaseTableName: queryComponent.MasterTable.SQLName, 183 DatabaseTableName: queryComponent.MasterTable.SQLName,
184 FieldSchema: NewFieldSchemaFromField(f.Field), 184 FieldSchema: NewFieldSchemaFromField(f.Field),
@@ -252,28 +252,6 @@ func NewFormulaField(f domain.FieldExpr, args ...interface{}) FormulaField { @@ -252,28 +252,6 @@ func NewFormulaField(f domain.FieldExpr, args ...interface{}) FormulaField {
252 return res 252 return res
253 } 253 }
254 254
255 -func NewFieldSchema(f domain.TableField) FieldSchema {  
256 - var res = FieldSchema{  
257 - FieldZhName: f.FieldName,  
258 - FieldEnName: f.FieldSqlName,  
259 - FieldType: f.FieldSQLType,  
260 - FieldDescription: "",  
261 - IsAllowNull: true,  
262 - }  
263 - return res  
264 -}  
265 -  
266 -func NewFieldSchemaFromField(f *domain.Field) FieldSchema {  
267 - var res = FieldSchema{  
268 - FieldZhName: f.Name,  
269 - FieldEnName: f.SQLName,  
270 - FieldType: f.SQLType,  
271 - FieldDescription: "",  
272 - IsAllowNull: true,  
273 - }  
274 - return res  
275 -}  
276 -  
277 func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule { 255 func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule {
278 var res = FormulaDataHandleRule{ 256 var res = FormulaDataHandleRule{
279 RuleType: 1, 257 RuleType: 1,
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 ) 9 )
10 10
11 var DefaultCache = cache.New(12*time.Hour, 1*time.Hour) 11 var DefaultCache = cache.New(12*time.Hour, 1*time.Hour)
  12 +var TableCacheExpire = 24 * 60 * 60 * 2 // 两天过期
12 13
13 func KeyCompanyUser(companyId int, userId int) string { 14 func KeyCompanyUser(companyId int, userId int) string {
14 return fmt.Sprintf("local:cache:user:%d:%d", companyId, userId) 15 return fmt.Sprintf("local:cache:user:%d:%d", companyId, userId)
@@ -26,15 +27,19 @@ func SetDataTable(tableId int, table *domain.DataTable) { @@ -26,15 +27,19 @@ func SetDataTable(tableId int, table *domain.DataTable) {
26 DefaultDataTableCacheService.SetDataTable(tableId, table) 27 DefaultDataTableCacheService.SetDataTable(tableId, table)
27 } 28 }
28 29
29 -var DefaultDataTableCacheService = &DataTableCacheService{} 30 +// 1:优化点 redis 一万条数据占用内存 10M 无法大量使用,需要内存+本地文件形式
  31 +//var DefaultDataTableCacheService DataTableCacheService= &DataTableRedisCacheService{}
30 32
31 -type DataTableCacheService struct { 33 +var DefaultDataTableCacheService DataTableCacheService = &DataTableLocalCacheService{}
  34 +
  35 +type DataTableLocalCacheService struct {
32 } 36 }
33 37
34 -func (svr *DataTableCacheService) KeyDataTable(tableId int) string { 38 +func (svr *DataTableLocalCacheService) KeyDataTable(tableId int) string {
35 return fmt.Sprintf("local:cache:table:%d", tableId) 39 return fmt.Sprintf("local:cache:table:%d", tableId)
36 } 40 }
37 -func (svr *DataTableCacheService) GetDataTable(tableId int) (*domain.DataTable, bool) { 41 +
  42 +func (svr *DataTableLocalCacheService) GetDataTable(tableId int) (*domain.DataTable, bool) {
38 v, ok := DefaultCache.Get(KeyDataTable(tableId)) 43 v, ok := DefaultCache.Get(KeyDataTable(tableId))
39 if !ok { 44 if !ok {
40 log.Logger.Info(fmt.Sprintf("【缓存】 miss cache %v", KeyDataTable(tableId))) 45 log.Logger.Info(fmt.Sprintf("【缓存】 miss cache %v", KeyDataTable(tableId)))
@@ -43,11 +48,20 @@ func (svr *DataTableCacheService) GetDataTable(tableId int) (*domain.DataTable, @@ -43,11 +48,20 @@ func (svr *DataTableCacheService) GetDataTable(tableId int) (*domain.DataTable,
43 log.Logger.Info(fmt.Sprintf("【缓存】 hit cache %v", KeyDataTable(tableId))) 48 log.Logger.Info(fmt.Sprintf("【缓存】 hit cache %v", KeyDataTable(tableId)))
44 return v.(*domain.DataTable), true 49 return v.(*domain.DataTable), true
45 } 50 }
46 -func (svr *DataTableCacheService) SetDataTable(tableId int, table *domain.DataTable) { 51 +
  52 +func (svr *DataTableLocalCacheService) SetDataTable(tableId int, table *domain.DataTable) {
47 log.Logger.Info(fmt.Sprintf("【缓存】 set cache %v", KeyDataTable(tableId))) 53 log.Logger.Info(fmt.Sprintf("【缓存】 set cache %v", KeyDataTable(tableId)))
48 - DefaultCache.Set(KeyDataTable(tableId), table, 24*time.Hour*30) 54 + DefaultCache.Set(KeyDataTable(tableId), table, time.Duration(TableCacheExpire)*time.Second)
49 } 55 }
50 -func (svr *DataTableCacheService) DeleteDataTable(tableId int) { 56 +
  57 +func (svr *DataTableLocalCacheService) DeleteDataTable(tableId int) {
51 log.Logger.Info(fmt.Sprintf("【缓存】 delete cache %v", KeyDataTable(tableId))) 58 log.Logger.Info(fmt.Sprintf("【缓存】 delete cache %v", KeyDataTable(tableId)))
52 DefaultCache.Delete(KeyDataTable(tableId)) 59 DefaultCache.Delete(KeyDataTable(tableId))
53 } 60 }
  61 +
  62 +type DataTableCacheService interface {
  63 + KeyDataTable(tableId int) string
  64 + GetDataTable(tableId int) (*domain.DataTable, bool)
  65 + SetDataTable(tableId int, table *domain.DataTable)
  66 + DeleteDataTable(tableId int)
  67 +}
  1 +package cache
  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 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
  10 +)
  11 +
  12 +type DataTableRedisCacheService struct {
  13 +}
  14 +
  15 +func (svr *DataTableRedisCacheService) KeyDataTable(tableId int) string {
  16 + return fmt.Sprintf("%s:cache:table:%d", constant.CACHE_PREFIX, tableId)
  17 +}
  18 +
  19 +func (svr *DataTableRedisCacheService) GetDataTable(tableId int) (*domain.DataTable, bool) {
  20 + key := svr.KeyDataTable(tableId)
  21 + data, err := redis.ZeroCoreRedis.Get(key)
  22 + if err == redis.NotFound || len(data) == 0 {
  23 + log.Logger.Info(fmt.Sprintf("【缓存】 miss cache %v", key))
  24 + return nil, false
  25 + }
  26 + var table = &domain.DataTable{}
  27 + err = json.UnmarshalFromString(data, table)
  28 + if err != nil {
  29 + log.Logger.Error(fmt.Sprintf("【缓存】 miss cache %v,err %v", key, err.Error()))
  30 + return nil, false
  31 + }
  32 + log.Logger.Info(fmt.Sprintf("【缓存】 hit cache %v", key))
  33 + return table, true
  34 +}
  35 +
  36 +func (svr *DataTableRedisCacheService) SetDataTable(tableId int, table *domain.DataTable) {
  37 + key := svr.KeyDataTable(tableId)
  38 + log.Logger.Info(fmt.Sprintf("【缓存】 set cache %v", key))
  39 + redis.ZeroCoreRedis.Setex(key, json.MarshalToString(table), TableCacheExpire)
  40 +}
  41 +
  42 +func (svr *DataTableRedisCacheService) DeleteDataTable(tableId int) {
  43 + key := svr.KeyDataTable(tableId)
  44 + log.Logger.Info(fmt.Sprintf("【缓存】 delete cache %v", key))
  45 + redis.ZeroCoreRedis.Del(key)
  46 +}
@@ -2,6 +2,7 @@ package domainService @@ -2,6 +2,7 @@ package domainService
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
  5 +
5 "github.com/beego/beego/v2/client/httplib" 6 "github.com/beego/beego/v2/client/httplib"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
@@ -146,6 +147,13 @@ func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) ( @@ -146,6 +147,13 @@ func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) (
146 // } 147 // }
147 // return &domain.DataFormulasGenerate{}, nil 148 // return &domain.DataFormulasGenerate{}, nil
148 //} 149 //}
  150 + if param.QuerySet.Type == domain.CalculateSet.ToString() {
  151 + _, err := param.QuerySetService.(*QuerySetService).LoadCalculateSetData(param.Context.(*domain.Context), param.QuerySet, param.QueryComponents)
  152 + if err != nil {
  153 + return nil, err
  154 + }
  155 + return &domain.DataFormulasGenerate{}, nil
  156 + }
149 return apiByteLib.FormulasGenerate(param) 157 return apiByteLib.FormulasGenerate(param)
150 } 158 }
151 159
@@ -33,8 +33,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * @@ -33,8 +33,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *
33 table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) 33 table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx)
34 // 通知底层保存、进行回调 34 // 通知底层保存、进行回调
35 var response *domain.DataSaveTable 35 var response *domain.DataSaveTable
36 - response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId, Table: table})  
37 - if err != nil { 36 + if response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId, Table: table}); err != nil {
38 return nil, err 37 return nil, err
39 } 38 }
40 // 来自源文件的 39 // 来自源文件的
@@ -154,12 +153,11 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain. @@ -154,12 +153,11 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain.
154 153
155 func NewCopyTable(tableType domain.TableType, fileName string, dataFields []*domain.Field, rowCount int) *domain.Table { 154 func NewCopyTable(tableType domain.TableType, fileName string, dataFields []*domain.Field, rowCount int) *domain.Table {
156 var table = &domain.Table{} 155 var table = &domain.Table{}
157 - // New Table  
158 table.TableType = tableType.ToString() 156 table.TableType = tableType.ToString()
159 table.Name = fileName 157 table.Name = fileName
160 - table.SQLName = pin(fileName) //SQLTableName() 158 + table.SQLName = pin(fileName)
161 table.PK = PK() 159 table.PK = PK()
162 - if table.TableType == domain.CalculateTable.ToString() || table.TableType == domain.CalculateItem.ToString() { 160 + if table.TableType == domain.CalculateItem.ToString() {
163 table.PK = nil 161 table.PK = nil
164 } 162 }
165 table.DataFieldIndex = len(dataFields) 163 table.DataFieldIndex = len(dataFields)
@@ -192,7 +190,7 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field { @@ -192,7 +190,7 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field {
192 return &domain.Field{ 190 return &domain.Field{
193 Index: index, 191 Index: index,
194 Name: name, 192 Name: name,
195 - SQLName: fmt.Sprintf("%v_c%d", pin(name), index), //fieldName(index), 193 + SQLName: fmt.Sprintf("%v_c%d", pin(name), index),
196 SQLType: sqlType, 194 SQLType: sqlType,
197 Description: "", 195 Description: "",
198 Flag: flag, 196 Flag: flag,
@@ -25,17 +25,17 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i @@ -25,17 +25,17 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i
25 return nil, fmt.Errorf("文件未校验") 25 return nil, fmt.Errorf("文件未校验")
26 } 26 }
27 duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName, 27 duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName,
28 - "tableTypes":[]string{string(domain.MainTable),string(domain.SubTable),string(domain.SideTable)}}) 28 + "tableTypes": []string{string(domain.MainTable), string(domain.SubTable), string(domain.SideTable)}})
29 if err == nil && duplicateTable != nil { 29 if err == nil && duplicateTable != nil {
30 return nil, fmt.Errorf("表名称重复") 30 return nil, fmt.Errorf("表名称重复")
31 } 31 }
32 32
33 - mainTable := NewTable(domain.MainTable, tableName, table.DataFields, table.RowCount).WithContext(ctx)  
34 - _, err = tableRepository.Save(mainTable)  
35 - if err != nil { 33 + mainTable := NewTable(domain.MainTable, tableName, table.DataFields, table.RowCount).
  34 + WithContext(ctx).
  35 + WithPrefix(domain.MainTable.ToString())
  36 + if _, err = tableRepository.Save(mainTable); err != nil {
36 return nil, err 37 return nil, err
37 } 38 }
38 -  
39 // 日志 39 // 日志
40 if err = FastLog(ptr.transactionContext, domain.CommonLog, mainTable.TableId, &GenerateMainTableLog{ 40 if err = FastLog(ptr.transactionContext, domain.CommonLog, mainTable.TableId, &GenerateMainTableLog{
41 LogEntry: domain.NewLogEntry(tableName, domain.MainTable.ToString(), domain.GenerateMainTable, ctx), 41 LogEntry: domain.NewLogEntry(tableName, domain.MainTable.ToString(), domain.GenerateMainTable, ctx),
@@ -91,7 +91,7 @@ type Log interface { @@ -91,7 +91,7 @@ type Log interface {
91 91
92 var _ Log = (*FileUploadSuccessLog)(nil) 92 var _ Log = (*FileUploadSuccessLog)(nil)
93 93
94 -// 1.1文件上传成功 94 +// FileUploadSuccessLog 1.1文件上传成功
95 type FileUploadSuccessLog struct { 95 type FileUploadSuccessLog struct {
96 domain.LogEntry 96 domain.LogEntry
97 } 97 }
@@ -100,7 +100,7 @@ func (l *FileUploadSuccessLog) Content() string { @@ -100,7 +100,7 @@ func (l *FileUploadSuccessLog) Content() string {
100 return fmt.Sprintf("上传成功") 100 return fmt.Sprintf("上传成功")
101 } 101 }
102 102
103 -// 1.2文件上传失败 103 +// FileUploadFailLog 1.2文件上传失败
104 type FileUploadFailLog struct { 104 type FileUploadFailLog struct {
105 domain.LogEntry 105 domain.LogEntry
106 Reason string 106 Reason string
@@ -110,7 +110,7 @@ func (l *FileUploadFailLog) Content() string { @@ -110,7 +110,7 @@ func (l *FileUploadFailLog) Content() string {
110 return fmt.Sprintf("上传失败,失败原因:%s", l.Reason) 110 return fmt.Sprintf("上传失败,失败原因:%s", l.Reason)
111 } 111 }
112 112
113 -// 2.文件校验 113 +// FileVerifyLog 2.文件校验
114 type FileVerifyLog struct { 114 type FileVerifyLog struct {
115 domain.LogEntry 115 domain.LogEntry
116 // 错误信息 116 // 错误信息
@@ -127,7 +127,7 @@ func (l *FileVerifyLog) Content() string { @@ -127,7 +127,7 @@ func (l *FileVerifyLog) Content() string {
127 return msg 127 return msg
128 } 128 }
129 129
130 -// 3.主表生成日志 130 +// GenerateMainTableLog 3.主表生成日志
131 type GenerateMainTableLog struct { 131 type GenerateMainTableLog struct {
132 domain.LogEntry 132 domain.LogEntry
133 // 表名 133 // 表名
@@ -141,7 +141,7 @@ func (l *GenerateMainTableLog) Content() string { @@ -141,7 +141,7 @@ func (l *GenerateMainTableLog) Content() string {
141 return msg 141 return msg
142 } 142 }
143 143
144 -// 4.主表拆分 144 +// SpiltMainTableLog 4.主表拆分
145 type SpiltMainTableLog struct { 145 type SpiltMainTableLog struct {
146 domain.LogEntry 146 domain.LogEntry
147 Reserve []*domain.Field 147 Reserve []*domain.Field
@@ -175,7 +175,7 @@ func (l *SpiltMainTableLog) fieldNames(fields []*domain.Field) []string { @@ -175,7 +175,7 @@ func (l *SpiltMainTableLog) fieldNames(fields []*domain.Field) []string {
175 return names 175 return names
176 } 176 }
177 177
178 -// 5.分表编辑 178 +// SubTableEditLog 5.分表编辑
179 type SubTableEditLog struct { 179 type SubTableEditLog struct {
180 domain.LogEntry 180 domain.LogEntry
181 181
@@ -208,7 +208,7 @@ func (l *SubTableEditLog) fieldNames(fields []*domain.Field) []string { @@ -208,7 +208,7 @@ func (l *SubTableEditLog) fieldNames(fields []*domain.Field) []string {
208 return names 208 return names
209 } 209 }
210 210
211 -// 6.表复制日志 211 +// CopyTableLog 6.表复制日志
212 type CopyTableLog struct { 212 type CopyTableLog struct {
213 domain.LogEntry 213 domain.LogEntry
214 // 表名 214 // 表名
@@ -220,7 +220,7 @@ func (l *CopyTableLog) Content() string { @@ -220,7 +220,7 @@ func (l *CopyTableLog) Content() string {
220 return msg 220 return msg
221 } 221 }
222 222
223 -// 7.编辑记录 223 +// RowAddLog 7.编辑记录
224 type RowAddLog struct { 224 type RowAddLog struct {
225 domain.LogEntry 225 domain.LogEntry
226 } 226 }
@@ -239,10 +239,8 @@ type RowUpdateLog struct { @@ -239,10 +239,8 @@ type RowUpdateLog struct {
239 239
240 func (l *RowUpdateLog) Content() string { 240 func (l *RowUpdateLog) Content() string {
241 change := "" 241 change := ""
242 - //index := l.Number + l.Where.Offset()  
243 for _, f := range l.FieldValue { 242 for _, f := range l.FieldValue {
244 if f.OldValue != f.Value { 243 if f.OldValue != f.Value {
245 - //change += fmt.Sprintf("%v字段%v行的值从%v更改为%v;", f.Field.Name, index, f.OldValue, f.Value)  
246 change += fmt.Sprintf("【%v】字段的值从“%v”更改为“%v”;", f.Field.Name, f.OldValue, f.Value) 244 change += fmt.Sprintf("【%v】字段的值从“%v”更改为“%v”;", f.Field.Name, f.OldValue, f.Value)
247 } 245 }
248 } 246 }
@@ -261,7 +259,6 @@ type RowRemoveLog struct { @@ -261,7 +259,6 @@ type RowRemoveLog struct {
261 259
262 func (l *RowRemoveLog) Content() string { 260 func (l *RowRemoveLog) Content() string {
263 index := l.DeleteRowCount 261 index := l.DeleteRowCount
264 - //msg := fmt.Sprintf("删除%v行数据;筛选件:%v",index,"")  
265 msg := fmt.Sprintf("删除%v行数据;", index) 262 msg := fmt.Sprintf("删除%v行数据;", index)
266 filters := make([]string, 0) 263 filters := make([]string, 0)
267 inArgs := func(args []string) string { 264 inArgs := func(args []string) string {
@@ -281,7 +278,7 @@ func (l *RowRemoveLog) Content() string { @@ -281,7 +278,7 @@ func (l *RowRemoveLog) Content() string {
281 return msg 278 return msg
282 } 279 }
283 280
284 -// 8.表删除日志 281 +// DeleteTableLog 8.表删除日志
285 type DeleteTableLog struct { 282 type DeleteTableLog struct {
286 domain.LogEntry 283 domain.LogEntry
287 // 表名 284 // 表名
@@ -302,7 +299,7 @@ func (l *DeleteTableLog) Content() string { @@ -302,7 +299,7 @@ func (l *DeleteTableLog) Content() string {
302 return msg 299 return msg
303 } 300 }
304 301
305 -// 9.数据追加日志 302 +// AppendDataToTableLog 9.数据追加日志
306 type AppendDataToTableLog struct { 303 type AppendDataToTableLog struct {
307 domain.LogEntry 304 domain.LogEntry
308 Table *domain.Table 305 Table *domain.Table
@@ -323,7 +320,8 @@ func (l *AppendDataToTableLog) Content() string { @@ -323,7 +320,8 @@ func (l *AppendDataToTableLog) Content() string {
323 return msg 320 return msg
324 } 321 }
325 322
326 -/*步骤日志*/ 323 +/* *********************************************步骤日志************************************************** */
  324 +
327 type ExcelTableEditLog struct { 325 type ExcelTableEditLog struct {
328 domain.LogEntry 326 domain.LogEntry
329 // 操作名称 327 // 操作名称
@@ -278,6 +278,9 @@ func (ptr *QuerySetService) PreviewPrepare(ctx *domain.Context, querySetId int, @@ -278,6 +278,9 @@ func (ptr *QuerySetService) PreviewPrepare(ctx *domain.Context, querySetId int,
278 return t, nil 278 return t, nil
279 } 279 }
280 } 280 }
  281 + if domain.QueryComponents(queryComponents).IsEmpty(domain.TableType(querySet.Type)) {
  282 + return &domain.Table{}, nil
  283 + }
281 284
282 // 验证 285 // 验证
283 if err = ptr.validQueryComponents(queryComponents); err != nil { 286 if err = ptr.validQueryComponents(queryComponents); err != nil {
@@ -308,9 +311,6 @@ func (ptr *QuerySetService) PreviewPrepare(ctx *domain.Context, querySetId int, @@ -308,9 +311,6 @@ func (ptr *QuerySetService) PreviewPrepare(ctx *domain.Context, querySetId int,
308 var table *domain.Table = NewCopyTable(domain.TableType(domain.TemporaryTable), querySet.Name, domain.RangeFields(fields, domain.ChangeFieldFlag), 0). 311 var table *domain.Table = NewCopyTable(domain.TableType(domain.TemporaryTable), querySet.Name, domain.RangeFields(fields, domain.ChangeFieldFlag), 0).
309 WithContext(ctx). 312 WithContext(ctx).
310 WithPrefix(strings.ToLower(string(domain.TemporaryTable))) 313 WithPrefix(strings.ToLower(string(domain.TemporaryTable)))
311 - if querySet.Type == domain.CalculateTable.ToString() {  
312 - table.PK = nil  
313 - }  
314 // 循环依赖判断 314 // 循环依赖判断
315 if err = ptr.validDependentCircle(ctx, querySet, queryComponents); err != nil { 315 if err = ptr.validDependentCircle(ctx, querySet, queryComponents); err != nil {
316 return nil, err 316 return nil, err
@@ -937,29 +937,26 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string, @@ -937,29 +937,26 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string,
937 if err != nil { 937 if err != nil {
938 return nil, err 938 return nil, err
939 } 939 }
940 - copyTable := NewCopyTable(domain.TableType(t), name, table.Fields(false), 0).WithContext(ctx).WithPrefix(qs.Type) 940 + copyTable := NewCopyTable(domain.TableType(t), name, table.Fields(false), 0).
  941 + WithContext(ctx).
  942 + WithPrefix(qs.Type).
  943 + ApplyDefaultModule()
941 copyTable, err = tableRepository.Save(copyTable) 944 copyTable, err = tableRepository.Save(copyTable)
942 if err != nil { 945 if err != nil {
943 return nil, err 946 return nil, err
944 } 947 }
945 948
946 // 调用底层的组装sql 949 // 调用底层的组装sql
947 - formulasGenerateResponse, err := ByteCore.FormulasGenerate(domain.ReqFormulasGenerate{ 950 + _, err = ByteCore.FormulasGenerate(domain.ReqFormulasGenerate{
948 QuerySet: qs, 951 QuerySet: qs,
949 Table: copyTable, 952 Table: copyTable,
950 QueryComponents: qs.QueryComponents, 953 QueryComponents: qs.QueryComponents,
  954 + QuerySetService: ptr,
  955 + Context: ctx,
951 }) 956 })
952 if err != nil { 957 if err != nil {
953 return nil, err 958 return nil, err
954 } 959 }
955 - if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName {  
956 - //copyTable.SQLName = formulasGenerateResponse.FormulaName  
957 - //tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)  
958 - //copyTable, err = tableRepository.Save(copyTable)  
959 - //if err != nil {  
960 - // return nil, err  
961 - //}  
962 - }  
963 copy.QuerySetInfo.BindTableId = copyTable.TableId 960 copy.QuerySetInfo.BindTableId = copyTable.TableId
964 } 961 }
965 copy, err = querySetRepository.Save(copy) 962 copy, err = querySetRepository.Save(copy)
@@ -2,16 +2,18 @@ package domainService @@ -2,16 +2,18 @@ package domainService
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "sort"
  6 + "strings"
  7 +
5 "github.com/zeromicro/go-zero/core/collection" 8 "github.com/zeromicro/go-zero/core/collection"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
7 "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"
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" 11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" 12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
10 - "strings"  
11 ) 13 )
12 14
13 -const DefaultExpandNum = 10000  
14 -const MaxExpandNum = 50000 15 +const DefaultExpandNum = 1000
  16 +const MaxExpandNum = 5000
15 17
16 func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain.QuerySet, queryComponents []*domain.QueryComponent) (*domain.DataTable, error) { 18 func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain.QuerySet, queryComponents []*domain.QueryComponent) (*domain.DataTable, error) {
17 var ( 19 var (
@@ -26,7 +28,13 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain @@ -26,7 +28,13 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain
26 // 加载Tables数据 28 // 加载Tables数据
27 q := queryComponents[0] 29 q := queryComponents[0]
28 cells := q.Layout.LayoutCells() 30 cells := q.Layout.LayoutCells()
29 - dataTables = ptr.LoadDataTables(ctx, cells) 31 + if len(cells) == 0 {
  32 + return res, nil
  33 + }
  34 + dataTables, err = ptr.LoadDataTables(ctx, cells)
  35 + if err != nil {
  36 + return nil, err
  37 + }
30 // 设置数据 38 // 设置数据
31 dt := &DataLayoutDataTable{ 39 dt := &DataLayoutDataTable{
32 DataTable: res, 40 DataTable: res,
@@ -38,10 +46,10 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain @@ -38,10 +46,10 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain
38 cells[i].Length = length 46 cells[i].Length = length
39 cells[i].BlockData = blockData 47 cells[i].BlockData = blockData
40 } 48 }
41 - // 根据数据修改便宜 49 + // 根据数据修改偏移
42 CellsLocationAdjust(cells) 50 CellsLocationAdjust(cells)
43 // 数据布局 51 // 数据布局
44 - res, err = DataLayout(res, dataTables, cells) 52 + res, err = DataLayout(res, cells)
45 if err != nil { 53 if err != nil {
46 return nil, err 54 return nil, err
47 } 55 }
@@ -60,18 +68,6 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { @@ -60,18 +68,6 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
60 yMin = cells[0].Y 68 yMin = cells[0].Y
61 yMax = cells[0].Y 69 yMax = cells[0].Y
62 } 70 }
63 - min := func(a, b int) int {  
64 - if a > b {  
65 - return b  
66 - }  
67 - return a  
68 - }  
69 - max := func(a, b int) int {  
70 - if a < b {  
71 - return b  
72 - }  
73 - return a  
74 - }  
75 for i := 1; i <= len(cells)-1; i++ { 71 for i := 1; i <= len(cells)-1; i++ {
76 cell := cells[i] 72 cell := cells[i]
77 xMin = min(xMin, cell.X) 73 xMin = min(xMin, cell.X)
@@ -111,7 +107,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { @@ -111,7 +107,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
111 } 107 }
112 //move = cell.Length 108 //move = cell.Length
113 //c = cell 109 //c = cell
114 - if max(move, cell.Length) != move { 110 + if max(move, cell.Length) != move && c == nil {
115 c = cell 111 c = cell
116 } 112 }
117 move = max(move, cell.Length) 113 move = max(move, cell.Length)
@@ -121,6 +117,61 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { @@ -121,6 +117,61 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
121 } 117 }
122 } 118 }
123 119
  120 +func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
  121 + yList := cellsRange(cells, "y")
  122 + xList := cellsRange(cells, "x")
  123 + for i := 0; i < len(yList); i++ {
  124 + j := yList[i]
  125 + move := 0
  126 + var c *domain.LayoutCell
  127 + for _, cell := range cells {
  128 + if cell.Y != j {
  129 + continue
  130 + }
  131 + if cell.Direction != domain.DirectionRight {
  132 + continue
  133 + }
  134 + if max(move, cell.Length) != move {
  135 + c = cell
  136 + }
  137 + move = max(move, cell.Length)
  138 + }
  139 + ChangeLocation(cells, domain.DirectionRight, j, move, c)
  140 + }
  141 + for j := 0; j < len(xList); j++ {
  142 + i := xList[j]
  143 + move := 0
  144 + var c *domain.LayoutCell
  145 + for _, cell := range cells {
  146 + if cell.X != i {
  147 + continue
  148 + }
  149 + if cell.Direction != domain.DirectionDown {
  150 + continue
  151 + }
  152 + if max(move, cell.Length) != move && c == nil {
  153 + c = cell
  154 + }
  155 + move = max(move, cell.Length)
  156 + }
  157 + ChangeLocation(cells, domain.DirectionDown, i, move, c)
  158 + }
  159 +}
  160 +
  161 +func cellsRange(cells []*domain.LayoutCell, direction string) []int {
  162 + list := collection.NewSet()
  163 + for i := range cells {
  164 + if strings.ToLower(direction) == "x" {
  165 + list.Add(cells[i].X)
  166 + } else {
  167 + list.Add(cells[i].Y)
  168 + }
  169 + }
  170 + sortList := list.KeysInt()
  171 + sort.Ints(sortList)
  172 + return sortList
  173 +}
  174 +
124 func ChangeLocation(cells []*domain.LayoutCell, direction string, position, move int, c *domain.LayoutCell) { 175 func ChangeLocation(cells []*domain.LayoutCell, direction string, position, move int, c *domain.LayoutCell) {
125 // log.Logger.Info("修改定位点") 176 // log.Logger.Info("修改定位点")
126 if move == 0 { 177 if move == 0 {
@@ -148,6 +199,8 @@ func FastTable(table *domain.Table) (*domain.DataTable, error) { @@ -148,6 +199,8 @@ func FastTable(table *domain.Table) (*domain.DataTable, error) {
148 TableName: table.SQLName, 199 TableName: table.SQLName,
149 Select: table.Fields(false), 200 Select: table.Fields(false),
150 } 201 }
  202 + options.SetDefaultOrder()
  203 + options.SetOffsetLimit(1, 10000)
151 var dataTable *domain.DataTable 204 var dataTable *domain.DataTable
152 dataTable, err = FastDataTable(options) 205 dataTable, err = FastDataTable(options)
153 if err != nil { 206 if err != nil {
@@ -164,7 +217,6 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) { @@ -164,7 +217,6 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) {
164 if err != nil { 217 if err != nil {
165 return nil, err 218 return nil, err
166 } 219 }
167 -  
168 dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, starrocks.DB)() 220 dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, starrocks.DB)()
169 if err != nil { 221 if err != nil {
170 return nil, err 222 return nil, err
@@ -172,7 +224,7 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) { @@ -172,7 +224,7 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) {
172 return dataTable, nil 224 return dataTable, nil
173 } 225 }
174 226
175 -func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.LayoutCell) map[int]*domain.DataTable { 227 +func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.LayoutCell) (map[int]*domain.DataTable, error) {
176 var ( 228 var (
177 dataTables = make(map[int]*domain.DataTable) 229 dataTables = make(map[int]*domain.DataTable)
178 tableRepository, _ = repository.NewTableRepository(ptr.transactionContext) 230 tableRepository, _ = repository.NewTableRepository(ptr.transactionContext)
@@ -187,28 +239,27 @@ func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain. @@ -187,28 +239,27 @@ func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.
187 if len(tableIds.KeysInt()) > 0 { 239 if len(tableIds.KeysInt()) > 0 {
188 _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": tableIds.KeysInt()}) 240 _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": tableIds.KeysInt()})
189 if err != nil { 241 if err != nil {
190 - return nil 242 + return nil, err
191 } 243 }
192 for _, t := range tables { 244 for _, t := range tables {
193 if _, ok := dataTables[t.TableId]; ok { 245 if _, ok := dataTables[t.TableId]; ok {
194 continue 246 continue
195 } 247 }
196 - dataTable, e := FastTable(t)  
197 - if e != nil {  
198 - log.Logger.Error(e.Error())  
199 - continue 248 + dataTable, err := FastTable(t)
  249 + if err != nil {
  250 + log.Logger.Error(err.Error())
  251 + return nil, fmt.Errorf("获取【%s】出现异常:%s", t.Name, err.Error())
200 } 252 }
201 dataTable.Fields = t.DataFields 253 dataTable.Fields = t.DataFields
202 dataTables[t.TableId] = dataTable 254 dataTables[t.TableId] = dataTable
203 } 255 }
204 } 256 }
205 - return dataTables 257 + return dataTables, nil
206 } 258 }
207 259
208 -func DataLayout(res *domain.DataTable, dataTables map[int]*domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) { 260 +func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) {
209 dt := &DataLayoutDataTable{ 261 dt := &DataLayoutDataTable{
210 DataTable: res, 262 DataTable: res,
211 - //MapDataTables: dataTables,  
212 unprocessed: cells, 263 unprocessed: cells,
213 } 264 }
214 dt.Init(DefaultExpandNum) 265 dt.Init(DefaultExpandNum)
@@ -218,14 +269,6 @@ func DataLayout(res *domain.DataTable, dataTables map[int]*domain.DataTable, cel @@ -218,14 +269,6 @@ func DataLayout(res *domain.DataTable, dataTables map[int]*domain.DataTable, cel
218 } 269 }
219 cell := dt.unprocessed[0] 270 cell := dt.unprocessed[0]
220 dt.unprocessed = dt.unprocessed[1:] 271 dt.unprocessed = dt.unprocessed[1:]
221 - //blockData, length := dt.BlockData(cell)  
222 - //if err := dt.Expand(cell, length); err != nil {  
223 - // return nil, err  
224 - //}  
225 - //dt.addByLocation(cell, blockData)  
226 - //blockData, length := dt.BlockData(cell)  
227 - // 当前单元格子 影响其他格子坐标  
228 - //dt.changeUnProcessedLocation(cell, cell.Length)  
229 if err := dt.Expand(cell, cell.Length); err != nil { 272 if err := dt.Expand(cell, cell.Length); err != nil {
230 return nil, err 273 return nil, err
231 } 274 }
@@ -273,8 +316,13 @@ func (l *Location) UpdateY(y int) { @@ -273,8 +316,13 @@ func (l *Location) UpdateY(y int) {
273 } 316 }
274 } 317 }
275 318
276 -func (d *DataLayoutDataTable) StartCell() {  
277 - 319 +func (l *Location) Update(x int, y int, compare func(int, int) int) {
  320 + if x != 0 {
  321 + l.X = compare(l.X, x)
  322 + }
  323 + if y != 0 {
  324 + l.Y = compare(l.Y, y)
  325 + }
278 } 326 }
279 327
280 func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData []string) { 328 func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData []string) {
@@ -287,23 +335,19 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [ @@ -287,23 +335,19 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [
287 for i := range blockData { 335 for i := range blockData {
288 d.DataTable.Data[cell.X][cell.Y+i] = blockData[i] 336 d.DataTable.Data[cell.X][cell.Y+i] = blockData[i]
289 } 337 }
290 - d.PointEnd.UpdateX(cell.X)  
291 - d.PointEnd.UpdateY(cell.Y + len(blockData) - 1) 338 + d.PointEnd.Update(cell.X, cell.Y+len(blockData)-1, max)
292 case domain.DirectionDown: 339 case domain.DirectionDown:
293 for i := range blockData { 340 for i := range blockData {
294 d.DataTable.Data[cell.X+i][cell.Y] = blockData[i] 341 d.DataTable.Data[cell.X+i][cell.Y] = blockData[i]
295 } 342 }
296 - d.PointEnd.UpdateX(cell.X + len(blockData) - 1)  
297 - d.PointEnd.UpdateY(cell.Y) 343 + d.PointEnd.Update(cell.X+len(blockData)-1, cell.Y, max)
298 case domain.DirectionNone: 344 case domain.DirectionNone:
299 d.DataTable.Data[cell.X][cell.Y] = blockData[0] 345 d.DataTable.Data[cell.X][cell.Y] = blockData[0]
300 - d.PointEnd.UpdateX(cell.X)  
301 - d.PointEnd.UpdateY(cell.Y) 346 + d.PointEnd.Update(cell.X, cell.Y, max)
302 } 347 }
303 } 348 }
304 349
305 func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutCell, length int) { 350 func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutCell, length int) {
306 - // log.Logger.Info("修改定位点")  
307 for _, cell := range d.unprocessed { 351 for _, cell := range d.unprocessed {
308 switch lastCell.Direction { 352 switch lastCell.Direction {
309 case domain.DirectionRight: 353 case domain.DirectionRight:
@@ -315,7 +359,6 @@ func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutC @@ -315,7 +359,6 @@ func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutC
315 cell.X += length - 1 359 cell.X += length - 1
316 } 360 }
317 } 361 }
318 - // log.Logger.Info(fmt.Sprintf("%s %s X:%d Y:%d", cell.Data.Field.SQLName, cell.Direction, cell.X, cell.Y))  
319 } 362 }
320 } 363 }
321 364
@@ -329,7 +372,7 @@ func (d *DataLayoutDataTable) BlockData(cells *domain.LayoutCell) ([]string, int @@ -329,7 +372,7 @@ func (d *DataLayoutDataTable) BlockData(cells *domain.LayoutCell) ([]string, int
329 if !ok { 372 if !ok {
330 return block, 0 373 return block, 0
331 } 374 }
332 - values := table.Values(&domain.Field{SQLName: cells.Data.TableField.FieldSqlName}) 375 + values := table.Values(&domain.Field{SQLName: cells.Data.TableField.FieldSqlName, SQLType: cells.Data.TableField.FieldSQLType})
333 if len(values) == 0 { 376 if len(values) == 0 {
334 return block, 0 377 return block, 0
335 } 378 }
@@ -411,3 +454,16 @@ func (d *DataLayoutDataTable) CellOutRange(cell *domain.LayoutCell, length int) @@ -411,3 +454,16 @@ func (d *DataLayoutDataTable) CellOutRange(cell *domain.LayoutCell, length int)
411 } 454 }
412 return false 455 return false
413 } 456 }
  457 +
  458 +func min(a, b int) int {
  459 + if a > b {
  460 + return b
  461 + }
  462 + return a
  463 +}
  464 +func max(a, b int) int {
  465 + if a < b {
  466 + return b
  467 + }
  468 + return a
  469 +}
@@ -13,6 +13,7 @@ func TestDataLayout(t *testing.T) { @@ -13,6 +13,7 @@ func TestDataLayout(t *testing.T) {
13 cells []*domain.LayoutCell 13 cells []*domain.LayoutCell
14 flag Location 14 flag Location
15 title string 15 title string
  16 + debug bool
16 }{ 17 }{
17 { 18 {
18 title: "配置组多组混合", 19 title: "配置组多组混合",
@@ -410,6 +411,93 @@ func TestDataLayout(t *testing.T) { @@ -410,6 +411,93 @@ func TestDataLayout(t *testing.T) {
410 flag: Location{X: 2, Y: 1}, 411 flag: Location{X: 2, Y: 1},
411 }, 412 },
412 { 413 {
  414 + title: "测试用例4",
  415 + cells: []*domain.LayoutCell{
  416 + // 分组一
  417 + {
  418 + X: 0,
  419 + Y: 0,
  420 + Length: 5,
  421 + ImageData: "a",
  422 + Direction: domain.DirectionDown,
  423 + },
  424 + {
  425 + X: 0,
  426 + Y: 1,
  427 + Length: 5,
  428 + ImageData: "b",
  429 + Direction: domain.DirectionDown,
  430 + },
  431 + // ,
  432 + // {
  433 + // X: 1,
  434 + // Y: 1,
  435 + // Length: 5,
  436 + // ImageData: "c",
  437 + // Direction: domain.DirectionRight,
  438 + // },
  439 + // {
  440 + // X: 2,
  441 + // Y: 1,
  442 + // Length: 5,
  443 + // ImageData: "d",
  444 + // Direction: domain.DirectionRight,
  445 + // },
  446 + },
  447 + flag: Location{X: 0, Y: 0},
  448 + },
  449 + {
  450 + title: "测试用例5",
  451 + cells: []*domain.LayoutCell{
  452 + // 分组一
  453 + {
  454 + X: 0,
  455 + Y: 0,
  456 + Length: 5,
  457 + ImageData: "a",
  458 + Direction: domain.DirectionDown,
  459 + },
  460 + {
  461 + X: 0,
  462 + Y: 1,
  463 + Length: 6,
  464 + ImageData: "b",
  465 + Direction: domain.DirectionDown,
  466 + },
  467 + {
  468 + X: 1,
  469 + Y: 0,
  470 + Length: 1,
  471 + ImageData: "t",
  472 + Direction: domain.DirectionNone,
  473 + },
  474 + {
  475 + X: 1,
  476 + Y: 1,
  477 + Length: 1,
  478 + ImageData: "x",
  479 + Direction: domain.DirectionNone,
  480 + },
  481 + // ,
  482 + // {
  483 + // X: 1,
  484 + // Y: 1,
  485 + // Length: 5,
  486 + // ImageData: "c",
  487 + // Direction: domain.DirectionRight,
  488 + // },
  489 + // {
  490 + // X: 2,
  491 + // Y: 1,
  492 + // Length: 5,
  493 + // ImageData: "d",
  494 + // Direction: domain.DirectionRight,
  495 + // },
  496 + },
  497 + flag: Location{X: 0, Y: 0},
  498 + debug:true,
  499 + },
  500 + {
413 title: "测试用例6", 501 title: "测试用例6",
414 cells: []*domain.LayoutCell{ 502 cells: []*domain.LayoutCell{
415 // 分组一 503 // 分组一
@@ -445,13 +533,17 @@ func TestDataLayout(t *testing.T) { @@ -445,13 +533,17 @@ func TestDataLayout(t *testing.T) {
445 } 533 }
446 } 534 }
447 } 535 }
  536 + debugItem:= false
448 for _, input := range inputs { 537 for _, input := range inputs {
  538 + if debugItem && !input.debug{
  539 + continue
  540 + }
449 padding(input.cells) 541 padding(input.cells)
450 // 根据数据修改位移 542 // 根据数据修改位移
451 CellsLocationAdjust(input.cells) 543 CellsLocationAdjust(input.cells)
452 // 数据布局 544 // 数据布局
453 res := &domain.DataTable{} 545 res := &domain.DataTable{}
454 - res, err := DataLayout(res, nil, input.cells) 546 + res, err := DataLayout(res, input.cells)
455 if err != nil { 547 if err != nil {
456 assert.NoError(t, err) 548 assert.NoError(t, err)
457 } 549 }
@@ -500,6 +592,20 @@ b | | | | | | | | | @@ -500,6 +592,20 @@ b | | | | | | | | |
500 b | | | | | | | | | 592 b | | | | | | | | |
501 | | | | | d | d | d | d | d 593 | | | | | d | d | d | d | d
502 594
  595 +a | b
  596 +a | b
  597 +a | b
  598 +a | b
  599 +a | b
  600 +
  601 +a | b
  602 +a | b
  603 +a | b
  604 +a | b
  605 +a | b
  606 + | b
  607 +t | x
  608 +
503 a | | | | | 609 a | | | | |
504 | c | c | c | c | c 610 | c | c | c | c | c
505 | d | d | d | d | d 611 | d | d | d | d | d
@@ -40,7 +40,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl @@ -40,7 +40,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl
40 fields = MappingFields(mainTable, fields) 40 fields = MappingFields(mainTable, fields)
41 dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.MainTableField}) 41 dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.MainTableField})
42 manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.ManualField}) 42 manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.ManualField})
43 - table := NewTable(domain.SubTable, name, fields, mainTable.RowCount).WithContext(ctx) 43 + table := NewTable(domain.SubTable, name, fields, mainTable.RowCount).WithContext(ctx).WithPrefix(string(domain.SubTable))
44 table.DataFieldIndex = mainTable.DataFieldIndex 44 table.DataFieldIndex = mainTable.DataFieldIndex
45 table.DataFields = dataFields 45 table.DataFields = dataFields
46 table.ManualFields = manualFields 46 table.ManualFields = manualFields
@@ -2,6 +2,7 @@ package domainService @@ -2,6 +2,7 @@ package domainService
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 +
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
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/repository"
@@ -28,9 +29,6 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab @@ -28,9 +29,6 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
28 if err != nil { 29 if err != nil {
29 return nil, err 30 return nil, err
30 } 31 }
31 - if !(table.TableType == domain.MainTable.ToString() || table.TableType == domain.SubTable.ToString()) {  
32 - return nil, fmt.Errorf("主表、分表才允许复制")  
33 - }  
34 var mainTable *domain.Table 32 var mainTable *domain.Table
35 dataFields := table.DataFields 33 dataFields := table.DataFields
36 if table.TableType == domain.SubTable.ToString() { 34 if table.TableType == domain.SubTable.ToString() {
@@ -45,7 +43,10 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab @@ -45,7 +43,10 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
45 } 43 }
46 } 44 }
47 // 验证表名是否重复 45 // 验证表名是否重复
48 - duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName}) 46 + duplicateTable, err := tableRepository.FindOne(map[string]interface{}{
  47 + "context": ctx,
  48 + "tableName": tableName,
  49 + "tableTypes": domain.TableTypesToStringList(domain.MainTable, domain.SubTable, domain.SideTable)})
49 if err == nil && duplicateTable != nil { 50 if err == nil && duplicateTable != nil {
50 return nil, fmt.Errorf("表名称重复") 51 return nil, fmt.Errorf("表名称重复")
51 } 52 }
@@ -53,7 +54,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab @@ -53,7 +54,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
53 sideTable := NewCopyTable(domain.SideTable, tableName, dataFields, table.RowCount). 54 sideTable := NewCopyTable(domain.SideTable, tableName, dataFields, table.RowCount).
54 WithContext(ctx). 55 WithContext(ctx).
55 WithParentId(table.TableId). 56 WithParentId(table.TableId).
56 - WithDataFieldIndex(table.DataFieldIndex) 57 + WithDataFieldIndex(table.DataFieldIndex).
  58 + WithPrefix(domain.SideTable.ToString())
57 if sideTable, err = tableRepository.Save(sideTable); err != nil { 59 if sideTable, err = tableRepository.Save(sideTable); err != nil {
58 return nil, err 60 return nil, err
59 } 61 }
@@ -62,8 +62,9 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl @@ -62,8 +62,9 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl
62 return nil, err 62 return nil, err
63 } 63 }
64 } 64 }
65 -  
66 - // Log 65 + defer func() {
  66 + AsyncEvent(domain.NewEventTable(ctx, domain.TableDataEditEvent).WithTable(table))
  67 + }()
67 // 日志 68 // 日志
68 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &SubTableEditLog{ 69 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &SubTableEditLog{
69 LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.EditSubTable, ctx), 70 LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.EditSubTable, ctx),
@@ -13,6 +13,8 @@ func KeyExportTable(ctx *domain.Context, tableId int) string { @@ -13,6 +13,8 @@ func KeyExportTable(ctx *domain.Context, tableId int) string {
13 13
14 var ZeroCoreRedis *redis.Redis 14 var ZeroCoreRedis *redis.Redis
15 15
  16 +var NotFound = redis.ErrEmptyKey
  17 +
16 func InitZeroCoreRedis() { 18 func InitZeroCoreRedis() {
17 ZeroCoreRedis = redis.New(constant.REDIS_HOST+":"+constant.REDIS_PORT, redis.WithPass(constant.REDIS_AUTH)) 19 ZeroCoreRedis = redis.New(constant.REDIS_HOST+":"+constant.REDIS_PORT, redis.WithPass(constant.REDIS_AUTH))
18 } 20 }
@@ -3,8 +3,8 @@ package starrocks @@ -3,8 +3,8 @@ package starrocks
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "fmt" 5 "fmt"
6 - "github.com/google/uuid"  
7 "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"
8 "gorm.io/gorm" 8 "gorm.io/gorm"
9 "html" 9 "html"
10 "html/template" 10 "html/template"
@@ -15,8 +15,12 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { @@ -15,8 +15,12 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error {
15 for _, f := range fields { 15 for _, f := range fields {
16 if f.Field.Flag == domain.PKField && f.Value == "" { 16 if f.Field.Flag == domain.PKField && f.Value == "" {
17 //continue 17 //continue
18 - id, _ := uuid.NewUUID()  
19 - f.Value = id.String() 18 + //id, _ := uuid.NewUUID()
  19 + // idString := id.String()
  20 + // 需要调用分布式id生成
  21 + id, _ := utils.NewSnowflakeId()
  22 + idString := fmt.Sprintf("%d", id)
  23 + f.Value = idString
20 } 24 }
21 value[f.Field.SQLName] = f.TypeValue() 25 value[f.Field.SQLName] = f.TypeValue()
22 } 26 }
@@ -128,17 +128,23 @@ func (o *QueryOptions) AdditionOptionsByTable(table *domain.Table) *QueryOptions @@ -128,17 +128,23 @@ func (o *QueryOptions) AdditionOptionsByTable(table *domain.Table) *QueryOptions
128 } 128 }
129 129
130 type Condition struct { 130 type Condition struct {
  131 + params QueryOptions
131 domain.Condition 132 domain.Condition
132 Distinct bool 133 Distinct bool
133 DisableFormat bool 134 DisableFormat bool
134 } 135 }
135 136
136 func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) { 137 func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) {
  138 + c.SetParams(params)
137 if len(c.Like) > 0 { 139 if len(c.Like) > 0 {
138 q.Where(fmt.Sprintf("%v like '%%%v%%'", c.FormatIfNull(params, c.Field), c.Like)) 140 q.Where(fmt.Sprintf("%v like '%%%v%%'", c.FormatIfNull(params, c.Field), c.Like))
139 } 141 }
140 if len(c.In) > 0 { 142 if len(c.In) > 0 {
141 - q.Where(fmt.Sprintf("%v in %v", c.FormatIfNull(params, c.Field), c.InArgs(c.In))) 143 + if c.Field.SQLType == domain.Float.ToString() {
  144 + q.Where(fmt.Sprintf("%v in %v", c.CastType(c.Field.SQLName, domain.DECIMALV2.ToString()), c.InArgs(c.In)))
  145 + } else {
  146 + q.Where(fmt.Sprintf("%v in %v", c.CastType(c.FormatIfNull(params, c.Field), "string"), c.InArgs(c.In)))
  147 + }
142 } 148 }
143 if len(c.Ex) > 0 { 149 if len(c.Ex) > 0 {
144 in := c.InArgs(c.Ex) 150 in := c.InArgs(c.Ex)
@@ -166,13 +172,18 @@ func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) { @@ -166,13 +172,18 @@ func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) {
166 } 172 }
167 } 173 }
168 if c.Distinct { 174 if c.Distinct {
169 - q.Distinct(c.Field.SQLName) 175 + // 需要优化
  176 + q.Distinct(c.FormatFiled(c.Field))
170 } 177 }
171 if len(c.Order) > 0 { 178 if len(c.Order) > 0 {
172 q.Order(fmt.Sprintf("%v %v", c.Field.SQLName, c.Order)) 179 q.Order(fmt.Sprintf("%v %v", c.Field.SQLName, c.Order))
173 } 180 }
174 } 181 }
175 182
  183 +func (c *Condition) SetParams(params QueryOptions) {
  184 + c.params = params
  185 +}
  186 +
176 func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string { 187 func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string {
177 if params.Table != nil && params.Table.TableType == domain.ObjectDBTable { 188 if params.Table != nil && params.Table.TableType == domain.ObjectDBTable {
178 return f.SQLName 189 return f.SQLName
@@ -183,6 +194,42 @@ func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string { @@ -183,6 +194,42 @@ func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string {
183 return f.SQLName 194 return f.SQLName
184 } 195 }
185 196
  197 +func (c Condition) FormatFiled(f *domain.Field) string {
  198 + return formatFiled(c.Field)
  199 +}
  200 +
  201 +func (c Condition) CastType(sql, t string) string {
  202 + if c.params.Table != nil && c.params.Table.TableType == domain.ObjectDBTable {
  203 + return sql
  204 + }
  205 + return castType(sql, t)
  206 +}
  207 +
  208 +func (c Condition) CastTypeByField(f *domain.Field, t string) string {
  209 + if c.params.Table != nil && c.params.Table.TableType == domain.ObjectDBTable {
  210 + return f.SQLName
  211 + }
  212 + if f.SQLType == domain.Float.ToString() || f.SQLType == domain.DECIMAL279.ToString() {
  213 + return castTypeAlias(f.SQLName, domain.DECIMALV2.ToString())
  214 + }
  215 + return castType(f.SQLName, t)
  216 +}
  217 +
  218 +func formatFiled(f *domain.Field) string {
  219 + //if f.SQLType == domain.Float.ToString() || f.SQLType == domain.DECIMAL279.ToString() {
  220 + // return castTypeAlias(f.SQLName, domain.DECIMALV2.ToString())
  221 + //}
  222 + return f.SQLName
  223 +}
  224 +
  225 +func castType(sql, t string) string {
  226 + return fmt.Sprintf("cast(%v as %v)", sql, t)
  227 +}
  228 +
  229 +func castTypeAlias(sql, t string) string {
  230 + return fmt.Sprintf("cast(%v as %v) %v", sql, t, sql)
  231 +}
  232 +
186 var opMap = map[string]string{ 233 var opMap = map[string]string{
187 "=": "=", 234 "=": "=",
188 ">": ">", 235 ">": ">",
@@ -292,7 +339,7 @@ func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) { @@ -292,7 +339,7 @@ func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) {
292 fields = append(fields, "'' "+f.SQLName) 339 fields = append(fields, "'' "+f.SQLName)
293 continue 340 continue
294 } 341 }
295 - fields = append(fields, f.SQLName) 342 + fields = append(fields, formatFiled(f))
296 } 343 }
297 query.Select(strings.Join(fields, ",")) 344 query.Select(strings.Join(fields, ","))
298 } 345 }
@@ -117,3 +117,10 @@ func TestRound(t *testing.T) { @@ -117,3 +117,10 @@ func TestRound(t *testing.T) {
117 t.Logf("%.1f", Truncate(99.99, 1)) 117 t.Logf("%.1f", Truncate(99.99, 1))
118 t.Logf("%v", Truncate(99, 0)) 118 t.Logf("%v", Truncate(99, 0))
119 } 119 }
  120 +
  121 +func TestNewSnowflakeId(t *testing.T) {
  122 + id, _ := NewSnowflakeId()
  123 + for i := 0; i < 100; i++ {
  124 + t.Log(id / 2)
  125 + }
  126 +}