UpdateJXDataFromIPEasyJob.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.AgentFeedbackMemo != "已算绩效" || p.AgentFeedbackMemo==null ) && p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")))
  17. .Include(p=>p.Reviewer)
  18. .Include(p=>p.CalMonth)
  19. .ToList<PerformanceItem>();
  20. if (lstItem != null)
  21. {
  22. int i = 0;
  23. foreach (var Item in lstItem)
  24. {
  25. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{++i}\t{Item.CaseNo}");
  26. int iTryCount = 0;
  27. TryAgain:
  28. try
  29. {
  30. iTryCount++;
  31. dynamic retObj = utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem,string.IsNullOrEmpty(Item.CaseStage)?null: Item.CaseStage);
  32. IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retObj;
  33. if (keyValuePairs.ContainsKey("DoItemCoefficient") && Item.DoItemCoefficient != retObj.DoItemCoefficient)
  34. {
  35. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  36. }
  37. if (keyValuePairs.ContainsKey("DoItemMemo") && Item.DoItemMemo != retObj.DoItemMemo && !string.IsNullOrEmpty(retObj.DoItemMemo))
  38. {
  39. Item.DoItemMemo = retObj.DoItemMemo;
  40. }
  41. if (keyValuePairs.ContainsKey("DoItemState") && Item.DoItemState != retObj.DoItemState && !string.IsNullOrEmpty(retObj.DoItemState))
  42. {
  43. Item.DoItemState = retObj.DoItemState;
  44. }
  45. if (keyValuePairs.ContainsKey("CustomerLimitDate"))
  46. {
  47. if (!string.IsNullOrEmpty(retObj.CustomerLimitDate))
  48. {
  49. DateTime date = DateTime.Parse(retObj.CustomerLimitDate);
  50. if (date != Item.CustomerLimitDate)
  51. Item.CustomerLimitDate = date;
  52. }
  53. }
  54. if (keyValuePairs.ContainsKey("EntrustingDate"))
  55. {
  56. if (!string.IsNullOrEmpty(retObj.EntrustingDate))
  57. {
  58. DateTime date = DateTime.Parse(retObj.EntrustingDate);
  59. if (date != Item.EntrustingDate)
  60. Item.EntrustingDate = date;
  61. }
  62. }
  63. if (keyValuePairs.ContainsKey("FinalizationDate"))
  64. {
  65. if (!string.IsNullOrEmpty(retObj.FinalizationDate))
  66. {
  67. DateTime date = DateTime.Parse(retObj.FinalizationDate);
  68. if (date != Item.FinalizationDate)
  69. Item.FinalizationDate = date;
  70. }
  71. }
  72. if (keyValuePairs.ContainsKey("FinishedDate"))
  73. {
  74. if (!string.IsNullOrEmpty(retObj.FinishedDate))
  75. {
  76. DateTime date = DateTime.Parse(retObj.FinishedDate);
  77. if (date != Item.FinishedDate)
  78. Item.FinishedDate = date;
  79. }
  80. }
  81. if (keyValuePairs.ContainsKey("FirstDraftDate"))
  82. {
  83. if (!string.IsNullOrEmpty(retObj.FirstDraftDate))
  84. {
  85. DateTime date = DateTime.Parse(retObj.FirstDraftDate);
  86. if (date != Item.FirstDraftDate)
  87. Item.FirstDraftDate = date;
  88. }
  89. }
  90. if (keyValuePairs.ContainsKey("InternalDate"))
  91. {
  92. if (!string.IsNullOrEmpty(retObj.InternalDate))
  93. {
  94. DateTime date = DateTime.Parse(retObj.InternalDate);
  95. if (date != Item.InternalDate)
  96. Item.InternalDate = date;
  97. }
  98. }
  99. if (keyValuePairs.ContainsKey("ReturnDate"))
  100. {
  101. if (!string.IsNullOrEmpty(retObj.ReturnDate))
  102. {
  103. DateTime date = DateTime.Parse(retObj.ReturnDate);
  104. if (date != Item.ReturnDate)
  105. Item.ReturnDate = date;
  106. }
  107. }
  108. if (keyValuePairs.ContainsKey("WordCount"))
  109. {
  110. if (!string.IsNullOrEmpty(retObj.WordCount))
  111. {
  112. var wordCount = int.Parse(retObj.WordCount);
  113. if (wordCount != Item.WordCount)
  114. Item.WordCount = wordCount;
  115. }
  116. }
  117. if (keyValuePairs.ContainsKey("Reviewer") && (Item.Reviewer ==null || Item.Reviewer.Name != retObj.Reviewer) && !string.IsNullOrEmpty(retObj.Reviewer))
  118. {
  119. string name = retObj.Reviewer;
  120. if (!string.IsNullOrEmpty(name))
  121. {
  122. var temReviewer = spDb.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  123. if (temReviewer == null)
  124. {
  125. //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  126. }
  127. else
  128. {
  129. //Item.Reviewer = temReviewer;
  130. Item.ReviewerId = temReviewer.Id;
  131. }
  132. }
  133. }
  134. if (keyValuePairs.ContainsKey("ApplicationType") && Item.ApplicationType != retObj.ApplicationType && !string.IsNullOrEmpty(retObj.ApplicationType))
  135. {
  136. Item.ApplicationType = retObj.ApplicationType;
  137. }
  138. if (keyValuePairs.ContainsKey("BusinessType") && Item.BusinessType != retObj.BusinessType && !string.IsNullOrEmpty(retObj.BusinessType))
  139. {
  140. Item.BusinessType = retObj.BusinessType;
  141. }
  142. if (keyValuePairs.ContainsKey("CaseCoefficient") && Item.CaseCoefficient != retObj.CaseCoefficient && !string.IsNullOrEmpty(retObj.CaseCoefficient))
  143. {
  144. if (!string.IsNullOrEmpty(retObj.CaseCoefficient)){
  145. Item.CaseCoefficient = retObj.CaseCoefficient;
  146. }
  147. }
  148. //if (keyValuePairs.ContainsKey("CaseMemo") && Item.CaseMemo != retObj.CaseMemo && !string.IsNullOrEmpty(retObj.CaseMemo))
  149. //{
  150. // Item.CaseMemo = retObj.CaseMemo;
  151. //}
  152. if (keyValuePairs.ContainsKey("CaseStage") && Item.CaseStage != retObj.CaseStage && !string.IsNullOrEmpty(retObj.CaseStage))
  153. {
  154. Item.CaseStage = retObj.CaseStage;
  155. }
  156. if (keyValuePairs.ContainsKey("CaseState") && Item.CaseState != retObj.CaseState && !string.IsNullOrEmpty(retObj.CaseState))
  157. {
  158. Item.CaseState = retObj.CaseState;
  159. }
  160. if (keyValuePairs.ContainsKey("CaseType") && Item.CaseType != retObj.CaseType && !string.IsNullOrEmpty(retObj.CaseType))
  161. {
  162. Item.CaseType = retObj.CaseType;
  163. }
  164. //if (Item.FinishedDate.HasValue &&
  165. // Item.FinishedDate.Value.ToString("yyyy-MM") != DateTime.Parse($"{Item.CalMonth.Year}-{Item.CalMonth.Month}-01").ToString("yyyy-MM"))
  166. //{
  167. // //删除完成日变成下一个月的记录
  168. // var ItemStaffs = spDb.ItemStaffs.Where(p => p.ItemId == Item.Id).ToList();
  169. // foreach(var itemstaff in ItemStaffs)
  170. // {
  171. // spDb.Remove(itemstaff);
  172. // }
  173. // spDb.PerformanceItems.Remove(Item);
  174. // spDb.SaveChanges();
  175. //}
  176. //else
  177. //{
  178. if (spDb.Entry(Item).State != EntityState.Unchanged)
  179. {
  180. Utility.Utility.CalBasePoint(Item, spDb.BasePointRules.ToList());
  181. spDb.SaveChanges();
  182. }
  183. //}
  184. }
  185. catch(Exception ex)
  186. {
  187. if(iTryCount <= 3)
  188. {
  189. goto TryAgain;
  190. }
  191. System.Diagnostics.Debug.WriteLine(ex.ToString());
  192. }
  193. }
  194. }
  195. return Task.CompletedTask;
  196. }
  197. }
  198. }