修复树表上级关系绑定验证,优化CURD代码生成

This commit is contained in:
孟帅
2023-05-29 20:24:13 +08:00
parent d8024d73f8
commit c8a808fcfd
49 changed files with 1453 additions and 1001 deletions

View File

@@ -20,6 +20,16 @@ import (
"hotgo/utility/validate"
)
@{ if eq .options.Step.HasEdit true }
// @{.varName}UpdateFields 修改@{.tableComment}字段过滤
type @{.varName}UpdateFields struct {
@{.updateFieldsColumns}
}
// @{.varName}InsertFields 新增@{.tableComment}字段过滤
type @{.varName}InsertFields struct {
@{.insertFieldsColumns}
}
// @{.varName}EditInp 修改/新增@{.tableComment}
type @{.varName}EditInp struct {
entity.@{.daoName}
@@ -97,6 +107,20 @@ type @{.varName}StatusInp struct {
}
func (in *@{.varName}StatusInp) Filter(ctx context.Context) (err error) {
if in.@{.pk.GoName} <= 0 {
err = gerror.New("@{.pk.Dc}不能为空")
return
}
if in.Status <= 0 {
err = gerror.New("状态不能为空")
return
}
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
err = gerror.New("状态不正确")
return
}
return
}

View File

@@ -16,7 +16,6 @@ import (
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/library/contexts"
"hotgo/internal/library/hgorm"
@@ -50,12 +49,21 @@ func (s *s@{.servFunName}) List(ctx context.Context, in @{.templateGroup}in.@{.v
@{.listWhere}
@{.listJoin.link}
totalCount, err = mod.Clone().Count()
if totalCount == 0 || err != nil {
if err != nil {
err = gerror.Wrap(err, "获取@{.tableComment}数据行失败,请稍后重试!")
return
}
if totalCount == 0 {
return
}
@{.listJoin.select}
err = mod.Fields(@{.listJoin.fields}).Page(in.Page, in.PerPage).@{.listOrder}.Scan(&list)
if err = mod.Fields(@{.listJoin.fields}).Page(in.Page, in.PerPage).@{.listOrder}.Scan(&list);err != nil {
err = gerror.Wrap(err, "获取@{.tableComment}列表失败,请稍后重试!")
return
}
return
}
@{ if eq .options.Step.HasExport true }
@@ -102,13 +110,17 @@ func (s *s@{.servFunName}) Edit(ctx context.Context, in @{.templateGroup}in.@{.v
@{ if eq .options.Step.HasDel true }
// Delete 删除@{.tableComment}
func (s *s@{.servFunName}) Delete(ctx context.Context, in @{.templateGroup}in.@{.varName}DeleteInp) (err error) {
_, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Delete()
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Delete();err != nil {
err = gerror.Wrap(err, "删除@{.tableComment}失败,请稍后重试!")
return
}
return
}@{end}
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
// MaxSort 获取@{.tableComment}最大排序
func (s *s@{.servFunName}) MaxSort(ctx context.Context, in @{.templateGroup}in.@{.varName}MaxSortInp) (res *@{.templateGroup}in.@{.varName}MaxSortModel, err error) {
if err = dao.@{.daoName}.Ctx(ctx).Fields(dao.@{.daoName}.Columns().Sort).OrderDesc(dao.@{.daoName}.Columns().Sort).Scan(&res); err != nil {
err = gerror.Wrap(err, "获取@{.tableComment}最大排序,请稍后重试!")
return
}
@@ -123,28 +135,19 @@ func (s *s@{.servFunName}) MaxSort(ctx context.Context, in @{.templateGroup}in.@
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// View 获取@{.tableComment}指定信息
func (s *s@{.servFunName}) View(ctx context.Context, in @{.templateGroup}in.@{.varName}ViewInp) (res *@{.templateGroup}in.@{.varName}ViewModel, err error) {
err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Scan(&res)
if err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Scan(&res);err != nil {
err = gerror.Wrap(err, "获取@{.tableComment}信息,请稍后重试!")
return
}
return
}@{end}
@{ if eq .options.Step.HasStatus true }
// Status 更新@{.tableComment}状态
func (s *s@{.servFunName}) Status(ctx context.Context, in @{.templateGroup}in.@{.varName}StatusInp) (err error) {
if in.@{.pk.GoName} <= 0 {
err = gerror.New("@{.pk.Dc}不能为空")
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Data(@{.statusUpdate}).Update();err != nil {
err = gerror.Wrap(err, "更新@{.tableComment}状态失败,请稍后重试!")
return
}
if in.Status <= 0 {
err = gerror.New("状态不能为空")
return
}
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
err = gerror.New("状态不正确")
return
}
_, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(@{.statusUpdate}).Update()
return
}
@{end}
@@ -161,7 +164,10 @@ func (s *s@{.servFunName}) Switch(ctx context.Context, in @{.templateGroup}in.@{
return
}
_, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(@{.switchUpdate}).Update()
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Data(@{.switchUpdate}).Update();err != nil {
err = gerror.Wrap(err, "更新@{.tableComment}开关失败,请稍后重试!")
return
}
return
}
@{end}