package action;

import java.util.List;

import util.MyJson;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

import entity.OaMail;
import entity.OaUser;
import biz.CommonBiz;

public class MailAction {
	private static final String TOSEND = "tosend";
	private static final String TORECEIVE = "toreceive";
	private static final String TOJUNK = "tojunk";
	private CommonBiz commonBiz;
	private OaMail mail;
	public CommonBiz getCommonBiz() {
		return commonBiz;
	}
	public void setCommonBiz(CommonBiz commonBiz) {
		this.commonBiz = commonBiz;
	}
	public OaMail getMail() {
		return mail;
	}
	public void setMail(OaMail mail) {
		this.mail = mail;
	}
	/**
	 * 跳转收件箱
	 * @return
	 */
	public String toReceive(){
		return TORECEIVE;
	}
	
	/**
	 * 跳转发件箱
	 * @return
	 */
	public String toSend(){
		return TOSEND;
	}
	
	/**
	 * 跳转发件箱
	 * @return
	 */
	public String toJunk(){
		return TOJUNK;
	}
	
	/**
	 * 查询当前用户的收件列表
	 * @return
	 */
	public String findMailList(){
		// 获取当前登录用户
		OaUser user = (OaUser) ActionContext.getContext().getSession().get("user");
		// 获取当前用户的收件列表
		List<OaMail> mailList=commonBiz.getOaMailDAO().getHibernateTemplate().find("from OaMail where oaUserByReceiver.uid=? and receiveDel=0 order by state asc,sendDate desc",user.getUid());
		String msg = "{totalCount:" + mailList.size() + ",result:";
		msg += MyJson.toJsonStr(mailList, "oaRole");
		msg += "}";
		ActionContext.getContext().put("msg", msg);
		return Action.SUCCESS;
	}
	
	/**
	 * 查询当前用户的发件列表
	 * @return
	 */
	public String findSendMailList(){
		// 获取当前登录用户
		OaUser user = (OaUser) ActionContext.getContext().getSession().get("user");
		// 获取当前用户的发件列表
		List<OaMail> mailList=commonBiz.getOaMailDAO().getHibernateTemplate().find("from OaMail where oaUserBySender.uid=? and sendDel=0",user.getUid());
		String msg = "{totalCount:" + mailList.size() + ",result:";
		msg += MyJson.toJsonStr(mailList, "oaRole");
		msg += "}";
		ActionContext.getContext().put("msg", msg);
		return Action.SUCCESS;
	}
	
	/**
	 * 查询当前用户的垃圾箱列表
	 * @return
	 */
	public String findJunkMailList(){
		// 获取当前登录用户
		OaUser user = (OaUser) ActionContext.getContext().getSession().get("user");
		// 获取当前用户的垃圾箱列表
		List<OaMail> mailList=commonBiz.getOaMailDAO().getHibernateTemplate().find("from OaMail where (sendDel=1 and oaUserBySender.uid=?) or (receiveDel=1 and oaUserByReceiver.uid=?)",new Object[]{user.getUid(),user.getUid()});
		String msg = "{totalCount:" + mailList.size() + ",result:";
		msg += MyJson.toJsonStr(mailList, "oaRole");
		msg += "}";
		ActionContext.getContext().put("msg", msg);
		return Action.SUCCESS;
	}
	
	/**
	 * 添加新邮件
	 * @return
	 */
	public String addMail(){
		commonBiz.getOaMailDAO().save(mail);
		ActionContext.getContext().put("msg", "{success:true,msg:'发送成功'}");
		return Action.SUCCESS;
	}
	
	/**
	 * 读取未读邮件,修改其状态
	 * @return
	 */
	public String readMail(){
		mail=commonBiz.getOaMailDAO().findById(mail.getId());
		mail.setState(1);
		commonBiz.getOaMailDAO().merge(mail);
		ActionContext.getContext().put("msg", "{success:true}");
		return Action.SUCCESS;
	}
	
	/**
	 * 临时删除邮件(修改发件状态)
	 * @return
	 */
	public String sendDeleteMail(){
		mail=commonBiz.getOaMailDAO().findById(mail.getId());
		mail.setSendDel(1);
		commonBiz.getOaMailDAO().merge(mail);
		ActionContext.getContext().put("msg", "{success:true,msg:'删除成功'}");
		return Action.SUCCESS;
	}
	
	/**
	 * 临时删除邮件(修改收件状态)
	 * @return
	 */
	public String receiveDeleteMail(){
		mail=commonBiz.getOaMailDAO().findById(mail.getId());
		mail.setReceiveDel(1);
		commonBiz.getOaMailDAO().merge(mail);
		ActionContext.getContext().put("msg", "{success:true,msg:'删除成功'}");
		return Action.SUCCESS;
	}
	
	/**
	 * 彻底删除邮件
	 * @return
	 */
	public String deleteMailSure(){
		// 获取当前登录用户
		OaUser user = (OaUser) ActionContext.getContext().getSession().get("user");
		// 获取一条邮件
		mail=commonBiz.getOaMailDAO().findById(mail.getId());
		// 如果删除的为收件
		if (user.getName().equals(mail.getOaUserByReceiver().getName())) {
			/*
			 * 判断发件状态是否为彻底删除
			 * 如果彻底删除,就将该条数据彻底删除
			 * 否则修改收件状态为2
			 */ 
			if (mail.getSendDel()==2) {
				commonBiz.getOaMailDAO().delete(mail);
			}else{
				mail.setReceiveDel(2);
				commonBiz.getOaMailDAO().merge(mail);
			}
		}
		// 如果删除的为发件
		if (user.getName().equals(mail.getOaUserBySender().getName())) {
			/*
			 * 判断收件状态是否为彻底删除
			 * 如果彻底删除,就将该条数据彻底删除
			 * 否则修改发件状态为2
			 */
			if (mail.getReceiveDel()==2) {
				commonBiz.getOaMailDAO().delete(mail);
			}else{
				mail.setSendDel(2);
				commonBiz.getOaMailDAO().merge(mail);
			}
		}
		ActionContext.getContext().put("msg", "{success:true,msg:'删除成功'}");
		return Action.SUCCESS;
	}
}
最近下载更多
lvdong2023  LV10 2023年5月18日
微信网友_5963854197018624  LV7 2023年4月6日
泓鼎168  LV20 2023年3月30日
cx123123  LV7 2022年5月17日
habiya  LV3 2022年3月15日
ewan007  LV30 2022年3月10日
微信网友_5845420553359360  LV4 2022年2月27日
wanglinddad  LV55 2021年11月6日
freeblow  LV2 2021年5月20日
and123456  LV11 2021年5月11日
最近浏览更多
1111112222  LV6 1月8日
lvyga1  LV2 2024年12月20日
WBelong  LV8 2024年12月5日
angaochong  LV5 2024年10月29日
lqzixi  LV4 2024年10月9日
cyd yyds  LV2 2024年8月5日
校园网  LV9 2024年8月4日
qwe6002  LV10 2024年5月24日
dzx199212  LV1 2024年5月22日
sunlea  LV20 2024年5月9日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友