MissingCaseReviewHandler.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. var appealRecord = ((spDbContext)spContext).AppealRecords.Where<AppealRecord>(f => f.Id == appealRecordId).Include(f=>f.Creater).FirstOrDefault();
  39. string strCaseNo ="";
  40. string strDoItem="";
  41. string strCaseStage = "";
  42. foreach (var iv in result)
  43. {
  44. if (iv.InputField == null)
  45. {
  46. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  47. }
  48. if (iv.InputField.FieldName == "我方文号")
  49. {
  50. strCaseNo = iv.Value;
  51. continue;
  52. }
  53. if (iv.InputField.FieldName == "处理事项")
  54. {
  55. strDoItem=iv.Value;
  56. continue;
  57. }
  58. if (iv.InputField.FieldName == "案件阶段")
  59. {
  60. strCaseStage = iv.Value;
  61. continue;
  62. }
  63. }
  64. var itemControler = new PerformanceItemController((spDbContext)spContext,new Services.FileTaskCacheService());
  65. PerformanceItem Item = null;
  66. if (strDoItem == "发明一次OA授权")
  67. {
  68. try
  69. {
  70. Item = itemControler.GetItemInfoByCaseStage(strCaseNo,new List<string>() { "处理审查意见", "电询", "集中审查", "补正","新申请" }, "");
  71. }
  72. catch { }
  73. #region oldcode
  74. //if (Item == null || Item.ItemStaffs.Where(s => s.DoPerson.Name == appealRecord.Creater.Name).Count() ==0 )
  75. //{
  76. // Item = null;
  77. // try
  78. // {
  79. // Item = itemControler.GetItemInfoByCaseStage(strCaseNo, "电询", "");
  80. // }
  81. // catch { }
  82. //}
  83. //if (Item == null || Item.ItemStaffs.Where(s => s.DoPerson.Name == appealRecord.Creater.Name).Count() == 0)
  84. //{
  85. // Item = null;
  86. // try
  87. // {
  88. // Item = itemControler.GetItemInfoByCaseStage(strCaseNo, "集中审查", "");
  89. // }
  90. // catch { }
  91. //}
  92. //if (Item == null || Item.ItemStaffs.Where(s => s.DoPerson.Name == appealRecord.Creater.Name).Count() == 0)
  93. //{
  94. // Item = null;
  95. // try
  96. // {
  97. // Item = itemControler.GetItemInfoByCaseStage(strCaseNo, "补正", "");
  98. // }
  99. // catch { }
  100. //}
  101. //if (Item == null || Item.ItemStaffs.Where(s => s.DoPerson.Name == appealRecord.Creater.Name).Count() == 0)
  102. //{
  103. // Item = null;
  104. // try
  105. // {
  106. // Item = itemControler.GetItemInfoByCaseStage(strCaseNo, "新申请", "");
  107. // }
  108. // catch { }
  109. //}
  110. #endregion
  111. }
  112. else
  113. {
  114. Item = itemControler.GetItemInfoByCaseStage(strCaseNo, strDoItem, strCaseStage);
  115. }
  116. CalMonth calMonth = ((spDbContext)spContext).CalMonths.FirstOrDefault(c=>c.Status == 0);
  117. if (calMonth != null )
  118. {
  119. if (Item.Id == 0 || Item.CalMonthId != calMonth.Id)
  120. {
  121. Item.Id = 0;
  122. if (strDoItem == "发明一次OA授权")
  123. {
  124. if (Item.ItemStaffs.Where(s => s.DoPerson.Name == appealRecord.Creater.Name).Count() == 0)
  125. {
  126. throw new Exception($"最后一次{Item.DoItem}处理人与缺漏申请人不一致!");
  127. }
  128. else
  129. {
  130. Item.DoItem = strDoItem;
  131. Item.AgentFeedbackMemo = strDoItem;
  132. }
  133. }
  134. SaveToDb(Item, (spDbContext)spContext, calMonth);
  135. itemControler.RefreshPoint(Item);
  136. }
  137. }
  138. }
  139. }
  140. private void SaveToDb(PerformanceItem item,spDbContext Context,CalMonth calMonth)
  141. {
  142. try
  143. {
  144. item.CalMonthId = calMonth.Id;
  145. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  146. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  147. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  148. if (items != null)
  149. {
  150. item.AgentFeedbackMemo = "已算绩效";
  151. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  152. item.BasePoint = 0;
  153. }
  154. if (item.Customer != null && !string.IsNullOrEmpty(item.Customer.Name))
  155. {
  156. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  157. if (temCustomer == null)
  158. {
  159. temCustomer = new Customer() { Name = item.Customer.Name };
  160. //item.Customer.Id = 0;
  161. Context.Customers.Add(temCustomer);
  162. Context.SaveChanges();
  163. item.Customer = temCustomer;
  164. //item.CustomerId = item.Customer.Id;
  165. }
  166. else
  167. {
  168. item.Customer = temCustomer;
  169. }
  170. item.CustomerId = item.Customer.Id;
  171. item.Customer = null;
  172. }
  173. else
  174. {
  175. item.Customer = null;
  176. }
  177. var ItemStaffs = item.ItemStaffs;
  178. item.ItemStaffs = null;
  179. if (item.ReviewerId != null)
  180. {
  181. var Reviewer = item.Reviewer;
  182. item.Reviewer = null;
  183. }
  184. Context.PerformanceItems.Add(item);
  185. Context.SaveChanges();
  186. foreach (ItemStaff itemStaff in ItemStaffs)
  187. {
  188. itemStaff.ItemId = item.Id;
  189. itemStaff.Item = null;
  190. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  191. {
  192. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  193. if (temStaff != null)
  194. {
  195. itemStaff.DoPersonId = temStaff.Id;
  196. itemStaff.DoPerson = null;
  197. }
  198. else
  199. {
  200. Context.Staffs.Add(itemStaff.DoPerson);
  201. Context.SaveChanges();
  202. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  203. itemStaff.DoPerson = null;
  204. }
  205. }
  206. else
  207. {
  208. itemStaff.DoPerson = null;
  209. }
  210. }
  211. Context.ItemStaffs.AddRange(ItemStaffs);
  212. Context.SaveChanges();
  213. }
  214. catch (Exception ex)
  215. {
  216. throw ex;
  217. }
  218. }
  219. }
  220. }