From e9ff27ce8b6f29954499733c69009d8b9669b9d2 Mon Sep 17 00:00:00 2001 From: public_host Date: Tue, 20 Apr 2021 10:46:40 +0800 Subject: [PATCH] fix --- hasaki-gen-crud/hasaki-gen-crud.js | 2 +- hasaki-gen-crud/template.go | 8 ++-- test.go | 94 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/hasaki-gen-crud/hasaki-gen-crud.js b/hasaki-gen-crud/hasaki-gen-crud.js index 1a9b431..2153ecd 100644 --- a/hasaki-gen-crud/hasaki-gen-crud.js +++ b/hasaki-gen-crud/hasaki-gen-crud.js @@ -93,7 +93,7 @@ try { text = text.replace(/Temp3A60/g, struct) let structHeadLower = struct structHeadLower[0] = struct[0].toLocaleLowerCase() - text = text.replace(/temp3A60/g, struct) + text = text.replace(/TempLowHead3A60/g, structHeadLower) text = text.replace(/Prefix3A60/g, prefix) console.log(text) console.log(endPosition) diff --git a/hasaki-gen-crud/template.go b/hasaki-gen-crud/template.go index 443c245..65b5119 100644 --- a/hasaki-gen-crud/template.go +++ b/hasaki-gen-crud/template.go @@ -62,7 +62,7 @@ func InitializationTemp3A60(router *hskgin.GinHelper) { //todo 权限控制 } - router.Any("/Prefix3A60/temp3A60/get", func(ctx *hskgin.GinContextHelper) { + router.Any("/Prefix3A60/TempLowHead3A60/get", func(ctx *hskgin.GinContextHelper) { authority(ctx) req := Temp3A60{} ctx.Bind(&req) @@ -71,7 +71,7 @@ func InitializationTemp3A60(router *hskgin.GinHelper) { ctx.DisplayByData(req) }) - router.Any("/Prefix3A60/temp3A60/save", func(ctx *hskgin.GinContextHelper) { + router.Any("/Prefix3A60/TempLowHead3A60/save", func(ctx *hskgin.GinContextHelper) { authority(ctx) req := Temp3A60{} ctx.Bind(&req) @@ -82,7 +82,7 @@ func InitializationTemp3A60(router *hskgin.GinHelper) { ctx.DisplayByData(req) }) - router.Any("/Prefix3A60/temp3A60/data", func(ctx *hskgin.GinContextHelper) { + router.Any("/Prefix3A60/TempLowHead3A60/data", func(ctx *hskgin.GinContextHelper) { authority(ctx) req := Temp3A60{} ctx.Bind(&req) @@ -90,7 +90,7 @@ func InitializationTemp3A60(router *hskgin.GinHelper) { ctx.DisplayByData(data) }) - router.Any("/Prefix3A60/temp3A60/list", func(ctx *hskgin.GinContextHelper) { + router.Any("/Prefix3A60/TempLowHead3A60/list", func(ctx *hskgin.GinContextHelper) { authority(ctx) req := Temp3A60{} ctx.Bind(&req) diff --git a/test.go b/test.go index c859281..8c4f214 100644 --- a/test.go +++ b/test.go @@ -1,9 +1,103 @@ package main +import ( + "git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb" + "git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin" +) + type MyTestr struct { Id int } +func (that *MyTestr) where() (q interface{}, args []interface{}) { + //todo 根据需求修改 + return "`id`=?", []interface{}{ + that.Id, + } +} + +func (that *MyTestr) Save(isAllCols ...bool) (err error) { + tmp := MyTestr{} + whereQuery, whereArgs := that.where() + hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Get(&tmp) + if tmp.Id == 0 { + _, err = hskdb.GetXormAuto().Insert(that) + } else { + if len(isAllCols) > 0 && isAllCols[0] { + _, err = hskdb.GetXormAuto().AllCols().Where(whereQuery, whereArgs...).Update(that) + } else { + _, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Update(that) + } + } + return err +} + +func (that *MyTestr) Load() (err error) { + whereQuery, whereArgs := that.where() + _, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Get(&that) + return +} + +func (that *MyTestr) Data() (data []MyTestr) { + hskdb.GetXormAuto().OrderBy("id desc").Find(&data) + return +} + +func (that *MyTestr) PageData(page, pageSize int) (data []MyTestr, count int64) { + count, _ = hskdb.GetXormAuto().OrderBy("id desc").Limit(pageSize, page*pageSize).FindAndCount(&data) + return +} + +func (that *MyTestr) Delete() (err error) { + whereQuery, whereArgs := that.where() + _, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Delete(&that) + return +} + +//该方法请不要放在db文件中 +func InitializationMyTestr(router *hskgin.GinHelper) { + var authority = func(ctx *hskgin.GinContextHelper) { + //todo 权限控制 + } + + router.Any("/admin/MyTestr/get", func(ctx *hskgin.GinContextHelper) { + authority(ctx) + req := MyTestr{} + ctx.Bind(&req) + err := req.Load() + ctx.CheckErrDisplayByError(err) + ctx.DisplayByData(req) + }) + + router.Any("/admin/MyTestr/save", func(ctx *hskgin.GinContextHelper) { + authority(ctx) + req := MyTestr{} + ctx.Bind(&req) + err := req.Save() + ctx.CheckErrDisplayByError(err) + err = req.Load() + ctx.CheckErrDisplayByError(err) + ctx.DisplayByData(req) + }) + + router.Any("/admin/MyTestr/data", func(ctx *hskgin.GinContextHelper) { + authority(ctx) + req := MyTestr{} + ctx.Bind(&req) + data := req.Data() + ctx.DisplayByData(data) + }) + + router.Any("/admin/MyTestr/list", func(ctx *hskgin.GinContextHelper) { + authority(ctx) + req := MyTestr{} + ctx.Bind(&req) + page := ctx.ParamRequired2Page(true) + data, count := req.PageData(page, 10) + ctx.DisplayByPage(data, count) + }) +} + type MyTestr2 struct { Id int }