作者 yangfu

fix: format sql name

package domainService
import (
"bytes"
"fmt"
"github.com/google/uuid"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -191,5 +192,29 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field {
}
func pin(name string) string {
return tool_funs.ToPinYin(name, "_")
pinyin := tool_funs.ToPinYin(name, "_")
newPinyin := bytes.NewBuffer(nil)
firstCharIsLetter := false
for i := range pinyin {
b := pinyin[i]
if !firstCharIsLetter {
firstCharIsLetter = isLetters(b)
}
if !firstCharIsLetter {
continue
}
if !(isDigital(b) || isLetters(b) || b == byte('_')) {
continue
}
newPinyin.WriteByte(b)
}
return newPinyin.String()
}
func isDigital(b byte) bool {
return b >= byte('0') && b <= byte('9')
}
func isLetters(b byte) bool {
return (b >= byte('a') && b <= byte('z')) || (b >= byte('A') && b <= byte('Z'))
}
... ...
... ... @@ -94,7 +94,12 @@ func (d *FilePreviewDto) Load(fileId int, m *domain.DataLoadDataTable, file *red
d.TableType = domain.ExcelTable.ToString()
d.Fields = m.Fields
var fields []*domain.Field
mapData := domain.ToFieldData(m.Fields, m.Data, true)
mapData := domain.ToFieldData(m.Fields, formatData(m.Data, func(s string) string {
if s == "<NA>" {
return ""
}
return s
}), true)
d.Data = domain.GripData(mapData, int64(m.Total))
d.PageNumber = m.PageNumber
... ... @@ -115,6 +120,15 @@ func (ptr *PreviewDataTableService) GetFileId() int {
return ptr.FileId
}
func formatData(data [][]string, f func(s string) string) [][]string {
for i := 0; i < len(data); i++ {
for j := 0; j < len(data[i]); j++ {
data[i][j] = f(data[i][j])
}
}
return data
}
func NewLoadDataTableService(transactionContext *pgTransaction.TransactionContext) (*PreviewDataTableService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...