diff --git a/QMPlusServer/model/autoCodeModel/autoCode.go b/QMPlusServer/model/autoCodeModel/autoCode.go index dd2cf8d773b319c7c58def23a2c8f4c6aa7ae03e..bd9cb1826315aef06fb803d2e6cd297f50209a6a 100644 --- a/QMPlusServer/model/autoCodeModel/autoCode.go +++ b/QMPlusServer/model/autoCodeModel/autoCode.go @@ -2,7 +2,6 @@ package autoCodeModel import ( "fmt" - log "gin-vue-admin/init/initlog" "html/template" "os" ) @@ -55,27 +54,28 @@ func Temp() { ComponentDictionary: nil, } a := AutoCodeStruct{ - StructName: "Test", - PackageName: "autocode", - Components: []Component{a1, a2}, + StructName: "Test", + PackageName: "autocode", + Abbreviation: "t", + Components: []Component{a1, a2}, } _dir := "../" + a.PackageName exist, err := pathExists(_dir) if err != nil { - log.L.Info("get dir error![%v]\n", err) + //log.L.Info(fmt.Sprintf("get dir error![%v]\n", err)) return } if exist { - log.L.Info("has dir![%v]\n", _dir) + //log.L.Info(fmt.Sprintf("has dir![%v]\n"+_dir)) } else { - log.L.Info("no dir![%v]\n", _dir) + //log.L.Info(fmt.Sprintf("no dir![%v]\n"+_dir)) // 创建文件夹 err := os.Mkdir(_dir, os.ModePerm) if err != nil { - log.L.Error("mkdir failed![%v]\n", err) + //log.L.Error(fmt.Sprintf("mkdir error![%v]\n",err)) } else { - log.L.Info("mkdir success!\n") + //log.L.Info("mkdir success!\n") } } file, err := os.OpenFile("../"+a.PackageName+"/struct.go", os.O_CREATE|os.O_WRONLY, 0755) diff --git a/QMPlusServer/tpl/te/struct.go.tpl b/QMPlusServer/tpl/te/struct.go.tpl index 290141009d05ab7745eab60c25b15dfa57b8be96..47a74c8142c21546de8845b587b92973fbd948b6 100644 --- a/QMPlusServer/tpl/te/struct.go.tpl +++ b/QMPlusServer/tpl/te/struct.go.tpl @@ -6,7 +6,6 @@ import ( "gin-vue-admin/init/qmsql" "gin-vue-admin/model/modelInterface" "github.com/jinzhu/gorm" - "github.com/pkg/errors" ) type {{.StructName}} struct { @@ -15,22 +14,38 @@ type {{.StructName}} struct { } // 创建{{.StructName}} -func ({{.Abbreviation}} *{{StructName}})Create{{.StructName}}()(err error){ +func ({{.Abbreviation}} *{{.StructName}})Create{{.StructName}}()(err error){ err = qmsql.DEFAULTDB.Create({{.Abbreviation}}).Error return err } // 删除{{.StructName}} -func ({{.Abbreviation}} *{{StructName}})Delete{{.StructName}}()(err error){ +func ({{.Abbreviation}} *{{.StructName}})Delete{{.StructName}}()(err error){ err = qmsql.DEFAULTDB.Delete({{.Abbreviation}}).Error return err } // 更新{{.StructName}} -func ({{.Abbreviation}} *{{StructName}})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){ - +func ({{.Abbreviation}} *{{.StructName}})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){ + err = qmsql.DEFAULTDB.Save({{.Abbreviation}}).Error + return err, *{{.Abbreviation}} } -func ({{.Abbreviation}} *{{StructName}})Create(){ +// 根据ID查看单条{{.StructName}} +func ({{.Abbreviation}} *{{.StructName}})FindById()(err error,re{{.Abbreviation}} {{.StructName}}){ + err = qmsql.DEFAULTDB.Where("id = ?",{{.Abbreviation}}.ID).First(&re{{.Abbreviation}}).Error + return err,re{{.Abbreviation}} +} +// 分页获取{{.StructName}} +func ({{.Abbreviation}} *{{.StructName}})GetInfoList(info modelInterface.PageInfo)(err error, list interface{}, total int){ + // 封装分页方法 调用即可 传入 当前的结构体和分页信息 + err, db, total := servers.PagingServer({{.Abbreviation}}, info) + if err != nil { + return + } else { + var re{{.StructName}}List []{{.StructName}} + err = db.Find(&re{{.StructName}}List).Error + return err, re{{.StructName}}List, total + } } \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue b/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue index dfa172eb0dd11b78dbb16d8430ceec63ae67cae9..67056cb48f0c2332b1c28daf13f35f5df357a404 100644 --- a/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue +++ b/QMPlusVuePage/src/view/superAdmin/autoCode/index.vue @@ -7,6 +7,9 @@ + + +