MissingCaseReviewHandler.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. else
  28. {
  29. if (iv.InputField.FieldName == "审核意见" && string.IsNullOrEmpty(iv.Value))
  30. {
  31. throw (new ApplicationException("请填写审核意见!"));
  32. }
  33. }
  34. }
  35. if (isAggree)
  36. {
  37. var result = ((spDbContext)spContext).InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == appealRecordId && f.InputField.AppealState == 0).ToList();
  38. string strCaseNo="";
  39. string strDoItem="";
  40. string strCaseStage = "";
  41. foreach (var iv in result)
  42. {
  43. if (iv.InputField == null)
  44. {
  45. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  46. }
  47. if (iv.InputField.FieldName == "我方文号")
  48. {
  49. strCaseNo = iv.Value;
  50. continue;
  51. }
  52. if (iv.InputField.FieldName == "处理事项")
  53. {
  54. strDoItem=iv.Value;
  55. continue;
  56. }
  57. if (iv.InputField.FieldName == "案件阶段")
  58. {
  59. strCaseStage = iv.Value;
  60. continue;
  61. }
  62. }
  63. var itemControler = new PerformanceItemController((spDbContext)spContext,new Services.FileTaskCacheService());
  64. PerformanceItem Item = itemControler.GetItemInfoByCaseStage(strCaseNo,strDoItem, strCaseStage);
  65. CalMonth calMonth = ((spDbContext)spContext).CalMonths.FirstOrDefault(c=>c.Status == 0);
  66. if (calMonth != null )
  67. {
  68. if (Item.Id == 0 || Item.CalMonthId != calMonth.Id)
  69. {
  70. Item.Id = 0;
  71. SaveToDb(Item, (spDbContext)spContext, calMonth);
  72. itemControler.RefreshPoint(Item);
  73. }
  74. }
  75. }
  76. }
  77. private void SaveToDb(PerformanceItem item,spDbContext Context,CalMonth calMonth)
  78. {
  79. try
  80. {
  81. item.CalMonthId = calMonth.Id;
  82. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  83. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  84. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  85. if (items != null)
  86. {
  87. item.AgentFeedbackMemo = "已算绩效";
  88. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  89. item.BasePoint = 0;
  90. }
  91. if (item.Customer != null && !string.IsNullOrEmpty(item.Customer.Name))
  92. {
  93. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  94. if (temCustomer == null)
  95. {
  96. temCustomer = new Customer() { Name = item.Customer.Name };
  97. //item.Customer.Id = 0;
  98. Context.Customers.Add(temCustomer);
  99. Context.SaveChanges();
  100. item.Customer = temCustomer;
  101. //item.CustomerId = item.Customer.Id;
  102. }
  103. else
  104. {
  105. item.Customer = temCustomer;
  106. }
  107. item.CustomerId = item.Customer.Id;
  108. item.Customer = null;
  109. }
  110. else
  111. {
  112. item.Customer = null;
  113. }
  114. var ItemStaffs = item.ItemStaffs;
  115. item.ItemStaffs = null;
  116. if (item.ReviewerId != null)
  117. {
  118. var Reviewer = item.Reviewer;
  119. item.Reviewer = null;
  120. }
  121. Context.PerformanceItems.Add(item);
  122. Context.SaveChanges();
  123. foreach (ItemStaff itemStaff in ItemStaffs)
  124. {
  125. itemStaff.ItemId = item.Id;
  126. itemStaff.Item = null;
  127. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  128. {
  129. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  130. if (temStaff != null)
  131. {
  132. itemStaff.DoPersonId = temStaff.Id;
  133. itemStaff.DoPerson = null;
  134. }
  135. else
  136. {
  137. Context.Staffs.Add(itemStaff.DoPerson);
  138. Context.SaveChanges();
  139. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  140. itemStaff.DoPerson = null;
  141. }
  142. }
  143. else
  144. {
  145. itemStaff.DoPerson = null;
  146. }
  147. }
  148. Context.ItemStaffs.AddRange(ItemStaffs);
  149. Context.SaveChanges();
  150. }
  151. catch (Exception ex)
  152. {
  153. throw ex;
  154. }
  155. }
  156. }
  157. }