ChangeReviewerReviewer.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Microsoft.EntityFrameworkCore;
  2. using System;
  3. using System.Linq;
  4. using wispro.sp.entity;
  5. using wispro.sp.share;
  6. namespace wispro.sp.api.AppealHandler
  7. {
  8. public class ChangeReviewerReviewer : IDoAppealObject
  9. {
  10. public void DoAppeal(AppealObject appeal, int appealRecordId, DbContext spContext)
  11. {
  12. bool isAggree = false;
  13. foreach (var iv in appeal.inputFieldValues)
  14. {
  15. if (iv.InputField == null)
  16. {
  17. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  18. }
  19. if (iv.InputField.FieldName == "审核意见" && iv.Value == "确认变更")
  20. {
  21. isAggree = true;
  22. break;
  23. }
  24. else
  25. {
  26. if (iv.InputField.FieldName == "审核意见" && string.IsNullOrEmpty(iv.Value))
  27. {
  28. throw (new ApplicationException("请填写审核意见!"));
  29. }
  30. }
  31. }
  32. if (isAggree)
  33. {
  34. var result = ((spDbContext)spContext).InputFieldValues.Where<InputFieldValue>(f =>
  35. f.AppealRecordId == appealRecordId && f.InputField.AppealState == 0)
  36. .ToList();
  37. string strReviewerName = "";
  38. foreach (var iv in result)
  39. {
  40. if (iv.InputField == null)
  41. {
  42. iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
  43. }
  44. if (iv.InputField.FieldName == "实际核稿人")
  45. {
  46. strReviewerName = iv.Value;
  47. break;
  48. }
  49. }
  50. var appRecord = ((spDbContext)spContext).AppealRecords.Include(a=>a.Item).FirstOrDefault(f => f.Id == appealRecordId);
  51. if (appRecord != null && appRecord.Item != null)
  52. {
  53. var newStaff = ((spDbContext)spContext).Staffs.FirstOrDefault(s => s.Name == strReviewerName.Trim());
  54. if(newStaff != null)
  55. {
  56. appRecord.Item.ReviewerId = newStaff.Id;
  57. }
  58. else
  59. {
  60. throw new ApplicationException("输入的【实际核稿人】不存在!");
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }