数据库连接初始化优化
权限部分修改
This commit is contained in:
1 parent
4979fd659f
commit
deeb82048b
37 files changed
+726
-721
No files matched your search
@@ -2,14 +2,13 @@ package sys_role
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-admin/app/admin/models/system"
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/apis"
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/log"
|
||||
"go-admin/tools"
|
||||
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -17,6 +16,17 @@ type SysRole struct {
|
||||
apis.Api
|
||||
}
|
||||
|
||||
// @Summary 角色列表数据
|
||||
// @Description Get JSON
|
||||
// @Tags 角色/Role
|
||||
// @Param roleName query string false "roleName"
|
||||
// @Param status query string false "status"
|
||||
// @Param roleKey query string false "roleKey"
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageIndex query int false "页码"
|
||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/role [get]
|
||||
// @Security Bearer
|
||||
func (e *SysRole) GetSysRoleList(c *gin.Context) {
|
||||
msgID := tools.GenerateMsgIDFromContext(c)
|
||||
d := new(dto.SysRoleSearch)
|
||||
@@ -47,6 +57,14 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) {
|
||||
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
|
||||
}
|
||||
|
||||
// @Summary 获取Role数据
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色/Role
|
||||
// @Param roleId path string false "roleId"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
|
||||
// @Router /api/v1/role/{id} [get]
|
||||
// @Security Bearer
|
||||
func (e *SysRole) GetSysRole(c *gin.Context) {
|
||||
control := new(dto.SysRoleById)
|
||||
db, err := tools.GetOrm(c)
|
||||
@@ -76,6 +94,16 @@ func (e *SysRole) GetSysRole(c *gin.Context) {
|
||||
e.OK(c, object, "查看成功")
|
||||
}
|
||||
|
||||
// @Summary 创建角色
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色/Role
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.SysRole true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/role [post]
|
||||
// @Security Bearer
|
||||
func (e *SysRole) InsertSysRole(c *gin.Context) {
|
||||
control := new(dto.SysRoleControl)
|
||||
db, err := tools.GetOrm(c)
|
||||
@@ -97,21 +125,35 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
// 设置创建人
|
||||
object.CreateBy= tools.GetUserId(c)
|
||||
object.CreateBy = tools.GetUserId(c)
|
||||
|
||||
serviceSysRole := service.SysRole{}
|
||||
serviceSysRole.Orm = db
|
||||
serviceSysRole.MsgID = msgID
|
||||
err = serviceSysRole.InsertSysRole(object)
|
||||
s := service.SysRole{}
|
||||
s.Orm = db
|
||||
s.MsgID = msgID
|
||||
err = s.InsertSysRole(object)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
e.Error(c, http.StatusInternalServerError, err, "创建失败")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = global.LoadPolicy(c)
|
||||
if err != nil {
|
||||
e.Error(c, http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(c, object.GetId(), "创建成功")
|
||||
}
|
||||
|
||||
// @Summary 修改用户角色
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色/Role
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.SysRole true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
|
||||
// @Router /api/v1/role/{id} [put]
|
||||
// @Security Bearer
|
||||
func (e *SysRole) UpdateSysRole(c *gin.Context) {
|
||||
control := new(dto.SysRoleControl)
|
||||
db, err := tools.GetOrm(c)
|
||||
@@ -134,17 +176,30 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) {
|
||||
}
|
||||
object.UpdateBy = tools.GetUserId(c)
|
||||
|
||||
serviceSysRole := service.SysRole{}
|
||||
serviceSysRole.Orm = db
|
||||
serviceSysRole.MsgID = msgID
|
||||
err = serviceSysRole.UpdateSysRole(object)
|
||||
s := service.SysRole{}
|
||||
s.Orm = db
|
||||
s.MsgID = msgID
|
||||
err = s.UpdateSysRole(object)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
_, err = global.LoadPolicy(c)
|
||||
if err != nil {
|
||||
e.Error(c, http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(c, object.GetId(), "更新成功")
|
||||
}
|
||||
|
||||
// @Summary 删除用户角色
|
||||
// @Description 删除数据
|
||||
// @Tags 角色/Role
|
||||
// @Param roleId path int true "roleId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
||||
// @Router /api/v1/role/{roleId} [delete]
|
||||
// @Security Bearer
|
||||
func (e *SysRole) DeleteSysRole(c *gin.Context) {
|
||||
control := new(dto.SysRoleById)
|
||||
db, err := tools.GetOrm(c)
|
||||
@@ -162,14 +217,51 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
serviceSysRole := service.SysRole{}
|
||||
serviceSysRole.Orm = db
|
||||
serviceSysRole.MsgID = msgID
|
||||
err = serviceSysRole.RemoveSysRole(control)
|
||||
s := service.SysRole{}
|
||||
s.Orm = db
|
||||
s.MsgID = msgID
|
||||
err = s.RemoveSysRole(control)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
_, err = global.LoadPolicy(c)
|
||||
if err != nil {
|
||||
e.Error(c, http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(c, control.GetId(), "删除成功")
|
||||
}
|
||||
|
||||
func (e *SysRole) UpdateRoleDataScope(c *gin.Context) {
|
||||
control := new(dto.RoleDataScopeReq)
|
||||
db, err := tools.GetOrm(c)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
msgID := tools.GenerateMsgIDFromContext(c)
|
||||
//更新操作
|
||||
err = c.Bind(control)
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] request bind error, %s", msgID, err.Error())
|
||||
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
data := &system.SysRole{
|
||||
RoleId: control.RoleId,
|
||||
DataScope: control.DataScope,
|
||||
DeptIds: control.DeptIds,
|
||||
}
|
||||
data.UpdateBy = tools.GetUserId(c)
|
||||
s := &service.SysRole{}
|
||||
s.Orm = db
|
||||
s.MsgID = msgID
|
||||
err = s.UpdateDataScope(data)
|
||||
if err != nil {
|
||||
e.Error(c, http.StatusInternalServerError, err, "")
|
||||
return
|
||||
}
|
||||
e.OK(c, nil, "操作成功")
|
||||
}
|
||||
Reference in new issue
Block a user