Commit 699d2a1c by chenxianqi

推荐项目

parent b6e64b63
......@@ -5,8 +5,8 @@ httpport = 8080
copyrequestbody = true
viewspath = "public"
# 用于本地服务今天地址
static_host = "http://localhost:8080/static/uploads/images"
# 用于本地服务静态资源地址
static_host = "http://localhost:8080"
# 进程监控
EnableAdmin = false
......
......@@ -64,7 +64,7 @@ func (c *MessageController) List() {
}
// push notify update current service contacts list
// 待处理888 推送给客的的聊天列表
// 待处理888 推送给客的的聊天列表
// if len(robotlbrary.Robots) > 0 {
// robotlbrary.PushNewContacts(auth.UID, robotlbrary.Robots[0])
// }
......@@ -166,7 +166,7 @@ func (c *MessageController) Transfer() {
// 待处理888 发送消息
// robot.SendMessage(strconv.FormatInt(admin.ID, 10), []byte(messageStringOne))
utils.MessageInto(message, true)
utils.MessageInto(message)
// Send to forwarded customer service
......@@ -178,7 +178,7 @@ func (c *MessageController) Transfer() {
// 待处理888 发送消息
// robot.SendMessage(strconv.FormatInt(transferDto.ToAccount, 10), []byte(messageStringTwo))
utils.MessageInto(message, true)
utils.MessageInto(message)
// send to user
// message.FromAccount = robot.ID
......@@ -191,7 +191,7 @@ func (c *MessageController) Transfer() {
// 待处理888 发送消息
// robot.SendMessage(strconv.FormatInt(transferDto.UserAccount, 10), []byte(messageString3))
utils.MessageInto(message, false)
utils.MessageInto(message)
// Transfer to the library for counting service times
servicesStatistical := models.ServicesStatistical{UserAccount: transferDto.UserAccount, ServiceAccount: transferDto.ToAccount, TransferAccount: admin.ID, Platform: user.Platform, CreateAt: time.Now().Unix()}
......
......@@ -381,7 +381,7 @@ func (c *PublicController) PushMessage() {
var msgContent []byte
msgContent, _ = base64.StdEncoding.DecodeString(pushMessage.Payload)
utils.StringToInterface(string(msgContent), &getMessage)
utils.MessageInto(getMessage, false)
utils.MessageInto(getMessage)
c.JSON(configs.ResponseSucess, "push success", nil)
......@@ -426,7 +426,7 @@ func (c *PublicController) Upload() {
c.JSON(configs.ResponseFail, "上传失败!", &err)
}
c.JSON(configs.ResponseSucess, "上传成功!", &fileName)
c.JSON(configs.ResponseSucess, "上传成功!", "/"+fpath)
}
// CancelMessage cancel a message
......
......@@ -112,18 +112,24 @@ func init() {
}
var fileDescriptor_014de31d7ac8c57c = []byte{
// 168 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0xc9, 0x4c,
0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4d, 0x2f, 0x2a, 0x48, 0x2e, 0x56,
0x92, 0xe3, 0xe2, 0x08, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x4b, 0x2d, 0x16, 0x12, 0xe2, 0x62, 0x49,
0x49, 0x2c, 0x49, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x95, 0x64, 0xb9, 0xd8,
0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0xb0, 0x49, 0x1b, 0x2d, 0x65, 0xe4, 0x62, 0xf1, 0x4e,
0x4d, 0x2b, 0x15, 0x32, 0xe7, 0x12, 0x72, 0x4f, 0x2d, 0xf1, 0xcf, 0xcb, 0xc9, 0xcc, 0x4b, 0x75,
0xcc, 0xc9, 0x09, 0xca, 0x4f, 0xca, 0x2f, 0x29, 0x16, 0xe2, 0xd3, 0x03, 0xdb, 0xa2, 0x07, 0x35,
0x42, 0x8a, 0x1f, 0xce, 0x87, 0x58, 0xa9, 0xc4, 0x20, 0x64, 0xc0, 0xc5, 0x1d, 0x50, 0x5a, 0x9c,
0xe1, 0x9b, 0x5a, 0x5c, 0x9c, 0x98, 0x9e, 0x4a, 0x8c, 0x0e, 0x23, 0x2e, 0x5e, 0xe7, 0xc4, 0xbc,
0xe4, 0xd4, 0x1c, 0xe2, 0xf5, 0x24, 0xb1, 0x81, 0x3d, 0x6d, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff,
0x0b, 0x6e, 0x06, 0xcc, 0x04, 0x01, 0x00, 0x00,
// 265 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x4d, 0x4b, 0x33, 0x41,
0x10, 0x84, 0xdf, 0xf0, 0xc6, 0xaf, 0xf6, 0x23, 0x38, 0x20, 0x88, 0xa0, 0xc8, 0xe2, 0xc1, 0xd3,
0x22, 0x51, 0x14, 0xbc, 0xc5, 0x1c, 0x42, 0x08, 0x6a, 0xd8, 0x08, 0x9e, 0x3b, 0xb3, 0x9d, 0xdd,
0x81, 0x49, 0xcf, 0xba, 0xdd, 0x4b, 0xfe, 0xa6, 0x3f, 0x49, 0x5c, 0x25, 0x5e, 0x3c, 0x8c, 0xb7,
0x19, 0x9a, 0xaa, 0xea, 0xa7, 0x68, 0xd8, 0xb3, 0xde, 0x11, 0x6b, 0x5a, 0xd5, 0x41, 0x83, 0xd9,
0x28, 0xea, 0xca, 0x4a, 0x72, 0x06, 0xdb, 0x19, 0x49, 0x15, 0x98, 0xc4, 0x18, 0xe8, 0xe6, 0xa8,
0x78, 0xdc, 0x39, 0xef, 0x5c, 0xee, 0x64, 0xed, 0x3b, 0x39, 0x85, 0xad, 0x8c, 0xde, 0x1a, 0x12,
0xfd, 0x6d, 0xdc, 0x7f, 0xff, 0x0f, 0xdd, 0x09, 0x2d, 0x1a, 0x73, 0x07, 0x66, 0x44, 0xfa, 0xcc,
0xde, 0x31, 0x0d, 0xbc, 0xcf, 0xc2, 0x3c, 0xa8, 0x98, 0x83, 0xb4, 0x4d, 0x49, 0xbf, 0x2d, 0x4e,
0x7a, 0xeb, 0xff, 0x57, 0x64, 0xf2, 0xcf, 0x5c, 0xc1, 0xee, 0xb4, 0x91, 0xf2, 0x91, 0x44, 0xb0,
0xa0, 0x18, 0x45, 0x1f, 0xf6, 0x87, 0xc8, 0x96, 0xfc, 0x1f, 0x34, 0xf7, 0x70, 0x34, 0x23, 0xac,
0x6d, 0x39, 0xe1, 0xb0, 0xf2, 0x94, 0x17, 0xf4, 0xe2, 0xd4, 0x53, 0xd4, 0x86, 0x37, 0xd0, 0xfb,
0x41, 0xcb, 0x97, 0x8e, 0xa3, 0x54, 0xb7, 0x70, 0x38, 0x66, 0xa1, 0x5a, 0x67, 0x8a, 0xea, 0x44,
0x9d, 0x45, 0x1f, 0x99, 0xf6, 0xd9, 0xc7, 0x13, 0xad, 0x86, 0x81, 0x15, 0x6d, 0x5c, 0x8b, 0x63,
0xb8, 0x18, 0x91, 0xae, 0xe1, 0x1e, 0x50, 0xe8, 0xd5, 0x69, 0xd9, 0x42, 0x0e, 0x38, 0x9f, 0x7a,
0xd4, 0x45, 0xa8, 0x97, 0x11, 0x56, 0xf3, 0xcd, 0xf6, 0x3e, 0xae, 0x3f, 0x02, 0x00, 0x00, 0xff,
0xff, 0x4f, 0xab, 0x2e, 0xaf, 0x2f, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
......@@ -141,6 +147,11 @@ type KefuClient interface {
GetOnlineAllRobots(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
PushMessage(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
CancelMessage(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
SearchKnowledgeTitles(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
GetOnlineAdmins(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
InsertStatistical(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
PushNewContacts(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
GetKnowledgeBaseWithTitleAndPlatform(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error)
}
type kefuClient struct {
......@@ -178,11 +189,61 @@ func (c *kefuClient) CancelMessage(ctx context.Context, in *Request, opts ...grp
return out, nil
}
func (c *kefuClient) SearchKnowledgeTitles(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error) {
out := new(Respones)
err := c.cc.Invoke(ctx, "/grpcs.Kefu/SearchKnowledgeTitles", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *kefuClient) GetOnlineAdmins(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error) {
out := new(Respones)
err := c.cc.Invoke(ctx, "/grpcs.Kefu/GetOnlineAdmins", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *kefuClient) InsertStatistical(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error) {
out := new(Respones)
err := c.cc.Invoke(ctx, "/grpcs.Kefu/InsertStatistical", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *kefuClient) PushNewContacts(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error) {
out := new(Respones)
err := c.cc.Invoke(ctx, "/grpcs.Kefu/PushNewContacts", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *kefuClient) GetKnowledgeBaseWithTitleAndPlatform(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Respones, error) {
out := new(Respones)
err := c.cc.Invoke(ctx, "/grpcs.Kefu/GetKnowledgeBaseWithTitleAndPlatform", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// KefuServer is the server API for Kefu service.
type KefuServer interface {
GetOnlineAllRobots(context.Context, *Request) (*Respones, error)
PushMessage(context.Context, *Request) (*Respones, error)
CancelMessage(context.Context, *Request) (*Respones, error)
SearchKnowledgeTitles(context.Context, *Request) (*Respones, error)
GetOnlineAdmins(context.Context, *Request) (*Respones, error)
InsertStatistical(context.Context, *Request) (*Respones, error)
PushNewContacts(context.Context, *Request) (*Respones, error)
GetKnowledgeBaseWithTitleAndPlatform(context.Context, *Request) (*Respones, error)
}
// UnimplementedKefuServer can be embedded to have forward compatible implementations.
......@@ -198,6 +259,21 @@ func (*UnimplementedKefuServer) PushMessage(ctx context.Context, req *Request) (
func (*UnimplementedKefuServer) CancelMessage(ctx context.Context, req *Request) (*Respones, error) {
return nil, status.Errorf(codes.Unimplemented, "method CancelMessage not implemented")
}
func (*UnimplementedKefuServer) SearchKnowledgeTitles(ctx context.Context, req *Request) (*Respones, error) {
return nil, status.Errorf(codes.Unimplemented, "method SearchKnowledgeTitles not implemented")
}
func (*UnimplementedKefuServer) GetOnlineAdmins(ctx context.Context, req *Request) (*Respones, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetOnlineAdmins not implemented")
}
func (*UnimplementedKefuServer) InsertStatistical(ctx context.Context, req *Request) (*Respones, error) {
return nil, status.Errorf(codes.Unimplemented, "method InsertStatistical not implemented")
}
func (*UnimplementedKefuServer) PushNewContacts(ctx context.Context, req *Request) (*Respones, error) {
return nil, status.Errorf(codes.Unimplemented, "method PushNewContacts not implemented")
}
func (*UnimplementedKefuServer) GetKnowledgeBaseWithTitleAndPlatform(ctx context.Context, req *Request) (*Respones, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetKnowledgeBaseWithTitleAndPlatform not implemented")
}
func RegisterKefuServer(s *grpc.Server, srv KefuServer) {
s.RegisterService(&_Kefu_serviceDesc, srv)
......@@ -257,6 +333,96 @@ func _Kefu_CancelMessage_Handler(srv interface{}, ctx context.Context, dec func(
return interceptor(ctx, in, info, handler)
}
func _Kefu_SearchKnowledgeTitles_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KefuServer).SearchKnowledgeTitles(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpcs.Kefu/SearchKnowledgeTitles",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KefuServer).SearchKnowledgeTitles(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _Kefu_GetOnlineAdmins_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KefuServer).GetOnlineAdmins(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpcs.Kefu/GetOnlineAdmins",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KefuServer).GetOnlineAdmins(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _Kefu_InsertStatistical_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KefuServer).InsertStatistical(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpcs.Kefu/InsertStatistical",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KefuServer).InsertStatistical(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _Kefu_PushNewContacts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KefuServer).PushNewContacts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpcs.Kefu/PushNewContacts",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KefuServer).PushNewContacts(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _Kefu_GetKnowledgeBaseWithTitleAndPlatform_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KefuServer).GetKnowledgeBaseWithTitleAndPlatform(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpcs.Kefu/GetKnowledgeBaseWithTitleAndPlatform",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KefuServer).GetKnowledgeBaseWithTitleAndPlatform(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
var _Kefu_serviceDesc = grpc.ServiceDesc{
ServiceName: "grpcs.Kefu",
HandlerType: (*KefuServer)(nil),
......@@ -273,6 +439,26 @@ var _Kefu_serviceDesc = grpc.ServiceDesc{
MethodName: "CancelMessage",
Handler: _Kefu_CancelMessage_Handler,
},
{
MethodName: "SearchKnowledgeTitles",
Handler: _Kefu_SearchKnowledgeTitles_Handler,
},
{
MethodName: "GetOnlineAdmins",
Handler: _Kefu_GetOnlineAdmins_Handler,
},
{
MethodName: "InsertStatistical",
Handler: _Kefu_InsertStatistical_Handler,
},
{
MethodName: "PushNewContacts",
Handler: _Kefu_PushNewContacts_Handler,
},
{
MethodName: "GetKnowledgeBaseWithTitleAndPlatform",
Handler: _Kefu_GetKnowledgeBaseWithTitleAndPlatform_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "client.proto",
......
......@@ -5,6 +5,11 @@ service Kefu {
rpc GetOnlineAllRobots (Request) returns (Respones) {}
rpc PushMessage (Request) returns (Respones) {}
rpc CancelMessage (Request) returns (Respones) {}
rpc SearchKnowledgeTitles (Request) returns (Respones) {}
rpc GetOnlineAdmins (Request) returns (Respones) {}
rpc InsertStatistical (Request) returns (Respones) {}
rpc PushNewContacts (Request) returns (Respones) {}
rpc GetKnowledgeBaseWithTitleAndPlatform (Request) returns (Respones) {}
}
message Respones {
string data = 1;
......
......@@ -3,11 +3,12 @@ package grpcs
import (
context "context"
"encoding/base64"
"encoding/json"
"kefu_server/models"
"kefu_server/services"
"kefu_server/utils"
"log"
"net"
"strconv"
"github.com/astaxie/beego/logs"
grpc "google.golang.org/grpc"
......@@ -29,7 +30,7 @@ func (s *kefuServer) PushMessage(ctx context.Context, in *Request) (*Respones, e
var message models.Message
msgContent, _ := base64.StdEncoding.DecodeString(in.Data)
utils.StringToInterface(string(msgContent), &message)
utils.MessageInto(message, false)
utils.MessageInto(message)
return &Respones{Data: "push success"}, nil
}
......@@ -40,18 +41,63 @@ func (s *kefuServer) CancelMessage(ctx context.Context, in *Request) (*Respones,
// cancel
messageRepository := services.GetMessageRepositoryInstance()
_, err := messageRepository.Delete(request)
logs.Info("messageRepository== ", request)
if err != nil {
logs.Info("grpc CancelMessage err == ", err)
}
return &Respones{Data: "cancel message success"}, nil
}
// SearchKnowledgeTitles
func (s *kefuServer) SearchKnowledgeTitles(ctx context.Context, in *Request) (*Respones, error) {
var request models.KnowledgeBaseTitleRequestDto
utils.StringToInterface(in.Data, &request)
knowledgeBaseRepository := services.GetKnowledgeBaseRepositoryInstance()
titles := knowledgeBaseRepository.SearchKnowledgeTitles(request)
return &Respones{Data: utils.InterfaceToString(titles)}, nil
}
// GetOnlineAdmins
func (s *kefuServer) GetOnlineAdmins(ctx context.Context, in *Request) (*Respones, error) {
adminRepository := services.GetAdminRepositoryInstance()
admins := adminRepository.GetOnlineAdmins()
return &Respones{Data: utils.InterfaceToString(admins)}, nil
}
// PushNewContacts
func (s *kefuServer) PushNewContacts(ctx context.Context, in *Request) (*Respones, error) {
uid, _ := strconv.ParseInt(in.Data, 10, 64)
utils.PushNewContacts(uid)
return &Respones{Data: "PushNewContacts success"}, nil
}
// InsertStatistical
func (s *kefuServer) InsertStatistical(ctx context.Context, in *Request) (*Respones, error) {
var servicesStatistical models.ServicesStatistical
utils.StringToInterface(in.Data, &servicesStatistical)
statisticalRepository := services.GetStatisticalRepositoryInstance()
_, err := statisticalRepository.Add(&servicesStatistical)
if err != nil {
logs.Info("InsertStatistical err == ", err)
}
return &Respones{Data: "insert success"}, nil
}
// GetKnowledgeBaseWithTitle
func (s *kefuServer) GetKnowledgeBaseWithTitleAndPlatform(ctx context.Context, in *Request) (*Respones, error) {
request := make(map[string]string)
json.Unmarshal([]byte(in.Data), &request)
knowledgeBaseRepository := services.GetKnowledgeBaseRepositoryInstance()
platform, _ := strconv.ParseInt(request["platform"], 10, 64)
knowledgeBase := knowledgeBaseRepository.GetKnowledgeBaseWithTitleAndPlatform(request["title"], platform)
return &Respones{Data: utils.InterfaceToString(knowledgeBase)}, nil
}
// Run run grpc server
func Run() {
lis, err := net.Listen("tcp", ":8028")
if err != nil {
log.Fatalf("grpc server failed: %v", err)
logs.Info("grpc server failed: %v", err)
}
s := grpc.NewServer()
RegisterKefuServer(s, &kefuServer{})
......
......@@ -34,7 +34,7 @@ func initLog() {
}
func main() {
end := make(chan bool, 1)
// init db
db.Run()
......@@ -60,4 +60,5 @@ func main() {
// run application
beego.Run()
<-end
}
package models
// KnowledgeBaseTitleDto struct
type KnowledgeBaseTitleDto struct {
Title string `json:"title"`
}
// KnowledgeBaseTitleRequestDto struct
type KnowledgeBaseTitleRequestDto struct {
Payload string `json:"payload"`
KeyWords string `json:"keyWords"`
IsSerachSub bool `json:"isSerachSub"`
Platform int64 `json:"platform"`
Limit int64 `json:"limit"`
}
......@@ -15,6 +15,7 @@ type AdminRepositoryInterface interface {
Add(admin *models.Admin, col1 string) (bool, int64, error)
Delete(id int64) (int64, error)
GetAdmins(request *AdminPaginationDto) (*AdminPaginationDto, error)
GetOnlineAdmins() []models.Admin
CheckAdminsLoginTimeOutAndSetOffline(lastMessageUnixTimer int64) int64
}
......@@ -85,6 +86,17 @@ func (r *AdminRepository) Update(id int64, params orm.Params) (int64, error) {
return index, err
}
// GetOnlineAdmins online all admin
func (r *AdminRepository) GetOnlineAdmins() []models.Admin {
var admins []models.Admin
_, err := r.o.Raw("SELECT a.*, IFNULL(c.count,0) AS `count` FROM admin as a LEFT JOIN (SELECT to_account,COUNT(*) AS count FROM `contact` WHERE is_session_end = 0 GROUP BY to_account) c ON a.id = c.to_account WHERE a.`online` = 1 ORDER BY c.count").QueryRows(&admins)
if err != nil {
logs.Warn("GetOnlineAdmins online all admin------------", err)
return []models.Admin{}
}
return admins
}
// Add create a admin
func (r *AdminRepository) Add(admin *models.Admin, col1 string) (bool, int64, error) {
_bool, index, err := r.o.ReadOrCreate(admin, col1)
......
......@@ -101,7 +101,7 @@ func (r *ContactRepository) GetContacts(uid int64) ([]models.ContactDto, error)
_, err := r.o.Raw("SELECT c.id AS cid,c.to_account,c.is_session_end, c.last_message,c.last_message_type,c.from_account, c.create_at AS contact_create_at,u.*, IFNULL(m.`count`,0) AS `read` FROM `contact` c LEFT JOIN `user` u ON c.from_account = u.id LEFT JOIN (SELECT to_account,from_account, COUNT(*) as `count` FROM message WHERE `read` = 1 GROUP BY to_account,from_account) m ON m.to_account = c.to_account AND m.from_account = c.from_account WHERE c.to_account = ? AND c.delete = 0 ORDER BY c.create_at DESC", uid).QueryRows(&contactDto)
if err != nil {
logs.Warn("GetContacts get Contacts------------", err)
return nil, err
return []models.ContactDto{}, err
}
// content base 64 decode
for index, contact := range contactDto {
......
......@@ -16,6 +16,8 @@ type KnowledgeBaseRepositoryInterface interface {
Add(knowledgeBase *models.KnowledgeBase, col1 string) (bool, int64, error)
Update(id int64, params *orm.Params) (int64, error)
Delete(id int64) (int64, error)
SearchKnowledgeTitles(request models.KnowledgeBaseTitleRequestDto) []models.KnowledgeBaseTitleDto
GetKnowledgeBaseWithTitleAndPlatform(title string, platform int64) *models.KnowledgeBase
}
// KnowledgeBaseRepository struct
......@@ -43,6 +45,43 @@ func (r *KnowledgeBaseRepository) Add(knowledgeBase *models.KnowledgeBase, col1
return _bool, index, err
}
// SearchKnowledgeTitles Search Knowledge Titles
// payload = "key1"
// keyWords = "key1|key2|key3"
func (r *KnowledgeBaseRepository) SearchKnowledgeTitles(request models.KnowledgeBaseTitleRequestDto) []models.KnowledgeBaseTitleDto {
if request.Payload == "" {
return []models.KnowledgeBaseTitleDto{}
}
var knowledgeBaseTitleDto []models.KnowledgeBaseTitleDto
subTitle := ""
fields := "title"
if request.IsSerachSub {
fields = "title,sub_title"
}
roobtKeyWords := strings.Split(strings.Trim(request.KeyWords, "|"), "|")
if request.KeyWords == "" {
subTitle := ""
for _, value := range roobtKeyWords {
if strings.Contains(value, request.Payload) {
subTitle += subTitle + " sub_title LIKE \"%" + value + "%\" OR "
}
}
}
if request.IsSerachSub && request.KeyWords != "" {
for _, value := range roobtKeyWords {
subTitle += " sub_title LIKE \"%" + value + "%\" OR "
}
}
subTitle += " sub_title LIKE \"%" + request.Payload + "%\" "
_, err := r.o.Raw("SELECT "+fields+" FROM knowledge_base WHERE ( "+subTitle+" ) AND platform IN (?,?) ORDER by rand() limit ?", 1, request.Platform, request.Limit).QueryRows(&knowledgeBaseTitleDto)
if err != nil {
logs.Warn("Search Knowledge Titles------------", err)
return []models.KnowledgeBaseTitleDto{}
}
return knowledgeBaseTitleDto
}
// Update knowledgeBase
func (r *KnowledgeBaseRepository) Update(id int64, params orm.Params) (int64, error) {
index, err := r.q.Filter("id", id).Update(params)
......@@ -108,6 +147,17 @@ func (r *KnowledgeBaseRepository) GetKnowledgeBaseWithTitle(title string) *model
return &base
}
// GetKnowledgeBaseWithTitleAndPlatform get one KnowledgeBase with title and platform
func (r *KnowledgeBaseRepository) GetKnowledgeBaseWithTitleAndPlatform(title string, platform int64) *models.KnowledgeBase {
var knowledge models.KnowledgeBase
if err := r.q.Filter("title", title).Filter("platform__in", 1, platform).One(&knowledge); err != nil {
logs.Warn("GetKnowledgeBaseWithTitle get one KnowledgeBase with title------------", err)
return nil
}
knowledge.SubTitle = strings.Trim(knowledge.SubTitle, "|")
return &knowledge
}
// Delete delete a KnowledgeBase
func (r *KnowledgeBaseRepository) Delete(id int64) (int64, error) {
index, err := r.q.Filter("id", id).Delete()
......
......@@ -63,7 +63,7 @@ func appTask() {
message.ToAccount = contact.ToAccount
messageString = utils.InterfaceToString(message)
utils.PushMessage(contact.ToAccount, messageString)
utils.MessageInto(message, true)
utils.MessageInto(message)
// Message after timeout
if robot.TimeoutText != "" {
......
......@@ -59,7 +59,8 @@ func HTTPRequest(path string, method string, data interface{}, token string) *HT
if err != nil {
response.Code = 500
response.Message = "链接错误"
logs.Error(err)
logs.Error("链接错误====err", err)
return nil
}
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
req.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
......@@ -70,12 +71,17 @@ func HTTPRequest(path string, method string, data interface{}, token string) *HT
req.Header.Set("Authorization", token)
req.Header.Set("usertype", "cmp_app")
resp, err := client.Do(req)
if err != nil {
response.Code = 502
response.Message = "链接错误:" + err.Error()
return response
}
response.Code = resp.StatusCode
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
response.Code = 400
response.Message = "请求错误"
response.Code = 502
response.Message = "读取数据错处:" + err.Error()
return response
}
if resp.StatusCode != 200 {
......@@ -84,6 +90,5 @@ func HTTPRequest(path string, method string, data interface{}, token string) *HT
return response
}
json.Unmarshal(body, response)
// response.Data = string(body)
return response
}
......@@ -10,10 +10,10 @@ import (
)
// MessageInto push message
func MessageInto(message models.Message, isKF bool) {
func MessageInto(message models.Message) {
// 不处理的类型
if message.BizType == "contacts" || message.BizType == "pong" || message.BizType == "welcome" || message.BizType == "into" || message.BizType == "search_knowledge" {
if message.BizType == "contacts" || message.BizType == "handshake" || message.BizType == "pong" || message.BizType == "welcome" || message.BizType == "into" || message.BizType == "search_knowledge" {
return
}
......@@ -26,13 +26,12 @@ func MessageInto(message models.Message, isKF bool) {
// content内容转base64
message.Payload = base64.StdEncoding.EncodeToString([]byte(message.Payload))
// 过滤掉下面类型的消息不入库
if !(message.BizType == "handshake") {
if !isKF {
// UserRepository instance
userRepository := services.GetUserRepositoryInstance()
user := userRepository.GetUser(message.ToAccount)
// 接收者是用户
if user != nil {
// 默认已读消息
message.Read = 0
......@@ -43,6 +42,7 @@ func MessageInto(message models.Message, isKF bool) {
if user != nil && user.IsWindow == 0 {
message.Read = 1
}
}
// message.BizType == "end" is not read
......@@ -53,8 +53,6 @@ func MessageInto(message models.Message, isKF bool) {
// 消息入库
_, _ = messageRepository.Add(&message)
}
// RobotRepository instance
robotRepository := services.GetRobotRepositoryInstance()
......
package utils
import (
"encoding/base64"
"encoding/json"
"kefu_server/models"
"kefu_server/services"
"time"
)
// PushNewContacts 推送最新聊天列表给客服
func PushNewContacts(uid int64) {
contactData, _ := services.GetContactRepositoryInstance().GetContacts(uid)
// 消息体
message := models.Message{}
message.BizType = "contacts"
message.FromAccount = 1
message.Timestamp = time.Now().Unix()
for index, contact := range contactData {
payload, _ := base64.StdEncoding.DecodeString(contact.LastMessage)
contactData[index].LastMessage = string(payload)
}
message.ToAccount = uid
messageContentByte, _ := json.Marshal(contactData)
message.Payload = string(messageContentByte)
PushMessage(uid, InterfaceToString(message))
}
......@@ -30,7 +30,6 @@ func PushMessage(toAccount int64, msg string) bool {
fmt.Println(response)
return false
}
return true
}
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 sign in to comment