修复树表上级关系绑定验证,优化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

@@ -6,20 +6,14 @@
package adminin
import (
"context"
"github.com/gogf/gf/v2/errors/gerror"
"hotgo/internal/consts"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/form"
"hotgo/utility/validate"
)
// DeptNameUniqueInp 名称是否唯一
type DeptNameUniqueInp struct {
Name string
Id int64
}
type DeptNameUniqueModel struct {
IsUnique bool
}
// DeptMaxSortInp 最大排序
type DeptMaxSortInp struct {
Id int64
@@ -29,13 +23,59 @@ type DeptMaxSortModel struct {
Sort int
}
// DeptEditInp 修改/新增字典数据
// DeptEditInp 修改/新增部门数据
type DeptEditInp struct {
entity.AdminDept
}
func (in *DeptEditInp) Filter(ctx context.Context) (err error) {
if in.Name == "" {
err = gerror.New("名称不能为空")
return
}
if in.Id > 0 && in.Id == in.Pid {
err = gerror.New("上级部门不能是自己")
return
}
return
}
type DeptEditModel struct{}
// DeptDeleteInp 删除字典类型
// DeptUpdateFields 修改数据字段过滤
type DeptUpdateFields struct {
Id int64 `json:"id" description:"部门ID"`
Pid int64 `json:"pid" description:"父部门ID"`
Name string `json:"name" description:"部门名称"`
Code string `json:"code" description:"部门编码"`
Type string `json:"type" description:"部门类型"`
Leader string `json:"leader" description:"负责人"`
Phone string `json:"phone" description:"联系电话"`
Email string `json:"email" description:"邮箱"`
Level int `json:"level" description:"关系树等级"`
Tree string `json:"tree" description:"关系树"`
Sort int `json:"sort" description:"排序"`
Status int `json:"status" description:"部门状态"`
}
// DeptInsertFields 新增数据字段过滤
type DeptInsertFields struct {
Pid int64 `json:"pid" description:"父部门ID"`
Name string `json:"name" description:"部门名称"`
Code string `json:"code" description:"部门编码"`
Type string `json:"type" description:"部门类型"`
Leader string `json:"leader" description:"负责人"`
Phone string `json:"phone" description:"联系电话"`
Email string `json:"email" description:"邮箱"`
Level int `json:"level" description:"关系树等级"`
Tree string `json:"tree" description:"关系树"`
Sort int `json:"sort" description:"排序"`
Status int `json:"status" description:"部门状态"`
}
// DeptDeleteInp 删除部门类型
type DeptDeleteInp struct {
Id interface{}
}
@@ -72,6 +112,26 @@ type DeptListModel struct {
type DeptStatusInp struct {
entity.AdminDept
}
func (in *DeptStatusInp) Filter(ctx context.Context) (err error) {
if in.Id <= 0 {
err = gerror.New("ID不能为空")
return
}
if in.Status <= 0 {
err = gerror.New("状态不能为空")
return
}
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
err = gerror.New("状态不正确")
return
}
return
}
type DeptStatusModel struct{}
type DeptOptionInp struct {

View File

@@ -15,6 +15,7 @@ import (
"hotgo/internal/library/contexts"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/form"
"hotgo/utility/validate"
)
// MemberUpdateCashInp 更新会员提现信息
@@ -110,11 +111,11 @@ type LoginMemberInfoModel struct {
// MemberEditInp 修改/新增管理员
type MemberEditInp struct {
Id int64 `json:"id" dc:""`
RoleId int64 `json:"roleId" v:"required#角色不能为空" dc:"角色ID"`
PostIds []int64 `json:"postIds" v:"required#岗位不能为空" dc:"岗位ID"`
DeptId int64 `json:"deptId" v:"required#部门不能为空" dc:"部门ID"`
Username string `json:"username" v:"required#账号不能为空" dc:"帐号"`
Id int64 `json:"id" dc:"管理员ID"`
RoleId int64 `json:"roleId" v:"required#角色不能为空" dc:"角色ID"`
PostIds []int64 `json:"postIds" v:"required#岗位不能为空" dc:"岗位ID"`
DeptId int64 `json:"deptId" v:"required#部门不能为空" dc:"部门ID"`
Username string `json:"username" v:"required#账号不能为空" dc:"帐号"`
PasswordHash string `json:"passwordHash" dc:"密码hash"`
Password string `json:"password" dc:"密码"`
RealName string `json:"realName" dc:"真实姓名"`
@@ -130,8 +131,6 @@ type MemberEditInp struct {
Mobile string `json:"mobile" dc:"手机号码"`
Remark string `json:"remark" dc:"备注"`
Status int `json:"status" dc:"状态"`
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" dc:"修改时间"`
}
type MemberAddInp struct {
@@ -214,6 +213,25 @@ type MemberCash struct {
type MemberStatusInp struct {
entity.AdminMember
}
func (in *MemberStatusInp) Filter(ctx context.Context) (err error) {
if in.Id <= 0 {
err = gerror.New("ID不能为空")
return
}
if in.Status <= 0 {
err = gerror.New("状态不能为空")
return
}
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
err = gerror.New("状态不正确")
return
}
return
}
type MemberStatusModel struct{}
// MemberSelectInp 获取可选的后台用户选项

View File

@@ -3,16 +3,99 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package adminin
import (
"context"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"hotgo/internal/model"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/form"
"sort"
)
// GetPermissionsInp 获取指定角色的菜单权限
type GetPermissionsInp struct {
RoleId int64 `json:"id"`
}
type GetPermissionsModel struct {
MenuIds []int64 `json:"menuIds"`
}
// UpdatePermissionsInp 更新指定角色的菜单权限
type UpdatePermissionsInp struct {
RoleId int64 `json:"id"`
MenuIds []int64 `json:"menuIds"`
}
// RoleDeleteInp 删除角色
type RoleDeleteInp struct {
Id int64 `json:"id" v:"required"`
}
func (in *RoleDeleteInp) Filter(ctx context.Context) (err error) {
if in.Id <= 0 {
err = gerror.New("ID不能为空")
return
}
return
}
// RoleEditInp 获取列表
type RoleEditInp struct {
entity.AdminRole
}
func (in *RoleEditInp) Filter(ctx context.Context) (err error) {
if in.Name == "" {
err = gerror.New("名称不能为空")
return
}
if in.Key == "" {
err = gerror.New("编码不能为空")
return
}
if in.Id > 0 && in.Id == in.Pid {
err = gerror.New("上级角色不能是自己")
return
}
return
}
// RoleUpdateFields 修改数据字段过滤
type RoleUpdateFields struct {
Id int64 `json:"id" description:"角色ID"`
Name string `json:"name" description:"角色名称"`
Key string `json:"key" description:"角色权限字符串"`
DataScope int `json:"dataScope" description:"数据范围"`
CustomDept *gjson.Json `json:"customDept" description:"自定义部门权限"`
Pid int64 `json:"pid" description:"上级角色ID"`
Level int `json:"level" description:"关系树等级"`
Tree string `json:"tree" description:"关系树"`
Remark string `json:"remark" description:"备注"`
Sort int `json:"sort" description:"排序"`
Status int `json:"status" description:"角色状态"`
}
// RoleInsertFields 新增数据字段过滤
type RoleInsertFields struct {
Name string `json:"name" description:"角色名称"`
Key string `json:"key" description:"角色权限字符串"`
DataScope int `json:"dataScope" description:"数据范围"`
CustomDept *gjson.Json `json:"customDept" description:"自定义部门权限"`
Pid int64 `json:"pid" description:"上级角色ID"`
Level int `json:"level" description:"关系树等级"`
Tree string `json:"tree" description:"关系树"`
Remark string `json:"remark" description:"备注"`
Sort int `json:"sort" description:"排序"`
Status int `json:"status" description:"角色状态"`
}
// RoleListInp 获取列表
type RoleListInp struct {
form.PageReq
@@ -29,18 +112,6 @@ type RoleListModel struct {
List []*RoleTree `json:"list"`
}
func Sort(v []*RoleTree) {
sort.SliceStable(v, func(i, j int) bool {
if v[i].Sort < v[j].Sort {
return true
}
if v[i].Sort > v[j].Sort {
return false
}
return v[i].Id < v[j].Id
})
}
// RoleMemberListInp 查询列表
type RoleMemberListInp struct {
form.PageReq
@@ -68,8 +139,16 @@ type MenuRoleListModel struct {
CheckedKeys []int64 `json:"checkedKeys" dc:"选择的菜单ID"`
}
// DataScopeEditInp 获取数据权限选项
type DataScopeEditInp struct {
Id int64 `json:"id" v:"required" dc:"角色ID"`
DataScope int `json:"dataScope" v:"required" dc:"数据范围"`
CustomDept []int64 `json:"customDept" dc:"自定义部门权限"`
}
func (in *DataScopeEditInp) Filter(ctx context.Context) (err error) {
if in.Id <= 0 {
return gerror.New("角色ID不正确")
}
return
}