From e955bc2f0f61118ca7a8441ba90d535b0aad7341 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Fri, 1 Oct 2021 02:11:11 +0800 Subject: [PATCH] no message --- controller/openapi.go | 46 +++++++++++++++++++++++++++++++++++++------ test/utils_test.go | 6 ++++-- utils/helper.go | 31 +++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/controller/openapi.go b/controller/openapi.go index 36e7955..6d88a15 100644 --- a/controller/openapi.go +++ b/controller/openapi.go @@ -203,6 +203,10 @@ func (this *OpenApiController) UI2CSS(c *gin.Context) { } +func GetXMLNode(xmltype string ) string{ + return string("m_") + utils.ToSnakeString(xmltype) + "_" +} + func GetXmlController(path io.Reader) string{ list := list.List{} maps := map[string]int{} @@ -216,7 +220,6 @@ func GetXmlController(path io.Reader) string{ } switch startElement := token.(type) { case xml.StartElement: - log.Print(0,startElement.Name) if(list.Len() == 0){ ins := new(Controller) ins.Name = getAttr("name",startElement.Attr) @@ -232,27 +235,58 @@ func GetXmlController(path io.Reader) string{ } break case xml.EndElement: - log.Print(1,startElement.Name) break } } begin := list.Front() first := true + for begin.Next() != nil{ if begin.Value.(*Controller).Name != ""{ if first{ first = false }else{ - log.Print(begin.Value.(*Controller).Name," ",begin.Value.(*Controller).Type) if _,ok := maps[begin.Value.(*Controller).Type] ;ok{ maps[begin.Value.(*Controller).Type]++ }else{ maps[begin.Value.(*Controller).Type] = 1 } - // ui::Button* btn_add_new = dynamic_cast(FindControl(L"open_button")); - ret += fmt.Sprintf("ui::%s * = dynamic_cast(FindControl(L\"%s\"))\r\n",begin.Value.(*Controller).Type, - begin.Value.(*Controller).Type,begin.Value.(*Controller).Name) + + ret += fmt.Sprintf("ui::%s * m_%s_%d;\r\n", + begin.Value.(*Controller).Type, + utils.ToSnakeString(begin.Value.(*Controller).Type), + maps[begin.Value.(*Controller).Type]) + } + } + begin = begin.Next() + } + + ret+="\r\n\r\n" + + begin = list.Front() + first = true + for k := range maps { + delete(maps, k) + } + + for begin.Next() != nil{ + if begin.Value.(*Controller).Name != ""{ + if first{ + first = false + }else{ + if _,ok := maps[begin.Value.(*Controller).Type] ;ok{ + maps[begin.Value.(*Controller).Type]++ + }else{ + maps[begin.Value.(*Controller).Type] = 1 + } + + ret += fmt.Sprintf("ui::%s * m_%s_%d = dynamic_cast(FindControl(L\"%s\"))\r\n", + begin.Value.(*Controller).Type, + utils.ToSnakeString(begin.Value.(*Controller).Type), + maps[begin.Value.(*Controller).Type], + begin.Value.(*Controller).Type, + begin.Value.(*Controller).Name) } } begin = begin.Next() diff --git a/test/utils_test.go b/test/utils_test.go index da48fdb..965427c 100644 --- a/test/utils_test.go +++ b/test/utils_test.go @@ -1,7 +1,7 @@ /* * @Author: your name * @Date: 2021-02-27 21:31:29 - * @LastEditTime: 2021-09-20 01:32:26 + * @LastEditTime: 2021-10-01 01:12:40 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \background\test\utils_test.go @@ -33,7 +33,9 @@ func TestDDL2ORM(t *testing.T) { log.Print(gocode) } - +func TestVariableNameChange(t *testing.T){ + t.Log(utils.ToSnakeString("CaTest")) +} func TestSpeed(t *testing.T){ var tcpAddr *net.TCPAddr tcpAddr,_ = net.ResolveTCPAddr("tcp","192.168.5.133:7") diff --git a/utils/helper.go b/utils/helper.go index 316cfa9..fd2243c 100644 --- a/utils/helper.go +++ b/utils/helper.go @@ -7,7 +7,7 @@ import ( ) // 蛇形转驼峰 -func toCamelString(s string) string { +func ToCamelString(s string) string { data := make([]byte, 0, len(s)) j := false k := false @@ -31,6 +31,29 @@ func toCamelString(s string) string { return string(data[:]) } +func ToSnakeString(s string)string{ + data := make([]byte, 0, len(s)) + uper := false + num := len(s) - 1 + for i := 0; i <= num; i++ { + d := s[i] + if d >= 'A' && d <= 'Z' { + uper = true + } + if(uper){ + if(i != 0){ + data = append(data, '_') + data = append(data, d + 32) + }else{ + data = append(data, d + 32) + } + uper = false + }else{ + data = append(data, d) + } + } + return string(data) +} type FieldDesc struct { FiledName string `json:"field_name"` @@ -61,10 +84,10 @@ func CreateGoStruct(name string,doc []FieldDesc) string{ if len(doc) == 0{ return "" } - ret := fmt.Sprintf("golang gorm tag struct 代码:\r\ntype %s struct{\r\n",toCamelString(name)) + ret := fmt.Sprintf("golang gorm tag struct 代码:\r\ntype %s struct{\r\n",ToCamelString(name)) for _,v := range doc{ filed := "\t\t" - camelField := toCamelString(v.FiledName) + camelField := ToCamelString(v.FiledName) filed += camelField tag := fmt.Sprintf("`json:\"%s\" gorm:\"column:%s\" sql:\"%s\"`",v.FiledName,v.FiledName,v.FiledName) filed += " " + DDLType2Golang(v.Type) + " " + tag + " \r\n" @@ -82,7 +105,7 @@ func CreateMarkdownTable(name string,doc []FieldDesc) string{ if len(doc) == 0{ return "" } - ret := fmt.Sprintf("数据表 %s markdown 表格字段说明: \r\n",toCamelString(name)) + ret := fmt.Sprintf("数据表 %s markdown 表格字段说明: \r\n",ToCamelString(name)) ret += "|字段名称|字段类型|字段说明|是否主键| \r\n|-|-|-|-| \r\n" for _,v := range doc{ ret += fmt.Sprintf("|%s|%s||%t|\r\n",v.FiledName,v.Type,v.Primary)