Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
com.hdp.customerservice
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘文胜
com.hdp.customerservice
Commits
02f62bb4
Commit
02f62bb4
authored
Jun 18, 2015
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1111
parent
3b1a1387
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
191 additions
and
9 deletions
+191
-9
HistoryEntity.java
...ain/java/com/hdp/customerservice/model/HistoryEntity.java
+17
-0
HistoryRepository.java
...com/hdp/customerservice/repository/HistoryRepository.java
+25
-0
HistoryService.java
.../java/com/hdp/customerservice/service/HistoryService.java
+22
-0
HistoryServiceImpl.java
...a/com/hdp/customerservice/service/HistoryServiceImpl.java
+27
-0
MemberServiceImpl.java
...va/com/hdp/customerservice/service/MemberServiceImpl.java
+0
-2
CustomerManager.java
...va/com/hdp/customerservice/websocket/CustomerManager.java
+10
-0
HistoryHandler.java
...ava/com/hdp/customerservice/websocket/HistoryHandler.java
+66
-0
IMManager.java
...ain/java/com/hdp/customerservice/websocket/IMManager.java
+16
-7
WaiterManager.java
...java/com/hdp/customerservice/websocket/WaiterManager.java
+6
-0
MessageHandler.java
src/main/java/com/hdp/pi/wechat/handler/MessageHandler.java
+2
-0
No files found.
src/main/java/com/hdp/customerservice/model/HistoryEntity.java
View file @
02f62bb4
...
...
@@ -9,6 +9,8 @@ import javax.persistence.GenerationType;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
com.ibm.icu.util.Calendar
;
/**
* (pi_customerservice_history)
*
...
...
@@ -62,6 +64,21 @@ public class HistoryEntity implements java.io.Serializable {
@Column
(
name
=
"createat"
,
nullable
=
false
)
private
Date
createAt
;
public
HistoryEntity
(){}
public
HistoryEntity
(
Integer
entCode
,
String
openid
,
Long
workid
,
String
content
,
Integer
type
){
this
.
entCode
=
entCode
;
this
.
openId
=
openid
;
this
.
workId
=
workid
;
this
.
content
=
content
;
this
.
type
=
type
;
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
new
Date
());
this
.
year
=
c
.
get
(
Calendar
.
YEAR
);
this
.
month
=
c
.
get
(
Calendar
.
MONTH
)+
1
;
this
.
day
=
c
.
get
(
Calendar
.
DATE
);
this
.
createAt
=
c
.
getTime
();
}
/**
* 获取
*
...
...
src/main/java/com/hdp/customerservice/repository/HistoryRepository.java
0 → 100644
View file @
02f62bb4
/**
* @Title: WorksRepository.java
* @Package com.hdp.customerservice.repository
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午4:16:38
* @version V1.0
*/
package
com
.
hdp
.
customerservice
.
repository
;
import
org.springframework.stereotype.Repository
;
import
com.hdp.customerservice.model.HistoryEntity
;
@Repository
public
interface
HistoryRepository
extends
BaseRepository
<
HistoryEntity
,
Long
>{
/**
* @Title: WorksRepository.java
* @Package com.hdp.customerservice.repository
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午4:16:38
* @version V1.0
*/
}
src/main/java/com/hdp/customerservice/service/HistoryService.java
0 → 100644
View file @
02f62bb4
/**
* @Title: HistoryService.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月18日 下午3:38:40
* @version V1.0
*/
package
com
.
hdp
.
customerservice
.
service
;
import
com.hdp.customerservice.model.HistoryEntity
;
public
interface
HistoryService
extends
BaseService
<
HistoryEntity
,
Long
>{
/**
* @Title: HistoryService.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月18日 下午3:38:40
* @version V1.0
*/
}
src/main/java/com/hdp/customerservice/service/HistoryServiceImpl.java
0 → 100644
View file @
02f62bb4
/**
* @Title: HistoryServiceImpl.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月18日 下午3:39:18
* @version V1.0
*/
package
com
.
hdp
.
customerservice
.
service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.hdp.customerservice.model.HistoryEntity
;
@Service
@Transactional
(
readOnly
=
true
)
public
class
HistoryServiceImpl
extends
AbstractBaseServiceImpl
<
HistoryEntity
,
Long
>
implements
HistoryService
{
/**
* @Title: HistoryServiceImpl.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月18日 下午3:39:18
* @version V1.0
*/
}
src/main/java/com/hdp/customerservice/service/MemberServiceImpl.java
View file @
02f62bb4
...
...
@@ -8,12 +8,10 @@
*/
package
com
.
hdp
.
customerservice
.
service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.hdp.customerservice.model.MemberEntity
;
import
com.hdp.customerservice.repository.MemberRepository
;
@Service
@Transactional
(
readOnly
=
true
)
...
...
src/main/java/com/hdp/customerservice/websocket/CustomerManager.java
View file @
02f62bb4
...
...
@@ -9,6 +9,7 @@
package
com
.
hdp
.
customerservice
.
websocket
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
org.springframework.util.StringUtils
;
...
...
@@ -17,11 +18,20 @@ import com.hdp.pi.wechat.messages.AbstractMessage;
public
class
CustomerManager
{
private
static
LinkedBlockingQueue
<
AbstractMessage
>
queue
=
new
LinkedBlockingQueue
<
AbstractMessage
>();
private
static
ConcurrentHashMap
<
String
,
Customer
>
users
=
new
ConcurrentHashMap
<
String
,
Customer
>();
private
CustomerManager
(){}
public
static
void
pushMessage
(
AbstractMessage
message
){
try
{
queue
.
put
(
message
);
}
catch
(
InterruptedException
e
)
{
}
}
public
static
Customer
getUserByOpenId
(
String
openId
){
if
(
StringUtils
.
isEmpty
(
openId
)){
return
null
;
...
...
src/main/java/com/hdp/customerservice/websocket/HistoryHandler.java
0 → 100644
View file @
02f62bb4
/**
* @Title: HistoryHandler.java
* @Package com.hdp.customerservice.websocket
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月18日 下午3:35:38
* @version V1.0
*/
package
com
.
hdp
.
customerservice
.
websocket
;
import
java.io.IOException
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
javax.websocket.Session
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.hdp.customerservice.model.HistoryEntity
;
import
com.hdp.customerservice.service.HistoryService
;
@Component
public
class
HistoryHandler
{
/**
* @Title: HistoryHandler.java
* @Package com.hdp.customerservice.websocket
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月18日 下午3:35:38
* @version V1.0
*/
private
static
LinkedBlockingQueue
<
HistoryEntity
>
queue
=
new
LinkedBlockingQueue
<
HistoryEntity
>();
public
static
void
push
(
HistoryEntity
h
){
try
{
queue
.
put
(
h
);
}
catch
(
InterruptedException
e
)
{
}
}
@Autowired
private
void
hand
(
HistoryService
historyService
){
new
Thread
(
new
Runnable
()
{
//消息发射器
public
void
hand
(){
HistoryEntity
h
=
queue
.
poll
();
if
(
h
==
null
){
try
{
Thread
.
sleep
(
3000
);
}
catch
(
InterruptedException
e
)
{
}
}
try
{
historyService
.
save
(
h
);
}
catch
(
Throwable
e
){
}
}
@Override
public
void
run
()
{
while
(
true
){
hand
();
}
}
}).
start
();
}
}
src/main/java/com/hdp/customerservice/websocket/IMManager.java
View file @
02f62bb4
...
...
@@ -20,6 +20,7 @@ import org.apache.commons.logging.LogFactory;
import
org.springframework.util.StringUtils
;
import
com.alibaba.fastjson.JSONObject
;
import
com.hdp.customerservice.model.HistoryEntity
;
import
com.hdp.customerservice.websocket.model.Customer
;
import
com.hdp.customerservice.websocket.model.Waiter
;
import
com.hdp.pi.wechat.messages.AbstractMessage
;
...
...
@@ -47,8 +48,9 @@ public class IMManager {
}
public
static
void
pushMessage
(
AbstractMessage
message
){
CustomerManager
.
addUserIfNotExist
(
message
);
try
{
CustomerManager
.
pushMessage
(
message
);
queue
.
put
(
message
);
}
catch
(
InterruptedException
e
)
{
}
...
...
@@ -60,6 +62,10 @@ public class IMManager {
public
void
hand
(){
AbstractMessage
e
=
queue
.
poll
();
if
(
e
==
null
){
try
{
Thread
.
sleep
(
3000
);
}
catch
(
InterruptedException
e1
)
{
}
return
;
}
Customer
customer
=
CustomerManager
.
getUserByOpenId
(
e
.
openId
);
...
...
@@ -79,23 +85,26 @@ public class IMManager {
pushMessage
(
e
);
return
;
}
String
message
=
null
;
try
{
session
.
getBasicRemote
().
sendText
(
JSONObject
.
toJSONString
(
e
));
message
=
JSONObject
.
toJSONString
(
e
);
session
.
getBasicRemote
().
sendText
(
message
);
}
catch
(
IOException
e1
)
{
pushMessage
(
e
);
return
;
}
try
{
HistoryEntity
h
=
new
HistoryEntity
(
e
.
entCode
,
e
.
openId
,
Long
.
parseLong
(
waiter
.
id
),
message
,
1
);
HistoryHandler
.
push
(
h
);
}
catch
(
Throwable
e1
){
}
}
@Override
public
void
run
()
{
while
(
true
){
hand
();
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
}
}
}
}).
start
();
...
...
src/main/java/com/hdp/customerservice/websocket/WaiterManager.java
View file @
02f62bb4
...
...
@@ -36,6 +36,12 @@ public class WaiterManager {
waiters
.
put
(
waiter
.
id
,
waiter
);
}
public
static
void
removeWaiter
(
String
id
){
if
(!
StringUtils
.
isEmpty
(
id
)){
waiters
.
remove
(
id
);
}
}
public
static
Waiter
[]
getWaits
(){
Waiter
[]
ws
=
new
Waiter
[
waiters
.
size
()];
return
waiters
.
values
().
toArray
(
ws
);
...
...
src/main/java/com/hdp/pi/wechat/handler/MessageHandler.java
View file @
02f62bb4
...
...
@@ -53,6 +53,8 @@ public abstract class MessageHandler {
boolean
result
=
Boolean
.
TRUE
;
//默认为处理成功
AbstractMessage
entity
=
decode
(
message
);
//特有字段需子类重写
entity
.
msgType
=
msgType
;
//消息类型
entity
.
entCode
=
entCode
;
entity
.
appId
=
appId
;
deCommonInfo
(
entity
,
message
);
//处理通用字段
if
(
null
!=
entity
){
IMManager
.
pushMessage
(
entity
);
...
...
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