UpdateJXDataFromIPEasyJob.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. try
  28. {
  29. dynamic retObj = utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem,string.IsNullOrEmpty(Item.CaseStage)?null: Item.CaseStage);
  30. IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retObj;
  31. if (keyValuePairs.ContainsKey("DoItemCoefficient") && Item.DoItemCoefficient != retObj.DoItemCoefficient)
  32. {
  33. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  34. }
  35. if (keyValuePairs.ContainsKey("DoItemMemo") && Item.DoItemMemo != retObj.DoItemMemo && !string.IsNullOrEmpty(retObj.DoItemMemo))
  36. {
  37. Item.DoItemMemo = retObj.DoItemMemo;
  38. }
  39. if (keyValuePairs.ContainsKey("DoItemState") && Item.DoItemState != retObj.DoItemState && !string.IsNullOrEmpty(retObj.DoItemState))
  40. {
  41. Item.DoItemState = retObj.DoItemState;
  42. }
  43. if (keyValuePairs.ContainsKey("CustomerLimitDate"))
  44. {
  45. if (!string.IsNullOrEmpty(retObj.CustomerLimitDate))
  46. {
  47. DateTime date = DateTime.Parse(retObj.CustomerLimitDate);
  48. if (date != Item.CustomerLimitDate)
  49. Item.CustomerLimitDate = date;
  50. }
  51. }
  52. if (keyValuePairs.ContainsKey("EntrustingDate"))
  53. {
  54. if (!string.IsNullOrEmpty(retObj.EntrustingDate))
  55. {
  56. DateTime date = DateTime.Parse(retObj.EntrustingDate);
  57. if (date != Item.EntrustingDate)
  58. Item.EntrustingDate = date;
  59. }
  60. }
  61. if (keyValuePairs.ContainsKey("FinalizationDate"))
  62. {
  63. if (!string.IsNullOrEmpty(retObj.FinalizationDate))
  64. {
  65. DateTime date = DateTime.Parse(retObj.FinalizationDate);
  66. if (date != Item.FinalizationDate)
  67. Item.FinalizationDate = date;
  68. }
  69. }
  70. if (keyValuePairs.ContainsKey("FinishedDate"))
  71. {
  72. if (!string.IsNullOrEmpty(retObj.FinishedDate))
  73. {
  74. DateTime date = DateTime.Parse(retObj.FinishedDate);
  75. if (date != Item.FinishedDate)
  76. Item.FinishedDate = date;
  77. }
  78. }
  79. if (keyValuePairs.ContainsKey("FirstDraftDate"))
  80. {
  81. if (!string.IsNullOrEmpty(retObj.FirstDraftDate))
  82. {
  83. DateTime date = DateTime.Parse(retObj.FirstDraftDate);
  84. if (date != Item.FirstDraftDate)
  85. Item.FirstDraftDate = date;
  86. }
  87. }
  88. if (keyValuePairs.ContainsKey("InternalDate"))
  89. {
  90. if (!string.IsNullOrEmpty(retObj.InternalDate))
  91. {
  92. DateTime date = DateTime.Parse(retObj.InternalDate);
  93. if (date != Item.InternalDate)
  94. Item.InternalDate = date;
  95. }
  96. }
  97. if (keyValuePairs.ContainsKey("ReturnDate"))
  98. {
  99. if (!string.IsNullOrEmpty(retObj.ReturnDate))
  100. {
  101. DateTime date = DateTime.Parse(retObj.ReturnDate);
  102. if (date != Item.ReturnDate)
  103. Item.ReturnDate = date;
  104. }
  105. }
  106. if (keyValuePairs.ContainsKey("Reviewer") && (Item.Reviewer ==null || Item.Reviewer.Name != retObj.Reviewer) && !string.IsNullOrEmpty(retObj.Reviewer))
  107. {
  108. string name = retObj.Reviewer;
  109. if (!string.IsNullOrEmpty(name))
  110. {
  111. var temReviewer = spDb.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  112. if (temReviewer == null)
  113. {
  114. //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  115. }
  116. else
  117. {
  118. //Item.Reviewer = temReviewer;
  119. //Item.ReviewerId = temReviewer.Id;
  120. }
  121. }
  122. }
  123. if (keyValuePairs.ContainsKey("ApplicationType") && Item.ApplicationType != retObj.ApplicationType && !string.IsNullOrEmpty(retObj.ApplicationType))
  124. {
  125. Item.ApplicationType = retObj.ApplicationType;
  126. }
  127. if (keyValuePairs.ContainsKey("BusinessType") && Item.BusinessType != retObj.BusinessType && !string.IsNullOrEmpty(retObj.BusinessType))
  128. {
  129. Item.BusinessType = retObj.BusinessType;
  130. }
  131. if (keyValuePairs.ContainsKey("CaseCoefficient") && Item.CaseCoefficient != retObj.CaseCoefficient && !string.IsNullOrEmpty(retObj.CaseCoefficient))
  132. {
  133. if (!string.IsNullOrEmpty(retObj.CaseCoefficient)){
  134. Item.CaseCoefficient = retObj.CaseCoefficient;
  135. }
  136. }
  137. //if (keyValuePairs.ContainsKey("CaseMemo") && Item.CaseMemo != retObj.CaseMemo && !string.IsNullOrEmpty(retObj.CaseMemo))
  138. //{
  139. // Item.CaseMemo = retObj.CaseMemo;
  140. //}
  141. if (keyValuePairs.ContainsKey("CaseStage") && Item.CaseStage != retObj.CaseStage && !string.IsNullOrEmpty(retObj.CaseStage))
  142. {
  143. Item.CaseStage = retObj.CaseStage;
  144. }
  145. if (keyValuePairs.ContainsKey("CaseState") && Item.CaseState != retObj.CaseState && !string.IsNullOrEmpty(retObj.CaseState))
  146. {
  147. Item.CaseState = retObj.CaseState;
  148. }
  149. if (keyValuePairs.ContainsKey("CaseType") && Item.CaseType != retObj.CaseType && !string.IsNullOrEmpty(retObj.CaseType))
  150. {
  151. Item.CaseType = retObj.CaseType;
  152. }
  153. if (spDb.Entry(Item).State != EntityState.Unchanged)
  154. {
  155. Utility.Utility.CalBasePoint(Item, spDb.BasePointRules.ToList());
  156. spDb.SaveChanges();
  157. }
  158. }
  159. catch(Exception ex)
  160. {
  161. System.Diagnostics.Debug.WriteLine(ex.ToString());
  162. }
  163. }
  164. }
  165. return Task.CompletedTask;
  166. }
  167. }
  168. }