Commit fb9b837d by Li Feifei

develop

parent 21ffb012
......@@ -57,7 +57,7 @@ func newMysqlClient() {
}
orm.RegisterModel(new(CompanyApp), new(ImBase), new(ImChatRoom), new(ImUserRelationship), new(ImUser))
orm.Debug = true
MysqlClient = orm.NewOrm()
log.Println("MySQL connect success")
}
......@@ -8,10 +8,11 @@ require (
github.com/go-redis/redis/v8 v8.0.0-beta.5
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.1
github.com/grpc-ecosystem/grpc-health-probe v0.3.2 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/rs/xid v1.2.1
github.com/segmentio/ksuid v1.0.2
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
golang.org/x/net v0.0.0-20191021144547-ec77196f6094
google.golang.org/grpc v1.30.0
google.golang.org/protobuf v1.24.0
gopkg.in/go-playground/validator.v9 v9.31.0
......
......@@ -64,7 +64,10 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/grpc-ecosystem/grpc-health-probe v0.3.2 h1:daShAySXI1DnGc8U9B1E4Qm6o7qzmFR4aRIJ4vY/TUo=
github.com/grpc-ecosystem/grpc-health-probe v0.3.2/go.mod h1:izVOQ4RWbjUR6lm4nn+VLJyQ+FyaiGmprEYgI04Gs7U=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
......@@ -112,6 +115,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191021144547-ec77196f6094 h1:5O4U9trLjNpuhpynaDsqwCk+Tw6seqJz1EbqbnzHrc8=
golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
......@@ -121,6 +126,7 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191020212454-3e7259c5e7c2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
......@@ -143,6 +149,7 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaR
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
......
......@@ -5,7 +5,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"im-microservice/sevice/im_user"
"log"
"net"
"regexp"
......@@ -15,12 +15,15 @@ import (
"im-microservice/helper"
"im-microservice/pb"
"im-microservice/sevice/im_chat_room"
"im-microservice/sevice/im_user"
iur "im-microservice/sevice/im_user_relationship"
ic "im-microservice/sevice/im_configure"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
)
const (
......@@ -103,13 +106,14 @@ func main() {
log.Fatalf("failed to listen: %v", err)
}
//var opts []grpc.ServerOption
//opts = append(opts, grpc.UnaryInterceptor(auth))
//s := grpc.NewServer(opts...)
s := grpc.NewServer()
var opts []grpc.ServerOption
opts = append(opts, grpc.UnaryInterceptor(auth))
s := grpc.NewServer(opts...)
// s := grpc.NewServer()
pb.RegisterConfigureSeviceServer(s, &ic.ConfigureSevice{})
pb.RegisterChatRoomServiceServer(s, &im_chat_room.ImChatRoomService{})
pb.RegisterImUserServer(s, &im_user.ImUserServer{})
pb.RegisterUserRelationshipServiceServer(s, &iur.UserRelationshipService{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
......
......@@ -2,9 +2,9 @@ package im_chat_room
import (
"errors"
"im-microservice/helper"
"im-microservice/db"
"im-microservice/helper"
"im-microservice/pb"
"im-microservice/validator_struct"
......@@ -21,20 +21,20 @@ const (
chat_create_time = "createtime"
)
func AddChatRoom (addStruct *validator_struct.ChatRoomAddStruct) (int64, error) {
func AddChatRoom(addStruct *validator_struct.ChatRoomAddStruct) (int64, error) {
var chat db.ImChatRoom
now := helper.GetNowTime()
chat.Name = addStruct.Name
chat.Announcement = addStruct.Announcement
chat.Creator = addStruct.Creator
chat.Status = 1;
chat.Status = 1
chat.Createtime = now
chat.Updatetime = now
room_id, err := db.MysqlClient.Insert(&chat)
return room_id, err
}
func UpdateChatRoom( update *validator_struct.ChatRoomUpdate) error {
func UpdateChatRoom(update *validator_struct.ChatRoomUpdate) error {
orm_params := make(orm.Params)
if update.Status != 0 {
orm_params[chat_status] = update.Status
......@@ -50,13 +50,15 @@ func UpdateChatRoom( update *validator_struct.ChatRoomUpdate) error {
return errors.New("修改房间的参数为空")
}
orm_params["updatetime"] = helper.GetNowTime()
_, err := db.MysqlClient.QueryTable(chat_table_name).Filter(chat_room_id, update.RoomId).Update(orm_params)
_, err := db.MysqlClient.QueryTable(chat_table_name).
Filter(chat_room_id, update.RoomId).Update(orm_params)
return err
}
func DeleteChatRoom(room_id int64) error {
_, err := db.MysqlClient.QueryTable(chat_table_name).Filter(chat_room_id, room_id).Delete()
_, err := db.MysqlClient.QueryTable(chat_table_name).
Filter(chat_room_id, room_id).Delete()
return err
}
......@@ -75,14 +77,14 @@ func GetChatRooms(request *pb.ChatRoomAllRequest) (results map[string]interface{
page = request.GetPage()
)
if page == 0 {
page = 1;
page = 1
}
count_db := db.MysqlClient.QueryTable(chat_table_name)
if announcement != "" {
count_db = count_db.Filter(chat_announcement + "__icontains", announcement)
count_db = count_db.Filter(chat_announcement+"__icontains", announcement)
}
if name != "" {
count_db = count_db.Filter(chat_room + "__icontains", name)
count_db = count_db.Filter(chat_room+"__icontains", name)
}
if status != 0 {
count_db = count_db.Filter(chat_status, status)
......@@ -91,14 +93,13 @@ func GetChatRooms(request *pb.ChatRoomAllRequest) (results map[string]interface{
count_db = count_db.Filter(chat_creator, creator)
}
if createtime != "" {
count_db = count_db.Filter(chat_create_time + "__age__gte", createtime)
count_db = count_db.Filter(chat_create_time+"__gte", createtime)
}
ctn, err := count_db.Count()
if err != nil {
return
}
if ctn == 0 {
err = errors.New("没有查询到任何数据")
return
}
// 获取查询条件聊天室的总数
......
......@@ -13,13 +13,14 @@ type ImChatRoomService struct {
pb.UnimplementedChatRoomServiceServer
}
func (cr *ImChatRoomService) Add(ctx context.Context, in *pb.ChatRoomAddRequest) (reply *pb.ChatRoomAddReply, err error) {
func (cr *ImChatRoomService) Add(ctx context.Context,
in *pb.ChatRoomAddRequest) (reply *pb.ChatRoomAddReply, err error) {
chat_room_struct := vs.NewAddChatRoom(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
room_id, err := helper.AddChatRoom(chat_room_struct)
room_id, err := AddChatRoom(chat_room_struct)
if err != nil {
return
}
......@@ -28,41 +29,43 @@ func (cr *ImChatRoomService) Add(ctx context.Context, in *pb.ChatRoomAddRequest)
return
}
func (cr *ImChatRoomService) Update(ctx context.Context, in *pb.ChatRoomUpdateRequest) (reply *pb.ChatRoomUpdateReply, err error) {
func (cr *ImChatRoomService) Update(ctx context.Context,
in *pb.ChatRoomUpdateRequest) (reply *pb.ChatRoomUpdateReply, err error) {
chat_room_struct := vs.NewChatRoomUpdate(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
if err = helper.UpdateChatRoom(chat_room_struct); err != nil {
if err = UpdateChatRoom(chat_room_struct); err != nil {
return
}
reply = &pb.ChatRoomUpdateReply{}
return
}
func (cr *ImChatRoomService) Delete(ctx context.Context, in *pb.ChatRoomDelRequest) (reply *pb.ChatRoomDelReply, err error) {
func (cr *ImChatRoomService) Delete(ctx context.Context,
in *pb.ChatRoomDelRequest) (reply *pb.ChatRoomDelReply, err error) {
chat_room_struct := vs.NewChatRoomDel(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
if err = helper.DeleteChatRoom(chat_room_struct.RoomId); err != nil {
if err = DeleteChatRoom(chat_room_struct.RoomId); err != nil {
return
}
reply = &pb.ChatRoomDelReply{}
return
}
func (cr *ImChatRoomService) Info(ctx context.Context, in *pb.ChatRoomInfoRequest) (reply *pb.ChatRoomInfoReply, err error) {
func (cr *ImChatRoomService) Info(ctx context.Context,
in *pb.ChatRoomInfoRequest) (reply *pb.ChatRoomInfoReply, err error) {
chat_room_struct := vs.NewChatRoomInfo(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
db_chat_room, err := helper.ChatRoomInfo(chat_room_struct)
db_chat_room, err := ChatRoomInfo(chat_room_struct)
if err != nil {
return
}
......@@ -82,13 +85,16 @@ func getchatroom(room db.ImChatRoom) *pb.ChatRoomInfoReply {
}
}
func (cr *ImChatRoomService) All(ctx context.Context, in *pb.ChatRoomAllRequest) (reply *pb.GetChatRoomsReply, err error) {
results, err := helper.GetChatRooms(in)
func (cr *ImChatRoomService) All(ctx context.Context,
in *pb.ChatRoomAllRequest) (reply *pb.GetChatRoomsReply, err error) {
results, err := GetChatRooms(in)
if err != nil {
return
}
reply = &pb.GetChatRoomsReply{Paginate: &pb.Page{}}
if len(results) == 0 {
return
}
db_rooms := results["list"].([]db.ImChatRoom)
for _, v := range db_rooms {
reply.List = append(reply.List, getchatroom(v))
......
......@@ -16,7 +16,8 @@ const (
func GetImBaseByUserId(user_id int64) (db.ImBase, error) {
var im_base db.ImBase
err := db.MysqlClient.QueryTable(b_table_name).Filter(b_user_id, user_id).One(&im_base)
err := db.MysqlClient.QueryTable(b_table_name).
Filter(b_user_id, user_id).One(&im_base)
return im_base, err
}
......@@ -25,21 +26,24 @@ func AddImBase(im *validator_struct.ConfigureAddStruct) error {
configure.CompanyUserId = im.CompanyUserId
configure.MsgHookUrl = im.MsgHookUrl
configure.MultideviceType = im.MultideviceType
_, err := db.MysqlClient.Insert(configure);
_, err := db.MysqlClient.Insert(configure)
return err
}
func DelConfigure(user_id int64) error {
configure := new(db.ImBase)
configure.CompanyUserId = user_id
_, err := db.MysqlClient.Delete(configure);
_, err := db.MysqlClient.Delete(configure)
return err
}
func GetConfigureAll() []*db.ImBase {
func GetConfigureAll() ([]*db.ImBase, error) {
var configurs []*db.ImBase
_, _ = db.MysqlClient.QueryTable(b_table_name).All(&configurs)
return configurs
num, err := db.MysqlClient.QueryTable(b_table_name).All(&configurs)
if num == 0 {
return configurs, nil
}
return configurs, err
}
func UpdateConfiguer(im *validator_struct.ConfigureUpdateStruct) error {
......@@ -53,6 +57,7 @@ func UpdateConfiguer(im *validator_struct.ConfigureUpdateStruct) error {
if len(orm_params) == 0 {
return errors.New("没有数据更改")
}
_, err := db.MysqlClient.QueryTable(b_table_name).Filter(b_user_id, im.CompanyUserId).Update(orm_params)
_, err := db.MysqlClient.QueryTable(b_table_name).
Filter(b_user_id, im.CompanyUserId).Update(orm_params)
return err
}
......@@ -13,45 +13,52 @@ type ConfigureSevice struct {
pb.UnimplementedConfigureSeviceServer
}
func (cs *ConfigureSevice) Add(ctx context.Context, in *pb.ConfigureRequest) (reply *pb.ConfigureReply, err error) {
func (cs *ConfigureSevice) Add(ctx context.Context,
in *pb.ConfigureRequest) (reply *pb.ConfigureReply, err error) {
configure_add_struct := vs.NewConfigureAddStruct(in)
if err = helper.Valiator(configure_add_struct); err != nil {
return
}
// 已经添加过配置无需在添加
if _, err = helper.GetImBaseByUserId(configure_add_struct.CompanyUserId); err == nil {
if _, err = GetImBaseByUserId(configure_add_struct.CompanyUserId); err == nil {
err = errors.New("已经添加过配置,无需再添加")
return
}
// 添加配置
if err = helper.AddImBase(configure_add_struct); err != nil {
if err = AddImBase(configure_add_struct); err != nil {
return
}
reply = &pb.ConfigureReply{}
return
}
func (cs *ConfigureSevice) Delete(ctx context.Context, in *pb.ConfigureDelRequest) (reply *pb.ConfigureReply, err error) {
func (cs *ConfigureSevice) Delete(ctx context.Context,
in *pb.ConfigureDelRequest) (reply *pb.ConfigureReply, err error) {
cds := vs.NewConfigureDelStruct(in)
if err = helper.Valiator(cds); err != nil {
return
}
// 执行删除操作
if err = helper.DelConfigure(cds.CompanyUserId); err != nil {
if err = DelConfigure(cds.CompanyUserId); err != nil {
return
}
reply = &pb.ConfigureReply{}
return
}
func (cs *ConfigureSevice) Select(ctx context.Context, in *pb.GetAllRequest) (reply *pb.GetAllReply, err error) {
func (cs *ConfigureSevice) Select(ctx context.Context,
in *pb.GetAllRequest) (reply *pb.GetAllReply, err error) {
reply = &pb.GetAllReply{}
configs := helper.GetConfigureAll()
if len(configs) > 0 {
configs, err := GetConfigureAll()
if err != nil {
return
}
if len(configs) == 0 {
return
}
for _, v := range configs {
reply.GetAll = append(reply.GetAll, &pb.GetAllOneReply{
......@@ -62,18 +69,19 @@ func (cs *ConfigureSevice) Select(ctx context.Context, in *pb.GetAllRequest) (re
},
})
}
}
return
}
func (cs *ConfigureSevice) Update(ctx context.Context, in *pb.UpdateRequest) (reply *pb.ConfigureReply, err error) {
func (cs *ConfigureSevice) Update(ctx context.Context,
in *pb.UpdateRequest) (reply *pb.ConfigureReply, err error) {
configure_add_struct := vs.NewConfigureUpdateStruct(in)
if err = helper.Valiator(configure_add_struct); err != nil {
return
}
// 更新数据
if err = helper.UpdateConfiguer(configure_add_struct); err != nil {
if err = UpdateConfiguer(configure_add_struct); err != nil {
return
}
reply = &pb.ConfigureReply{}
......
package im_user_relationship
import (
"errors"
"github.com/astaxie/beego/orm"
"im-microservice/db"
"im-microservice/helper"
"im-microservice/validator_struct"
)
var (
db_tabel = "im_user_relationship"
db_field_accid = "accid"
db_field_faccid = "faccid"
db_field_type = "type"
db_field_msg = "msg"
db_field_blacklist = "blacklist"
db_field_mute = "mute"
db_field_serverex = "serverex"
db_field_updatetime = "updatetime"
db_field_createtime = "createtime"
open = 2
close = 1
)
// 是否是好友
func IsUserRelationship(accid, faccid string) bool {
return db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, accid).
Filter(db_field_faccid, faccid).Exist()
}
func AddUserRelationship(in *validator_struct.UserRelationshipAdd) error {
var us db.ImUserRelationship
now := helper.GetNowTime()
us.Accid = in.Accid
us.Faccid = in.Faccid
us.Msg = in.Msg
us.Type = int(in.Type)
us.Updatetime = now
us.Blacklist = open
us.Mute = open
us.Createtime = now
_, err := db.MysqlClient.Insert(&us)
return err
}
func DBDelete(in *validator_struct.UserRelationshipDel) error {
_, err := db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, in.Accid).
Filter(db_field_faccid, in.Faccid).Delete()
return err
}
func DBAll(in *validator_struct.UserRelationshipAll) ([]db.ImUserRelationship, error) {
var friends []db.ImUserRelationship
num, err := db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, in.Accid).
Filter(db_field_blacklist, open).Filter(db_field_updatetime+"__gte", in.Updatetime).
All(&friends, db_field_faccid, db_field_updatetime)
if err != nil {
return nil, err
}
if num == 0 {
return nil, errors.New("好友列表为空")
}
return friends, nil
}
func SetSpecialRelationDb(in *validator_struct.SetSpecialRelation) error {
if ok := IsUserRelationship(in.Accid, in.TargetAcc); !ok {
return errors.New("被操作用户不是该用户好友")
}
orm_params := make(orm.Params)
// 加入黑名单
if in.RelationType == 1 {
if in.Value == 1 {
//黑名单
orm_params["blacklist"] = close
} else {
orm_params["blacklist"] = open
}
} else {
if in.Value == 1 {
//禁音
orm_params["mute"] = close
} else {
orm_params["mute"] = open
}
}
if len(orm_params) == 0 {
return nil
}
_, err := db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, in.Accid).
Filter(db_field_faccid, in.TargetAcc).Update(orm_params)
return err
}
func ListBlackAndMuteListDB(in *validator_struct.ListBlackAndMuteList) (blacklist []db.ImUserRelationship,
mutelist []db.ImUserRelationship, err error) {
query_db := db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, in.Accid)
_, err = query_db.Filter(db_field_blacklist, close).All(&blacklist)
if err != nil {
return
}
_, err = query_db.Filter(db_field_mute, close).All(&mutelist)
return
}
package im_user_relationship
import (
"context"
"errors"
"im-microservice/sevice/im_user"
"im-microservice/helper"
"im-microservice/pb"
vs "im-microservice/validator_struct"
)
type UserRelationshipService struct {
pb.UnimplementedUserRelationshipServiceServer
}
func (us *UserRelationshipService) Add(ctx context.Context,
in *pb.UserRelationshipAddRequest) (reply *pb.UserRelationshipAddReply, err error) {
m := map[string]interface{}{
"accid": in.GetAccid(),
"faccid": in.GetFaccid(),
"type": in.GetType(),
"msg": in.GetMsg(),
}
request := vs.NewUserRelationshipAdd(m)
if err = helper.Valiator(request); err != nil {
return
}
if ok := IsUserRelationship(request.Accid, request.Faccid); ok {
err = errors.New("已经添加过该好友")
return
}
//添加好友
if err = AddUserRelationship(request); err != nil {
return
}
// 更改用户版本信息
u_map := make(map[string]interface{})
u_map["edition"] = helper.GetNowTime()
_, _ = im_user.UpdateImUser(request.Accid, u_map)
reply = &pb.UserRelationshipAddReply{}
return
}
func (us *UserRelationshipService) Delete(ctx context.Context,
in *pb.UserRelationshipDelRequest) (reply *pb.UserRelationshipAddReply, err error) {
m := map[string]interface{}{
"accid": in.GetAccid(),
"faccid": in.GetFaccid(),
}
request := vs.NewUserRelationshipDel(m)
if err = helper.Valiator(request); err != nil {
return
}
// 删除好友
if err = DBDelete(request); err != nil {
return
}
// 更改用户版本信息
u_map := make(map[string]interface{})
u_map["edition"] = helper.GetNowTime()
_, _ = im_user.UpdateImUser(request.Accid, u_map)
reply = &pb.UserRelationshipAddReply{}
return
}
func (us *UserRelationshipService) All(ctx context.Context,
in *pb.UserRelationshipListRequest) (reply *pb.UserRelationshipListReply, err error) {
m := map[string]interface{}{
"accid": in.GetAccid(),
"updatetime": in.GetUpdatetime(),
}
request := vs.NewUserRelationshipAll(m)
if err = helper.Valiator(request); err != nil {
return
}
results, err := DBAll(request)
if err != nil {
return
}
reply = &pb.UserRelationshipListReply{}
for _, v := range results {
reply.List = append(reply.List, &pb.UserRelationshipInfo{
Faccid: v.Faccid,
Updatetime: v.Updatetime,
})
}
return
}
func (us *UserRelationshipService) SetSpecialRelation(ctx context.Context,
in *pb.SetSpecialRelationReq) (reply *pb.UserRelationshipAddReply, err error) {
m := map[string]interface{}{
"accid": in.GetAccid(),
"faccid": in.GetTargetAcc(),
"relation_type": in.GetRelationType(),
"value": in.GetValue(),
}
request := vs.NewSetSpecialRelation(m)
if err = helper.Valiator(request); err != nil {
return
}
if err = SetSpecialRelationDb(request); err != nil {
return
}
reply = &pb.UserRelationshipAddReply{}
return
}
func (us *UserRelationshipService) ListBlackAndMuteList(ctx context.Context,
in *pb.ListBlackAndMuteListReq) (reply *pb.ListBlackAndMuteListReply, err error) {
m := map[string]interface{}{
"accid": in.GetAccid(),
}
request := vs.NewListBlackAndMuteList(m)
if err = helper.Valiator(request); err != nil {
return
}
blacklist, mutelist, err := ListBlackAndMuteListDB(request)
if err != nil {
return
}
reply = &pb.ListBlackAndMuteListReply{}
if len(blacklist) > 0 {
for _, v := range blacklist {
reply.Blacklist = append(reply.Blacklist,
&pb.UserRelationshipInfo{Updatetime: v.Updatetime, Faccid: v.Faccid})
}
}
if len(mutelist) > 0 {
for _, v := range mutelist {
reply.Mutelist = append(reply.Mutelist,
&pb.UserRelationshipInfo{Updatetime: v.Updatetime, Faccid: v.Faccid})
}
}
return
}
syntax = "proto3";
package pb;
import "u-proto/common.proto";
//添加好友
message UserRelationshipAddRequest {
Common Common = 1;
string Accid = 2;
string Faccid = 3;
int64 Type = 4;
string Msg = 5;
}
message UserRelationshipAddReply {}
//删除好友
message UserRelationshipDelRequest {
Common Common = 1;
string Accid = 2;
string Faccid = 3;
}
// 获取好友关系
message UserRelationshipListRequest {
Common Common = 1;
string Accid = 2;
string Updatetime = 3;
}
message UserRelationshipInfo {
string Faccid = 1;
string Updatetime = 2;
}
message UserRelationshipListReply {
repeated UserRelationshipInfo List = 1;
}
//设置黑名单/静音
message SetSpecialRelationReq {
Common Common = 1;
string Accid = 2;
string TargetAcc = 3;
int64 RelationType = 4;
int64 Value = 5;
}
//查看指定用户的黑名单和静音列表
message ListBlackAndMuteListReq {
Common Common = 1;
string Accid = 2;
}
message ListBlackAndMuteListReply {
repeated UserRelationshipInfo Mutelist = 1;
repeated UserRelationshipInfo Blacklist = 2;
}
service UserRelationshipService {
rpc Add(UserRelationshipAddRequest) returns (UserRelationshipAddReply) {}
rpc Delete(UserRelationshipDelRequest) returns (UserRelationshipAddReply) {}
rpc All(UserRelationshipListRequest) returns (UserRelationshipListReply) {}
rpc SetSpecialRelation(SetSpecialRelationReq) returns (UserRelationshipAddReply) {}
rpc ListBlackAndMuteList(ListBlackAndMuteListReq) returns(ListBlackAndMuteListReply) {}
}
\ No newline at end of file
......@@ -9,12 +9,27 @@ type ConfigureAddStruct struct {
MsgHookUrl string `validate:"required"`
}
func NewConfigureAddStruct(in *pb.ConfigureRequest) *ConfigureAddStruct {
return &ConfigureAddStruct{
CompanyUserId: in.Public.GetCompanyUserId(),
MultideviceType: in.Public.GetMultideviceType(),
MsgHookUrl: in.Public.GetMsgHookUrl(),
func NewConfigureAddStruct(inter interface{}) *ConfigureAddStruct {
config := &ConfigureAddStruct{}
switch inter.(type) {
case *pb.ConfigureRequest:
var c = inter.(*pb.ConfigureRequest)
config.CompanyUserId = c.Public.GetCompanyUserId()
config.MultideviceType = c.Public.GetMultideviceType()
config.MsgHookUrl = c.Public.GetMsgHookUrl()
case map[string]interface{}:
var c = inter.(map[string]interface{})
if cui, ok := c["company_user_id"].(int64); ok {
config.CompanyUserId = cui
}
if mt, ok := c["multidevice_type"].(int64); ok {
config.MultideviceType = mt
}
if mhu, ok := c["msg_hook_url"].(string); ok {
config.MsgHookUrl = mhu
}
}
return config
}
// 修改配置
......@@ -24,12 +39,27 @@ type ConfigureUpdateStruct struct {
MsgHookUrl string
}
func NewConfigureUpdateStruct(in *pb.UpdateRequest) *ConfigureUpdateStruct {
return &ConfigureUpdateStruct{
CompanyUserId: in.Public.GetCompanyUserId(),
MultideviceType: in.Public.GetMultideviceType(),
MsgHookUrl: in.Public.GetMsgHookUrl(),
func NewConfigureUpdateStruct(in interface{}) *ConfigureUpdateStruct {
var config_update = &ConfigureUpdateStruct{}
switch in.(type) {
case *pb.UpdateRequest:
var v = in.(*pb.ConfigureRequest)
config_update.CompanyUserId = v.Public.GetCompanyUserId()
config_update.MultideviceType = v.Public.GetMultideviceType()
config_update.MsgHookUrl = v.Public.GetMsgHookUrl()
case map[string]interface{}:
var c = in.(map[string]interface{})
if cui, ok := c["company_user_id"].(int64); ok {
config_update.CompanyUserId = cui
}
if mt, ok := c["multidevice_type"].(int64); ok {
config_update.MultideviceType = mt
}
if mhu, ok := c["msg_hook_url"].(string); ok {
config_update.MsgHookUrl = mhu
}
}
return config_update
}
// 删除配置
......@@ -37,8 +67,20 @@ type ConfigureDelStruct struct {
CompanyUserId int64 `validate:"required,numeric"`
}
func NewConfigureDelStruct(in *pb.ConfigureDelRequest) *ConfigureDelStruct {
return &ConfigureDelStruct{CompanyUserId: in.GetCompanyUserId()}
func NewConfigureDelStruct(inter interface{}) *ConfigureDelStruct {
room := &ConfigureDelStruct{}
switch inter.(type) {
case *pb.ConfigureDelRequest:
var c = inter.(*pb.ConfigureDelRequest)
room.CompanyUserId = c.GetCompanyUserId()
case map[string]interface{}:
var c = inter.(map[string]interface{})
if v, ok := c["company_user_id"].(int64); ok {
room.CompanyUserId = v
}
}
return room
}
// 创建聊天室
......@@ -97,7 +139,88 @@ type ChatRoomInfo struct {
Updatetime string
}
func NewChatRoomInfo(in *pb.ChatRoomInfoRequest) *ChatRoomInfo {
return &ChatRoomInfo{RoomId: in.GetRoomId()}
func NewChatRoomInfo(inter interface{}) *ChatRoomInfo {
room := &ChatRoomInfo{}
switch inter.(type) {
case *pb.ChatRoomInfoRequest:
var c = inter.(*pb.ChatRoomInfoRequest)
room.RoomId = c.RoomId
case map[string]interface{}:
var c = inter.(map[string]interface{})
if v, ok := c["room_id"].(int64); ok {
room.RoomId = v
}
}
return room
}
//添加好友
type UserRelationshipAdd struct {
Accid string `validate:"required"`
Faccid string `validate:"required"`
Type int64 `validate:"required"`
Msg string
}
func NewUserRelationshipAdd(in map[string]interface{}) *UserRelationshipAdd {
return &UserRelationshipAdd{
Accid: in["accid"].(string),
Faccid: in["faccid"].(string),
Type: in["type"].(int64),
Msg: in["msg"].(string),
}
}
// 删除好友
type UserRelationshipDel struct {
Accid string `validate:"required"`
Faccid string `validate:"required"`
}
func NewUserRelationshipDel(in map[string]interface{}) *UserRelationshipDel {
return &UserRelationshipDel{
Accid: in["accid"].(string),
Faccid: in["faccid"].(string),
}
}
// 获取好友列表
type UserRelationshipAll struct {
Accid string `validate:"required"`
Updatetime string `validate:"required"`
}
func NewUserRelationshipAll(in map[string]interface{}) *UserRelationshipAll {
return &UserRelationshipAll{
Accid: in["accid"].(string),
Updatetime: in["updatetime"].(string),
}
}
// 设置用户黑名单/禁音
type SetSpecialRelation struct {
Accid string `validate:"required"`
TargetAcc string `validate:"required"`
RelationType int64 `validate:"required,numeric,min=1"`
Value int64 `validate:"required,numeric,min=1"`
}
func NewSetSpecialRelation(in map[string]interface{}) *SetSpecialRelation{
return &SetSpecialRelation{
Accid: in["accid"].(string),
TargetAcc: in["faccid"].(string),
RelationType: in["relation_type"].(int64),
Value: in["value"].(int64),
}
}
// 获取用户列表
type ListBlackAndMuteList struct {
Accid string `validate:"required"`
}
func NewListBlackAndMuteList(in map[string]interface{}) *ListBlackAndMuteList {
return &ListBlackAndMuteList{Accid:in["accid"].(string)}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment