From 2ceaa7005e037b1e51696796481d52d2afe6b1b1 Mon Sep 17 00:00:00 2001 From: yxh Date: Wed, 6 Apr 2022 18:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/system/sys_dept.go | 39 ++++++++ api/v1/system/sys_role.go | 12 ++- internal/app/system/controller/sys_dept.go | 33 +++++++ internal/app/system/controller/sys_role.go | 6 ++ internal/app/system/model/entity/sys_dept.go | 27 +++++ internal/app/system/router/router.go | 1 + internal/app/system/service/context.go | 4 +- .../service/internal/dao/internal/sys_dept.go | 98 +++++++++++++++++++ .../system/service/internal/dao/sys_dept.go | 27 +++++ .../system/service/internal/do/sys_dept.go | 29 ++++++ internal/app/system/service/sys_auth_rule.go | 4 +- internal/app/system/service/sys_dept.go | 71 ++++++++++++++ internal/app/system/service/sys_login_log.go | 4 +- internal/app/system/service/sys_role.go | 22 ++++- internal/app/system/service/sys_user.go | 4 +- manifest/config/config.yaml | 2 +- 16 files changed, 370 insertions(+), 13 deletions(-) create mode 100644 api/v1/system/sys_dept.go create mode 100644 internal/app/system/controller/sys_dept.go create mode 100644 internal/app/system/model/entity/sys_dept.go create mode 100644 internal/app/system/service/internal/dao/internal/sys_dept.go create mode 100644 internal/app/system/service/internal/dao/sys_dept.go create mode 100644 internal/app/system/service/internal/do/sys_dept.go create mode 100644 internal/app/system/service/sys_dept.go diff --git a/api/v1/system/sys_dept.go b/api/v1/system/sys_dept.go new file mode 100644 index 0000000..90a37bd --- /dev/null +++ b/api/v1/system/sys_dept.go @@ -0,0 +1,39 @@ +/* +* @desc:部门管理参数 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/4/6 15:07 + */ + +package system + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/tiger1103/gfast/v3/internal/app/system/model/entity" +) + +type DeptSearchReq struct { + g.Meta `path:"/dept/list" tags:"部门管理" method:"get" summary:"部门列表"` + DeptName string `p:"deptName"` + Status string `p:"status"` +} + +type DeptSearchRes struct { + g.Meta `mime:"application/json"` + DeptList []*entity.SysDept `json:"deptList"` +} + +type DeptAddReq struct { + g.Meta `path:"/dept/add" tags:"部门管理" method:"post" summary:"添加部门"` + ParentID int `p:"parentId" v:"required#父级不能为空"` + DeptName string `p:"deptName" v:"required#部门名称不能为空"` + OrderNum int `p:"orderNum" v:"required#排序不能为空"` + Leader string `p:"leader"` + Phone string `p:"phone"` + Email string `p:"email" v:"email#邮箱格式不正确"` + Status uint `p:"status" v:"required#状态必须"` + Ancestors string `p:"ancestors"` +} + +type DeptAddRes struct { +} diff --git a/api/v1/system/sys_role.go b/api/v1/system/sys_role.go index 6fa8987..ee34691 100644 --- a/api/v1/system/sys_role.go +++ b/api/v1/system/sys_role.go @@ -16,8 +16,8 @@ import ( type RoleListReq struct { g.Meta `path:"/role/list" tags:"角色管理" method:"get" summary:"角色列表"` - RoleName string `p:"roleName"` //参数名称 - Status string `p:"status"` //状态 + RoleName string `p:"roleName"` //参数名称 + Status string `p:"roleStatus"` //状态 commonApi.PageReq } @@ -71,3 +71,11 @@ type RoleEditReq struct { type RoleEditRes struct { } + +type RoleDeleteReq struct { + g.Meta `path:"/role/delete" tags:"角色管理" method:"delete" summary:"删除角色"` + Ids []int64 `p:"ids" v:"required#角色id不能为空"` +} + +type RoleDeleteRes struct { +} diff --git a/internal/app/system/controller/sys_dept.go b/internal/app/system/controller/sys_dept.go new file mode 100644 index 0000000..928048d --- /dev/null +++ b/internal/app/system/controller/sys_dept.go @@ -0,0 +1,33 @@ +/* +* @desc:部门管理 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/4/6 15:15 + */ + +package controller + +import ( + "context" + "github.com/tiger1103/gfast/v3/api/v1/system" + "github.com/tiger1103/gfast/v3/internal/app/system/service" +) + +var Dept = sysDeptController{} + +type sysDeptController struct { + BaseController +} + +// List 部门列表 +func (c *sysDeptController) List(ctx context.Context, req *system.DeptSearchReq) (res *system.DeptSearchRes, err error) { + res = new(system.DeptSearchRes) + res.DeptList, err = service.Dept().GetList(ctx, req) + return +} + +// Add 添加部门 +func (c *sysDeptController) Add(ctx context.Context, req *system.DeptAddReq) (res *system.DeptAddRes, err error) { + err = service.Dept().Add(ctx, req) + return +} diff --git a/internal/app/system/controller/sys_role.go b/internal/app/system/controller/sys_role.go index 60ad928..5d18763 100644 --- a/internal/app/system/controller/sys_role.go +++ b/internal/app/system/controller/sys_role.go @@ -54,3 +54,9 @@ func (c *roleController) Edit(ctx context.Context, req *system.RoleEditReq) (res err = service.Role().EditRole(ctx, req) return } + +// Delete 删除角色 +func (c *roleController) Delete(ctx context.Context, req *system.RoleDeleteReq) (res *system.RoleDeleteRes, err error) { + err = service.Role().DeleteByIds(ctx, req.Ids) + return +} diff --git a/internal/app/system/model/entity/sys_dept.go b/internal/app/system/model/entity/sys_dept.go new file mode 100644 index 0000000..acbc258 --- /dev/null +++ b/internal/app/system/model/entity/sys_dept.go @@ -0,0 +1,27 @@ +// ================================================================================= +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// SysDept is the golang structure for table sys_dept. +type SysDept struct { + DeptId int64 `json:"deptId" description:"部门id"` + ParentId int64 `json:"parentId" description:"父部门id"` + Ancestors string `json:"ancestors" description:"祖级列表"` + DeptName string `json:"deptName" description:"部门名称"` + OrderNum int `json:"orderNum" description:"显示顺序"` + Leader string `json:"leader" description:"负责人"` + Phone string `json:"phone" description:"联系电话"` + Email string `json:"email" description:"邮箱"` + Status uint `json:"status" description:"部门状态(0正常 1停用)"` + CreatedBy uint64 `json:"createdBy" description:"创建人"` + UpdatedBy int64 `json:"updatedBy" description:"修改人"` + CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` + UpdatedAt *gtime.Time `json:"updatedAt" description:"修改时间"` + DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"` +} diff --git a/internal/app/system/router/router.go b/internal/app/system/router/router.go index ea9d019..ca28a1b 100644 --- a/internal/app/system/router/router.go +++ b/internal/app/system/router/router.go @@ -25,6 +25,7 @@ func BindController(group *ghttp.RouterGroup) { controller.User, controller.Menu, controller.Role, + controller.Dept, controller.DictData, ) }) diff --git a/internal/app/system/service/context.go b/internal/app/system/service/context.go index b6ff44f..06b7154 100644 --- a/internal/app/system/service/context.go +++ b/internal/app/system/service/context.go @@ -23,12 +23,12 @@ type IContext interface { } // Context 上下文管理服务 -var contextImpl = contextServiceImpl{} +var contextService = contextServiceImpl{} type contextServiceImpl struct{} func Context() IContext { - return IContext(&contextImpl) + return IContext(&contextService) } // Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。 diff --git a/internal/app/system/service/internal/dao/internal/sys_dept.go b/internal/app/system/service/internal/dao/internal/sys_dept.go new file mode 100644 index 0000000..d22ae8c --- /dev/null +++ b/internal/app/system/service/internal/dao/internal/sys_dept.go @@ -0,0 +1,98 @@ +// ========================================================================== +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// SysDeptDao is the data access object for table sys_dept. +type SysDeptDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns SysDeptColumns // columns contains all the column names of Table for convenient usage. +} + +// SysDeptColumns defines and stores column names for table sys_dept. +type SysDeptColumns struct { + DeptId string // 部门id + ParentId string // 父部门id + Ancestors string // 祖级列表 + DeptName string // 部门名称 + OrderNum string // 显示顺序 + Leader string // 负责人 + Phone string // 联系电话 + Email string // 邮箱 + Status string // 部门状态(0正常 1停用) + CreatedBy string // 创建人 + UpdatedBy string // 修改人 + CreatedAt string // 创建时间 + UpdatedAt string // 修改时间 + DeletedAt string // 删除时间 +} + +// sysDeptColumns holds the columns for table sys_dept. +var sysDeptColumns = SysDeptColumns{ + DeptId: "dept_id", + ParentId: "parent_id", + Ancestors: "ancestors", + DeptName: "dept_name", + OrderNum: "order_num", + Leader: "leader", + Phone: "phone", + Email: "email", + Status: "status", + CreatedBy: "created_by", + UpdatedBy: "updated_by", + CreatedAt: "created_at", + UpdatedAt: "updated_at", + DeletedAt: "deleted_at", +} + +// NewSysDeptDao creates and returns a new DAO object for table data access. +func NewSysDeptDao() *SysDeptDao { + return &SysDeptDao{ + group: "default", + table: "sys_dept", + columns: sysDeptColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *SysDeptDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *SysDeptDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *SysDeptDao) Columns() SysDeptColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *SysDeptDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *SysDeptDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *SysDeptDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/app/system/service/internal/dao/sys_dept.go b/internal/app/system/service/internal/dao/sys_dept.go new file mode 100644 index 0000000..9ab645d --- /dev/null +++ b/internal/app/system/service/internal/dao/sys_dept.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/dao/internal" +) + +// internalSysDeptDao is internal type for wrapping internal DAO implements. +type internalSysDeptDao = *internal.SysDeptDao + +// sysDeptDao is the data access object for table sys_dept. +// You can define custom methods on it to extend its functionality as you wish. +type sysDeptDao struct { + internalSysDeptDao +} + +var ( + // SysDept is globally public accessible object for table sys_dept operations. + SysDept = sysDeptDao{ + internal.NewSysDeptDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/app/system/service/internal/do/sys_dept.go b/internal/app/system/service/internal/do/sys_dept.go new file mode 100644 index 0000000..6139fbc --- /dev/null +++ b/internal/app/system/service/internal/do/sys_dept.go @@ -0,0 +1,29 @@ +// ================================================================================= +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// SysDept is the golang structure of table sys_dept for DAO operations like Where/Data. +type SysDept struct { + g.Meta `orm:"table:sys_dept, do:true"` + DeptId interface{} // 部门id + ParentId interface{} // 父部门id + Ancestors interface{} // 祖级列表 + DeptName interface{} // 部门名称 + OrderNum interface{} // 显示顺序 + Leader interface{} // 负责人 + Phone interface{} // 联系电话 + Email interface{} // 邮箱 + Status interface{} // 部门状态(0正常 1停用) + CreatedBy interface{} // 创建人 + UpdatedBy interface{} // 修改人 + CreatedAt *gtime.Time // 创建时间 + UpdatedAt *gtime.Time // 修改时间 + DeletedAt *gtime.Time // 删除时间 +} diff --git a/internal/app/system/service/sys_auth_rule.go b/internal/app/system/service/sys_auth_rule.go index b2af7e6..57f9382 100644 --- a/internal/app/system/service/sys_auth_rule.go +++ b/internal/app/system/service/sys_auth_rule.go @@ -41,10 +41,10 @@ type IRule interface { type ruleImpl struct { } -var rule = ruleImpl{} +var ruleService = ruleImpl{} func Rule() IRule { - return IRule(&rule) + return IRule(&ruleService) } func (s *ruleImpl) GetMenuListSearch(ctx context.Context, req *system.RuleSearchReq) (res []*model.SysAuthRuleInfoRes, err error) { diff --git a/internal/app/system/service/sys_dept.go b/internal/app/system/service/sys_dept.go new file mode 100644 index 0000000..a2e3887 --- /dev/null +++ b/internal/app/system/service/sys_dept.go @@ -0,0 +1,71 @@ +/* +* @desc:部门管理 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/4/6 15:19 + */ + +package service + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" + "github.com/tiger1103/gfast/v3/api/v1/system" + commonService "github.com/tiger1103/gfast/v3/internal/app/common/service" + "github.com/tiger1103/gfast/v3/internal/app/system/consts" + "github.com/tiger1103/gfast/v3/internal/app/system/model/entity" + "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/dao" + "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/do" + "github.com/tiger1103/gfast/v3/library/liberr" +) + +type IDept interface { + GetList(ctx context.Context, req *system.DeptSearchReq) (list []*entity.SysDept, err error) + Add(ctx context.Context, req *system.DeptAddReq) (err error) +} + +var deptService = deptImpl{} + +func Dept() IDept { + return IDept(&deptService) +} + +type deptImpl struct { +} + +func (s *deptImpl) GetList(ctx context.Context, req *system.DeptSearchReq) (list []*entity.SysDept, err error) { + err = g.Try(func() { + m := dao.SysDept.Ctx(ctx) + if req.DeptName != "" { + m = m.Where("dept_name like ?", "%"+req.DeptName+"%") + } + if req.Status != "" { + m = m.Where("status", gconv.Int(req.Status)) + } + err = m.Scan(&list) + liberr.ErrIsNil(ctx, err, "获取角色列表失败") + }) + return +} + +// Add 添加部门 +func (s *deptImpl) Add(ctx context.Context, req *system.DeptAddReq) (err error) { + err = g.Try(func() { + _, err = dao.SysDept.Ctx(ctx).Insert(do.SysDept{ + ParentId: req.ParentID, + Ancestors: req.Ancestors, + DeptName: req.DeptName, + OrderNum: req.OrderNum, + Leader: req.Leader, + Phone: req.Phone, + Email: req.Email, + Status: req.Status, + CreatedBy: Context().GetUserId(ctx), + }) + liberr.ErrIsNil(ctx, err, "添加部门失败") + // 删除缓存 + commonService.Cache().RemoveByTag(ctx, consts.CacheSysAuthTag) + }) + return +} diff --git a/internal/app/system/service/sys_login_log.go b/internal/app/system/service/sys_login_log.go index 49eb2b4..1d4e3b7 100644 --- a/internal/app/system/service/sys_login_log.go +++ b/internal/app/system/service/sys_login_log.go @@ -22,13 +22,13 @@ type sysLoginLogImpl struct { } var ( - sysLoginLog = sysLoginLogImpl{ + sysLoginLogService = sysLoginLogImpl{ Pool: grpool.New(100), } ) func SysLoginLog() ISysLoginLog { - return ISysLoginLog(&sysLoginLog) + return ISysLoginLog(&sysLoginLogService) } func (s *sysLoginLogImpl) Invoke(ctx context.Context, data *model.LoginLogParams) { diff --git a/internal/app/system/service/sys_role.go b/internal/app/system/service/sys_role.go index 2dbb46a..ce6dae9 100644 --- a/internal/app/system/service/sys_role.go +++ b/internal/app/system/service/sys_role.go @@ -28,15 +28,16 @@ type IRole interface { Get(ctx context.Context, id uint) (res *entity.SysRole, err error) GetFilteredNamedPolicy(ctx context.Context, id uint) (gpSlice []int, err error) EditRole(ctx context.Context, req *system.RoleEditReq) error + DeleteByIds(ctx context.Context, ids []int64) (err error) } type roleImpl struct { } -var role = roleImpl{} +var roleService = roleImpl{} func Role() IRole { - return IRole(&role) + return IRole(&roleService) } func (s *roleImpl) GetRoleListSearch(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error) { @@ -176,3 +177,20 @@ func (s *roleImpl) EditRole(ctx context.Context, req *system.RoleEditReq) (err e }) return } + +// DeleteByIds 删除角色 +func (s *roleImpl) DeleteByIds(ctx context.Context, ids []int64) (err error) { + err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { + err = g.Try(func() { + _, err = dao.SysRole.Ctx(ctx).TX(tx).Where(dao.SysRole.Columns().Id+" in(?)", ids).Delete() + liberr.ErrIsNil(ctx, err, "删除角色失败") + //删除角色权限 + for _, v := range ids { + err = s.DelRoleRule(ctx, v) + liberr.ErrIsNil(ctx, err) + } + }) + return err + }) + return +} diff --git a/internal/app/system/service/sys_user.go b/internal/app/system/service/sys_user.go index b95df19..ac55d5a 100644 --- a/internal/app/system/service/sys_user.go +++ b/internal/app/system/service/sys_user.go @@ -39,11 +39,11 @@ type userImpl struct{} var ( notCheckAuthAdminIds *gset.Set //无需验证权限的用户id - user = userImpl{} + userService = userImpl{} ) func User() IUser { - return IUser(&user) + return IUser(&userService) } func (s *userImpl) NotCheckAuthAdminIds(ctx context.Context) *gset.Set { diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index 062cb9a..9b54a54 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -76,7 +76,7 @@ gfcli: gen: dao: - link: "mysql:root:123456@tcp(127.0.0.1:3306)/gfast-v3" - tables: "sys_role" + tables: "sys_dept" removePrefix: "gf_" descriptionTag: true noModelComment: true