style: 错误信息英文返回-system 模块路由
This commit is contained in:
@@ -51,7 +51,7 @@ func (s *SysRoleController) List(c *gin.Context) {
|
||||
func (s *SysRoleController) Info(c *gin.Context) {
|
||||
roleId := c.Param("roleId")
|
||||
if roleId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
data := s.sysRoleService.SelectRoleById(roleId)
|
||||
@@ -69,14 +69,15 @@ func (s *SysRoleController) Add(c *gin.Context) {
|
||||
var body model.SysRole
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.RoleID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 判断角色名称是否唯一
|
||||
uniqueRoleName := s.sysRoleService.CheckUniqueRoleName(body.RoleName, "")
|
||||
if !uniqueRoleName {
|
||||
msg := fmt.Sprintf("角色新增【%s】失败,角色名称已存在", body.RoleName)
|
||||
// 角色新增【%s】失败,角色名称已存在
|
||||
msg := fmt.Sprintf("Character addition [%s] failed, character name already exists", body.RoleName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -84,7 +85,8 @@ func (s *SysRoleController) Add(c *gin.Context) {
|
||||
// 判断角色键值是否唯一
|
||||
uniqueRoleKey := s.sysRoleService.CheckUniqueRoleKey(body.RoleKey, "")
|
||||
if !uniqueRoleKey {
|
||||
msg := fmt.Sprintf("角色新增【%s】失败,角色键值已存在", body.RoleName)
|
||||
// 角色新增【%s】失败,角色键值已存在
|
||||
msg := fmt.Sprintf("Character addition [%s] failed, character key already exists", body.RoleName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -105,27 +107,30 @@ func (s *SysRoleController) Edit(c *gin.Context) {
|
||||
var body model.SysRole
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.RoleID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否管理员角色
|
||||
if body.RoleID == admin.ROLE_ID {
|
||||
c.JSON(200, result.ErrMsg("不允许操作管理员角色"))
|
||||
// 不允许操作管理员角色
|
||||
c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
role := s.sysRoleService.SelectRoleById(body.RoleID)
|
||||
if role.RoleID != body.RoleID {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问角色数据!"))
|
||||
// 没有可访问角色数据!
|
||||
c.JSON(200, result.ErrMsg("There is no accessible role data!"))
|
||||
return
|
||||
}
|
||||
|
||||
// 判断角色名称是否唯一
|
||||
uniqueRoleName := s.sysRoleService.CheckUniqueRoleName(body.RoleName, body.RoleID)
|
||||
if !uniqueRoleName {
|
||||
msg := fmt.Sprintf("角色修改【%s】失败,角色名称已存在", body.RoleName)
|
||||
// 角色修改【%s】失败,角色名称已存在
|
||||
msg := fmt.Sprintf("Character modification [%s] failed, character name already exists", body.RoleName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -133,7 +138,8 @@ func (s *SysRoleController) Edit(c *gin.Context) {
|
||||
// 判断角色键值是否唯一
|
||||
uniqueRoleKey := s.sysRoleService.CheckUniqueRoleKey(body.RoleKey, body.RoleID)
|
||||
if !uniqueRoleKey {
|
||||
msg := fmt.Sprintf("角色修改【%s】失败,角色键值已存在", body.RoleName)
|
||||
// 角色修改【%s】失败,角色键值已存在
|
||||
msg := fmt.Sprintf("Character modification [%s] failed, character key already exists", body.RoleName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -153,7 +159,7 @@ func (s *SysRoleController) Edit(c *gin.Context) {
|
||||
func (s *SysRoleController) Remove(c *gin.Context) {
|
||||
roleIds := c.Param("roleIds")
|
||||
if roleIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
@@ -166,7 +172,8 @@ func (s *SysRoleController) Remove(c *gin.Context) {
|
||||
// 检查是否管理员角色
|
||||
for _, id := range uniqueIDs {
|
||||
if id == admin.ROLE_ID {
|
||||
c.JSON(200, result.ErrMsg("不允许操作管理员角色"))
|
||||
// 不允许操作管理员角色
|
||||
c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -175,7 +182,7 @@ func (s *SysRoleController) Remove(c *gin.Context) {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf("删除成功:%d", rows)
|
||||
msg := fmt.Sprintf("Deleted successfully: %d", rows)
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
}
|
||||
|
||||
@@ -191,26 +198,29 @@ func (s *SysRoleController) Status(c *gin.Context) {
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否管理员角色
|
||||
if body.RoleID == admin.ROLE_ID {
|
||||
c.JSON(200, result.ErrMsg("不允许操作管理员角色"))
|
||||
// 不允许操作管理员角色
|
||||
c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
role := s.sysRoleService.SelectRoleById(body.RoleID)
|
||||
if role.RoleID != body.RoleID {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问角色数据!"))
|
||||
// 没有可访问角色数据!
|
||||
c.JSON(200, result.ErrMsg("There is no accessible role data!"))
|
||||
return
|
||||
}
|
||||
|
||||
// 与旧值相等不变更
|
||||
if role.Status == body.Status {
|
||||
c.JSON(200, result.ErrMsg("变更状态与旧值相等!"))
|
||||
// 变更状态与旧值相等!
|
||||
c.JSON(200, result.ErrMsg("The change status is equal to the old value!"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -245,20 +255,22 @@ func (s *SysRoleController) DataScope(c *gin.Context) {
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否管理员角色
|
||||
if body.RoleID == admin.ROLE_ID {
|
||||
c.JSON(200, result.ErrMsg("不允许操作管理员角色"))
|
||||
// 不允许操作管理员角色
|
||||
c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
role := s.sysRoleService.SelectRoleById(body.RoleID)
|
||||
if role.RoleID != body.RoleID {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问角色数据!"))
|
||||
// 没有可访问角色数据!
|
||||
c.JSON(200, result.ErrMsg("There is no accessible role data!"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -286,14 +298,15 @@ func (s *SysRoleController) AuthUserAllocatedList(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
roleId, ok := querys["roleId"]
|
||||
if !ok || roleId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
role := s.sysRoleService.SelectRoleById(roleId.(string))
|
||||
if role.RoleID != roleId {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问角色数据!"))
|
||||
// 没有可访问角色数据!
|
||||
c.JSON(200, result.ErrMsg("There is no accessible role data!"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -316,7 +329,7 @@ func (s *SysRoleController) AuthUserChecked(c *gin.Context) {
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -331,7 +344,7 @@ func (s *SysRoleController) AuthUserChecked(c *gin.Context) {
|
||||
// 检查是否存在
|
||||
role := s.sysRoleService.SelectRoleById(body.RoleID)
|
||||
if role.RoleID != body.RoleID {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问角色数据!"))
|
||||
c.JSON(200, result.ErrMsg("There is no accessible role data!"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -357,7 +370,8 @@ func (s *SysRoleController) Export(c *gin.Context) {
|
||||
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
|
||||
data := s.sysRoleService.SelectRolePage(querys, dataScopeSQL)
|
||||
if data["total"].(int64) == 0 {
|
||||
c.JSON(200, result.ErrMsg("导出数据记录为空"))
|
||||
// 导出数据记录为空
|
||||
c.JSON(200, result.ErrMsg("Export data record is empty"))
|
||||
return
|
||||
}
|
||||
rows := data["rows"].([]model.SysRole)
|
||||
@@ -366,26 +380,26 @@ func (s *SysRoleController) Export(c *gin.Context) {
|
||||
fileName := fmt.Sprintf("role_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
||||
// 第一行表头标题
|
||||
headerCells := map[string]string{
|
||||
"A1": "角色序号",
|
||||
"B1": "角色名称",
|
||||
"C1": "角色权限",
|
||||
"D1": "角色排序",
|
||||
"E1": "数据范围",
|
||||
"F1": "角色状态",
|
||||
"A1": "RoleID",
|
||||
"B1": "RoleName",
|
||||
"C1": "RoleKey",
|
||||
"D1": "RoleSort",
|
||||
"E1": "DataScope",
|
||||
"F1": "Status",
|
||||
}
|
||||
// 从第二行开始的数据
|
||||
dataCells := make([]map[string]any, 0)
|
||||
for i, row := range rows {
|
||||
idx := strconv.Itoa(i + 2)
|
||||
// 数据范围
|
||||
dataScope := "空"
|
||||
dataScope := "Empty"
|
||||
if v, ok := roledatascope.RoleDataScope[row.DataScope]; ok {
|
||||
dataScope = v
|
||||
}
|
||||
// 角色状态
|
||||
statusValue := "停用"
|
||||
statusValue := "deactivate"
|
||||
if row.Status == "1" {
|
||||
statusValue = "正常"
|
||||
statusValue = "normalcy"
|
||||
}
|
||||
dataCells = append(dataCells, map[string]any{
|
||||
"A" + idx: row.RoleID,
|
||||
|
||||
Reference in New Issue
Block a user