parent
659c3bc1cf
commit
c216340120
@ -0,0 +1,400 @@
|
|||||||
|
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/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{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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 GetDepartment(c *gin.Context) {
|
||||||
|
params := api.GetDepartmentReq{}
|
||||||
|
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.GetDepartmentReq{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
client := rpc.NewOrganizationClient(etcdConn)
|
||||||
|
RpcResp, err := client.GetDepartment(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.GetDepartmentResp{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 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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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{}
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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())
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
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.UserInDepartmentList}
|
||||||
|
apiResp.Data = jsonData.JsonDataList(RpcResp.UserInDepartmentList)
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||||
|
c.JSON(http.StatusOK, apiResp)
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package base_info
|
||||||
|
|
||||||
|
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
|
|
||||||
|
type CreateDepartmentReq struct {
|
||||||
|
*open_im_sdk.Department
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
type CreateDepartmentResp struct {
|
||||||
|
CommResp
|
||||||
|
Department *open_im_sdk.Department `json:"-"`
|
||||||
|
Data map[string]interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateDepartmentReq struct {
|
||||||
|
*open_im_sdk.Department
|
||||||
|
DepartmentID string `json:"departmentID" binding:"required"`
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
type UpdateDepartmentResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDepartmentReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
DepartmentID string
|
||||||
|
}
|
||||||
|
type GetDepartmentResp struct {
|
||||||
|
CommResp
|
||||||
|
DepartmentList []*open_im_sdk.Department `json:"-"`
|
||||||
|
Data []map[string]interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteDepartmentReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
DepartmentID string
|
||||||
|
}
|
||||||
|
type DeleteDepartmentResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateOrganizationUserReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
OrganizationUser *open_im_sdk.OrganizationUser
|
||||||
|
}
|
||||||
|
type CreateOrganizationUserResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateOrganizationUserReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
OrganizationUser *open_im_sdk.OrganizationUser
|
||||||
|
}
|
||||||
|
type UpdateOrganizationUserResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateDepartmentMemberReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UserInDepartment *open_im_sdk.UserInDepartment
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateDepartmentMemberResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUserInDepartmentReq struct {
|
||||||
|
UserID string
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
type GetUserInDepartmentResp struct {
|
||||||
|
CommResp
|
||||||
|
UserInDepartment *open_im_sdk.UserInDepartment `json:"-"`
|
||||||
|
Data map[string]interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateUserInDepartmentReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UserInDepartment *open_im_sdk.UserInDepartment
|
||||||
|
}
|
||||||
|
type UpdateUserInDepartmentResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteOrganizationUserReq struct {
|
||||||
|
UserID string
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
type DeleteOrganizationUserResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDepartmentMemberReq struct {
|
||||||
|
DepartmentID string
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
type GetDepartmentMemberResp struct {
|
||||||
|
CommResp
|
||||||
|
UserInDepartmentList []*open_im_sdk.UserInDepartment `json:"-"`
|
||||||
|
Data []map[string]interface{} `json:"data"`
|
||||||
|
}
|
@ -0,0 +1,155 @@
|
|||||||
|
package im_mysql_model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/db"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateDepartment(department *db.Department) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
department.CreateTime = time.Now()
|
||||||
|
return dbConn.Table("departments").Create(department).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDepartment(departmentID string) (error, *db.Department) {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
var department db.Department
|
||||||
|
err = dbConn.Table("departments").Where("department_id=?", departmentID).Find(&department).Error
|
||||||
|
return err, &department
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateDepartment(department *db.Department, args map[string]interface{}) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if args != nil {
|
||||||
|
return dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSubDepartmentList(departmentID string) (error, []db.Department) {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
var departmentList []db.Department
|
||||||
|
err = dbConn.Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
|
||||||
|
return err, departmentList
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteDepartment(departmentID string) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = dbConn.Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = dbConn.Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateOrganizationUser(organizationUser *db.OrganizationUser) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
organizationUser.CreateTime = time.Now()
|
||||||
|
return dbConn.Table("organization_users").Create(organizationUser).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[string]interface{}) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if args != nil {
|
||||||
|
return dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateDepartmentMember(departmentMember *db.DepartmentMember) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
departmentMember.CreateTime = time.Now()
|
||||||
|
return dbConn.Table("department_members").Create(departmentMember).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetUserInDepartment(userID string) (error, []db.DepartmentMember) {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
var departmentMemberList []db.DepartmentMember
|
||||||
|
err = dbConn.Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
|
||||||
|
return err, departmentMemberList
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateUserInDepartment(userInDepartmentList []db.DepartmentMember) error {
|
||||||
|
if len(userInDepartmentList) == 0 {
|
||||||
|
return errors.New("args failed")
|
||||||
|
}
|
||||||
|
if err := DeleteUserInAllDepartment(userInDepartmentList[0].UserID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, v := range userInDepartmentList {
|
||||||
|
if err := CreateDepartmentMember(&v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteUserInAllDepartment(userID string) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return dbConn.Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteOrganizationUser(OrganizationUserID string) error {
|
||||||
|
if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return dbConn.Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
var departmentMemberList []db.DepartmentMember
|
||||||
|
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
|
||||||
|
|
||||||
|
var userIDList []string = make([]string, 0)
|
||||||
|
for _, v := range departmentMemberList {
|
||||||
|
userIDList = append(userIDList, v.UserID)
|
||||||
|
}
|
||||||
|
return err, userIDList
|
||||||
|
}
|
Loading…
Reference in new issue