mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-15 06:23:44 +08:00
版本预发布
This commit is contained in:
@@ -28,16 +28,16 @@ type c@{.varName} struct{}
|
||||
func (c *c@{.varName}) List(ctx context.Context, req *@{.varName | ToLower}.ListReq) (res *@{.varName | ToLower}.ListRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}ListInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
list, totalCount, err := service.@{.templateGroup | UcFirst}@{.varName}().List(ctx, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.ListRes)
|
||||
@@ -45,24 +45,22 @@ func (c *c@{.varName}) List(ctx context.Context, req *@{.varName | ToLower}.List
|
||||
res.PageCount = form.CalPageCount(totalCount, req.PerPage)
|
||||
res.Page = req.Page
|
||||
res.PerPage = req.PerPage
|
||||
return res, nil
|
||||
return
|
||||
}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// Export 导出@{.tableComment}列表
|
||||
func (c *c@{.varName}) Export(ctx context.Context, req *@{.varName | ToLower}.ExportReq) (res *@{.varName | ToLower}.ExportRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}ListInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.@{.templateGroup | UcFirst}@{.varName}().Export(ctx, in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Export(ctx, in)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
@@ -70,17 +68,15 @@ func (c *c@{.varName}) Export(ctx context.Context, req *@{.varName | ToLower}.Ex
|
||||
func (c *c@{.varName}) Edit(ctx context.Context, req *@{.varName | ToLower}.EditReq) (res *@{.varName | ToLower}.EditRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}EditInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.@{.templateGroup | UcFirst}@{.varName}().Edit(ctx, in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Edit(ctx, in)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
@@ -88,12 +84,12 @@ func (c *c@{.varName}) Edit(ctx context.Context, req *@{.varName | ToLower}.Edit
|
||||
func (c *c@{.varName}) MaxSort(ctx context.Context, req *@{.varName | ToLower}.MaxSortReq) (res *@{.varName | ToLower}.MaxSortRes, err error) {
|
||||
data, err := service.@{.templateGroup | UcFirst}@{.varName}().MaxSort(ctx, sysin.@{.varName}MaxSortInp{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.MaxSortRes)
|
||||
res.@{.varName}MaxSortModel = data
|
||||
return res, nil
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasView true }
|
||||
@@ -101,21 +97,21 @@ func (c *c@{.varName}) MaxSort(ctx context.Context, req *@{.varName | ToLower}.M
|
||||
func (c *c@{.varName}) View(ctx context.Context, req *@{.varName | ToLower}.ViewReq) (res *@{.varName | ToLower}.ViewRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}ViewInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
data, err := service.@{.templateGroup | UcFirst}@{.varName}().View(ctx, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.ViewRes)
|
||||
res.@{.varName}ViewModel = data
|
||||
return res, nil
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
@@ -123,17 +119,15 @@ func (c *c@{.varName}) View(ctx context.Context, req *@{.varName | ToLower}.View
|
||||
func (c *c@{.varName}) Delete(ctx context.Context, req *@{.varName | ToLower}.DeleteReq) (res *@{.varName | ToLower}.DeleteRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}DeleteInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.@{.templateGroup | UcFirst}@{.varName}().Delete(ctx, in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Delete(ctx, in)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
@@ -141,17 +135,15 @@ func (c *c@{.varName}) Delete(ctx context.Context, req *@{.varName | ToLower}.De
|
||||
func (c *c@{.varName}) Status(ctx context.Context, req *@{.varName | ToLower}.StatusReq) (res *@{.varName | ToLower}.StatusRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}StatusInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.@{.templateGroup | UcFirst}@{.varName}().Status(ctx, in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Status(ctx, in)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
@@ -159,17 +151,14 @@ func (c *c@{.varName}) Status(ctx context.Context, req *@{.varName | ToLower}.St
|
||||
func (c *c@{.varName}) Switch(ctx context.Context, req *@{.varName | ToLower}.SwitchReq) (res *@{.varName | ToLower}.SwitchRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}SwitchInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.@{.templateGroup | UcFirst}@{.varName}().Switch(ctx, in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Switch(ctx, in)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// @{.varName}EditInp 修改/新增@{.tableComment}
|
||||
type @{.varName}EditInp struct {
|
||||
entity.Test
|
||||
entity.@{.daoName}
|
||||
}
|
||||
|
||||
func (in *@{.varName}EditInp) Filter(ctx context.Context) (err error) {
|
||||
@@ -38,6 +38,10 @@ type @{.varName}DeleteInp struct {
|
||||
@{.pk.GoName} interface{} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}DeleteInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}DeleteModel struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasView true }
|
||||
@@ -46,8 +50,12 @@ type @{.varName}ViewInp struct {
|
||||
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}ViewInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}ViewModel struct {
|
||||
entity.Test
|
||||
entity.@{.daoName}
|
||||
}@{end}
|
||||
|
||||
// @{.varName}ListInp 获取@{.tableComment}列表
|
||||
@@ -56,13 +64,14 @@ type @{.varName}ListInp struct {
|
||||
@{.listInpColumns}
|
||||
}
|
||||
|
||||
func (in *@{.varName}ListInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}ListModel struct {
|
||||
@{.listModelColumns}
|
||||
}
|
||||
|
||||
func (in *@{.varName}ListInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// @{.varName}ExportModel 导出@{.tableComment}
|
||||
type @{.varName}ExportModel struct {
|
||||
@@ -72,6 +81,10 @@ type @{.varName}ExportModel struct {
|
||||
// @{.varName}MaxSortInp 获取@{.tableComment}最大排序
|
||||
type @{.varName}MaxSortInp struct{}
|
||||
|
||||
func (in *@{.varName}MaxSortInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}MaxSortModel struct {
|
||||
Sort int `json:"sort" description:"排序"`
|
||||
}
|
||||
@@ -83,6 +96,10 @@ type @{.varName}StatusInp struct {
|
||||
Status int `json:"status" dc:"状态"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}StatusInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}StatusModel struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
@@ -92,5 +109,9 @@ type @{.varName}SwitchInp struct {
|
||||
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}SwitchInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}SwitchModel struct{}
|
||||
@{end}
|
@@ -21,6 +21,7 @@ import (
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/hgorm"
|
||||
"hotgo/internal/library/hgorm/handler"
|
||||
"hotgo/internal/model/input/@{.templateGroup}in"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/internal/service"
|
||||
@@ -39,46 +40,42 @@ func init() {
|
||||
service.Register@{.servFunName}(New@{.servFunName}())
|
||||
}
|
||||
|
||||
// Model @{.tableComment}Orm模型
|
||||
func (s *s@{.servFunName}) Model(ctx context.Context) *gdb.Model {
|
||||
return dao.@{.daoName}.Ctx(ctx)
|
||||
// Model @{.tableComment}ORM模型
|
||||
func (s *s@{.servFunName}) Model(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
return handler.Model(dao.@{.daoName}.Ctx(ctx), option...)
|
||||
}
|
||||
|
||||
// List 获取@{.tableComment}列表
|
||||
func (s *s@{.servFunName}) List(ctx context.Context, in @{.templateGroup}in.@{.varName}ListInp) (list []*@{.templateGroup}in.@{.varName}ListModel, totalCount int, err error) {
|
||||
mod := dao.@{.daoName}.Ctx(ctx)
|
||||
mod := s.Model(ctx)
|
||||
@{.listWhere}
|
||||
@{.listJoin.link}
|
||||
totalCount, err = mod.Clone().Count(1)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
return
|
||||
}
|
||||
|
||||
if totalCount == 0 {
|
||||
return list, totalCount, nil
|
||||
return
|
||||
}
|
||||
|
||||
@{.listJoin.select}
|
||||
if err = mod.Fields(fields).Handler(hgorm.HandlerFilterAuth).Page(in.Page, in.PerPage).@{.listOrder}.Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
return list, totalCount, err
|
||||
err = mod.Fields(fields).Page(in.Page, in.PerPage).@{.listOrder}.Scan(&list)
|
||||
return
|
||||
}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// Export 导出@{.tableComment}
|
||||
func (s *s@{.servFunName}) Export(ctx context.Context, in @{.templateGroup}in.@{.varName}ListInp) (err error) {
|
||||
list, totalCount, err := s.List(ctx, in)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
// 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...}
|
||||
tags, err := convert.GetEntityDescTags(@{.templateGroup}in.@{.varName}ExportModel{})
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -87,13 +84,11 @@ func (s *s@{.servFunName}) Export(ctx context.Context, in @{.templateGroup}in.@{
|
||||
exports []@{.templateGroup}in.@{.varName}ExportModel
|
||||
)
|
||||
|
||||
err = gconv.Scan(list, &exports)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName); err != nil {
|
||||
if err = gconv.Scan(list, &exports);err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName)
|
||||
return
|
||||
}@{end}
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
@@ -112,61 +107,50 @@ 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 = dao.@{.daoName}.Ctx(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Delete()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Delete()
|
||||
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, consts.ErrorORM)
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
res.Sort = res.Sort + g.Cfg().MustGet(ctx, "hotgo.admin.maxSortIncrement").Int()
|
||||
return res, nil
|
||||
if res == nil {
|
||||
res = new(@{.templateGroup}in.@{.varName}MaxSortModel)
|
||||
}
|
||||
|
||||
res.Sort = form.DefaultMaxSort(ctx, res.Sort)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasView true }
|
||||
// View 获取@{.tableComment}指定信息
|
||||
func (s *s@{.servFunName}) View(ctx context.Context, in @{.templateGroup}in.@{.varName}ViewInp) (res *@{.templateGroup}in.@{.varName}ViewModel, err error) {
|
||||
if err = dao.@{.daoName}.Ctx(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Scan(&res)
|
||||
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}不能为空")
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
_, err = dao.@{.daoName}.Ctx(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(dao.@{.daoName}.Columns().Status, in.Status).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(@{.statusUpdate}).Update()
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
@@ -179,15 +163,10 @@ func (s *s@{.servFunName}) Switch(ctx context.Context, in @{.templateGroup}in.@{
|
||||
|
||||
if !validate.InSliceString(fields, in.Key) {
|
||||
err = gerror.New("开关键名不在白名单")
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
_, err = dao.@{.daoName}.Ctx(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(in.Key, in.Value).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(@{.switchUpdate}).Update()
|
||||
return
|
||||
}
|
||||
@{end}
|
@@ -1,31 +1,33 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-modal
|
||||
v-model:show="isShowModal"
|
||||
:show-icon="false"
|
||||
preset="dialog"
|
||||
:title="params?.@{.pk.TsName} > 0 ? '编辑 #' + params?.@{.pk.TsName} : '添加'"
|
||||
:style="{
|
||||
width: dialogWidth,
|
||||
}"
|
||||
>
|
||||
<n-form
|
||||
:model="params"
|
||||
:rules="rules"
|
||||
ref="formRef"
|
||||
label-placement="left"
|
||||
:label-width="80"
|
||||
class="py-4"
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-modal
|
||||
v-model:show="isShowModal"
|
||||
:show-icon="false"
|
||||
preset="dialog"
|
||||
:title="params?.@{.pk.TsName} > 0 ? '编辑 #' + params?.@{.pk.TsName} : '添加'"
|
||||
:style="{
|
||||
width: dialogWidth,
|
||||
}"
|
||||
>
|
||||
<n-form
|
||||
:model="params"
|
||||
:rules="rules"
|
||||
ref="formRef"
|
||||
label-placement="left"
|
||||
:label-width="80"
|
||||
class="py-4"
|
||||
>
|
||||
@{.formItem}
|
||||
</n-form>
|
||||
</n-form>
|
||||
<template #action>
|
||||
<n-space>
|
||||
<n-button @click="closeForm">取消</n-button>
|
||||
<n-button type="info" :loading="formBtnLoading" @click="confirmForm">确定</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
</n-modal>
|
||||
</n-spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -57,10 +59,8 @@
|
||||
},
|
||||
});
|
||||
|
||||
const params = computed(() => {
|
||||
return props.formParams;
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const params = ref<State>(props.formParams);
|
||||
const message = useMessage();
|
||||
const formRef = ref<any>({});
|
||||
const dialogWidth = ref('75%');
|
||||
|
Reference in New Issue
Block a user