123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- using LeaRun.Application.Entity.PublicInfoManage;
- using LeaRun.Application.IService.PublicInfoManage;
- using LeaRun.Data;
- using LeaRun.Data.Repository;
- using LeaRun.Util.Extension;
- using LeaRun.Util.WebControl;
- using System;
- using System.Collections.Generic;
- using System.Data.Common;
- using System.Linq;
- using System.Text;
- namespace LeaRun.Application.Service.PublicInfoManage
- {
- /// <summary>
- /// 版 本 6.1
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:佘赐雄
- /// 日 期:2015.12.8 11:31
- /// 描 述:邮件内容
- /// </summary>
- public class EmailContentService : RepositoryFactory<EmailContentEntity>, IEmailContentService
- {
- #region 获取数据
- /// <summary>
- /// 未读邮件
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="userId">用户Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- public IEnumerable<EmailContentEntity> GetUnreadMail(Pagination pagination, string userId, string keyword)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT a.AddresseeId AS ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority,
- a.IsHighlight,
- a.CreateDate
- FROM Email_Addressee a
- LEFT JOIN Email_Content c ON c.ContentId = a.ContentId
- WHERE a.RecipientId = @userId AND a.IsRead <> 1");
- strSql.Append(" AND a.DeleteMark = 0");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- if (!keyword.IsEmpty())
- {
- strSql.Append(" AND c.Theme like @Theme");
- parameter.Add(DbParameters.CreateDbParameter("@Theme", '%' + keyword + '%'));
- }
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray(), pagination);
- }
- /// <summary>
- /// 未读邮件数量
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public int GetUnreadMailCount(string userId)
- {
- var expression = LinqExtensions.True<EmailAddresseeEntity>();
- expression = expression.And(t => t.RecipientId == userId);
- expression = expression.And(t => t.IsRead != 1);
- expression = expression.And(t => t.DeleteMark == 0);
- return new RepositoryFactory().BaseRepository().IQueryable<EmailAddresseeEntity>(expression).Count();
- }
- /// <summary>
- /// 星标邮件
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="userId">用户Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- public IEnumerable<EmailContentEntity> GetAsteriskMail(Pagination pagination, string userId, string keyword)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT a.AddresseeId AS ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority,
- a.IsHighlight,
- a.CreateDate
- FROM Email_Addressee a
- LEFT JOIN Email_Content c ON c.ContentId = a.ContentId
- WHERE a.RecipientId = @userId AND a.IsHighlight = 1");
- strSql.Append(" AND a.DeleteMark = 0");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- if (!keyword.IsEmpty())
- {
- strSql.Append(" AND c.Theme like @Theme");
- parameter.Add(DbParameters.CreateDbParameter("@Theme", '%' + keyword + '%'));
- }
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray(), pagination);
- }
- /// <summary>
- /// 星标邮件数量
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public int GetAsteriskMailCount(string userId)
- {
- var expression = LinqExtensions.True<EmailAddresseeEntity>();
- expression = expression.And(t => t.RecipientId == userId);
- expression = expression.And(t => t.IsHighlight == 1);
- expression = expression.And(t => t.DeleteMark == 0);
- return new RepositoryFactory().BaseRepository().IQueryable<EmailAddresseeEntity>(expression).Count();
- }
- /// <summary>
- /// 草稿箱
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="userId">用户Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- public IEnumerable<EmailContentEntity> GetDraftMail(Pagination pagination, string userId, string keyword)
- {
- var expression = LinqExtensions.True<EmailContentEntity>();
- expression = expression.And(t => t.SendState == 0);
- expression = expression.And(t => t.CreateUserId == userId);
- if (!keyword.IsEmpty())
- {
- expression = expression.And(t => t.Theme.Contains(keyword));
- }
- return this.BaseRepository().FindList(expression, pagination);
- }
- /// <summary>
- /// 草稿箱数量
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public int GetDraftMailCount(string userId)
- {
- var expression = LinqExtensions.True<EmailContentEntity>();
- expression = expression.And(t => t.SendState == 0);
- expression = expression.And(t => t.CreateUserId == userId);
- return this.BaseRepository().IQueryable(expression).Count();
- }
- /// <summary>
- /// 回收箱
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="userId">用户Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- public IEnumerable<EmailContentEntity> GetRecycleMail(Pagination pagination, string userId, string keyword)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT *
- FROM ( SELECT a.AddresseeId AS ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority ,
- a.IsHighlight ,
- a.CreateDate
- FROM Email_Addressee a
- LEFT JOIN Email_Content c ON c.ContentId = a.ContentId
- WHERE a.RecipientId = @userId
- AND a.DeleteMark = 1
- UNION
- SELECT c.ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority ,
- c.IsHighlight ,
- c.CreateDate
- FROM Email_Content c
- WHERE c.CreateUserId = @userId
- AND c.DeleteMark = 1
- ) t WHERE 1=1");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- if (!keyword.IsEmpty())
- {
- strSql.Append(" AND Theme like @Theme");
- parameter.Add(DbParameters.CreateDbParameter("@Theme", '%' + keyword + '%'));
- }
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray(), pagination);
- }
- /// <summary>
- /// 回收箱数量
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public int GetRecycleMailCount(string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT COUNT(1)
- FROM ( SELECT a.AddresseeId AS ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority ,
- a.IsHighlight ,
- a.CreateDate
- FROM Email_Addressee a
- LEFT JOIN Email_Content c ON c.ContentId = a.ContentId
- WHERE a.RecipientId = @userId
- AND a.DeleteMark = 1
- UNION
- SELECT c.ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority ,
- c.IsHighlight ,
- c.CreateDate
- FROM Email_Content c
- WHERE c.CreateUserId = @userId
- AND c.DeleteMark = 1
- ) t");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- return this.BaseRepository().FindObject(strSql.ToString(), parameter.ToArray()).ToInt();
- }
- /// <summary>
- /// 收件箱
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="userId">用户Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- public IEnumerable<EmailContentEntity> GetAddresseeMail(Pagination pagination, string userId, string keyword)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT a.AddresseeId AS ContentId ,
- c.Theme ,
- c.ThemeColor ,
- c.SenderId ,
- c.SenderName ,
- c.SenderTime ,
- c.SendPriority,
- c.CreateDate,
- a.IsHighlight
- FROM Email_Addressee a
- LEFT JOIN Email_Content c ON c.ContentId = a.ContentId
- WHERE a.RecipientId = @userId");
- strSql.Append(" AND a.DeleteMark = 0 ");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- if (!keyword.IsEmpty())
- {
- strSql.Append(" AND c.Theme like @Theme");
- parameter.Add(DbParameters.CreateDbParameter("@Theme", '%' + keyword + '%'));
- }
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray(), pagination);
- }
- /// <summary>
- /// 收件箱数量
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public int GetAddresseeMailCount(string userId)
- {
- var expression = LinqExtensions.True<EmailAddresseeEntity>();
- expression = expression.And(t => t.RecipientId == userId);
- expression = expression.And(t => t.DeleteMark == 0);
- return new RepositoryFactory().BaseRepository().IQueryable<EmailAddresseeEntity>(expression).Count();
- }
- /// <summary>
- /// 已发送
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="userId">用户Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- public IEnumerable<EmailContentEntity> GetSentMail(Pagination pagination, string userId, string keyword)
- {
- var expression = LinqExtensions.True<EmailContentEntity>();
- expression = expression.And(t => t.SendState == 1);
- expression = expression.And(t => t.CreateUserId == userId);
- expression = expression.And(t => t.DeleteMark == 0);
- if (!keyword.IsEmpty())
- {
- expression = expression.And(t => t.Theme.Contains(keyword));
- }
- return this.BaseRepository().FindList(expression, pagination);
- }
- /// <summary>
- /// 已发送数量
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public int GetSentMailCount(string userId)
- {
- var expression = LinqExtensions.True<EmailContentEntity>();
- expression = expression.And(t => t.SendState == 1);
- expression = expression.And(t => t.CreateUserId == userId);
- expression = expression.And(t => t.DeleteMark == 0);
- return this.BaseRepository().IQueryable(expression).Count();
- }
- /// <summary>
- /// 邮件实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public EmailContentEntity GetEntity(string keyValue)
- {
- return this.BaseRepository().FindEntity(keyValue);
- }
- /// <summary>
- /// 收件邮件实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public EmailAddresseeEntity GetAddresseeEntity(string keyValue)
- {
- return new RepositoryFactory().BaseRepository().FindEntity<EmailAddresseeEntity>(keyValue);
- }
- #endregion
- #region 提交数据
- /// <summary>
- /// 删除草稿
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void RemoveDraftForm(string keyValue)
- {
- this.BaseRepository().Delete(keyValue);
- }
- /// <summary>
- /// 删除未读、星标、收件
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void RemoveAddresseeForm(string keyValue)
- {
- EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity();
- emailAddresseeEntity.AddresseeId = keyValue;
- emailAddresseeEntity.DeleteMark = 1;
- new RepositoryFactory().BaseRepository().Update(emailAddresseeEntity);
- }
- /// <summary>
- /// 彻底删除未读、星标、收件
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void ThoroughRemoveAddresseeForm(string keyValue)
- {
- new RepositoryFactory().BaseRepository().Delete<EmailAddresseeEntity>(keyValue);
- }
- /// <summary>
- /// 删除回收
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="Type">类型</param>
- public void RemoveRecycleForm(string keyValue, int Type)
- {
- this.BaseRepository().Delete(keyValue);
- }
- /// <summary>
- /// 删除已发
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void RemoveSentForm(string keyValue)
- {
- EmailContentEntity emailContentEntity = new EmailContentEntity();
- emailContentEntity.ContentId = keyValue;
- emailContentEntity.DeleteMark = 1;
- this.BaseRepository().Update(emailContentEntity);
- }
- /// <summary>
- /// 彻底删除已发
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void ThoroughRemoveSentForm(string keyValue)
- {
- EmailContentEntity emailContentEntity = new EmailContentEntity();
- emailContentEntity.ContentId = keyValue;
- emailContentEntity.DeleteMark = 2;
- this.BaseRepository().Update(emailContentEntity);
- }
- /// <summary>
- /// 保存邮件表单(发送、存入草稿、草稿编辑)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="emailContentEntity">邮件实体</param>
- /// <param name="addresssIds">收件人</param>
- /// <param name="copysendIds">抄送人</param>
- /// <param name="bccsendIds">密送人</param>
- /// <returns></returns>
- public void SaveForm(string keyValue, EmailContentEntity emailContentEntity, string[] addresssIds, string[] copysendIds, string[] bccsendIds)
- {
- if (emailContentEntity.SendState == 0)
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- emailContentEntity.Modify(keyValue);
- this.BaseRepository().Update(emailContentEntity);
- }
- else
- {
- emailContentEntity.Create();
- this.BaseRepository().Insert(emailContentEntity);
- }
- }
- else
- {
- IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- emailContentEntity.Modify(keyValue);
- db.Update(emailContentEntity);
- }
- else
- {
- emailContentEntity.Create();
- db.Insert(emailContentEntity);
- }
- #region 收件人
- foreach (var item in addresssIds)
- {
- EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity();
- emailAddresseeEntity.Create();
- emailAddresseeEntity.ContentId = emailContentEntity.ContentId;
- emailAddresseeEntity.RecipientId = item;
- emailAddresseeEntity.RecipientState = 0;
- db.Insert(emailAddresseeEntity);
- }
- #endregion
- #region 抄送人
- foreach (var item in copysendIds)
- {
- EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity();
- emailAddresseeEntity.Create();
- emailAddresseeEntity.ContentId = emailContentEntity.ContentId;
- emailAddresseeEntity.RecipientId = item;
- emailAddresseeEntity.RecipientState = 1;
- db.Insert(emailAddresseeEntity);
- }
- #endregion
- #region 密送人
- foreach (var item in bccsendIds)
- {
- EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity();
- emailAddresseeEntity.Create();
- emailAddresseeEntity.ContentId = emailContentEntity.ContentId;
- emailAddresseeEntity.RecipientId = item;
- emailAddresseeEntity.RecipientState = 2;
- db.Insert(emailAddresseeEntity);
- }
- #endregion
- db.Commit();
- }
- catch (System.Exception)
- {
- db.Rollback();
- throw;
- }
- }
- }
- /// <summary>
- /// 设置邮件已读/未读
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="IsRead">是否已读:0-未读1-已读</param>
- public void ReadEmail(string keyValue, int IsRead = 1)
- {
- EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity();
- emailAddresseeEntity.AddresseeId = keyValue;
- emailAddresseeEntity.IsRead = IsRead;
- emailAddresseeEntity.ReadCount = emailAddresseeEntity.ReadCount + 1;
- emailAddresseeEntity.ReadDate = DateTime.Now;
- new RepositoryFactory().BaseRepository().Update(emailAddresseeEntity);
- }
- /// <summary>
- /// 设置邮件星标/取消星标
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="asterisk">星标:0-取消星标1-星标</param>
- public void SteriskEmail(string keyValue, int sterisk = 1)
- {
- EmailAddresseeEntity emailAddresseeEntity = new EmailAddresseeEntity();
- emailAddresseeEntity.AddresseeId = keyValue;
- emailAddresseeEntity.IsHighlight = sterisk;
- new RepositoryFactory().BaseRepository().Update(emailAddresseeEntity);
- }
- #endregion
- }
- }
|