Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/character-l…
…ibrary-metadata-bastion into test
正在显示
18 个修改的文件
包含
302 行增加
和
62 行删除
| @@ -9,6 +9,7 @@ HTTP_PORT = 8081 | @@ -9,6 +9,7 @@ HTTP_PORT = 8081 | ||
| 9 | ENABLE_KAFKA_LOG11 = true | 9 | ENABLE_KAFKA_LOG11 = true |
| 10 | HTTPS_PORT = 8143 | 10 | HTTPS_PORT = 8143 |
| 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com | 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
| 12 | +# AUTH_SERVER_HOST = http://127.0.0.1:8081 | ||
| 12 | BYTE_CORE_HOST = http://47.97.5.102:8303 | 13 | BYTE_CORE_HOST = http://47.97.5.102:8303 |
| 13 | METADATA_BASTION_HOST = http://106.75.231.90:9999 | 14 | METADATA_BASTION_HOST = http://106.75.231.90:9999 |
| 14 | 15 |
| @@ -13,7 +13,7 @@ type CalculateItemPreviewQuery struct { | @@ -13,7 +13,7 @@ type CalculateItemPreviewQuery struct { | ||
| 13 | // 查询集合ID | 13 | // 查询集合ID |
| 14 | QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"` | 14 | QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"` |
| 15 | // 公式 | 15 | // 公式 |
| 16 | - Formula *domain.FieldExpr `json:"formula"` | 16 | + Formula *domain.FieldExpr `json:"formula" valid:"Required"` |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | func (dependencyGraphQuery *CalculateItemPreviewQuery) Valid(validation *validation.Validation) { | 19 | func (dependencyGraphQuery *CalculateItemPreviewQuery) Valid(validation *validation.Validation) { |
| @@ -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 | // 依赖关系图 |
| @@ -425,7 +428,9 @@ func (querySetService *QuerySetService) CalculateItemPreview(ctx *domain.Context | @@ -425,7 +428,9 @@ func (querySetService *QuerySetService) CalculateItemPreview(ctx *domain.Context | ||
| 425 | defer func() { | 428 | defer func() { |
| 426 | transactionContext.RollbackTransaction() | 429 | transactionContext.RollbackTransaction() |
| 427 | }() | 430 | }() |
| 428 | - | 431 | + if q.Formula.MixTableModel() { |
| 432 | + q.Formula.ExprSql = q.Formula.Complete() | ||
| 433 | + } | ||
| 429 | _, result := GetItemValues(transactionContext, q) | 434 | _, result := GetItemValues(transactionContext, q) |
| 430 | if err := transactionContext.CommitTransaction(); err != nil { | 435 | if err := transactionContext.CommitTransaction(); err != nil { |
| 431 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 436 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -480,6 +485,10 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C | @@ -480,6 +485,10 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C | ||
| 480 | if err != nil { | 485 | if err != nil { |
| 481 | return nil, nil | 486 | return nil, nil |
| 482 | } | 487 | } |
| 488 | + | ||
| 489 | + if q.Formula.MixTableModel() { | ||
| 490 | + q.Formula.ExprSql = q.Formula.Complete() | ||
| 491 | + } | ||
| 483 | value := starrocks.CalculateItemValue(starrocks.DB, q.Formula) | 492 | value := starrocks.CalculateItemValue(starrocks.DB, q.Formula) |
| 484 | 493 | ||
| 485 | var result = make([]itemValue, 0) | 494 | var result = make([]itemValue, 0) |
| @@ -18,7 +18,7 @@ type TableObjectDto struct { | @@ -18,7 +18,7 @@ type TableObjectDto struct { | ||
| 18 | // 父级ID | 18 | // 父级ID |
| 19 | ParentId int `json:"parentId"` | 19 | ParentId int `json:"parentId"` |
| 20 | // 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块 | 20 | // 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块 |
| 21 | - //Module int `json:"module"` | 21 | + Module int `json:"module"` |
| 22 | // 标识 | 22 | // 标识 |
| 23 | Flag string `json:"flag,omitempty"` | 23 | Flag string `json:"flag,omitempty"` |
| 24 | // 启用状态 | 24 | // 启用状态 |
| @@ -34,9 +34,9 @@ func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto { | @@ -34,9 +34,9 @@ func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto { | ||
| 34 | d.Name = m.Name | 34 | d.Name = m.Name |
| 35 | d.ParentId = m.ParentId | 35 | d.ParentId = m.ParentId |
| 36 | d.SQLName = m.SQLName | 36 | d.SQLName = m.SQLName |
| 37 | - //if m.TableInfo != nil { | ||
| 38 | - // d.Module = m.TableInfo.ApplyOnModule | ||
| 39 | - //} | 37 | + if m.TableInfo != nil { |
| 38 | + d.Module = m.TableInfo.ApplyOnModule | ||
| 39 | + } | ||
| 40 | d.Fields = make([]*domain.Field, 0) | 40 | d.Fields = make([]*domain.Field, 0) |
| 41 | return d | 41 | return d |
| 42 | } | 42 | } |
| @@ -432,6 +432,9 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | @@ -432,6 +432,9 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | ||
| 432 | for _, f := range cmd.TableFields { | 432 | for _, f := range cmd.TableFields { |
| 433 | set.AddStr(f.TableSqlName) | 433 | set.AddStr(f.TableSqlName) |
| 434 | } | 434 | } |
| 435 | + if cmd.MixTableModel() { | ||
| 436 | + cmd.ExprSql = cmd.Complete() | ||
| 437 | + } | ||
| 435 | selectValue := cmd.ExprSql | 438 | selectValue := cmd.ExprSql |
| 436 | //if _, parseErr := strconv.ParseFloat(cmd.ExprSql, 64); parseErr != nil { | 439 | //if _, parseErr := strconv.ParseFloat(cmd.ExprSql, 64); parseErr != nil { |
| 437 | // selectValue = "'" + selectValue + "'" | 440 | // selectValue = "'" + selectValue + "'" |
| @@ -24,7 +24,7 @@ var METADATA_BASTION_HOST = "http://127.0.0.1:8080" | @@ -24,7 +24,7 @@ var METADATA_BASTION_HOST = "http://127.0.0.1:8080" | ||
| 24 | 24 | ||
| 25 | var BYTE_CORE_HOST = "http://192.168.100.34:8303" | 25 | var BYTE_CORE_HOST = "http://192.168.100.34:8303" |
| 26 | 26 | ||
| 27 | -var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com/" | 27 | +var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com" |
| 28 | 28 | ||
| 29 | //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | 29 | //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} |
| 30 | 30 | ||
| @@ -45,6 +45,7 @@ func init() { | @@ -45,6 +45,7 @@ func init() { | ||
| 45 | BYTE_CORE_HOST = Configurator.DefaultString("BYTE_CORE_HOST", BYTE_CORE_HOST) | 45 | BYTE_CORE_HOST = Configurator.DefaultString("BYTE_CORE_HOST", BYTE_CORE_HOST) |
| 46 | SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) | 46 | SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) |
| 47 | HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) | 47 | HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) |
| 48 | + AUTH_SERVER_HOST = Configurator.DefaultString("AUTH_SERVER_HOST", AUTH_SERVER_HOST) | ||
| 48 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 49 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
| 49 | PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) | 50 | PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) |
| 50 | CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV | 51 | CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | -import "fmt" | 3 | +import ( |
| 4 | + "fmt" | ||
| 5 | + "github.com/zeromicro/go-zero/core/collection" | ||
| 6 | + "strings" | ||
| 7 | +) | ||
| 4 | 8 | ||
| 5 | var ( | 9 | var ( |
| 6 | SchemaTable TableType = "Schema" // 方案 | 10 | SchemaTable TableType = "Schema" // 方案 |
| @@ -95,6 +99,50 @@ type FieldExpr struct { | @@ -95,6 +99,50 @@ type FieldExpr struct { | ||
| 95 | ExprSql string `json:"exprSql"` | 99 | ExprSql string `json:"exprSql"` |
| 96 | } | 100 | } |
| 97 | 101 | ||
| 102 | +func (expr *FieldExpr) Complete() string { | ||
| 103 | + exprSql := expr.ExprSql | ||
| 104 | + for _, f := range expr.TableFields { | ||
| 105 | + sql := fmt.Sprintf("%s.%s", f.TableSqlName, f.FieldSqlName) | ||
| 106 | + //zhSql := fmt.Sprintf("%s.%s", f.TableName, f.FieldSqlName) | ||
| 107 | + sub := fmt.Sprintf("max(%s.%s)", f.TableSqlName, f.FieldSqlName) | ||
| 108 | + //zhSub := fmt.Sprintf("max(%s.%s)", f.TableName, f.FieldSqlName) | ||
| 109 | + if strings.Contains(expr.ExprSql, fmt.Sprintf("(%s)", sql)) { | ||
| 110 | + continue | ||
| 111 | + } | ||
| 112 | + exprSql = strings.ReplaceAll(exprSql, sql, sub) | ||
| 113 | + //expr.ExprSql = strings.ReplaceAll(expr.ExprSql, sql, sub) | ||
| 114 | + //expr.ExprHuman = strings.ReplaceAll(expr.ExprHuman, zhSql, zhSub) | ||
| 115 | + } | ||
| 116 | + return exprSql | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +func (expr *FieldExpr) Tables() []int { | ||
| 120 | + set := collection.NewSet() | ||
| 121 | + for _, f := range expr.TableFields { | ||
| 122 | + if f.TableId == 0 { | ||
| 123 | + continue | ||
| 124 | + } | ||
| 125 | + set.Add(f.TableId) | ||
| 126 | + } | ||
| 127 | + return set.KeysInt() | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +func (expr *FieldExpr) MixTableModel() bool { | ||
| 131 | + var result = 0 | ||
| 132 | + for _, f := range expr.TableFields { | ||
| 133 | + if strings.HasPrefix(f.TableSqlName, strings.ToLower(CalculateItem.ToString())) { | ||
| 134 | + if result&1 == 0 { | ||
| 135 | + result += 1 | ||
| 136 | + } | ||
| 137 | + } else { | ||
| 138 | + if result&2 == 0 { | ||
| 139 | + result += 2 | ||
| 140 | + } | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + return result == 3 | ||
| 144 | +} | ||
| 145 | + | ||
| 98 | type LabelColumn struct { | 146 | type LabelColumn struct { |
| 99 | Column TableField `json:"column,omitempty"` | 147 | Column TableField `json:"column,omitempty"` |
| 100 | LabelExpr string `json:"labelExpr"` | 148 | LabelExpr string `json:"labelExpr"` |
| @@ -39,3 +39,8 @@ func (tk *UserToken) ParseToken(str string) error { | @@ -39,3 +39,8 @@ func (tk *UserToken) ParseToken(str string) error { | ||
| 39 | } | 39 | } |
| 40 | return errors.New("token 解析失败") | 40 | return errors.New("token 解析失败") |
| 41 | } | 41 | } |
| 42 | + | ||
| 43 | +// CheckUserInfo 如果UserToken有效 返回:true 否则返回false | ||
| 44 | +func (tk *UserToken) CheckUserInfo() bool { | ||
| 45 | + return !(tk.UserId > 100000000 || tk.UserId <= 0) | ||
| 46 | +} |
| @@ -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 |
| @@ -12,6 +12,7 @@ type ( | @@ -12,6 +12,7 @@ type ( | ||
| 12 | FormulaName string `json:"formulaName"` | 12 | FormulaName string `json:"formulaName"` |
| 13 | FormulaType int `json:"formulaType"` //公式类型 1.方案2.子过程 | 13 | FormulaType int `json:"formulaType"` //公式类型 1.方案2.子过程 |
| 14 | FormulaConditions []FormulaCondition `json:"formulaConditions"` | 14 | FormulaConditions []FormulaCondition `json:"formulaConditions"` |
| 15 | + FormulaCalculate *FormulaCalculate `json:"formulaCalculate"` | ||
| 15 | } | 16 | } |
| 16 | 17 | ||
| 17 | FormulasGenerateResponse struct { | 18 | FormulasGenerateResponse struct { |
| @@ -58,9 +59,28 @@ type ( | @@ -58,9 +59,28 @@ type ( | ||
| 58 | FieldSchema FieldSchema `json:"fieldSchema"` | 59 | FieldSchema FieldSchema `json:"fieldSchema"` |
| 59 | ConditionExpression string `json:"conditionExpression"` | 60 | ConditionExpression string `json:"conditionExpression"` |
| 60 | } | 61 | } |
| 62 | + | ||
| 63 | + FormulaCalculate struct { | ||
| 64 | + DatabaseTableName string `json:"databaseTableName"` | ||
| 65 | + FormulaCalculateFields []*FormulaCalculateField `json:"formulaCalculateFields"` | ||
| 66 | + FormulaGroupFields []*FormulaGroupField `json:"formulaGroupFields"` | ||
| 67 | + } | ||
| 68 | + FormulaCalculateField struct { | ||
| 69 | + DatabaseTableName string `json:"databaseTableName"` | ||
| 70 | + FieldSchema FieldSchema `json:"fieldSchema"` | ||
| 71 | + CalculateExpression string `json:"calculateExpression"` | ||
| 72 | + // 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称) | ||
| 73 | + CalculateFieldName string `json:"calculateFieldName"` | ||
| 74 | + } | ||
| 75 | + FormulaGroupField struct { | ||
| 76 | + DatabaseTableName string `json:"databaseTableName"` | ||
| 77 | + FieldSchema FieldSchema `json:"fieldSchema"` | ||
| 78 | + // 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称) | ||
| 79 | + GroupFieldName string `json:"groupFieldName"` | ||
| 80 | + } | ||
| 61 | ) | 81 | ) |
| 62 | 82 | ||
| 63 | -func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest { | 83 | +func NewFormulasGenerateRequest(querySet *domain.QuerySet, table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest { |
| 64 | var formatFormulaName = func(input string) string { | 84 | var formatFormulaName = func(input string) string { |
| 65 | sep := fmt.Sprintf("_c%d", table.Context.CompanyId) | 85 | sep := fmt.Sprintf("_c%d", table.Context.CompanyId) |
| 66 | before := strings.Split(input, sep) | 86 | before := strings.Split(input, sep) |
| @@ -75,14 +95,22 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q | @@ -75,14 +95,22 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q | ||
| 75 | FormulaType: 0, | 95 | FormulaType: 0, |
| 76 | FormulaConditions: make([]FormulaCondition, 0), | 96 | FormulaConditions: make([]FormulaCondition, 0), |
| 77 | } | 97 | } |
| 78 | - if table.TableType == domain.SchemaTable.ToString() { | 98 | + if querySet.Type == domain.SchemaTable.ToString() { |
| 79 | req.FormulaType = 1 | 99 | req.FormulaType = 1 |
| 80 | - } else { | 100 | + } else if querySet.Type == domain.SubProcessTable.ToString() { |
| 81 | req.FormulaType = 2 | 101 | req.FormulaType = 2 |
| 102 | + } else if querySet.Type == domain.CalculateTable.ToString() { | ||
| 103 | + req.FormulaType = 3 | ||
| 104 | + } else if querySet.Type == domain.CalculateItem.ToString() { | ||
| 105 | + req.FormulaType = 4 | ||
| 82 | } | 106 | } |
| 83 | 107 | ||
| 84 | - for i := range queryComponents { | ||
| 85 | - req.FormulaConditions = append(req.FormulaConditions, NewFormulaCondition(queryComponents[i])) | 108 | + if req.FormulaType == 1 || req.FormulaType == 2 { |
| 109 | + for i := range queryComponents { | ||
| 110 | + req.FormulaConditions = append(req.FormulaConditions, NewFormulaCondition(queryComponents[i])) | ||
| 111 | + } | ||
| 112 | + } else { | ||
| 113 | + req.FormulaCalculate = NewFormulaCalculate(table, queryComponents[0]) | ||
| 86 | } | 114 | } |
| 87 | 115 | ||
| 88 | return req | 116 | return req |
| @@ -104,6 +132,75 @@ func NewFormulaCondition(queryComponent *domain.QueryComponent) FormulaCondition | @@ -104,6 +132,75 @@ func NewFormulaCondition(queryComponent *domain.QueryComponent) FormulaCondition | ||
| 104 | return res | 132 | return res |
| 105 | } | 133 | } |
| 106 | 134 | ||
| 135 | +func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryComponent) *FormulaCalculate { | ||
| 136 | + var res = &FormulaCalculate{ | ||
| 137 | + DatabaseTableName: "", | ||
| 138 | + FormulaGroupFields: make([]*FormulaGroupField, 0), | ||
| 139 | + FormulaCalculateFields: make([]*FormulaCalculateField, 0), | ||
| 140 | + } | ||
| 141 | + if queryComponent.Formula != nil { | ||
| 142 | + formula := queryComponent.Formula | ||
| 143 | + res.DatabaseTableName = formula.TableFields[0].TableSqlName | ||
| 144 | + exprSql := formula.ExprSql | ||
| 145 | + if queryComponent.Formula.MixTableModel() { | ||
| 146 | + exprSql = queryComponent.Formula.Complete() | ||
| 147 | + } | ||
| 148 | + for _, f := range queryComponent.Formula.TableFields { | ||
| 149 | + res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
| 150 | + DatabaseTableName: f.TableSqlName, | ||
| 151 | + FieldSchema: NewFieldSchema(f), | ||
| 152 | + CalculateExpression: exprSql, | ||
| 153 | + CalculateFieldName: table.DataFields[0].SQLName, | ||
| 154 | + }) | ||
| 155 | + } | ||
| 156 | + //res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
| 157 | + // DatabaseTableName: res.DatabaseTableName, | ||
| 158 | + // FieldSchema: NewFieldSchemaFromField(table.DataFields[0]), | ||
| 159 | + // CalculateExpression: formula.ExprSql, | ||
| 160 | + // CalculateFieldName: table.DataFields[0].SQLName, | ||
| 161 | + //}) | ||
| 162 | + } | ||
| 163 | + if queryComponent.Aggregation != nil { | ||
| 164 | + res.DatabaseTableName = queryComponent.MasterTable.SQLName | ||
| 165 | + for i, f := range queryComponent.Aggregation.ValueFields { | ||
| 166 | + tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName}) | ||
| 167 | + if !ok { | ||
| 168 | + continue | ||
| 169 | + } | ||
| 170 | + if i == 0 { | ||
| 171 | + res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
| 172 | + DatabaseTableName: queryComponent.MasterTable.SQLName, | ||
| 173 | + FieldSchema: NewFieldSchemaFromField(&domain.Field{ | ||
| 174 | + Name: "序号", | ||
| 175 | + SQLName: "id", | ||
| 176 | + SQLType: domain.String.ToString(), | ||
| 177 | + }), | ||
| 178 | + CalculateExpression: fmt.Sprintf("max(%s.%s)", queryComponent.MasterTable.SQLName, "id"), | ||
| 179 | + CalculateFieldName: "id", | ||
| 180 | + }) | ||
| 181 | + } | ||
| 182 | + res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ | ||
| 183 | + DatabaseTableName: queryComponent.MasterTable.SQLName, | ||
| 184 | + FieldSchema: NewFieldSchemaFromField(f.Field), | ||
| 185 | + CalculateExpression: f.Expr.ExprSql, | ||
| 186 | + CalculateFieldName: tableField.SQLName, | ||
| 187 | + }) | ||
| 188 | + } | ||
| 189 | + for _, f := range queryComponent.Aggregation.RowFields { | ||
| 190 | + tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName}) | ||
| 191 | + if !ok { | ||
| 192 | + continue | ||
| 193 | + } | ||
| 194 | + res.FormulaGroupFields = append(res.FormulaGroupFields, &FormulaGroupField{ | ||
| 195 | + DatabaseTableName: queryComponent.MasterTable.SQLName, | ||
| 196 | + FieldSchema: NewFieldSchemaFromField(f.Field), | ||
| 197 | + GroupFieldName: tableField.SQLName, | ||
| 198 | + }) | ||
| 199 | + } | ||
| 200 | + } | ||
| 201 | + return res | ||
| 202 | +} | ||
| 203 | + | ||
| 107 | func NewFormulaSelectFields(t *domain.QueryComponentTable) FormulaSelectFields { | 204 | func NewFormulaSelectFields(t *domain.QueryComponentTable) FormulaSelectFields { |
| 108 | var res = FormulaSelectFields{ | 205 | var res = FormulaSelectFields{ |
| 109 | DatabaseTableName: t.SQLName, | 206 | DatabaseTableName: t.SQLName, |
| @@ -124,7 +221,11 @@ func NewFormulaSelectCondition(c domain.ConditionExpr) FormulaSelectCondition { | @@ -124,7 +221,11 @@ func NewFormulaSelectCondition(c domain.ConditionExpr) FormulaSelectCondition { | ||
| 124 | res.ConditionRightField.ConditionExpression = " null " | 221 | res.ConditionRightField.ConditionExpression = " null " |
| 125 | } | 222 | } |
| 126 | if c.OperatorSymbol == "!=" && strings.ToLower(c.FieldRight.ExprSql) == "null" { | 223 | if c.OperatorSymbol == "!=" && strings.ToLower(c.FieldRight.ExprSql) == "null" { |
| 127 | - res.ConditionOperator = "is not" | 224 | + res.ConditionOperator = " is not " |
| 225 | + res.ConditionRightField.ConditionExpression = "null" | ||
| 226 | + } | ||
| 227 | + if c.OperatorSymbol == "<>" && strings.ToLower(c.FieldRight.ExprSql) == "null" { | ||
| 228 | + res.ConditionOperator = " is not " | ||
| 128 | res.ConditionRightField.ConditionExpression = "null" | 229 | res.ConditionRightField.ConditionExpression = "null" |
| 129 | } | 230 | } |
| 130 | return res | 231 | return res |
| @@ -162,6 +263,17 @@ func NewFieldSchema(f domain.TableField) FieldSchema { | @@ -162,6 +263,17 @@ func NewFieldSchema(f domain.TableField) FieldSchema { | ||
| 162 | return res | 263 | return res |
| 163 | } | 264 | } |
| 164 | 265 | ||
| 266 | +func NewFieldSchemaFromField(f *domain.Field) FieldSchema { | ||
| 267 | + var res = FieldSchema{ | ||
| 268 | + FieldZhName: f.Name, | ||
| 269 | + FieldEnName: f.SQLName, | ||
| 270 | + FieldType: f.SQLType, | ||
| 271 | + FieldDescription: "", | ||
| 272 | + IsAllowNull: true, | ||
| 273 | + } | ||
| 274 | + return res | ||
| 275 | +} | ||
| 276 | + | ||
| 165 | func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule { | 277 | func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule { |
| 166 | var res = FormulaDataHandleRule{ | 278 | var res = FormulaDataHandleRule{ |
| 167 | RuleType: 1, | 279 | RuleType: 1, |
| @@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" |
| 10 | - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" | ||
| 11 | ) | 10 | ) |
| 12 | 11 | ||
| 13 | type ByteCoreService struct { | 12 | type ByteCoreService struct { |
| @@ -129,24 +128,24 @@ func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalVal | @@ -129,24 +128,24 @@ func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalVal | ||
| 129 | 128 | ||
| 130 | func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) { | 129 | func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) { |
| 131 | apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | 130 | apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
| 132 | - if param.QuerySet.Type == domain.CalculateItem.ToString() { | ||
| 133 | - if err := starrocks.Exec(starrocks.DB, | ||
| 134 | - starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields, | ||
| 135 | - starrocks.CalculateItemViewSql(¶m.QueryComponents[0].Formula.FieldExpr), | ||
| 136 | - )); err != nil { | ||
| 137 | - return nil, err | ||
| 138 | - } | ||
| 139 | - return &domain.DataFormulasGenerate{}, nil | ||
| 140 | - } | ||
| 141 | - if param.QuerySet.Type == domain.CalculateTable.ToString() { | ||
| 142 | - if err := starrocks.Exec(starrocks.DB, | ||
| 143 | - starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields, | ||
| 144 | - starrocks.CalculateTableViewSql(param.QueryComponents[0].MasterTable.SQLName, ¶m.QueryComponents[0].Aggregation.Aggregation), | ||
| 145 | - )); err != nil { | ||
| 146 | - return nil, err | ||
| 147 | - } | ||
| 148 | - return &domain.DataFormulasGenerate{}, nil | ||
| 149 | - } | 131 | + //if param.QuerySet.Type == domain.CalculateItem.ToString() { |
| 132 | + // if err := starrocks.Exec(starrocks.DB, | ||
| 133 | + // starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields, | ||
| 134 | + // starrocks.CalculateItemViewSql(¶m.QueryComponents[0].Formula.FieldExpr), | ||
| 135 | + // )); err != nil { | ||
| 136 | + // return nil, err | ||
| 137 | + // } | ||
| 138 | + // return &domain.DataFormulasGenerate{}, nil | ||
| 139 | + //} | ||
| 140 | + //if param.QuerySet.Type == domain.CalculateTable.ToString() { | ||
| 141 | + // if err := starrocks.Exec(starrocks.DB, | ||
| 142 | + // starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields, | ||
| 143 | + // starrocks.CalculateTableViewSql(param.QueryComponents[0].MasterTable.SQLName, ¶m.QueryComponents[0].Aggregation.Aggregation), | ||
| 144 | + // )); err != nil { | ||
| 145 | + // return nil, err | ||
| 146 | + // } | ||
| 147 | + // return &domain.DataFormulasGenerate{}, nil | ||
| 148 | + //} | ||
| 150 | return apiByteLib.FormulasGenerate(param) | 149 | return apiByteLib.FormulasGenerate(param) |
| 151 | } | 150 | } |
| 152 | 151 |
| @@ -368,7 +368,13 @@ func (l *CreateQuerySetLog) OperateType() string { | @@ -368,7 +368,13 @@ func (l *CreateQuerySetLog) OperateType() string { | ||
| 368 | } | 368 | } |
| 369 | 369 | ||
| 370 | func (l *CreateQuerySetLog) LogType() string { | 370 | func (l *CreateQuerySetLog) LogType() string { |
| 371 | - if l.Qs.Type == domain.SchemaTable.ToString() || l.Qs.Type == domain.SubProcessTable.ToString() { | 371 | + if l.Qs.Type == domain.SchemaTable.ToString() { |
| 372 | + return domain.QuerySetLog.ToString() | ||
| 373 | + } | ||
| 374 | + if l.Qs.Type == domain.SubProcessTable.ToString() { | ||
| 375 | + return domain.QuerySetLog.ToString() | ||
| 376 | + } | ||
| 377 | + if l.Qs.Type == domain.CalculateTable.ToString() { | ||
| 372 | return domain.QuerySetLog.ToString() | 378 | return domain.QuerySetLog.ToString() |
| 373 | } | 379 | } |
| 374 | return domain.FormulaLog.ToString() | 380 | return domain.FormulaLog.ToString() |
| @@ -390,7 +396,13 @@ func (l *RenameQuerySetLog) OperateType() string { | @@ -390,7 +396,13 @@ func (l *RenameQuerySetLog) OperateType() string { | ||
| 390 | } | 396 | } |
| 391 | 397 | ||
| 392 | func (l *RenameQuerySetLog) LogType() string { | 398 | func (l *RenameQuerySetLog) LogType() string { |
| 393 | - if l.Qs.Type == domain.SchemaTable.ToString() || l.Qs.Type == domain.SubProcessTable.ToString() { | 399 | + if l.Qs.Type == domain.SchemaTable.ToString() { |
| 400 | + return domain.QuerySetLog.ToString() | ||
| 401 | + } | ||
| 402 | + if l.Qs.Type == domain.SubProcessTable.ToString() { | ||
| 403 | + return domain.QuerySetLog.ToString() | ||
| 404 | + } | ||
| 405 | + if l.Qs.Type == domain.CalculateTable.ToString() { | ||
| 394 | return domain.QuerySetLog.ToString() | 406 | return domain.QuerySetLog.ToString() |
| 395 | } | 407 | } |
| 396 | return domain.FormulaLog.ToString() | 408 | return domain.FormulaLog.ToString() |
| @@ -420,6 +432,9 @@ func (l *DeleteQuerySetLog) LogType() string { | @@ -420,6 +432,9 @@ func (l *DeleteQuerySetLog) LogType() string { | ||
| 420 | if qs.Type == domain.SchemaTable.ToString() || qs.Type == domain.SubProcessTable.ToString() { | 432 | if qs.Type == domain.SchemaTable.ToString() || qs.Type == domain.SubProcessTable.ToString() { |
| 421 | return domain.QuerySetLog.ToString() | 433 | return domain.QuerySetLog.ToString() |
| 422 | } | 434 | } |
| 435 | + if qs.Type == domain.CalculateTable.ToString() { | ||
| 436 | + return domain.QuerySetLog.ToString() | ||
| 437 | + } | ||
| 423 | return domain.FormulaLog.ToString() | 438 | return domain.FormulaLog.ToString() |
| 424 | } | 439 | } |
| 425 | 440 | ||
| @@ -450,6 +465,9 @@ func (l *CopyQuerySetLog) LogType() string { | @@ -450,6 +465,9 @@ func (l *CopyQuerySetLog) LogType() string { | ||
| 450 | if qs.Type == domain.SchemaTable.ToString() || qs.Type == domain.SubProcessTable.ToString() { | 465 | if qs.Type == domain.SchemaTable.ToString() || qs.Type == domain.SubProcessTable.ToString() { |
| 451 | return domain.QuerySetLog.ToString() | 466 | return domain.QuerySetLog.ToString() |
| 452 | } | 467 | } |
| 468 | + if qs.Type == domain.CalculateTable.ToString() { | ||
| 469 | + return domain.QuerySetLog.ToString() | ||
| 470 | + } | ||
| 453 | return domain.FormulaLog.ToString() | 471 | return domain.FormulaLog.ToString() |
| 454 | } | 472 | } |
| 455 | 473 |
| @@ -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 |
| @@ -561,7 +564,7 @@ func formulaEditLog(ctx *domain.Context, querySet *domain.QuerySet, queryCompone | @@ -561,7 +564,7 @@ func formulaEditLog(ctx *domain.Context, querySet *domain.QuerySet, queryCompone | ||
| 561 | return res | 564 | return res |
| 562 | } | 565 | } |
| 563 | if oldQC.Formula.ExprSql != newQC.Formula.ExprSql { | 566 | if oldQC.Formula.ExprSql != newQC.Formula.ExprSql { |
| 564 | - res = append(res, NewFastSourceLog(domain.QuerySetLog, sourceId, &EditFormulaLog{ | 567 | + res = append(res, NewFastSourceLog(domain.FormulaLog, sourceId, &EditFormulaLog{ |
| 565 | LogEntry: entry, | 568 | LogEntry: entry, |
| 566 | OperationType: domain.EditCalculateItem, | 569 | OperationType: domain.EditCalculateItem, |
| 567 | Old: oldQC.Formula.ExprHuman, | 570 | Old: oldQC.Formula.ExprHuman, |
| @@ -588,12 +591,23 @@ func aggregationEditLog(ctx *domain.Context, querySet *domain.QuerySet, queryCom | @@ -588,12 +591,23 @@ func aggregationEditLog(ctx *domain.Context, querySet *domain.QuerySet, queryCom | ||
| 588 | for _, f := range oldQC.Aggregation.AggregationFields() { | 591 | for _, f := range oldQC.Aggregation.AggregationFields() { |
| 589 | mapOldAgFields[f.DisplayName] = f | 592 | mapOldAgFields[f.DisplayName] = f |
| 590 | } | 593 | } |
| 594 | + mapNewAgFields := make(map[string]*domain.AggregationField) | ||
| 595 | + for _, f := range newQC.Aggregation.AggregationFields() { | ||
| 596 | + mapNewAgFields[f.DisplayName] = f | ||
| 597 | + } | ||
| 591 | changList := make([]string, 0) | 598 | changList := make([]string, 0) |
| 592 | for _, f := range newQC.Aggregation.AggregationFields() { | 599 | for _, f := range newQC.Aggregation.AggregationFields() { |
| 593 | if v, ok := mapOldAgFields[f.DisplayName]; ok { | 600 | if v, ok := mapOldAgFields[f.DisplayName]; ok { |
| 594 | if f.Diff(v) { | 601 | if f.Diff(v) { |
| 595 | changList = append(changList, fmt.Sprintf("%s修改为%s", v.Info(), f.Info())) | 602 | changList = append(changList, fmt.Sprintf("%s修改为%s", v.Info(), f.Info())) |
| 596 | } | 603 | } |
| 604 | + } else { | ||
| 605 | + changList = append(changList, fmt.Sprintf("增加%s", f.Info())) | ||
| 606 | + } | ||
| 607 | + } | ||
| 608 | + for _, f := range oldQC.Aggregation.AggregationFields() { | ||
| 609 | + if _, ok := mapNewAgFields[f.DisplayName]; !ok { | ||
| 610 | + changList = append(changList, fmt.Sprintf("删除%s", f.Info())) | ||
| 597 | } | 611 | } |
| 598 | } | 612 | } |
| 599 | 613 | ||
| @@ -674,12 +688,16 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateItemTable(ctx *domain.Context | @@ -674,12 +688,16 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateItemTable(ctx *domain.Context | ||
| 674 | dependencyTables := querySet.GetDependencyTables(queryComponents) | 688 | dependencyTables := querySet.GetDependencyTables(queryComponents) |
| 675 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 689 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
| 676 | queryComponent := queryComponents[0] | 690 | queryComponent := queryComponents[0] |
| 691 | + //!!!warning:每个字段默认需要带函数,没有就补全max() | ||
| 692 | + //if queryComponent.Formula.MixTableModel() { | ||
| 693 | + // queryComponent.Formula.Complete() | ||
| 694 | + //} | ||
| 677 | field := DataField(querySet.Name, domain.String.ToString(), domain.MainTableField, 1) | 695 | field := DataField(querySet.Name, domain.String.ToString(), domain.MainTableField, 1) |
| 678 | if len(queryComponent.Formula.TableFields) > 0 { | 696 | if len(queryComponent.Formula.TableFields) > 0 { |
| 679 | field.SQLType = queryComponent.Formula.TableFields[0].FieldSQLType | 697 | field.SQLType = queryComponent.Formula.TableFields[0].FieldSQLType |
| 680 | } | 698 | } |
| 681 | var table *domain.Table = NewCopyTable(domain.TableType(querySet.Type), querySet.Name, []*domain.Field{field}, 1).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type)) | 699 | var table *domain.Table = NewCopyTable(domain.TableType(querySet.Type), querySet.Name, []*domain.Field{field}, 1).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type)) |
| 682 | - table.PK = nil | 700 | + //table.PK = nil |
| 683 | if querySet.QuerySetInfo.BindTableId > 0 { | 701 | if querySet.QuerySetInfo.BindTableId > 0 { |
| 684 | table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId}) | 702 | table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId}) |
| 685 | if err != nil { | 703 | if err != nil { |
| @@ -715,6 +733,9 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateTable(ctx *domain.Context, qu | @@ -715,6 +733,9 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateTable(ctx *domain.Context, qu | ||
| 715 | queryComponent.MasterTable = masterTable | 733 | queryComponent.MasterTable = masterTable |
| 716 | fields := make([]*domain.Field, 0) | 734 | fields := make([]*domain.Field, 0) |
| 717 | aggregationFields := queryComponent.Aggregation.AggregationFields() | 735 | aggregationFields := queryComponent.Aggregation.AggregationFields() |
| 736 | + if len(aggregationFields) == 0 { | ||
| 737 | + return nil, fmt.Errorf("行、值不能同时为空") | ||
| 738 | + } | ||
| 718 | selectedFields := make([]string, 0) | 739 | selectedFields := make([]string, 0) |
| 719 | for index, f := range aggregationFields { | 740 | for index, f := range aggregationFields { |
| 720 | // 数值类型转浮点类型, 兼容类似表达式 1 * 1.1 | 741 | // 数值类型转浮点类型, 兼容类似表达式 1 * 1.1 |
| @@ -776,6 +797,9 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str | @@ -776,6 +797,9 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str | ||
| 776 | return err | 797 | return err |
| 777 | } | 798 | } |
| 778 | table.Name = name | 799 | table.Name = name |
| 800 | + if table.TableType == domain.CalculateItem.ToString() && len(table.DataFields) > 0 { | ||
| 801 | + table.DataFields[0].Name = name | ||
| 802 | + } | ||
| 779 | if _, err := tableRepository.Save(table); err != nil { | 803 | if _, err := tableRepository.Save(table); err != nil { |
| 780 | return err | 804 | return err |
| 781 | } | 805 | } |
| @@ -68,7 +68,8 @@ func CreateRequestLogFilter(console bool) func(ctx *context.Context) { | @@ -68,7 +68,8 @@ func CreateRequestLogFilter(console bool) func(ctx *context.Context) { | ||
| 68 | 68 | ||
| 69 | func JwtFilter() func(ctx *context.Context) { | 69 | func JwtFilter() func(ctx *context.Context) { |
| 70 | return func(ctx *context.Context) { | 70 | return func(ctx *context.Context) { |
| 71 | - token := ctx.Request.Header.Get("Authorization") | 71 | + //token := ctx.Request.Header.Get("Authorization") |
| 72 | + token := ctx.Request.Header.Get("x-mmm-accesstoken") | ||
| 72 | if len(token) > 0 { | 73 | if len(token) > 0 { |
| 73 | token = strings.TrimPrefix(token, "Bearer ") | 74 | token = strings.TrimPrefix(token, "Bearer ") |
| 74 | userToken := &domain.UserToken{} | 75 | userToken := &domain.UserToken{} |
| @@ -49,19 +49,24 @@ func ParseContext(c beego.BaseController) *domain.Context { | @@ -49,19 +49,24 @@ func ParseContext(c beego.BaseController) *domain.Context { | ||
| 49 | userToken, ok := token.(*domain.UserToken) | 49 | userToken, ok := token.(*domain.UserToken) |
| 50 | if ok { | 50 | if ok { |
| 51 | // cache user info | 51 | // cache user info |
| 52 | - key := cache.KeyCompanyUser(companyId, userId) | ||
| 53 | - if cacheItem, ok := cache.DefaultCache.Get(key); ok { | ||
| 54 | - v := cacheItem.(*authlib.DataUserMe) | ||
| 55 | - userName = v.User.NickName | ||
| 56 | - } else { | ||
| 57 | - requestToken, _ := userToken.GenerateToken() | ||
| 58 | - authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST).WithToken(requestToken) | ||
| 59 | - userInfo, err := authLib.MeInfo(authlib.RequestUserMeQuery{}) | ||
| 60 | - if err != nil || userInfo == nil || userInfo.User == nil { | ||
| 61 | - goto END | 52 | + key := cache.KeyCompanyUser(int(userToken.CompanyId), int(userToken.UserId)) |
| 53 | + if userToken.CheckUserInfo() { | ||
| 54 | + if cacheItem, ok := cache.DefaultCache.Get(key); ok { | ||
| 55 | + v := cacheItem.(*authlib.DataUserMe) | ||
| 56 | + userName = v.User.NickName | ||
| 57 | + } else { | ||
| 58 | + requestToken, _ := userToken.GenerateToken() | ||
| 59 | + authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST).WithToken(requestToken) | ||
| 60 | + userInfo, err := authLib.MeInfo(authlib.RequestUserMeQuery{ | ||
| 61 | + UserId: int(userToken.UserId), | ||
| 62 | + CompanyId: int(userToken.CompanyId), | ||
| 63 | + }) | ||
| 64 | + if err != nil || userInfo == nil || userInfo.User == nil { | ||
| 65 | + goto END | ||
| 66 | + } | ||
| 67 | + userName = userInfo.User.NickName | ||
| 68 | + cache.DefaultCache.SetDefault(key, userInfo) | ||
| 62 | } | 69 | } |
| 63 | - userName = userInfo.User.NickName | ||
| 64 | - cache.DefaultCache.SetDefault(key, userInfo) | ||
| 65 | } | 70 | } |
| 66 | // assign user | 71 | // assign user |
| 67 | companyId = int(userToken.CompanyId) | 72 | companyId = int(userToken.CompanyId) |
| @@ -91,6 +91,17 @@ func (controller *LogController) QuerySetLog() { | @@ -91,6 +91,17 @@ func (controller *LogController) QuerySetLog() { | ||
| 91 | ResponseGrid(controller.BaseController, total, data, err) | 91 | ResponseGrid(controller.BaseController, total, data, err) |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | +func (controller *LogController) FormulaLog() { | ||
| 95 | + logService := service.NewLogService(nil) | ||
| 96 | + cmd := &command.SearchLogCommand{} | ||
| 97 | + controller.Unmarshal(cmd) | ||
| 98 | + cmd.LogType = domain.FormulaLog.ToString() | ||
| 99 | + cmd.SortByLogId = "DESC" | ||
| 100 | + cmd.Context = ParseContext(controller.BaseController) | ||
| 101 | + total, data, err := logService.SearchLog(cmd) | ||
| 102 | + ResponseGrid(controller.BaseController, total, data, err) | ||
| 103 | +} | ||
| 104 | + | ||
| 94 | func (controller *LogController) VerifiedStepLog() { | 105 | func (controller *LogController) VerifiedStepLog() { |
| 95 | logService := service.NewLogService(nil) | 106 | logService := service.NewLogService(nil) |
| 96 | cmd := &command.SearchLogCommand{} | 107 | cmd := &command.SearchLogCommand{} |
| @@ -15,4 +15,5 @@ func init() { | @@ -15,4 +15,5 @@ func init() { | ||
| 15 | web.Router("/data/logs/table-operate-Log", &controllers.LogController{}, "Post:TableOperateLog") | 15 | web.Router("/data/logs/table-operate-Log", &controllers.LogController{}, "Post:TableOperateLog") |
| 16 | web.Router("/data/logs/verified-step-Log", &controllers.LogController{}, "Post:VerifiedStepLog") | 16 | web.Router("/data/logs/verified-step-Log", &controllers.LogController{}, "Post:VerifiedStepLog") |
| 17 | web.Router("/data/logs/query-set-log", &controllers.LogController{}, "Post:QuerySetLog") | 17 | web.Router("/data/logs/query-set-log", &controllers.LogController{}, "Post:QuerySetLog") |
| 18 | + web.Router("/data/logs/formula-log", &controllers.LogController{}, "Post:FormulaLog") | ||
| 18 | } | 19 | } |
-
请 注册 或 登录 后发表评论