天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
8.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.DAL.Sys;
using QMAPP.Entity.Sys;
using QMFrameWork.Mail;
using Quartz;
using QMAPP.MD.Entity.Sys;
namespace QMAPP.BLL.Sys
{
/// <summary>
/// 超时提醒逻辑层对象
/// </summary>
public class OverTimeRemindBLL : BaseBLL,IJob
{
#region 判断当前用户是否有超出时间1提醒
/// <summary>
/// 判断当前用户是否有超出时间提醒
/// </summary>
/// <returns></returns>
public bool CheckCurrenUserOverTime1Remind()
{
string userId = this.LoginUser.UserID;
OverTimeRemindDAL dal = new OverTimeRemindDAL();
NoticeManageBll bmBll = new NoticeManageBll();
SIParamSetBLL paramSetBll = new SIParamSetBLL();
//默认是24小时
int OverTime1 = 24;
//获取支持交互参数对象
SIParamSet paramSet = paramSetBll.Get(new SIParamSet());
if (paramSet != null && paramSet.OverTime1 == 0)
{
OverTime1 = paramSet.OverTime1;
}
int count = 0;
List<OverTimeRemind> overTimeList = dal.GetOverTimeRemindList(userId);
if (overTimeList != null && overTimeList.Count > 0)
{
foreach (OverTimeRemind otr in overTimeList)
{
//如果超出时间1
//如果当前日期减去问题创建日期时插入一条提醒
if ((DateTime.Now - Convert.ToDateTime(otr.ActionTime)).TotalHours > OverTime1)
{
NoticeInfo notice = new NoticeInfo();
notice.NOTICETYPE = "1";
notice.USETIME = DateTime.Now.Date;
notice.OUTTIME = DateTime.Now.Date;
notice.CANREPLY = "0";
notice.SENDAIM = userId;
notice.UserID = userId;
notice.NOTICETITLE = "您有一个问题[" + otr.PDesp + "]需要处理.";
notice.NOTICECONTEXT = otr.PDesp;
count += bmBll.SaveOverTimeRemind(notice);
}
}
};
return count>0;
}
#endregion
#region 判断当前用户是否有超出时间2提醒
/// <summary>
/// 判断当前用户是否有超出时间提醒
/// </summary>
/// <returns></returns>
public string CheckCurrenUserOverTime2Remind()
{
try
{
OverTimeRemindDAL dal = new OverTimeRemindDAL();
NoticeManageBll bmBll = new NoticeManageBll();
SIParamSetBLL paramSetBll = new SIParamSetBLL();
//获取支持交互参数对象
SIParamSet paramSet = paramSetBll.Get(new SIParamSet());
if (paramSet == null)
{
return "未设置支持交互参数.";
}
int OverTime2 = paramSet.OverTime2;
if (string.IsNullOrEmpty(paramSet.SmtpServer) || string.IsNullOrEmpty(paramSet.SmtpUser) || string.IsNullOrEmpty(paramSet.SmtpPassword) || string.IsNullOrEmpty(paramSet.DoMain) || string.IsNullOrEmpty(paramSet.FromUserMail))
{
return "未设置邮件服务器信息.";
}
List<OverTimeRemind> overTimeList = dal.GetOverTimeRemindList("");
if (overTimeList != null && overTimeList.Count > 0)
{
List<User> userList = dal.GetBusinessManage();
foreach (OverTimeRemind otr in overTimeList)
{
//如果超出时间2
//如果当前日期减去问题创建日期时插入一条提醒
if ((DateTime.Now - Convert.ToDateTime(otr.ActionTime)).TotalHours > OverTime2)
{
string result = SendMail(paramSet, otr, userList,"");
}
}
};
}
catch (Exception ex)
{
return "邮件发送失败请联系管理员.";
}
return "问题超时提醒任务执行完成.";
}
#endregion
#region 发送邮件给处理用户
/// <summary>
/// 发送邮件给处理用户
/// </summary>
/// <returns></returns>
public string SentMailToUser(List<OverTimeRemind> overTimeList)
{
try
{
OverTimeRemindDAL dal = new OverTimeRemindDAL();
NoticeManageBll bmBll = new NoticeManageBll();
SIParamSetBLL paramSetBll = new SIParamSetBLL();
//获取支持交互参数对象
SIParamSet paramSet = paramSetBll.Get(new SIParamSet());
if (paramSet == null)
{
return "未设置支持交互参数.";
}
if (string.IsNullOrEmpty(paramSet.SmtpServer) || string.IsNullOrEmpty(paramSet.SmtpUser) || string.IsNullOrEmpty(paramSet.SmtpPassword) || string.IsNullOrEmpty(paramSet.DoMain) || string.IsNullOrEmpty(paramSet.FromUserMail))
{
return "未设置邮件服务器信息.";
}
if (overTimeList != null && overTimeList.Count > 0)
{
List<User> userList = dal.GetBusinessManage();
foreach (OverTimeRemind otr in overTimeList)
{
SendMail(paramSet, otr, userList,"");
}
};
}
catch (Exception ex)
{
return "邮件发送失败请联系管理员.";
}
return "问题超时提醒任务执行完成.";
}
#endregion
#region 发送邮件方法
/// <summary>
/// 发送邮件方法
/// </summary>
/// <param name="paramSet">服务器参数</param>
/// <param name="otr">对象参数</param>
private string SendMail(SIParamSet paramSet, OverTimeRemind otr, List<User> userList, string subject)
{
if (userList == null || userList.Count <= 0)
{
return "没有业务管理员";
}
SmtpServerInfo ServerInfo = new SmtpServerInfo();
ServerInfo.SmtpServer = paramSet.SmtpServer;
ServerInfo.SenderUser = paramSet.SmtpUser;
ServerInfo.SenderPassword = paramSet.SmtpPassword;
ServerInfo.DoMain = paramSet.DoMain;
ServerInfo.SenderUserEmail = paramSet.FromUserMail;
string[] mailArr = null;
List<string> mailList = null;
//查找业务管理员
foreach (User userInfo in userList)
{
//查找处理部门的业务管理员
List<User> tempList = userList.FindAll(p => p.OrgaID == otr.SDept);
if (tempList != null && tempList.Count > 0)
{
mailList = new List<string>();
foreach (User ui in tempList)
{
mailList.Add(ui.Email);
}
}
}
//将业务管理员的MAIL放到数据中
if (mailList == null || mailList.Count < 0)
{
return "没有找到指定部门的业务管理员";
}
MailInfo MailInfo = new MailInfo();
MailInfo.Content = otr.PDesp;//内容
if (string.IsNullOrEmpty(subject))
{
subject = "您有一个问题需要处理.";
}
MailInfo.Subject = subject;//标题
mailArr = mailList.ToArray();
//获取需要送人员的邮件数组
//MailInfo.ToMail = new String[] { "yunfeng.wang@qmht.cn" };//收件人地址
MailInfo.ToMail = mailArr;
QMFrameWork.Mail.MailHelper mailHelper = new QMFrameWork.Mail.MailHelper();
mailHelper.SendMail(MailInfo, ServerInfo);
return "发送成功!";
}
#endregion
#region 实现任务调度接口
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public virtual void Execute(IJobExecutionContext context)
{
CheckCurrenUserOverTime2Remind();
}
#endregion
}
}