group.go 27.9 KB
Newer Older
落凡尘.'s avatar
落凡尘. 已提交
1 2 3
package group

import (
4 5
	"Open_IM/pkg/common/config"
	"Open_IM/pkg/common/log"
W
wenxu12345 已提交
6
	"Open_IM/pkg/common/token_verify"
7
	"Open_IM/pkg/grpc-etcdv3/getcdv3"
programor_guo's avatar
programor_guo 已提交
8
	pb "Open_IM/pkg/proto/group"
落凡尘.'s avatar
落凡尘. 已提交
9 10 11 12 13 14 15 16
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

type InviteUserToGroupReq struct {
programor_guo's avatar
programor_guo 已提交
17
	GroupID     string   `json:"groupID" binding:"required"`
落凡尘.'s avatar
落凡尘. 已提交
18 19 20 21 22 23 24 25 26 27
	UidList     []string `json:"uidList" binding:"required"`
	Reason      string   `json:"reason"`
	OperationID string   `json:"operationID" binding:"required"`
}

type GetJoinedGroupListReq struct {
	OperationID string `json:"operationID" binding:"required"`
}

type KickGroupMemberReq struct {
落凡尘.'s avatar
落凡尘. 已提交
28 29 30 31
	GroupID     string                    `json:"groupID"`
	UidListInfo []*pb.GroupMemberFullInfo `json:"uidListInfo" binding:"required"`
	Reason      string                    `json:"reason"`
	OperationID string                    `json:"operationID" binding:"required"`
落凡尘.'s avatar
落凡尘. 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45
}

func KickGroupMember(c *gin.Context) {

	params := KickGroupMemberReq{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}

	req := &pb.KickGroupMemberReq{
		OperationID: params.OperationID,
		GroupID:     params.GroupID,
		Token:       c.Request.Header.Get("token"),
programor_guo's avatar
programor_guo 已提交
46

落凡尘.'s avatar
落凡尘. 已提交
47
		UidListInfo: params.UidListInfo,
落凡尘.'s avatar
落凡尘. 已提交
48 49
	}
	log.Info(req.Token, req.OperationID, "recv req: ", req.String())
W
wenxu12345 已提交
50 51
	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)
落凡尘.'s avatar
落凡尘. 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
	RpcResp, err := client.KickGroupMember(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "GetGroupMemberList failed, err: ", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}

	type KickGroupMemberResp struct {
		ErrorCode int32       `json:"errCode"`
		ErrorMsg  string      `json:"errMsg"`
		Data      []Id2Result `json:"data"`
	}

	var memberListResp KickGroupMemberResp
	memberListResp.ErrorMsg = RpcResp.ErrorMsg
	memberListResp.ErrorCode = RpcResp.ErrorCode
	for _, v := range RpcResp.Id2Result {
		memberListResp.Data = append(memberListResp.Data,
			Id2Result{UId: v.UId,
				Result: v.Result})
	}
	c.JSON(http.StatusOK, memberListResp)
}

type GetGroupMembersInfoReq struct {
	GroupID     string   `json:"groupID"`
	MemberList  []string `json:"memberList"`
	OperationID string   `json:"operationID"`
}
type GetGroupMembersInfoResp struct {
	ErrorCode int32          `json:"errCode"`
	ErrorMsg  string         `json:"errMsg"`
	Data      []MemberResult `json:"data"`
}

