no message
parent
977b272ec6
commit
e955bc2f0f
|
@ -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<ui::Button*>(FindControl(L"open_button"));
|
||||
ret += fmt.Sprintf("ui::%s * = dynamic_cast<ui::%s*>(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<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()
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue