del files

This commit is contained in:
wangchuxiao
2023-01-13 18:00:18 +08:00
parent cc1a9e1d4a
commit 51529eece3
55 changed files with 167 additions and 7336 deletions
-696
View File
@@ -1,696 +0,0 @@
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/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"
)
// @Summary 创建部门
// @Description 创建部门
// @Tags 组织架构相关
// @ID CreateDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.CreateDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.CreateDepartmentResp{data=open_im_sdk.Department}
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/create_department [post]
func CreateDepartment(c *gin.Context) {
params := api.CreateDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
utils.CopyStructFields(req.DepartmentInfo, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 更新部门信息
// @Description 更新部门信息
// @Tags 组织架构相关
// @ID UpdateDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.UpdateDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.UpdateDepartmentResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/update_department [post]
func UpdateDepartment(c *gin.Context) {
params := api.UpdateDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
utils.CopyStructFields(req.DepartmentInfo, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 获取子部门列表
// @Description 获取子部门列表
// @Tags 组织架构相关
// @ID GetSubDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.GetSubDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.GetSubDepartmentResp{data=[]open_im_sdk.Department}
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/get_sub_department [post]
func GetSubDepartment(c *gin.Context) {
params := api.GetSubDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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) {
}
// @Summary 删除部门
// @Description 删除部门
// @Tags 组织架构相关
// @ID DeleteDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.DeleteDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.DeleteDepartmentResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/delete_department [post]
func DeleteDepartment(c *gin.Context) {
params := api.DeleteDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 组织架构导入用户
// @Description 组织架构导入用户
// @Tags 组织架构相关
// @ID CreateOrganizationUser
// @Accept json
// @Param token header string true "im token"
// @Param req body api.CreateOrganizationUserReq true "请求"
// @Produce json
// @Success 0 {object} api.CreateOrganizationUserResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/create_organization_user [post]
func CreateOrganizationUser(c *gin.Context) {
params := api.CreateOrganizationUserReq{}
if err := c.BindJSON(&params); 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, &params)
utils.CopyStructFields(req.OrganizationUser, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 更新组织架构中的用户
// @Description 更新组织架构中的用户
// @Tags 组织架构相关
// @ID UpdateOrganizationUser
// @Accept json
// @Param token header string true "im token"
// @Param req body api.UpdateOrganizationUserReq true "请求"
// @Produce json
// @Success 0 {object} api.UpdateOrganizationUserResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/update_organization_user [post]
func UpdateOrganizationUser(c *gin.Context) {
params := api.UpdateOrganizationUserReq{}
if err := c.BindJSON(&params); 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, &params)
utils.CopyStructFields(req.OrganizationUser, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 创建部门用户
// @Description 创建部门用户
// @Tags 组织架构相关
// @ID CreateDepartmentMember
// @Accept json
// @Param token header string true "im token"
// @Param req body api.CreateDepartmentMemberReq true "请求"
// @Produce json
// @Success 0 {object} api.CreateDepartmentMemberResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/create_department_member [post]
func CreateDepartmentMember(c *gin.Context) {
params := api.CreateDepartmentMemberReq{}
if err := c.BindJSON(&params); 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, &params)
utils.CopyStructFields(req.DepartmentMember, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 获取部门中的所有用户
// @Description 获取部门中的所有用户
// @Tags 组织架构相关
// @ID GetUserInDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.GetUserInDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.GetUserInDepartmentResp{data=open_im_sdk.UserInDepartment}
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/get_user_in_department [post]
func GetUserInDepartment(c *gin.Context) {
params := api.GetUserInDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 更新部门中某个用户
// @Description 更新部门中某个用户
// @Tags 组织架构相关
// @ID UpdateUserInDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.UpdateUserInDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.UpdateUserInDepartmentResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/update_user_in_department [post]
func UpdateUserInDepartment(c *gin.Context) {
params := api.UpdateUserInDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
utils.CopyStructFields(req, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 删除组织架构中某个用户
// @Description 删除组织架构中某个用户
// @Tags 组织架构相关
// @ID DeleteOrganizationUser
// @Accept json
// @Param token header string true "im token"
// @Param req body api.DeleteOrganizationUserReq true "请求"
// @Produce json
// @Success 0 {object} api.DeleteOrganizationUserResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/delete_organization_user [post]
func DeleteOrganizationUser(c *gin.Context) {
params := api.DeleteOrganizationUserReq{}
if err := c.BindJSON(&params); 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, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 获取部门中所有成员
// @Description 获取部门中所有成员
// @Tags 组织架构相关
// @ID GetDepartmentMember
// @Accept json
// @Param token header string true "im token"
// @Param req body api.GetDepartmentMemberReq true "请求"
// @Produce json
// @Success 0 {object} api.GetDepartmentMemberResp{data=[]open_im_sdk.UserDepartmentMember}
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/get_department_member [post]
func GetDepartmentMember(c *gin.Context) {
params := api.GetDepartmentMemberReq{}
if err := c.BindJSON(&params); 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, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
// @Summary 删除部门中某个用户
// @Description 删除部门中某个用户
// @Tags 组织架构相关
// @ID DeleteUserInDepartment
// @Accept json
// @Param token header string true "im token"
// @Param req body api.DeleteUserInDepartmentReq true "请求"
// @Produce json
// @Success 0 {object} api.DeleteUserInDepartmentResp
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /organization/delete_user_in_department [post]
func DeleteUserInDepartment(c *gin.Context) {
params := api.DeleteUserInDepartmentReq{}
if err := c.BindJSON(&params); 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, &params)
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.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
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)
}
func GetUserInOrganization(c *gin.Context) {
req := api.GetUserInOrganizationReq{}
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
err, _ := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
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
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
reqPb := &rpc.GetUserInOrganizationReq{OperationID: req.OperationID, UserIDList: req.UserIDList}
client := rpc.NewOrganizationClient(etcdConn)
respPb, err := client.GetUserInOrganization(context.Background(), reqPb)
if err != nil {
errMsg := "rpc DeleteUserInDepartment failed " + err.Error() + reqPb.String()
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
apiResp := api.GetUserInOrganizationResp{CommResp: api.CommResp{ErrCode: respPb.ErrCode, ErrMsg: respPb.ErrMsg}, OrganizationUserList: respPb.OrganizationUsers}
apiResp.Data = jsonData.JsonDataList(apiResp.OrganizationUserList)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
c.JSON(http.StatusOK, apiResp)
}
-89
View File
@@ -1,89 +0,0 @@
package register
import (
"Open_IM/pkg/common/constant"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"errors"
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type CheckLoginLimitReq struct {
OperationID string `json:"operationID"`
UserID string `json:"userID"`
}
type CheckLoginLimitResp struct {
}
func CheckLoginLimit(c *gin.Context) {
req := CheckLoginLimitReq{}
if err := c.BindJSON(&req); err != nil {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
ip := c.Request.Header.Get("X-Forward-For")
if ip == "" {
ip = c.ClientIP()
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "IP: ", ip)
user, err := imdb.GetUserIPLimit(req.UserID)
if err != nil && !errors.Is(gorm.ErrRecordNotFound, err) {
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.UserID
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": errMsg})
return
}
if err := imdb.UpdateIpReocord(req.UserID, ip); err != nil {
log.NewError(req.OperationID, err.Error(), req.UserID, ip)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": err.Error()})
return
}
var Limited bool
var LimitError error
// 指定账户指定ip才能登录
Limited, LimitError = imdb.IsLimitUserLoginIp(user.UserID, ip)
if LimitError != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError})
return
}
if Limited {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "user ip limited Login"})
return
}
// 该ip不能登录
Limited, LimitError = imdb.IsLimitLoginIp(ip)
if LimitError != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError})
return
}
if Limited {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "ip limited Login"})
return
}
Limited, LimitError = imdb.UserIsBlock(user.UserID)
if LimitError != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, user.UserID)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError})
return
}
if Limited {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "user is block"})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
}
-123
View File
@@ -1,123 +0,0 @@
package register
import (
apiStruct "Open_IM/pkg/base_info"
"Open_IM/pkg/common/constant"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
type InvitationCode struct {
InvitationCode string `json:"invitationCode"`
CreateTime time.Time `json:"createTime"`
UserID string `json:"userID"`
LastTime time.Time `json:"lastTime"`
Status int32 `json:"status"`
}
type GenerateInvitationCodeReq struct {
CodesNum int `json:"codesNum" binding:"required"`
CodeLen int `json:"codeLen" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GenerateInvitationCodeResp struct {
Codes []string `json:"codes"`
}
func GenerateInvitationCode(c *gin.Context) {
req := GenerateInvitationCodeReq{}
resp := GenerateInvitationCodeResp{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var err error
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
resp.Codes, err = imdb.BatchCreateInvitationCodes(req.CodesNum, req.CodeLen)
if err != nil {
log.NewError(req.OperationID, "BatchCreateInvitationCodes failed", req.CodesNum, req.CodeLen)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "Verification code error!"})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
}
type QueryInvitationCodeReq struct {
Code string `json:"code" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type QueryInvitationCodeResp struct {
InvitationCode
}
func QueryInvitationCode(c *gin.Context) {
req := QueryInvitationCodeReq{}
resp := QueryInvitationCodeResp{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
invitation, err := imdb.GetInvitationCode(req.Code)
if err != nil {
log.NewError(req.OperationID, "GetInvitationCode failed", req.Code)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "Verification code error!"})
return
}
resp.UserID = invitation.UserID
resp.CreateTime = invitation.CreateTime
resp.Status = invitation.Status
resp.LastTime = invitation.LastTime
resp.InvitationCode.InvitationCode = invitation.InvitationCode
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
}
type GetInvitationCodesReq struct {
Status int32 `json:"status"`
OperationID string `json:"operationID" binding:"required"`
apiStruct.Pagination
}
type GetInvitationCodesResp struct {
apiStruct.Pagination
Codes []InvitationCode `json:"codes"`
CodeNums int64 `json:"codeNums"`
}
func GetInvitationCodes(c *gin.Context) {
req := GetInvitationCodesReq{}
resp := GetInvitationCodesResp{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
codes, count, err := imdb.GetInvitationCodes(req.ShowNumber, req.PageNumber, req.Status)
if err != nil {
log.NewError(req.OperationID, "GetInvitationCode failed", req.ShowNumber, req.PageNumber, req.Status)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "Verification code error!"})
return
}
resp.Pagination.PageNumber = req.PageNumber
resp.Pagination.ShowNumber = req.ShowNumber
for _, v := range codes {
resp.Codes = append(resp.Codes, InvitationCode{
InvitationCode: v.InvitationCode,
CreateTime: v.CreateTime,
UserID: v.UserID,
LastTime: v.LastTime,
Status: v.Status,
})
}
resp.CodeNums = count
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
}
-223
View File
@@ -1,223 +0,0 @@
package register
import (
//api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/constant"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
type QueryIPRegisterReq struct {
OperationID string `json:"operationID"`
IP string `json:"ip"`
}
type QueryIPRegisterResp struct {
IP string `json:"ip"`
RegisterNum int `json:"num"`
Status int `json:"status"`
UserIDList []string `json:"userIDList"`
}
func QueryIPRegister(c *gin.Context) {
req := QueryIPRegisterReq{}
resp := QueryIPRegisterResp{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
userIDList, err := imdb.GetRegisterUserNum(req.IP)
if err != nil {
log.NewError(req.OperationID, "GetInvitationCode failed", req.IP)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "GetRegisterUserNum error!"})
return
}
resp.IP = req.IP
resp.RegisterNum = len(userIDList)
resp.UserIDList = userIDList
ipLimit, err := imdb.QueryIPLimits(req.IP)
if err != nil {
log.NewError(req.OperationID, "QueryIPLimits failed", req.IP, err.Error())
} else {
if ipLimit != nil {
if ipLimit.Ip != "" {
resp.Status = 1
}
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
}
type AddIPLimitReq struct {
OperationID string `json:"operationID"`
IP string `json:"ip"`
LimitTime int32 `json:"limitTime"`
}
type AddIPLimitResp struct {
}
func AddIPLimit(c *gin.Context) {
req := AddIPLimitReq{}
//resp := AddIPLimitResp{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
if err := imdb.InsertOneIntoIpLimits(imdb.IpLimit{
Ip: req.IP,
LimitRegister: 1,
LimitLogin: 1,
CreateTime: time.Now(),
LimitTime: utils.UnixSecondToTime(int64(req.LimitTime)),
}); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP, req.LimitTime)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "InsertOneIntoIpLimits error!"})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
}
type RemoveIPLimitReq struct {
OperationID string `json:"operationID"`
IP string `json:"ip"`
}
type RemoveIPLimitResp struct {
}
func RemoveIPLimit(c *gin.Context) {
req := RemoveIPLimitReq{}
//resp := AddIPLimitResp{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrArgs, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
if err := imdb.DeleteOneFromIpLimits(req.IP); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "InsertOneIntoIpLimits error!"})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
}
// ===========================================sk ==========================
type QueryUserIDIPLimitLoginReq struct {
UserID string `json:"userID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
//type QueryUserIDIPLimitLoginResp struct {
// UserIpLimit []db.UserIpLimit `json:"userIpLimit"`
//}
func QueryUserIDLimitLogin(c *gin.Context) {
req := QueryUserIDIPLimitLoginReq{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
resp, err := imdb.GetIpLimitsLoginByUserID(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "GetIpLimitsByUserID error!"})
return
}
if len(resp) > 0 {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": gin.H{"limit": resp}})
}
type AddUserIPLimitLoginReq struct {
UserID string `json:"userID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
IP string `json:"ip"`
}
type AddUserIPLimitLoginResp struct {
}
// 添加ip 特定用户才能登录 user_ip_limits 表
func AddUserIPLimitLogin(c *gin.Context) {
req := AddUserIPLimitLoginReq{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
userIp := imdb.UserIpLimit{UserID: req.UserID, Ip: req.IP}
err := imdb.UpdateUserInfo(imdb.User{
UserID: req.UserID,
// LoginLimit: 1,
})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "InsertUserIpLimitsLogin error!"})
return
}
err = imdb.InsertUserIpLimitsLogin(&userIp)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "InsertUserIpLimitsLogin error!"})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
}
type RemoveUserIPLimitReq struct {
UserID string `json:"userID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
IP string `json:"ip"`
}
type RemoveUserIPLimitResp struct {
}
// 删除ip 特定用户才能登录 user_ip_limits 表
func RemoveUserIPLimitLogin(c *gin.Context) {
req := RemoveUserIPLimitReq{}
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
err := imdb.DeleteUserIpLimitsLogin(req.UserID, req.IP)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "DeleteUserIpLimitsLogin error!"})
return
}
ips, err := imdb.GetIpLimitsLoginByUserID(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "GetIpLimitsLoginByUserID error!"})
return
}
if len(ips) == 0 {
err := imdb.UpdateUserInfoByMap(imdb.User{
UserID: req.UserID,
}, map[string]interface{}{"login_limit": 0})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "UpdateUserInfo error!"})
return
}
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
}
@@ -1,313 +0,0 @@
package register
import (
"Open_IM/internal/api/manage"
"Open_IM/internal/rpc/msg"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/getcdv3"
groupRpc "Open_IM/pkg/proto/group"
organizationRpc "Open_IM/pkg/proto/organization"
commonPb "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"errors"
"fmt"
"math/rand"
"strings"
"time"
"github.com/golang/protobuf/proto"
)
type OnboardingProcessReq struct {
OperationID string
UserID string
NickName string
FaceURL string
PhoneNumber string
Email string
}
var Ch chan OnboardingProcessReq
func init() {
Ch = make(chan OnboardingProcessReq, 1000)
}
func OnboardingProcessRoutine() {
for {
req := <-Ch
go func() {
onboardingProcess(req.OperationID, req.UserID, req.NickName, req.FaceURL, req.PhoneNumber, req.Email)
}()
}
}
func onboardingProcess(operationID, userID, userName, faceURL, phoneNumber, email string) {
log.NewInfo(operationID, utils.GetSelfFuncName(), userName, userID, faceURL)
var joinDepartmentIDList []string
if len(config.Config.Demo.JoinDepartmentIDList) == 0 {
departmentID, err := imdb.GetRandomDepartmentID()
if err != nil {
log.NewError(utils.GetSelfFuncName(), "GetRandomDepartmentID failed", err.Error())
return
}
joinDepartmentIDList = []string{departmentID}
} else {
joinDepartmentIDList = config.Config.Demo.JoinDepartmentIDList
}
if config.Config.Demo.CreateOrganizationUserAndJoinDepartment && len(joinDepartmentIDList) > 0 {
if err := createOrganizationUser(operationID, userID, userName, phoneNumber, email); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "createOrganizationUser failed", err.Error())
}
for _, departmentID := range joinDepartmentIDList {
if err := joinTestDepartment(operationID, userID, departmentID); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "joinTestDepartment failed", err.Error())
}
}
}
if config.Config.Demo.JoinDepartmentGroups {
for _, departmentID := range joinDepartmentIDList {
groupIDList, err := GetDepartmentGroupIDList(operationID, departmentID)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
}
log.Debug(operationID, utils.GetSelfFuncName(), "getjoinGroupIDListdepartmentID", groupIDList)
joinGroups(operationID, userID, userName, faceURL, groupIDList)
log.NewInfo(operationID, utils.GetSelfFuncName(), "fineshed")
}
}
if config.Config.Demo.OaNotification {
oaNotification(operationID, userID)
}
}
func createOrganizationUser(operationID, userID, userName, phoneNumber, email string) error {
defer func() {
log.NewInfo(operationID, utils.GetSelfFuncName(), userID)
}()
log.NewInfo(operationID, utils.GetSelfFuncName(), "start createOrganizationUser")
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, operationID)
if etcdConn == nil {
errMsg := operationID + "getcdv3.GetDefaultConn == nil"
log.NewError(operationID, errMsg)
return errors.New(errMsg)
}
client := organizationRpc.NewOrganizationClient(etcdConn)
req := &organizationRpc.CreateOrganizationUserReq{
OrganizationUser: &commonPb.OrganizationUser{
UserID: userID,
Nickname: userName,
EnglishName: randomEnglishName(),
Gender: constant.Male,
CreateTime: uint32(time.Now().Unix()),
Telephone: phoneNumber,
Mobile: phoneNumber,
Email: email,
},
OperationID: operationID,
OpUserID: config.Config.Manager.AppManagerUid[0],
IsRegister: false,
}
resp, err := client.CreateOrganizationUser(context.Background(), req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
return err
}
if resp.ErrCode != 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), resp)
return errors.New(resp.ErrMsg)
}
return nil
}
func joinTestDepartment(operationID, userID, departmentID string) error {
defer func() {
log.NewInfo(operationID, utils.GetSelfFuncName(), userID)
}()
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, operationID)
if etcdConn == nil {
errMsg := operationID + "getcdv3.GetDefaultConn == nil"
log.NewError(operationID, errMsg)
return errors.New(errMsg)
}
client := organizationRpc.NewOrganizationClient(etcdConn)
req := &organizationRpc.CreateDepartmentMemberReq{
DepartmentMember: &commonPb.DepartmentMember{
UserID: userID,
DepartmentID: departmentID,
Position: randomPosition(),
},
OperationID: operationID,
OpUserID: config.Config.Manager.AppManagerUid[0],
}
resp, err := client.CreateDepartmentMember(context.Background(), req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
return err
}
if resp.ErrCode != 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), resp)
return errors.New(resp.ErrMsg)
}
return nil
}
func GetDepartmentGroupIDList(operationID, departmentID string) ([]string, error) {
defer func() {
log.NewInfo(operationID, utils.GetSelfFuncName(), departmentID)
}()
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName, operationID)
if etcdConn == nil {
errMsg := operationID + "getcdv3.GetDefaultConn == nil"
log.NewError(operationID, errMsg)
return nil, errors.New(errMsg)
}
client := organizationRpc.NewOrganizationClient(etcdConn)
req := organizationRpc.GetDepartmentParentIDListReq{
DepartmentID: departmentID,
OperationID: operationID,
}
resp, err := client.GetDepartmentParentIDList(context.Background(), &req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), req.String())
return nil, err
}
if resp.ErrCode != 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), resp)
return nil, errors.New(resp.ErrMsg)
}
resp.ParentIDList = append(resp.ParentIDList, departmentID)
getDepartmentRelatedGroupIDListReq := organizationRpc.GetDepartmentRelatedGroupIDListReq{OperationID: operationID, DepartmentIDList: resp.ParentIDList}
getDepartmentParentIDListResp, err := client.GetDepartmentRelatedGroupIDList(context.Background(), &getDepartmentRelatedGroupIDListReq)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), getDepartmentRelatedGroupIDListReq.String())
return nil, err
}
if getDepartmentParentIDListResp.ErrCode != 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), getDepartmentParentIDListResp)
return nil, errors.New(getDepartmentParentIDListResp.ErrMsg)
}
return getDepartmentParentIDListResp.GroupIDList, nil
}
func joinGroups(operationID, userID, userName, faceURL string, groupIDList []string) {
defer func() {
log.NewInfo(operationID, utils.GetSelfFuncName(), userID, groupIDList)
}()
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, operationID)
if etcdConn == nil {
errMsg := operationID + "getcdv3.GetDefaultConn == nil"
log.NewError(operationID, errMsg)
return
}
client := groupRpc.NewGroupClient(etcdConn)
for _, groupID := range groupIDList {
req := &groupRpc.InviteUserToGroupReq{
OperationID: operationID,
GroupID: groupID,
Reason: "register auto join",
InvitedUserIDList: []string{userID},
OpUserID: config.Config.Manager.AppManagerUid[1],
}
resp, err := client.InviteUserToGroup(context.Background(), req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), req.String())
continue
}
if resp.ErrCode != 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), resp)
continue
}
onboardingProcessNotification(operationID, userID, groupID, userName, faceURL)
}
}
// welcome user join department notification
func onboardingProcessNotification(operationID, userID, groupID, userName, faceURL string) {
defer func() {
log.NewInfo(operationID, utils.GetSelfFuncName(), userID, groupID)
}()
//var tips commonPb.TipsComm
//tips.DefaultTips = config.Config.Notification.JoinDepartmentNotification.DefaultTips.Tips
//tips.JsonDetail = ""
//content, err := proto.Marshal(&tips)
//if err != nil {
// log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), "proto marshal failed")
// return
//}
welcomeString := fmt.Sprintf("欢迎%s加入部门", userName)
notification := &msg.NotificationMsg{
SendID: userID,
RecvID: groupID,
Content: []byte(welcomeString),
MsgFrom: constant.UserMsgType,
ContentType: constant.Text,
SessionType: constant.SuperGroupChatType,
OperationID: operationID,
SenderNickname: userName,
SenderFaceURL: faceURL,
}
// notification user join group
msg.Notification(notification)
}
func oaNotification(operationID, userID string) {
var err error
elem := manage.OANotificationElem{
NotificationName: "入职通知",
NotificationFaceURL: "",
NotificationType: 1,
Text: "欢迎你入职公司",
Url: "",
MixType: 0,
PictureElem: manage.PictureElem{},
SoundElem: manage.SoundElem{},
VideoElem: manage.VideoElem{},
FileElem: manage.FileElem{},
Ex: "",
}
sysNotification := &msg.NotificationMsg{
SendID: config.Config.Manager.AppManagerUid[0],
RecvID: userID,
MsgFrom: constant.SysMsgType,
ContentType: constant.OANotification,
SessionType: constant.NotificationChatType,
OperationID: operationID,
}
var tips commonPb.TipsComm
tips.JsonDetail = utils.StructToJsonString(elem)
sysNotification.Content, err = proto.Marshal(&tips)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "elem: ", elem, err.Error())
return
}
msg.Notification(sysNotification)
}
func randomEnglishName() string {
l := []string{"abandon", "entail", "nebula", "shrink", "accumulate", "etch", "nostalgia", "slide",
"feudal", "adverse", "exploit", "occupy", "solve", "amazing", "fantasy", "orchid", "spiky", "approve", "flap"}
rand.Seed(time.Now().UnixNano())
index := rand.Intn(len(l) - 1)
return l[index]
}
func randomPosition() string {
l := []string{"后端工程师", "前端工程师", "设计师"}
rand.Seed(time.Now().UnixNano())
index := rand.Intn(len(l) - 1)
return l[index]
}
+1 -1
View File
@@ -1,7 +1,7 @@
package gate
import (
cbApi "Open_IM/pkg/call_back_struct"
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
+1 -1
View File
@@ -1,7 +1,7 @@
package logic
import (
cbApi "Open_IM/pkg/call_back_struct"
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/callback"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
+1 -1
View File
@@ -1,7 +1,7 @@
package friend
import (
cbApi "Open_IM/pkg/call_back_struct"
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
+1 -1
View File
@@ -1,7 +1,7 @@
package group
import (
cbApi "Open_IM/pkg/call_back_struct"
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
+1 -1
View File
@@ -1,7 +1,7 @@
package msg
import (
cbApi "Open_IM/pkg/call_back_struct"
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/callback"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
+1 -1
View File
@@ -1,7 +1,7 @@
package msg
import (
cbApi "Open_IM/pkg/call_back_struct"
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
-574
View File
@@ -1,574 +0,0 @@
package organization
import (
chat "Open_IM/internal/rpc/msg"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
rocksCache "Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log"
promePkg "Open_IM/pkg/common/prometheus"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/getcdv3"
pbAuth "Open_IM/pkg/proto/auth"
groupRpc "Open_IM/pkg/proto/group"
rpc "Open_IM/pkg/proto/organization"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"net"
"strconv"
"strings"
"time"
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
)
type organizationServer struct {
rpcPort int
rpcRegisterName string
etcdSchema string
etcdAddr []string
}
func NewServer(port int) *organizationServer {
log.NewPrivateLog(constant.LogFileName)
return &organizationServer{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImOrganizationName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
func (s *organizationServer) Run() {
log.NewInfo("", "organization rpc start ")
listenIP := ""
if config.Config.ListenIP == "" {
listenIP = "0.0.0.0"
} else {
listenIP = config.Config.ListenIP
}
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
//listener network
listener, err := net.Listen("tcp", address)
if err != nil {
panic("listening err:" + err.Error() + s.rpcRegisterName)
}
log.NewInfo("", "listen network success, ", address, listener)
defer listener.Close()
//grpc server
var grpcOpts []grpc.ServerOption
if config.Config.Prometheus.Enable {
promePkg.NewGrpcRequestCounter()
promePkg.NewGrpcRequestFailedCounter()
promePkg.NewGrpcRequestSuccessCounter()
grpcOpts = append(grpcOpts, []grpc.ServerOption{
// grpc.UnaryInterceptor(promePkg.UnaryServerInterceptorProme),
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
}...)
}
srv := grpc.NewServer(grpcOpts...)
defer srv.GracefulStop()
//Service registers with etcd
rpc.RegisterOrganizationServer(srv, s)
rpcRegisterIP := config.Config.RpcRegisterIP
if config.Config.RpcRegisterIP == "" {
rpcRegisterIP, err = utils.GetLocalIP()
if err != nil {
log.Error("", "GetLocalIP failed ", err.Error())
}
}
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
if err != nil {
log.NewError("", "RegisterEtcd failed ", err.Error())
panic(utils.Wrap(err, "register organization module rpc to etcd err"))
}
log.NewInfo("", "organization rpc RegisterEtcd success", rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
err = srv.Serve(listener)
if err != nil {
log.NewError("", "Serve failed ", err.Error())
return
}
log.NewInfo("", "organization rpc success")
}
func (s *organizationServer) CreateDepartment(ctx context.Context, req *rpc.CreateDepartmentReq) (*rpc.CreateDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
department := imdb.Department{}
utils.CopyStructFields(&department, req.DepartmentInfo)
if department.DepartmentID == "" {
department.DepartmentID = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
}
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
if err := imdb.CreateDepartment(&department); err != nil {
errMsg := req.OperationID + " " + "CreateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
createdDepartment, err := imdb.GetDepartment(department.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error() + department.DepartmentID
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "GetDepartment ", department.DepartmentID, *createdDepartment)
resp := &rpc.CreateDepartmentResp{DepartmentInfo: &open_im_sdk.Department{}}
utils.CopyStructFields(resp.DepartmentInfo, createdDepartment)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
resp.ErrCode = constant.ErrInternal.ErrCode
resp.ErrMsg = errMsg
return resp, nil
}
client := groupRpc.NewGroupClient(etcdConn)
createGroupReq := &groupRpc.CreateGroupReq{
InitMemberList: []*groupRpc.GroupAddMemberInfo{},
GroupInfo: &open_im_sdk.GroupInfo{
Introduction: req.DepartmentInfo.Name,
GroupName: req.DepartmentInfo.Name,
FaceURL: req.DepartmentInfo.FaceURL,
CreateTime: uint32(time.Now().Unix()),
CreatorUserID: req.OpUserID,
GroupType: constant.NormalGroup,
OwnerUserID: req.OpUserID,
},
OperationID: req.OperationID,
OpUserID: req.OpUserID,
OwnerUserID: req.OpUserID,
}
createGroupResp, err := client.CreateGroup(context.Background(), createGroupReq)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CreateGroup rpc failed", createGroupReq, err.Error())
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg + " createGroup failed " + err.Error()
return resp, nil
}
if createGroupResp.ErrCode != 0 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), resp)
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg + " createGroup failed " + createGroupResp.ErrMsg
return resp, nil
}
if err := imdb.SetDepartmentRelatedGroupID(createGroupResp.GroupInfo.GroupID, department.DepartmentID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetDepartmentRelatedGroupID failed", err.Error())
}
return resp, nil
}
func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.UpdateDepartmentReq) (*rpc.UpdateDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
department := imdb.Department{}
utils.CopyStructFields(&department, req.DepartmentInfo)
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
if err := imdb.UpdateDepartment(&department, nil); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg, department)
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
resp := &rpc.UpdateDepartmentResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
var departmentList []imdb.Department
var err error
if req.DepartmentID == "-1" {
departmentList, err = rocksCache.GetAllDepartmentsFromCache()
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
} else {
departmentList, err = imdb.GetSubDepartmentList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
}
log.Debug(req.OperationID, "GetSubDepartmentList ", req.DepartmentID, departmentList)
resp := &rpc.GetSubDepartmentResp{}
for _, v := range departmentList {
v1 := open_im_sdk.Department{}
utils.CopyStructFields(&v1, v)
log.Debug(req.OperationID, "src ", v, "dst ", v1)
err, v1.MemberNum = imdb.GetDepartmentMemberNum(v1.DepartmentID)
if err != nil {
log.Error(req.OperationID, "GetDepartmentMemberNum failed ", err.Error(), v1.DepartmentID)
continue
}
err, v1.SubDepartmentNum = imdb.GetSubDepartmentNum(v1.DepartmentID)
if err != nil {
log.Error(req.OperationID, "GetSubDepartmentNum failed ", err.Error(), v1.DepartmentID)
continue
}
resp.DepartmentList = append(resp.DepartmentList, &v1)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
return resp, nil
}
func (s *organizationServer) DeleteDepartment(ctx context.Context, req *rpc.DeleteDepartmentReq) (*rpc.DeleteDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
err := imdb.DeleteDepartment(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + "DeleteDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg, req.DepartmentID)
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "DeleteDepartment ", req.DepartmentID)
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
resp := &rpc.DeleteDepartmentResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rpc.CreateOrganizationUserReq) (*rpc.CreateOrganizationUserResp, error) {
authReq := &pbAuth.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
utils.CopyStructFields(authReq.UserInfo, req.OrganizationUser)
authReq.OperationID = req.OperationID
if req.IsRegister {
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
client := pbAuth.NewAuthClient(etcdConn)
reply, err := client.UserRegister(context.Background(), authReq)
if err != nil {
errMsg := "UserRegister failed " + err.Error()
log.NewError(req.OperationID, errMsg)
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
if reply.CommonResp.ErrCode != 0 {
errMsg := "UserRegister failed " + reply.CommonResp.ErrMsg
log.NewError(req.OperationID, errMsg)
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
organizationUser := imdb.OrganizationUser{}
utils.CopyStructFields(&organizationUser, req.OrganizationUser)
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth))
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser)
err := imdb.CreateOrganizationUser(&organizationUser)
if err != nil {
errMsg := req.OperationID + " " + "CreateOrganizationUser failed " + err.Error()
log.Error(req.OperationID, errMsg, organizationUser)
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "CreateOrganizationUser ", organizationUser)
resp := &rpc.CreateOrganizationUserResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
//chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rpc.UpdateOrganizationUserReq) (*rpc.UpdateOrganizationUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) && req.OpUserID != req.OrganizationUser.UserID {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
organizationUser := imdb.OrganizationUser{}
utils.CopyStructFields(&organizationUser, req.OrganizationUser)
if req.OrganizationUser.Birth != 0 {
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth))
log.Debug(req.OperationID, "time: ", organizationUser.Birth, req.OrganizationUser.Birth)
}
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser)
err := imdb.UpdateOrganizationUser(&organizationUser, nil)
if err != nil {
errMsg := req.OperationID + " " + "CreateOrganizationUser failed " + err.Error()
log.Error(req.OperationID, errMsg, organizationUser)
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "UpdateOrganizationUser ", organizationUser)
resp := &rpc.UpdateOrganizationUserResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rpc.CreateDepartmentMemberReq) (*rpc.CreateDepartmentMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
err, _ := imdb.GetOrganizationUser(req.DepartmentMember.UserID)
if err != nil {
errMsg := req.OperationID + " " + req.DepartmentMember.UserID + " is not exist"
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
departmentMember := imdb.DepartmentMember{}
utils.CopyStructFields(&departmentMember, req.DepartmentMember)
log.Debug(req.OperationID, "src ", *req.DepartmentMember, "dst ", departmentMember)
err = imdb.CreateDepartmentMember(&departmentMember)
if err != nil {
errMsg := req.OperationID + " " + "CreateDepartmentMember failed " + err.Error()
log.Error(req.OperationID, errMsg, departmentMember)
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "UpdateOrganizationUser ", departmentMember)
if err := rocksCache.DelAllDepartmentMembersFromCache(); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
resp := &rpc.CreateDepartmentMemberResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) GetDepartmentParentIDList(_ context.Context, req *rpc.GetDepartmentParentIDListReq) (resp *rpc.GetDepartmentParentIDListResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req.String())
resp = &rpc.GetDepartmentParentIDListResp{}
parentIDList, err := imdb.GetDepartmentParentIDList(req.DepartmentID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetDepartmentParentIDList failed", err.Error())
resp.ErrMsg = constant.ErrDB.ErrMsg + ": " + err.Error()
resp.ErrCode = constant.ErrDB.ErrCode
return resp, nil
}
resp.ParentIDList = parentIDList
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp.String())
return resp, nil
}
func (s *organizationServer) GetUserInDepartmentByUserID(userID string, operationID string) (*open_im_sdk.UserInDepartment, error) {
err, organizationUser := imdb.GetOrganizationUser(userID)
if err != nil {
return nil, utils.Wrap(err, "GetOrganizationUser failed")
}
err, departmentMemberList := imdb.GetUserInDepartment(userID)
if err != nil {
return nil, utils.Wrap(err, "GetUserInDepartment failed")
}
log.Debug(operationID, "GetUserInDepartment ", departmentMemberList)
resp := &open_im_sdk.UserInDepartment{OrganizationUser: &open_im_sdk.OrganizationUser{}}
utils.CopyStructFields(resp.OrganizationUser, organizationUser)
for _, v := range departmentMemberList {
v1 := open_im_sdk.DepartmentMember{}
utils.CopyStructFields(&v1, v)
log.Debug(operationID, "DepartmentMember src ", v, "dst ", v1)
resp.DepartmentMemberList = append(resp.DepartmentMemberList, &v1)
}
return resp, nil
}
func (s *organizationServer) GetUserInDepartment(ctx context.Context, req *rpc.GetUserInDepartmentReq) (*rpc.GetUserInDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
r, err := s.GetUserInDepartmentByUserID(req.UserID, req.OperationID)
if err != nil {
errMsg := req.OperationID + " " + "GetUserInDepartmentByUserID failed " + err.Error()
log.Error(req.OperationID, errMsg, req.UserID)
return &rpc.GetUserInDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "GetUserInDepartmentByUserID success ", req.UserID, r)
resp := rpc.GetUserInDepartmentResp{UserInDepartment: &open_im_sdk.UserInDepartment{OrganizationUser: &open_im_sdk.OrganizationUser{}}}
resp.UserInDepartment.DepartmentMemberList = r.DepartmentMemberList
resp.UserInDepartment.OrganizationUser = r.OrganizationUser
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
return &resp, nil
}
func (s *organizationServer) UpdateUserInDepartment(ctx context.Context, req *rpc.UpdateUserInDepartmentReq) (*rpc.UpdateUserInDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
departmentMember := &imdb.DepartmentMember{}
utils.CopyStructFields(departmentMember, req.DepartmentMember)
log.Debug(req.OperationID, "dst ", departmentMember, "src ", req.DepartmentMember)
err := imdb.UpdateUserInDepartment(departmentMember, nil)
if err != nil {
errMsg := req.OperationID + " " + "UpdateUserInDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg, *departmentMember)
return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
resp := &rpc.UpdateUserInDepartmentResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) DeleteUserInDepartment(ctx context.Context, req *rpc.DeleteUserInDepartmentReq) (*rpc.DeleteUserInDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.DeleteUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
err := imdb.DeleteUserInDepartment(req.DepartmentID, req.UserID)
if err != nil {
errMsg := req.OperationID + " " + "DeleteUserInDepartment failed " + err.Error()
log.Error(req.OperationID, errMsg, req.DepartmentID, req.UserID)
return &rpc.DeleteUserInDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "DeleteUserInDepartment success ", req.DepartmentID, req.UserID)
resp := &rpc.DeleteUserInDepartmentResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rpc.DeleteOrganizationUserReq) (*rpc.DeleteOrganizationUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.DeleteOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
err := imdb.DeleteOrganizationUser(req.UserID)
if err != nil {
errMsg := req.OperationID + " " + "DeleteOrganizationUser failed " + err.Error()
log.Error(req.OperationID, errMsg, req.UserID)
return &rpc.DeleteOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "DeleteOrganizationUser success ", req.UserID)
resp := &rpc.DeleteOrganizationUserResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
return resp, nil
}
func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
var departmentMemberList []imdb.DepartmentMember
var err error
if req.DepartmentID == "-1" {
departmentMemberList, err = rocksCache.GetAllDepartmentMembersFromCache()
if err != nil {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
} else {
departmentMemberList, err = imdb.GetDepartmentMemberList(req.DepartmentID)
if err != nil {
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
log.Error(req.OperationID, errMsg)
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
}
}
log.Debug(req.OperationID, "GetDepartmentMemberList ", departmentMemberList)
resp := rpc.GetDepartmentMemberResp{}
for _, v := range departmentMemberList {
err, organizationUser := imdb.GetOrganizationUser(v.UserID)
if err != nil {
log.Error(req.OperationID, "GetOrganizationUser failed ", err.Error())
continue
}
respOrganizationUser := &open_im_sdk.OrganizationUser{}
respDepartmentMember := &open_im_sdk.DepartmentMember{}
utils.CopyStructFields(respOrganizationUser, organizationUser)
utils.CopyStructFields(respDepartmentMember, &v)
userDepartmentMember := open_im_sdk.UserDepartmentMember{OrganizationUser: respOrganizationUser, DepartmentMember: respDepartmentMember}
log.Debug(req.OperationID, "GetUserInDepartmentByUserID success ", userDepartmentMember)
resp.UserDepartmentMemberList = append(resp.UserDepartmentMemberList, &userDepartmentMember)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
return &resp, nil
}
func (s *organizationServer) GetDepartmentRelatedGroupIDList(ctx context.Context, req *rpc.GetDepartmentRelatedGroupIDListReq) (resp *rpc.GetDepartmentRelatedGroupIDListResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &rpc.GetDepartmentRelatedGroupIDListResp{}
groupIDList, err := imdb.GetDepartmentRelatedGroupIDList(req.DepartmentIDList)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.ErrMsg = constant.ErrDB.ErrMsg + " GetDepartMentRelatedGroupIDList failed " + err.Error()
resp.ErrCode = constant.ErrDB.ErrCode
return resp, nil
}
resp.GroupIDList = groupIDList
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *organizationServer) GetUserInOrganization(_ context.Context, req *rpc.GetUserInOrganizationReq) (resp *rpc.GetUserInOrganizationResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &rpc.GetUserInOrganizationResp{}
organizationUserList, err := imdb.GetOrganizationUsers(req.UserIDList)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserIDList)
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = err.Error()
return resp, nil
}
for _, v := range organizationUserList {
organizationUser := &open_im_sdk.OrganizationUser{}
utils.CopyStructFields(organizationUser, v)
organizationUser.CreateTime = uint32(v.CreateTime.Unix())
organizationUser.Birth = uint32(v.CreateTime.Unix())
resp.OrganizationUsers = append(resp.OrganizationUsers, organizationUser)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}