You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
6.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package BaseRoleController
import (
"dsBaseWeb/Business/BaseRole/BaseRoleService"
"dsBaseWeb/Model"
"dsBaseWeb/Utils/CommonUtil"
"github.com/gin-gonic/gin"
"net/http"
)
func Routers(r *gin.RouterGroup) {
rr := r.Group("/role")
rr.GET("/PageRoleInfo", PageRoleInfo)
rr.GET("/GetRoleInfo", GetRoleInfo)
rr.POST("/AddRoleInfo", AddRoleInfo)
rr.POST("/DeleteRoleInfo", DeleteRoleInfo)
rr.POST("/UpdateRoleInfo", UpdateRoleInfo)
return
}
// @Summary 根据系统ID或身份ID获取角色信息
// @Description 根据系统ID或身份ID获取角色信息
// @Tags 角色信息
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param page query int true "第几页"
// @Param limit query int true "一页显示多少条"
// @Param appId query string true "系统ID 全部传-1"
// @Param identityId query string true "身份ID 全部传-1"
// @Success 200 {object} Model.Res
// @Router /base/role/PageRoleInfo [get]
// @X-RoleLimit ["1"]
// @X-Sort [1]
func PageRoleInfo(c *gin.Context) {
//第几页
page := CommonUtil.ConvertStringToInt32(c.Query("page"))
//一页显示多少条
limit := CommonUtil.ConvertStringToInt32(c.Query("limit"))
//系统ID
appId := c.Query("appId")
//身份ID
identityId := CommonUtil.ConvertStringToInt32(c.Query("identityId"))
r, err := BaseRoleService.PageBaseRoleInfo(appId, identityId, page, limit)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: "调用RPC服务失败",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Success: r.Success,
Message: r.Message,
List: CommonUtil.ConvertJsonStringToMapArray(r.List),
Count: r.Count,
})
}
// @Summary 根据菜单ID获取该角色信息
// @Description 根据菜单ID获取该角色信息
// @Tags 角色信息
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param roleId query string true "角色ID"
// @Success 200 {object} Model.Res
// @Router /base/role/GetRoleInfo [get]
// @X-EmptyLimit ["roleId"]
// @X-LengthLimit [{"roleId":"36,36"}]
// @X-RoleLimit ["1"]
// @X-Sort [2]
func GetRoleInfo(c *gin.Context) {
//角色ID
roleId := c.Query("roleId")
r, err := BaseRoleService.GetBaseRoleInfo(roleId)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: "调用RPC服务失败",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Success: r.Success,
Message: r.Message,
List: CommonUtil.ConvertJsonStringToMapArray(r.List),
})
}
// @Summary 增加角色信息
// @Description 增加角色信息
// @Tags 角色信息
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param roleName formData string true "角色名称"
// @Param roleCode formData string true "角色编码"
// @Param identityId formData int true "身份ID"
// @Param roleLevel formData int true "角色级别 2省级教育局 3市级教育局 4区(县)级教育局 5省级教辅单位 6市级教辅单位 7区(县)级教辅单位 8校级"
// @Param appIds formData string true "角色所属系统ID多个用逗号分隔通用传-1"
// @Param sortId formData int true "排序号"
// @Success 200 {object} Model.Res
// @Router /base/role/AddRoleInfo [post]
// @X-EmptyLimit ["roleName","roleCode","identityId","roleLevel","appIds","sortId"]
// @X-LengthLimit [{"roleName":"2,50"},{"roleCode":"2,20"}]
// @X-RoleLimit ["1"]
// @X-Sort [3]
func AddRoleInfo(c *gin.Context) {
//角色名称
roleName := c.PostForm("roleName")
//角色编码
roleCode := c.PostForm("roleCode")
//身份ID
identityId := CommonUtil.ConvertStringToInt32(c.PostForm("identityId"))
//角色级别
roleLevel := CommonUtil.ConvertStringToInt32(c.PostForm("roleLevel"))
//角色所属系统ID
appIds := c.PostForm("appIds")
//排序号
sortId := CommonUtil.ConvertStringToInt32(c.PostForm("sortId"))
r, err := BaseRoleService.AddBaseRoleInfo(roleName, roleCode, identityId, roleLevel, appIds, sortId)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: "调用RPC服务失败",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Success: r.Success,
Message: r.Message,
})
}
// @Summary 删除角色信息
// @Description 删除角色信息
// @Tags 角色信息
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param roleIds formData string true "角色ID多个用逗号分隔"
// @Success 200 {object} Model.Res
// @Router /base/role/DeleteRoleInfo [post]
// @X-EmptyLimit ["roleIds"]
// @X-LengthLimit [{"roleIds":"36,1800"}]
// @X-RoleLimit ["1"]
// @X-Sort [4]
func DeleteRoleInfo(c *gin.Context) {
//角色ID
roleIds := c.PostForm("roleIds")
r, err := BaseRoleService.DeleteBaseRoleInfo(roleIds)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: "调用RPC服务失败",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Success: r.Success,
Message: r.Message,
})
}
// @Summary 增加角色信息
// @Description 增加角色信息
// @Tags 角色信息
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param roleId formData string true "角色ID"
// @Param roleName formData string true "角色名称"
// @Param roleCode formData string true "角色编码"
// @Param identityId formData int true "身份ID"
// @Param roleLevel formData int true "角色级别"
// @Param appIds formData string true "角色所属系统ID多个用逗号分隔通用传-1"
// @Param sortId formData int true "排序号"
// @Success 200 {object} Model.Res
// @Router /base/role/UpdateRoleInfo [post]
// @X-EmptyLimit ["roleId","roleName","roleCode","identityId","roleLevel","appIds","sortId"]
// @X-LengthLimit [{"roleName":"36,36"},{"roleName":"2,50"},{"roleCode":"2,20"}]
// @X-RoleLimit ["1"]
// @X-Sort [5]
func UpdateRoleInfo(c *gin.Context) {
//角色ID
roleId := c.PostForm("roleId")
//角色名称
roleName := c.PostForm("roleName")
//角色编码
roleCode := c.PostForm("roleCode")
//身份ID
identityId := CommonUtil.ConvertStringToInt32(c.PostForm("identityId"))
//角色级别
roleLevel := CommonUtil.ConvertStringToInt32(c.PostForm("roleLevel"))
//角色所属系统ID
appIds := c.PostForm("appIds")
//排序号
sortId := CommonUtil.ConvertStringToInt32(c.PostForm("sortId"))
r, err := BaseRoleService.UpdateBaseRoleInfo(roleId, roleName, roleCode, identityId, roleLevel, appIds, sortId)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: "调用RPC服务失败",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Success: r.Success,
Message: r.Message,
})
}