ReviewerAppealModel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.Json;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. using wispro.sp.web.Services;
  9. namespace wispro.sp.web.Models
  10. {
  11. public class ReviewerAppealModel
  12. {
  13. public PerformanceItem Item { get; set; }
  14. public AppealType AppealType { get; set; }
  15. public List<InputField> CreateInputFields { get; set; }
  16. public List<InputFieldValue> CreateAppealFieldValues { get; set; }
  17. public List<InputField> inputFields { get; set; }
  18. public List<InputFieldValue> inputFieldValues { get; set; }
  19. public List<AttachFile> attachFiles { get; set; }
  20. public AppealRecord AppealRecord { get; set; }
  21. public async Task Init(AppealTypeService _atService, int appealRecordId)
  22. {
  23. this.AppealRecord =await _atService.getAppealRecord(appealRecordId);
  24. Item = this.AppealRecord.Item;
  25. CreateInputFields = await _atService.GetInputFields(this.AppealRecord.TypeId, 0);
  26. CreateAppealFieldValues = await _atService.GetInputFieldValues(this.AppealRecord.Id,0);
  27. inputFields = await _atService.GetInputFields(this.AppealRecord.TypeId, 1);
  28. attachFiles = await _atService.GetAppealRecordAttachFiles(this.AppealRecord.Id);
  29. inputFieldValues = new List<InputFieldValue>();
  30. foreach (var field in inputFields)
  31. {
  32. Console.WriteLine($"inputFields:{JsonSerializer.Serialize(field)}");
  33. if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
  34. {
  35. List<InputFieldValue> temValues = new List<InputFieldValue>();
  36. string[] pList = field.MapObjectField.Split(new char[] { '.' });
  37. string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
  38. var pInfo = Item.GetType().GetProperty(pList[0]);
  39. var o = pInfo.GetValue(Item);
  40. if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
  41. {
  42. List<string> Values = new List<string>();
  43. List<string> Labels = new List<string>();
  44. var objList = o as IEnumerable;
  45. foreach (var obj in objList)
  46. {
  47. var objValue = obj;
  48. var objLabel = obj;
  49. for (int i = 1; i < pList.Length; i++)
  50. {
  51. objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
  52. }
  53. for (int i = 1; i < plList.Length; i++)
  54. {
  55. objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
  56. }
  57. var fValue = new InputFieldValue();
  58. fValue.InputField = field;
  59. fValue.InputFieldId = field.Id;
  60. fValue.Label = objLabel.ToString();
  61. if (objValue != null)
  62. {
  63. fValue.Value = objValue.ToString();
  64. }
  65. inputFieldValues.Add(fValue);
  66. temValues.Add(fValue);
  67. }
  68. }
  69. else
  70. {
  71. var fValue = new InputFieldValue();
  72. fValue.InputField = field;
  73. fValue.InputFieldId = field.Id;
  74. inputFieldValues.Add(fValue);
  75. }
  76. }
  77. else
  78. {
  79. Console.WriteLine($"inputFields:{JsonSerializer.Serialize(field)}");
  80. var fValue = new InputFieldValue();
  81. fValue.InputField = field;
  82. fValue.InputFieldId = field.Id;
  83. inputFieldValues.Add(fValue);
  84. }
  85. }
  86. }
  87. }
  88. }