作者 yangfu

fix: field match bug

... ... @@ -99,14 +99,17 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea
}
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Create(ctx, newQuerySet); err != nil {
var querySet *domain.QuerySet
if querySet, err = svr.Create(ctx, newQuerySet); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
response := dto.QuerySetDto{}
response.Load(querySet)
return response, nil
}
// 依赖关系图
... ...
... ... @@ -253,7 +253,7 @@ func (gateway ApiByteLib) FormulasGenerate(param domain.ReqFormulasGenerate) (*d
url := gateway.Host() + "/formulas/generate"
method := "post"
var data FormulasGenerateResponse
request := NewFormulasGenerateRequest(param.Table, param.QueryComponents)
request := NewFormulasGenerateRequest(param.QuerySet, param.Table, param.QueryComponents)
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
... ...
... ... @@ -80,7 +80,7 @@ type (
}
)
func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest {
func NewFormulasGenerateRequest(querySet *domain.QuerySet, table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest {
var formatFormulaName = func(input string) string {
sep := fmt.Sprintf("_c%d", table.Context.CompanyId)
before := strings.Split(input, sep)
... ... @@ -95,13 +95,13 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q
FormulaType: 0,
FormulaConditions: make([]FormulaCondition, 0),
}
if table.TableType == domain.SchemaTable.ToString() {
if querySet.Type == domain.SchemaTable.ToString() {
req.FormulaType = 1
} else if table.TableType == domain.SubProcessTable.ToString() {
} else if querySet.Type == domain.SubProcessTable.ToString() {
req.FormulaType = 2
} else if table.TableType == domain.CalculateTable.ToString() {
} else if querySet.Type == domain.CalculateTable.ToString() {
req.FormulaType = 3
} else if table.TableType == domain.CalculateItem.ToString() {
} else if querySet.Type == domain.CalculateItem.ToString() {
req.FormulaType = 4
}
... ... @@ -141,17 +141,25 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
if queryComponent.Formula != nil {
formula := queryComponent.Formula
res.DatabaseTableName = formula.TableFields[0].TableSqlName
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: res.DatabaseTableName,
FieldSchema: NewFieldSchemaFromField(table.DataFields[0]),
CalculateExpression: formula.ExprSql,
CalculateFieldName: table.DataFields[0].SQLName,
})
for _, f := range queryComponent.Formula.TableFields {
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: f.TableSqlName,
FieldSchema: NewFieldSchema(f),
CalculateExpression: formula.ExprSql,
CalculateFieldName: table.DataFields[0].SQLName,
})
}
//res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
// DatabaseTableName: res.DatabaseTableName,
// FieldSchema: NewFieldSchemaFromField(table.DataFields[0]),
// CalculateExpression: formula.ExprSql,
// CalculateFieldName: table.DataFields[0].SQLName,
//})
}
if queryComponent.Aggregation != nil {
res.DatabaseTableName = queryComponent.MasterTable.SQLName
for _, f := range queryComponent.Aggregation.ValueFields {
tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name})
tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})
if !ok {
continue
}
... ... @@ -163,7 +171,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
})
}
for _, f := range queryComponent.Aggregation.RowFields {
tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name})
tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})
if !ok {
continue
}
... ... @@ -197,7 +205,11 @@ func NewFormulaSelectCondition(c domain.ConditionExpr) FormulaSelectCondition {
res.ConditionRightField.ConditionExpression = " null "
}
if c.OperatorSymbol == "!=" && strings.ToLower(c.FieldRight.ExprSql) == "null" {
res.ConditionOperator = "is not"
res.ConditionOperator = " is not "
res.ConditionRightField.ConditionExpression = "null"
}
if c.OperatorSymbol == "<>" && strings.ToLower(c.FieldRight.ExprSql) == "null" {
res.ConditionOperator = " is not "
res.ConditionRightField.ConditionExpression = "null"
}
return res
... ...
... ... @@ -34,7 +34,7 @@ func NewQuerySetService(transactionContext *pgTransaction.TransactionContext) (*
}
}
func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) error {
func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*domain.QuerySet, error) {
newQuerySet := &domain.QuerySet{
Type: qs.Type,
Flag: qs.Flag,
... ... @@ -59,24 +59,24 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) err
if qs.ParentId > 0 {
parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": qs.ParentId})
if err != nil {
return ErrQuerySetParentNotExists
return nil, ErrQuerySetParentNotExists
}
if parent.Type != qs.Type {
return ErrQuerySetInvalidType
return nil, ErrQuerySetInvalidType
}
options["parentId"] = qs.ParentId
}
// check duplicate name
if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == qs.Name {
return ErrQuerySetNameExists
return nil, ErrQuerySetNameExists
}
// current sort
newQuerySet.Sort, err = dao.QuerySetCurrentSort(ptr.transactionContext, qs.Type, qs.ParentId)
if err != nil {
return err
return nil, err
}
if newQuerySet, err = querySetRepository.Save(newQuerySet); err != nil {
return err
return nil, err
}
// 日志
... ... @@ -84,9 +84,9 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) err
LogEntry: domain.NewLogEntry(newQuerySet.Name, qs.Type, domain.UnKnown, ctx),
Qs: newQuerySet,
}); err != nil {
return err
return nil, err
}
return nil
return newQuerySet, nil
}
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,
var table *domain.Table = NewCopyTable(domain.TableType(domain.TemporaryTable), querySet.Name, domain.RangeFields(fields, domain.ChangeFieldFlag), 0).
WithContext(ctx).
WithPrefix(strings.ToLower(string(domain.TemporaryTable)))
if querySet.Type == domain.CalculateTable.ToString() {
table.PK = nil
}
// 循环依赖判断
if err = ptr.validDependentCircle(ctx, querySet, queryComponents); err != nil {
return nil, err
... ... @@ -726,6 +729,9 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateTable(ctx *domain.Context, qu
queryComponent.MasterTable = masterTable
fields := make([]*domain.Field, 0)
aggregationFields := queryComponent.Aggregation.AggregationFields()
if len(aggregationFields) == 0 {
return nil, fmt.Errorf("行、值不能同时为空")
}
selectedFields := make([]string, 0)
for index, f := range aggregationFields {
// 数值类型转浮点类型, 兼容类似表达式 1 * 1.1
... ...