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

代码生成自动识别主键类型

yxh 4 лет назад
Родитель
Сommit
314d606944
2 измененных файлов с 5 добавлено и 5 удалено
  1. 2 2
      template/vm/go/controller.template
  2. 3 3
      template/vm/go/service.template

+ 2 - 2
template/vm/go/controller.template

@@ -112,7 +112,7 @@ func (c *{{$structName}}) Add(r *ghttp.Request) {
 
 // Get 获取
 func (c *{{$structName}}) Get(r *ghttp.Request) {
-	id := r.GetInt64("id")
+	id := r.Get{{$.table.PkColumn.GoType | CaseCamel}}("id")
 	info, err := service.{{.table.ClassName}}.GetInfoById(r.GetCtx(),id)
 	if err != nil {
 		c.FailJsonExit(r, err.Error())
@@ -161,7 +161,7 @@ func (c *{{$structName}}) Edit(r *ghttp.Request) {
 
 // Delete 删除
 func (c *{{$structName}}) Delete(r *ghttp.Request) {
-	ids := r.GetInts("ids")
+	ids := r.Get{{$.table.PkColumn.GoType | CaseCamel}}s("ids")
 	err := service.{{.table.ClassName}}.DeleteByIds(r.GetCtx(),ids)
 	if err != nil {
 		c.FailJsonExit(r, err.Error())

+ 3 - 3
template/vm/go/service.template

@@ -114,7 +114,7 @@ func (s *{{$structName}}) GetList(req *dao.{{.table.ClassName}}SearchReq) (total
 
 
 // GetInfoById 通过id获取
-func (s *{{$structName}}) GetInfoById(ctx context.Context,id int64) (info *model.{{.table.ClassName}}, err error) {
+func (s *{{$structName}}) GetInfoById(ctx context.Context,id {{$.table.PkColumn.GoType}}) (info *model.{{.table.ClassName}}, err error) {
 	if id == 0 {
 		err = gerror.New("参数错误")
 		return
@@ -148,7 +148,7 @@ func (s *{{$structName}}) Edit(ctx context.Context,req *dao.{{.table.ClassName}}
 
 
 // DeleteByIds 删除
-func (s *{{$structName}}) DeleteByIds(ctx context.Context,ids []int) (err error) {
+func (s *{{$structName}}) DeleteByIds(ctx context.Context,ids []{{$.table.PkColumn.GoType}}) (err error) {
 	if len(ids) == 0 {
 		err = gerror.New("参数错误")
 		return
@@ -182,7 +182,7 @@ func (s *{{$structName}}) Change{{$column.GoField}}(ctx context.Context,req *dao
 
 {{if eq .table.TplCategory "tree"}}
 // GetChildrenIds 通过ID获取子级ID
-func (s *{{$structName}})GetChildrenIds(ctx context.Context,ids []int) ([]int, error) {
+func (s *{{$structName}})GetChildrenIds(ctx context.Context,ids []{{$.table.PkColumn.GoType}}) ([]{{$.table.PkColumn.GoType}}, error) {
 	//获取所有
 	_,_,all, err := s.GetList(&dao.{{.table.ClassName}}SearchReq{PageReq:comModel.PageReq{Ctx: ctx}})
 	if err != nil {