...
|
...
|
@@ -12,6 +12,7 @@ type ( |
|
|
FormulaName string `json:"formulaName"`
|
|
|
FormulaType int `json:"formulaType"` //公式类型 1.方案2.子过程
|
|
|
FormulaConditions []FormulaCondition `json:"formulaConditions"`
|
|
|
FormulaCalculate *FormulaCalculate `json:"formulaCalculate"`
|
|
|
}
|
|
|
|
|
|
FormulasGenerateResponse struct {
|
...
|
...
|
@@ -58,6 +59,25 @@ type ( |
|
|
FieldSchema FieldSchema `json:"fieldSchema"`
|
|
|
ConditionExpression string `json:"conditionExpression"`
|
|
|
}
|
|
|
|
|
|
FormulaCalculate struct {
|
|
|
DatabaseTableName string `json:"databaseTableName"`
|
|
|
FormulaCalculateFields []*FormulaCalculateField `json:"formulaCalculateFields"`
|
|
|
FormulaGroupFields []*FormulaGroupField `json:"formulaGroupFields"`
|
|
|
}
|
|
|
FormulaCalculateField struct {
|
|
|
DatabaseTableName string `json:"databaseTableName"`
|
|
|
FieldSchema FieldSchema `json:"fieldSchema"`
|
|
|
CalculateExpression string `json:"calculateExpression"`
|
|
|
// 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称)
|
|
|
CalculateFieldName string `json:"calculateFieldName"`
|
|
|
}
|
|
|
FormulaGroupField struct {
|
|
|
DatabaseTableName string `json:"databaseTableName"`
|
|
|
FieldSchema FieldSchema `json:"fieldSchema"`
|
|
|
// 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称)
|
|
|
GroupFieldName string `json:"groupFieldName"`
|
|
|
}
|
|
|
)
|
|
|
|
|
|
func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest {
|
...
|
...
|
@@ -77,13 +97,21 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q |
|
|
}
|
|
|
if table.TableType == domain.SchemaTable.ToString() {
|
|
|
req.FormulaType = 1
|
|
|
} else {
|
|
|
} else if table.TableType == domain.SubProcessTable.ToString() {
|
|
|
req.FormulaType = 2
|
|
|
} else if table.TableType == domain.CalculateTable.ToString() {
|
|
|
req.FormulaType = 3
|
|
|
} else if table.TableType == domain.CalculateItem.ToString() {
|
|
|
req.FormulaType = 4
|
|
|
}
|
|
|
|
|
|
if req.FormulaType == 1 || req.FormulaType == 2 {
|
|
|
for i := range queryComponents {
|
|
|
req.FormulaConditions = append(req.FormulaConditions, NewFormulaCondition(queryComponents[i]))
|
|
|
}
|
|
|
} else {
|
|
|
req.FormulaCalculate = NewFormulaCalculate(table, queryComponents[0])
|
|
|
}
|
|
|
|
|
|
return req
|
|
|
}
|
...
|
...
|
@@ -104,6 +132,51 @@ func NewFormulaCondition(queryComponent *domain.QueryComponent) FormulaCondition |
|
|
return res
|
|
|
}
|
|
|
|
|
|
func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryComponent) *FormulaCalculate {
|
|
|
var res = &FormulaCalculate{
|
|
|
DatabaseTableName: "",
|
|
|
FormulaGroupFields: make([]*FormulaGroupField, 0),
|
|
|
FormulaCalculateFields: make([]*FormulaCalculateField, 0),
|
|
|
}
|
|
|
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,
|
|
|
})
|
|
|
}
|
|
|
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})
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
|
|
|
DatabaseTableName: queryComponent.MasterTable.SQLName,
|
|
|
FieldSchema: NewFieldSchemaFromField(f.Field),
|
|
|
CalculateExpression: f.Expr.ExprSql,
|
|
|
CalculateFieldName: tableField.SQLName,
|
|
|
})
|
|
|
}
|
|
|
for _, f := range queryComponent.Aggregation.RowFields {
|
|
|
tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name})
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
res.FormulaGroupFields = append(res.FormulaGroupFields, &FormulaGroupField{
|
|
|
DatabaseTableName: queryComponent.MasterTable.SQLName,
|
|
|
FieldSchema: NewFieldSchemaFromField(f.Field),
|
|
|
GroupFieldName: tableField.SQLName,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
func NewFormulaSelectFields(t *domain.QueryComponentTable) FormulaSelectFields {
|
|
|
var res = FormulaSelectFields{
|
|
|
DatabaseTableName: t.SQLName,
|
...
|
...
|
@@ -162,6 +235,17 @@ func NewFieldSchema(f domain.TableField) FieldSchema { |
|
|
return res
|
|
|
}
|
|
|
|
|
|
func NewFieldSchemaFromField(f *domain.Field) FieldSchema {
|
|
|
var res = FieldSchema{
|
|
|
FieldZhName: f.Name,
|
|
|
FieldEnName: f.SQLName,
|
|
|
FieldType: f.SQLType,
|
|
|
FieldDescription: "",
|
|
|
IsAllowNull: true,
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule {
|
|
|
var res = FormulaDataHandleRule{
|
|
|
RuleType: 1,
|
...
|
...
|
|