半点优化网 http://www.bdxc.net/
当前位置首页 > 网站技术问题> 正文

谁有论坛上站内信实现jsp structs2源码啊

2022-05-27 02:41:01 暂无评论 278 网站技术问题 有论坛   源码   structs2

import java.io.*;import java.util.List;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.struts2.ServletActionContext;import com.credit.proj.entity.FileForm;import com.credit.proj.entity.Message;import com.credit.proj.entity.VMessage;import com.credit.publicmodel.commons.BaseAction;import com.credit.publicmodel.commons.Constants;import com.credit.publicmodel.message.service.MessageService;import com.credit.publicmodel.permission.security.userDetails.UserInfo;import com.credit.publicmodel.util.DateUtil;import com.credit.publicmodel.util.FileUtil;import com.credit.publicmodel.util.JsonUtil;/** * @funciton 消息处理 * * @author credit004 * */public class MessageAction extends BaseAction implements Constants{ private static final long serialVersionUID = 1L; private final Log log = LogFactory.getLog(getClass()); private int start; private int limit; private MessageService messageService; // private int msgType; private String sendToId; private String piKey; private String title; private String content; private int id; private int isRead; // private int processType = 0; private int msgType; private String title_S = ; private int msgType_S = 0; private String title_SS = ; private int msgType_SS = 0; /*文件上传*/ private File fileUpload;//上传文件 如若要设置原型的话,请注意 private String fileName;//上传的名字 如若要设置原型的话,请注意 private String contentType;//上传的类型 如若要设置原型的话,请注意 private int global_msgId;//附件下载(列表) private int downId;//下载附件 private int del_msgId;//删除文件,设置message表 标识 FileForm ff = null; /**所有新消息*/ public void getAllNewMessage() throws Exception{ UserInfo ui = (UserInfo)this.getSession().getAttribute(userDetails); String userId = %,+String.valueOf(ui.getId())+,%; int totalNumber = messageService.getReadMessageAmount(userId, 0); List<VMessage> list = messageService.getUserReadMessageForPages(userId, start, limit,0); JsonUtil.jsonFromList(list,totalNumber); } /**轮询*/ public int countMessage(){ UserInfo userInfo = (UserInfo)this.getSession().getAttribute(userDetails); String userId = %,+String.valueOf(userInfo.getId())+,%; int count = messageService.getReadMessageAmount(userId,0); return count; } /**发送消息 jiang*/ public String sendMessage() throws Exception{ Message msg = new Message(); FileForm ff = new FileForm(); UserInfo userInfo = (UserInfo)this.getSession().getAttribute(userDetails); //上传文件存储的名字 String storeFileName = ; //上传路径 String path = ; // judge boolean isUploadOk = false; String sendToId = ,+this.sendToId+,; /*消息*/ msg.setPiKey(piKey); msg.setType(msgType); msg.setTitle(title); msg.setContent(content); msg.setCreateTime(DateUtil.getNowDateTime()); msg.setSendTime(DateUtil.getNowDateTime(yyyy-MM-dd (E) HH:mm)); msg.setSendFrom(userInfo.getId()); msg.setProcessType(Constants.PROCESS_TYPE_BG); msg.setTakePeople(sendToId); /*文件上传 上传了文件*/ if(fileUpload != null){ storeFileName = msg+DateUtil.getNowDateTime(yyyyMMddHHmmssSSS)+FileUtil.getExtention(fileName); path = /upload/+userInfo.getUsername()+/msg/appendix/+storeFileName; String realPath = ServletActionContext.getServletContext() .getRealPath(path); File storeFile = new File(realPath); System.out.println(文件长度=+fileUpload.length()); ff.setContentType(contentType); ff.setIsDel(0); ff.setSize(fileUpload.length()); ff.setName(fileName); ff.setPath(path); ff.setSendToId(sendToId); ff.setTitle(userInfo.getName()+ 提供的附件); ff.setType(1);//1 代表消息上传附件 待议 ff.setUploaderId(userInfo.getId()); ff.setUpTime(DateUtil.getNowDateTime()); isUploadOk = FileUtil.fileUpload(fileUpload, storeFile, this.BUFFER_SIZE_MSG); msg.setHasAppendix(1);//设置有附件 if(!isUploadOk){ ff = null; } }else{ ff = null;//没上传文件 } messageService.sendMessage(msg,ff); return null; } /**删除消息 jiang*/ public void delMessage() throws Exception{ messageService.delMessage(id); id = 0;//使用完后---初始化 } /**得到详细信息 jiang*/ public void getDetailMessage() throws Exception{ messageService.getDetailMessage(id); messageService.readMessage(id, 1);//设置已读 id = 0;//使用完后--初始化 } /**设置已读 作废 jiang*/ public void readMessage() throws Exception{ log.info(isRead==+isRead); } /**已读通知 已作废 jiang*/ public void getReadMesage() throws Exception{ UserInfo ui = (UserInfo)this.getSession().getAttribute(userDetails); String userId = %,+String.valueOf(ui.getId())+,%; int totalNumber = messageService.getReadMessageAmount(userId,1); List<VMessage> list = messageService.getUserReadMessageForPages(userId, start, limit,1); JsonUtil.jsonFromList(list,totalNumber); } /**收消息盒子*/ public void getMessageBox() throws Exception{ UserInfo ui = (UserInfo)this.getSession().getAttribute(userDetails); String userId = %,+String.valueOf(ui.getId())+,%; int isDel = 0; List<VMessage> list = null; int totalNumber = 0; // System.out.println(show me the state+isRead+processType+msgType); if(title_S.equals() && msgType_S == 0){ totalNumber = messageService.getAllMessageAmout(userId, isDel); list = messageService.getUserMessageForPages(userId, isDel, start, limit); }else{ String title_S = %+this.title_S+%; Object[] params = {userId,title_S,this.title_S,msgType_S,msgType_S,}; totalNumber = messageService.getSearchMessageAmount(params); list = messageService.getUserSearchMessageForPages(params, start, limit); } JsonUtil.jsonFromList(list,totalNumber); } /**发消息盒子 jiang*/ public void sendMessageBox() throws Exception{ UserInfo ui = (UserInfo)this.getSession().getAttribute(userDetails); String title_SS = %+this.title_SS+%; Object[] params = {ui.getId(),title_SS,this.title_SS,msgType_SS,msgType_SS}; //here codes int totalNumber = messageService.getUserSendMessageAmount(params); List<VMessage> list = messageService.getUserSendMessageForPages(params, start, limit); JsonUtil.jsonFromList(list,totalNumber); } /*********************************************************************/ /** ################# 附件下载 ##################### **/ /*********************************************************************/ /**附件下载列表*/ public void showDownload() throws Exception{ int isDel = 0; System.out.println(global_msgId=+global_msgId); int totalNumber = messageService.getDownloadAmount(global_msgId, isDel); List<FileForm> list = messageService.getDownload(global_msgId, isDel, start, limit); JsonUtil.jsonFromList(list,totalNumber); } /*********************************************************************/ /**下载--获得输入流*/ public InputStream getMsgDownload(){ // FileForm ff = messageService.getFile(downId); String path = ff.getPath(); System.out.println(ff==+ff.getPath()); return ServletActionContext.getServletContext().getResourceAsStream(path); } /**下载--默认*/ public String msgDownload(){ ff = messageService.getFile(downId); return success; } /**下载--向struts.xml内传值 jiang*/ public String getDownloadFileName(){// FileForm ff = messageService.getFile(downId); String fileName = ff.getName(); try { fileName = new String(fileName.getBytes(),ISO8859-1); if(ff != null){ return fileName; }else{ return ; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return error; } /*********************************************************************/ /**删除 下载文件---只是在数据库标识已删除 jiang*/ public void delMsgDownload() { String jsonStr = ; try { messageService.delFile(downId,del_msgId); jsonStr = {success:true}; JsonUtil.writeJsonString(jsonStr); } catch (Exception e) { jsonStr = {success:false}; e.printStackTrace(); }finally{ JsonUtil.writeJsonStringNoException(jsonStr); } } /*****回收站*******/ public void delectedMessage() throws Exception{ UserInfo ui = (UserInfo)this.getSession().getAttribute(userDetails); String userId = %,+String.valueOf(ui.getId())+,%; int totalNumber = messageService.getAllMessageAmout(userId, 1); List<VMessage> list = messageService.getUserMessageForPages(userId, 1, start, limit); JsonUtil.jsonFromList(list,totalNumber); } /**从数据库中删除消息*/ public void removeMessage(){ String jstonStr = {success:false}; try { messageService.removeMessage(id); jstonStr = {success:true}; } catch (Exception e) { jstonStr = {success:false}; e.printStackTrace(); } JsonUtil.writeJsonStringNoException(jstonStr); } /*############################ getter and setters ##########################*/

你去csdn上问问,那里可能有人有

猜你喜欢