UpdateJXDataFromIPEasyJob.cs 11 KB

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