func GetGroupMembersInfo(c *gin.Context) {
	log.Info("", "", "GetGroupMembersInfo start....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)

	params := GetGroupMembersInfoReq{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}

	req := &pb.GetGroupMembersInfoReq{
		OperationID: params.OperationID,
		GroupID:     params.GroupID,
		MemberList:  params.MemberList,
		Token:       c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "recv req: ", len(params.MemberList))

	RpcResp, err := client.GetGroupMembersInfo(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "GetGroupMemberList failed, err: ", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}

	var memberListResp GetGroupMembersInfoResp
	memberListResp.ErrorMsg = RpcResp.ErrorMsg
	memberListResp.ErrorCode = RpcResp.ErrorCode
	for _, v := range RpcResp.MemberList {
		memberListResp.Data = append(memberListResp.Data,
			MemberResult{GroupId: req.GroupID,
				UserId:   v.UserId,
				Role:     v.Role,
				JoinTime: uint64(v.JoinTime),
				Nickname: v.NickName,
				FaceUrl:  v.FaceUrl})
	}
	c.JSON(http.StatusOK, memberListResp)
}

type GetGroupMemberListReq struct {
	GroupID     string `json:"groupID"`
	Filter      int32  `json:"filter"`
	NextSeq     int32  `json:"nextSeq"`
	OperationID string `json:"operationID"`
}
落凡尘.'s avatar
落凡尘. 已提交
135 136 137 138
type getGroupAllMemberReq struct {
	GroupID     string `json:"groupID"`
	OperationID string `json:"operationID"`
}
落凡尘.'s avatar
落凡尘. 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

type MemberResult struct {
	GroupId  string `json:"groupID"`
	UserId   string `json:"userId"`
	Role     int32  `json:"role"`
	JoinTime uint64 `json:"joinTime"`
	Nickname string `json:"nickName"`
	FaceUrl  string `json:"faceUrl"`
}

func GetGroupMemberList(c *gin.Context) {
	log.Info("", "", "GetGroupMemberList start....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)

	params := GetGroupMemberListReq{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.GetGroupMemberListReq{
		OperationID: params.OperationID,
		Filter:      params.Filter,
		NextSeq:     params.NextSeq,
		GroupID:     params.GroupID,
		Token:       c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "recv req: ", req.String())
	RpcResp, err := client.GetGroupMemberList(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "GetGroupMemberList failed, err: ", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}

	type GetGroupMemberListResp struct {
		ErrorCode int32          `json:"errCode"`
		ErrorMsg  string         `json:"errMsg"`
		NextSeq   int32          `json:"nextSeq"`
		Data      []MemberResult `json:"data"`
	}

	var memberListResp GetGroupMemberListResp
	memberListResp.ErrorMsg = RpcResp.ErrorMsg
	memberListResp.ErrorCode = RpcResp.ErrorCode
	memberListResp.NextSeq = RpcResp.NextSeq
	for _, v := range RpcResp.MemberList {
		memberListResp.Data = append(memberListResp.Data,
			MemberResult{GroupId: req.GroupID,
				UserId:   v.UserId,
				Role:     v.Role,
				JoinTime: uint64(v.JoinTime),
				Nickname: v.NickName,
				FaceUrl:  v.FaceUrl})
	}
	c.JSON(http.StatusOK, memberListResp)

}

落凡尘.'s avatar
落凡尘. 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
func GetGroupAllMember(c *gin.Context) {
	log.Info("", "", "GetGroupAllMember start....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)

	params := getGroupAllMemberReq{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.GetGroupAllMemberReq{
		GroupID:     params.GroupID,
		OperationID: params.OperationID,
		Token:       c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "recv req: ", req.String())
	RpcResp, err := client.GetGroupAllMember(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "GetGroupAllMember failed, err: ", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}

	type GetGroupMemberListResp struct {
		ErrorCode int32          `json:"errCode"`
		ErrorMsg  string         `json:"errMsg"`
		Data      []MemberResult `json:"data"`
	}

	var memberListResp GetGroupMemberListResp
	memberListResp.ErrorMsg = RpcResp.ErrorMsg
	memberListResp.ErrorCode = RpcResp.ErrorCode
	for _, v := range RpcResp.MemberList {
		memberListResp.Data = append(memberListResp.Data,
			MemberResult{GroupId: req.GroupID,
				UserId:   v.UserId,
				Role:     v.Role,
				JoinTime: uint64(v.JoinTime),
				Nickname: v.NickName,
				FaceUrl:  v.FaceUrl})
	}
	c.JSON(http.StatusOK, memberListResp)
}

落凡尘.'s avatar
落凡尘. 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
type groupResult struct {
	GroupId      string `json:"groupId"`
	GroupName    string `json:"groupName"`
	Notification string `json:"notification"`
	Introduction string `json:"introduction"`
	FaceUrl      string `json:"faceUrl"`
	OwnerId      string `json:"ownerId"`
	CreateTime   uint64 `json:"createTime"`
	MemberCount  uint32 `json:"memberCount"`
}

func GetJoinedGroupList(c *gin.Context) {
	log.Info("", "", "GetJoinedGroupList start....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	fmt.Println("config:    ", etcdConn, config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)

	params := GetJoinedGroupListReq{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.GetJoinedGroupListReq{
		OperationID: params.OperationID,
		Token:       c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "recv req: ", req.String())

	RpcResp, err := client.GetJoinedGroupList(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "GetJoinedGroupList failed, err: ", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}
落凡尘.'s avatar
落凡尘. 已提交
279
	log.Info(req.Token, req.OperationID, "GetJoinedGroupList: ", RpcResp)
落凡尘.'s avatar
落凡尘. 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349

	type GetJoinedGroupListResp struct {
		ErrorCode int32         `json:"errCode"`
		ErrorMsg  string        `json:"errMsg"`
		Data      []groupResult `json:"data"`
	}

	var GroupListResp GetJoinedGroupListResp
	GroupListResp.ErrorCode = RpcResp.ErrorCode
	GroupListResp.ErrorMsg = RpcResp.ErrorMsg
	for _, v := range RpcResp.GroupList {
		GroupListResp.Data = append(GroupListResp.Data,
			groupResult{GroupId: v.GroupId, GroupName: v.GroupName,
				Notification: v.Notification,
				Introduction: v.Introduction,
				FaceUrl:      v.FaceUrl,
				OwnerId:      v.OwnerId,
				CreateTime:   v.CreateTime,
				MemberCount:  v.MemberCount})
	}
	c.JSON(http.StatusOK, GroupListResp)
}

type Id2Result struct {
	UId    string `json:"uid"`
	Result int32  `json:"result"`
}

func InviteUserToGroup(c *gin.Context) {
	log.Info("", "", "InviteUserToGroup start....")
	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)

	params := InviteUserToGroupReq{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.InviteUserToGroupReq{
		OperationID: params.OperationID,
		GroupID:     params.GroupID,
		Reason:      params.Reason,
		UidList:     params.UidList,
		Token:       c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "recv req: ", req.String())

	RpcResp, err := client.InviteUserToGroup(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "InviteUserToGroup failed, err: ", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}

	type InviteUserToGroupResp struct {
		ErrorCode int32       `json:"errCode"`
		ErrorMsg  string      `json:"errMsg"`
		I2R       []Id2Result `json:"data"`
	}

	var iResp InviteUserToGroupResp
	iResp.ErrorMsg = RpcResp.ErrorMsg
	iResp.ErrorCode = RpcResp.ErrorCode
	for _, v := range RpcResp.Id2Result {
		iResp.I2R = append(iResp.I2R, Id2Result{UId: v.UId, Result: v.Result})
	}

	//resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": RpcResp.Id2Result}
	c.JSON(http.StatusOK, iResp)
}
W
wenxu12345 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791

type paramsCreateGroupStruct struct {
	MemberList   []*pb.GroupAddMemberInfo `json:"memberList"`
	GroupName    string                   `json:"groupName"`
	Introduction string                   `json:"introduction"`
	Notification string                   `json:"notification"`
	FaceUrl      string                   `json:"faceUrl"`
	OperationID  string                   `json:"operationID" binding:"required"`
	Ex           string                   `json:"ex"`
}

func CreateGroup(c *gin.Context) {
	log.Info("", "", "api create group init ....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsCreateGroupStruct{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.CreateGroupReq{
		MemberList:   params.MemberList,
		GroupName:    params.GroupName,
		Introduction: params.Introduction,
		Notification: params.Notification,
		FaceUrl:      params.FaceUrl,
		OperationID:  params.OperationID,
		Ex:           params.Ex,
		Token:        c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "api create group is server,params=%s", req.String())
	RpcResp, err := client.CreateGroup(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "err=%s,call create group  rpc server failed", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call  rpc server failed"})
		return
	}
	log.InfoByArgs("call create group  rpc server success,args=%s", RpcResp.String())
	if RpcResp.ErrorCode == 0 {
		resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": gin.H{"groupID": RpcResp.GroupID}}
		c.JSON(http.StatusOK, resp)
	} else {
		c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
	}
	log.InfoByArgs("api create group success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}

type paramsGroupApplicationList struct {
	OperationID string `json:"operationID" binding:"required"`
}

func newUserRegisterReq(params *paramsGroupApplicationList) *group.GetGroupApplicationListReq {
	pbData := group.GetGroupApplicationListReq{
		OperationID: params.OperationID,
	}
	return &pbData
}

type paramsGroupApplicationListRet struct {
	ID               string `json:"id"`
	GroupID          string `json:"groupID"`
	FromUserID       string `json:"fromUserID"`
	ToUserID         string `json:"toUserID"`
	Flag             int32  `json:"flag"`
	RequestMsg       string `json:"reqMsg"`
	HandledMsg       string `json:"handledMsg"`
	AddTime          int64  `json:"createTime"`
	FromUserNickname string `json:"fromUserNickName"`
	ToUserNickname   string `json:"toUserNickName"`
	FromUserFaceUrl  string `json:"fromUserFaceURL"`
	ToUserFaceUrl    string `json:"toUserFaceURL"`
	HandledUser      string `json:"handledUser"`
	Type             int32  `json:"type"`
	HandleStatus     int32  `json:"handleStatus"`
	HandleResult     int32  `json:"handleResult"`
}

func GetGroupApplicationList(c *gin.Context) {
	log.Info("", "", "api GetGroupApplicationList init ....")
	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := group.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsGroupApplicationList{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	pbData := newUserRegisterReq(&params)

	token := c.Request.Header.Get("token")
	if claims, err := token_verify.ParseToken(token); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
		return
	} else {
		pbData.UID = claims.UID
	}

	log.Info("", "", "api GetGroupApplicationList is server, [data: %s]", pbData.String())
	reply, err := client.GetGroupApplicationList(context.Background(), pbData)
	if err != nil {
		log.Error("", "", "api GetGroupApplicationList call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}
	log.Info("", "", "api GetGroupApplicationList call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())

	unProcessCount := 0
	userReq := make([]paramsGroupApplicationListRet, 0)
	if reply != nil && reply.Data != nil && reply.Data.User != nil {
		for i := 0; i < len(reply.Data.User); i++ {
			req := paramsGroupApplicationListRet{}
			req.ID = reply.Data.User[i].ID
			req.GroupID = reply.Data.User[i].GroupID
			req.FromUserID = reply.Data.User[i].FromUserID
			req.ToUserID = reply.Data.User[i].ToUserID
			req.Flag = reply.Data.User[i].Flag
			req.RequestMsg = reply.Data.User[i].RequestMsg
			req.HandledMsg = reply.Data.User[i].HandledMsg
			req.AddTime = reply.Data.User[i].AddTime
			req.FromUserNickname = reply.Data.User[i].FromUserNickname
			req.ToUserNickname = reply.Data.User[i].ToUserNickname
			req.FromUserFaceUrl = reply.Data.User[i].FromUserFaceUrl
			req.ToUserFaceUrl = reply.Data.User[i].ToUserFaceUrl
			req.HandledUser = reply.Data.User[i].HandledUser
			req.Type = reply.Data.User[i].Type
			req.HandleStatus = reply.Data.User[i].HandleStatus
			req.HandleResult = reply.Data.User[i].HandleResult
			userReq = append(userReq, req)

			if req.Flag == 0 {
				unProcessCount++
			}
		}
	}

	c.JSON(http.StatusOK, gin.H{
		"errCode": reply.ErrCode,
		"errMsg":  reply.ErrMsg,
		"data": gin.H{
			"count": unProcessCount,
			"user":  userReq,
		},
	})

}

type paramsGetGroupInfo struct {
	GroupIDList []string `json:"groupIDList" binding:"required"`
	OperationID string   `json:"operationID" binding:"required"`
}

func GetGroupsInfo(c *gin.Context) {
	log.Info("", "", "api get groups info init ....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsGetGroupInfo{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.GetGroupsInfoReq{
		GroupIDList: params.GroupIDList,
		Token:       c.Request.Header.Get("token"),
		OperationID: params.OperationID,
	}
	log.Info(req.Token, req.OperationID, "get groups info is server,params=%s", req.String())
	RpcResp, err := client.GetGroupsInfo(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "call get groups info rpc server failed,err=%s", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call  rpc server failed"})
		return
	}
	log.InfoByArgs("call get groups info rpc server success", RpcResp.String())
	if RpcResp.ErrorCode == 0 {
		groupsInfo := make([]pb.GroupInfo, 0)
		for _, v := range RpcResp.Data {
			var groupInfo pb.GroupInfo
			groupInfo.GroupId = v.GroupId
			groupInfo.GroupName = v.GroupName
			groupInfo.Notification = v.Notification
			groupInfo.Introduction = v.Introduction
			groupInfo.FaceUrl = v.FaceUrl
			groupInfo.CreateTime = v.CreateTime
			groupInfo.OwnerId = v.OwnerId
			groupInfo.MemberCount = v.MemberCount

			groupsInfo = append(groupsInfo, groupInfo)
		}
		c.JSON(http.StatusOK, gin.H{
			"errCode": RpcResp.ErrorCode,
			"errMsg":  RpcResp.ErrorMsg,
			"data":    groupsInfo,
		})
	} else {
		c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
	}
}

type paramsGroupApplicationResponse struct {
	OperationID      string `json:"operationID" binding:"required"`
	GroupID          string `json:"groupID" binding:"required"`
	FromUserID       string `json:"fromUserID" binding:"required"`
	FromUserNickName string `json:"fromUserNickName"`
	FromUserFaceUrl  string `json:"fromUserFaceUrl"`
	ToUserID         string `json:"toUserID" binding:"required"`
	ToUserNickName   string `json:"toUserNickName"`
	ToUserFaceUrl    string `json:"toUserFaceUrl"`
	AddTime          int64  `json:"addTime"`
	RequestMsg       string `json:"requestMsg"`
	HandledMsg       string `json:"handledMsg"`
	Type             int32  `json:"type"`
	HandleStatus     int32  `json:"handleStatus"`
	HandleResult     int32  `json:"handleResult"`

	UserID string `json:"userID"`
}

func newGroupApplicationResponse(params *paramsGroupApplicationResponse) *group.GroupApplicationResponseReq {
	pbData := group.GroupApplicationResponseReq{
		OperationID:      params.OperationID,
		GroupID:          params.GroupID,
		FromUserID:       params.FromUserID,
		FromUserNickName: params.FromUserNickName,
		FromUserFaceUrl:  params.FromUserFaceUrl,
		ToUserID:         params.ToUserID,
		ToUserNickName:   params.ToUserNickName,
		ToUserFaceUrl:    params.ToUserFaceUrl,
		AddTime:          params.AddTime,
		RequestMsg:       params.RequestMsg,
		HandledMsg:       params.HandledMsg,
		Type:             params.Type,
		HandleStatus:     params.HandleStatus,
		HandleResult:     params.HandleResult,
	}
	return &pbData
}

func ApplicationGroupResponse(c *gin.Context) {
	log.Info("", "", "api GroupApplicationResponse init ....")
	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := group.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsGroupApplicationResponse{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	pbData := newGroupApplicationResponse(&params)

	token := c.Request.Header.Get("token")
	if claims, err := token_verify.ParseToken(token); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
		return
	} else {
		pbData.OwnerID = claims.UID
	}

	log.Info("", "", "api GroupApplicationResponse is server, [data: %s]", pbData.String())
	reply, err := client.GroupApplicationResponse(context.Background(), pbData)
	if err != nil {
		log.Error("", "", "api GroupApplicationResponse call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}
	log.Info("", "", "api GroupApplicationResponse call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())

	c.JSON(http.StatusOK, gin.H{
		"errCode": reply.ErrCode,
		"errMsg":  reply.ErrMsg,
	})

}

type paramsJoinGroup struct {
	GroupID     string `json:"groupID" binding:"required"`
	Message     string `json:"message"`
	OperationID string `json:"operationID" binding:"required"`
}

func JoinGroup(c *gin.Context) {
	log.Info("", "", "api join group init....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsJoinGroup{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.JoinGroupReq{
		GroupID:     params.GroupID,
		Message:     params.Message,
		Token:       c.Request.Header.Get("token"),
		OperationID: params.OperationID,
	}
	log.Info(req.Token, req.OperationID, "api join group is server,params=%s", req.String())
	RpcResp, err := client.JoinGroup(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "call join group  rpc server failed,err=%s", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call  rpc server failed"})
		return
	}
	log.InfoByArgs("call join group rpc server success,args=%s", RpcResp.String())
	c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
}

type paramsQuitGroup struct {
	GroupID     string `json:"groupID" binding:"required"`
	OperationID string `json:"operationID" binding:"required"`
}

func QuitGroup(c *gin.Context) {
	log.Info("", "", "api quit group init ....")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsQuitGroup{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.QuitGroupReq{
		GroupID:     params.GroupID,
		OperationID: params.OperationID,
		Token:       c.Request.Header.Get("token"),
	}
	log.Info(req.Token, req.OperationID, "api quit group is server,params=%s", req.String())
	RpcResp, err := client.QuitGroup(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "call quit group rpc server failed,err=%s", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call  rpc server failed"})
		return
	}
	log.InfoByArgs("call quit group rpc server success,args=%s", RpcResp.String())
	c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
	log.InfoByArgs("api quit group success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}

type paramsSetGroupInfo struct {
	GroupID      string `json:"groupId"  binding:"required"`
	GroupName    string `json:"groupName"`
	Notification string `json:"notification"`
	Introduction string `json:"introduction"`
	FaceUrl      string `json:"faceUrl"`
	OperationID  string `json:"operationID"  binding:"required"`
}

func SetGroupInfo(c *gin.Context) {
	log.Info("", "", "api set group info init...")

	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := pb.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsSetGroupInfo{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	req := &pb.SetGroupInfoReq{
		GroupID:      params.GroupID,
		GroupName:    params.GroupName,
		Notification: params.Notification,
		Introduction: params.Introduction,
		FaceUrl:      params.FaceUrl,
		Token:        c.Request.Header.Get("token"),
		OperationID:  params.OperationID,
	}
	log.Info(req.Token, req.OperationID, "api set group info is server,params=%s", req.String())
	RpcResp, err := client.SetGroupInfo(context.Background(), req)
	if err != nil {
		log.Error(req.Token, req.OperationID, "call set group info rpc server failed,err=%s", err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call  rpc server failed"})
		return
	}
	log.InfoByArgs("call set group info rpc server success,args=%s", RpcResp.String())
	c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
}

type paramsTransferGroupOwner struct {
	OperationID string `json:"operationID" binding:"required"`
	GroupID     string `json:"groupID" binding:"required"`
	UID         string `json:"uid" binding:"required"`
}

func newTransferGroupOwnerReq(params *paramsTransferGroupOwner) *group.TransferGroupOwnerReq {
	pbData := group.TransferGroupOwnerReq{
		OperationID: params.OperationID,
		GroupID:     params.GroupID,
		NewOwner:    params.UID,
	}
	return &pbData
}

func TransferGroupOwner(c *gin.Context) {
	log.Info("", "", "api TransferGroupOwner init ....")
	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
	client := group.NewGroupClient(etcdConn)
	//defer etcdConn.Close()

	params := paramsTransferGroupOwner{}
	if err := c.BindJSON(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
		return
	}
	pbData := newTransferGroupOwnerReq(&params)

	token := c.Request.Header.Get("token")
	if claims, err := token_verify.ParseToken(token); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
		return
	} else {
		pbData.OldOwner = claims.UID
	}

	log.Info("", "", "api TransferGroupOwner is server, [data: %s]", pbData.String())
	reply, err := client.TransferGroupOwner(context.Background(), pbData)
	if err != nil {
		log.Error("", "", "api TransferGroupOwner call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
		return
	}
	log.Info("", "", "api TransferGroupOwner call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())

	c.JSON(http.StatusOK, gin.H{
		"errCode": reply.ErrCode,
		"errMsg":  reply.ErrMsg,
	})

}