提交 89e192e3 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

new definition format

上级 2892549e
...@@ -22,7 +22,10 @@ func Generate(def string, total int, fieldsToExportStr string, out string, forma ...@@ -22,7 +22,10 @@ func Generate(def string, total int, fieldsToExportStr string, out string, forma
fieldsToExport := strings.Split(fieldsToExportStr, ",") fieldsToExport := strings.Split(fieldsToExportStr, ",")
gen.LoadRootDef(def, fieldsToExport) rangeClsFields, instClsFields := gen.LoadClsDef(def, fieldsToExport)
rangeClsFields = rangeClsFields
instClsFields = instClsFields
rows, colTypes := gen.GenerateForDefinition(total, fieldsToExport) rows, colTypes := gen.GenerateForDefinition(total, fieldsToExport)
content := Print(rows, format, table, colTypes, fieldsToExport) content := Print(rows, format, table, colTypes, fieldsToExport)
......
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"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"strings"
)
func LoadClsDef(file string, fieldsToExport []string) []model.FieldValue {
referFieldValues := make([]model.FieldValue, 0)
yamlContent, err := ioutil.ReadFile(file)
if err != nil {
logUtils.Screen("fail to read " + file)
return referFieldValues
}
def := model.DefData{}
err = yaml.Unmarshal(yamlContent, &def)
if err != nil {
logUtils.Screen("fail to parse " + file)
return referFieldValues
}
constant.RootDef = def
for _, field := range def.Fields {
if !stringUtils.FindInArr(field.Field, fieldsToExport) { continue }
loadClsField(&field, &referFieldValues)
}
return referFieldValues
}
func loadClsField(field *model.DefField, referFieldValues *[]model.FieldValue) {
if len(field.Fields) > 0 {
for _, child := range field.Fields {
loadClsField(&child, referFieldValues)
}
} else if field.From != "" {
referFile, referType, tableName := getReferProp(field.From)
fieldValue := getReferFieldValue(referFile, referType, tableName)
*referFieldValues = append(*referFieldValues, fieldValue)
}
}
func getReferProp(from string) (string, string, string) {
referFile := ""
referType := ""
tableName := ""
sep := string(os.PathSeparator)
index := strings.LastIndex(from, ".yaml")
if index > -1 { // yaml, system.nubmer.yaml
left := from[:index]
left = strings.ReplaceAll(left, ".", sep)
referFile = left + ".yaml"
} else { // excel, system.address.china
index = strings.LastIndex(from, ".")
left := from[:index]
left = strings.ReplaceAll(left, ".", sep)
referFile = left + ".xlsx"
tableName = from[index:]
}
if strings.Index(referFile, "system") > -1 {
referFile = constant.ResDir + referFile
}
return referFile, referType, tableName
}
func getReferFieldValue(referFile string, referType string, tableName string) model.FieldValue {
fieldValue := model.FieldValue{}
return fieldValue
}
\ No newline at end of file
...@@ -7,12 +7,10 @@ import ( ...@@ -7,12 +7,10 @@ import (
stringUtils "github.com/easysoft/zendata/src/utils/string" stringUtils "github.com/easysoft/zendata/src/utils/string"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
"os"
"strings"
) )
func LoadRootDef(file string, fieldsToExport []string) ([]model.ClsRange, []model.ClsInst) { func LoadRootDef(file string, fieldsToExport []string) ([]model.ClsRanges, []model.ClsInst) {
referRangeFields := make([]model.ClsRange, 0) referRangeFields := make([]model.ClsRanges, 0)
referInstFields := make([]model.ClsInst, 0) referInstFields := make([]model.ClsInst, 0)
yamlContent, err := ioutil.ReadFile(file) yamlContent, err := ioutil.ReadFile(file)
...@@ -38,7 +36,7 @@ func LoadRootDef(file string, fieldsToExport []string) ([]model.ClsRange, []mode ...@@ -38,7 +36,7 @@ func LoadRootDef(file string, fieldsToExport []string) ([]model.ClsRange, []mode
if field.Select != "" { // excel if field.Select != "" { // excel
} else if field.Use != "" { // range or instance format } else if field.Use != "" { // range or instance format
//referFile, referType := getReferPath(field.From) //referFile, referType := getReferProp(field.From)
// init const.ResMap // init const.ResMap
} }
...@@ -49,33 +47,3 @@ func LoadRootDef(file string, fieldsToExport []string) ([]model.ClsRange, []mode ...@@ -49,33 +47,3 @@ func LoadRootDef(file string, fieldsToExport []string) ([]model.ClsRange, []mode
return referRangeFields, referInstFields return referRangeFields, referInstFields
} }
func getReferPath(from string) (string, string, string) {
referFile := ""
referType := ""
tableName := ""
sep := string(os.PathSeparator)
index := strings.LastIndex(from, ".yaml")
if index > -1 { // system.nubmer.yaml
left := from[:index]
left = strings.ReplaceAll(left, ".", sep)
referFile = left + ".yaml"
} else { // system.address.china
index = strings.LastIndex(from, ".")
left := from[:index]
left = strings.ReplaceAll(left, ".", sep)
referFile = left + ".xlsx"
tableName = from[index:]
}
if strings.Index(referFile, "system") > -1 {
referFile = constant.ResDir + referFile
}
return referFile, referType, tableName
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册