MissingCaseReviewHandler.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using Microsoft.EntityFrameworkCore;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using wispro.sp.api.Controllers;
  7. using wispro.sp.entity;
  8. using wispro.sp.share;
  9. namespace wispro.sp.api.AppealHandler
  10. {
  11. public class MissingCaseReviewHandler : IDoAppealObject
  12. {
  13. public void DoAppeal(AppealObject appeal, int appealRecordId, DbContext spContext)
  14. {
  15. bool isAggree = false;
  16. foreach (var iv in appeal.inputFieldValues)
  17. {
  18. if (iv.InputField == null)
  19. {
  20. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  21. }
  22. if (iv.InputField.FieldName == "审核意见" && iv.Value =="同意")
  23. {
  24. isAggree = true;
  25. break;
  26. }
  27. }
  28. if (isAggree)
  29. {
  30. var result = ((spDbContext)spContext).InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == appealRecordId && f.InputField.AppealState == 0).ToList();
  31. string strCaseNo="";
  32. string strDoItem="";
  33. string strCaseStage = "";
  34. foreach (var iv in result)
  35. {
  36. if (iv.InputField == null)
  37. {
  38. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  39. }
  40. if (iv.InputField.FieldName == "我方文号")
  41. {
  42. strCaseNo = iv.Value;
  43. continue;
  44. }
  45. if (iv.InputField.FieldName == "处理事项")
  46. {
  47. strDoItem=iv.Value;
  48. continue;
  49. }
  50. if (iv.InputField.FieldName == "案件阶段")
  51. {
  52. strCaseStage = iv.Value;
  53. continue;
  54. }
  55. }
  56. var itemControler = new PerformanceItemController((spDbContext)spContext,new Services.FileTaskCacheService());
  57. PerformanceItem Item = itemControler.GetItemInfoByCaseStage(strCaseNo,strDoItem, strCaseStage);
  58. var Rules = ((spDbContext)spContext).BasePointRules.ToList();
  59. Utility.Utility.CalBasePoint(Item, Rules);
  60. CalMonth calMonth = ((spDbContext)spContext).CalMonths.FirstOrDefault(c=>c.Status == 0);
  61. if (calMonth != null )
  62. {
  63. if (Item.Id == 0 || Item.CalMonthId != calMonth.Id)
  64. {
  65. Item.Id = 0;
  66. SaveToDb(Item, (spDbContext)spContext, calMonth);
  67. }
  68. }
  69. //((spDbContext)spContext).PerformanceItems.Add(Item);
  70. //((spDbContext)spContext).SaveChanges();
  71. }
  72. }
  73. private void SaveToDb(PerformanceItem item,spDbContext Context,CalMonth calMonth)
  74. {
  75. try
  76. {
  77. item.CalMonthId = calMonth.Id;
  78. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  79. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  80. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  81. if (items != null)
  82. {
  83. item.AgentFeedbackMemo = "已算绩效";
  84. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  85. item.BasePoint = 0;
  86. }
  87. if (item.Customer != null && !string.IsNullOrEmpty(item.Customer.Name))
  88. {
  89. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  90. if (temCustomer == null)
  91. {
  92. temCustomer = new Customer() { Name = item.Customer.Name };
  93. //item.Customer.Id = 0;
  94. Context.Customers.Add(temCustomer);
  95. Context.SaveChanges();
  96. item.Customer = temCustomer;
  97. //item.CustomerId = item.Customer.Id;
  98. }
  99. else
  100. {
  101. item.Customer = temCustomer;
  102. }
  103. item.CustomerId = item.Customer.Id;
  104. item.Customer = null;
  105. }
  106. else
  107. {
  108. item.Customer = null;
  109. }
  110. var ItemStaffs = item.ItemStaffs;
  111. item.ItemStaffs = null;
  112. if (item.ReviewerId != null)
  113. {
  114. var Reviewer = item.Reviewer;
  115. item.Reviewer = null;
  116. }
  117. Context.PerformanceItems.Add(item);
  118. Context.SaveChanges();
  119. foreach (ItemStaff itemStaff in ItemStaffs)
  120. {
  121. itemStaff.ItemId = item.Id;
  122. itemStaff.Item = null;
  123. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  124. {
  125. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  126. if (temStaff != null)
  127. {
  128. itemStaff.DoPersonId = temStaff.Id;
  129. itemStaff.DoPerson = null;
  130. }
  131. else
  132. {
  133. Context.Staffs.Add(itemStaff.DoPerson);
  134. Context.SaveChanges();
  135. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  136. itemStaff.DoPerson = null;
  137. }
  138. }
  139. else
  140. {
  141. itemStaff.DoPerson = null;
  142. }
  143. }
  144. Context.ItemStaffs.AddRange(ItemStaffs);
  145. Context.SaveChanges();
  146. }
  147. catch (Exception ex)
  148. {
  149. throw ex;
  150. }
  151. }
  152. }
  153. }