Browse Source

修正由于发邮件是异步导致附件覆盖,邮件附件中案件清单不对的问题

luocaiyang 8 months ago
parent
commit
5eca828758
1 changed files with 40 additions and 47 deletions
  1. 40 47
      wispro.sp.api/Controllers/CaseFileCompareController.cs

+ 40 - 47
wispro.sp.api/Controllers/CaseFileCompareController.cs

@@ -970,14 +970,15 @@ namespace wispro.sp.api.Controllers
             var top10List = monthItemList.OrderByDescending(r => r.CustomerSim)
                 .Take(10).ToList();
 
-            
+
             Hashtable reviewerHash = new Hashtable(); //核稿人
             Hashtable crHash = new Hashtable(); //客户对接人
             Hashtable dphash = new Hashtable(); //部长
             foreach (var item in top10List)
             {
                 #region 核稿人
-                if (!string.IsNullOrEmpty(item.Reviewer)) {
+                if (!string.IsNullOrEmpty(item.Reviewer))
+                {
                     Staff reviewer = Context.Staffs.Where(s => s.Name == item.Reviewer).FirstOrDefault();
                     List<retObject> rets = new List<retObject>();
                     foreach (Staff k in reviewerHash.Keys)
@@ -998,10 +999,11 @@ namespace wispro.sp.api.Controllers
                 #endregion
 
                 #region 客户对接人
-                
-                if (!string.IsNullOrEmpty(item.Customer)) {
+
+                if (!string.IsNullOrEmpty(item.Customer))
+                {
                     Customer c = Context.Customers.Where(s => s.Name == item.Customer)
-                        .Include(s=>s.ResponseMan).FirstOrDefault();
+                        .Include(s => s.ResponseMan).FirstOrDefault();
                     if (c != null && c.ResponseMan != null)
                     {
                         List<retObject> rets = new List<retObject>();
@@ -1023,72 +1025,49 @@ namespace wispro.sp.api.Controllers
                 #endregion
 
                 #region 部长
-                
+
                 string[] Handlers = item.Handers.Split(",");
-                foreach(string n in Handlers)
+                foreach (string n in Handlers)
                 {
                     var dpList = Context.DepartmentPositions.Where(d => d.Staff.Name == n).Include(d => d.department).ToList();
-                    foreach(var dp in dpList)
+                    foreach (var dp in dpList)
                     {
                         var dpObj = Context.DepartmentPositions.Where(d => d.departmentId == dp.departmentId && d.Position.Name == "部长").Include(d => d.Staff).FirstOrDefault();
-                        if(dpObj!= null)
+                        if (dpObj != null)
                         {
                             List<retObject> rets = new List<retObject>();
-                            foreach(Staff k in dphash.Keys)
+                            foreach (Staff k in dphash.Keys)
                             {
-                                if(k.Id == dpObj.StaffId)
+                                if (k.Id == dpObj.StaffId)
                                 {
                                     rets = (List<retObject>)dphash[k];
                                     break;
                                 }
                             }
-                            if (rets.Count ==0)
-                            { 
+                            if (rets.Count == 0)
+                            {
                                 dphash.Add(dpObj.Staff, rets);
                             }
 
-                            if(!rets.Contains(item))
+                            if (!rets.Contains(item))
                                 rets.Add(item);
                         }
 
                     }
-                    
+
                 }
                 #endregion
             }
 
-            foreach(Staff sf in reviewerHash.Keys)
-            {
-                List<retObject> temList = (List<retObject>)reviewerHash[sf];
-                DataTable temdt  = CoverttoDatable(temList);
-                string strPath = $"{year}年{month}月客户修改权要排名前10的案件清单(审核人).xlsx";
-                utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
-                string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月您核稿的案件,客户权要修改率在前10的案件,请注意核稿质量!";
-                _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
-            }
+            SendMail(year, month, reviewerHash,"核稿");
 
-            foreach (Staff sf in crHash.Keys)
-            {
-                List<retObject> temList = (List<retObject>)crHash[sf];
-                DataTable temdt = CoverttoDatable(temList);
-                string strPath = $"{year}年{month}月客户修改权要排名前10的案件清单(客户对接人).xlsx";
-                utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
-                string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月你对接的客户的案件,客户权要修改率在前10的案件,请注意!";
-                _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
-            }
+            SendMail(year, month, crHash, "对接客户");
 
-            foreach (Staff sf in dphash.Keys)
-            {
-                List<retObject> temList = (List<retObject>)dphash[sf];
-                DataTable temdt = CoverttoDatable(temList);
-                string strPath = $"{year}年{month}月客户修改权要排名前10的案件清单(部长).xlsx";
-                utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
-                string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月贵部人员处理的,客户权要修改率在前10的案件,请注意!";
-                _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
-            }
+            SendMail(year, month, dphash, "部门人员处理");
+            
 
             DataTable dt = CoverttoDatable(top10List);
-            string top10_filePath = $"{year}年{month}月客户修改权要排名前10的案件清单.xlsx";
+            string top10_filePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"{year}年{month}月客户修改权要排名前10的案件清单.xlsx");
             utility.NPOIExcel.DataTableToExcel(dt, top10_filePath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
             #endregion
 
@@ -1100,17 +1079,17 @@ namespace wispro.sp.api.Controllers
 
             DataTable excdt = CoverttoDatable(excItemList);
 
-            string except_filePath = $"{year}年{month}月疑似有问题的案件清单.xlsx";
+            string except_filePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"{year}年{month}月疑似有问题的案件清单.xlsx");
             utility.NPOIExcel.DataTableToExcel(excdt, except_filePath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
             #endregion
 
             #region 所有案件清单
             var allItemList = monthItemList
-                .OrderBy(r => r.Customer).ThenByDescending(r=>r.CustomerSim)
+                .OrderBy(r => r.Customer).ThenByDescending(r => r.CustomerSim)
                 .ToList();
             DataTable alldt = CoverttoDatable(allItemList);
 
-            string all_filePath = $"{year}年{month}月案件清单.xlsx";
+            string all_filePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(),$"{year}年{month}月案件清单.xlsx");
             utility.NPOIExcel.DataTableToExcel(alldt, all_filePath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
 
             #endregion
@@ -1119,10 +1098,24 @@ namespace wispro.sp.api.Controllers
             _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "罗才洋", "luocaiyang@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
             _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "李庆波", "liqingbo@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
             _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "钟子敏", "zhongzimin@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
-            _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "王姝然", "zhongzimin@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
+            _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "王姝然", "wangshuran@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
             #endregion
         }
 
+        private void SendMail(int year, int month, Hashtable objHash,string type)
+        {
+            foreach (Staff sf in objHash.Keys)
+            {
+                List<retObject> temList = (List<retObject>)objHash[sf];
+                DataTable temdt = CoverttoDatable(temList);
+                string strPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"{year}年{month}月客户修改权要排名前10的案件清单({type})_{sf.Name}.xlsx");
+                utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
+                string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月您{type}的案件,客户权要修改率在前10的案件,请注意!";
+                
+                _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
+            }
+        }
+
         private double? getCalValue(CaseInfo caseInfo,int type,int stage)
         {
             double? calValue = null;