ReportService.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. ReportSearchModel searchModel = new ReportSearchModel();
  63. searchModel.Id=id.ToString();
  64. var result = await _repository.GetWithoutReportData(searchModel);
  65. //var content = await _repository.GetByIdAsync(id);
  66. //if (content == null)
  67. //{
  68. // throw new Exception("没有此报表");
  69. //}
  70. //var contentDto = _mapper.Map<ReportViewModel>(content);
  71. var content = result.FirstOrDefault();
  72. return content;
  73. }
  74. public async Task<object> GetReportDataByIdAsync(Guid id)
  75. {
  76. var content = await _repository.GetByIdAsync(id);
  77. if (content == null)
  78. {
  79. throw new Exception("没有此报表");
  80. }
  81. object oRecord;
  82. switch (content.I_Type)
  83. {
  84. case 2:
  85. oRecord = JsonConvert.DeserializeObject<HiddenDangerRectificationAcceptanceFormViewModel>(content.C_Data.Trim()); // HiddenDangerRectificationAcceptanceFormViewModel firePreventionWeekRecord
  86. break;
  87. case 1:
  88. oRecord = JsonConvert.DeserializeObject<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data.Trim());
  89. break;
  90. case 3:
  91. oRecord = JsonConvert.DeserializeObject<IEnumerable<FireFightingFacilitiesWeekRecordViewModel>>(content.C_Data.Trim());
  92. break;
  93. case 4:
  94. oRecord = JsonConvert.DeserializeObject<IEnumerable<FireInspectionRecordViewModel>>(content.C_Data.Trim());
  95. break;
  96. case 5:
  97. oRecord = JsonConvert.DeserializeObject<IEnumerable<InspectionWorkOrderModel>>(content.C_Data.Trim());
  98. break;
  99. default:
  100. oRecord = null;
  101. break;
  102. }
  103. //IEnumerable<FirePreventionWeekRecordViewModel> firePreventionWeekRecord = JsonConvert.DeserializeObject<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data.Trim());
  104. //if (string.IsNullOrEmpty(content.C_Data))
  105. //{
  106. // firePreventionWeekRecord = JsonHelper.ParseFormByJson<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data);
  107. //}
  108. return oRecord;
  109. }
  110. public async Task<HiddenDangerRectificationAcceptanceFormViewModel> GetHiddenDangerRectificationAcceptanceFormReportDataByIdAsync(Guid id)
  111. {
  112. var content = await _repository.GetByIdAsync(id);
  113. if (content == null)
  114. {
  115. throw new Exception("没有此报表");
  116. }
  117. HiddenDangerRectificationAcceptanceFormViewModel firePreventionWeekRecord = JsonConvert.DeserializeObject<HiddenDangerRectificationAcceptanceFormViewModel>(content.C_Data.Trim());
  118. return firePreventionWeekRecord;
  119. }
  120. public Task<bool> IsExistAsync(Guid id)
  121. {
  122. throw new NotImplementedException();
  123. }
  124. public Task<int> UpdateOneAsync(ReportViewModel viewModel, params string[] fields)
  125. {
  126. throw new NotImplementedException();
  127. }
  128. public async Task UpdateAsync(Guid id, ReportUpdateViewModel updateModel)
  129. {
  130. var content = await _repository.GetByIdAsync(id);
  131. if (content == null)
  132. {
  133. throw new Exception("没有此报表");
  134. }
  135. _mapper.Map(updateModel, content, typeof(ReportUpdateViewModel), typeof(TISP_Report));
  136. _repository.Update(content);
  137. var result = await _repository.SaveAsync();
  138. if (!result)
  139. {
  140. throw new Exception("更新失败");
  141. }
  142. }
  143. }
  144. }