ChatAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:6k
源码类别:
Jsp/Servlet
开发平台:
Java
- //Created by MyEclipse Struts
- // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
- package com.oa.module.communicate.comm.chat;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.actions.DispatchAction;
- import com.oa.module.communicate.comm.Tchat;
- import com.oa.module.office.user.Tuser;
- /**
- * 即时通讯 action
- * MyEclipse Struts Creation date: 01-29-2008
- *
- * XDoclet definition:
- *
- * @struts.action parameter="task" validate="true"
- */
- public class ChatAction extends DispatchAction {
- // --------------------------------------------------------- Instance
- // Variables
- private ChatIntefer chatinter;
- // --------------------------------------------------------- Methods
- /**
- * Method execute
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- */
- public ActionForward chat(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- // 所有部门
- List deptlist = chatinter.selectalldept();
- // 所有用户
- List userlist = chatinter.selecttalluser();
- request.setAttribute("deptlist", deptlist);
- request.setAttribute("userlist", userlist);
- HttpSession session = request.getSession();
- Tuser user = (Tuser)session.getAttribute("user");
- request.setAttribute("uno",String.valueOf(user.getUno()));
- request.setAttribute("uname",user.getUname());
- // 所有在线用户
- List onlinelist = PubVar.onlineUserList;
- request.setAttribute("onlinelist", onlinelist);
- return mapping.findForward("chat");
- }
- public ActionForward online(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- PrintWriter out = null;
- try {
- out = response.getWriter();
- } catch (IOException e) {
- e.printStackTrace();
- }
- String text = "";
- List list = PubVar.onlineUserList;
- for (int i = 0; i < list.size(); i++) {
- Tuser userinfo = (Tuser) list.get(i);
- String userid = String.valueOf(userinfo.getUno());
- if (text != "") {
- text = text + "," + userid;
- } else {
- text = userid;
- }
- }
- out.println(text);
- return null;
- }
- public ActionForward read(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String reciever=request.getParameter("sender");
- List chatlist=chatinter.read(reciever);
- PrintWriter out = null;
- try {
- out = response.getWriter();
- } catch (IOException e) {
- e.printStackTrace();
- }
- for(int i=0;i<chatlist.size();i++){
- Map map=(Map)chatlist.get(i);
- String sender=map.get("uname").toString();
- String content =map.get("ccontent").toString();
- String date=map.get("csendtime").toString();
- String id=map.get("cisread").toString();
- out.print(sender);
- out.print(" ");
- out.print(date);
- out.print("<br><br>");
- out.print(content);
- out.print("<br><br>");
- //修改未读字段为已读字段
- chatinter.updateisread(id);
- }
- return null;
- }
- public ActionForward history(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String id = request.getParameter("id");
- System.out.println(id);
- List history=chatinter.selecthistory(request,id);
- request.setAttribute("history",history);
- return mapping.findForward("history");
- }
- public ActionForward save(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String content=request.getParameter("content");
- String sender=request.getParameter("sender");
- String getter=request.getParameter("getter");
- String date=request.getParameter("date");
- String chattype=request.getParameter("chattype");
- if(chattype.equals("0")){
- Tchat chat=new Tchat();
- chat.setCcontent(content);
- chat.setCsendid(Integer.parseInt(sender));
- chat.setCaccepid(getter);
- chat.setCsendtime(date);
- chat.setCisread("0");
- chat.setCsendtype(chattype);
- chatinter.save(chat);
- }else if(chattype.equals("1")){
- boolean fl=false;//设个标志
- List userlist=chatinter.userbydept(getter);//查找该部门下的所有用户
- for(int i=0;i<userlist.size();i++){
- Tchat chat=new Tchat();
- Map map=(Map)userlist.get(i);
- String userid=map.get("uno").toString();
- if(!userid.equals(sender)){
- if(!fl){
- chat.setFlag("1");//表示下面的都是相同的content
- fl=true;
- }
- chat.setCcontent(content);
- chat.setCsendid(Integer.parseInt(sender));
- chat.setCaccepid(userid);
- chat.setCsendtime(date);
- chat.setCisread("0");
- chat.setCsendtype(chattype);
- chatinter.save(chat);
- }
- }
- }else if(chattype.equals("2")){
- boolean fl=false;//设个标志
- List userlist=chatinter.selecttalluser();//查找全公司员工
- for(int i=0;i<userlist.size();i++){
- Tchat chat=new Tchat();
- Map map=(Map)userlist.get(i);
- String userid=map.get("uno").toString();
- if(!userid.equals(sender)){
- if(!fl){
- chat.setFlag("1");//表示下面的都是相同的content
- fl=true;
- }
- chat.setCcontent(content);
- chat.setCsendid(Integer.parseInt(sender));
- chat.setCaccepid(userid);
- chat.setCsendtime(date);
- chat.setCisread("0");
- chat.setCsendtype(chattype);
- chatinter.save(chat);
- }
- }
- }
- return null;
- }
- public ChatIntefer getChatinter() {
- return chatinter;
- }
- public void setChatinter(ChatIntefer chatinter) {
- this.chatinter = chatinter;
- }
- }