package controller import ( "errors" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" "github.com/gin-gonic/gin" "github.com/spf13/cast" ) // 新增组织 func AddOrg(c *gin.Context) { var input request.OrgInput if err := c.ShouldBindJSON(&input); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } //参数检测 DataType 0 目录 1组织 if input.DataType == 0 && input.Name == "" { SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入目录名称"), nil) return } if input.DataType == 1 { if input.Name == "" { SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("请输入机构名称")), nil) return } if input.OrganizationCode == "" { SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入组织机构代码"), nil) return } } orgService := service.Organization{User: header.GetUser(c)} result, err := orgService.AddOrg(input) if err != nil { SendJsonResponse(c, err, nil) return } SendJsonResponse(c, resp.OK, result) } // 更新组织或目录 func UpdateOrg(c *gin.Context) { var input request.OrgInput if err := c.ShouldBindJSON(&input); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } //参数检测 DataType 0 目录 1组织 if input.DataType == 0 && input.Name == "" { SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入目录名称"), nil) return } if input.DataType == 1 { if input.Name == "" { SendJsonResponse(c, resp.FAIL.WithMsg("请输入机构名称"), nil) return } if input.OrganizationCode == "" { SendJsonResponse(c, resp.FAIL.WithMsg("请输入组织机构代码"), nil) return } } orgService := service.Organization{User: header.GetUser(c)} if err := orgService.UpdateOrg(cast.ToInt64(c.Param("id")), input); err != nil { SendJsonResponse(c, err, nil) return } SendJsonResponse(c, resp.OK, nil) } // 删除组织或者目录 func DeleteOrg(c *gin.Context) { orgService := service.Organization{User: header.GetUser(c)} if err := orgService.DeleteOrg(cast.ToInt64(c.Param("id"))); err != nil { SendJsonResponse(c, err, nil) return } SendJsonResponse(c, resp.OK, nil) } // 组织排序 func SortOrg(c *gin.Context) { var input []request.OrgSortInput if err := c.ShouldBindJSON(&input); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } orgService := service.Organization{User: header.GetUser(c)} if err := orgService.SortOrg(input); err != nil { SendJsonResponse(c, err, nil) return } SendJsonResponse(c, resp.OK, nil) } // 查询组织树 func GetOrgTree(c *gin.Context) { orgService := service.Organization{} result, err := orgService.GetOrgTree() if err != nil { SendJsonResponse(c, err, nil) return } SendJsonResponse(c, resp.OK, result) } // 查询组织详情 func OrgDetail(c *gin.Context) { var input request.QueryOrgDetailInput if err := c.ShouldBind(&input); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } if input.OrganizationId == "" { SendJsonResponse(c, resp.InvalidParam.WithMsg("组织id必填"), nil) return } //if input.DataType == "" { // SendJsonResponse(c, resp.InvalidParam.WithMsg("DataType必填"), nil) // return //} if input.Limit == 0 { input.Limit = 10 } orgService := service.Organization{} result, err := orgService.OrgDetail(input) if err != nil { SendJsonResponse(c, err, nil) return } SendJsonResponse(c, resp.OK, result) } // //// 查询业务系统信息 //func GetBusinessMsg(c *gin.Context) { // var input request.GetBusinessMsgInput // if err := c.ShouldBind(&input); err != nil { // SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), nil) // return // } // if input.OrganizationId == "" { // SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("组织id必填")), nil) // return // } // if input.Limit == 0 { // input.Limit = 10 // } // orgService := service.Organization{} // respult, count, err := orgService.GetBusinessMsg(input) // if err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonPageResponse(c, resp.GET_OK, respult, count) //} // //// 查询组织用户详情 //func OrgUserDetail(c *gin.Context) { // id := cast.ToInt(c.Param("id")) // if id <= 0 { // SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil) // return // } // orgService := service.Organization{} // respult, err := orgService.OrgUserDetail(id) // if err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonResponse(c, resp.GET_OK, respult) //} // //// 组织添加用户时查询的角色列表 //func OrgUserRoles(c *gin.Context) { // isadmin := c.Query("is_admin") // if isadmin == "" { // SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("用户类型必填")), nil) // return // } // orgService := service.Organization{} // respult, err := orgService.OrgUserRoles(cast.ToInt(isadmin)) // if err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonResponse(c, resp.GET_OK, respult) //} // //// 添加组织用户 //func OrgAddUser(c *gin.Context) { // var input request.OrgUserInput // if err := c.ShouldBindJSON(&input); err != nil { // SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil) // return // } // if err := vd.Validate(input); err != nil { // SendJsonResponse(c, err, "") // return // } // if input.IsAdmin != 2 && input.IsAdmin != 3 { // SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(errors.New("超出类型可选范围")), nil) // return // } // // orgService := service.Organization{User: util.GetContextUser(c)} // if err := orgService.OrgAddUser(input); err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonResponse(c, resp.ADD_OK, nil) //} // //// 编辑用户 //func OrgUpdateUser(c *gin.Context) { // id := cast.ToInt(c.Param("id")) // if id <= 0 { // SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil) // return // } // var input request.UpdateOrgUserInput // if err := c.ShouldBindJSON(&input); err != nil { // SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil) // return // } // if err := vd.Validate(input); err != nil { // SendJsonResponse(c, err, "") // return // } // orgService := service.Organization{User: util.GetContextUser(c)} // if err := orgService.OrgUpdateUser(id, input); err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonResponse(c, resp.UPDATE_OK, nil) //} // //// 删除组织用户 //func DelOrgUser(c *gin.Context) { // var input request.DelOrgUser // if err := c.ShouldBindJSON(&input); err != nil { // SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil) // return // } // if len(input.Ids) <= 0 { // SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil) // return // } // orgService := service.Organization{User: util.GetContextUser(c)} // if err := orgService.DelOrgUser(input); err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonResponse(c, resp.DELETE_OK, nil) //} // //// 去重校验 //func CheckRepetition(c *gin.Context) { // var input request.CheckRepetition // if err := c.ShouldBindJSON(&input); err != nil { // SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil) // return // } // orgService := service.Organization{} // if err := orgService.CheckRepetition(input); err != nil { // SendJsonResponse(c, err, nil) // return // } // SendJsonResponse(c, resp.GET_OK, nil) //}