ChangeDoPersonReviewer.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 oldPersons = strOldPerson.Split(new char[] { ' ', ',' },StringSplitOptions.RemoveEmptyEntries);
  55. var newPersons = strNewPerson.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  56. bool oldPersonExist = false;
  57. List<ItemStaff> waitingRemoveObj = new List<ItemStaff>();
  58. foreach (ItemStaff staff in itemStaffs)
  59. {
  60. if (oldPersons.Contains(staff.DoPerson.Name))
  61. {
  62. waitingRemoveObj.Add(staff);
  63. oldPersonExist = true;
  64. }
  65. else
  66. {
  67. oldPersonExist = false;
  68. break;
  69. }
  70. }
  71. if (oldPersonExist)
  72. {
  73. ((spDbContext)spContext).ItemStaffs.RemoveRange(waitingRemoveObj);
  74. foreach (var temName in newPersons)
  75. {
  76. var newStaff = ((spDbContext)spContext).Staffs.FirstOrDefault(s => s.Name == temName.Trim());
  77. if (newStaff != null)
  78. {
  79. ((spDbContext)spContext).ItemStaffs.Add(new ItemStaff()
  80. {
  81. ItemId = appRecord.ItemId.Value,
  82. DoPersonId = newStaff.Id
  83. });
  84. }
  85. else
  86. {
  87. throw new ApplicationException("变更后处理人不存在!");
  88. }
  89. }
  90. }
  91. else
  92. {
  93. throw new ApplicationException("变更前处理人不存在!");
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }