UpdateJXDataFromIPEasyJob.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using Microsoft.EntityFrameworkCore;
  2. using Quartz;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity;
  9. namespace wispro.sp.api.Job
  10. {
  11. public class UpdateJXDataFromIPEasyJob : IJob
  12. {
  13. public void UpdateFromIPEasy(PerformanceItem Item,spDbContext spDb)
  14. {
  15. dynamic retObj = utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem, string.IsNullOrEmpty(Item.CaseStage) ? null : Item.CaseStage);
  16. IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retObj;
  17. if (keyValuePairs.ContainsKey("DoItemCoefficient") && Item.DoItemCoefficient != retObj.DoItemCoefficient)
  18. {
  19. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  20. }
  21. if (keyValuePairs.ContainsKey("DoItemMemo") && Item.DoItemMemo != retObj.DoItemMemo && !string.IsNullOrEmpty(retObj.DoItemMemo))
  22. {
  23. Item.DoItemMemo = retObj.DoItemMemo;
  24. }
  25. if (keyValuePairs.ContainsKey("DoItemState") && Item.DoItemState != retObj.DoItemState && !string.IsNullOrEmpty(retObj.DoItemState))
  26. {
  27. Item.DoItemState = retObj.DoItemState;
  28. }
  29. if (keyValuePairs.ContainsKey("CustomerLimitDate"))
  30. {
  31. if (!string.IsNullOrEmpty(retObj.CustomerLimitDate))
  32. {
  33. DateTime date = DateTime.Parse(retObj.CustomerLimitDate);
  34. if (date != Item.CustomerLimitDate)
  35. Item.CustomerLimitDate = date;
  36. }
  37. }
  38. if (keyValuePairs.ContainsKey("EntrustingDate"))
  39. {
  40. if (!string.IsNullOrEmpty(retObj.EntrustingDate))
  41. {
  42. DateTime date = DateTime.Parse(retObj.EntrustingDate);
  43. if (date != Item.EntrustingDate)
  44. Item.EntrustingDate = date;
  45. }
  46. }
  47. if (keyValuePairs.ContainsKey("FinalizationDate"))
  48. {
  49. if (!string.IsNullOrEmpty(retObj.FinalizationDate))
  50. {
  51. DateTime date = DateTime.Parse(retObj.FinalizationDate);
  52. if (date != Item.FinalizationDate)
  53. Item.FinalizationDate = date;
  54. }
  55. }
  56. if (keyValuePairs.ContainsKey("FinishedDate"))
  57. {
  58. if (!string.IsNullOrEmpty(retObj.FinishedDate))
  59. {
  60. DateTime date = DateTime.Parse(retObj.FinishedDate);
  61. if (date != Item.FinishedDate)
  62. Item.FinishedDate = date;
  63. }
  64. }
  65. if (keyValuePairs.ContainsKey("FirstDraftDate"))
  66. {
  67. if (!string.IsNullOrEmpty(retObj.FirstDraftDate))
  68. {
  69. DateTime date = DateTime.Parse(retObj.FirstDraftDate);
  70. if (date != Item.FirstDraftDate)
  71. Item.FirstDraftDate = date;
  72. }
  73. }
  74. if (keyValuePairs.ContainsKey("InternalDate"))
  75. {
  76. if (!string.IsNullOrEmpty(retObj.InternalDate))
  77. {
  78. DateTime date = DateTime.Parse(retObj.InternalDate);
  79. if (date != Item.InternalDate)
  80. Item.InternalDate = date;
  81. }
  82. }
  83. if (keyValuePairs.ContainsKey("ReturnDate"))
  84. {
  85. if (!string.IsNullOrEmpty(retObj.ReturnDate))
  86. {
  87. DateTime date = DateTime.Parse(retObj.ReturnDate);
  88. if (date != Item.ReturnDate)
  89. Item.ReturnDate = date;
  90. }
  91. }
  92. if (keyValuePairs.ContainsKey("WordCount"))
  93. {
  94. if (!string.IsNullOrEmpty(retObj.WordCount))
  95. {
  96. var wordCount = int.Parse(retObj.WordCount);
  97. if (wordCount != Item.WordCount)
  98. Item.WordCount = wordCount;
  99. }
  100. }
  101. if (keyValuePairs.ContainsKey("Reviewer") && (Item.Reviewer == null || Item.Reviewer.Name != retObj.Reviewer) && !string.IsNullOrEmpty(retObj.Reviewer))
  102. {
  103. string name = retObj.Reviewer;
  104. if (!string.IsNullOrEmpty(name))
  105. {
  106. var temReviewer = spDb.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  107. if (temReviewer == null)
  108. {
  109. //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  110. }
  111. else
  112. {
  113. //Item.Reviewer = temReviewer;
  114. Item.ReviewerId = temReviewer.Id;
  115. }
  116. }
  117. }
  118. if (keyValuePairs.ContainsKey("ApplicationType") && Item.ApplicationType != retObj.ApplicationType && !string.IsNullOrEmpty(retObj.ApplicationType))
  119. {
  120. Item.ApplicationType = retObj.ApplicationType;
  121. }
  122. if (keyValuePairs.ContainsKey("BusinessType") && Item.BusinessType != retObj.BusinessType && !string.IsNullOrEmpty(retObj.BusinessType))
  123. {
  124. Item.BusinessType = retObj.BusinessType;
  125. }
  126. if (keyValuePairs.ContainsKey("CaseCoefficient") && Item.CaseCoefficient != retObj.CaseCoefficient && !string.IsNullOrEmpty(retObj.CaseCoefficient))
  127. {
  128. if (!string.IsNullOrEmpty(retObj.CaseCoefficient))
  129. {
  130. Item.CaseCoefficient = retObj.CaseCoefficient;
  131. }
  132. }
  133. //if (keyValuePairs.ContainsKey("CaseMemo") && Item.CaseMemo != retObj.CaseMemo && !string.IsNullOrEmpty(retObj.CaseMemo))
  134. //{
  135. // Item.CaseMemo = retObj.CaseMemo;
  136. //}
  137. if (keyValuePairs.ContainsKey("CaseStage") && Item.CaseStage != retObj.CaseStage && !string.IsNullOrEmpty(retObj.CaseStage))
  138. {
  139. Item.CaseStage = retObj.CaseStage;
  140. }
  141. if (keyValuePairs.ContainsKey("CaseState") && Item.CaseState != retObj.CaseState && !string.IsNullOrEmpty(retObj.CaseState))
  142. {
  143. Item.CaseState = retObj.CaseState;
  144. }
  145. if (keyValuePairs.ContainsKey("CaseType") && Item.CaseType != retObj.CaseType && !string.IsNullOrEmpty(retObj.CaseType))
  146. {
  147. Item.CaseType = retObj.CaseType;
  148. }
  149. if (spDb.Entry(Item).State != EntityState.Unchanged)
  150. {
  151. if (Item.AgentFeedbackMemo != "特殊点数申诉")
  152. {
  153. Utility.Utility.CalBasePoint(Item, spDb.BasePointRules.ToList());
  154. spDb.SaveChanges();
  155. }
  156. }
  157. }
  158. public Task Execute(IJobExecutionContext context)
  159. {
  160. spDbContext spDb = new spDbContext();
  161. var lstItem = spDb.PerformanceItems.Where<PerformanceItem>(p =>
  162. ((p.AgentFeedbackMemo != "已算绩效" || p.AgentFeedbackMemo==null ) && p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")))
  163. .Include(p=>p.Reviewer)
  164. .Include(p=>p.CalMonth)
  165. .ToList<PerformanceItem>();
  166. if (lstItem != null)
  167. {
  168. int i = 0;
  169. foreach (var Item in lstItem)
  170. {
  171. int iTryCount = 0;
  172. TryAgain:
  173. try
  174. {
  175. iTryCount++;
  176. UpdateFromIPEasy(Item, spDb);
  177. Log($"{DateTime.Now}\t{++i}\t{Item.CaseNo}");
  178. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{i}\t{Item.CaseNo}");
  179. //}
  180. }
  181. catch(Exception ex)
  182. {
  183. if(iTryCount <= 3)
  184. {
  185. goto TryAgain;
  186. }
  187. System.Diagnostics.Debug.WriteLine(ex.ToString());
  188. Log($"{DateTime.Now}\t{++i}\t{Item.CaseNo}\r\n{ex.ToString()}");
  189. }
  190. }
  191. }
  192. return Task.CompletedTask;
  193. }
  194. private void Log(string strMessage)
  195. {
  196. StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
  197. sw.Write($"{strMessage}\r\n");
  198. sw.Flush();
  199. sw.Close();
  200. sw.Dispose();
  201. }
  202. }
  203. }