refactor🎨 核心业务结构调整
This commit is contained in:
1 parent
408dcc5057
commit
e473f158e8
13 files changed
+406
-761
No files matched your search
+68
-84
@@ -19,6 +19,7 @@ type SysRole struct {
|
||||
api.Api
|
||||
}
|
||||
|
||||
// GetSysRoleList
|
||||
// @Summary 角色列表数据
|
||||
// @Description Get JSON
|
||||
// @Tags 角色/Role
|
||||
@@ -31,36 +32,32 @@ type SysRole struct {
|
||||
// @Router /api/v1/role [get]
|
||||
// @Security Bearer
|
||||
func (e SysRole) GetSysRoleList(c *gin.Context) {
|
||||
e.Context = c
|
||||
log := e.GetLogger()
|
||||
d := new(dto.SysRoleSearch)
|
||||
db, err := e.GetOrm()
|
||||
s := new(service.SysRole)
|
||||
req := new(dto.SysRoleSearch)
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
//查询列表
|
||||
err = d.Bind(c)
|
||||
if err != nil {
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
list := make([]models.SysRole, 0)
|
||||
var count int64
|
||||
s := service.SysRole{}
|
||||
s.Log = log
|
||||
s.Orm = db
|
||||
err = s.GetSysRolePage(d, &list, &count)
|
||||
|
||||
err = s.GetSysRolePage(req, &list, &count)
|
||||
if err != nil {
|
||||
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
|
||||
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||
}
|
||||
|
||||
// GetSysRole
|
||||
// @Summary 获取Role数据
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色/Role
|
||||
@@ -70,27 +67,22 @@ func (e SysRole) GetSysRoleList(c *gin.Context) {
|
||||
// @Router /api/v1/role/{id} [get]
|
||||
// @Security Bearer
|
||||
func (e SysRole) GetSysRole(c *gin.Context) {
|
||||
e.Context = c
|
||||
log := e.GetLogger()
|
||||
control := new(dto.SysRoleById)
|
||||
db, err := e.GetOrm()
|
||||
s := service.SysRole{}
|
||||
req := new(dto.SysRoleById)
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
//查看详情
|
||||
err = control.Bind(c)
|
||||
if err != nil {
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
var object models.SysRole
|
||||
|
||||
s := service.SysRole{}
|
||||
s.Log = log
|
||||
s.Orm = db
|
||||
err = s.GetSysRole(control, &object)
|
||||
err = s.GetSysRole(req, &object)
|
||||
if err != nil {
|
||||
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
|
||||
return
|
||||
@@ -99,6 +91,7 @@ func (e SysRole) GetSysRole(c *gin.Context) {
|
||||
e.OK(object, "查看成功")
|
||||
}
|
||||
|
||||
// InsertSysRole
|
||||
// @Summary 创建角色
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色/Role
|
||||
@@ -111,24 +104,25 @@ func (e SysRole) GetSysRole(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysRole) InsertSysRole(c *gin.Context) {
|
||||
s := service.SysRole{}
|
||||
control := new(dto.SysRoleControl)
|
||||
req := new(dto.SysRoleControl)
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(control).
|
||||
Bind(req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置创建人
|
||||
control.CreateBy = user.GetUserId(c)
|
||||
if control.Status == "" {
|
||||
control.Status = "2"
|
||||
req.CreateBy = user.GetUserId(c)
|
||||
if req.Status == "" {
|
||||
req.Status = "2"
|
||||
}
|
||||
|
||||
err = s.InsertSysRole(control)
|
||||
err = s.InsertSysRole(req)
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(http.StatusInternalServerError, err, "创建失败")
|
||||
@@ -139,7 +133,7 @@ func (e SysRole) InsertSysRole(c *gin.Context) {
|
||||
e.Error(http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(control.GetId(), "创建成功")
|
||||
e.OK(req.GetId(), "创建成功")
|
||||
}
|
||||
|
||||
// UpdateSysRole 修改用户角色
|
||||
@@ -155,21 +149,22 @@ func (e SysRole) InsertSysRole(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysRole) UpdateSysRole(c *gin.Context) {
|
||||
s := service.SysRole{}
|
||||
control := new(dto.SysRoleControl)
|
||||
req := new(dto.SysRoleControl)
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(control).
|
||||
Bind(req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
cb :=sdk.Runtime.GetCasbinKey(c.Request.Host)
|
||||
cb := sdk.Runtime.GetCasbinKey(c.Request.Host)
|
||||
|
||||
control.SetUpdateBy(user.GetUserId(c))
|
||||
req.SetUpdateBy(user.GetUserId(c))
|
||||
|
||||
err = s.UpdateSysRole(control,cb)
|
||||
err = s.UpdateSysRole(req, cb)
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
@@ -179,9 +174,10 @@ func (e SysRole) UpdateSysRole(c *gin.Context) {
|
||||
e.Error(http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(control.GetId(), "更新成功")
|
||||
e.OK(req.GetId(), "更新成功")
|
||||
}
|
||||
|
||||
// DeleteSysRole
|
||||
// @Summary 删除用户角色
|
||||
// @Description 删除数据
|
||||
// @Tags 角色/Role
|
||||
@@ -191,29 +187,22 @@ func (e SysRole) UpdateSysRole(c *gin.Context) {
|
||||
// @Router /api/v1/role [delete]
|
||||
// @Security Bearer
|
||||
func (e SysRole) DeleteSysRole(c *gin.Context) {
|
||||
e.Context = c
|
||||
log := e.GetLogger()
|
||||
control := new(dto.SysRoleById)
|
||||
db, err := e.GetOrm()
|
||||
s := new(service.SysRole)
|
||||
req := new(dto.SysRoleById)
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
//删除操作
|
||||
err = control.Bind(c)
|
||||
err = s.RemoveSysRole(req)
|
||||
if err != nil {
|
||||
log.Errorf("Bind error: %s", err)
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
|
||||
s := service.SysRole{}
|
||||
s.Orm = db
|
||||
s.Log = log
|
||||
err = s.RemoveSysRole(control)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
e.Logger.Error(err)
|
||||
e.Error(http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
@@ -222,39 +211,34 @@ func (e SysRole) DeleteSysRole(c *gin.Context) {
|
||||
e.Error(http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(control.GetId(), "删除成功")
|
||||
e.OK(req.GetId(), "删除成功")
|
||||
}
|
||||
|
||||
// UpdateRoleDataScope 更新角色数据权限
|
||||
func (e SysRole) UpdateRoleDataScope(c *gin.Context) {
|
||||
e.Context = c
|
||||
log := e.GetLogger()
|
||||
control := new(dto.RoleDataScopeReq)
|
||||
db, err := e.GetOrm()
|
||||
s := &service.SysRole{}
|
||||
req := new(dto.RoleDataScopeReq)
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
//更新操作
|
||||
err = c.Bind(control)
|
||||
if err != nil {
|
||||
log.Errorf("request bind error, %s", err.Error())
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
data := &models.SysRole{
|
||||
RoleId: control.RoleId,
|
||||
DataScope: control.DataScope,
|
||||
DeptIds: control.DeptIds,
|
||||
RoleId: req.RoleId,
|
||||
DataScope: req.DataScope,
|
||||
DeptIds: req.DeptIds,
|
||||
}
|
||||
data.UpdateBy = user.GetUserId(c)
|
||||
s := &service.SysRole{}
|
||||
s.Orm = db
|
||||
s.Log = log
|
||||
|
||||
err = s.UpdateDataScope(data)
|
||||
if err != nil {
|
||||
e.Error(http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(nil, "操作成功")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user