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.
444 lines
20 KiB
444 lines
20 KiB
package organization
|
|
|
|
import (
|
|
jsonData "Open_IM/internal/utils"
|
|
api "Open_IM/pkg/base_info"
|
|
"Open_IM/pkg/common/config"
|
|
"Open_IM/pkg/common/log"
|
|
"Open_IM/pkg/common/token_verify"
|
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
|
rpc "Open_IM/pkg/proto/organization"
|
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
|
"Open_IM/pkg/utils"
|
|
"context"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func CreateDepartment(c *gin.Context) {
|
|
params := api.CreateDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
req := &rpc.CreateDepartmentReq{DepartmentInfo: &open_im_sdk.Department{}}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
utils.CopyStructFields(req.DepartmentInfo, ¶ms)
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + " " + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.CreateDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc CreateDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.CreateDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Department: RpcResp.DepartmentInfo}
|
|
apiResp.Data = jsonData.JsonDataOne(RpcResp.DepartmentInfo)
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func UpdateDepartment(c *gin.Context) {
|
|
params := api.UpdateDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
req := &rpc.UpdateDepartmentReq{DepartmentInfo: &open_im_sdk.Department{}}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
utils.CopyStructFields(req.DepartmentInfo, ¶ms)
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.UpdateDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc UpdateDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.UpdateDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func GetSubDepartment(c *gin.Context) {
|
|
params := api.GetSubDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
req := &rpc.GetSubDepartmentReq{}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.GetSubDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc GetDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.GetSubDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, DepartmentList: RpcResp.DepartmentList}
|
|
apiResp.Data = jsonData.JsonDataList(RpcResp.DepartmentList)
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func GetAllDepartment(c *gin.Context) {
|
|
|
|
}
|
|
|
|
func DeleteDepartment(c *gin.Context) {
|
|
params := api.DeleteDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
req := &rpc.DeleteDepartmentReq{}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.DeleteDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc DeleteDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.DeleteDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func CreateOrganizationUser(c *gin.Context) {
|
|
params := api.CreateOrganizationUserReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.CreateOrganizationUserReq{OrganizationUser: &open_im_sdk.OrganizationUser{}}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
utils.CopyStructFields(req.OrganizationUser, ¶ms)
|
|
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.CreateOrganizationUser(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc CreateOrganizationUser failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.CreateOrganizationUserResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func UpdateOrganizationUser(c *gin.Context) {
|
|
params := api.UpdateOrganizationUserReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.UpdateOrganizationUserReq{OrganizationUser: &open_im_sdk.OrganizationUser{}}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
utils.CopyStructFields(req.OrganizationUser, ¶ms)
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.UpdateOrganizationUser(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc UpdateOrganizationUser failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.UpdateOrganizationUserResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func CreateDepartmentMember(c *gin.Context) {
|
|
params := api.CreateDepartmentMemberReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.CreateDepartmentMemberReq{DepartmentMember: &open_im_sdk.DepartmentMember{}}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
utils.CopyStructFields(req.DepartmentMember, ¶ms)
|
|
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.CreateDepartmentMember(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc CreateDepartmentMember failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.CreateDepartmentMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func GetUserInDepartment(c *gin.Context) {
|
|
params := api.GetUserInDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.GetUserInDepartmentReq{}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.GetUserInDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc GetUserInDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.GetUserInDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, UserInDepartment: RpcResp.UserInDepartment}
|
|
apiResp.Data = jsonData.JsonDataOne(RpcResp.UserInDepartment)
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func UpdateUserInDepartment(c *gin.Context) {
|
|
params := api.UpdateUserInDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.UpdateUserInDepartmentReq{DepartmentMember: &open_im_sdk.DepartmentMember{}}
|
|
utils.CopyStructFields(req.DepartmentMember, ¶ms)
|
|
utils.CopyStructFields(req, ¶ms)
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.UpdateUserInDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc UpdateUserInDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.UpdateUserInDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func DeleteOrganizationUser(c *gin.Context) {
|
|
params := api.DeleteOrganizationUserReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.DeleteOrganizationUserReq{}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.DeleteOrganizationUser(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc DeleteOrganizationUser failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.DeleteOrganizationUserResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func GetDepartmentMember(c *gin.Context) {
|
|
params := api.GetDepartmentMemberReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
|
|
req := &rpc.GetDepartmentMemberReq{}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.GetDepartmentMember(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc GetDepartmentMember failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.GetDepartmentMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, UserInDepartmentList: RpcResp.UserDepartmentMemberList}
|
|
apiResp.Data = jsonData.JsonDataList(RpcResp.UserDepartmentMemberList)
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|
|
|
|
func DeleteUserInDepartment(c *gin.Context) {
|
|
params := api.DeleteUserInDepartmentReq{}
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
req := &rpc.DeleteUserInDepartmentReq{}
|
|
utils.CopyStructFields(req, ¶ms)
|
|
|
|
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
|
req.OpUserID = opUserID
|
|
if err != nil {
|
|
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
|
client := rpc.NewOrganizationClient(etcdConn)
|
|
RpcResp, err := client.DeleteUserInDepartment(context.Background(), req)
|
|
if err != nil {
|
|
errMsg := "rpc DeleteUserInDepartment failed " + err.Error() + req.String()
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
|
return
|
|
}
|
|
|
|
apiResp := api.DeleteUserInDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
|
c.JSON(http.StatusOK, apiResp)
|
|
}
|