Просмотр исходного кода

修改 代码 自动生成器 不能适配于 pusher 的问题

paddy 4 лет назад
Родитель
Сommit
f786adc8a4
4 измененных файлов с 28 добавлено и 69 удалено
  1. 6 3
      code_gen/apigen/controller_gen.go
  2. 1 1
      code_gen/apigen/model_gen.go
  3. 0 62
      code_gen/gen.go
  4. 21 3
      code_gen/utils/utils.go

+ 6 - 3
code_gen/apigen/controller_gen.go

@@ -41,9 +41,12 @@ package gen
 import (
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
 	"github.com/gin-gonic/gin"
-	
-	"{{.app.ApplicationName}}/controllers/partial/{{.data.Dir}}"
-	
+
+{{if ne .data.Dir ""}}
+    "{{.app.ApplicationName}}/controllers/partial/{{.data.Dir}}"
+{{else}}
+    "{{.app.ApplicationName}}/controllers/partial"
+{{end}}
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/engine"
 )
 {{$dataName := CamelizeStr .data.Name true}}

+ 1 - 1
code_gen/apigen/model_gen.go

@@ -14,7 +14,7 @@ type {{$structName}} struct {
 
     {{range .data.ColumnList -}}
 	//{{.Caption}}
-	{{CamelizeStr .Name true}}   {{XormTime .Type}}   {{Backquote}}{{Xorm . | Unescaped}}json:"{{.Name}}"{{Backquote}}
+	{{CamelizeStr .Name true}}   {{FixType .Type}}   {{Backquote}}{{Xorm . | Unescaped}}json:"{{.Name}}"{{Backquote}}
     {{end}}
 }
 

+ 0 - 62
code_gen/gen.go

@@ -129,70 +129,8 @@ func DoGenerate(xmlfile string, isCompress bool) []byte {
 			tData,
 			isCompress)
 		res.Data = append(res.Data, *gr)
-
-		gr = utils.NewResult(
-			"sql",
-			fmt.Sprintf("%s/sqlconfig/%s_controller/%s_page_count.tpl", app.ApplicationName, table.Name, table.Name),
-			apigen.GenCount,
-			tData,
-			isCompress)
-		res.Data = append(res.Data, *gr)
-
-		gr = utils.NewResult(
-			"sql",
-			fmt.Sprintf("%s/sqlconfig/%s_controller/%s_page_select.tpl", app.ApplicationName, table.Name, table.Name),
-			apigen.GenSelect,
-			tData,
-			isCompress)
-		res.Data = append(res.Data, *gr)
-
-		gr = utils.NewResult(
-			"sql",
-			fmt.Sprintf("%s/sqlconfig/%s/%s_gen.xml", app.ApplicationName, app.ApplicationName, table.Name),
-			apigen.GenSql,
-			tData,
-			isCompress)
-		res.Data = append(res.Data, *gr)
 	}
 
-	/*
-		main := utils.GenerateResult{}
-		main.Type = "main"
-		main.Name ="main.go"
-
-		apiTpl := utils.GenerateResult{}
-		apiTpl.Type = "doc"
-		apiTpl.Name ="doc/api.tpl"
-
-		docker := utils.GenerateResult{}
-		docker.Type = "ci"
-		docker.Name ="Dockerfile"
-
-		godep := utils.GenerateResult{}
-		godep.Type = "ci"
-		godep.Name ="godep.yaml"
-
-		gitignore := utils.GenerateResult{}
-		gitignore.Type = "ci"
-		gitignore.Name =".gitignore"
-
-		drone := utils.GenerateResult{}
-		drone.Type = "ci"
-		drone.Name =".drone.yml"
-
-		vue := utils.GenerateResult{}
-		vue.Type = "vue"
-		vue.Name ="vue/api/modules/%s/index.js"
-
-		charts := utils.GenerateResult{}
-		charts.Type = "charts"
-		charts.Name ="charts/values.yaml"
-
-		chartsTmpl := utils.GenerateResult{}
-		chartsTmpl.Type = "charts"
-		chartsTmpl.Name ="charts/templates/config.yaml"
-	*/
-
 	out, err := json.Marshal(res)
 	if err != nil {
 		fmt.Println(err.Error())

+ 21 - 3
code_gen/utils/utils.go

@@ -273,8 +273,26 @@ func GenTemplate(templateText string, templateData interface{}, params map[strin
 				If(col.IsUnique, "unique", If(col.IsIndex, "index", "")))
 			return str
 		},
-		"XormTime": func(time string) interface{} {
-			return If(time == "local_time", "sysmodel.LocalTime", time)
+		"FixType": func(v string) interface{} {
+			vs := strings.Split(v, " ")
+			v0 := vs[0]
+			v1 := ""
+			if len(vs) > 1 {
+				v1 = vs[1]
+			}
+
+			if strings.HasPrefix(v0, "$") {
+				v0 = v0[1:]
+				v0 = CamelizeStr(v0, true)
+			} else if v0 == "local_time" {
+				return "sysmodel.LocalTime"
+			} else if v0 == "datetime" {
+				return "time.Time"
+			}
+			if v1 == "array" {
+				v0 = "[]" + v0
+			}
+			return v0
 		},
 		"Backquote": func() string {
 			return "`"
@@ -290,7 +308,7 @@ func GenTemplate(templateText string, templateData interface{}, params map[strin
 		"ParamsContainDT": func(params []XmlColumn) bool {
 			isContain := false
 			for _, v := range params {
-				if strings.ToLower(v.Type) == "local_time"  || strings.ToLower(v.DbType) == "datetime" {
+				if strings.ToLower(v.Type) == "local_time" || strings.ToLower(v.DbType) == "datetime" {
 					isContain = true
 					break
 				}