提交 22aec936 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

add crc column

上级 0e35d947
......@@ -8,6 +8,7 @@ import (
logUtils "github.com/easysoft/zendata/src/utils/log"
numbUtils "github.com/easysoft/zendata/src/utils/numb"
_ "github.com/mattn/go-sqlite3"
"hash/crc32"
"strconv"
)
......@@ -32,7 +33,7 @@ func Upgrade() {
sheet := "Sheet1"
excel := excelize.NewFile()
headerData := []interface{}{"seq", "name", "state", "zipCode", "cityCode"}
headerData := []interface{}{"seq", "name", "state", "zipCode", "cityCode", "crc"}
colNumb := AddExcelRow(excel, sheet, 1, headerData)
rowIndex := 1
......@@ -86,11 +87,20 @@ func Upgrade() {
func AddExcelRow(excel *excelize.File, sheet string, rowIndex int, cols []interface{}) string {
start := byte('A')
var numb string
line := ""
for index, col := range cols {
numb = string(start + byte(index))
colNumb := numb + strconv.Itoa(rowIndex)
excel.SetCellValue(sheet, colNumb, col)
line = line + col.(string)
}
// 校验位
if rowIndex > 1 {
numb = string(start + byte(len(cols)))
crcField := crc32.ChecksumIEEE([]byte(line))
excel.SetCellValue(sheet, numb+strconv.Itoa(rowIndex), crcField)
}
return numb
......
package gen
import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
"strconv"
"strings"
)
func GenerateFieldValuesFromExcel(field *model.Field, fieldValue *model.FieldValue, level int) {
// get file and step string
rang := strings.TrimSpace(field.Range)
sectionArr := strings.Split(rang, ":")
file := sectionArr[0]
stepStr := "1"
if len(sectionArr) == 2 { stepStr = sectionArr[1] }
// read from file
list := make([]string, 0)
relaPath := constant.DataDir + file
list = strings.Split("str" + relaPath, "\n")
// get step and rand
rand := false
step := 1
if strings.ToLower(strings.TrimSpace(stepStr)) != "r" {
stepInt, err := strconv.Atoi(stepStr)
if err == nil {
step = stepInt
}
} else {
rand = true
}
// get index for data retrieve
numbs := GenerateIntItems(0, (int64)(len(list) - 1), step, rand)
// get data by index
index := 0
for _, numb := range numbs {
item := list[numb.(int64)]
if index >= constant.MaxNumb { break }
if strings.TrimSpace(item) == "" { continue }
fieldValue.Values = append(fieldValue.Values, item)
index = index + 1
}
if len(fieldValue.Values) == 0 {
fieldValue.Values = append(fieldValue.Values, "N/A")
}
}
func ConvertExcelToSQLite(file string) {
}
func ReadDataSQLite(table string) []string {
list := make([]string, 0)
return list
}
\ No newline at end of file
......@@ -3,9 +3,6 @@ package gen
import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
logUtils "github.com/easysoft/zendata/src/utils/log"
"io/ioutil"
"os"
"strconv"
"strings"
)
......@@ -40,6 +37,8 @@ func GenerateFieldChildren(field *model.Field, fieldValue *model.FieldValue, lev
func GenerateFieldValues(field *model.Field, fieldValue *model.FieldValue, level int) {
if strings.Index(field.Range, ".txt") > -1 {
GenerateFieldValuesFromText(field, fieldValue, level)
} else if strings.Index(field.Range, ".xlsx") > -1 {
GenerateFieldValuesFromExcel(field, fieldValue, level)
} else {
GenerateFieldValuesFromList(field, fieldValue, level)
}
......@@ -98,69 +97,6 @@ func GenerateFieldValuesFromList(field *model.Field, fieldValue *model.FieldValu
}
}
func GenerateFieldValuesFromText(field *model.Field, fieldValue *model.FieldValue, level int) {
// get file and step string
rang := strings.TrimSpace(field.Range)
sectionArr := strings.Split(rang, ":")
file := sectionArr[0]
stepStr := "1"
if len(sectionArr) == 2 { stepStr = sectionArr[1] }
// read from file
list := make([]string, 0)
relaPath := constant.ResDir + file
content, err := ioutil.ReadFile(relaPath)
if err != nil {
logUtils.Screen("fail to read " + relaPath + ", try to use global config")
relaPath = "def" + string(os.PathSeparator) + file
content, err = ioutil.ReadFile(relaPath)
if err != nil {
logUtils.Screen("fail to read " + relaPath + ", will return")
fieldValue.Values = append(fieldValue.Values, "N/A")
return
} else {
logUtils.Screen("success to read " + relaPath)
}
} else {
logUtils.Screen("success to read " + relaPath)
}
str := string(content)
str = strings.Replace(str, "\\r\\n", "\\n", -1)
list = strings.Split(str, "\n")
// get step and rand
rand := false
step := 1
if strings.ToLower(strings.TrimSpace(stepStr)) != "r" {
stepInt, err := strconv.Atoi(stepStr)
if err == nil {
step = stepInt
}
} else {
rand = true
}
// get index for data retrieve
numbs := GenerateIntItems(0, (int64)(len(list) - 1), step, rand)
// get data by index
index := 0
for _, numb := range numbs {
item := list[numb.(int64)]
if index >= constant.MaxNumb { break }
if strings.TrimSpace(item) == "" { continue }
fieldValue.Values = append(fieldValue.Values, item)
index = index + 1
}
if len(fieldValue.Values) == 0 {
fieldValue.Values = append(fieldValue.Values, "N/A")
}
}
func CheckRangeType(startStr string, endStr string, stepStr string) (string, interface{}, int, bool) {
rand := false
......
package gen
import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
logUtils "github.com/easysoft/zendata/src/utils/log"
"io/ioutil"
"os"
"strconv"
"strings"
)
func GenerateFieldValuesFromText(field *model.Field, fieldValue *model.FieldValue, level int) {
// get file and step string
rang := strings.TrimSpace(field.Range)
sectionArr := strings.Split(rang, ":")
file := sectionArr[0]
stepStr := "1"
if len(sectionArr) == 2 { stepStr = sectionArr[1] }
// read from file
list := make([]string, 0)
relaPath := constant.ResDir + file
content, err := ioutil.ReadFile(relaPath)
if err != nil {
logUtils.Screen("fail to read " + relaPath + ", try to use global config")
relaPath = "def" + string(os.PathSeparator) + file
content, err = ioutil.ReadFile(relaPath)
if err != nil {
logUtils.Screen("fail to read " + relaPath + ", will return")
fieldValue.Values = append(fieldValue.Values, "N/A")
return
} else {
logUtils.Screen("success to read " + relaPath)
}
} else {
logUtils.Screen("success to read " + relaPath)
}
str := string(content)
str = strings.Replace(str, "\\r\\n", "\\n", -1)
list = strings.Split(str, "\n")
// get step and rand
rand := false
step := 1
if strings.ToLower(strings.TrimSpace(stepStr)) != "r" {
stepInt, err := strconv.Atoi(stepStr)
if err == nil {
step = stepInt
}
} else {
rand = true
}
// get index for data retrieve
numbs := GenerateIntItems(0, (int64)(len(list) - 1), step, rand)
// get data by index
index := 0
for _, numb := range numbs {
item := list[numb.(int64)]
if index >= constant.MaxNumb { break }
if strings.TrimSpace(item) == "" { continue }
fieldValue.Values = append(fieldValue.Values, item)
index = index + 1
}
if len(fieldValue.Values) == 0 {
fieldValue.Values = append(fieldValue.Values, "N/A")
}
}
\ No newline at end of file
......@@ -79,18 +79,7 @@ fields:
type: custom
range: custom.yaml
- name: id
note: 数字
type: list
range: 1-10000
isNumb: true
- name: field6
note: 复合字段的某一个字段,指定查询条件。
type: user.name
range: age>10
- name: field7
note: 复合字段取多个字段。
type: user
range: age>10
format: $name-$age-$sex
type: address.city
range: select name from address_city where state like '%山东%'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册