style: 错误信息英文返回-system 模块路由

This commit is contained in:
TsMask
2023-11-08 14:56:36 +08:00
parent ae7f2d050c
commit a102f772cb
21 changed files with 460 additions and 342 deletions

View File

@@ -43,7 +43,7 @@ func (s *SysDeptController) List(c *gin.Context) {
}
err := c.ShouldBindQuery(&querys)
if err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
@@ -64,7 +64,7 @@ func (s *SysDeptController) List(c *gin.Context) {
func (s *SysDeptController) Info(c *gin.Context) {
deptId := c.Param("deptId")
if deptId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
data := s.sysDeptService.SelectDeptById(deptId)
@@ -82,7 +82,7 @@ func (s *SysDeptController) Add(c *gin.Context) {
var body model.SysDept
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DeptID != "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
@@ -90,16 +90,19 @@ func (s *SysDeptController) Add(c *gin.Context) {
if body.ParentID != "0" {
deptParent := s.sysDeptService.SelectDeptById(body.ParentID)
if deptParent.DeptID != body.ParentID {
c.JSON(200, result.ErrMsg("没有权限访问部门数据!"))
// 没有可访问部门数据!
c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
return
}
if deptParent.Status == common.STATUS_NO {
msg := fmt.Sprintf("上级部门【%s】停用不允许新增", deptParent.DeptName)
// 上级部门【%s】停用不允许新增
msg := fmt.Sprintf("Upper division [%s] deactivated, no new additions allowed", deptParent.DeptName)
c.JSON(200, result.ErrMsg(msg))
return
}
if deptParent.DelFlag == common.STATUS_YES {
msg := fmt.Sprintf("上级部门【%s】已删除不允许新增", deptParent.DeptName)
// 上级部门【%s】已删除不允许新增
msg := fmt.Sprintf("The parent department [%s] has been deleted and is not allowed to be added", deptParent.DeptName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -111,7 +114,8 @@ func (s *SysDeptController) Add(c *gin.Context) {
// 检查同级下名称唯一
uniqueDeptName := s.sysDeptService.CheckUniqueDeptName(body.DeptName, body.ParentID, "")
if !uniqueDeptName {
msg := fmt.Sprintf("部门新增【%s】失败部门名称已存在", body.DeptName)
// 部门新增【%s】失败部门名称已存在
msg := fmt.Sprintf("Department add [%s] failed, department name already exists", body.DeptName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -132,13 +136,14 @@ func (s *SysDeptController) Edit(c *gin.Context) {
var body model.SysDept
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DeptID == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 上级部门不能选自己
if body.DeptID == body.ParentID {
msg := fmt.Sprintf("部门修改【%s】失败上级部门不能是自己", body.DeptName)
// 部门修改【%s】失败上级部门不能是自己
msg := fmt.Sprintf("Departmental modification [%s] failed, the parent department cannot be itself", body.DeptName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -146,14 +151,16 @@ func (s *SysDeptController) Edit(c *gin.Context) {
// 检查数据是否存在
deptInfo := s.sysDeptService.SelectDeptById(body.DeptID)
if deptInfo.DeptID != body.DeptID {
c.JSON(200, result.ErrMsg("没有权限访问部门数据!"))
// 没有可访问部门数据!
c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
return
}
// 父级ID不为0是要检查
if body.ParentID != "0" {
deptParent := s.sysDeptService.SelectDeptById(body.ParentID)
if deptParent.DeptID != body.ParentID {
c.JSON(200, result.ErrMsg("没有权限访问部门数据!"))
// 没有可访问部门数据!
c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
return
}
}
@@ -161,7 +168,8 @@ func (s *SysDeptController) Edit(c *gin.Context) {
// 检查同级下名称唯一
uniqueDeptName := s.sysDeptService.CheckUniqueDeptName(body.DeptName, body.ParentID, body.DeptID)
if !uniqueDeptName {
msg := fmt.Sprintf("部门修改【%s】失败部门名称已存在", body.DeptName)
// 部门修改【%s】失败部门名称已存在
msg := fmt.Sprintf("Department modification [%s] failed, department name already exists", body.DeptName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -170,7 +178,8 @@ func (s *SysDeptController) Edit(c *gin.Context) {
if body.Status == common.STATUS_NO {
hasChild := s.sysDeptService.HasChildByDeptId(body.DeptID)
if hasChild > 0 {
msg := fmt.Sprintf("该部门包含未停用的子部门数量:%d", hasChild)
// 该部门包含未停用的子部门数量:%d
msg := fmt.Sprintf("Number of subsectors not deactivated included in this sector: %d", hasChild)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -191,21 +200,23 @@ func (s *SysDeptController) Edit(c *gin.Context) {
func (s *SysDeptController) Remove(c *gin.Context) {
deptId := c.Param("deptId")
if deptId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 检查数据是否存在
dept := s.sysDeptService.SelectDeptById(deptId)
if dept.DeptID != deptId {
c.JSON(200, result.ErrMsg("没有权限访问部门数据!"))
// 没有可访问部门数据!
c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
return
}
// 检查是否存在子部门
hasChild := s.sysDeptService.HasChildByDeptId(deptId)
if hasChild > 0 {
msg := fmt.Sprintf("不允许删除,存在子部门数:%d", hasChild)
// 不允许删除,存在子部门数:%d
msg := fmt.Sprintf("Deletion not allowed, number of subsectors present: %d", hasChild)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -213,14 +224,16 @@ func (s *SysDeptController) Remove(c *gin.Context) {
// 检查是否分配给用户
existUser := s.sysDeptService.CheckDeptExistUser(deptId)
if existUser > 0 {
msg := fmt.Sprintf("不允许删除,部门已分配给用户数:%d", existUser)
// 不允许删除,部门已分配给用户数:%d
msg := fmt.Sprintf("Deletions are not allowed and the department has been assigned to the number of users: %d", existUser)
c.JSON(200, result.ErrMsg(msg))
return
}
rows := s.sysDeptService.DeleteDeptById(deptId)
if rows > 0 {
msg := fmt.Sprintf("删除成功:%d", rows)
// 删除成功:%d
msg := fmt.Sprintf("Deleted successfully: %d", rows)
c.JSON(200, result.OkMsg(msg))
return
}
@@ -233,7 +246,7 @@ func (s *SysDeptController) Remove(c *gin.Context) {
func (s *SysDeptController) ExcludeChild(c *gin.Context) {
deptId := c.Param("deptId")
if deptId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
@@ -274,7 +287,7 @@ func (s *SysDeptController) TreeSelect(c *gin.Context) {
}
err := c.ShouldBindQuery(&querys)
if err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
@@ -295,7 +308,7 @@ func (s *SysDeptController) TreeSelect(c *gin.Context) {
func (s *SysDeptController) RoleDeptTreeSelect(c *gin.Context) {
roleId := c.Param("roleId")
if roleId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}