TispSpotRegionService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Model.SearchModel;
  5. using Ropin.Inspection.Model.ViewModel;
  6. using Ropin.Inspection.Repository.Interface;
  7. using Ropin.Inspection.Service.Interface;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Linq.Expressions;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace Ropin.Inspection.Service
  15. {
  16. public class TispSpotRegionService : ITispSpotRegionService
  17. {
  18. private readonly ITispSpotRegionRepository _repository;
  19. private readonly IMapper _mapper;
  20. private readonly IClaimsAccessor _claims;
  21. public TispSpotRegionService(IClaimsAccessor claims, ITispSpotRegionRepository repository, IMapper mapper)
  22. {
  23. _repository = repository;
  24. _mapper = mapper;
  25. _claims = claims;
  26. }
  27. public Task CreateOneAsync(TispSpotsRegionViewModel viewModel)
  28. {
  29. throw new NotImplementedException();
  30. }
  31. public async Task CreateSpotsRegionsAsync(TispSpotRegionCreateViewModel viewModel)
  32. {
  33. foreach (Guid RegionId in viewModel.RegionIdList)
  34. {
  35. await _repository.DeleteByRegionIdAsync(RegionId);
  36. foreach (Guid spotId in viewModel.SpotIdList)
  37. {
  38. TISP_SpotRegion spotRegion = new TISP_SpotRegion()
  39. {
  40. C_SpotCode = spotId,
  41. C_RegionCode = RegionId,
  42. C_CreateBy = _claims.ApiUserId,
  43. D_CreateOn = DateTime.Now,
  44. C_LastUpdatedBy = _claims.ApiUserId,
  45. D_LastUpdatedOn = DateTime.Now,
  46. C_Status = '1',
  47. };
  48. _repository.Create(spotRegion);
  49. }
  50. }
  51. var result = await _repository.SaveAsync();
  52. if (!result)
  53. {
  54. throw new Exception("创建失败");
  55. }
  56. }
  57. public async Task DeleteAsync(Guid id)
  58. {
  59. var content = await _repository.GetByIdAsync(id);
  60. if (content == null)
  61. {
  62. throw new Exception("没有此巡检路径");
  63. }
  64. _repository.Delete(content);
  65. var result = await _repository.SaveAsync();
  66. if (!result)
  67. {
  68. throw new Exception("删除失败");
  69. }
  70. }
  71. public Task<IEnumerable<TispSpotsRegionViewModel>> GetByConditionAsync(Expression<Func<TispSpotsRegionViewModel, bool>> expression)
  72. {
  73. throw new NotImplementedException();
  74. }
  75. public Task<TispSpotsRegionViewModel> GetByIdAsync(Guid id)
  76. {
  77. throw new NotImplementedException();
  78. }
  79. public async Task<IEnumerable<TispSpotsRegionViewModel>> GetSpotRegionsAsyncByPage(TispSpotRegionSearchModel searchViewModel)
  80. {
  81. var pagedList = await _repository.GetSpotRegionsAsyncByPage(searchViewModel);
  82. searchViewModel.TotalCount = pagedList == null ? 0 : pagedList.Totals;
  83. return pagedList?.Rows;
  84. }
  85. public async Task<IEnumerable<TispSpotsRegionViewModel>> GetSpotsRegionAsyncByPage(TispSpotRegionSearchModel searchViewModel)
  86. {
  87. var pagedList = await _repository.GetSpotsRegionAsyncByPage(searchViewModel);
  88. searchViewModel.TotalCount = pagedList == null ? 0 : pagedList.Totals;
  89. return pagedList?.Rows;
  90. }
  91. public Task<bool> IsExistAsync(Guid id)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. public Task UpdateAsync(Guid id, TispContentUpdateViewModel updateModel)
  96. {
  97. throw new NotImplementedException();
  98. }
  99. public Task<int> UpdateOneAsync(TispSpotsRegionViewModel viewModel, params string[] fields)
  100. {
  101. throw new NotImplementedException();
  102. }
  103. }
  104. }