Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
933871ed
Commit
933871ed
authored
Sep 05, 2019
by
libin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
客服功能
parent
e40a12ff
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
505 additions
and
0 deletions
+505
-0
CustomerServiceDTO.java
...ain/java/com/xxfc/platform/im/dto/CustomerServiceDTO.java
+76
-0
CustomerService.java
...main/java/com/xxfc/platform/im/model/CustomerService.java
+78
-0
CustomerServiceVO.java
.../main/java/com/xxfc/platform/im/vo/CustomerServiceVO.java
+77
-0
CustomerServiceBiz.java
...ain/java/com/xxfc/platform/im/biz/CustomerServiceBiz.java
+123
-0
UserBiz.java
...erver/src/main/java/com/xxfc/platform/im/biz/UserBiz.java
+40
-0
CustomerServiceRepository.java
...com/xxfc/platform/im/repos/CustomerServiceRepository.java
+26
-0
CustomerServiceController.java
.../com/xxfc/platform/im/rest/CustomerServiceController.java
+39
-0
CustomerServiceAdminController.java
...latform/im/rest/admin/CustomerServiceAdminController.java
+46
-0
No files found.
xx-im/xx-im-api/src/main/java/com/xxfc/platform/im/dto/CustomerServiceDTO.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 10:35
*/
@Data
@Builder
(
toBuilder
=
true
)
@AllArgsConstructor
@NoArgsConstructor
public
class
CustomerServiceDTO
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
/**
* 客服名称
*/
private
String
name
;
/**
* 帐号
*/
private
String
account
;
/**
* 密码
*/
private
String
password
;
/**
* 客服头像
*/
private
String
icon
;
/**
* App id
*/
private
Integer
appUserId
;
/**
* im id
*/
private
String
imUserId
;
/**
* 区域id
*/
private
Integer
areaId
;
/**
* 区域名称
*/
private
String
areaName
;
/**
* 问候语句
*/
private
String
greeting
;
/**
* 客服类型
*/
private
Integer
type
;
/**
* 客服电话
*/
private
String
telphone
;
}
xx-im/xx-im-api/src/main/java/com/xxfc/platform/im/model/CustomerService.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.mongodb.morphia.annotations.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Field
;
/**
* @author libin
* @version 1.0
* @description 客服
* @data 2019/9/5 9:27
*/
@Data
@Builder
(
toBuilder
=
true
)
@AllArgsConstructor
@NoArgsConstructor
@Document
(
collection
=
"customer_service"
)
public
class
CustomerService
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
private
String
id
;
/**
* 客服名称
*/
private
String
name
;
/**
* 客服头像
*/
private
String
icon
;
/**
* App id
*/
@Field
(
"app_user_id"
)
private
Integer
appUserId
;
/**
* im id
*/
@Field
(
"im_user_id"
)
private
Integer
imUserId
;
/**
* 区域id
*/
@Field
(
"area_id"
)
private
Integer
areaId
;
/**
* 区域名称
*/
@Field
(
"area_name"
)
private
String
areaName
;
/**
* 问候语句
*/
private
String
greeting
;
/**
* 客服类型
*/
private
Integer
type
;
/**
* 客服电话
*/
private
String
telphone
;
/**
* 是事删除 true:删除状态 1:正常
*/
@Field
(
"is_del"
)
private
Boolean
isDel
;
@Field
(
"create_time"
)
private
Long
createTime
;
@Field
(
"update_time"
)
private
Long
updateTime
;
}
xx-im/xx-im-api/src/main/java/com/xxfc/platform/im/vo/CustomerServiceVO.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 10:37
*/
@Data
@Builder
(
toBuilder
=
true
)
@NoArgsConstructor
@AllArgsConstructor
public
class
CustomerServiceVO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
/**
* 客服名称
*/
private
String
name
;
/**
* 密码
*/
private
String
password
;
/**
* 客服头像
*/
private
String
icon
;
/**
* App id
*/
private
Integer
appUserId
;
/**
* im id
*/
private
Integer
imUserId
;
/**
* 区域id
*/
private
Integer
areaId
;
/**
* 区域名称
*/
private
String
areaName
;
/**
* 问候语句
*/
private
String
greeting
;
/**
* 客服类型
*/
private
Integer
type
;
/**
* 客服电话
*/
private
String
telphone
;
private
Long
createTime
;
private
Long
updateTime
;
}
xx-im/xx-im-server/src/main/java/com/xxfc/platform/im/biz/CustomerServiceBiz.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
biz
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.common.constant.UserConstant
;
import
com.github.wxiaoqi.security.common.exception.BaseException
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
com.mongodb.client.result.UpdateResult
;
import
com.xxfc.platform.im.dto.CustomerServiceDTO
;
import
com.xxfc.platform.im.model.CustomerService
;
import
com.xxfc.platform.im.model.User
;
import
com.xxfc.platform.im.repos.CustomerServiceRepository
;
import
com.xxfc.platform.im.vo.CustomerServiceVO
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Service
;
import
java.time.Instant
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
Query
.
query
;
import
static
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
Update
.
update
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 9:49
*/
@Service
@RequiredArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
public
class
CustomerServiceBiz
{
private
final
static
String
INIT_PASSWORD
=
"12345678"
;
private
final
static
String
NICK_PRE_NAME
=
"XXKF"
;
private
final
CustomerServiceRepository
customerServiceRepository
;
private
final
MongoTemplate
mongoTemplate
;
private
final
UserBiz
userBiz
;
public
CustomerServiceVO
findById
(
String
id
){
CustomerServiceVO
customerServiceVO
=
new
CustomerServiceVO
();
customerServiceRepository
.
findById
(
id
).
ifPresent
(
customerService
->
{
BeanUtils
.
copyProperties
(
customerService
,
customerServiceVO
);
});
Map
<
Integer
,
User
>
imMap
=
userBiz
.
findAllByImUserIds
(
Arrays
.
asList
(
customerServiceVO
.
getImUserId
()));
User
user
=
imMap
.
get
(
customerServiceVO
.
getImUserId
());
customerServiceVO
.
setPassword
(
user
.
getPassword
());
return
customerServiceVO
;
}
/**
* 添加客服
* @param customerServiceDTO
*/
public
void
addCustomerService
(
CustomerServiceDTO
customerServiceDTO
){
CustomerService
customerService
=
new
CustomerService
();
BeanUtils
.
copyProperties
(
customerServiceDTO
,
customerService
);
customerService
.
setCreateTime
(
Instant
.
now
().
toEpochMilli
());
String
password
=
new
BCryptPasswordEncoder
(
UserConstant
.
PW_ENCORDER_SALT
).
encode
(
INIT_PASSWORD
);
customerService
.
setName
(
String
.
format
(
"%s%s"
,
NICK_PRE_NAME
,
customerServiceDTO
.
getTelphone
()));
customerService
.
setIsDel
(
false
);
Map
<
String
,
Object
>
imMap
=
new
HashMap
<>(
2
);
imMap
.
put
(
"telephone"
,
customerServiceDTO
.
getTelphone
());
imMap
.
put
(
"password"
,
password
);
imMap
.
put
(
"nickname"
,
customerService
.
getName
());
BaseResponse
imResponse
=
userBiz
.
register
(
imMap
);
String
imResult
=
imResponse
.
getMessage
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
imResult
);
Map
<
String
,
Object
>
data
=
(
Map
<
String
,
Object
>)
jsonObject
.
get
(
"data"
);
Object
userId
=
data
.
get
(
"userId"
);
if
(
Objects
.
isNull
(
userId
)){
throw
new
BaseException
(
"注册失败"
);
}
customerService
.
setImUserId
((
Integer
)
userId
);
customerServiceRepository
.
save
(
customerService
);
}
public
List
<
CustomerServiceVO
>
findAll
()
{
List
<
CustomerServiceVO
>
customerServiceVOS
=
new
ArrayList
<>();
// List<CustomerService> customerServices = mongoTemplate.find(Query.query(Criteria.where("isDel").is(false)), CustomerService.class);
List
<
CustomerService
>
customerServices
=
customerServiceRepository
.
findByIsDelEquals
(
false
);
CustomerServiceVO
customerServiceVO
;
if
(
CollectionUtils
.
isNotEmpty
(
customerServices
)){
List
<
Integer
>
imUserIds
=
customerServices
.
stream
().
map
(
CustomerService:
:
getImUserId
).
collect
(
Collectors
.
toList
());
Map
<
Integer
,
User
>
imMap
=
userBiz
.
findAllByImUserIds
(
imUserIds
);
for
(
CustomerService
customerService
:
customerServices
)
{
customerServiceVO
=
new
CustomerServiceVO
();
BeanUtils
.
copyProperties
(
customerService
,
customerServiceVO
);
User
user
=
imMap
.
get
(
customerService
.
getImUserId
());
if
(
Objects
.
nonNull
(
user
)){
customerServiceVO
.
setPassword
(
user
.
getPassword
());
}
customerServiceVOS
.
add
(
customerServiceVO
);
}
}
return
customerServiceVOS
;
}
/**
* 删除客服
* @param id
* @param imUserId
*/
public
void
updateCustomerServiceIsDelToTrue
(
String
id
,
Integer
imUserId
){
Query
query
=
query
(
Criteria
.
where
(
"_id"
).
is
(
id
));
Update
update
=
update
(
"is_del"
,
true
).
set
(
"update_time"
,
Instant
.
now
().
toEpochMilli
());
UpdateResult
customer_service
=
mongoTemplate
.
updateFirst
(
query
,
update
,
Map
.
class
,
"customer_service"
);
userBiz
.
deleteById
(
imUserId
);
}
}
xx-im/xx-im-server/src/main/java/com/xxfc/platform/im/biz/UserBiz.java
View file @
933871ed
...
@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSONObject;
import
com.github.wxiaoqi.security.admin.feign.UserFeign
;
import
com.github.wxiaoqi.security.admin.feign.UserFeign
;
import
com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO
;
import
com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO
;
import
com.github.wxiaoqi.security.admin.vo.ImiVo
;
import
com.github.wxiaoqi.security.admin.vo.ImiVo
;
import
com.github.wxiaoqi.security.common.constant.UserConstant
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.mongodb.client.result.UpdateResult
;
import
com.mongodb.client.result.UpdateResult
;
import
com.xxfc.platform.im.model.User
;
import
com.xxfc.platform.im.model.User
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
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
;
...
@@ -17,6 +19,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
...
@@ -17,6 +19,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
@@ -27,7 +30,10 @@ import java.net.HttpURLConnection;
...
@@ -27,7 +30,10 @@ import java.net.HttpURLConnection;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@Component
@Component
@Slf4j
@Slf4j
...
@@ -229,4 +235,38 @@ public class UserBiz {
...
@@ -229,4 +235,38 @@ public class UserBiz {
return
imiVo
;
return
imiVo
;
}
}
/**
*根据 id 批量查询
* @param imUserIds
* @return
*/
public
Map
<
Integer
,
User
>
findAllByImUserIds
(
List
<
Integer
>
imUserIds
)
{
Map
<
Integer
,
User
>
imUserMap
=
new
HashMap
<>(
imUserIds
.
size
());
List
<
User
>
users
=
mongoTemplate
.
find
(
Query
.
query
(
Criteria
.
where
(
"id"
).
in
(
imUserIds
)),
User
.
class
);
if
(
CollectionUtils
.
isEmpty
(
users
)){
return
imUserMap
;
}
imUserMap
=
users
.
stream
().
collect
(
Collectors
.
toMap
(
User:
:
getId
,
Function
.
identity
()));
return
imUserMap
;
}
/**
* 更新Im 密码
* @param telphone
* @param password
*/
public
void
updatePasswordByPhone
(
String
telphone
,
String
password
){
Query
query
=
Query
.
query
(
Criteria
.
where
(
"phone"
).
is
(
telphone
));
password
=
new
BCryptPasswordEncoder
(
UserConstant
.
PW_ENCORDER_SALT
).
encode
(
password
);
Update
update
=
Update
.
update
(
"password"
,
password
);
mongoTemplate
.
updateFirst
(
query
,
update
,
Map
.
class
,
"user"
);
}
/**
* 删除 im
* @param imUserId
*/
public
void
deleteById
(
Integer
imUserId
)
{
mongoTemplate
.
remove
(
Query
.
query
(
Criteria
.
where
(
"id"
).
is
(
imUserId
)),
User
.
class
);
}
}
}
xx-im/xx-im-server/src/main/java/com/xxfc/platform/im/repos/CustomerServiceRepository.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
repos
;
import
com.xxfc.platform.im.model.CustomerService
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 10:55
*/
@Repository
public
interface
CustomerServiceRepository
extends
MongoRepository
<
CustomerService
,
String
>
{
/**
* 查询客服
* @param isDel 删除状态
* @return
*/
List
<
CustomerService
>
findByIsDelEquals
(
Boolean
isDel
);
}
xx-im/xx-im-server/src/main/java/com/xxfc/platform/im/rest/CustomerServiceController.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
rest
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.xxfc.platform.im.biz.CustomerServiceBiz
;
import
com.xxfc.platform.im.vo.CustomerServiceVO
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 10:31
*/
@RestController
@RequiredArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
@RequestMapping
(
"/app/unauth/customer_service"
)
public
class
CustomerServiceController
{
private
final
CustomerServiceBiz
customerServiceBiz
;
@GetMapping
(
"/list"
)
public
ObjectRestResponse
<
List
<
CustomerServiceVO
>>
findAll
(){
List
<
CustomerServiceVO
>
customerServiceVOS
=
customerServiceBiz
.
findAll
();
return
ObjectRestResponse
.
succ
(
customerServiceVOS
);
}
@GetMapping
(
"/{id}"
)
public
ObjectRestResponse
<
CustomerServiceVO
>
findById
(
@PathVariable
(
value
=
"id"
)
String
id
){
CustomerServiceVO
customerServiceVO
=
customerServiceBiz
.
findById
(
id
);
return
ObjectRestResponse
.
succ
(
customerServiceVO
);
}
}
xx-im/xx-im-server/src/main/java/com/xxfc/platform/im/rest/admin/CustomerServiceAdminController.java
0 → 100644
View file @
933871ed
package
com
.
xxfc
.
platform
.
im
.
rest
.
admin
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.xxfc.platform.im.biz.CustomerServiceBiz
;
import
com.xxfc.platform.im.biz.UserBiz
;
import
com.xxfc.platform.im.dto.CustomerServiceDTO
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 10:32
*/
@RestController
@RequiredArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
@RequestMapping
(
"/admin/customer_service"
)
public
class
CustomerServiceAdminController
{
private
final
CustomerServiceBiz
customerServiceBiz
;
private
final
UserBiz
userBiz
;
@PostMapping
(
"/add"
)
public
ObjectRestResponse
<
Void
>
addCustomerService
(
@RequestBody
CustomerServiceDTO
customerServiceDTO
){
customerServiceBiz
.
addCustomerService
(
customerServiceDTO
);
return
ObjectRestResponse
.
succ
();
}
@PutMapping
(
"/update_password/{telphone}/{password}"
)
public
ObjectRestResponse
<
Void
>
updateCustomerService
(
@PathVariable
(
value
=
"telphone"
)
String
telphone
,
@PathVariable
(
value
=
"password"
)
String
password
){
userBiz
.
updatePasswordByPhone
(
telphone
,
password
);
return
ObjectRestResponse
.
succ
();
}
@DeleteMapping
(
"/delete/{id}/{imUserId}"
)
public
ObjectRestResponse
<
Void
>
deleteCustomerService
(
@PathVariable
(
value
=
"id"
)
String
id
,
@PathVariable
(
value
=
"imUserId"
)
Integer
imUserId
){
customerServiceBiz
.
updateCustomerServiceIsDelToTrue
(
id
,
imUserId
);
return
ObjectRestResponse
.
succ
();
}
}
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