123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using AutoMapper;
- using Newtonsoft.Json;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Common.Helper;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Model.SearchModel;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Repository.Interface;
- using Ropin.Inspection.Service.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Service
- {
- public class ReportService : IReportService
- {
- private readonly IReportRepository _repository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- public ReportService(IClaimsAccessor claims, IReportRepository repository, IMapper mapper)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- }
- public async Task<IEnumerable<ReportViewModel>> GetWithoutReportData(ReportSearchModel searchModel)
- {
- var result = await _repository.GetWithoutReportData(searchModel);
- return result;
- }
- public async Task CreateOneAsync(ReportViewModel viewModel)
- {
- var content = _mapper.Map<TISP_Report>(viewModel);
- content.D_CreateTime = DateTime.Now;
- content.C_Status = "1";
- _repository.Create(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- public async Task DeleteAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此报表");
- }
- _repository.Delete(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- public async Task<ReportViewModel> GetByIdAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此报表");
- }
- var contentDto = _mapper.Map<ReportViewModel>(content);
- return contentDto;
- }
- public async Task<object> GetReportDataByIdAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此报表");
- }
- object oRecord;
- switch (content.I_Type)
- {
- case 2:
- oRecord = JsonConvert.DeserializeObject<HiddenDangerRectificationAcceptanceFormViewModel>(content.C_Data.Trim()); // HiddenDangerRectificationAcceptanceFormViewModel firePreventionWeekRecord
- break;
- case 1:
- oRecord = JsonConvert.DeserializeObject<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data.Trim());
- break;
- case 3:
- oRecord = JsonConvert.DeserializeObject<IEnumerable<FireFightingFacilitiesWeekRecordViewModel>>(content.C_Data.Trim());
- break;
- case 4:
- oRecord = JsonConvert.DeserializeObject<IEnumerable<FireInspectionRecordViewModel>>(content.C_Data.Trim());
- break;
- default:
- oRecord = null;
- break;
- }
- //IEnumerable<FirePreventionWeekRecordViewModel> firePreventionWeekRecord = JsonConvert.DeserializeObject<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data.Trim());
- //if (string.IsNullOrEmpty(content.C_Data))
- //{
- // firePreventionWeekRecord = JsonHelper.ParseFormByJson<IEnumerable<FirePreventionWeekRecordViewModel>>(content.C_Data);
- //}
- return oRecord;
- }
- public async Task<HiddenDangerRectificationAcceptanceFormViewModel> GetHiddenDangerRectificationAcceptanceFormReportDataByIdAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此报表");
- }
- HiddenDangerRectificationAcceptanceFormViewModel firePreventionWeekRecord = JsonConvert.DeserializeObject<HiddenDangerRectificationAcceptanceFormViewModel>(content.C_Data.Trim());
- return firePreventionWeekRecord;
- }
- public Task<bool> IsExistAsync(Guid id)
- {
- throw new NotImplementedException();
- }
- public Task<int> UpdateOneAsync(ReportViewModel viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- public async Task UpdateAsync(Guid id, ReportUpdateViewModel updateModel)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此报表");
- }
- _mapper.Map(updateModel, content, typeof(ReportUpdateViewModel), typeof(TISP_Report));
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- }
- }
|