作者 yangfu
提交者 yangfu

chore: compatible optimize

... ... @@ -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) {
... ...
... ... @@ -13,6 +13,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
"strings"
"time"
)
... ... @@ -311,6 +312,39 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear
return nil, factory.FastError(err)
}
if len(searchQuerySetQuery.MatchName) > 0 {
mapQuerySet := (domain.QuerySets(querySets)).ToMap()
tmpQuerySets := make([]*domain.QuerySet, 0)
for _, item := range querySets {
if strings.Contains(item.Name, searchQuerySetQuery.MatchName) {
tmpQuerySets = append(tmpQuerySets, item)
}
}
tmpParentQuerySets := make([]*domain.QuerySet, 0)
mapTmpParentQuerySets := (domain.QuerySets(tmpQuerySets)).ToMap()
for _, item := range tmpQuerySets {
var parentId = item.ParentId
for {
if parentId <= 0 {
break
}
v, ok := mapQuerySet[parentId]
if !ok {
break
}
if _, ok := mapTmpParentQuerySets[v.QuerySetId]; !ok {
mapTmpParentQuerySets[v.QuerySetId] = v
tmpParentQuerySets = append(tmpParentQuerySets, v)
}
parentId = v.ParentId
}
}
tmpQuerySets = append(tmpQuerySets, tmpParentQuerySets...)
querySets = tmpQuerySets
}
var result = dto.NewQuerySetDtoList(querySets)
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -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
}
... ...
... ... @@ -132,3 +132,13 @@ func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent)
sort.Ints(res)
return res
}
type QuerySets []*QuerySet
func (querySets QuerySets) ToMap() map[int]*QuerySet {
var result = make(map[int]*QuerySet)
for i := range querySets {
result[querySets[i].QuerySetId] = querySets[i]
}
return result
}
... ...
... ... @@ -12,6 +12,7 @@ type (
FormulaName string `json:"formulaName"`
FormulaType int `json:"formulaType"` //公式类型 1.方案2.子过程
FormulaConditions []FormulaCondition `json:"formulaConditions"`
FormulaCalculate *FormulaCalculate `json:"formulaCalculate"`
}
FormulasGenerateResponse struct {
... ... @@ -58,6 +59,25 @@ type (
FieldSchema FieldSchema `json:"fieldSchema"`
ConditionExpression string `json:"conditionExpression"`
}
FormulaCalculate struct {
DatabaseTableName string `json:"databaseTableName"`
FormulaCalculateFields []*FormulaCalculateField `json:"formulaCalculateFields"`
FormulaGroupFields []*FormulaGroupField `json:"formulaGroupFields"`
}
FormulaCalculateField struct {
DatabaseTableName string `json:"databaseTableName"`
FieldSchema FieldSchema `json:"fieldSchema"`
CalculateExpression string `json:"calculateExpression"`
// 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称)
CalculateFieldName string `json:"calculateFieldName"`
}
FormulaGroupField struct {
DatabaseTableName string `json:"databaseTableName"`
FieldSchema FieldSchema `json:"fieldSchema"`
// 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称)
GroupFieldName string `json:"groupFieldName"`
}
)
func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.QueryComponent) FormulasGenerateRequest {
... ... @@ -77,12 +97,20 @@ func NewFormulasGenerateRequest(table *domain.Table, queryComponents []*domain.Q
}
if table.TableType == domain.SchemaTable.ToString() {
req.FormulaType = 1
} else {
} else if table.TableType == domain.SubProcessTable.ToString() {
req.FormulaType = 2
} else if table.TableType == domain.CalculateTable.ToString() {
req.FormulaType = 3
} else if table.TableType == domain.CalculateItem.ToString() {
req.FormulaType = 4
}
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,51 @@ func NewFormulaCondition(queryComponent *domain.QueryComponent) FormulaCondition
return res
}
func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryComponent) *FormulaCalculate {
var res = &FormulaCalculate{
DatabaseTableName: "",
FormulaGroupFields: make([]*FormulaGroupField, 0),
FormulaCalculateFields: make([]*FormulaCalculateField, 0),
}
if queryComponent.Formula != nil {
formula := queryComponent.Formula
res.DatabaseTableName = formula.TableFields[0].TableSqlName
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: res.DatabaseTableName,
FieldSchema: NewFieldSchemaFromField(table.DataFields[0]),
CalculateExpression: formula.ExprSql,
CalculateFieldName: table.DataFields[0].SQLName,
})
}
if queryComponent.Aggregation != nil {
res.DatabaseTableName = queryComponent.MasterTable.SQLName
for _, f := range queryComponent.Aggregation.ValueFields {
tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name})
if !ok {
continue
}
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: queryComponent.MasterTable.SQLName,
FieldSchema: NewFieldSchemaFromField(f.Field),
CalculateExpression: f.Expr.ExprSql,
CalculateFieldName: tableField.SQLName,
})
}
for _, f := range queryComponent.Aggregation.RowFields {
tableField, ok := table.MatchField(&domain.Field{Name: f.Field.Name})
if !ok {
continue
}
res.FormulaGroupFields = append(res.FormulaGroupFields, &FormulaGroupField{
DatabaseTableName: queryComponent.MasterTable.SQLName,
FieldSchema: NewFieldSchemaFromField(f.Field),
GroupFieldName: tableField.SQLName,
})
}
}
return res
}
func NewFormulaSelectFields(t *domain.QueryComponentTable) FormulaSelectFields {
var res = FormulaSelectFields{
DatabaseTableName: t.SQLName,
... ... @@ -162,6 +235,17 @@ func NewFieldSchema(f domain.TableField) FieldSchema {
return res
}
func NewFieldSchemaFromField(f *domain.Field) FieldSchema {
var res = FieldSchema{
FieldZhName: f.Name,
FieldEnName: f.SQLName,
FieldType: f.SQLType,
FieldDescription: "",
IsAllowNull: true,
}
return res
}
func NewFormulaDataHandleRule(s domain.SelectExprGroup) FormulaDataHandleRule {
var res = FormulaDataHandleRule{
RuleType: 1,
... ...
... ... @@ -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()
}
... ...
... ... @@ -561,7 +561,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 +588,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()))
}
}
... ...
... ... @@ -160,7 +160,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{})
query.SetWhereByQueryOption("type = ?", "type")
query.SetWhereByQueryOption("flag = ?", "flag")
query.SetWhereByQueryOption("status = ?", "status")
query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName")
//query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName")
if v, ok := queryOptions["types"]; ok && len(v.([]string)) > 0 {
query.Where("type in (?)", pg.In(v))
}
... ...
... ... @@ -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{}
... ...
... ... @@ -50,18 +50,20 @@ func ParseContext(c beego.BaseController) *domain.Context {
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
if userToken.UserId != 0 {
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
}
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")
}
... ...