using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMFrameWork.Common.Encrypt; using QMFrameWork.Data; using QMAPP.Entity.Sys; using QMAPP.DAL.Sys; using QMAPP.BLL.Dict; using System.IO; using System.Data; using QMAPP.Entity; namespace QMAPP.BLL.Sys { /// /// 公告管理 /// 创建人:王丹丹 /// 创建时间:2015.03.09 /// public class NoticeManageBll:BaseBLL { #region 获取公告信息 /// /// 获取公告信息 /// /// 条件 /// 用户信息 public NoticeInfo Get(NoticeInfo notice) { try { return new NoticeManageDAL().Get(notice); } catch (Exception ex) { throw ex; } } #endregion #region 根据通知ID,从通知浏览记录表中,获取发送目标 /// /// 根据通知ID,从通知浏览记录表中,获取发送目标 /// /// 条件 /// public IList GetSendaimIdList(string noticeID) { try { return new NoticeManageDAL().GetSendaimIdList(noticeID); } catch (Exception ex) { throw ex; } } #endregion #region 获取公告列表 /// /// 获取公告列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(NoticeInfo condition, DataPage page) { try { condition.UserName = LoginUser.LoginUserID; return new NoticeManageDAL().GetList(condition, page); } catch (Exception ex) { throw ex; } } #endregion #region 公告信息是否重复 /// /// 判断公告名称是否存在 /// /// 信息 /// true:已存在;fasel:不存在。 public bool ExistsNotice(NoticeInfo notice) { try { return new NoticeManageDAL().ExistsNotice(notice); } catch (Exception ex) { throw ex; } } #endregion #region 保存公告 #region 保存 /// /// 保存公告 /// /// 公告信息 /// 插入数 public DataResult Save(NoticeInfo notice) { DataResult result = new DataResult(); NoticeBrowse noticebrowse = new NoticeBrowse(); NoticeManageDAL nmDal = new NoticeManageDAL(); try { result.IsSuccess = true; using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); //发送目标ID string strSendaim = notice.SENDAIM; if (string.IsNullOrEmpty(notice.NOTICEID)) { //通知基本信息 notice.NOTICEID = Guid.NewGuid().ToString(); notice.CREATEUSER = (notice.CREATEUSER == null ? LoginUser.UserID : notice.CREATEUSER); notice.CREATEDATE = DateTime.Now; notice.SENDTIME = DateTime.Now; notice.UPDATEUSER = notice.CREATEUSER; notice.UPDATEDATE = DateTime.Now; notice.SENDAIM = ""; //插入通知 nmDal.Insert(notice); //通知浏览基本信息 var list = strSendaim.Split(','); for (int i = 0; i < list.Count(); i++) { noticebrowse.PID = Guid.NewGuid().ToString(); noticebrowse.NOTICEID = notice.NOTICEID; noticebrowse.USERID = list[i]; noticebrowse.ISREAD = "0"; //插入通知浏览记录 nmDal.Insert(noticebrowse); } } else { //修改公告 notice.UPDATEUSER = LoginUser.UserID; notice.UPDATEDATE = DateTime.Now; notice.SENDAIM = ""; //更新通知信息 nmDal.Update(notice); //通知浏览基本信息 var list = strSendaim.Split(','); for (int i = 0; i < list.Count(); i++) { noticebrowse.NOTICEID = notice.NOTICEID; noticebrowse.USERID = list[i]; NoticeBrowse noticeBrowseModel = new NoticeBrowse(); //获取原通知下的浏览记录 noticeBrowseModel = nmDal.GetBrowseModel(noticebrowse); if (noticeBrowseModel == null) { noticeBrowseModel = new NoticeBrowse(); noticeBrowseModel.NOTICEID = noticebrowse.NOTICEID; noticeBrowseModel.USERID = noticebrowse.USERID; noticeBrowseModel.PID = Guid.NewGuid().ToString(); noticeBrowseModel.ISREAD = "0"; nmDal.Insert(noticeBrowseModel); } else { noticeBrowseModel.ISREAD = "0"; //更新新通知浏览记录 nmDal.Update(noticeBrowseModel); } } } session.CommitTs(); } return result; } catch (Exception ex) { throw ex; } } #endregion #region 插入公告 /// /// 插入公告 /// /// 公告信息 /// 插入数 public int Insert(NoticeInfo notice) { try { int count = 0; using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); count = new NoticeManageDAL().Insert(notice); session.CommitTs(); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 更新公告 /// /// 更新公告 /// /// 公告信息 /// 更新个数 public int Update(NoticeInfo notice) { try { return new NoticeManageDAL().Update(notice); } catch (Exception ex) { throw ex; } } #endregion #endregion #region 删除公告 /// /// 删除公告 /// /// public int DeleteNotice(string selectKey) { NoticeInfo notice = new NoticeInfo(); int count = 0; try { string[] list = selectKey.Split(":".ToCharArray()); //删除附件 foreach (var item in list) { notice.NOTICEID = item; notice = Get(notice); DeleteFile(notice.ATTACHFILE); } //删除通知 count = Delete(list); //删除浏览记录 DeleteBorwse(list); return count; } catch (Exception ex) { throw ex; } } /// /// 删除公告信息 /// /// 公告信息 /// 删除个数 public int Delete(string[] notices) { int count = 0; try { foreach (string notice in notices) { count += this.Delete(new NoticeInfo { NOTICEID = notice }); } return count; } catch (Exception ex) { throw ex; } } /// /// 删除公告信息 /// /// 公告信息 /// 删除个数 public int Delete(NoticeInfo notice) { try { return new NoticeManageDAL().Delete(notice); } catch (Exception ex) { throw ex; } } #endregion #region 获取未读取通知信息 /// /// 获取未读取通知信息 /// /// public List GetNotReadNotice(NoticeInfo model) { try { return new NoticeManageDAL().GetNotReadNotice(model); } catch (Exception ex) { throw ex; } } #endregion #region 获取未读即时通知信息 /// /// 获取未读即时通知信息 /// /// public List GetNotReadInstantNotice(NoticeInfo model) { try { return new NoticeManageDAL().GetNotReadInstantNotice(model); } catch (Exception ex) { throw ex; } } #endregion #region 公告浏览记录操作 #region 获取公告浏览记录 /// /// 获取公告浏览记录 /// /// 条件 /// 数据页 /// 数据页 public NoticeBrowse GetBrowseModel(NoticeBrowse condition) { try { return new NoticeManageDAL().GetBrowseModel(condition); } catch (Exception ex) { throw ex; } } #endregion #region 获取公告浏览记录列表 /// /// 获取公告浏览记录列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetBrowseList(NoticeBrowse condition,DataPage page) { try { condition.UserName = LoginUser.LoginUserID; condition.USERID = LoginUser.UserID; return new NoticeManageDAL().GetBrowseList(condition, page); } catch (Exception ex) { throw ex; } } /// /// 获取公告浏览记录列表 /// /// 条件 /// 查询数据列表 public NoticeBrowse GetBrowse(NoticeBrowse condition) { try { condition.UserName = LoginUser.LoginUserID; return new NoticeManageDAL().GetBrowse(condition); } catch (Exception ex) { throw ex; } } #endregion #region 更新公告浏览记录 /// /// 插入公告 /// /// 公告信息 /// 插入数 public int UpdateNoticeBrowse(NoticeBrowse model) { int count = 0; NoticeManageDAL nmDal = new NoticeManageDAL(); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); count = nmDal.Update(model); session.CommitTs(); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 定时删除超过六个月的通知浏览记录 /// /// 定时删除超过六个月的通知浏览记录 /// /// 删除个数 public int DeleteNoticeBrowse() { try { return new NoticeManageDAL().DeleteNoticeBrowse(); } catch (Exception ex) { throw ex; } } #endregion #region 删除浏览记录 /// /// 删除浏览记录 /// /// 浏览记录 /// 删除个数 public int DeleteBorwse(string[] notices) { int count = 0; try { foreach (string notice in notices) { count += this.Delete(new NoticeBrowse { NOTICEID = notice }); } return count; } catch (Exception ex) { throw ex; } } /// /// 删除浏览记录 /// /// 浏览记录 /// 删除个数 public int Delete(NoticeBrowse noticeBrowse) { try { return new NoticeManageDAL().Delete(noticeBrowse); } catch (Exception ex) { throw ex; } } #endregion #endregion #region 判断附件路径是否存在 public bool ExistsFile(string newFilePath) { bool issuccess = true; if (!File.Exists(newFilePath)) { issuccess = false; } return issuccess; } #endregion #region 删除附件 public void DeleteFile(string FilePath) { if (File.Exists(FilePath)) { File.Delete(FilePath); ; } } #endregion #region 根据用户姓名获取用户信息 /// /// 获取用户信息 /// /// 条件 /// 用户信息 public User GetUser(User user) { try { return new NoticeManageDAL().Get(user); } catch (Exception ex) { throw ex; } } #endregion #region 获取导出的数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(NoticeInfo model) { DataTable dt=new DataTable(); NoticeManageDAL nmDal=new NoticeManageDAL(); try { model.UserName = LoginUser.LoginUserID; dt= nmDal.GetExportData(model); //回复数量 foreach (DataRow dr in dt.Rows) { if (dr["REPLYCOUNT"].ToString() == "") { dr["REPLYCOUNT"] = "0"; } } return dt; } catch (Exception ex) { throw ex; } } #endregion #region 获取组织机构下人员列表 /// /// 获取组织机构下人员列表 /// /// 条件 /// 同级别菜单列表 public DataPage GetNoticeUserList(string orgaID, DataPage page) { try { return new NoticeManageDAL().GetNoticeUserList(orgaID, page); } catch (Exception ex) { throw ex; } } #endregion #region 获取组织机构数菜单列表 /// /// 获取所有组织机构数菜单列表 /// /// 条件 /// 同级别菜单列表 public List GetAllList() { try { return new NoticeManageDAL().GetAllList(); } catch (Exception ex) { throw ex; } } #endregion #region 插入未处理问题的公告 /// /// 插入未处理问题的公告 /// /// 公告信息 /// 插入数 public int SaveOverTimeRemind(NoticeInfo notice) { int count = 0; NoticeBrowse noticebrowse = new NoticeBrowse(); NoticeManageDAL nmDal = new NoticeManageDAL(); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); //通知基本信息 notice.NOTICEID = Guid.NewGuid().ToString(); notice.CREATEUSER = LoginUser.UserID; notice.CREATEDATE = DateTime.Now; notice.SENDTIME = DateTime.Now; notice.UPDATEUSER = notice.CREATEUSER; notice.UPDATEDATE = DateTime.Now; //判断当天的提醒是否存在 bool existsFlag = nmDal.OverTimeRemindNoticeExists(notice); if (existsFlag) { return 0; } //插入通知 count = nmDal.Insert(notice); //通知浏览基本信息 var list = notice.UserID.Split(','); for (int i = 0; i < list.Count(); i++) { noticebrowse.PID = Guid.NewGuid().ToString(); noticebrowse.NOTICEID = notice.NOTICEID; noticebrowse.USERID = list[i]; noticebrowse.ISREAD = "0"; //插入通知浏览记录 nmDal.Insert(noticebrowse); } session.CommitTs(); } return count; } catch (Exception ex) { throw ex; } } #endregion } }