公司的EDM軟件已經不少年了,須要更新程序並添加一些功能。功能描述:暫時內部使用,要有登錄及權限過濾功能;發送郵件和問卷檢測功能。sql
新需求中程序屬於一個流程中的子系統,因此對擴展有要求,登錄時考慮到高併發和容災,擬採用多進程方式,因而將session記錄到數據庫裏;數據庫
發送郵件過程當中,因爲要發送的郵箱屬於10W級,而SMTP服務器限制較多(同一Ip/郵箱,一段時間發送數量上線,發送速度限制,天天部分郵局發送數量上限),對於發送時數據的整理要求較高,還要檢測導入的郵箱是否有錯誤,歷史上是否有退訂和發送失敗中的再次發送不可能成功郵箱的記錄,排除不可能成功的郵箱;服務器
問卷須要對導入的文件進行檢測是否有多、缺、亂的格式,並生成可訪問的連接。session
一、框架模型:併發
本來是想試驗一下領域驅動模型來設計,不過最後把本身繞進去了,出不來了,待到有所成的時候再寫吧。這裏簡要的介紹一下:框架
Models就不用說了,數據庫模型;ide
Commons裏面是一些公共類和頁面顯示數據模型;高併發
1 using System; 2 using System.Collections.Generic; 3 4 namespace Commons.DTO 5 { 6 public class SendTypePages 7 { 8 public int Id { get; set; } 9 public string CustomerName { get; set; } 10 public string EdmName { get; set; } 11 public string Person { get; set; } 12 public string EdmUrl { get; set; } 13 public string DesignUrl { get; set; } 14 public string EmailUrl { get; set; } 15 public string SetTime { get; set; } 16 public string SendStatus { get; set; } 17 } 18 19 public class StopSendType 20 { 21 public int Id { get; set; } 22 public string EdmBeginUrl { get; set; } 23 public string SendStatus { get; set; } 24 public string EdmName { get; set; } 25 } 26 27 public class SendTypeStatis 28 { 29 public string EdmName { get; set; } 30 public string EdmNewUrl { get; set; } 31 public string SetTime { get; set; } 32 public int? TotalCounts { get; set; } 33 public string SendStatus { get; set; } 34 public string CustomerName { get; set; } 35 public double TheBackCount { get; set; } 36 public double TheArriveCount { get; set; } 37 public double TheOpenCount { get; set; } 38 public double EdmBeginUrl { get; set; } 39 public double TheOpenTimesCount { get; set; } 40 public double TheSendCount { get; set; } 41 public double TheTotalCount { get; set; } 42 public double TheUnableCount { get; set; } 43 public string TheArriveProcent { get; set; } 44 public string TheOpenProcent { get; set; } 45 } 46 47 public class TheBackEmailPage 48 { 49 public int Id { get; set; } 50 public string CustomerName { get; set; } 51 public string EdmName { get; set; } 52 public string Email { get; set; } 53 public string Reason { get; set; } 54 public string SetTime { get; set; } 55 } 56 57 public class JsonDate 58 { 59 public int id { get; set; } 60 public string text { get; set; } 61 public List<JsonDate> children { get; set; } 62 } 63 64 public class CustomerList 65 { 66 public int Id { get; set; } 67 public string CustomerName { get; set; } 68 public string Remarks { get; set; } 69 public string Phone { get; set; } 70 public string Email { get; set; } 71 public string Enterprise { get; set; } 72 public string Setion { get; set; } 73 } 74 75 public class QuestionnaireList 76 { 77 public int Id { get; set; } 78 public string CustomerName { get; set; } 79 public string Name { get; set; } 80 public int ReportTimes { get; set; } 81 public int GetBackTimes { get; set; } 82 public string UpTime { get; set; } 83 } 84 85 public class CustomerDto 86 { 87 public int Id { get; set; } 88 public string CustomerName { get; set; } 89 public string Phone { get; set; } 90 public string Email { get; set; } 91 public string Remarks { get; set; } 92 public string Enterprise { get; set; } 93 public string Setion { get; set; } 94 } 95 96 public class SendTest 97 { 98 public int Id { get; set; } 99 public string Email { get; set; } 100 public int IsOpen { get; set; } 101 public int IsReturn { get; set; } 102 public string TheBackReason { get; set; } 103 } 104 105 public class SendTypeEmailDto 106 { 107 public string QqEmail { get; set; } 108 public string WangyiEmail { get; set; } 109 public string TomEmail { get; set; } 110 public string SinaEmail { get; set; } 111 public string SohuEmail { get; set; } 112 public string OtherEmail { get; set; } 113 } 114 }
IRepository裏是基礎的crud和分頁獲取數據;spa
1 public class Repository<T> where T : class ,new() 2 { 3 readonly DbContext _entities = EfContextFactory.GetCurrentDbContext(); 4 public void InsertOrUpdate(T entity) 5 { 6 _entities.Set<T>().AddOrUpdate(entity); 7 } 8 9 public void Delete(IEnumerable<T> entity) 10 { 11 foreach (var en in entity) 12 { 13 _entities.Set<T>().Remove(en); 14 } 15 } 16 17 public IEnumerable<T> GetEntity(Func<T, bool> commandText) 18 { 19 var model = _entities.Set<T>().Where(commandText); 20 return model; 21 } 22 23 public IEnumerable<T> GetEntitiesForPaging(int pageNumber, int pageSize, Func<T, object> orderName, Func<T, bool> commandText, out int count) 24 { 25 var model = _entities.Set<T>() 26 .Where(commandText) 27 .OrderBy(orderName).ToList(); 28 var list = model.Skip((pageNumber - 1) * pageSize) 29 .Take(pageSize) 30 .ToList(); 31 count = model.Count; 32 return list; 33 } 34 35 public void Insert(string sql, params object[] paramters) 36 { 37 //entities.Database.SqlQuery<T>( sql, paramters); 38 _entities.Database.ExecuteSqlCommand(sql, paramters); 39 } 40 41 public bool SaveChange() 42 { 43 return _entities.SaveChanges() > 0; 44 } 45 }
Dal則是繼承IRepository的方法;設計
1 namespace DAL 2 { 3 public class UserRepository : IRepository.Repository<Models.UserInfo>, IRepository.IRepository<Models.UserInfo> 4 { 5 public List<string> GetEntities(string sql, params object[] paramters) 6 { 7 using (var entities = new Model1Container()) 8 { 9 return entities.Database.SqlQuery<string>(sql, paramters).ToList(); 10 } 11 } 12 } 13 }
Bll將數據庫數據進行整理得到前臺須要的數據;
1 //建立發送表 2 public void CreateEmailTable(string sendTableName) 3 { 4 var sql = "CREATE TABLE [dbo].[" + sendTableName + "] " + 5 "([Id] int IDENTITY(1,1) NOT NULL," + 6 "[Email] nvarchar(max) NOT NULL," + 7 "[IsSend] int NULL ," + 8 "[IsArrive] int NULL ," + 9 "[IsOpen] int NULL," + 10 "[IsReturnEmail] int NULL," + 11 "[TheBackReason] nvarchar(128) NULL ," + 12 "[EmailType] nvarchar(128) NULL )"; 13 _sendTypeRepository.Insert(sql); 14 } 15 16 //導入email,經過txt和excel格式 17 public void BulkEmail(string sendTableName, string path) 18 { 19 var sql = "BULK INSERT lxtest2.dbo.LoginTxt " +//要導入的數據庫目標表 20 "FROM '" + path + "' " + //文本源數據文件 21 "WITH ( " + 22 "FIELDTERMINATOR = ';', " + //列結束符 23 "ROWTERMINATOR = '\r\n' " + //行結束符 24 ")"; 25 //SqlParameter[] sqlParameters = 26 //{ 27 // new SqlParameter { ParameterName = "a", Value = 1 }, 28 // new SqlParameter { ParameterName = "b", Value = 2 } 29 //}; 30 31 _sendTypeRepository.Insert(sql); 32 RemoveEmail(sendTableName); 33 34 }