From 0965f48b6efc2ef190cefb163476d21a1752ee0e Mon Sep 17 00:00:00 2001 From: yingchaojie Date: Thu, 31 Mar 2022 16:24:49 +0800 Subject: [PATCH] v1.3.5: mod user break change --- Makefile | 2 +- mod/user/action/role/department_action.go | 2 +- mod/user/action/role/role_action.go | 2 +- mod/user/action/user/user_action.go | 2 +- mod/user/dao/userdao/userdao.go | 5 +++++ mod/user/mod.go | 3 +-- mod/user/model/department.go | 7 ++++--- mod/user/model/role.go | 4 +++- mod/user/model/user.go | 25 ++++++++++++----------- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 3c5dd2f..ce103f8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BINARY=go-core-kit -VERSION=1.3.2 +VERSION=1.3.5 DATE=`date +%FT%T%z` .PHONY: init build diff --git a/mod/user/action/role/department_action.go b/mod/user/action/role/department_action.go index ebc295b..016af79 100644 --- a/mod/user/action/role/department_action.go +++ b/mod/user/action/role/department_action.go @@ -97,7 +97,7 @@ func departmentDel(ctx *context.Context) { if val, ok := department.Extend.Map["immutable"]; ok && val.(bool) { panic(exception.New("该部门不可删除")) } - dao.Delete(department) + dao.DeleteOff(department) ctx.JsonSuccess(nil) } diff --git a/mod/user/action/role/role_action.go b/mod/user/action/role/role_action.go index 65b248d..3430810 100644 --- a/mod/user/action/role/role_action.go +++ b/mod/user/action/role/role_action.go @@ -93,7 +93,7 @@ func del(ctx *context.Context) { if us != nil && len(us) > 0 { panic(exception.New("角色下还有用户,不能删除")) } - dao.Delete(role) + dao.DeleteOff(role) ctx.JsonSuccess(nil) } diff --git a/mod/user/action/user/user_action.go b/mod/user/action/user/user_action.go index 11b9f5b..e343d72 100644 --- a/mod/user/action/user/user_action.go +++ b/mod/user/action/user/user_action.go @@ -222,7 +222,7 @@ func updateUserInfo(ctx *context.Context) { } user.Pwd.Set(cryptokit.MD5(params.NewPwd.String)) } - // todo usercenter + //todo usercenter dao.Update(u) ctx.JsonSuccess(nil) } diff --git a/mod/user/dao/userdao/userdao.go b/mod/user/dao/userdao/userdao.go index 9ade9c0..3f3ccd8 100644 --- a/mod/user/dao/userdao/userdao.go +++ b/mod/user/dao/userdao/userdao.go @@ -5,6 +5,7 @@ import ( "github.com/Masterminds/squirrel" "github.com/mizuki1412/go-core-kit/class/exception" "github.com/mizuki1412/go-core-kit/library/stringkit" + "github.com/mizuki1412/go-core-kit/mod/user/dao/departmentdao" "github.com/mizuki1412/go-core-kit/mod/user/dao/roledao" "github.com/mizuki1412/go-core-kit/mod/user/model" "github.com/mizuki1412/go-core-kit/service/sqlkit" @@ -33,8 +34,12 @@ func (dao *Dao) cascade(obj *model.User) { if obj.Role != nil { obj.Role = roledao.New(dao.Schema).FindById(obj.Role.Id) } + if obj.Department != nil { + obj.Department = departmentdao.New(dao.Schema).FindById(obj.Department.Id) + } case ResultNone: obj.Role = nil + obj.Department = nil } } func (dao *Dao) scan(sql string, args []any) []*model.User { diff --git a/mod/user/mod.go b/mod/user/mod.go index d2fa7b4..96e9a75 100644 --- a/mod/user/mod.go +++ b/mod/user/mod.go @@ -7,8 +7,7 @@ import ( "github.com/mizuki1412/go-core-kit/service/restkit/router" ) -/*** 用户、部门、角色模块 */ - +// All 用户、部门、角色模块 func All() []func(r *router.Router) { return []func(r *router.Router){user.Init, role.Init, smscode.Init} } diff --git a/mod/user/model/department.go b/mod/user/model/department.go index c8e4ebc..fb87924 100644 --- a/mod/user/model/department.go +++ b/mod/user/model/department.go @@ -7,13 +7,14 @@ import ( ) type Department struct { - Id int32 `json:"id" db:"id" pk:"true" tablename:"department" autoincrement:"true"` - No class.String `json:"no,omitempty" db:"no"` + Id int32 `autoincrement:"true" json:"id" db:"id" pk:"true" tablename:"department"` + No class.String `json:"no,omitempty" db:"no" description:"编号"` Name class.String `json:"name,omitempty" db:"name"` - Descr class.String `json:"descr,omitempty" db:"descr"` + Descr class.String `json:"descr,omitempty" db:"descr" description:"描述"` Parent *Department `json:"parent,omitempty" db:"parent"` Extend class.MapString `json:"extend,omitempty" db:"extend"` CreateDt class.Time `json:"createDt,omitempty" db:"createdt"` + Off class.Bool `json:"off,omitempty" db:"off"` Children []*Department `json:"children"` } diff --git a/mod/user/model/role.go b/mod/user/model/role.go index 7f457a9..63ea765 100644 --- a/mod/user/model/role.go +++ b/mod/user/model/role.go @@ -12,7 +12,9 @@ type Role struct { Name class.String `json:"name,omitempty" db:"name"` Description class.String `json:"description,omitempty" db:"description"` Privileges class.ArrString `json:"privileges,omitempty" db:"privileges"` - Extend class.MapString `json:"extend,omitempty" db:"extend"` + CreateDt class.Time `json:"createDt,omitempty" db:"createdt"` + Off class.Bool `json:"off,omitempty" db:"off"` + Extend class.MapString `json:"extend,omitempty" db:"extend" description:"immutable:不可删除"` } func (th *Role) Scan(value any) error { diff --git a/mod/user/model/user.go b/mod/user/model/user.go index 9d80242..5d8aea2 100644 --- a/mod/user/model/user.go +++ b/mod/user/model/user.go @@ -7,18 +7,19 @@ import ( ) type User struct { - Id int32 `json:"id,omitempty" db:"id" pk:"true" tablename:"admin_user" autoincrement:"true"` - Role *Role `json:"role,omitempty" db:"role"` - Username class.String `json:"username,omitempty" db:"username"` - Name class.String `json:"name,omitempty" db:"name"` - Phone class.String `json:"phone,omitempty" db:"phone"` - Pwd class.String `json:"-" db:"pwd"` - Gender class.Int32 `json:"gender" db:"gender"` - Image class.String `json:"image,omitempty" db:"image"` - Address class.String `json:"address,omitempty" db:"address"` - Off class.Int32 `json:"off" db:"off"` - Extend class.MapString `json:"extend,omitempty" db:"extend" description:""` - CreateDt class.Time `json:"createDt,omitempty" db:"createdt"` + Id int32 `json:"id,omitempty" db:"id" pk:"true" tablename:"admin_user" autoincrement:"true"` + Role *Role `json:"role,omitempty" db:"role"` + Department *Department `json:"department,omitempty" db:"department"` + Username class.String `json:"username,omitempty" db:"username"` + Name class.String `json:"name,omitempty" db:"name"` + Phone class.String `json:"phone,omitempty" db:"phone"` + Pwd class.String `json:"-" db:"pwd"` + Gender class.Int32 `json:"gender,omitempty" db:"gender" description:"1-nan,2-nv"` + Image class.String `json:"image,omitempty" db:"image" description:"头像"` + Address class.String `json:"address,omitempty" db:"address"` + Off class.Int32 `json:"off,omitempty" db:"off" description:"冻结 1, 删除 -1"` + Extend class.MapString `json:"extend,omitempty" db:"extend" description:"权限剔除privilegeExclude:[]"` + CreateDt class.Time `json:"createDt,omitempty" db:"createdt"` } const UserOffOK = 0