正在显示
12 个修改的文件
包含
396 行增加
和
16 行删除
| @@ -15,7 +15,7 @@ import ( | @@ -15,7 +15,7 @@ import ( | ||
| 15 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" | 15 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" |
| 16 | ) | 16 | ) |
| 17 | 17 | ||
| 18 | -const Version = "v1.0.1" | 18 | +const Version = "v1.2.0" |
| 19 | 19 | ||
| 20 | func main() { | 20 | func main() { |
| 21 | defer func() { | 21 | defer func() { |
| @@ -13,6 +13,8 @@ type QuerySetDetailDto struct { | @@ -13,6 +13,8 @@ type QuerySetDetailDto struct { | ||
| 13 | Name string `json:"name"` | 13 | Name string `json:"name"` |
| 14 | // 查询组件 | 14 | // 查询组件 |
| 15 | QueryComponents []*domain.QueryComponent `json:"queryComponents"` | 15 | QueryComponents []*domain.QueryComponent `json:"queryComponents"` |
| 16 | + // 查询集绑定的表 | ||
| 17 | + TableId int `json:"tableId"` | ||
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | func (d *QuerySetDetailDto) Load(m *domain.QuerySet) *QuerySetDetailDto { | 20 | func (d *QuerySetDetailDto) Load(m *domain.QuerySet) *QuerySetDetailDto { |
| @@ -21,5 +23,8 @@ func (d *QuerySetDetailDto) Load(m *domain.QuerySet) *QuerySetDetailDto { | @@ -21,5 +23,8 @@ func (d *QuerySetDetailDto) Load(m *domain.QuerySet) *QuerySetDetailDto { | ||
| 21 | d.Flag = m.Flag | 23 | d.Flag = m.Flag |
| 22 | d.Name = m.Name | 24 | d.Name = m.Name |
| 23 | d.QueryComponents = m.QueryComponents | 25 | d.QueryComponents = m.QueryComponents |
| 26 | + if m.QuerySetInfo != nil { | ||
| 27 | + d.TableId = m.QuerySetInfo.BindTableId | ||
| 28 | + } | ||
| 24 | return d | 29 | return d |
| 25 | } | 30 | } |
| @@ -426,7 +426,6 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | @@ -426,7 +426,6 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | ||
| 426 | if err := cmd.ValidateCommand(); err != nil { | 426 | if err := cmd.ValidateCommand(); err != nil { |
| 427 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 427 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 428 | } | 428 | } |
| 429 | - var result string = "成功" | ||
| 430 | 429 | ||
| 431 | set := collection.NewSet() | 430 | set := collection.NewSet() |
| 432 | for _, f := range cmd.TableFields { | 431 | for _, f := range cmd.TableFields { |
| @@ -439,11 +438,11 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | @@ -439,11 +438,11 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | ||
| 439 | sql += " limit 1" | 438 | sql += " limit 1" |
| 440 | tx := starrocks.DB.Exec(sql) | 439 | tx := starrocks.DB.Exec(sql) |
| 441 | if tx.Error != nil { | 440 | if tx.Error != nil { |
| 442 | - result = tx.Error.Error() | ||
| 443 | - } | ||
| 444 | return map[string]string{ | 441 | return map[string]string{ |
| 445 | - "result": result, | 442 | + "result": tx.Error.Error(), |
| 446 | }, nil | 443 | }, nil |
| 444 | + } | ||
| 445 | + return struct{}{}, nil | ||
| 447 | } | 446 | } |
| 448 | 447 | ||
| 449 | func NewTableService(options map[string]interface{}) *TableService { | 448 | func NewTableService(options map[string]interface{}) *TableService { |
| @@ -12,6 +12,8 @@ type ByteLibService interface { | @@ -12,6 +12,8 @@ type ByteLibService interface { | ||
| 12 | CancelFile(param ReqCancelFile) (*DataCancelFile, error) | 12 | CancelFile(param ReqCancelFile) (*DataCancelFile, error) |
| 13 | EditTableData(param ReqEditTableData) (*DataEditTableData, error) | 13 | EditTableData(param ReqEditTableData) (*DataEditTableData, error) |
| 14 | FieldOptionalValues(param ReqFieldOptionalValues) (*DataFieldOptionalValues, error) | 14 | FieldOptionalValues(param ReqFieldOptionalValues) (*DataFieldOptionalValues, error) |
| 15 | + FormulasGenerate(param ReqFormulasGenerate) (*DataFormulasGenerate, error) | ||
| 16 | + FormulasClear(param ReqFormulasClear) (*DataFormulasClear, error) | ||
| 15 | } | 17 | } |
| 16 | 18 | ||
| 17 | type ( | 19 | type ( |
| @@ -267,3 +269,24 @@ func ToFields(fields []*Field) []*Field { | @@ -267,3 +269,24 @@ func ToFields(fields []*Field) []*Field { | ||
| 267 | // } | 269 | // } |
| 268 | // return result | 270 | // return result |
| 269 | //} | 271 | //} |
| 272 | + | ||
| 273 | +type ( | ||
| 274 | + ReqFormulasGenerate struct { | ||
| 275 | + QuerySet *QuerySet | ||
| 276 | + Table *Table | ||
| 277 | + QueryComponents []*QueryComponent | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + DataFormulasGenerate struct { | ||
| 281 | + FormulaName string `json:"formulaName"` | ||
| 282 | + } | ||
| 283 | +) | ||
| 284 | + | ||
| 285 | +type ( | ||
| 286 | + ReqFormulasClear struct { | ||
| 287 | + QuerySetId int | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + DataFormulasClear struct { | ||
| 291 | + } | ||
| 292 | +) |
| @@ -259,3 +259,16 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} { | @@ -259,3 +259,16 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} { | ||
| 259 | return output | 259 | return output |
| 260 | } | 260 | } |
| 261 | } | 261 | } |
| 262 | + | ||
| 263 | +func RangeFields(fields []*Field, set ...func(*Field)) []*Field { | ||
| 264 | + for i := range fields { | ||
| 265 | + for j := range set { | ||
| 266 | + set[j](fields[i]) | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + return fields | ||
| 270 | +} | ||
| 271 | + | ||
| 272 | +func ChangeFieldFlag(f *Field) { | ||
| 273 | + f.Flag = MainTableField | ||
| 274 | +} |
| @@ -97,7 +97,9 @@ func ValidQuerySetFlag(t string) error { | @@ -97,7 +97,9 @@ func ValidQuerySetFlag(t string) error { | ||
| 97 | 97 | ||
| 98 | func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent) []int { | 98 | func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent) []int { |
| 99 | set := collection.NewSet() | 99 | set := collection.NewSet() |
| 100 | + | ||
| 100 | for i := range queryComponents { | 101 | for i := range queryComponents { |
| 102 | + set.AddInt(queryComponents[i].MasterTable.TableId) | ||
| 101 | for _, c := range queryComponents[i].Conditions { | 103 | for _, c := range queryComponents[i].Conditions { |
| 102 | for _, f := range c.FieldLeft.TableFields { | 104 | for _, f := range c.FieldLeft.TableFields { |
| 103 | set.AddInt(f.TableId) | 105 | set.AddInt(f.TableId) |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | +import "fmt" | ||
| 4 | + | ||
| 3 | var ( | 5 | var ( |
| 4 | SchemaTable TableType = "Schema" | 6 | SchemaTable TableType = "Schema" |
| 5 | SubProcessTable TableType = "SubProcess" | 7 | SubProcessTable TableType = "SubProcess" |
| @@ -97,6 +99,11 @@ type TableField struct { | @@ -97,6 +99,11 @@ type TableField struct { | ||
| 97 | TableSqlName string `json:"tableSqlName"` | 99 | TableSqlName string `json:"tableSqlName"` |
| 98 | FieldName string `json:"fieldName"` | 100 | FieldName string `json:"fieldName"` |
| 99 | FieldSqlName string `json:"fieldSqlName"` | 101 | FieldSqlName string `json:"fieldSqlName"` |
| 102 | + FieldSQLType string `json:"fieldSqlType"` | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +func (f TableField) String() string { | ||
| 106 | + return fmt.Sprintf("%s.%s", f.TableSqlName, f.FieldSqlName) | ||
| 100 | } | 107 | } |
| 101 | 108 | ||
| 102 | type QueryComponentTable struct { | 109 | type QueryComponentTable struct { |
| @@ -248,3 +248,33 @@ func (gateway ApiByteLib) FieldOptionalValues(param domain.ReqFieldOptionalValue | @@ -248,3 +248,33 @@ func (gateway ApiByteLib) FieldOptionalValues(param domain.ReqFieldOptionalValue | ||
| 248 | } | 248 | } |
| 249 | return &response, nil | 249 | return &response, nil |
| 250 | } | 250 | } |
| 251 | + | ||
| 252 | +func (gateway ApiByteLib) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) { | ||
| 253 | + url := gateway.Host() + "/formulas/generate" | ||
| 254 | + method := "post" | ||
| 255 | + var data FormulasGenerateResponse | ||
| 256 | + request := NewFormulasGenerateRequest(param.Table, param.QueryComponents) | ||
| 257 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
| 258 | + if err != nil { | ||
| 259 | + return nil, err | ||
| 260 | + } | ||
| 261 | + var response = domain.DataFormulasGenerate{ | ||
| 262 | + FormulaName: data.FormulaName, | ||
| 263 | + } | ||
| 264 | + return &response, nil | ||
| 265 | +} | ||
| 266 | + | ||
| 267 | +func (gateway ApiByteLib) FormulasClear(param domain.ReqFormulasClear) (*domain.DataFormulasClear, error) { | ||
| 268 | + url := gateway.Host() + "/formulas/generate" | ||
| 269 | + method := "post" | ||
| 270 | + var data FormulasGenerateResponse | ||
| 271 | + request := FormulasClearRequest{ | ||
| 272 | + FormulaId: intToString(param.QuerySetId), | ||
| 273 | + } | ||
| 274 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
| 275 | + if err != nil { | ||
| 276 | + return nil, err | ||
| 277 | + } | ||
| 278 | + var response = domain.DataFormulasClear{} | ||
| 279 | + return &response, nil | ||
| 280 | +} |
| @@ -309,6 +309,7 @@ type ( | @@ -309,6 +309,7 @@ type ( | ||
| 309 | SplitTableName string `json:"splitTableName"` | 309 | SplitTableName string `json:"splitTableName"` |
| 310 | DatabaseTableFieldSchemas []FieldSchema `json:"databaseTableFieldSchemas"` | 310 | DatabaseTableFieldSchemas []FieldSchema `json:"databaseTableFieldSchemas"` |
| 311 | SplitTableFieldSchemas []FieldSchema `json:"splitTableFieldSchemas"` | 311 | SplitTableFieldSchemas []FieldSchema `json:"splitTableFieldSchemas"` |
| 312 | + ManuallyFieldSchemas []FieldSchema `json:"manuallyFieldSchemas"` | ||
| 312 | } | 313 | } |
| 313 | 314 | ||
| 314 | SplitTableResponse struct{} | 315 | SplitTableResponse struct{} |
| @@ -329,7 +330,8 @@ func NewSplitTableRequest(param domain.ReqSplitTable) SplitTableRequest { | @@ -329,7 +330,8 @@ func NewSplitTableRequest(param domain.ReqSplitTable) SplitTableRequest { | ||
| 329 | DatabaseTableName: param.FromTable.SQLName, | 330 | DatabaseTableName: param.FromTable.SQLName, |
| 330 | SplitTableName: param.ToSubTable.SQLName, | 331 | SplitTableName: param.ToSubTable.SQLName, |
| 331 | DatabaseTableFieldSchemas: ToFieldSchemas(param.FromTable.DataFields), | 332 | DatabaseTableFieldSchemas: ToFieldSchemas(param.FromTable.DataFields), |
| 332 | - SplitTableFieldSchemas: ToFieldSchemas(param.ToSubTable.DataFields), | 333 | + SplitTableFieldSchemas: ToFieldSchemas(param.ToSubTable.Fields(false)), |
| 334 | + ManuallyFieldSchemas: ToFieldSchemas(param.ToSubTable.ManualFields), | ||
| 333 | } | 335 | } |
| 334 | } | 336 | } |
| 335 | 337 | ||
| @@ -359,3 +361,11 @@ func NewCheckoutTablesFilterColumnDataRequest(param domain.ReqFieldOptionalValue | @@ -359,3 +361,11 @@ func NewCheckoutTablesFilterColumnDataRequest(param domain.ReqFieldOptionalValue | ||
| 359 | FilterParameters: map[string]string{"keyWord": param.Match}, | 361 | FilterParameters: map[string]string{"keyWord": param.Match}, |
| 360 | } | 362 | } |
| 361 | } | 363 | } |
| 364 | + | ||
| 365 | +type ( | ||
| 366 | + FormulasClearRequest struct { | ||
| 367 | + FormulaId string `json:"formulaId"` | ||
| 368 | + } | ||
| 369 | + FormulasClearResponse struct { | ||
| 370 | + } | ||
| 371 | +) |
| 1 | +package bytelib | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 6 | + "strings" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type ( | ||
| 10 | + FormulasGenerateRequest struct { | ||
| 11 | + FormulaId string `json:"formulaId"` | ||
| 12 | + FormulaName string `json:"formulaName"` | ||
| 13 | + FormulaType int `json:"formulaType"` //公式类型 1.方案2.子过程 | ||
| 14 | + FormulaConditions []FormulaCondition `json:"formulaConditions"` | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + FormulasGenerateResponse struct { | ||
| 18 | + FormulaName string `json:"formulaName"` | ||
| 19 | + } | ||
| 20 | + FormulaCondition struct { | ||
| 21 | + FormulaSelectFields FormulaSelectFields `json:"formulaSelectFields"` | ||
| 22 | + FormulaSelectConditions []FormulaSelectCondition `json:"formulaSelectConditions"` | ||
| 23 | + FormulaDataHandleRules []FormulaDataHandleRule `json:"formulaDataHandleRules"` | ||
| 24 | + } | ||
| 25 | + // FormulaSelectFields 公式select字段 | ||
| 26 | + FormulaSelectFields struct { | ||
| 27 | + DatabaseTableName string `json:"databaseTableName"` | ||
| 28 | + FieldSchemas []FieldSchema `json:"fieldSchemas"` | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + FormulaSelectCondition struct { | ||
| 32 | + ConditionLeftField FormulaField `json:"conditionLeftField"` | ||
| 33 | + ConditionOperator string `json:"conditionOperator"` | ||
| 34 | + ConditionRightField FormulaField `json:"conditionRightField"` | ||
| 35 | + AndOr string `json:"andOr"` | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + FormulaDataHandleRule struct { | ||
| 39 | + RuleType int `json:"ruleType"` //Int, 规则类型 1.拆分赋值2.正常赋值 | ||
| 40 | + FormulaJoinCondition FormulaJoinCondition `json:"formulaJoinCondition"` // 拆分赋值 | ||
| 41 | + AssignValueCondition AssignValueCondition `json:"assignValueCondition"` // 正常赋值 | ||
| 42 | + } | ||
| 43 | + // FormulaJoinCondition 拆分链接条件 | ||
| 44 | + FormulaJoinCondition struct { | ||
| 45 | + ConditionLeftField FormulaField `json:"conditionLeftField"` | ||
| 46 | + ConditionRightField FormulaField `json:"conditionRightField"` | ||
| 47 | + JoinAssignValues []AssignValueCondition `json:"joinAssignValues"` | ||
| 48 | + } | ||
| 49 | + // AssignValueCondition 拆分规则 | ||
| 50 | + AssignValueCondition struct { | ||
| 51 | + ConditionLeftField FormulaField `json:"conditionLeftField"` | ||
| 52 | + ConditionRightField FormulaField `json:"conditionRightField"` | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + // FormulaField 公式字段 | ||
| 56 | + FormulaField struct { | ||
| 57 | + DatabaseTableName string `json:"databaseTableName"` | ||
| 58 | + FieldSchema FieldSchema `json:"fieldSchema"` | ||
| 59 | + ConditionExpression string `json:"conditionExpression"` | ||
| 60 | + } | ||
| 61 | +) | ||
| 62 | + | ||
| 63 | +func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest { | ||
| 64 | + var formatFormulaName = func(input string) string { | ||
| 65 | + sep := fmt.Sprintf("_c%d", table.Context.CompanyId) | ||
| 66 | + before := strings.Split(input, sep) | ||
| 67 | + if len(before) >= 2 { | ||
| 68 | + return before[0] + sep | ||
| 69 | + } | ||
| 70 | + return input | ||
| 71 | + } | ||
| 72 | + var req = FormulasGenerateRequest{ | ||
| 73 | + FormulaId: intToString(table.TableId), | ||
| 74 | + FormulaName: formatFormulaName(table.SQLName), | ||
| 75 | + FormulaType: 0, | ||
| 76 | + FormulaConditions: make([]FormulaCondition, 0), | ||
| 77 | + } | ||
| 78 | + if table.TableType == domain.SchemaTable.ToString() { | ||
| 79 | + req.FormulaType = 1 | ||
| 80 | + } else { | ||
| 81 | + req.FormulaType = 2 | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + for i := range queryComponents { | ||
| 85 | + req.FormulaConditions = append(req.FormulaConditions, NewFormulaCondition(queryComponents[i])) | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + return req | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +func NewFormulaCondition(queryComponent *domain.QueryComponent) FormulaCondition { | ||
| 92 | + var res = FormulaCondition{ | ||
| 93 | + FormulaSelectFields: NewFormulaSelectFields(queryComponent.MasterTable), | ||
| 94 | + FormulaSelectConditions: make([]FormulaSelectCondition, 0), | ||
| 95 | + FormulaDataHandleRules: make([]FormulaDataHandleRule, 0), | ||
| 96 | + } | ||
| 97 | + for _, c := range queryComponent.Conditions { | ||
| 98 | + res.FormulaSelectConditions = append(res.FormulaSelectConditions, NewFormulaSelectCondition(c)) | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + for _, s := range queryComponent.Selects { | ||
| 102 | + res.FormulaDataHandleRules = append(res.FormulaDataHandleRules, NewFormulaDataHandleRule(s)) | ||
| 103 | + } | ||
| 104 | + return res | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +func NewFormulaSelectFields(t domain.QueryComponentTable) FormulaSelectFields { | ||
| 108 | + var res = FormulaSelectFields{ | ||
| 109 | + DatabaseTableName: t.SQLName, | ||
| 110 | + FieldSchemas: ToFieldSchemas(t.Fields), | ||
| 111 | + } | ||
| 112 | + return res | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +func NewFormulaSelectCondition(c domain.ConditionExpr) FormulaSelectCondition { | ||
| 116 | + var res = FormulaSelectCondition{ | ||
| 117 | + ConditionOperator: c.OperatorSymbol, | ||
| 118 | + AndOr: c.AndOr, | ||
| 119 | + ConditionLeftField: NewFormulaField(c.FieldLeft, true), | ||
| 120 | + ConditionRightField: NewFormulaField(c.FieldRight), | ||
| 121 | + } | ||
| 122 | + return res | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +func NewFormulaField(f domain.FieldExpr, args ...interface{}) FormulaField { | ||
| 126 | + var res = FormulaField{ | ||
| 127 | + DatabaseTableName: "", | ||
| 128 | + FieldSchema: FieldSchema{}, | ||
| 129 | + ConditionExpression: f.ExprSql, | ||
| 130 | + } | ||
| 131 | + // 字段包含多个列 | ||
| 132 | + if len(f.TableFields) > 0 { | ||
| 133 | + res.DatabaseTableName = f.TableFields[0].TableSqlName | ||
| 134 | + res.FieldSchema = NewFieldSchema(f.TableFields[0]) | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + if len(args) >= 1 && len(f.TableFields) >= 1 { | ||
| 138 | + // set ConditionExpression empty | ||
| 139 | + if args[0].(bool) && f.ExprSql == f.TableFields[0].String() { | ||
| 140 | + res.ConditionExpression = "" | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + return res | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +func NewFieldSchema(f domain.TableField) FieldSchema { | ||
| 147 | + var res = FieldSchema{ | ||
| 148 | + FieldZhName: f.FieldName, | ||
| 149 | + FieldEnName: f.FieldSqlName, | ||
| 150 | + FieldType: f.FieldSQLType, | ||
| 151 | + FieldDescription: "", | ||
| 152 | + IsAllowNull: true, | ||
| 153 | + } | ||
| 154 | + return res | ||
| 155 | +} | ||
| 156 | + | ||
| 157 | +func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule { | ||
| 158 | + var res = FormulaDataHandleRule{ | ||
| 159 | + RuleType: 1, | ||
| 160 | + } | ||
| 161 | + if s.Type == string(domain.TableSplit) { | ||
| 162 | + res.RuleType = 1 | ||
| 163 | + res.FormulaJoinCondition = NewFormulaJoinCondition(s) | ||
| 164 | + } | ||
| 165 | + if s.Type == string(domain.NormalAssign) { | ||
| 166 | + res.RuleType = 2 | ||
| 167 | + res.AssignValueCondition = NewAssignValueCondition(s.SelectExpr) | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + return res | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +func NewFormulaJoinCondition(s domain.SelectExprGroup) FormulaJoinCondition { | ||
| 174 | + var res = FormulaJoinCondition{ | ||
| 175 | + ConditionLeftField: NewFormulaField(s.FieldLeft, true), | ||
| 176 | + ConditionRightField: NewFormulaField(s.FieldRight), | ||
| 177 | + } | ||
| 178 | + for _, sub := range s.SubSelects { | ||
| 179 | + res.JoinAssignValues = append(res.JoinAssignValues, NewAssignValueCondition(sub)) | ||
| 180 | + } | ||
| 181 | + return res | ||
| 182 | +} | ||
| 183 | + | ||
| 184 | +func NewAssignValueCondition(selectExpr domain.SelectExpr) AssignValueCondition { | ||
| 185 | + var res = AssignValueCondition{ | ||
| 186 | + ConditionLeftField: NewFormulaField(selectExpr.FieldLeft, true), | ||
| 187 | + ConditionRightField: NewFormulaField(selectExpr.FieldRight), | ||
| 188 | + } | ||
| 189 | + return res | ||
| 190 | +} |
| @@ -126,6 +126,16 @@ func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalVal | @@ -126,6 +126,16 @@ func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalVal | ||
| 126 | return apiByteLib.FieldOptionalValues(param) | 126 | return apiByteLib.FieldOptionalValues(param) |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | +func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) { | ||
| 130 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
| 131 | + return apiByteLib.FormulasGenerate(param) | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +func (ptr *ByteCoreService) FormulasClear(param domain.ReqFormulasClear) (*domain.DataFormulasClear, error) { | ||
| 135 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
| 136 | + return apiByteLib.FormulasClear(param) | ||
| 137 | +} | ||
| 138 | + | ||
| 129 | ////////////// | 139 | ////////////// |
| 130 | // 字库核心 | 140 | // 字库核心 |
| 131 | ////////////// | 141 | ////////////// |
| @@ -100,6 +100,22 @@ func (ptr *QuerySetService) Update(ctx *domain.Context, querySetId int, queryCom | @@ -100,6 +100,22 @@ func (ptr *QuerySetService) Update(ctx *domain.Context, querySetId int, queryCom | ||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | // 调用底层的组装sql | 102 | // 调用底层的组装sql |
| 103 | + formulasGenerateResponse, err := ByteCore.FormulasGenerate(domain.ReqFormulasGenerate{ | ||
| 104 | + QuerySet: qs, | ||
| 105 | + Table: table, | ||
| 106 | + QueryComponents: queryComponents, | ||
| 107 | + }) | ||
| 108 | + if err != nil { | ||
| 109 | + return err | ||
| 110 | + } | ||
| 111 | + if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName { | ||
| 112 | + table.SQLName = formulasGenerateResponse.FormulaName | ||
| 113 | + tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
| 114 | + table, err = tableRepository.Save(table) | ||
| 115 | + if err != nil { | ||
| 116 | + return err | ||
| 117 | + } | ||
| 118 | + } | ||
| 103 | 119 | ||
| 104 | // 生成日志 | 120 | // 生成日志 |
| 105 | if err = ptr.UpdateQuerySetLog(ctx, qs, queryComponents); err != nil { | 121 | if err = ptr.UpdateQuerySetLog(ctx, qs, queryComponents); err != nil { |
| @@ -311,7 +327,7 @@ func (ptr *QuerySetService) CreateOrUpdateQuerySetTable(ctx *domain.Context, que | @@ -311,7 +327,7 @@ func (ptr *QuerySetService) CreateOrUpdateQuerySetTable(ctx *domain.Context, que | ||
| 311 | return nil, err | 327 | return nil, err |
| 312 | } | 328 | } |
| 313 | masterTable = domain.NewQueryComponentTable(foundMasterTable) | 329 | masterTable = domain.NewQueryComponentTable(foundMasterTable) |
| 314 | - var table *domain.Table = NewTable(domain.TableType(querySet.Type), querySet.Name, masterTable.Fields, 0).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type)) | 330 | + var table *domain.Table = NewTable(domain.TableType(querySet.Type), querySet.Name, domain.RangeFields(masterTable.Fields, domain.ChangeFieldFlag), 0).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type)) |
| 315 | if querySet.QuerySetInfo.BindTableId > 0 { | 331 | if querySet.QuerySetInfo.BindTableId > 0 { |
| 316 | table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId}) | 332 | table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId}) |
| 317 | if err != nil { | 333 | if err != nil { |
| @@ -320,21 +336,36 @@ func (ptr *QuerySetService) CreateOrUpdateQuerySetTable(ctx *domain.Context, que | @@ -320,21 +336,36 @@ func (ptr *QuerySetService) CreateOrUpdateQuerySetTable(ctx *domain.Context, que | ||
| 320 | table.DataFields = masterTable.Fields | 336 | table.DataFields = masterTable.Fields |
| 321 | table.UpdatedAt = time.Now() | 337 | table.UpdatedAt = time.Now() |
| 322 | } | 338 | } |
| 323 | - | ||
| 324 | - // 循环依赖判断 | ||
| 325 | - tableDependencyService, _ := NewTableDependencyService(ptr.transactionContext) | 339 | + var validTables = make([]*domain.Table, 0) |
| 326 | if len(dependencyTables) > 0 { | 340 | if len(dependencyTables) > 0 { |
| 327 | - _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": dependencyTables, "tableTypes": []string{domain.SchemaTable.ToString(), domain.SubProcessTable.ToString()}}) | 341 | + _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": dependencyTables}) |
| 328 | if err != nil { | 342 | if err != nil { |
| 329 | return nil, err | 343 | return nil, err |
| 330 | } | 344 | } |
| 331 | - if len(tables) > 0 { | ||
| 332 | - tree := tableDependencyService.TableDependTree(tables, querySet.QuerySetInfo.BindTableId) | 345 | + tableMap := make(map[int]*domain.Table) |
| 346 | + for i := range tables { | ||
| 347 | + tableMap[tables[i].TableId] = tables[i] | ||
| 348 | + } | ||
| 349 | + for _, c := range queryComponents { | ||
| 350 | + if t, ok := tableMap[c.MasterTable.TableId]; ok { | ||
| 351 | + c.MasterTable = domain.NewQueryComponentTable(t) | ||
| 352 | + } | ||
| 353 | + } | ||
| 354 | + for _, t := range validTables { | ||
| 355 | + if t.TableType == domain.SchemaTable.ToString() || t.TableType == domain.SubProcessTable.ToString() { | ||
| 356 | + validTables = append(validTables, t) | ||
| 357 | + } | ||
| 358 | + } | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | + // 循环依赖判断 | ||
| 362 | + tableDependencyService, _ := NewTableDependencyService(ptr.transactionContext) | ||
| 363 | + if len(validTables) > 0 { | ||
| 364 | + tree := tableDependencyService.TableDependTree(validTables, querySet.QuerySetInfo.BindTableId) | ||
| 333 | if tableDependencyService.Detect(ctx, tree.EdgesArray()) { | 365 | if tableDependencyService.Detect(ctx, tree.EdgesArray()) { |
| 334 | return nil, NewCircleDependError(tableDependencyService.CircleTable(), querySet) | 366 | return nil, NewCircleDependError(tableDependencyService.CircleTable(), querySet) |
| 335 | } | 367 | } |
| 336 | } | 368 | } |
| 337 | - } | ||
| 338 | 369 | ||
| 339 | table.TableInfo.ApplyOnModule = domain.ModuleAll | 370 | table.TableInfo.ApplyOnModule = domain.ModuleAll |
| 340 | table.TableInfo.DependencyTables = dependencyTables | 371 | table.TableInfo.DependencyTables = dependencyTables |
| @@ -392,6 +423,22 @@ func (ptr *QuerySetService) ChangeStatus(ctx *domain.Context, querySetId int, st | @@ -392,6 +423,22 @@ func (ptr *QuerySetService) ChangeStatus(ctx *domain.Context, querySetId int, st | ||
| 392 | if err != nil { | 423 | if err != nil { |
| 393 | return err | 424 | return err |
| 394 | } | 425 | } |
| 426 | + | ||
| 427 | + if qs.QuerySetInfo.BindTableId != 0 { | ||
| 428 | + tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
| 429 | + table, err := tableRepository.FindOne(map[string]interface{}{"tableId": qs.QuerySetInfo.BindTableId}) | ||
| 430 | + if err != nil { | ||
| 431 | + return err | ||
| 432 | + } | ||
| 433 | + if status == domain.StatusOn { | ||
| 434 | + table.TableInfo.SetApplyOn(domain.ModuleAll) | ||
| 435 | + } else { | ||
| 436 | + table.TableInfo.SetApplyOn(domain.ModuleQuerySetCenter | domain.ModuleCalculateCenter) | ||
| 437 | + } | ||
| 438 | + if _, err = tableRepository.Save(table); err != nil { | ||
| 439 | + return err | ||
| 440 | + } | ||
| 441 | + } | ||
| 395 | return nil | 442 | return nil |
| 396 | } | 443 | } |
| 397 | 444 | ||
| @@ -417,14 +464,37 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string, | @@ -417,14 +464,37 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string, | ||
| 417 | if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == name { | 464 | if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == name { |
| 418 | return ErrQuerySetNameExists | 465 | return ErrQuerySetNameExists |
| 419 | } | 466 | } |
| 420 | - // TODO:create-table | ||
| 421 | if copy.QuerySetInfo.BindTableId != 0 { | 467 | if copy.QuerySetInfo.BindTableId != 0 { |
| 422 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 468 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
| 423 | table, err := tableRepository.FindOne(map[string]interface{}{"tableId": copy.QuerySetInfo.BindTableId}) | 469 | table, err := tableRepository.FindOne(map[string]interface{}{"tableId": copy.QuerySetInfo.BindTableId}) |
| 424 | if err != nil { | 470 | if err != nil { |
| 425 | return err | 471 | return err |
| 426 | } | 472 | } |
| 427 | - NewTable(domain.TableType(t), name, table.DataFields, 0).WithContext(ctx) | 473 | + copyTable := NewTable(domain.TableType(t), name, table.Fields(false), 0).WithContext(ctx).WithPrefix(qs.Type) |
| 474 | + | ||
| 475 | + copyTable, err = tableRepository.Save(copyTable) | ||
| 476 | + if err != nil { | ||
| 477 | + return err | ||
| 478 | + } | ||
| 479 | + | ||
| 480 | + // 调用底层的组装sql | ||
| 481 | + formulasGenerateResponse, err := ByteCore.FormulasGenerate(domain.ReqFormulasGenerate{ | ||
| 482 | + QuerySet: qs, | ||
| 483 | + Table: table, | ||
| 484 | + QueryComponents: qs.QueryComponents, | ||
| 485 | + }) | ||
| 486 | + if err != nil { | ||
| 487 | + return err | ||
| 488 | + } | ||
| 489 | + if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName { | ||
| 490 | + copyTable.SQLName = formulasGenerateResponse.FormulaName | ||
| 491 | + tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
| 492 | + copyTable, err = tableRepository.Save(copyTable) | ||
| 493 | + if err != nil { | ||
| 494 | + return err | ||
| 495 | + } | ||
| 496 | + } | ||
| 497 | + copy.QuerySetInfo.BindTableId = copyTable.TableId | ||
| 428 | } | 498 | } |
| 429 | _, err = querySetRepository.Save(copy) | 499 | _, err = querySetRepository.Save(copy) |
| 430 | if err != nil { | 500 | if err != nil { |
| @@ -469,6 +539,9 @@ func (ptr *QuerySetService) Delete(ctx *domain.Context, querySetId int) error { | @@ -469,6 +539,9 @@ func (ptr *QuerySetService) Delete(ctx *domain.Context, querySetId int) error { | ||
| 469 | if err := dao.TableSoftDelete(ptr.transactionContext, querySets[i].QuerySetInfo.BindTableId, domain.TableType(querySets[i].Type)); err != nil { | 539 | if err := dao.TableSoftDelete(ptr.transactionContext, querySets[i].QuerySetInfo.BindTableId, domain.TableType(querySets[i].Type)); err != nil { |
| 470 | return err | 540 | return err |
| 471 | } | 541 | } |
| 542 | + ByteCore.FormulasClear(domain.ReqFormulasClear{ | ||
| 543 | + QuerySetId: querySets[i].QuerySetId, | ||
| 544 | + }) | ||
| 472 | } | 545 | } |
| 473 | } | 546 | } |
| 474 | // 日志 | 547 | // 日志 |
| @@ -620,3 +693,21 @@ func (ptr *QuerySetService) GetAllChild(ctx *domain.Context, querySetId int, inc | @@ -620,3 +693,21 @@ func (ptr *QuerySetService) GetAllChild(ctx *domain.Context, querySetId int, inc | ||
| 620 | } | 693 | } |
| 621 | return result, nil | 694 | return result, nil |
| 622 | } | 695 | } |
| 696 | + | ||
| 697 | +/* | ||
| 698 | +DROP VIEW IF EXISTS schema_xiao_shou_ming_xi_fen_biao_t456157_c1; | ||
| 699 | +create view schema_xiao_shou_ming_xi_fen_biao_t456157_c1( | ||
| 700 | + hui_zong_qu_yu_c5 COMMENT "汇总区域" | ||
| 701 | +) as( | ||
| 702 | + WITH xiao_shou_ming_xi_fen_biao_t456157_c1 AS ( | ||
| 703 | + SELECT | ||
| 704 | + IF | ||
| 705 | + ( ke_hu_dui_zhao_biao_t969072_c1.hui_zong_qu_yu_c5 IS NULL, xiao_shou_ming_xi_fen_biao_t456157_c1.yuan_gong_bian_ma_c4, ke_hu_dui_zhao_biao_t969072_c1.hui_zong_qu_yu_c5 ) hui_zong_qu_yu_c5 | ||
| 706 | + FROM | ||
| 707 | + xiao_shou_ming_xi_fen_biao_t456157_c1 | ||
| 708 | + LEFT JOIN ke_hu_dui_zhao_biao_t969072_c1 ON xiao_shou_ming_xi_fen_biao_t456157_c1.ke_hu_bian_ma_c14 = ke_hu_dui_zhao_biao_t969072_c1.jin_die_ke_hu_bian_ma_c3 | ||
| 709 | + ) | ||
| 710 | + SELECT * | ||
| 711 | + FROM | ||
| 712 | + xiao_shou_ming_xi_fen_biao_t456157_c1 | ||
| 713 | +*/ |
-
请 注册 或 登录 后发表评论