Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SiEn
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
SiEn
Commits
0a30aeef
Commit
0a30aeef
authored
Nov 03, 2020
by
zhangjw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1:订单推送到客服模块
2:完善MQ配置和逻辑
parent
15696384
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
45 additions
and
59 deletions
+45
-59
api-app/src/main/java/com/jumeirah/api/app/controller/AppUserController.java
+1
-7
common/src/main/java/com/jumeirah/common/mq/Queue.java
+0
-15
config/src/main/resources/config/application-dev.yml
+1
-2
config/src/main/resources/config/application-test.yml
+7
-0
customer-service/src/main/java/com/ym/im/handler/BaseHandler.java
+4
-5
customer-service/src/main/java/com/ym/im/mq/Receiver.java
+22
-20
customer-service/src/main/java/com/ym/im/service/impl/StaffServiceImpl.java
+4
-4
customer-service/src/main/resources/application-dev.yml
+3
-3
customer-service/src/main/resources/application-test.yml
+3
-3
No files found.
api-app/src/main/java/com/jumeirah/api/app/controller/AppUserController.java
View file @
0a30aeef
...
@@ -18,15 +18,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
...
@@ -18,15 +18,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
...
...
common/src/main/java/com/jumeirah/common/mq/Queue.java
View file @
0a30aeef
package
com
.
jumeirah
.
common
.
mq
;
package
com
.
jumeirah
.
common
.
mq
;
import
com.jumeirah.common.entity.Stroke
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -18,13 +17,9 @@ public class Queue {
...
@@ -18,13 +17,9 @@ public class Queue {
@Autowired
@Autowired
private
AmqpTemplate
rabbitTemplate
;
private
AmqpTemplate
rabbitTemplate
;
@Value
(
"${spring.rabbitmq.user-queue-name}"
)
private
String
userQueueName
;
@Value
(
"${spring.rabbitmq.order-queue-name}"
)
@Value
(
"${spring.rabbitmq.order-queue-name}"
)
private
String
orderQueueName
;
private
String
orderQueueName
;
/**
/**
* 推送订单状态到客服系统
* 推送订单状态到客服系统
*
*
...
@@ -34,14 +29,5 @@ public class Queue {
...
@@ -34,14 +29,5 @@ public class Queue {
rabbitTemplate
.
convertAndSend
(
orderQueueName
,
stroke
);
rabbitTemplate
.
convertAndSend
(
orderQueueName
,
stroke
);
}
}
/**
* 禁用用户
*
* @param userId
*/
public
void
disableUserQueue
(
String
userId
)
{
rabbitTemplate
.
convertAndSend
(
userQueueName
,
userId
);
}
}
}
\ No newline at end of file
config/src/main/resources/config/application-dev.yml
View file @
0a30aeef
...
@@ -30,8 +30,7 @@ spring:
...
@@ -30,8 +30,7 @@ spring:
port
:
5672
port
:
5672
username
:
root
username
:
root
password
:
root
password
:
root
user-queue-name
:
disable.user.dev
order-queue-name
:
push.order.dev
order-queue-name
:
push.order
# 打印SQL语句和结果集,本地开发环境可开启,线上注释掉
# 打印SQL语句和结果集,本地开发环境可开启,线上注释掉
mybatis-plus
:
mybatis-plus
:
...
...
config/src/main/resources/config/application-test.yml
View file @
0a30aeef
...
@@ -26,6 +26,13 @@ spring:
...
@@ -26,6 +26,13 @@ spring:
password
:
temple123456
password
:
temple123456
port
:
6379
port
:
6379
rabbitmq
:
host
:
47.99.47.225
port
:
5672
username
:
root
password
:
root
order-queue-name
:
push.order
# 打印SQL语句和结果集,本地开发环境可开启,线上注释掉
# 打印SQL语句和结果集,本地开发环境可开启,线上注释掉
mybatis-plus
:
mybatis-plus
:
configuration
:
configuration
:
...
...
customer-service/src/main/java/com/ym/im/handler/BaseHandler.java
View file @
0a30aeef
package
com
.
ym
.
im
.
handler
;
package
com
.
ym
.
im
.
handler
;
import
com.ym.im.entity.base.ChannelAttributeKey
;
import
com.ym.im.entity.base.ChannelAttributeKey
;
import
com.ym.im.exception.HttpException
;
import
com.ym.im.factory.SingleChatFactory
;
import
com.ym.im.factory.SingleChatFactory
;
import
io.netty.channel.ChannelHandler
;
import
io.netty.channel.ChannelHandler
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelHandlerContext
;
...
@@ -30,10 +29,10 @@ public abstract class BaseHandler<T> extends SimpleChannelInboundHandler<T> {
...
@@ -30,10 +29,10 @@ public abstract class BaseHandler<T> extends SimpleChannelInboundHandler<T> {
@Override
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
if
(
cause
instanceof
HttpException
)
{
//
if (cause instanceof HttpException) {
return
;
//
return;
}
//
}
singleChatFactory
.
getService
(
ctx
.
channel
().
attr
(
ChannelAttributeKey
.
ROLE_TYPE
).
get
()).
offline
(
ctx
);
//
singleChatFactory.getService(ctx.channel().attr(ChannelAttributeKey.ROLE_TYPE).get()).offline(ctx);
}
}
}
}
customer-service/src/main/java/com/ym/im/mq/Receiver.java
View file @
0a30aeef
package
com
.
ym
.
im
.
mq
;
package
com
.
ym
.
im
.
mq
;
import
com.ym.im.config.RabbitConfig
;
import
com.ym.im.entity.*
;
import
com.ym.im.entity.*
;
import
com.ym.im.entity.base.NettyConstant
;
import
com.ym.im.entity.base.NettyConstant
;
import
com.ym.im.entity.enums.RoleEnum
;
import
com.ym.im.entity.enums.RoleEnum
;
...
@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -30,7 +32,7 @@ public class Receiver {
...
@@ -30,7 +32,7 @@ public class Receiver {
@Autowired
@Autowired
private
Queue
queue
;
private
Queue
queue
;
@
Autowired
@
Resource
(
name
=
"myRedisTemplate"
)
private
RedisTemplate
redisTemplate
;
private
RedisTemplate
redisTemplate
;
@Autowired
@Autowired
...
@@ -64,9 +66,10 @@ public class Receiver {
...
@@ -64,9 +66,10 @@ public class Receiver {
redisTemplate
.
delete
(
NettyConstant
.
STAFF_USERIDS_KEY
+
staffId
);
redisTemplate
.
delete
(
NettyConstant
.
STAFF_USERIDS_KEY
+
staffId
);
//客服真离线后 才转发
//客服真离线后 才转发
if
(
channelGroup
.
getMerchantStaff
(
staffId
)
==
null
)
{
if
(
channelGroup
.
getMerchantStaff
(
staffId
)
==
null
)
{
final
Set
<
Long
>
userIds
=
staffSocketInfo
.
getUserIds
();
final
Set
userIds
=
staffSocketInfo
.
getUserIds
();
log
.
info
(
"客服离线队列: "
+
"ID: "
+
"UserIds:"
+
userIds
);
log
.
info
(
"客服离线队列: "
+
"ID: "
+
"UserIds:"
+
userIds
);
userIds
.
forEach
(
userId
->
{
userIds
.
forEach
(
uid
->
{
Long
userId
=
Long
.
valueOf
(
uid
.
toString
());
//用户在线才重新分配和转发
//用户在线才重新分配和转发
if
(
channelGroup
.
USER_GROUP
.
get
(
userId
)
!=
null
)
{
if
(
channelGroup
.
USER_GROUP
.
get
(
userId
)
!=
null
)
{
final
StaffSocketInfo
idleStaff
=
staffService
.
getIdleStaff
(
staffSocketInfo
.
getMerchantId
(),
userId
);
final
StaffSocketInfo
idleStaff
=
staffService
.
getIdleStaff
(
staffSocketInfo
.
getMerchantId
(),
userId
);
...
@@ -105,33 +108,32 @@ public class Receiver {
...
@@ -105,33 +108,32 @@ public class Receiver {
@RabbitListener
(
queues
=
ORDER_QUEUE_NAME
)
@RabbitListener
(
queues
=
ORDER_QUEUE_NAME
)
public
void
orderHandler
(
String
json
)
{
public
void
orderHandler
(
String
json
)
{
final
Stroke
stroke
=
JsonUtils
.
json2Obj
(
json
,
Stroke
.
class
);
final
Stroke
stroke
=
JsonUtils
.
json2Obj
(
json
,
Stroke
.
class
);
final
Long
mcId
=
stroke
.
getMcId
();
final
Long
userId
=
stroke
.
getUserId
();
final
Long
userId
=
stroke
.
getUserId
();
final
UserSocketInfo
userSocketInfo
=
channelGroup
.
USER_GROUP
.
get
(
userId
);
final
UserSocketInfo
userSocketInfo
=
channelGroup
.
USER_GROUP
.
get
(
userId
);
if
(
userSocketInfo
==
null
)
{
if
(
userSocketInfo
==
null
)
{
return
;
return
;
}
}
StaffSocketInfo
staffSocketInfo
=
channelGroup
.
getMerchantStaff
(
userSocketInfo
.
getStaffId
(
stroke
.
getMcId
()));
final
MsgBody
<
Stroke
>
orderInfo
=
new
MsgBody
<
Stroke
>().
setCode
(
MsgBody
.
ORDER
).
setData
(
stroke
);
final
MsgBody
<
Stroke
>
orderInfo
=
new
MsgBody
<
Stroke
>().
setCode
(
MsgBody
.
ORDER
).
setData
(
stroke
);
/**
final
StaffSocketInfo
staffSocketInfo
=
channelGroup
.
getMerchantStaff
(
userSocketInfo
.
getStaffId
(
stroke
.
getMcId
()))
==
null
?
staffService
.
getIdleStaff
(
mcId
,
userId
)
:
null
;
* 绑定客服在线,发送订单信息
*/
if
(
staffSocketInfo
!=
null
)
{
if
(
staffSocketInfo
!=
null
)
{
staffSocketInfo
.
writeAndFlush
(
orderInfo
);
staffSocketInfo
.
writeAndFlush
(
orderInfo
);
log
.
info
(
"客服订单: "
+
"给客服("
+
staffSocketInfo
.
getStaffId
()
+
")发送订单:"
+
orderInfo
.
toString
());
log
.
info
(
"客服订单: "
+
"给客服("
+
staffSocketInfo
.
getStaffId
()
+
")发送订单:"
+
orderInfo
.
toString
());
return
;
}
/**
* 绑定客服不在线,给历史客服发送订单信息
*/
final
Long
staffId
=
(
Long
)
redisTemplate
.
opsForHash
().
get
(
NettyConstant
.
IM_USERS
,
userId
);
if
(
staffId
!=
null
)
{
log
.
info
(
"客服订单: "
+
"尝试给历史客服("
+
staffId
+
")发送订单:"
+
orderInfo
.
toString
());
staffSocketInfo
=
channelGroup
.
getMerchantStaff
(
staffId
);
if
(
staffSocketInfo
!=
null
)
{
staffSocketInfo
.
writeAndFlush
(
orderInfo
);
log
.
info
(
"客服订单: "
+
"给历史客服("
+
staffId
+
")发送订单:"
+
orderInfo
.
toString
());
}
}
}
// /**
// * 绑定客服不在线,给历史客服发送订单信息
// */
// final Long staffId = (Long) redisTemplate.opsForHash().get(NettyConstant.IM_USERS, userId);
// if (staffId != null) {
// log.info("客服订单: " + "尝试给历史客服(" + staffId + ")发送订单:" + orderInfo.toString());
// staffSocketInfo = channelGroup.getMerchantStaff(staffId);
// if (staffSocketInfo != null) {
// staffSocketInfo.writeAndFlush(orderInfo);
// log.info("客服订单: " + "给历史客服(" + staffId + ")发送订单:" + orderInfo.toString());
// }
// }
}
}
...
...
customer-service/src/main/java/com/ym/im/service/impl/StaffServiceImpl.java
View file @
0a30aeef
...
@@ -28,10 +28,10 @@ public class StaffServiceImpl implements StaffService {
...
@@ -28,10 +28,10 @@ public class StaffServiceImpl implements StaffService {
@Override
@Override
public
StaffSocketInfo
getIdleStaff
(
Long
merchantId
,
Long
userId
)
{
public
StaffSocketInfo
getIdleStaff
(
Long
merchantId
,
Long
userId
)
{
// final LinkedHashMap<Long, StaffSocketInfo> socketInfoMap = channelGroup.STAFF_GROUP.get(merchantId);
if
(
channelGroup
.
STAFF_GROUP
.
get
(
merchantId
)
==
null
)
{
// if (socketInfoMap == null || socketInfoMap.size() == 0) {
return
null
;
// return null;
}
// }
final
LinkedHashMap
<
Long
,
StaffSocketInfo
>
collect
=
channelGroup
.
STAFF_GROUP
.
get
(
merchantId
)
final
LinkedHashMap
<
Long
,
StaffSocketInfo
>
collect
=
channelGroup
.
STAFF_GROUP
.
get
(
merchantId
)
.
entrySet
()
.
entrySet
()
.
stream
()
.
stream
()
...
...
customer-service/src/main/resources/application-dev.yml
View file @
0a30aeef
...
@@ -24,10 +24,10 @@ spring:
...
@@ -24,10 +24,10 @@ spring:
jackson
:
jackson
:
default-property-inclusion
:
non_null
default-property-inclusion
:
non_null
rabbitmq
:
rabbitmq
:
host
:
127.0.0.1
host
:
47.99.47.225
port
:
5672
port
:
5672
username
:
admin
username
:
root
password
:
admin
password
:
root
delay-queue-name
:
delay.ack.dev
delay-queue-name
:
delay.ack.dev
staff-offline-Queue-Name
:
staff.offline.dev
staff-offline-Queue-Name
:
staff.offline.dev
exchange-name
:
delay.exchange.dev
exchange-name
:
delay.exchange.dev
...
...
customer-service/src/main/resources/application-test.yml
View file @
0a30aeef
...
@@ -29,9 +29,9 @@ spring:
...
@@ -29,9 +29,9 @@ spring:
port
:
5672
port
:
5672
username
:
root
username
:
root
password
:
root
password
:
root
delay-queue-name
:
delay.ack
-Jw
delay-queue-name
:
delay.ack
.dev
staff-offline-Queue-Name
:
staff.offline
-Jw
staff-offline-Queue-Name
:
staff.offline
.dev
exchange-name
:
delay.exchange
exchange-name
:
delay.exchange
.dev
listener
:
listener
:
simple
:
simple
:
default-requeue-rejected
:
false
default-requeue-rejected
:
false
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment