...
|
...
|
@@ -100,6 +100,22 @@ func (ptr *QuerySetService) Update(ctx *domain.Context, querySetId int, queryCom |
|
|
}
|
|
|
|
|
|
// 调用底层的组装sql
|
|
|
formulasGenerateResponse, err := ByteCore.FormulasGenerate(domain.ReqFormulasGenerate{
|
|
|
QuerySet: qs,
|
|
|
Table: table,
|
|
|
QueryComponents: queryComponents,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName {
|
|
|
table.SQLName = formulasGenerateResponse.FormulaName
|
|
|
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
|
|
|
table, err = tableRepository.Save(table)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 生成日志
|
|
|
if err = ptr.UpdateQuerySetLog(ctx, qs, queryComponents); err != nil {
|
...
|
...
|
@@ -311,7 +327,7 @@ func (ptr *QuerySetService) CreateOrUpdateQuerySetTable(ctx *domain.Context, que |
|
|
return nil, err
|
|
|
}
|
|
|
masterTable = domain.NewQueryComponentTable(foundMasterTable)
|
|
|
var table *domain.Table = NewTable(domain.TableType(querySet.Type), querySet.Name, masterTable.Fields, 0).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type))
|
|
|
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))
|
|
|
if querySet.QuerySetInfo.BindTableId > 0 {
|
|
|
table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId})
|
|
|
if err != nil {
|
...
|
...
|
@@ -320,22 +336,37 @@ func (ptr *QuerySetService) CreateOrUpdateQuerySetTable(ctx *domain.Context, que |
|
|
table.DataFields = masterTable.Fields
|
|
|
table.UpdatedAt = time.Now()
|
|
|
}
|
|
|
|
|
|
// 循环依赖判断
|
|
|
tableDependencyService, _ := NewTableDependencyService(ptr.transactionContext)
|
|
|
var validTables = make([]*domain.Table, 0)
|
|
|
if len(dependencyTables) > 0 {
|
|
|
_, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": dependencyTables, "tableTypes": []string{domain.SchemaTable.ToString(), domain.SubProcessTable.ToString()}})
|
|
|
_, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": dependencyTables})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if len(tables) > 0 {
|
|
|
tree := tableDependencyService.TableDependTree(tables, querySet.QuerySetInfo.BindTableId)
|
|
|
if tableDependencyService.Detect(ctx, tree.EdgesArray()) {
|
|
|
return nil, NewCircleDependError(tableDependencyService.CircleTable(), querySet)
|
|
|
tableMap := make(map[int]*domain.Table)
|
|
|
for i := range tables {
|
|
|
tableMap[tables[i].TableId] = tables[i]
|
|
|
}
|
|
|
for _, c := range queryComponents {
|
|
|
if t, ok := tableMap[c.MasterTable.TableId]; ok {
|
|
|
c.MasterTable = domain.NewQueryComponentTable(t)
|
|
|
}
|
|
|
}
|
|
|
for _, t := range validTables {
|
|
|
if t.TableType == domain.SchemaTable.ToString() || t.TableType == domain.SubProcessTable.ToString() {
|
|
|
validTables = append(validTables, t)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 循环依赖判断
|
|
|
tableDependencyService, _ := NewTableDependencyService(ptr.transactionContext)
|
|
|
if len(validTables) > 0 {
|
|
|
tree := tableDependencyService.TableDependTree(validTables, querySet.QuerySetInfo.BindTableId)
|
|
|
if tableDependencyService.Detect(ctx, tree.EdgesArray()) {
|
|
|
return nil, NewCircleDependError(tableDependencyService.CircleTable(), querySet)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
table.TableInfo.ApplyOnModule = domain.ModuleAll
|
|
|
table.TableInfo.DependencyTables = dependencyTables
|
|
|
table, err = tableRepository.Save(table)
|
...
|
...
|
@@ -392,6 +423,22 @@ func (ptr *QuerySetService) ChangeStatus(ctx *domain.Context, querySetId int, st |
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
if qs.QuerySetInfo.BindTableId != 0 {
|
|
|
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
|
|
|
table, err := tableRepository.FindOne(map[string]interface{}{"tableId": qs.QuerySetInfo.BindTableId})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if status == domain.StatusOn {
|
|
|
table.TableInfo.SetApplyOn(domain.ModuleAll)
|
|
|
} else {
|
|
|
table.TableInfo.SetApplyOn(domain.ModuleQuerySetCenter | domain.ModuleCalculateCenter)
|
|
|
}
|
|
|
if _, err = tableRepository.Save(table); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -417,14 +464,37 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string, |
|
|
if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == name {
|
|
|
return ErrQuerySetNameExists
|
|
|
}
|
|
|
// TODO:create-table
|
|
|
if copy.QuerySetInfo.BindTableId != 0 {
|
|
|
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
|
|
|
table, err := tableRepository.FindOne(map[string]interface{}{"tableId": copy.QuerySetInfo.BindTableId})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
NewTable(domain.TableType(t), name, table.DataFields, 0).WithContext(ctx)
|
|
|
copyTable := NewTable(domain.TableType(t), name, table.Fields(false), 0).WithContext(ctx).WithPrefix(qs.Type)
|
|
|
|
|
|
copyTable, err = tableRepository.Save(copyTable)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 调用底层的组装sql
|
|
|
formulasGenerateResponse, err := ByteCore.FormulasGenerate(domain.ReqFormulasGenerate{
|
|
|
QuerySet: qs,
|
|
|
Table: table,
|
|
|
QueryComponents: qs.QueryComponents,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName {
|
|
|
copyTable.SQLName = formulasGenerateResponse.FormulaName
|
|
|
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
|
|
|
copyTable, err = tableRepository.Save(copyTable)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
copy.QuerySetInfo.BindTableId = copyTable.TableId
|
|
|
}
|
|
|
_, err = querySetRepository.Save(copy)
|
|
|
if err != nil {
|
...
|
...
|
@@ -469,6 +539,9 @@ func (ptr *QuerySetService) Delete(ctx *domain.Context, querySetId int) error { |
|
|
if err := dao.TableSoftDelete(ptr.transactionContext, querySets[i].QuerySetInfo.BindTableId, domain.TableType(querySets[i].Type)); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
ByteCore.FormulasClear(domain.ReqFormulasClear{
|
|
|
QuerySetId: querySets[i].QuerySetId,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
// 日志
|
...
|
...
|
@@ -620,3 +693,21 @@ func (ptr *QuerySetService) GetAllChild(ctx *domain.Context, querySetId int, inc |
|
|
}
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
DROP VIEW IF EXISTS schema_xiao_shou_ming_xi_fen_biao_t456157_c1;
|
|
|
create view schema_xiao_shou_ming_xi_fen_biao_t456157_c1(
|
|
|
hui_zong_qu_yu_c5 COMMENT "汇总区域"
|
|
|
) as(
|
|
|
WITH xiao_shou_ming_xi_fen_biao_t456157_c1 AS (
|
|
|
SELECT
|
|
|
IF
|
|
|
( 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
|
|
|
FROM
|
|
|
xiao_shou_ming_xi_fen_biao_t456157_c1
|
|
|
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
|
|
|
)
|
|
|
SELECT *
|
|
|
FROM
|
|
|
xiao_shou_ming_xi_fen_biao_t456157_c1
|
|
|
*/ |
...
|
...
|
|