...
|
...
|
@@ -7,6 +7,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -24,13 +25,26 @@ func (repository *ObjectTableDataRepository) makeDropTableSQL(tableId int) (stri |
|
|
}
|
|
|
|
|
|
// makeCreateTableSQL 创建表SQL
|
|
|
func (repository *ObjectTableDataRepository) makeCreateTableSQL(tableId int, fields []*bytelib.Field) (string, error) {
|
|
|
func (repository *ObjectTableDataRepository) makeCreateTableSQL(tableId int, tableData bytelib.TableData) (string, error) {
|
|
|
fields := tableData.Fields
|
|
|
list := tableData.Grid.List
|
|
|
if len(fields) <= 0 {
|
|
|
return "", errors.New("缺少字段信息")
|
|
|
}
|
|
|
columns := make([]string, 0)
|
|
|
for _, item := range fields {
|
|
|
columns = append(columns, item.SQLName+" text ")
|
|
|
fieldType := "text"
|
|
|
//判断字段是否为id,并且数据值能转为整型 设置字段类型 为 int8,否则为 text
|
|
|
if item.SQLName == "id" && len(list) > 0 {
|
|
|
listItem := list[0]
|
|
|
if idValue, ok := listItem["id"]; ok {
|
|
|
_, err := strconv.Atoi(idValue)
|
|
|
if err == nil {
|
|
|
fieldType = "int8"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
columns = append(columns, item.SQLName+" "+fieldType+" ")
|
|
|
}
|
|
|
sql := `Create TABLE data."` + fmt.Sprintf("%v", tableId) + `" (` + strings.Join(columns, ",") + `);`
|
|
|
return sql, nil
|
...
|
...
|
@@ -92,7 +106,7 @@ func (repository *ObjectTableDataRepository) InsertWithTableData(ctx context.Con |
|
|
return err
|
|
|
}
|
|
|
//创建表
|
|
|
createTableSql, err := repository.makeCreateTableSQL(int(tableDataPreview.ObjectId), tableDataPreview.Fields)
|
|
|
createTableSql, err := repository.makeCreateTableSQL(int(tableDataPreview.ObjectId), tableDataPreview)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
...
|
...
|
|