TprdLogService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using AutoMapper;
  2. using LinqKit;
  3. using Ropin.Inspection.Common.Accessor.Interface;
  4. using Ropin.Inspection.Model;
  5. using Ropin.Inspection.Model.Entities;
  6. using Ropin.Inspection.Repository;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Linq.Expressions;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace Ropin.Inspection.Service
  14. {
  15. public class TprdLogService : ITprdLogService
  16. {
  17. private readonly ITprdLogRepository _repository;
  18. private readonly IMapper _mapper;
  19. private readonly IClaimsAccessor _claims;
  20. public TprdLogService(IClaimsAccessor claims, ITprdLogRepository repository, IMapper mapper)
  21. {
  22. _repository = repository;
  23. _mapper = mapper;
  24. _claims = claims;
  25. }
  26. public async Task CreateOneAsync(TprdLogViewModel viewModel)
  27. {
  28. var content = _mapper.Map<TPRD_Log>(viewModel);
  29. content.C_Code = Guid.NewGuid();
  30. content.C_CreateBy = _claims.ApiUserId;
  31. content.D_CreateOn = DateTime.Now;
  32. // content.C_Status = "1";
  33. _repository.Create(content);
  34. var result = await _repository.SaveAsync();
  35. if (!result)
  36. {
  37. throw new Exception("创建失败");
  38. }
  39. }
  40. public async Task DeleteAsync(Guid id)
  41. {
  42. var content = await _repository.GetByIdAsync(id);
  43. if (content == null)
  44. {
  45. throw new Exception("数据库中没有此数据");
  46. }
  47. //_repository.Delete(content);
  48. //var result = await _repository.SaveAsync();
  49. //content.C_LastUpdatedBy = _claims.ApiUserId;
  50. //content.D_LastUpdatedOn = DateTime.Now;
  51. //content.C_Status = "0";
  52. _repository.Update(content);
  53. var result = await _repository.SaveAsync();
  54. if (!result)
  55. {
  56. throw new Exception("删除失败");
  57. }
  58. }
  59. public async Task<IEnumerable<TprdLogViewModel>> GetAllAsync()
  60. {
  61. var pagedList = await _repository.GetAllAsync();
  62. var contentDtoList = _mapper.Map<IEnumerable<TprdLogViewModel>>(pagedList.ToList());
  63. return contentDtoList.ToList();
  64. }
  65. public async Task<IEnumerable<TprdLogViewModel>> GetConditionAsync(TprdLogSearchModel searchModel)
  66. {
  67. var predicate = PredicateBuilder.New<TPRD_Log>(true);//查询条件,推荐后台使用这种方式灵活筛选
  68. #region 添加条件查询
  69. //predicate = predicate.And(i => i.C_Status.Equals("1"));
  70. if (!string.IsNullOrEmpty(searchModel.C_StoreCode))
  71. {
  72. predicate = predicate.And(i => i.C_StoreCode.Contains(searchModel.C_StoreCode));
  73. }
  74. #endregion
  75. var list = await _repository.GetPageAsync(predicate, "-D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
  76. searchModel.TotalCount = list.Totals;
  77. var dtoList = _mapper.Map<List<TPRD_Log>, List<TprdLogViewModel>>(list.Rows);
  78. return dtoList;
  79. }
  80. public async Task<TprdLogViewModel> GetByIdAsync(Guid id)
  81. {
  82. var content = await _repository.GetByIdAsync(id);
  83. var contentDto = _mapper.Map<TprdLogViewModel>(content);
  84. return contentDto;
  85. }
  86. public async Task UpdateAsync(Guid id, TprdLogUpdateModel updateModel)
  87. {
  88. var content = await _repository.GetByIdAsync(id);
  89. if (content == null)
  90. {
  91. throw new Exception("没有此数据");
  92. }
  93. _mapper.Map(updateModel, content, typeof(TprdLogUpdateModel), typeof(TPRD_Log));
  94. _repository.Update(content);
  95. var result = await _repository.SaveAsync();
  96. if (!result)
  97. {
  98. throw new Exception("更新失败");
  99. }
  100. }
  101. public Task<int> UpdateOneAsync(TprdLogViewModel viewModel, params string[] fields)
  102. {
  103. throw new NotImplementedException();
  104. }
  105. public Task<bool> IsExistAsync(Guid id)
  106. {
  107. throw new NotImplementedException();
  108. }
  109. public Task<IEnumerable<TprdLogViewModel>> GetByConditionAsync(Expression<Func<TprdLogViewModel, bool>> expression)
  110. {
  111. throw new NotImplementedException();
  112. }
  113. }
  114. }