ImageLibraryService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using LinqKit;
  2. using Microsoft.AspNetCore.Authentication;
  3. using Ropin.Inspection.Common.Accessor.Interface;
  4. using Ropin.Inspection.Model;
  5. using Ropin.Inspection.Model.Entities;
  6. using Ropin.Inspection.Model.ViewModel.LGS;
  7. using Ropin.Inspection.Repository.LGS;
  8. using Ropin.Inspection.Repository.LGS.Interface;
  9. using Ropin.Inspection.Service.LGS.Interface;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Linq.Expressions;
  14. using System.Net.NetworkInformation;
  15. using System.Security.Claims;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Xml.Linq;
  19. namespace Ropin.Inspection.Service.LGS
  20. {
  21. public class ImageLibraryService : IImageLibraryService
  22. {
  23. private readonly IImageLibraryRepository _imageLibraryRepository;
  24. private readonly IClaimsAccessor _claims;
  25. public ImageLibraryService(IImageLibraryRepository imageLibraryRepository, IClaimsAccessor claims)
  26. {
  27. _imageLibraryRepository=imageLibraryRepository;
  28. _claims = claims;
  29. }
  30. public async Task CreateOneAsync(ImageLibraryModel viewModel)
  31. {
  32. TLGS_ImageLibrary entity = new TLGS_ImageLibrary()
  33. {
  34. C_ID = viewModel.C_Id,
  35. C_Name = viewModel.C_Name,
  36. C_Type = viewModel.C_Type,
  37. C_Remark = viewModel.C_Remark,
  38. C_Status = viewModel.C_Status,
  39. I_Sort = viewModel.I_Sort,
  40. C_ImagePath = viewModel.C_ImagePath,
  41. C_CreateBy = _claims.ApiUserId.ToString(),
  42. C_Creator = _claims.ApiUserName,
  43. D_CreateOn = DateTime.Now,
  44. };
  45. _imageLibraryRepository.Create(entity);
  46. var result = await _imageLibraryRepository.SaveAsync();
  47. if (!result)
  48. {
  49. throw new Exception("创建失败");
  50. }
  51. }
  52. public async Task DeleteAsync(string id)
  53. {
  54. await _imageLibraryRepository.DeleteAsync(id);
  55. }
  56. public async Task<ImageLibraryModel> GetByIdAsync(string id)
  57. {
  58. var entity=await _imageLibraryRepository.GetByIdAsync(id);
  59. var model = new ImageLibraryModel
  60. {
  61. C_Id = entity.C_ID,
  62. C_Name = entity.C_Name,
  63. C_Type = entity.C_Type,
  64. C_Remark = entity.C_Remark,
  65. C_Status = entity.C_Status,
  66. I_Sort = entity.I_Sort,
  67. C_ImagePath = entity.C_ImagePath,
  68. };
  69. return model;
  70. }
  71. public Task<bool> IsExistAsync(string id)
  72. {
  73. throw new NotImplementedException();
  74. }
  75. public async Task<List<ImageLibraryModel>> PageAsync(ImageLibraryInput input)
  76. {
  77. var predicate = PredicateBuilder.New<TLGS_ImageLibrary>(true);//查询条件,推荐后台使用这种方式灵活筛选
  78. if (!string.IsNullOrEmpty(input.C_Status))
  79. {
  80. predicate = predicate.And(i => i.C_Status==input.C_Status);
  81. }
  82. if (!string.IsNullOrEmpty(input.C_Type))
  83. {
  84. predicate = predicate.And(i => i.C_Type==input.C_Type);
  85. }
  86. var pageData = await _imageLibraryRepository.GetPageAsync(predicate, "I_Sort", input.IsPagination, input.PageIndex, input.PageSize);
  87. input.TotalCount = pageData.Totals;
  88. var result = pageData.Rows.Select(x => new ImageLibraryModel
  89. {
  90. C_Id = x.C_ID,
  91. C_Name = x.C_Name,
  92. C_Type = x.C_Type,
  93. C_Remark = x.C_Remark,
  94. C_Status = x.C_Status,
  95. I_Sort = x.I_Sort,
  96. C_ImagePath = x.C_ImagePath,
  97. }).ToList();
  98. return result;
  99. }
  100. public async Task<int> UpdateOneAsync(ImageLibraryModel viewModel, params string[] fields)
  101. {
  102. var entity= await _imageLibraryRepository.GetByIdAsync(viewModel.C_Id);
  103. entity.C_Name = viewModel.C_Name;
  104. entity.C_Type = viewModel.C_Type;
  105. entity.C_Remark = viewModel.C_Remark;
  106. entity.C_Status = viewModel.C_Status;
  107. entity.I_Sort=viewModel.I_Sort;
  108. if (!string.IsNullOrEmpty(viewModel.base64Image))
  109. {
  110. entity.C_ImagePath = viewModel.C_ImagePath;
  111. }
  112. entity.D_lastUpdatedOn = DateTime.Now;
  113. entity.C_LastUpdatedBy= _claims.ApiUserId.ToString();
  114. entity.C_Modifier= _claims.ApiUserName;
  115. _imageLibraryRepository.Update(entity);
  116. var result=await _imageLibraryRepository.SaveAsync();
  117. return result?1:0;
  118. }
  119. }
  120. }