organization

pull/218/head
skiffer-git 3 years ago
parent 659c3bc1cf
commit c216340120

@ -8,6 +8,7 @@ import (
"Open_IM/internal/api/group"
"Open_IM/internal/api/manage"
"Open_IM/internal/api/office"
"Open_IM/internal/api/organization"
apiThird "Open_IM/internal/api/third"
"Open_IM/internal/api/user"
"Open_IM/pkg/common/config"
@ -136,6 +137,22 @@ func main() {
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
}
organizationGroup := r.Group("/organization")
{
organizationGroup.POST("/create_department", organization.CreateDepartment)
organizationGroup.POST("/update_department", organization.UpdateDepartment)
organizationGroup.POST("/get_department", organization.GetDepartment)
organizationGroup.POST("/delete_department", organization.DeleteDepartment)
organizationGroup.POST("/create_organization_user", organization.CreateOrganizationUser)
organizationGroup.POST("/update_organization_user", organization.UpdateOrganizationUser)
organizationGroup.POST("/create_department_member", organization.CreateDepartmentMember)
organizationGroup.POST("/get_user_in_department", organization.GetUserInDepartment)
organizationGroup.POST("/update_user_In_department", organization.UpdateUserInDepartment)
organizationGroup.POST("/delete_organization_user", organization.DeleteOrganizationUser)
organizationGroup.POST("/get_department_member", organization.GetDepartmentMember)
}
go apiThird.MinioInit()
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
flag.Parse()

@ -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(&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{}
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())
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(&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{}
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())
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(&params); 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, &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())
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(&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())
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(&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{}
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())
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(&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{}
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())
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(&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{}
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())
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(&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())
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(&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{}
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())
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(&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())
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(&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())
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)
}

@ -3,10 +3,15 @@ package organization
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
rpc "Open_IM/pkg/proto/organization"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"time"
"context"
"google.golang.org/grpc"
@ -64,5 +69,70 @@ func (s *organizationServer) Run() {
}
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.IsMangerUserID(req.OpUserID) {
errMsg := "is not app manger " + req.OpUserID + " " + req.OperationID
log.Error(req.OperationID, errMsg)
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
department := db.Department{}
utils.CopyStructFields(&department, req.DepartmentInfo)
if department.DepartmentID == "" {
department.DepartmentID = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
}
if imdb.CreateDepartment(&department) != nil {
}
err, createdDepartment := imdb.GetDepartment(department.DepartmentID)
if err != nil {
}
resp := &rpc.CreateDepartmentResp{DepartmentInfo: &open_im_sdk.Department{}}
utils.CopyStructFields(resp.DepartmentInfo, createdDepartment)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", resp)
return resp, nil
}
func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.UpdateDepartmentReq) (*rpc.UpdateDepartmentResp, error) {
return nil, nil
}
func (s *organizationServer) GetDepartment(ctx context.Context, req *rpc.GetDepartmentReq) (*rpc.GetDepartmentResp, error) {
return nil, nil
}
func (s *organizationServer) DeleteDepartment(ctx context.Context, req *rpc.DeleteDepartmentReq) (*rpc.DeleteDepartmentResp, error) {
return nil, nil
}
func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rpc.CreateOrganizationUserReq) (*rpc.CreateOrganizationUserResp, error) {
return nil, nil
}
func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rpc.UpdateOrganizationUserReq) (*rpc.UpdateOrganizationUserResp, error) {
return nil, nil
}
func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rpc.CreateDepartmentMemberReq) (*rpc.CreateDepartmentMemberResp, error) {
return nil, nil
}
func (s *organizationServer) GetUserInDepartment(ctx context.Context, req *rpc.GetUserInDepartmentReq) (*rpc.GetUserInDepartmentResp, error) {
return nil, nil
}
func (s *organizationServer) UpdateUserInDepartment(ctx context.Context, req *rpc.UpdateUserInDepartmentReq) (*rpc.UpdateUserInDepartmentResp, error) {
return nil, nil
}
func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rpc.DeleteOrganizationUserReq) (*rpc.DeleteOrganizationUserResp, error) {
return nil, nil
}
func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
return nil, nil
}

@ -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"`
}

@ -257,13 +257,14 @@ func (OrganizationUser) TableName() string {
}
type DepartmentMember struct {
UserID string `gorm:"column:user_id;primary_key;size:64"`
DepartmentID string `gorm:"column:department_id;primary_key;size:64"`
Order int32 `gorm:"column:order" json:"order"`
Position string `gorm:"column:position;size:256" json:"position"`
Leader int32 `gorm:"column:leader" json:"leader"`
Status int32 `gorm:"column:status" json:"status"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
UserID string `gorm:"column:user_id;primary_key;size:64"`
DepartmentID string `gorm:"column:department_id;primary_key;size:64"`
Order int32 `gorm:"column:order" json:"order"`
Position string `gorm:"column:position;size:256" json:"position"`
Leader int32 `gorm:"column:leader" json:"leader"`
Status int32 `gorm:"column:status" json:"status"`
CreateTime time.Time `gorm:"column:create_time"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
}
func (DepartmentMember) TableName() string {

@ -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
}

@ -138,6 +138,14 @@ func GetUserIDFromToken(token string, operationID string) (bool, string) {
return true, claims.UID
}
func ParseTokenGetUserID(token string, operationID string) (error, string) {
claims, err := ParseToken(token, operationID)
if err != nil {
return utils.Wrap(err, ""), ""
}
return nil, claims.UID
}
func ParseToken(tokensString, operationID string) (claims *Claims, err error) {
claims, err = GetClaimFromToken(tokensString)
if err != nil {

@ -114,12 +114,12 @@ message UpdateUserInDepartmentResp{
}
message DeleteOrganizationReq{
message DeleteOrganizationUserReq{
string userID = 1;
string operationID = 2;
string opUserID = 3;
}
message DeleteOrganizationResp{
message DeleteOrganizationUserResp{
int32 errCode = 1;
string errMsg = 2;
}
@ -139,7 +139,7 @@ message GetDepartmentMemberResp{
service organization{
rpc createDepartment(CreateDepartmentReq) returns(CreateDepartmentResp);
rpc CreateDepartment(CreateDepartmentReq) returns(CreateDepartmentResp);
rpc UpdateDepartment(UpdateDepartmentReq) returns(UpdateDepartmentResp);
rpc GetDepartment(GetDepartmentReq) returns(GetDepartmentResp);
rpc DeleteDepartment(DeleteDepartmentReq) returns(DeleteDepartmentResp);
@ -148,7 +148,7 @@ service organization{
rpc CreateDepartmentMember(CreateDepartmentMemberReq) returns(CreateDepartmentMemberResp);
rpc GetUserInDepartment(GetUserInDepartmentReq) returns(GetUserInDepartmentResp);
rpc UpdateUserInDepartment(UpdateUserInDepartmentReq) returns(UpdateUserInDepartmentResp);
rpc DeleteOrganization(DeleteOrganizationReq) returns(DeleteOrganizationResp);
rpc DeleteOrganizationUser(DeleteOrganizationUserReq) returns(DeleteOrganizationUserResp);
rpc GetDepartmentMember(GetDepartmentMemberReq) returns(GetDepartmentMemberResp);
}

Loading…
Cancel
Save