ReportService.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using AutoMapper;
  2. using Newtonsoft.Json;
  3. using Ropin.Inspection.Common.Accessor.Interface;
  4. using Ropin.Inspection.Common.Helper;
  5. using Ropin.Inspection.Model;
  6. using Ropin.Inspection.Model.Entities;
  7. using Ropin.Inspection.Model.SearchModel;
  8. using Ropin.Inspection.Model.ViewModel;
  9. using Ropin.Inspection.Repository.Interface;
  10. using Ropin.Inspection.Service.Interface;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace Ropin.Inspection.Service
  17. {
  18. public class ReportService : IReportService
  19. {
  20. private readonly IReportRepository _repository;
  21. private readonly IMapper _mapper;
  22. private readonly IClaimsAccessor _claims;
  23. public ReportService(IClaimsAccessor claims, IReportRepository repository, IMapper mapper)
  24. {
  25. _repository = repository;
  26. _mapper = mapper;
  27. _claims = claims;
  28. }
  29. public async Task<IEnumerable<ReportViewModel>> GetWithoutReportData(ReportSearchModel searchModel)
  30. {
  31. var result = await _repository.GetWithoutReportData(searchModel);
  32. return result;
  33. }
  34. public async Task CreateOneAsync(ReportViewModel viewModel)
  35. {
  36. var content = _mapper.Map<TISP_Report>(viewModel);
  37. content.D_CreateTime = DateTime.Now;
  38. content.C_Status = "1";
  39. _repository.Create(content);
  40. var result = await _repository.SaveAsync();
  41. if (!result)
  42. {
  43. throw new Exception("创建失败");
  44. }
  45. }
  46. public async Task DeleteAsync(Guid id)
  47. {
  48. var content = await _repository.GetByIdAsync(id);
  49. if (content == null)
  50. {
  51. throw new Exception("没有此报表");
  52. }
  53. _repository.Delete(content);
  54. var result = await _repository.SaveAsync();
  55. if (!result)
  56. {
  57. throw new Exception("删除失败");
  58. }
  59. }
  60. public async Task<ReportViewModel> GetByIdAsync(Guid id)
  61. {
  62. var content = await _repository.GetByIdAsync(id);
  63. if (content == null)
  64. {
  65. throw new Exception("没有此报表");
  66. }
  67. var contentDto = _mapper.Map<ReportViewModel>(content);
  68. return contentDto;
  69. }
  70. public async Task<object> GetReportDataByIdAsync(Guid id)
  71. {
  72. var content = await _repository.GetByIdAsync(id);
  73. if (content == null)
  74. {
  75. throw new Exception("没有此报表");
  76. }
  77. object oRecord;
  78. switch (content.I_Type)
  79. {
  80. case 2:
  81. oRecord = JsonConvert.DeserializeObject<HiddenDangerRectificationAcceptanceFormViewModel>(content.C_Data.Trim()); // HiddenDangerRectificationAcceptanceFormViewModel firePreventionWeekRecord
  82. break;
  83. case 1:
  84. oRecord = JsonConvert.DeserializeObject<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data.Trim());
  85. break;
  86. case 3:
  87. oRecord = JsonConvert.DeserializeObject<IEnumerable<FireFightingFacilitiesWeekRecordViewModel>>(content.C_Data.Trim());
  88. break;
  89. case 4:
  90. oRecord = JsonConvert.DeserializeObject<IEnumerable<FireInspectionRecordViewModel>>(content.C_Data.Trim());
  91. break;
  92. default:
  93. oRecord = null;
  94. break;
  95. }
  96. //IEnumerable<FirePreventionWeekRecordViewModel> firePreventionWeekRecord = JsonConvert.DeserializeObject<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data.Trim());
  97. //if (string.IsNullOrEmpty(content.C_Data))
  98. //{
  99. // firePreventionWeekRecord = JsonHelper.ParseFormByJson<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data);
  100. //}
  101. return oRecord;
  102. }
  103. public async Task<HiddenDangerRectificationAcceptanceFormViewModel> GetHiddenDangerRectificationAcceptanceFormReportDataByIdAsync(Guid id)
  104. {
  105. var content = await _repository.GetByIdAsync(id);
  106. if (content == null)
  107. {
  108. throw new Exception("没有此报表");
  109. }
  110. HiddenDangerRectificationAcceptanceFormViewModel firePreventionWeekRecord = JsonConvert.DeserializeObject<HiddenDangerRectificationAcceptanceFormViewModel>(content.C_Data.Trim());
  111. return firePreventionWeekRecord;
  112. }
  113. public Task<bool> IsExistAsync(Guid id)
  114. {
  115. throw new NotImplementedException();
  116. }
  117. public Task<int> UpdateOneAsync(ReportViewModel viewModel, params string[] fields)
  118. {
  119. throw new NotImplementedException();
  120. }
  121. public async Task UpdateAsync(Guid id, ReportUpdateViewModel updateModel)
  122. {
  123. var content = await _repository.GetByIdAsync(id);
  124. if (content == null)
  125. {
  126. throw new Exception("没有此报表");
  127. }
  128. _mapper.Map(updateModel, content, typeof(ReportUpdateViewModel), typeof(TISP_Report));
  129. _repository.Update(content);
  130. var result = await _repository.SaveAsync();
  131. if (!result)
  132. {
  133. throw new Exception("更新失败");
  134. }
  135. }
  136. }
  137. }