...
|
...
|
@@ -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,9 +59,28 @@ 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 {
|
|
|
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)
|
...
|
...
|
@@ -75,15 +95,23 @@ 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 {
|
|
|
} else if querySet.Type == domain.SubProcessTable.ToString() {
|
|
|
req.FormulaType = 2
|
|
|
} else if querySet.Type == domain.CalculateTable.ToString() {
|
|
|
req.FormulaType = 3
|
|
|
} else if querySet.Type == 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,75 @@ 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
|
|
|
exprSql := formula.ExprSql
|
|
|
if queryComponent.Formula.MixTableModel() {
|
|
|
exprSql = queryComponent.Formula.Complete()
|
|
|
}
|
|
|
for _, f := range queryComponent.Formula.TableFields {
|
|
|
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
|
|
|
DatabaseTableName: f.TableSqlName,
|
|
|
FieldSchema: NewFieldSchema(f),
|
|
|
CalculateExpression: 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 i, f := range queryComponent.Aggregation.ValueFields {
|
|
|
tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
if i == 0 {
|
|
|
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
|
|
|
DatabaseTableName: queryComponent.MasterTable.SQLName,
|
|
|
FieldSchema: NewFieldSchemaFromField(&domain.Field{
|
|
|
Name: "序号",
|
|
|
SQLName: "id",
|
|
|
SQLType: domain.String.ToString(),
|
|
|
}),
|
|
|
CalculateExpression: fmt.Sprintf("max(%s.%s)", queryComponent.MasterTable.SQLName, "id"),
|
|
|
CalculateFieldName: "id",
|
|
|
})
|
|
|
}
|
|
|
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.DisplayName})
|
|
|
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,
|
...
|
...
|
@@ -124,7 +221,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
|
...
|
...
|
@@ -162,6 +263,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,
|
...
|
...
|
|