no message

master
zcy 2021-10-01 02:11:11 +08:00
parent 977b272ec6
commit e955bc2f0f
3 changed files with 71 additions and 12 deletions

View File

@ -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{ func GetXmlController(path io.Reader) string{
list := list.List{} list := list.List{}
maps := map[string]int{} maps := map[string]int{}
@ -216,7 +220,6 @@ func GetXmlController(path io.Reader) string{
} }
switch startElement := token.(type) { switch startElement := token.(type) {
case xml.StartElement: case xml.StartElement:
log.Print(0,startElement.Name)
if(list.Len() == 0){ if(list.Len() == 0){
ins := new(Controller) ins := new(Controller)
ins.Name = getAttr("name",startElement.Attr) ins.Name = getAttr("name",startElement.Attr)
@ -232,27 +235,58 @@ func GetXmlController(path io.Reader) string{
} }
break break
case xml.EndElement: case xml.EndElement:
log.Print(1,startElement.Name)
break break
} }
} }
begin := list.Front() begin := list.Front()
first := true first := true
for begin.Next() != nil{ for begin.Next() != nil{
if begin.Value.(*Controller).Name != ""{ if begin.Value.(*Controller).Name != ""{
if first{ if first{
first = false first = false
}else{ }else{
log.Print(begin.Value.(*Controller).Name," ",begin.Value.(*Controller).Type)
if _,ok := maps[begin.Value.(*Controller).Type] ;ok{ if _,ok := maps[begin.Value.(*Controller).Type] ;ok{
maps[begin.Value.(*Controller).Type]++ maps[begin.Value.(*Controller).Type]++
}else{ }else{
maps[begin.Value.(*Controller).Type] = 1 maps[begin.Value.(*Controller).Type] = 1
} }
// ui::Button* btn_add_new = dynamic_cast<ui::Button*>(FindControl(L"open_button"));
ret += fmt.Sprintf("ui::%s * = dynamic_cast<ui::%s*>(FindControl(L\"%s\"))\r\n",begin.Value.(*Controller).Type, ret += fmt.Sprintf("ui::%s * m_%s_%d;\r\n",
begin.Value.(*Controller).Type,begin.Value.(*Controller).Name) 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<ui::%s*>(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() begin = begin.Next()

View File

@ -1,7 +1,7 @@
/* /*
* @Author: your name * @Author: your name
* @Date: 2021-02-27 21:31:29 * @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 * @LastEditors: Please set LastEditors
* @Description: In User Settings Edit * @Description: In User Settings Edit
* @FilePath: \background\test\utils_test.go * @FilePath: \background\test\utils_test.go
@ -33,7 +33,9 @@ func TestDDL2ORM(t *testing.T) {
log.Print(gocode) log.Print(gocode)
} }
func TestVariableNameChange(t *testing.T){
t.Log(utils.ToSnakeString("CaTest"))
}
func TestSpeed(t *testing.T){ func TestSpeed(t *testing.T){
var tcpAddr *net.TCPAddr var tcpAddr *net.TCPAddr
tcpAddr,_ = net.ResolveTCPAddr("tcp","192.168.5.133:7") tcpAddr,_ = net.ResolveTCPAddr("tcp","192.168.5.133:7")

View File

@ -7,7 +7,7 @@ import (
) )
// 蛇形转驼峰 // 蛇形转驼峰
func toCamelString(s string) string { func ToCamelString(s string) string {
data := make([]byte, 0, len(s)) data := make([]byte, 0, len(s))
j := false j := false
k := false k := false
@ -31,6 +31,29 @@ func toCamelString(s string) string {
return string(data[:]) 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 { type FieldDesc struct {
FiledName string `json:"field_name"` FiledName string `json:"field_name"`
@ -61,10 +84,10 @@ func CreateGoStruct(name string,doc []FieldDesc) string{
if len(doc) == 0{ if len(doc) == 0{
return "" 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{ for _,v := range doc{
filed := "\t\t" filed := "\t\t"
camelField := toCamelString(v.FiledName) camelField := ToCamelString(v.FiledName)
filed += camelField filed += camelField
tag := fmt.Sprintf("`json:\"%s\" gorm:\"column:%s\" sql:\"%s\"`",v.FiledName,v.FiledName,v.FiledName) tag := fmt.Sprintf("`json:\"%s\" gorm:\"column:%s\" sql:\"%s\"`",v.FiledName,v.FiledName,v.FiledName)
filed += " " + DDLType2Golang(v.Type) + " " + tag + " \r\n" filed += " " + DDLType2Golang(v.Type) + " " + tag + " \r\n"
@ -82,7 +105,7 @@ func CreateMarkdownTable(name string,doc []FieldDesc) string{
if len(doc) == 0{ if len(doc) == 0{
return "" return ""
} }
ret := fmt.Sprintf("数据表 %s markdown 表格字段说明: \r\n",toCamelString(name)) ret := fmt.Sprintf("数据表 %s markdown 表格字段说明: \r\n",ToCamelString(name))
ret += "|字段名称|字段类型|字段说明|是否主键| \r\n|-|-|-|-| \r\n" ret += "|字段名称|字段类型|字段说明|是否主键| \r\n|-|-|-|-| \r\n"
for _,v := range doc{ for _,v := range doc{
ret += fmt.Sprintf("|%s|%s||%t|\r\n",v.FiledName,v.Type,v.Primary) ret += fmt.Sprintf("|%s|%s||%t|\r\n",v.FiledName,v.Type,v.Primary)