using System; using System.Collections.Generic; using QMAPP.BLL; using QMAPP.BLL.Sys; using QMAPP.DAL.Sys; using QMAPP.Entity; using QMAPP.Entity.Sys; using QMAPP.FJC.BLL.Dict; using QMAPP.FJC.DAL.EquipMentAlarmManage; using QMAPP.FJC.Entity; using QMAPP.FJC.Entity.WarnManage; using QMFrameWork.Data; using QMFrameWork.Log; using QMFrameWork.Mail; namespace QMAPP.FJC.BLL.WarnManage { /// /// 模块编号:M6-3 /// 作 用:自动报警维护 /// 作 者:张敬贺 /// 编写日期:2015年06月19日 /// public class WarnManageBLL : BaseBLL { #region 报警信息维护 #region 报警信息获取信息 /// /// 报警信息获取信息 /// /// 条件 /// 信息 public DataResult WarnInfoGet(WarnInfo model) { DataResult result = new DataResult(); try { result.Result = new WarnManageDAL().WarnInfoGet(model); result.IsSuccess = true; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "获取报警记录异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "获取报警记录异常"; } return result; } #endregion #region 报警信息获取列表 /// /// 报警信息获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetWarnInfoList(WarnInfo condition, DataPage page) { DataResult result = new DataResult(); try { //获取信息列表 DataPage dataPage = new WarnManageDAL().GetWarnInfoList(condition, page); #region 转换工序类别显示类型 List list = dataPage.Result as List; //处理字典信息 DictManageBLL dictWARNTYPE = new DictManageBLL(DictKind.WARNTYPE); DictManageBLL dictISDONE = new DictManageBLL(DictKind.ISDONE); DictManageBLL dictISDEAL = new DictManageBLL(DictKind.ISDEAL); DictManageBLL dictCREATETYPE = new DictManageBLL(DictKind.CREATETYPE); foreach (var info in list) { //替换报警类别显示值 info.WARNTYPE = dictWARNTYPE.GetDictValue(info.WARNTYPE); //替换是否完成显示值 info.ISDONE = dictISDONE.GetDictValue(info.ISDONE); //替换是否发送显示值 info.ISDEAL = dictISDEAL.GetDictValue(info.ISDEAL); //替换生成方式显示值 info.CREATETYPE = dictCREATETYPE.GetDictValue(info.CREATETYPE); } #endregion result.IsSuccess = true; result.Result = dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "报警记录获取列表异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "报警记录获取列表异常!"; } return result; } /// /// 获取列表 /// /// 条件 /// 全部集合 public List GetAllWarnInfoList(WarnInfo condition) { try { //获取信息列表 List list = new WarnManageDAL().GetWarnInfoList(condition); return list; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "报警记录获取列表异常!" }); throw ex; } } #endregion #region 报警信息插入信息 /// /// 报警信息插入信息(单表) /// /// 信息 /// 插入行数 public DataResult WarnInfoInsert(WarnInfo model) { DataResult result = new DataResult(); WarnManageDAL ppDAL = new WarnManageDAL(); try { result.IsSuccess = true; //基本信息 model.PID = Guid.NewGuid().ToString(); model.CREATETYPE = QMAPP.FJC.Entity.EnumGeter.CREATETYPE.people.GetHashCode().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; int temp = ppDAL.WarnInfoInsert(model); if (temp == 0) { result.IsSuccess = false; result.Msg = "报警记录插入失败!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "报警记录插入异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "报警记录插入异常"; } return result; } #endregion #region 报警信息更新信息 /// /// 报警信息更新信息 /// /// /// 更新行数 public DataResult WarnInfoUpdate(WarnInfo model) { DataResult result = new DataResult(); result.IsSuccess = true; try { WarnInfo info = new WarnManageDAL().WarnInfoGet(model); //基本信息 info.CREATETYPE = model.CREATETYPE; info.WARNCODE = model.WARNCODE; info.WARNTYPE = model.WARNTYPE; info.WARNDESCRIBE = model.WARNDESCRIBE; info.MEMO = model.MEMO; info.UPDATEUSER = this.LoginUser.UserID; int temp = new WarnManageDAL().WarnInfoUpdate(info); if (temp == 0) { result.IsSuccess = false; result.Msg = "报警记录更新失败!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录更新异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "生产记录更新异常"; } return result; } #endregion #region 报警信息删除 /// /// 删除信息 /// /// /// 删除个数 public DataResult WarnInfoDelete(string strs) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; string[] list = strs.Split(":".ToCharArray()); try { foreach (string str in list) { count += this.DeleteWarnInfoInfo(new WarnInfo { PID = str }); } if (count != list.Length) { result.IsSuccess = false; result.Msg = "报警信息部分删除!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "报警记录删除异常!" }); result.IsSuccess = false; result.Msg = "报警记录删除异常!"; result.Ex = ex; } return result; } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteWarnInfoInfo(WarnInfo model) { int count = 0; try { count = new WarnManageDAL().WarnInfoDelete(model); return count; } catch (Exception ex) { throw ex; } } #endregion #endregion #region 报警类别维护 #region 报警类别获取信息 /// /// 报警类别获取信息 /// /// 条件 /// 信息 public DataResult WarnTypeGet(WarnType model) { DataResult result = new DataResult(); try { result.Result = new WarnManageDAL().WarnTypeGet(model); result.IsSuccess = true; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnTypeGetError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnTypeGetError; } return result; } #endregion #region 报警类别获取列表 /// /// 报警类别获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetWarnTypeList(WarnType condition, DataPage page) { DataResult result = new DataResult(); try { #region 获取报警与报警通知人关联列表 用于处理相应标记位 WarnTypeWithInformer warnTypeWithInformer = new WarnTypeWithInformer(); warnTypeWithInformer.INID = condition.WarnInformerId; List wtwList = new WarnManageDAL().GetWarnTypeWithInformerList(warnTypeWithInformer); #endregion //获取信息列表 DataPage dataPage = new WarnManageDAL().GetWarnTypeList(condition, page); #region 转换工序类别显示类型 List list = dataPage.Result as List; //处理字典信息 DictManageBLL dictWARNTYPE = new DictManageBLL(DictKind.WARNTYPE); foreach (var info in list) { //替换报警类别显示值 info.WARNTYPE = dictWARNTYPE.GetDictValue(info.WARNTYPE); //如果报警通知人为空,默认为是添加编辑人,添加时所有通知人与报警类别关联标记不做操作 if (!string.IsNullOrEmpty(warnTypeWithInformer.INID)) { foreach (var item in wtwList) { if (info.PID == item.WTID && condition.WarnInformerId == item.INID) { info.IsTypeWithInformer = true; } } } } #endregion result.IsSuccess = true; result.Result = dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnTypeGetListError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnTypeGetListError; } return result; } /// /// 获取列表 /// /// 条件 /// 全部集合 public List GetAllWarnTypeList(WarnType condition) { try { //获取信息列表 List list = new WarnManageDAL().GetWarnTypeList(condition); return list; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnTypeGetListError }); throw ex; } } #endregion #region 报警类别插入信息 /// /// 报警类别插入信息(单表) /// /// 信息 /// 插入行数 public DataResult WarnTypeInsert(WarnType model) { DataResult result = new DataResult(); WarnManageDAL ppDAL = new WarnManageDAL(); try { result.IsSuccess = true; //基本信息 model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; //判断报警代码是否存在 if (ExistsWarnType(model) == true) { result.IsSuccess = false; result.Msg = "报警代码重复"; return result; } int temp = ppDAL.WarnTypeInsert(model); if (temp == 0) { result.IsSuccess = false; result.Msg = Resource.WarnTypeInsertFail; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnTypeInsertError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnTypeInsertError; } return result; } #endregion #region 报警类别更新信息 /// /// 报警类别更新信息 /// /// /// 更新行数 public DataResult WarnTypeUpdate(WarnType model) { DataResult result = new DataResult(); result.IsSuccess = true; try { WarnType info = new WarnManageDAL().WarnTypeGet(model); //基本信息 info.WARNTYPE = model.WARNTYPE; info.WARNCODE = model.WARNCODE; info.WARNDESCRIBE = model.WARNDESCRIBE; info.UPDATEUSER = this.LoginUser.UserID; //判断报警代码是否存在 if (ExistsWarnType(info) == true) { result.IsSuccess = false; result.Msg = "报警代码重复"; return result; } int temp = new WarnManageDAL().WarnTypeUpdate(info); if (temp == 0) { result.IsSuccess = false; result.Msg = Resource.WarnTypeUpdateFail; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnTypeUpdateError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnTypeUpdateError; } return result; } #endregion #region 报警类别删除 /// /// 报警类别删除信息 /// /// /// 删除个数 public DataResult WarnTypeDelete(string strs) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; string[] list = strs.Split(":".ToCharArray()); WarnManageDAL dal = new WarnManageDAL(); try { foreach (string str in list) { #region 校验报警类别是否有对应的报警信息存在,如果存在不允许删除该报警类别 List warnInfoList = new List(); //获取要删除的报警类别的报警类别信息 WarnType typeInfo = dal.WarnTypeGet(new WarnType { PID = str }); WarnInfo warnInfo = new WarnInfo(); warnInfo.WARNCODE = typeInfo.WARNCODE; //根据报警代码获取报警信息 warnInfoList = dal.GetWarnInfoList(warnInfo); if (warnInfoList.Count > 0) { result.IsSuccess = false; result.Msg = "报警代码:"+typeInfo.WARNCODE+",有对应的报警信息存在,不能被删除!"; return result; } #endregion #region 如果报警类别不存在对应的报警信息,删除对应报警通知人在报警类别与报警通知人关联表中的关联信息 WarnTypeWithInformer warnTypeWithInformer = new WarnTypeWithInformer(); warnTypeWithInformer.WTID = str; dal.WarnTypeWithInformerDelete(warnTypeWithInformer); #endregion count += this.DeleteWarnTypeInfo(new WarnType { PID = str }); } if (count != list.Length) { result.IsSuccess = false; result.Msg = Resource.WarnTypePartDelete; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnTypeDeleteError }); result.IsSuccess = false; result.Msg = Resource.WarnTypeDeleteError; result.Ex = ex; } return result; } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteWarnTypeInfo(WarnType model) { int count = 0; try { count = new WarnManageDAL().WarnTypeDelete(model); return count; } catch (Exception ex) { throw ex; } } #endregion #region 报警类别重复校验 /// /// 报警类别重复校验 /// /// /// true:已存在;fasel:不存在。 public bool ExistsWarnType(WarnType model) { try { return new WarnManageDAL().ExistsWarnType(model); } catch (Exception ex) { throw ex; } } #endregion #endregion #region 报警通知人信息维护 #region 报警通知人信息获取信息 /// /// 报警通知人信息获取信息 /// /// 条件 /// 信息 public DataResult WarnInformerGet(WarnInformer model) { DataResult result = new DataResult(); try { result.Result = new WarnManageDAL().WarnInformerGet(model); result.IsSuccess = true; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnInformerGetError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnInformerGetError; } return result; } #endregion #region 报警通知人信息获取列表 /// /// 报警通知人信息获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetWarnInformerList(WarnInformer condition, DataPage page) { DataResult result = new DataResult(); try { //获取信息列表 DataPage dataPage = new WarnManageDAL().GetWarnInformerList(condition, page); #region 转换工序类别显示类型 List list = dataPage.Result as List; //处理字典信息 DictManageBLL dictINFOTYPE = new DictManageBLL(DictKind.INFOTYPE); foreach (var info in list) { //替换报警类别显示值 info.INFOTYPE = dictINFOTYPE.GetDictValue(info.INFOTYPE); } #endregion result.IsSuccess = true; result.Result = dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnInformerGetListError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnInformerGetListError; } return result; } /// /// 获取列表 /// /// 条件 /// 全部集合 public List GetAllWarnInformerList(WarnInformer condition) { try { //获取信息列表 List list = new WarnManageDAL().GetWarnInformerList(condition); return list; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录获取列表异常!" }); throw ex; } } #endregion #region 报警通知人信息插入信息 /// /// 报警通知人信息插入信息(单表) /// /// 信息 /// 插入行数 public DataResult WarnInformerInsert(WarnInformer model) { DataResult result = new DataResult(); WarnManageDAL ppDAL = new WarnManageDAL(); int temp = 0; result.IsSuccess = true; //基本信息 model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; //判断报警通知人邮箱和电话是否重复 if (ExistsWarnInformer(model) == true) { result.IsSuccess = false; result.Msg = "报警通知人邮箱或电话重复"; return result; } #region 中间表信息 List informerList = new List(); string[] strs = model.WarnTypeIds.Substring(0, model.WarnTypeIds.Length - 1).Split(":".ToCharArray()); foreach (var item in strs) { WarnType type = ppDAL.WarnTypeGet(new WarnType() { PID = item }); model.WARNCODE += (type.WARNCODE + ","); WarnTypeWithInformer warnTypeWithInformer = new WarnTypeWithInformer(); warnTypeWithInformer.PID = Guid.NewGuid().ToString(); warnTypeWithInformer.INID = model.PID; warnTypeWithInformer.WTID = item; warnTypeWithInformer.CREATEUSER = this.LoginUser.UserID; warnTypeWithInformer.CREATEDATE = DateTime.Now; warnTypeWithInformer.UPDATEUSER = warnTypeWithInformer.CREATEUSER; warnTypeWithInformer.UPDATEDATE = warnTypeWithInformer.CREATEDATE; informerList.Add(warnTypeWithInformer); } model.WARNCODE = model.WARNCODE.Substring(0, model.WARNCODE.Length - 1); #endregion using (IDataSession session = AppDataFactory.CreateMainSession()) { try { session.OpenTs(); ppDAL.BaseSession = session; #region 添加报警通知人 temp = ppDAL.WarnInformerInsert(model); #endregion #region 报警类别与报警通知人关联操作 //报警类别ID串 foreach (var item in informerList) { ppDAL.WarnTypeWithInformerInsert(item); } #endregion session.CommitTs(); } catch (Exception ex) { session.RollbackTs(); LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnInformerInsertError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnInformerInsertError; } } if (temp == 0) { result.IsSuccess = false; result.Msg = Resource.WarnInformerInsertFail; return result; } return result; } #endregion #region 报警通知人信息更新信息 /// /// 报警通知人信息更新信息 /// /// /// 更新行数 public DataResult WarnInformerUpdate(WarnInformer model) { DataResult result = new DataResult(); result.IsSuccess = true; int temp = 0; using (IDataSession session = AppDataFactory.CreateMainSession()) { try { session.OpenTs(); WarnManageDAL ppDAL = new WarnManageDAL(); WarnInformer info = ppDAL.WarnInformerGet(model); ppDAL.BaseSession = session; #region 更新报警通知人 //基本信息 info.INFORMNAME = model.INFORMNAME; info.INFORMCODE = model.INFORMCODE; info.MAIL = model.MAIL; info.MOBILEPHONENUMBER = model.MOBILEPHONENUMBER; info.INFOTYPE = model.INFOTYPE; info.MEMO = model.MEMO; info.UPDATEUSER = this.LoginUser.UserID; //判断报警通知人邮箱和电话是否重复 if (ExistsWarnInformer(model) == true) { result.IsSuccess = false; result.Msg = "报警通知人邮箱或电话重复"; return result; } #endregion #region 报警类别与报警通知人关联操作 #region 先删除当前报警通知人员关联的报警类别 WarnTypeWithInformer warnTypeWithInformer = new WarnTypeWithInformer(); warnTypeWithInformer.INID = model.PID; ppDAL.WarnTypeWithInformerDelete(warnTypeWithInformer); #endregion #region 添加新的报警类别关联关系 //报警类别ID串 string[] strs = model.WarnTypeIds.Substring(0, model.WarnTypeIds.Length - 1).Split(":".ToCharArray()); info.WARNCODE = ""; foreach (var item in strs) { WarnTypeWithInformer typeWithInformer = new WarnTypeWithInformer(); typeWithInformer.PID = Guid.NewGuid().ToString(); typeWithInformer.INID = model.PID; typeWithInformer.WTID = item; typeWithInformer.CREATEUSER = this.LoginUser.UserID; typeWithInformer.CREATEDATE = DateTime.Now; typeWithInformer.UPDATEUSER = typeWithInformer.CREATEUSER; typeWithInformer.UPDATEDATE = typeWithInformer.CREATEDATE; ppDAL.WarnTypeWithInformerInsert(typeWithInformer); WarnType type = session.Get(new WarnType() { PID = item }); info.WARNCODE += (type.WARNCODE + ","); } #endregion #endregion info.WARNCODE = info.WARNCODE.Substring(0, info.WARNCODE.Length - 1); temp = ppDAL.WarnInformerUpdate(info); session.CommitTs(); } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnInformerUpdateError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnInformerUpdateError; } } if (temp == 0) { result.IsSuccess = false; result.Msg = Resource.WarnInformerUpdateFail; return result; } return result; } #endregion #region 报警通知人信息删除 /// /// 报警通知人信息删除信息 /// /// /// 删除个数 public DataResult WarnInformerDelete(string strs) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; string[] list = strs.Split(":".ToCharArray()); WarnManageDAL dal = new WarnManageDAL(); try { foreach (string str in list) { #region 删除对应报警通知人在报警类别与报警通知人关联表中的关联信息 WarnTypeWithInformer warnTypeWithInformer = new WarnTypeWithInformer(); warnTypeWithInformer.INID = str; dal.WarnTypeWithInformerDelete(warnTypeWithInformer); #endregion count += this.DeleteWarnInformerInfo(new WarnInformer { PID = str }); } if (count != list.Length) { result.IsSuccess = false; result.Msg = Resource.WarnInformerPartDelete; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnInformerDeleteError }); result.IsSuccess = false; result.Msg = Resource.WarnInformerDeleteError; result.Ex = ex; } return result; } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteWarnInformerInfo(WarnInformer model) { int count = 0; try { count = new WarnManageDAL().WarnInformerDelete(model); return count; } catch (Exception ex) { throw ex; } } #endregion #region 报警通知人邮箱和电话重复校验 /// /// 报警通知人邮箱和电话重复校验 /// /// /// true:已存在;fasel:不存在。 public bool ExistsWarnInformer(WarnInformer model) { try { return new WarnManageDAL().ExistsWarnInformer(model); } catch (Exception ex) { throw ex; } } #endregion #endregion #region 关闭报警 /// /// 关闭报警 /// /// /// 完成计划 public DataResult WarnIsDone(string str) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; try { WarnInfo info = new WarnManageDAL().WarnInfoGet(new WarnInfo { PID = str }); //是否关闭 info.ISDONE = QMAPP.FJC.Entity.EnumGeter.ISDONE.yes.GetHashCode().ToString(); info.UPDATEUSER = this.LoginUser.UserID; count += new WarnManageDAL().WarnInfoUpdate(info); if (count == 0) { result.IsSuccess = false; result.Msg = Resource.WarnDoneFail; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnDoneError }); result.IsSuccess = false; result.Msg = Resource.WarnDoneError; result.Ex = ex; } return result; } #endregion #region 发送报警 #region 发送报警页面通知人信息获取列表 /// /// 报警通知人信息获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetWarnInformerListForSend(WarnInformer condition, DataPage page) { DataResult result = new DataResult(); WarnManageDAL wmDal = new WarnManageDAL(); List warnTypeWithInformerList = new List(); WarnTypeWithInformer warnTypeWithInformer = new WarnTypeWithInformer(); try { #region 通过报警信息获取报警代码 WarnInfo warnInfo = new WarnInfo(); warnInfo.PID = condition.WarnInfoIds; warnInfo = wmDal.WarnInfoGet(warnInfo); #endregion #region 通过报警代码获取报警类别ID WarnType warnType = new WarnType(); warnType.WARNCODE = warnInfo.WARNCODE; warnType = wmDal.WarnTypeGetWith(warnType); #endregion #region 如果报警类别不为空,通过报警类别ID获取报警类别和报警通知人表中的对应报警人信息 if (warnType != null) { warnTypeWithInformer.WTID = warnType.PID; warnTypeWithInformerList = wmDal.GetWarnTypeWithInformerList(warnTypeWithInformer); } #endregion //获取所有报警通知人信息 DataPage dataPage = wmDal.GetWarnInformerList(condition, page); #region 转换工序类别显示类型 List list = dataPage.Result as List; //处理字典信息 DictManageBLL dictINFOTYPE = new DictManageBLL(DictKind.INFOTYPE); foreach (var info in list) { //替换报警类别显示值 info.INFOTYPE = dictINFOTYPE.GetDictValue(info.INFOTYPE); //如果报警类别为空,所有通知人与报警类别关联标记不做操作 if (warnType != null) { foreach (var item in warnTypeWithInformerList) { if (info.PID == item.INID) { info.IsTypeWithInformer = true; } } } } #endregion result.IsSuccess = true; result.Result = dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnInformerGetListError }); result.IsSuccess = false; result.Ex = ex; result.Msg = Resource.WarnInformerGetListError; } return result; } #endregion #region 报警发送 /// /// 报警发送 /// /// /// 完成计划 public DataResult WarnIsSend(WarnDetail condition) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; WarnManageDAL dal = new WarnManageDAL(); List warnInformerList = new List(); try { #region 对报警信息操作 WarnInfo info = new WarnManageDAL().WarnInfoGet(new WarnInfo { PID = condition.WPID }); if (info != null) { //如果报警已经关闭,不能发送 if (info.ISDONE == QMAPP.FJC.Entity.EnumGeter.ISDONE.yes.GetHashCode().ToString()) { result.IsSuccess = false; result.Msg = Resource.IsDoneCanNotSend; return result; } //是否发送 info.ISDEAL = QMAPP.FJC.Entity.EnumGeter.ISDEAL.yes.GetHashCode().ToString(); info.UPDATEUSER = this.LoginUser.UserID; count += new WarnManageDAL().WarnInfoUpdate(info); } if (count == 0) { result.IsSuccess = false; result.Msg = Resource.WarnSendFail; return result; } #endregion #region 报警详情操作 string[] warnInformerAerry = condition.WarnInformerIds.Substring(0, condition.WarnInformerIds.Length - 1).Split(":".ToCharArray()); foreach (var item in warnInformerAerry) { WarnInformer warnInformer = new WarnInformer(); warnInformer.PID = item; warnInformer = dal.WarnInformerGet(warnInformer); //用于发送报警邮件使用 warnInformerList.Add(warnInformer); #region 报警详情数据整理 condition.PID = Guid.NewGuid().ToString(); condition.INID = warnInformer.PID; condition.INFORMNAME = warnInformer.INFORMNAME; condition.INFORMNAME = warnInformer.INFORMNAME; condition.INFORMCODE = warnInformer.INFORMCODE; //condition.INFOTYPE为手动创建时选中的发送方式,如果为空,发送方式以所选通知人的发送方式为准 if (string.IsNullOrEmpty(condition.INFOTYPE)) { condition.INFOTYPE = warnInformer.INFOTYPE; } #region 根据发送方式为邮箱或电话赋值 if (condition.INFOTYPE == QMAPP.FJC.Entity.EnumGeter.INFOTYPE.mobilePhoneNumber.GetHashCode().ToString()) { condition.MOBILEPHONENUMBER = warnInformer.MOBILEPHONENUMBER; } if (condition.INFOTYPE == QMAPP.FJC.Entity.EnumGeter.INFOTYPE.mail.GetHashCode().ToString()) { condition.MAIL = warnInformer.MAIL; } if (condition.INFOTYPE == QMAPP.FJC.Entity.EnumGeter.INFOTYPE.mobilePhoneAndMail.GetHashCode().ToString()) { condition.MAIL = warnInformer.MAIL; condition.MOBILEPHONENUMBER = warnInformer.MOBILEPHONENUMBER; } #endregion condition.CREATEUSER = this.LoginUser.UserID; condition.CREATEDATE = DateTime.Now; condition.UPDATEUSER = condition.CREATEUSER; condition.UPDATEDATE = condition.CREATEDATE; #endregion int temp = dal.WarnDetailInsert(condition); if (temp == 0) { result.IsSuccess = false; result.Msg = Resource.WarnDetailInsertFail; return result; } } #endregion #region 发送邮件 string sendState = SentMailToUser(warnInformerList, info); if (sendState != "发送成功") { result.IsSuccess = false; result.Msg = sendState; } #endregion } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = Resource.WarnSendError }); result.IsSuccess = false; result.Msg = Resource.WarnSendError; result.Ex = ex; } return result; } #endregion #region 发送邮件给处理用户 /// /// 发送邮件给处理用户 /// /// public string SentMailToUser(List warnInformerList, WarnInfo warnInfo) { try { OverTimeRemindDAL dal = new OverTimeRemindDAL(); NoticeManageBll bmBll = new NoticeManageBll(); SIParamSetBLL paramSetBll = new SIParamSetBLL(); //获取支持交互参数对象 SIParamSet paramSet = new SIParamSet(); if (paramSet == null) { return "未设置支持交互参数."; } paramSet.SmtpServer = System.Configuration.ConfigurationManager.AppSettings.Get("SmtpServer").ToString(); paramSet.SmtpUser = System.Configuration.ConfigurationManager.AppSettings.Get("SmtpUser").ToString(); paramSet.SmtpPassword = System.Configuration.ConfigurationManager.AppSettings.Get("SmtpPassword").ToString(); paramSet.DoMain = System.Configuration.ConfigurationManager.AppSettings.Get("DoMain").ToString(); paramSet.FromUserMail = System.Configuration.ConfigurationManager.AppSettings.Get("FromUserMail").ToString(); if (string.IsNullOrEmpty(paramSet.SmtpServer) || string.IsNullOrEmpty(paramSet.SmtpUser) || string.IsNullOrEmpty(paramSet.SmtpPassword) || string.IsNullOrEmpty(paramSet.DoMain) || string.IsNullOrEmpty(paramSet.FromUserMail)) { return "未设置邮件服务器信息."; } foreach (var item in warnInformerList) { string sendState = SendMail(paramSet, item, warnInfo, ""); if (sendState != "发送成功") { return sendState; } } } catch (Exception ex) { return "邮件发送失败请联系管理员."; } return "发送成功"; } #endregion #region 发送邮件方法 /// /// 发送邮件方法 /// /// 服务器参数 /// 对象参数 private string SendMail(SIParamSet paramSet, WarnInformer warnInformer, WarnInfo warnInfo, string subject) { if (warnInformer == null) { 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 mailList = new List(); //查找业务管理员 mailList.Add(warnInformer.MAIL); //将业务管理员的MAIL放到数据中 if (mailList == null || mailList.Count < 0) { return "没有找到指定邮箱"; } MailInfo mailInfo = new MailInfo(); #region 邮件内容 DictManageBLL dictCREATETYPE = new DictManageBLL(DictKind.CREATETYPE); //替换生成方式显示值 warnInfo.CREATETYPE = dictCREATETYPE.GetDictValue(warnInfo.CREATETYPE); mailInfo.Content = "报警类别:" + warnInfo.WARNTYPE + "
" + "报警代码:" + warnInfo.WARNCODE + "
" + "报警描述:" + warnInfo.WARNDESCRIBE + "
" + "生成方式:" + warnInfo.CREATETYPE;//内容 #endregion #region 邮件标题 if (string.IsNullOrEmpty(subject)) { subject = "您有一个报警需要处理."; } mailInfo.Subject = subject;//标题 #endregion 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 #endregion #region 报警详细信息获取列表 /// /// 报警详细信息获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetWarnDetailList(WarnDetail condition, DataPage page) { DataResult result = new DataResult(); try { //获取信息列表 DataPage dataPage = new WarnManageDAL().GetWarnDetailList(condition, page); #region 转换工序类别显示类型 List list = dataPage.Result as List; //处理字典信息 DictManageBLL dictINFOTYPE = new DictManageBLL(DictKind.INFOTYPE); foreach (var info in list) { //替换通知方式显示值 info.INFOTYPE = dictINFOTYPE.GetDictValue(info.INFOTYPE); } #endregion result.IsSuccess = true; result.Result = dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "报警详细记录获取列表异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "报警详细记录获取列表异常!"; } return result; } #endregion } }