Java在线咨询,多人咨询。
1、客服登录:客服有客服ID,单位ID:
WorkerVO workerVO = (WorkerVO) req.getSession().getAttribute("workerVO");
WorkerVO workerVO = (WorkerVO) req.getSession().getAttribute("workerVO");
if(workerVO==null){
workerVO = new WorkerVO();
String workerid = req.getParameter("workerid"); //单位ID
String userid = req.getParameter("userid"); //用户ID
if(!StringUtil.isBlank(workerid)){
boolean b = WorkerLogService.getWorker(workerid, workerVO); //获取单位信息
if(b){
//登陆成功
workerVO.setStartDate((new Date()).getTime());
if(!StringUtil.isBlank(userid)){
DeptService deptService = new DeptService();
OrgUserVO userVO = deptService.getOrgUser(userid); //获取用户信息
workerVO.setUserId(userid);
if(userVO!=null){
workerVO.setUserName(userVO.getUserName());
}
}
//1. get map
// key-userkey value-workersMap workersMap<String,Map> ------String 为单位id,
//--- Map为客服人员集合,Map<String,Object> ,key为客服Id, value为客服人员对象
//(客服人员ID,客服人员姓名,单位id ,单位名称 ,状态(1在线、2忙碌、3离线),在线——1在咨询中,2空闲,如果状态是不在线:值为0)。
super.init(config);
ServletContext
application=this.getServletContext();
//得到Application对象
Map<String,Map> workersMap = (Map)application.getAttribute("workersKey");
if(workersMap == null){ //判断Map是否为空
//初始化
Map<String,Map> workerMap = new Hashtable<String,Map>();
Map<String,Object> childWorkerMap = new Hashtable<String, Object>();
WorkerOnlineVO onlineWorker=new WorkerOnlineVO();
onlineWorker.setDeptId(workerVO.getDeptNo().toString());//单位Id
onlineWorker.setDeptName(workerVO.getDeptName());
onlineWorker.setWorkerUserId(workerVO.getUserId());
onlineWorker.setWorkerUserName(workerVO.getUserName());
onlineWorker.setState("1");
onlineWorker.setConsultate("2");
childWorkerMap.put(workerVO.getUserId(), onlineWorker);
workerMap.put(workerVO.getDeptNo().toString(), childWorkerMap);
application.setAttribute("workersKey", workerMap);
}else{
Map<String,Object> childWorkerMap=workersMap.get(workerVO.getDeptNo());
WorkerOnlineVO workerOnline=(WorkerOnlineVO) childWorkerMap.get(workerVO.getUserId());
if(workerOnline==null){
WorkerOnlineVO onlineWorker=new WorkerOnlineVO();
onlineWorker.setDeptId(workerVO.getDeptNo().toString());
onlineWorker.setDeptName(workerVO.getDeptName());
onlineWorker.setWorkerUserId(workerVO.getUserId());
onlineWorker.setWorkerUserName(workerVO.getUserName());
onlineWorker.setState("1");
onlineWorker.setConsultate("2");
childWorkerMap.put(workerVO.getUserId(), onlineWorker);
workersMap.put(workerVO.getDeptNo().toString(), childWorkerMap);
//application.setAttribute("workersKey", workersMap);
}else{
workerOnline.setState("1");
workerOnline.setConsultate("2");
childWorkerMap.put(workerVO.getUserId(), workerOnline);
workersMap.put(workerVO.getDeptNo().toString(), childWorkerMap);
//
application.setAttribute("workersKey", workersMap);
}
}
req.getSession().setAttribute("workerVO", workerVO);
OnlineStatusVO.WORKER_QUESTER_MAP.put(workerid, new ArrayList<QuesterVO>());
OnlineStatusVO.WORKER_VO_MAP.put(workerid, workerVO);
req.getRequestDispatcher("../worker.jsp").forward(req, res);
}else{
res.sendRedirect("../worker_index.jsp?flag=1");
}
}else if(!StringUtil.isBlank(userid)){
if("1".equals(userid)){
workerVO.setId("0");
workerVO.setDeptName("技术支持");
workerVO.setDeptNo("0");
workerVO.setState("1");
workerVO.setUserId(userid);
req.getSession().setAttribute("workerVO", workerVO);
OnlineStatusVO.WORKER_QUESTER_MAP.put("0", new ArrayList<QuesterVO>());
OnlineStatusVO.WORKER_VO_MAP.put("0", workerVO);
req.getRequestDispatcher("../worker.jsp").forward(req, res);
}
}else{
res.sendRedirect("../worker_index.jsp?flag=1");
}
}else{ //workerVO != null
if(StringUtil.isBlank(OnlineStatusVO.WORKER_QUESTER_MAP.get(workerVO.getId()))){
OnlineStatusVO.WORKER_QUESTER_MAP.put(workerVO.getId(), new ArrayList<QuesterVO>());
}
if(StringUtil.isBlank(OnlineStatusVO.WORKER_VO_MAP.get(workerVO.getId()))){
System.out.println("===OnlineStatusVO.WORKER_VO_MAP.get======");
OnlineStatusVO.WORKER_VO_MAP.put(workerVO.getId(), workerVO);
}
req.getRequestDispatcher("../worker.jsp").forward(req, res);
}
1、咨询者咨询:单位ID:
1、咨询者咨询:单位ID:
String workerId = req.getParameter("workerId"); //单位ID
String outmsg = "";
if(StringUtil.isBlank(workerId)){
Log.error("---单位Id为空------");
}else{
super.init(config);
ServletContext
application=this.getServletContext();
Map<String,Map> workersMap = (Map)application.getAttribute("workersKey");
if(workersMap==null){ //如果workersMap为空
outmsg="请电话咨询,电话号码为:XXXXX";
}else{
Map<String,WorkerOnlineVO> childWorkerMap =workersMap.get(workerId);
if(childWorkerMap==null){
outmsg="请电话咨询,电话号码为:XXXXX";
}else{
//boolean flagTel=false; //无客服人员在线
String workerUserIdTemp="";
Set<String> key = childWorkerMap.keySet();
for (Iterator it = key.iterator(); it.hasNext();) {
WorkerOnlineVO workerOnlineVo =childWorkerMap.get((String)it.next());
//状态(1在线、2忙碌、3离线),在线——1在咨询中,2空闲,如果状态是不在线:值为0
//安排人员的优先级:在线 --空闲 》在线--咨询中 ,其他条件不符合。
if(workerOnlineVo.getState().equals("1")&& workerOnlineVo.getConsultate().equals("2")){
//在线 --空闲 ------------优先级最高
workerUserIdTemp=workerOnlineVo.getWorkerUserId();
break;
}
else if(workerOnlineVo.getState().equals("1")&& workerOnlineVo.getConsultate().equals("1")){
//在线--咨询中
if(workerUserIdTemp.equals("")){
workerUserIdTemp=workerOnlineVo.getWorkerUserId();
}
}
}
if(workerUserIdTemp.equals("")){
outmsg="请电话咨询,电话号码为:XXXXX";
}else{
WorkerOnlineVO workerOnlineVo = childWorkerMap.get(workerUserIdTemp);
workerOnlineVo.setState("1");
workerOnlineVo.setConsultate("1");
childWorkerMap.put(workerOnlineVo.getWorkerUserId(), workerOnlineVo);
workersMap.put(workerId, childWorkerMap); //和原来的Map一样
//application.setAttribute("workersKey", workersMap);
outmsg = "您好,请问有什么可以帮助您的吗?";
QuesterVO questerVO = (QuesterVO) req.getSession().getAttribute("questerVO");
if(questerVO==null || !workerId.equals(questerVO.getWorkerId())){
OnlineStatusVO.WORKER_USER.put("workerUser", workerOnlineVo);
questerVO = QuesterLogService.getQuester(workerId); //必须使用人id
questerVO.setWorkerUserId(workerOnlineVo.getWorkerUserId());
req.getSession().setAttribute("questerVO", questerVO);
OnlineStatusVO.WORKER_QUESTER_MAP.get(workerId).add(questerVO);
OnlineStatusVO.QUESTER_VO_MAP.put(questerVO.getId(), questerVO);
req.setAttribute("workerOnlineVo", workerOnlineVo);
}
}
req.setAttribute("outmsg", outmsg);
req.getRequestDispatcher("/quester.jsp").forward(req, res);
}
}
}
3、中间类:
3、中间类:
public class OnlineStatusVO {
public static Map<String,WorkerVO> WORKER_VO_MAP = new HashMap<String,WorkerVO>();public static Map<String,QuesterVO> QUESTER_VO_MAP = new HashMap<String,QuesterVO>();public static Map<String, List<QuesterVO>> WORKER_QUESTER_MAP = new HashMap<String, List<QuesterVO>>();public static Map<String, WorkerOnlineVO> WORKER_USER = new HashMap<String, WorkerOnlineVO>();
}