UpdateJXDataFromIPEasyJob.cs 9.2 KB

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