Commit 02f62bb4 authored by 刘文胜's avatar 刘文胜

1111

parent 3b1a1387
......@@ -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();
}
/**
* 获取
*
......
/**
* @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
*/
}
/**
* @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
*/
}
/**
* @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
*/
}
......@@ -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)
......
......@@ -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;
......
/**
* @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();
}
}
......@@ -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();
......
......@@ -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);
......
......@@ -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);
......
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 to comment