正在显示
4 个修改的文件
包含
46 行增加
和
25 行删除
@@ -99,14 +99,17 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea | @@ -99,14 +99,17 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea | ||
99 | } | 99 | } |
100 | 100 | ||
101 | svr, _ := factory.FastQuerySetServices(transactionContext) | 101 | svr, _ := factory.FastQuerySetServices(transactionContext) |
102 | - if err := svr.Create(ctx, newQuerySet); err != nil { | 102 | + var querySet *domain.QuerySet |
103 | + if querySet, err = svr.Create(ctx, newQuerySet); err != nil { | ||
103 | return nil, factory.FastError(err) | 104 | return nil, factory.FastError(err) |
104 | } | 105 | } |
105 | 106 | ||
106 | if err := transactionContext.CommitTransaction(); err != nil { | 107 | if err := transactionContext.CommitTransaction(); err != nil { |
107 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 108 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
108 | } | 109 | } |
109 | - return struct{}{}, nil | 110 | + response := dto.QuerySetDto{} |
111 | + response.Load(querySet) | ||
112 | + return response, nil | ||
110 | } | 113 | } |
111 | 114 | ||
112 | // 依赖关系图 | 115 | // 依赖关系图 |
@@ -253,7 +253,7 @@ func (gateway ApiByteLib) FormulasGenerate(param domain.ReqFormulasGenerate) (*d | @@ -253,7 +253,7 @@ func (gateway ApiByteLib) FormulasGenerate(param domain.ReqFormulasGenerate) (*d | ||
253 | url := gateway.Host() + "/formulas/generate" | 253 | url := gateway.Host() + "/formulas/generate" |
254 | method := "post" | 254 | method := "post" |
255 | var data FormulasGenerateResponse | 255 | var data FormulasGenerateResponse |
256 | - request := NewFormulasGenerateRequest(param.Table, param.QueryComponents) | 256 | + request := NewFormulasGenerateRequest(param.QuerySet, param.Table, param.QueryComponents) |
257 | err := gateway.FastDoRequest(url, method, request, &data) | 257 | err := gateway.FastDoRequest(url, method, request, &data) |
258 | if err != nil { | 258 | if err != nil { |
259 | return nil, err | 259 | return nil, err |
@@ -80,7 +80,7 @@ type ( | @@ -80,7 +80,7 @@ type ( | ||
80 | } | 80 | } |
81 | ) | 81 | ) |
82 | 82 | ||
83 | -func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest { | 83 | +func NewFormulasGenerateRequest(querySet *domain.QuerySet, table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest { |
84 | var formatFormulaName = func(input string) string { | 84 | var formatFormulaName = func(input string) string { |
85 | sep := fmt.Sprintf("_c%d", table.Context.CompanyId) | 85 | sep := fmt.Sprintf("_c%d", table.Context.CompanyId) |
86 | before := strings.Split(input, sep) | 86 | before := strings.Split(input, sep) |
@@ -95,13 +95,13 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q | @@ -95,13 +95,13 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q | ||
95 | FormulaType: 0, | 95 | FormulaType: 0, |
96 | FormulaConditions: make([]FormulaCondition, 0), | 96 | FormulaConditions: make([]FormulaCondition, 0), |
97 | } | 97 | } |
98 | - if table.TableType == domain.SchemaTable.ToString() { | 98 | + if querySet.Type == domain.SchemaTable.ToString() { |
99 | req.FormulaType = 1 | 99 | req.FormulaType = 1 |
100 | - } else if table.TableType == domain.SubProcessTable.ToString() { | 100 | + } else if querySet.Type == domain.SubProcessTable.ToString() { |
101 | req.FormulaType = 2 | 101 | req.FormulaType = 2 |
102 | - } else if table.TableType == domain.CalculateTable.ToString() { | 102 | + } else if querySet.Type == domain.CalculateTable.ToString() { |
103 | req.FormulaType = 3 | 103 | req.FormulaType = 3 |
104 | - } else if table.TableType == domain.CalculateItem.ToString() { | 104 | + } else if querySet.Type == domain.CalculateItem.ToString() { |
105 | req.FormulaType = 4 | 105 | req.FormulaType = 4 |
106 | } | 106 | } |
107 | 107 | ||
@@ -141,17 +141,25 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | @@ -141,17 +141,25 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | ||
141 | if queryComponent.Formula != nil { | 141 | if queryComponent.Formula != nil { |
142 | formula := queryComponent.Formula | 142 | formula := queryComponent.Formula |
143 | res.DatabaseTableName = formula.TableFields[0].TableSqlName | 143 | res.DatabaseTableName = formula.TableFields[0].TableSqlName |
144 | - res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
145 | - DatabaseTableName: res.DatabaseTableName, | ||
146 | - FieldSchema: NewFieldSchemaFromField(table.DataFields[0]), | ||
147 | - CalculateExpression: formula.ExprSql, | ||
148 | - CalculateFieldName: table.DataFields[0].SQLName, | ||
149 | - }) | 144 | + for _, f := range queryComponent.Formula.TableFields { |
145 | + res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
146 | + DatabaseTableName: f.TableSqlName, | ||
147 | + FieldSchema: NewFieldSchema(f), | ||
148 | + CalculateExpression: formula.ExprSql, | ||
149 | + CalculateFieldName: table.DataFields[0].SQLName, | ||
150 | + }) | ||
151 | + } | ||
152 | + //res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
153 | + // DatabaseTableName: res.DatabaseTableName, | ||
154 | + // FieldSchema: NewFieldSchemaFromField(table.DataFields[0]), | ||
155 | + // CalculateExpression: formula.ExprSql, | ||
156 | + // CalculateFieldName: table.DataFields[0].SQLName, | ||
157 | + //}) | ||
150 | } | 158 | } |
151 | if queryComponent.Aggregation != nil { | 159 | if queryComponent.Aggregation != nil { |
152 | res.DatabaseTableName = queryComponent.MasterTable.SQLName | 160 | res.DatabaseTableName = queryComponent.MasterTable.SQLName |
153 | for _, f := range queryComponent.Aggregation.ValueFields { | 161 | for _, f := range queryComponent.Aggregation.ValueFields { |
154 | - tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name}) | 162 | + tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName}) |
155 | if !ok { | 163 | if !ok { |
156 | continue | 164 | continue |
157 | } | 165 | } |
@@ -163,7 +171,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | @@ -163,7 +171,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | ||
163 | }) | 171 | }) |
164 | } | 172 | } |
165 | for _, f := range queryComponent.Aggregation.RowFields { | 173 | for _, f := range queryComponent.Aggregation.RowFields { |
166 | - tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name}) | 174 | + tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName}) |
167 | if !ok { | 175 | if !ok { |
168 | continue | 176 | continue |
169 | } | 177 | } |
@@ -197,7 +205,11 @@ func NewFormulaSelectCondition(c domain.ConditionExpr) FormulaSelectCondition { | @@ -197,7 +205,11 @@ func NewFormulaSelectCondition(c domain.ConditionExpr) FormulaSelectCondition { | ||
197 | res.ConditionRightField.ConditionExpression = " null " | 205 | res.ConditionRightField.ConditionExpression = " null " |
198 | } | 206 | } |
199 | if c.OperatorSymbol == "!=" && strings.ToLower(c.FieldRight.ExprSql) == "null" { | 207 | if c.OperatorSymbol == "!=" && strings.ToLower(c.FieldRight.ExprSql) == "null" { |
200 | - res.ConditionOperator = "is not" | 208 | + res.ConditionOperator = " is not " |
209 | + res.ConditionRightField.ConditionExpression = "null" | ||
210 | + } | ||
211 | + if c.OperatorSymbol == "<>" && strings.ToLower(c.FieldRight.ExprSql) == "null" { | ||
212 | + res.ConditionOperator = " is not " | ||
201 | res.ConditionRightField.ConditionExpression = "null" | 213 | res.ConditionRightField.ConditionExpression = "null" |
202 | } | 214 | } |
203 | return res | 215 | return res |
@@ -34,7 +34,7 @@ func NewQuerySetService(transactionContext *pgTransaction.TransactionContext) (* | @@ -34,7 +34,7 @@ func NewQuerySetService(transactionContext *pgTransaction.TransactionContext) (* | ||
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | -func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) error { | 37 | +func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*domain.QuerySet, error) { |
38 | newQuerySet := &domain.QuerySet{ | 38 | newQuerySet := &domain.QuerySet{ |
39 | Type: qs.Type, | 39 | Type: qs.Type, |
40 | Flag: qs.Flag, | 40 | Flag: qs.Flag, |
@@ -59,24 +59,24 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) err | @@ -59,24 +59,24 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) err | ||
59 | if qs.ParentId > 0 { | 59 | if qs.ParentId > 0 { |
60 | parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": qs.ParentId}) | 60 | parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": qs.ParentId}) |
61 | if err != nil { | 61 | if err != nil { |
62 | - return ErrQuerySetParentNotExists | 62 | + return nil, ErrQuerySetParentNotExists |
63 | } | 63 | } |
64 | if parent.Type != qs.Type { | 64 | if parent.Type != qs.Type { |
65 | - return ErrQuerySetInvalidType | 65 | + return nil, ErrQuerySetInvalidType |
66 | } | 66 | } |
67 | options["parentId"] = qs.ParentId | 67 | options["parentId"] = qs.ParentId |
68 | } | 68 | } |
69 | // check duplicate name | 69 | // check duplicate name |
70 | if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == qs.Name { | 70 | if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == qs.Name { |
71 | - return ErrQuerySetNameExists | 71 | + return nil, ErrQuerySetNameExists |
72 | } | 72 | } |
73 | // current sort | 73 | // current sort |
74 | newQuerySet.Sort, err = dao.QuerySetCurrentSort(ptr.transactionContext, qs.Type, qs.ParentId) | 74 | newQuerySet.Sort, err = dao.QuerySetCurrentSort(ptr.transactionContext, qs.Type, qs.ParentId) |
75 | if err != nil { | 75 | if err != nil { |
76 | - return err | 76 | + return nil, err |
77 | } | 77 | } |
78 | if newQuerySet, err = querySetRepository.Save(newQuerySet); err != nil { | 78 | if newQuerySet, err = querySetRepository.Save(newQuerySet); err != nil { |
79 | - return err | 79 | + return nil, err |
80 | } | 80 | } |
81 | 81 | ||
82 | // 日志 | 82 | // 日志 |
@@ -84,9 +84,9 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) err | @@ -84,9 +84,9 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) err | ||
84 | LogEntry: domain.NewLogEntry(newQuerySet.Name, qs.Type, domain.UnKnown, ctx), | 84 | LogEntry: domain.NewLogEntry(newQuerySet.Name, qs.Type, domain.UnKnown, ctx), |
85 | Qs: newQuerySet, | 85 | Qs: newQuerySet, |
86 | }); err != nil { | 86 | }); err != nil { |
87 | - return err | 87 | + return nil, err |
88 | } | 88 | } |
89 | - return nil | 89 | + return newQuerySet, nil |
90 | } | 90 | } |
91 | 91 | ||
92 | func (ptr *QuerySetService) Update(ctx *domain.Context, querySetId int, queryComponents []*domain.QueryComponent) error { | 92 | func (ptr *QuerySetService) Update(ctx *domain.Context, querySetId int, queryComponents []*domain.QueryComponent) error { |
@@ -277,6 +277,9 @@ func (ptr *QuerySetService) PreviewPrepare(ctx *domain.Context, querySetId int, | @@ -277,6 +277,9 @@ func (ptr *QuerySetService) PreviewPrepare(ctx *domain.Context, querySetId int, | ||
277 | var table *domain.Table = NewCopyTable(domain.TableType(domain.TemporaryTable), querySet.Name, domain.RangeFields(fields, domain.ChangeFieldFlag), 0). | 277 | var table *domain.Table = NewCopyTable(domain.TableType(domain.TemporaryTable), querySet.Name, domain.RangeFields(fields, domain.ChangeFieldFlag), 0). |
278 | WithContext(ctx). | 278 | WithContext(ctx). |
279 | WithPrefix(strings.ToLower(string(domain.TemporaryTable))) | 279 | WithPrefix(strings.ToLower(string(domain.TemporaryTable))) |
280 | + if querySet.Type == domain.CalculateTable.ToString() { | ||
281 | + table.PK = nil | ||
282 | + } | ||
280 | // 循环依赖判断 | 283 | // 循环依赖判断 |
281 | if err = ptr.validDependentCircle(ctx, querySet, queryComponents); err != nil { | 284 | if err = ptr.validDependentCircle(ctx, querySet, queryComponents); err != nil { |
282 | return nil, err | 285 | return nil, err |
@@ -726,6 +729,9 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateTable(ctx *domain.Context, qu | @@ -726,6 +729,9 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateTable(ctx *domain.Context, qu | ||
726 | queryComponent.MasterTable = masterTable | 729 | queryComponent.MasterTable = masterTable |
727 | fields := make([]*domain.Field, 0) | 730 | fields := make([]*domain.Field, 0) |
728 | aggregationFields := queryComponent.Aggregation.AggregationFields() | 731 | aggregationFields := queryComponent.Aggregation.AggregationFields() |
732 | + if len(aggregationFields) == 0 { | ||
733 | + return nil, fmt.Errorf("行、值不能同时为空") | ||
734 | + } | ||
729 | selectedFields := make([]string, 0) | 735 | selectedFields := make([]string, 0) |
730 | for index, f := range aggregationFields { | 736 | for index, f := range aggregationFields { |
731 | // 数值类型转浮点类型, 兼容类似表达式 1 * 1.1 | 737 | // 数值类型转浮点类型, 兼容类似表达式 1 * 1.1 |
-
请 注册 或 登录 后发表评论