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
eeb0162a
Commit
eeb0162a
authored
Oct 28, 2020
by
zhangjw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1:新增:根据token获取userInfo接口
2:新增:查询航空公司商家表接口 3:客服模块获取deviceToken 4:细节调整 已知Bug修复
parent
0a2d7ffd
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
453 additions
and
59 deletions
+453
-59
api-app/src/main/java/com/jumeirah/api/app/controller/AppUserController.java
+9
-5
api-app/src/main/java/com/jumeirah/api/app/service/AppUserApiService.java
+13
-1
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppUserApiServiceImpl.java
+6
-0
api-system/src/main/java/com/jumeirah/api/system/controller/MerchantForSysController.java
+13
-6
common/src/main/java/com/jumeirah/common/service/MerchantService.java
+9
-0
common/src/main/java/com/jumeirah/common/service/impl/MerchantServiceImpl.java
+13
-0
customer-service/pom.xml
+7
-4
customer-service/src/main/java/com/ym/im/controller/SessionController.java
+1
-1
customer-service/src/main/java/com/ym/im/entity/AppUser.java
+98
-0
customer-service/src/main/java/com/ym/im/entity/DeviceTokenParam.java
+20
-0
customer-service/src/main/java/com/ym/im/entity/JwtTokenRedisVo.java
+0
-4
customer-service/src/main/java/com/ym/im/entity/SessionInfo.java
+2
-1
customer-service/src/main/java/com/ym/im/entity/StaffSocketInfo.java
+2
-2
customer-service/src/main/java/com/ym/im/entity/UserSocketInfo.java
+4
-5
customer-service/src/main/java/com/ym/im/entity/model/PushToken.java
+0
-14
customer-service/src/main/java/com/ym/im/service/ChatService.java
+2
-1
customer-service/src/main/java/com/ym/im/service/SessionListService.java
+1
-1
customer-service/src/main/java/com/ym/im/service/impl/SessionListServiceImpl.java
+2
-2
customer-service/src/main/java/com/ym/im/service/impl/StaffServiceImpl.java
+6
-6
customer-service/src/main/java/com/ym/im/service/impl/StaffSingleChatServiceImpl.java
+1
-1
customer-service/src/main/java/com/ym/im/service/impl/UserSingleChatServiceImpl.java
+12
-5
customer-service/src/main/java/com/ym/im/util/HttpClientUtils.java
+232
-0
No files found.
api-app/src/main/java/com/jumeirah/api/app/controller/AppUserController.java
View file @
eeb0162a
...
...
@@ -14,17 +14,15 @@ import io.geekidea.springbootplus.framework.log.annotation.Module;
import
io.geekidea.springbootplus.framework.log.annotation.OperationLog
;
import
io.geekidea.springbootplus.framework.log.enums.OperationLogType
;
import
io.geekidea.springbootplus.framework.shiro.jwt.JwtToken
;
import
io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil
;
import
io.geekidea.springbootplus.framework.shiro.util.JwtUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shiro.SecurityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
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
org.springframework.web.bind.annotation.*
;
/**
* APP用户 控制器
...
...
@@ -174,5 +172,11 @@ public class AppUserController extends BaseController {
return
appUserApiService
.
register
(
appSmsRegisterParam
,
language
);
}
@GetMapping
(
"/userInfo"
)
@ApiOperation
(
value
=
"根据token获取userInfo"
,
notes
=
"客服模块调用"
)
public
AppUser
getUserInfo
()
{
return
appUserApiService
.
getUserInfo
(
Long
.
valueOf
(
JwtUtil
.
getUsername
(
JwtTokenUtil
.
getToken
())));
}
}
api-app/src/main/java/com/jumeirah/api/app/service/AppUserApiService.java
View file @
eeb0162a
package
com
.
jumeirah
.
api
.
app
.
service
;
import
com.jumeirah.common.entity.AppUser
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.param.app.AppUserInfoParam
;
import
com.jumeirah.common.vo.app.LoginAppUserTokenVo
;
...
...
@@ -9,6 +10,7 @@ public interface AppUserApiService {
/**
* 注册
*
* @param loginParam
* @param language
* @return
...
...
@@ -19,13 +21,23 @@ public interface AppUserApiService {
/**
* 修改或补充用户信息
*
* @param appUserInfoParam
* @return
* @throws Exception
*/
boolean
updateAppUser
(
AppUserInfoParam
appUserInfoParam
)
throws
Exception
;
ApiResult
<
Boolean
>
updatePhone
(
String
phoneArea
,
String
phone
,
String
code
)
throws
Exception
;
ApiResult
<
Boolean
>
updatePhone
(
String
phoneArea
,
String
phone
,
String
code
)
throws
Exception
;
/**
* 获取用户信息
*
* @param userId
* @return
*/
AppUser
getUserInfo
(
Long
userId
);
}
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppUserApiServiceImpl.java
View file @
eeb0162a
package
com
.
jumeirah
.
api
.
app
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.jumeirah.api.app.service.AppSmsService
;
import
com.jumeirah.api.app.service.AppUserApiService
;
import
com.jumeirah.common.entity.AppUser
;
...
...
@@ -53,6 +54,11 @@ public class AppUserApiServiceImpl implements AppUserApiService {
}
@Override
public
AppUser
getUserInfo
(
Long
userId
)
{
return
appUserService
.
getOne
(
new
QueryWrapper
<
AppUser
>().
lambda
().
eq
(
AppUser:
:
getId
,
userId
));
}
@Override
public
ApiResult
<
LoginAppUserTokenVo
>
register
(
AppSmsRegisterParam
loginParam
,
String
language
)
throws
Exception
{
// 校验验证码
boolean
equalsRegisterCode
=
appSmsService
.
equalsRegisterCode
(
loginParam
.
getPhoneArea
(),
loginParam
.
getPhone
(),
loginParam
.
getSmsCode
());
...
...
api-system/src/main/java/com/jumeirah/api/system/controller/MerchantForSysController.java
View file @
eeb0162a
...
...
@@ -16,12 +16,9 @@ import io.swagger.annotations.ApiOperation;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* 航空公司商家表 控制器
...
...
@@ -93,5 +90,15 @@ public class MerchantForSysController extends BaseController {
return
ApiResult
.
ok
(
paging
);
}
/**
* 航空公司商家表
*/
@GetMapping
(
"/getList"
)
@OperationLog
(
name
=
"航空公司商家列表"
,
type
=
OperationLogType
.
LIST
)
@ApiOperation
(
value
=
"航空公司商家列表"
)
public
ApiResult
<
List
<
Merchant
>>
getMerchantList
()
{
return
ApiResult
.
ok
(
merchantService
.
getMerchantList
());
}
}
common/src/main/java/com/jumeirah/common/service/MerchantService.java
View file @
eeb0162a
...
...
@@ -6,6 +6,8 @@ import com.jumeirah.common.vo.MerchantQueryVo;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
java.util.List
;
/**
* 航空公司商家表 服务类
*
...
...
@@ -59,4 +61,11 @@ public interface MerchantService extends BaseService<Merchant> {
*/
Paging
<
MerchantQueryVo
>
getMerchantPageList
(
MerchantPageParam
merchantPageParam
)
throws
Exception
;
/**
* 获取全部商户
*
* @return
*/
List
<
Merchant
>
getMerchantList
();
}
common/src/main/java/com/jumeirah/common/service/impl/MerchantServiceImpl.java
View file @
eeb0162a
package
com
.
jumeirah
.
common
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
...
...
@@ -16,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
/**
* 航空公司商家表 服务实现类
*
...
...
@@ -59,4 +62,14 @@ public class MerchantServiceImpl extends BaseServiceImpl<MerchantMapper, Merchan
return
new
Paging
<
MerchantQueryVo
>(
iPage
);
}
@Override
public
List
<
Merchant
>
getMerchantList
()
{
return
baseMapper
.
selectList
(
new
QueryWrapper
<
Merchant
>().
lambda
()
.
eq
(
Merchant:
:
getState
,
1
)
.
eq
(
Merchant:
:
getDeleted
,
0
)
.
eq
(
Merchant:
:
getAuditRegisterStatus
,
1
)
.
orderByDesc
(
Merchant:
:
getCreateTime
));
}
}
customer-service/pom.xml
View file @
eeb0162a
...
...
@@ -47,9 +47,13 @@
</dependency>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
</dependency>
<dependency>
...
...
@@ -121,7 +125,6 @@
</dependency>
</dependencies>
<build>
...
...
customer-service/src/main/java/com/ym/im/controller/SessionController.java
View file @
eeb0162a
...
...
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.ym.im.entity.MsgBody
;
import
com.ym.im.entity.Session
;
import
com.ym.im.entity.enums.ResultStatus
;
import
com.ym.im.entity.
model.
SessionInfo
;
import
com.ym.im.entity.SessionInfo
;
import
com.ym.im.service.SessionListService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
customer-service/src/main/java/com/ym/im/entity/AppUser.java
0 → 100644
View file @
eeb0162a
package
com
.
ym
.
im
.
entity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* APP用户
*
* @author wei
* @since 2020-09-23
*/
@Data
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"AppUser对象"
)
@AllArgsConstructor
@NoArgsConstructor
public
class
AppUser
implements
Serializable
{
@ApiModelProperty
(
"主键"
)
private
Long
id
;
@ApiModelProperty
(
"用户名"
)
private
String
username
;
@ApiModelProperty
(
"姓"
)
private
String
surname
;
@ApiModelProperty
(
"名"
)
private
String
name
;
@ApiModelProperty
(
"公司名"
)
private
String
companyName
;
@ApiModelProperty
(
"微信号"
)
private
String
wechat
;
@ApiModelProperty
(
"出生日期"
)
private
String
dateOfBirth
;
@ApiModelProperty
(
"昵称"
)
private
String
nickname
;
@ApiModelProperty
(
"密码"
)
private
String
password
;
@ApiModelProperty
(
"盐值"
)
private
String
salt
;
@ApiModelProperty
(
"手机号码"
)
private
String
phone
;
@ApiModelProperty
(
"手机区号"
)
private
String
phoneArea
;
@ApiModelProperty
(
"性别,0:女,1:男,默认1"
)
private
Integer
gender
;
@ApiModelProperty
(
"设备类型,1:安卓,2:ios"
)
private
Integer
deviceType
;
@ApiModelProperty
(
"头像"
)
private
String
head
;
@ApiModelProperty
(
"推送token"
)
private
String
deviceToken
;
@ApiModelProperty
(
"备注"
)
private
String
remark
;
@ApiModelProperty
(
"状态,0:禁用,1:启用,2:锁定"
)
private
Integer
state
;
@ApiModelProperty
(
"部门id"
)
private
Long
departmentId
;
@ApiModelProperty
(
"角色id"
)
private
Long
roleId
;
@ApiModelProperty
(
"逻辑删除,0:未删除,1:已删除"
)
private
Integer
deleted
;
@ApiModelProperty
(
"版本"
)
private
Integer
version
;
@ApiModelProperty
(
"创建时间"
)
private
Date
createTime
;
@ApiModelProperty
(
"修改时间"
)
private
Date
updateTime
;
}
customer-service/src/main/java/com/ym/im/entity/DeviceTokenParam.java
0 → 100644
View file @
eeb0162a
package
com
.
ym
.
im
.
entity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
/**
* @author JJww
*/
@Data
@Accessors
(
chain
=
true
)
public
class
DeviceTokenParam
implements
Serializable
{
private
String
deviceToken
;
@ApiModelProperty
(
"设备类型,1:安卓,2:ios"
)
private
Integer
deviceType
;
}
customer-service/src/main/java/com/ym/im/entity/JwtTokenRedisVo.java
View file @
eeb0162a
...
...
@@ -66,10 +66,6 @@ public class JwtTokenRedisVo implements Serializable {
private
String
token
;
/**
* 设备推送token
*/
private
String
deviceToken
;
/**
* 创建时间
*/
private
Date
createDate
;
...
...
customer-service/src/main/java/com/ym/im/entity/
model/
SessionInfo.java
→
customer-service/src/main/java/com/ym/im/entity/SessionInfo.java
View file @
eeb0162a
package
com
.
ym
.
im
.
entity
.
model
;
package
com
.
ym
.
im
.
entity
;
import
com.ym.im.entity.Session
;
import
lombok.Data
;
...
...
@@ -16,4 +16,5 @@ public class SessionInfo extends Session {
private
String
latestRecord
;
private
Integer
msgType
;
}
customer-service/src/main/java/com/ym/im/entity/StaffSocketInfo.java
View file @
eeb0162a
...
...
@@ -4,6 +4,7 @@ import com.ym.im.entity.base.BaseSocketInfo;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.Accessors
;
import
java.util.HashSet
;
...
...
@@ -16,6 +17,7 @@ import java.util.Set;
*/
@Data
@Accessors
(
chain
=
true
)
@NoArgsConstructor
@EqualsAndHashCode
(
callSuper
=
false
)
public
class
StaffSocketInfo
extends
BaseSocketInfo
{
...
...
@@ -33,8 +35,6 @@ public class StaffSocketInfo extends BaseSocketInfo {
this
.
userIds
=
userIds
;
}
public
StaffSocketInfo
()
{
}
public
StaffSocketInfo
(
Long
staffId
,
Set
<
Long
>
userIds
)
{
this
.
staffId
=
staffId
;
...
...
customer-service/src/main/java/com/ym/im/entity/UserSocketInfo.java
View file @
eeb0162a
package
com
.
ym
.
im
.
entity
;
import
com.ym.im.entity.base.BaseSocketInfo
;
import
com.ym.im.entity.model.PushToken
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
...
...
@@ -19,15 +18,15 @@ import java.util.Set;
@EqualsAndHashCode
(
callSuper
=
false
)
public
class
UserSocketInfo
extends
BaseSocketInfo
{
private
Long
userId
;
private
String
col
;
private
Map
<
Long
,
Long
>
staffIds
=
new
HashMap
<>()
;
private
Long
userId
;
private
Set
<
Long
>
sessionList
;
private
PushToken
pushToken
;
private
DeviceTokenParam
deviceTokenParam
;
private
String
col
;
private
Map
<
Long
,
Long
>
staffIds
=
new
HashMap
<>()
;
public
Long
getStaffId
(
Long
merchantId
)
{
return
staffIds
.
get
(
merchantId
);
...
...
customer-service/src/main/java/com/ym/im/entity/model/PushToken.java
deleted
100644 → 0
View file @
0a2d7ffd
package
com
.
ym
.
im
.
entity
.
model
;
import
lombok.Data
;
/**
* @author xjx
* @Description
* @date 2019/11/18
*/
@Data
public
class
PushToken
{
private
String
pushToken
;
private
String
pushType
;
}
customer-service/src/main/java/com/ym/im/service/ChatService.java
View file @
eeb0162a
...
...
@@ -7,6 +7,7 @@ import io.netty.channel.ChannelHandlerContext;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
javax.validation.Valid
;
import
java.io.IOException
;
/**
* @author: JJww
...
...
@@ -20,7 +21,7 @@ public interface ChatService {
* @param ctx
* @return
*/
void
init
(
ChannelHandlerContext
ctx
);
void
init
(
ChannelHandlerContext
ctx
)
throws
IOException
;
/**
...
...
customer-service/src/main/java/com/ym/im/service/SessionListService.java
View file @
eeb0162a
...
...
@@ -3,7 +3,7 @@ package com.ym.im.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.ym.im.entity.MsgBody
;
import
com.ym.im.entity.Session
;
import
com.ym.im.entity.
model.
SessionInfo
;
import
com.ym.im.entity.SessionInfo
;
import
java.util.List
;
...
...
customer-service/src/main/java/com/ym/im/service/impl/SessionListServiceImpl.java
View file @
eeb0162a
...
...
@@ -6,7 +6,7 @@ import com.ym.im.entity.ChatRecord;
import
com.ym.im.entity.MsgBody
;
import
com.ym.im.entity.Session
;
import
com.ym.im.entity.enums.ResultStatus
;
import
com.ym.im.entity.
model.
SessionInfo
;
import
com.ym.im.entity.SessionInfo
;
import
com.ym.im.mapper.SessionListMapper
;
import
com.ym.im.service.ChatRecordService
;
import
com.ym.im.service.SessionListService
;
...
...
@@ -34,7 +34,7 @@ public class SessionListServiceImpl extends ServiceImpl<SessionListMapper, Sessi
final
List
<
SessionInfo
>
sessions
=
new
ArrayList
<>();
baseMapper
.
selectList
(
new
QueryWrapper
<
Session
>().
lambda
().
eq
(
Session:
:
getUserId
,
userId
)).
forEach
(
session
->
{
final
ChatRecord
latestMsg
=
chatRecordService
.
getLatestMsg
(
userId
,
session
.
getMerchantId
());
final
SessionInfo
sessionModel
=
new
SessionInfo
().
setLatestRecord
(
latestMsg
.
getMsgInfo
()).
setRecordId
(
latestMsg
.
getId
());
final
SessionInfo
sessionModel
=
new
SessionInfo
().
setLatestRecord
(
latestMsg
.
getMsgInfo
()).
set
MsgType
(
latestMsg
.
getMsgType
()).
set
RecordId
(
latestMsg
.
getId
());
BeanUtils
.
copyProperties
(
session
,
sessionModel
);
sessionModel
.
setModifyTime
(
latestMsg
.
getCreateTime
());
//最后一条信息创建时间为呼叫列表更新时间
sessions
.
add
(
sessionModel
);
...
...
customer-service/src/main/java/com/ym/im/service/impl/StaffServiceImpl.java
View file @
eeb0162a
...
...
@@ -28,11 +28,11 @@ public class StaffServiceImpl implements StaffService {
@Override
public
StaffSocketInfo
getIdleStaff
(
Long
merchantId
,
Long
userId
)
{
final
Map
<
Long
,
StaffSocketInfo
>
socketInfoMap
=
channelGroup
.
STAFF_GROUP
.
get
(
merchantId
);
if
(
socketInfoMap
.
size
()
==
0
)
{
return
null
;
}
final
LinkedHashMap
<
Long
,
StaffSocketInfo
>
collect
=
socketInfoMap
// final LinkedHash
Map<Long, StaffSocketInfo> socketInfoMap = channelGroup.STAFF_GROUP.get(merchantId);
// if (socketInfoMap == null ||
socketInfoMap.size() == 0) {
//
return null;
//
}
final
LinkedHashMap
<
Long
,
StaffSocketInfo
>
collect
=
channelGroup
.
STAFF_GROUP
.
get
(
merchantId
)
.
entrySet
()
.
stream
()
.
sorted
(
comparingByValue
(
new
Comparator
<
StaffSocketInfo
>()
{
...
...
@@ -81,7 +81,7 @@ public class StaffServiceImpl implements StaffService {
userSocketInfo
.
writeAndFlush
(
msgBody
);
//通知新客服
staffSocketInfo
.
writeAndFlush
(
msgBody
);
return
new
MsgBody
<>().
set
Data
(
ResultStatus
.
SUCCESS
.
getCode
());
return
new
MsgBody
<>().
set
Code
(
ResultStatus
.
SUCCESS
.
getCode
());
}
...
...
customer-service/src/main/java/com/ym/im/service/impl/StaffSingleChatServiceImpl.java
View file @
eeb0162a
...
...
@@ -86,7 +86,7 @@ public class StaffSingleChatServiceImpl implements ChatService {
if
(
userIds
.
size
()
!=
0
)
{
final
String
userListKey
=
NettyConstant
.
STAFF_USERIDS_KEY
+
staffId
;
redisTemplate
.
delete
(
userListKey
);
redisTemplate
.
opsForSet
().
add
(
userListKey
,
userIds
.
toArray
(
new
Long
[
userIds
.
size
()]
));
redisTemplate
.
opsForSet
().
add
(
userListKey
,
userIds
.
toArray
());
queue
.
staffOfflineQueue
(
new
StaffSocketInfo
(
staffId
,
userIds
));
//NioSocketChannel无法序列化 所以new StaffSocketInfo
}
channelGroup
.
removeMerchantStaff
(
staffId
);
...
...
customer-service/src/main/java/com/ym/im/service/impl/UserSingleChatServiceImpl.java
View file @
eeb0162a
...
...
@@ -9,6 +9,7 @@ import com.ym.im.entity.base.NettyConstant;
import
com.ym.im.entity.model.IdModel
;
import
com.ym.im.handler.ChannelGroupHandler
;
import
com.ym.im.service.*
;
import
com.ym.im.util.HttpClientUtils
;
import
com.ym.im.util.JsonUtils
;
import
com.ym.im.validation.group.ChatRecordReceiveGroup
;
import
com.ym.im.validation.group.ChatRecordSaveGroup
;
...
...
@@ -24,6 +25,7 @@ import org.springframework.validation.annotation.Validated;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -56,18 +58,23 @@ public class UserSingleChatServiceImpl implements ChatService {
@Autowired
private
SessionListService
sessiontListService
;
private
static
final
String
USER_INFO_URL
=
"http://192.168.1.237:8889/api/app/user/userInfo"
;
@Override
public
void
init
(
ChannelHandlerContext
ctx
)
{
public
void
init
(
ChannelHandlerContext
ctx
)
throws
IOException
{
final
Long
userId
=
ctx
.
channel
().
attr
(
ChannelAttributeKey
.
ROLE_ID
).
get
();
UserSocketInfo
userSocketInfo
=
new
UserSocketInfo
();
final
String
token
=
ctx
.
channel
().
attr
(
ChannelAttributeKey
.
TOKEN_INFO
).
get
();
final
UserSocketInfo
userSocketInfo
=
new
UserSocketInfo
();
userSocketInfo
.
setUserId
(
userId
);
userSocketInfo
.
setChannel
((
NioSocketChannel
)
ctx
.
channel
());
userSocketInfo
.
setCol
(
ctx
.
channel
().
attr
(
ChannelAttributeKey
.
COL_INFO
).
get
());
userSocketInfo
.
setToken
(
ctx
.
channel
().
attr
(
ChannelAttributeKey
.
TOKEN_INFO
).
get
());
userSocketInfo
.
setPushToken
(
null
);
userSocketInfo
.
setToken
(
token
);
userSocketInfo
.
setSessionList
(
this
.
getSessionList
(
userId
));
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"token"
,
token
);
final
AppUser
appUser
=
JsonUtils
.
json2Obj
(
HttpClientUtils
.
doGet
(
USER_INFO_URL
,
null
,
headers
),
AppUser
.
class
);
//获取deviceToken
userSocketInfo
.
setDeviceTokenParam
(
new
DeviceTokenParam
().
setDeviceToken
(
appUser
.
getDeviceToken
()).
setDeviceType
(
appUser
.
getDeviceType
()));
channelGroup
.
USER_GROUP
.
put
(
userId
,
userSocketInfo
);
this
.
restoreBindingRelationship
(
userId
);
//恢复历史绑定关系
this
.
broadcastUserOnline
(
userId
);
//通知客服 用户上线
...
...
@@ -112,7 +119,7 @@ public class UserSingleChatServiceImpl implements ChatService {
// 服务用户的客服不在线
if
(
staffSocketInfo
==
null
)
{
// Redis是否存在当前客服服务用户Set对象(TTL=60秒)
Set
members
=
redisTemplate
.
opsForSet
().
members
(
NettyConstant
.
STAFF_USERIDS_KEY
+
staffId
);
Set
<
Long
>
members
=
redisTemplate
.
opsForSet
().
members
(
NettyConstant
.
STAFF_USERIDS_KEY
+
staffId
);
// 客服下线超过60秒,当前客服服务用户Set对象已过期,重新分配客服
// 过期后set对象不会为空而是大小为0
if
(
members
.
size
()
==
0
)
{
...
...
customer-service/src/main/java/com/ym/im/util/HttpClientUtils.java
0 → 100644
View file @
eeb0162a
package
com
.
ym
.
im
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHeaders
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.*
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.config.Registry
;
import
org.apache.http.config.RegistryBuilder
;
import
org.apache.http.conn.socket.ConnectionSocketFactory
;
import
org.apache.http.conn.socket.PlainConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.entity.mime.MultipartEntityBuilder
;
import
org.apache.http.entity.mime.content.ContentBody
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicHeader
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.ssl.SSLContexts
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.MimeTypeUtils
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author 陈俊雄
* @since 2020/5/14
**/
@Slf4j
public
abstract
class
HttpClientUtils
{
private
static
final
int
TIMEOUT
=
60
;
private
static
final
String
UTF_8
=
"UTF-8"
;
private
static
final
BasicHeader
BASIC_HEADER
=
new
BasicHeader
(
HttpHeaders
.
CONTENT_TYPE
,
"application/x-www-form-uriencoded; charset=utf-8"
);
public
static
final
Map
<
String
,
String
>
JSON_HEADER
=
new
HashMap
<
String
,
String
>()
{
{
put
(
HttpHeaders
.
CONTENT_TYPE
,
MimeTypeUtils
.
APPLICATION_JSON_VALUE
);
}
};
/**
* 获取HttpClient
*
* @return CloseableHttpClient
*/
public
static
CloseableHttpClient
getHttpClient
()
{
return
HttpClients
.
createDefault
();
}
public
static
void
test
()
{
Registry
<
ConnectionSocketFactory
>
socketFactoryRegistry
=
RegistryBuilder
.<
ConnectionSocketFactory
>
create
()
.
register
(
"http"
,
PlainConnectionSocketFactory
.
INSTANCE
)
.
register
(
"https"
,
new
SSLConnectionSocketFactory
(
SSLContexts
.
createSystemDefault
()))
.
build
();
PoolingHttpClientConnectionManager
connManager
=
new
PoolingHttpClientConnectionManager
(
socketFactoryRegistry
);
HttpClients
.
custom
().
setConnectionManager
(
connManager
);
}
/**
* 执行Post请求
*
* @param uri uri
* @param params 请求参数
* @return 请求结果
*/
public
static
String
doPostForm
(
String
uri
,
Map
<
String
,
String
>
params
)
{
return
doPostForm
(
uri
,
params
,
null
);
}
/**
* 执行Post请求
*
* @param uri uri
* @param params 请求参数
* @param headers 请求头信息
* @return 请求结果
*/
public
static
String
doPostForm
(
String
uri
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
headers
)
{
HttpPost
httpPost
=
new
HttpPost
(
uri
);
setEntity
(
params
,
httpPost
);
return
send
(
getHttpClient
(),
httpPost
,
headers
);
}
public
static
String
doPostJson
(
String
uri
,
String
jsonString
)
{
return
doPostJson
(
getHttpClient
(),
uri
,
jsonString
,
JSON_HEADER
,
UTF_8
);
}
public
static
String
doPostJson
(
String
uri
,
String
jsonString
,
Map
<
String
,
String
>
headers
)
{
HttpPost
httpPost
=
new
HttpPost
(
uri
);
StringEntity
stringEntity
=
new
StringEntity
(
jsonString
,
UTF_8
);
headers
.
forEach
((
k
,
v
)
->
stringEntity
.
setContentType
(
v
));
httpPost
.
setEntity
(
stringEntity
);
return
send
(
getHttpClient
(),
httpPost
,
headers
);
}
public
static
String
doPostJson
(
CloseableHttpClient
httpClient
,
String
uri
,
String
jsonString
)
{
return
doPostJson
(
httpClient
,
uri
,
jsonString
,
JSON_HEADER
,
UTF_8
);
}
public
static
String
doPostJson
(
CloseableHttpClient
httpClient
,
String
uri
,
String
jsonString
,
String
encoding
)
{
return
doPostJson
(
httpClient
,
uri
,
jsonString
,
JSON_HEADER
,
encoding
);
}
public
static
String
doPostJson
(
CloseableHttpClient
httpClient
,
String
uri
,
String
jsonString
,
Map
<
String
,
String
>
headers
,
String
encoding
)
{
HttpPost
httpPost
=
new
HttpPost
(
uri
);
StringEntity
stringEntity
=
new
StringEntity
(
jsonString
,
encoding
);
headers
.
forEach
((
k
,
v
)
->
stringEntity
.
setContentType
(
v
));
httpPost
.
setEntity
(
stringEntity
);
return
send
(
httpClient
,
httpPost
,
headers
);
}
/**
* 设置请求参数
*
* @param params 请求参数
* @param method Http请求
*/
private
static
void
setEntity
(
Map
<
String
,
String
>
params
,
HttpEntityEnclosingRequestBase
method
)
{
// 设置请求参数
if
(
params
!=
null
)
{
List
<
NameValuePair
>
nameValuePairList
=
new
ArrayList
<>();
params
.
forEach
((
k
,
v
)
->
nameValuePairList
.
add
(
new
BasicNameValuePair
(
k
,
v
)));
try
{
method
.
setEntity
(
new
UrlEncodedFormEntity
(
nameValuePairList
,
UTF_8
));
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 发送请求
*
* @param httpClient httpClient
* @param request request
* @param headers 请求头
* @return 请求字符串结果
*/
private
static
String
send
(
CloseableHttpClient
httpClient
,
HttpRequestBase
request
,
Map
<
String
,
String
>
headers
)
{
// 设置请求头
if
(!
CollectionUtils
.
isEmpty
(
headers
))
{
headers
.
forEach
(
request:
:
setHeader
);
}
else
{
request
.
setHeader
(
BASIC_HEADER
);
}
// 设置超时时间
RequestConfig
config
=
RequestConfig
.
custom
()
.
setConnectTimeout
(
TIMEOUT
*
1000
)
.
setConnectionRequestTimeout
(
TIMEOUT
*
1000
)
.
setSocketTimeout
(
TIMEOUT
*
1000
).
build
();
request
.
setConfig
(
config
);
// 获取请求返回消息
String
result
=
null
;
try
{
// 执行请求
CloseableHttpResponse
response
=
httpClient
.
execute
(
request
);
if
(
response
.
getStatusLine
().
getStatusCode
()
!=
HttpStatus
.
SC_OK
)
{
log
.
warn
(
"Response status code:"
+
response
.
getStatusLine
().
getStatusCode
());
}
// 获取请求返回消息
result
=
EntityUtils
.
toString
(
response
.
getEntity
(),
UTF_8
);
response
.
close
();
httpClient
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"Http client error:"
+
e
.
getMessage
());
}
// 返回请求参数
return
result
;
}
public
static
String
doGet
(
String
uri
)
{
return
doGet
(
uri
,
null
,
null
);
}
public
static
String
doGet
(
String
uri
,
Map
<
String
,
Object
>
params
)
{
return
doGet
(
uri
,
params
,
null
);
}
public
static
String
doGet
(
String
uri
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
)
{
try
{
final
URIBuilder
uriBuilder
=
new
URIBuilder
(
new
URI
(
uri
));
uriBuilder
.
setCharset
(
StandardCharsets
.
UTF_8
);
if
(
params
!=
null
&&
params
.
size
()
>
0
)
{
params
.
forEach
((
k
,
v
)
->
uriBuilder
.
addParameter
(
k
,
v
.
toString
()));
}
final
HttpGet
httpGet
=
new
HttpGet
(
uriBuilder
.
build
());
return
send
(
getHttpClient
(),
httpGet
,
headers
);
}
catch
(
URISyntaxException
e
)
{
log
.
error
(
"Uri解析错误:"
+
e
.
getMessage
());
return
null
;
}
}
/**
* 发送multipart表单
*
* @param uri 请求路径
* @param params 表单体
* @param header 请求头
* @return resp
*/
public
static
String
multipartUpload
(
String
uri
,
Map
<
String
,
ContentBody
>
params
,
HashMap
<
String
,
String
>
header
)
{
final
HttpPost
httpPost
=
new
HttpPost
(
uri
);
// 设置请求体
final
MultipartEntityBuilder
builder
=
MultipartEntityBuilder
.
create
();
params
.
forEach
(
builder:
:
addPart
);
final
HttpEntity
entity
=
builder
.
build
();
httpPost
.
setEntity
(
entity
);
// 执行请求
return
send
(
getHttpClient
(),
httpPost
,
header
);
}
}
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