ChatAction.java
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:6k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. //Created by MyEclipse Struts
  2. // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
  3. package com.oa.module.communicate.comm.chat;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.servlet.http.HttpSession;
  11. import org.apache.struts.action.ActionForm;
  12. import org.apache.struts.action.ActionForward;
  13. import org.apache.struts.action.ActionMapping;
  14. import org.apache.struts.actions.DispatchAction;
  15. import com.oa.module.communicate.comm.Tchat;
  16. import com.oa.module.office.user.Tuser;
  17. /**
  18.  * 即时通讯 action
  19.  * MyEclipse Struts Creation date: 01-29-2008
  20.  * 
  21.  * XDoclet definition:
  22.  * 
  23.  * @struts.action parameter="task" validate="true"
  24.  */
  25. public class ChatAction extends DispatchAction {
  26. // --------------------------------------------------------- Instance
  27. // Variables
  28. private ChatIntefer chatinter;
  29. // --------------------------------------------------------- Methods
  30. /**
  31.  * Method execute
  32.  * 
  33.  * @param mapping
  34.  * @param form
  35.  * @param request
  36.  * @param response
  37.  * @return ActionForward
  38.  */
  39. public ActionForward chat(ActionMapping mapping, ActionForm form,
  40. HttpServletRequest request, HttpServletResponse response) {
  41. // 所有部门
  42. List deptlist = chatinter.selectalldept();
  43. // 所有用户
  44. List userlist = chatinter.selecttalluser();
  45. request.setAttribute("deptlist", deptlist);
  46. request.setAttribute("userlist", userlist);
  47. HttpSession session = request.getSession();
  48. Tuser user = (Tuser)session.getAttribute("user");
  49.  request.setAttribute("uno",String.valueOf(user.getUno()));
  50.  request.setAttribute("uname",user.getUname());
  51. // 所有在线用户
  52. List onlinelist = PubVar.onlineUserList;
  53. request.setAttribute("onlinelist", onlinelist);
  54. return mapping.findForward("chat");
  55. }
  56. public ActionForward online(ActionMapping mapping, ActionForm form,
  57. HttpServletRequest request, HttpServletResponse response) {
  58. PrintWriter out = null;
  59. try {
  60. out = response.getWriter();
  61. } catch (IOException e) {
  62. e.printStackTrace();
  63. }
  64. String text = "";
  65. List list = PubVar.onlineUserList;
  66. for (int i = 0; i < list.size(); i++) {
  67. Tuser userinfo = (Tuser) list.get(i);
  68. String userid = String.valueOf(userinfo.getUno());
  69. if (text != "") {
  70. text = text + "," + userid;
  71. } else {
  72. text = userid;
  73. }
  74. }
  75. out.println(text);
  76. return null;
  77. }
  78. public ActionForward read(ActionMapping mapping, ActionForm form,
  79. HttpServletRequest request, HttpServletResponse response) {
  80. String reciever=request.getParameter("sender");
  81. List chatlist=chatinter.read(reciever);
  82. PrintWriter out = null;
  83. try {
  84. out = response.getWriter();
  85. } catch (IOException e) {
  86. e.printStackTrace();
  87. }
  88. for(int i=0;i<chatlist.size();i++){
  89. Map map=(Map)chatlist.get(i);
  90. String sender=map.get("uname").toString();
  91. String content =map.get("ccontent").toString();
  92. String date=map.get("csendtime").toString();
  93. String id=map.get("cisread").toString();
  94. out.print(sender);
  95. out.print("&nbsp;&nbsp;");
  96. out.print(date);
  97. out.print("<br><br>");
  98. out.print(content);
  99. out.print("<br><br>");
  100. //修改未读字段为已读字段
  101. chatinter.updateisread(id);
  102. }
  103. return null;
  104. }
  105. public ActionForward history(ActionMapping mapping, ActionForm form,
  106. HttpServletRequest request, HttpServletResponse response) {
  107. String id = request.getParameter("id");
  108. System.out.println(id);
  109. List history=chatinter.selecthistory(request,id);
  110. request.setAttribute("history",history);
  111. return mapping.findForward("history");
  112. }
  113. public ActionForward save(ActionMapping mapping, ActionForm form,
  114. HttpServletRequest request, HttpServletResponse response) {
  115. String content=request.getParameter("content");
  116. String sender=request.getParameter("sender");
  117. String getter=request.getParameter("getter");
  118. String date=request.getParameter("date");
  119. String chattype=request.getParameter("chattype");
  120. if(chattype.equals("0")){
  121. Tchat chat=new Tchat();
  122. chat.setCcontent(content);
  123. chat.setCsendid(Integer.parseInt(sender));
  124. chat.setCaccepid(getter);
  125. chat.setCsendtime(date);
  126. chat.setCisread("0");
  127. chat.setCsendtype(chattype);
  128. chatinter.save(chat);
  129. }else if(chattype.equals("1")){
  130. boolean fl=false;//设个标志
  131. List userlist=chatinter.userbydept(getter);//查找该部门下的所有用户
  132. for(int i=0;i<userlist.size();i++){
  133. Tchat chat=new Tchat();
  134. Map map=(Map)userlist.get(i);
  135. String userid=map.get("uno").toString();
  136. if(!userid.equals(sender)){
  137. if(!fl){
  138. chat.setFlag("1");//表示下面的都是相同的content
  139. fl=true;
  140. }
  141. chat.setCcontent(content);
  142. chat.setCsendid(Integer.parseInt(sender));
  143. chat.setCaccepid(userid);
  144. chat.setCsendtime(date);
  145. chat.setCisread("0");
  146. chat.setCsendtype(chattype);
  147. chatinter.save(chat);
  148. }
  149. }
  150. }else if(chattype.equals("2")){
  151. boolean fl=false;//设个标志
  152. List userlist=chatinter.selecttalluser();//查找全公司员工
  153. for(int i=0;i<userlist.size();i++){
  154. Tchat chat=new Tchat();
  155. Map map=(Map)userlist.get(i);
  156. String userid=map.get("uno").toString();
  157. if(!userid.equals(sender)){
  158. if(!fl){
  159. chat.setFlag("1");//表示下面的都是相同的content
  160. fl=true;
  161. }
  162. chat.setCcontent(content);
  163. chat.setCsendid(Integer.parseInt(sender));
  164. chat.setCaccepid(userid);
  165. chat.setCsendtime(date);
  166. chat.setCisread("0");
  167. chat.setCsendtype(chattype);
  168. chatinter.save(chat);
  169. }
  170. }
  171. }
  172. return null;
  173. }
  174. public ChatIntefer getChatinter() {
  175. return chatinter;
  176. }
  177. public void setChatinter(ChatIntefer chatinter) {
  178. this.chatinter = chatinter;
  179. }
  180. }