作者 yangfu

fix: query set copy set default module

... ... @@ -67,22 +67,22 @@ func (table *Table) TableIdString() string {
func (table *Table) WithContext(ctx *Context) *Table {
rand.Seed(time.Now().Unix())
table.SQLName = fmt.Sprintf("%v_t%v_c%v", limitStringLen(table.SQLName,40), rand.Intn(1000000), limitStringLen(fmt.Sprintf("%d",ctx.CompanyId),8))
table.SQLName = fmt.Sprintf("%v_t%v_c%v", limitStringLen(table.SQLName, 40), rand.Intn(1000000), limitStringLen(fmt.Sprintf("%d", ctx.CompanyId), 8))
table.Context = ctx
return table
}
func limitStringLen(s string,l int)string{
result:=s
subLength :=l /2
if len(result)>l{
func limitStringLen(s string, l int) string {
result := s
subLength := l / 2
if len(result) > l {
result = result[:subLength] + result[len(result)-subLength:]
}
return result
}
func (table *Table) WithPrefix(prefix string) *Table {
if strings.HasPrefix(table.SQLName,"_"){
if strings.HasPrefix(table.SQLName, "_") {
table.SQLName = fmt.Sprintf("%v%v", strings.ToLower(prefix), table.SQLName)
return table
}
... ... @@ -90,6 +90,16 @@ func (table *Table) WithPrefix(prefix string) *Table {
return table
}
func (table *Table) ApplyDefaultModule() *Table {
if table.TableType == CalculateTable.ToString() || table.TableType == SubProcessTable.ToString() {
table.TableInfo.SetApplyOn(ModuleQuerySetCenter)
}
if table.TableType == SchemaTable.ToString() {
table.TableInfo.SetApplyOn(ModuleQuerySetCenter | ModuleCalculateCenter)
}
return table
}
func (table *Table) WithParentId(parentId int) *Table {
table.ParentId = parentId
return table
... ... @@ -146,10 +156,10 @@ func (t *Table) AssertTableType(types ...TableType) bool {
return false
}
func TableTypesToStringList(list ...TableType)[]string{
var result = make([]string,0)
for _,item:=range list{
func TableTypesToStringList(list ...TableType) []string {
var result = make([]string, 0)
for _, item := range list {
result = append(result, item.ToString())
}
return result
}
\ No newline at end of file
}
... ...
... ... @@ -937,7 +937,10 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string,
if err != nil {
return nil, err
}
copyTable := NewCopyTable(domain.TableType(t), name, table.Fields(false), 0).WithContext(ctx).WithPrefix(qs.Type)
copyTable := NewCopyTable(domain.TableType(t), name, table.Fields(false), 0).
WithContext(ctx).
WithPrefix(qs.Type).
ApplyDefaultModule()
copyTable, err = tableRepository.Save(copyTable)
if err != nil {
return nil, err
... ... @@ -949,18 +952,18 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string,
Table: copyTable,
QueryComponents: qs.QueryComponents,
QuerySetService: ptr,
Context: ctx,
Context: ctx,
})
if err != nil {
return nil, 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 nil, err
//}
//copyTable.SQLName = formulasGenerateResponse.FormulaName
//tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
//copyTable, err = tableRepository.Save(copyTable)
//if err != nil {
// return nil, err
//}
//}
copy.QuerySetInfo.BindTableId = copyTable.TableId
}
... ...