作者 yangfu

Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/character-l…

…ibrary-metadata-bastion into test
... ... @@ -9,6 +9,7 @@ HTTP_PORT = 8081
ENABLE_KAFKA_LOG11 = true
HTTPS_PORT = 8143
ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com
# AUTH_SERVER_HOST = http://127.0.0.1:8081
BYTE_CORE_HOST = http://47.97.5.102:8303
METADATA_BASTION_HOST = http://106.75.231.90:9999
... ...
... ... @@ -13,7 +13,7 @@ type CalculateItemPreviewQuery struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
// 公式
Formula *domain.FieldExpr `json:"formula"`
Formula *domain.FieldExpr `json:"formula" valid:"Required"`
}
func (dependencyGraphQuery *CalculateItemPreviewQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -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
}
// 依赖关系图
... ... @@ -425,7 +428,9 @@ func (querySetService *QuerySetService) CalculateItemPreview(ctx *domain.Context
defer func() {
transactionContext.RollbackTransaction()
}()
if q.Formula.MixTableModel() {
q.Formula.ExprSql = q.Formula.Complete()
}
_, result := GetItemValues(transactionContext, q)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -480,6 +485,10 @@ func GetItemValues(transactionContext application.TransactionContext, q *query.C
if err != nil {
return nil, nil
}
if q.Formula.MixTableModel() {
q.Formula.ExprSql = q.Formula.Complete()
}
value := starrocks.CalculateItemValue(starrocks.DB, q.Formula)
var result = make([]itemValue, 0)
... ...
... ... @@ -18,7 +18,7 @@ type TableObjectDto struct {
// 父级ID
ParentId int `json:"parentId"`
// 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块
//Module int `json:"module"`
Module int `json:"module"`
// 标识
Flag string `json:"flag,omitempty"`
// 启用状态
... ... @@ -34,9 +34,9 @@ func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto {
d.Name = m.Name
d.ParentId = m.ParentId
d.SQLName = m.SQLName
//if m.TableInfo != nil {
// d.Module = m.TableInfo.ApplyOnModule
//}
if m.TableInfo != nil {
d.Module = m.TableInfo.ApplyOnModule
}
d.Fields = make([]*domain.Field, 0)
return d
}
... ...
... ... @@ -432,6 +432,9 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command
for _, f := range cmd.TableFields {
set.AddStr(f.TableSqlName)
}
if cmd.MixTableModel() {
cmd.ExprSql = cmd.Complete()
}
selectValue := cmd.ExprSql
//if _, parseErr := strconv.ParseFloat(cmd.ExprSql, 64); parseErr != nil {
// selectValue = "'" + selectValue + "'"
... ...
... ... @@ -24,7 +24,7 @@ var METADATA_BASTION_HOST = "http://127.0.0.1:8080"
var BYTE_CORE_HOST = "http://192.168.100.34:8303"
var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com/"
var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com"
//var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
... ... @@ -45,6 +45,7 @@ func init() {
BYTE_CORE_HOST = Configurator.DefaultString("BYTE_CORE_HOST", BYTE_CORE_HOST)
SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV)
HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT)
AUTH_SERVER_HOST = Configurator.DefaultString("AUTH_SERVER_HOST", AUTH_SERVER_HOST)
SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV)
PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON)
CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV
... ...
package domain
import "fmt"
import (
"fmt"
"github.com/zeromicro/go-zero/core/collection"
"strings"
)
var (
SchemaTable TableType = "Schema" // 方案
... ... @@ -95,6 +99,50 @@ type FieldExpr struct {
ExprSql string `json:"exprSql"`
}
func (expr *FieldExpr) Complete() string {
exprSql := expr.ExprSql
for _, f := range expr.TableFields {
sql := fmt.Sprintf("%s.%s", f.TableSqlName, f.FieldSqlName)
//zhSql := fmt.Sprintf("%s.%s", f.TableName, f.FieldSqlName)
sub := fmt.Sprintf("max(%s.%s)", f.TableSqlName, f.FieldSqlName)
//zhSub := fmt.Sprintf("max(%s.%s)", f.TableName, f.FieldSqlName)
if strings.Contains(expr.ExprSql, fmt.Sprintf("(%s)", sql)) {
continue
}
exprSql = strings.ReplaceAll(exprSql, sql, sub)
//expr.ExprSql = strings.ReplaceAll(expr.ExprSql, sql, sub)
//expr.ExprHuman = strings.ReplaceAll(expr.ExprHuman, zhSql, zhSub)
}
return exprSql
}
func (expr *FieldExpr) Tables() []int {
set := collection.NewSet()
for _, f := range expr.TableFields {
if f.TableId == 0 {
continue
}
set.Add(f.TableId)
}
return set.KeysInt()
}
func (expr *FieldExpr) MixTableModel() bool {
var result = 0
for _, f := range expr.TableFields {
if strings.HasPrefix(f.TableSqlName, strings.ToLower(CalculateItem.ToString())) {
if result&1 == 0 {
result += 1
}
} else {
if result&2 == 0 {
result += 2
}
}
}
return result == 3
}
type LabelColumn struct {
Column TableField `json:"column,omitempty"`
LabelExpr string `json:"labelExpr"`
... ...
... ... @@ -39,3 +39,8 @@ func (tk *UserToken) ParseToken(str string) error {
}
return errors.New("token 解析失败")
}
// CheckUserInfo 如果UserToken有效 返回:true 否则返回false
func (tk *UserToken) CheckUserInfo() bool {
return !(tk.UserId > 100000000 || tk.UserId <= 0)
}
... ...
package authlib
type RequestUserMeQuery struct {
Token string
//Token string
UserId int
CompanyId int
}
type DataUserMe struct {
... ...
... ... @@ -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
... ...
... ... @@ -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,14 +95,22 @@ 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
}
for i := range queryComponents {
req.FormulaConditions = append(req.FormulaConditions, NewFormulaCondition(queryComponents[i]))
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,
... ...
... ... @@ -7,7 +7,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
)
type ByteCoreService struct {
... ... @@ -129,24 +128,24 @@ func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalVal
func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
if param.QuerySet.Type == domain.CalculateItem.ToString() {
if err := starrocks.Exec(starrocks.DB,
starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields,
starrocks.CalculateItemViewSql(&param.QueryComponents[0].Formula.FieldExpr),
)); err != nil {
return nil, err
}
return &domain.DataFormulasGenerate{}, nil
}
if param.QuerySet.Type == domain.CalculateTable.ToString() {
if err := starrocks.Exec(starrocks.DB,
starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields,
starrocks.CalculateTableViewSql(param.QueryComponents[0].MasterTable.SQLName, &param.QueryComponents[0].Aggregation.Aggregation),
)); err != nil {
return nil, err
}
return &domain.DataFormulasGenerate{}, nil
}
//if param.QuerySet.Type == domain.CalculateItem.ToString() {
// if err := starrocks.Exec(starrocks.DB,
// starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields,
// starrocks.CalculateItemViewSql(&param.QueryComponents[0].Formula.FieldExpr),
// )); err != nil {
// return nil, err
// }
// return &domain.DataFormulasGenerate{}, nil
//}
//if param.QuerySet.Type == domain.CalculateTable.ToString() {
// if err := starrocks.Exec(starrocks.DB,
// starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields,
// starrocks.CalculateTableViewSql(param.QueryComponents[0].MasterTable.SQLName, &param.QueryComponents[0].Aggregation.Aggregation),
// )); err != nil {
// return nil, err
// }
// return &domain.DataFormulasGenerate{}, nil
//}
return apiByteLib.FormulasGenerate(param)
}
... ...
... ... @@ -368,7 +368,13 @@ func (l *CreateQuerySetLog) OperateType() string {
}
func (l *CreateQuerySetLog) LogType() string {
if l.Qs.Type == domain.SchemaTable.ToString() || l.Qs.Type == domain.SubProcessTable.ToString() {
if l.Qs.Type == domain.SchemaTable.ToString() {
return domain.QuerySetLog.ToString()
}
if l.Qs.Type == domain.SubProcessTable.ToString() {
return domain.QuerySetLog.ToString()
}
if l.Qs.Type == domain.CalculateTable.ToString() {
return domain.QuerySetLog.ToString()
}
return domain.FormulaLog.ToString()
... ... @@ -390,7 +396,13 @@ func (l *RenameQuerySetLog) OperateType() string {
}
func (l *RenameQuerySetLog) LogType() string {
if l.Qs.Type == domain.SchemaTable.ToString() || l.Qs.Type == domain.SubProcessTable.ToString() {
if l.Qs.Type == domain.SchemaTable.ToString() {
return domain.QuerySetLog.ToString()
}
if l.Qs.Type == domain.SubProcessTable.ToString() {
return domain.QuerySetLog.ToString()
}
if l.Qs.Type == domain.CalculateTable.ToString() {
return domain.QuerySetLog.ToString()
}
return domain.FormulaLog.ToString()
... ... @@ -420,6 +432,9 @@ func (l *DeleteQuerySetLog) LogType() string {
if qs.Type == domain.SchemaTable.ToString() || qs.Type == domain.SubProcessTable.ToString() {
return domain.QuerySetLog.ToString()
}
if qs.Type == domain.CalculateTable.ToString() {
return domain.QuerySetLog.ToString()
}
return domain.FormulaLog.ToString()
}
... ... @@ -450,6 +465,9 @@ func (l *CopyQuerySetLog) LogType() string {
if qs.Type == domain.SchemaTable.ToString() || qs.Type == domain.SubProcessTable.ToString() {
return domain.QuerySetLog.ToString()
}
if qs.Type == domain.CalculateTable.ToString() {
return domain.QuerySetLog.ToString()
}
return domain.FormulaLog.ToString()
}
... ...
... ... @@ -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
... ... @@ -561,7 +564,7 @@ func formulaEditLog(ctx *domain.Context, querySet *domain.QuerySet, queryCompone
return res
}
if oldQC.Formula.ExprSql != newQC.Formula.ExprSql {
res = append(res, NewFastSourceLog(domain.QuerySetLog, sourceId, &EditFormulaLog{
res = append(res, NewFastSourceLog(domain.FormulaLog, sourceId, &EditFormulaLog{
LogEntry: entry,
OperationType: domain.EditCalculateItem,
Old: oldQC.Formula.ExprHuman,
... ... @@ -588,12 +591,23 @@ func aggregationEditLog(ctx *domain.Context, querySet *domain.QuerySet, queryCom
for _, f := range oldQC.Aggregation.AggregationFields() {
mapOldAgFields[f.DisplayName] = f
}
mapNewAgFields := make(map[string]*domain.AggregationField)
for _, f := range newQC.Aggregation.AggregationFields() {
mapNewAgFields[f.DisplayName] = f
}
changList := make([]string, 0)
for _, f := range newQC.Aggregation.AggregationFields() {
if v, ok := mapOldAgFields[f.DisplayName]; ok {
if f.Diff(v) {
changList = append(changList, fmt.Sprintf("%s修改为%s", v.Info(), f.Info()))
}
} else {
changList = append(changList, fmt.Sprintf("增加%s", f.Info()))
}
}
for _, f := range oldQC.Aggregation.AggregationFields() {
if _, ok := mapNewAgFields[f.DisplayName]; !ok {
changList = append(changList, fmt.Sprintf("删除%s", f.Info()))
}
}
... ... @@ -674,12 +688,16 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateItemTable(ctx *domain.Context
dependencyTables := querySet.GetDependencyTables(queryComponents)
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
queryComponent := queryComponents[0]
//!!!warning:每个字段默认需要带函数,没有就补全max()
//if queryComponent.Formula.MixTableModel() {
// queryComponent.Formula.Complete()
//}
field := DataField(querySet.Name, domain.String.ToString(), domain.MainTableField, 1)
if len(queryComponent.Formula.TableFields) > 0 {
field.SQLType = queryComponent.Formula.TableFields[0].FieldSQLType
}
var table *domain.Table = NewCopyTable(domain.TableType(querySet.Type), querySet.Name, []*domain.Field{field}, 1).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type))
table.PK = nil
//table.PK = nil
if querySet.QuerySetInfo.BindTableId > 0 {
table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId})
if err != nil {
... ... @@ -715,6 +733,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
... ... @@ -776,6 +797,9 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str
return err
}
table.Name = name
if table.TableType == domain.CalculateItem.ToString() && len(table.DataFields) > 0 {
table.DataFields[0].Name = name
}
if _, err := tableRepository.Save(table); err != nil {
return err
}
... ...
... ... @@ -68,7 +68,8 @@ func CreateRequestLogFilter(console bool) func(ctx *context.Context) {
func JwtFilter() func(ctx *context.Context) {
return func(ctx *context.Context) {
token := ctx.Request.Header.Get("Authorization")
//token := ctx.Request.Header.Get("Authorization")
token := ctx.Request.Header.Get("x-mmm-accesstoken")
if len(token) > 0 {
token = strings.TrimPrefix(token, "Bearer ")
userToken := &domain.UserToken{}
... ...
... ... @@ -49,19 +49,24 @@ func ParseContext(c beego.BaseController) *domain.Context {
userToken, ok := token.(*domain.UserToken)
if ok {
// cache user info
key := cache.KeyCompanyUser(companyId, userId)
if cacheItem, ok := cache.DefaultCache.Get(key); ok {
v := cacheItem.(*authlib.DataUserMe)
userName = v.User.NickName
} else {
requestToken, _ := userToken.GenerateToken()
authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST).WithToken(requestToken)
userInfo, err := authLib.MeInfo(authlib.RequestUserMeQuery{})
if err != nil || userInfo == nil || userInfo.User == nil {
goto END
key := cache.KeyCompanyUser(int(userToken.CompanyId), int(userToken.UserId))
if userToken.CheckUserInfo() {
if cacheItem, ok := cache.DefaultCache.Get(key); ok {
v := cacheItem.(*authlib.DataUserMe)
userName = v.User.NickName
} else {
requestToken, _ := userToken.GenerateToken()
authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST).WithToken(requestToken)
userInfo, err := authLib.MeInfo(authlib.RequestUserMeQuery{
UserId: int(userToken.UserId),
CompanyId: int(userToken.CompanyId),
})
if err != nil || userInfo == nil || userInfo.User == nil {
goto END
}
userName = userInfo.User.NickName
cache.DefaultCache.SetDefault(key, userInfo)
}
userName = userInfo.User.NickName
cache.DefaultCache.SetDefault(key, userInfo)
}
// assign user
companyId = int(userToken.CompanyId)
... ...
... ... @@ -91,6 +91,17 @@ func (controller *LogController) QuerySetLog() {
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *LogController) FormulaLog() {
logService := service.NewLogService(nil)
cmd := &command.SearchLogCommand{}
controller.Unmarshal(cmd)
cmd.LogType = domain.FormulaLog.ToString()
cmd.SortByLogId = "DESC"
cmd.Context = ParseContext(controller.BaseController)
total, data, err := logService.SearchLog(cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *LogController) VerifiedStepLog() {
logService := service.NewLogService(nil)
cmd := &command.SearchLogCommand{}
... ...
... ... @@ -15,4 +15,5 @@ func init() {
web.Router("/data/logs/table-operate-Log", &controllers.LogController{}, "Post:TableOperateLog")
web.Router("/data/logs/verified-step-Log", &controllers.LogController{}, "Post:VerifiedStepLog")
web.Router("/data/logs/query-set-log", &controllers.LogController{}, "Post:QuerySetLog")
web.Router("/data/logs/formula-log", &controllers.LogController{}, "Post:FormulaLog")
}
... ...