ChangeDoPersonReviewer.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 ChangeDoPersonReviewer : 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 strOldPerson = "";
  32. string strNewPerson = "";
  33. foreach (var iv in result)
  34. {
  35. if (iv.InputField == null)
  36. {
  37. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  38. }
  39. if (iv.InputField.FieldName == "变更前处理人")
  40. {
  41. strOldPerson = iv.Value;
  42. continue;
  43. }
  44. if (iv.InputField.FieldName == "变更后处理人")
  45. {
  46. strNewPerson = iv.Value;
  47. continue;
  48. }
  49. }
  50. var appRecord = ((spDbContext)spContext).AppealRecords.FirstOrDefault(f => f.Id == appealRecordId);
  51. if(appRecord != null)
  52. {
  53. var itemStaffs = ((spDbContext)spContext).ItemStaffs.Include(p=>p.DoPerson).Where(s => s.ItemId == appRecord.ItemId.Value);
  54. var newStaff = ((spDbContext)spContext).Staffs.FirstOrDefault(s=>s.Name == strNewPerson.Trim());
  55. if (newStaff != null)
  56. {
  57. bool oldPersonExist = false;
  58. foreach (ItemStaff staff in itemStaffs)
  59. {
  60. if (staff.DoPerson.Name == strOldPerson.Trim())
  61. {
  62. ((spDbContext)spContext).Staffs.Remove(staff.DoPerson);
  63. oldPersonExist = true;
  64. break;
  65. }
  66. }
  67. if (oldPersonExist)
  68. {
  69. ((spDbContext)spContext).ItemStaffs.Add(new ItemStaff() {
  70. ItemId = appRecord.ItemId.Value,
  71. DoPersonId = newStaff.Id
  72. });
  73. }
  74. else
  75. {
  76. throw new ApplicationException("变更前处理人不存在!");
  77. }
  78. }
  79. else
  80. {
  81. throw new ApplicationException("变更后处理人不存在!");
  82. }
  83. }
  84. //((spDbContext)spContext).PerformanceItems.Add(Item);
  85. //((spDbContext)spContext).SaveChanges();
  86. }
  87. }
  88. }
  89. }