TdevDevStoreLogService.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 Ropin.Inspection.Repository.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 TdevDevStoreLogService : ITdevDevStoreLogService
  17. {
  18. private readonly ITdevDevStoreLogRepository _repository;
  19. private readonly IMapper _mapper;
  20. private readonly IClaimsAccessor _claims;
  21. public TdevDevStoreLogService(IClaimsAccessor claims, ITdevDevStoreLogRepository repository, IMapper mapper)
  22. {
  23. _repository = repository;
  24. _mapper = mapper;
  25. _claims = claims;
  26. }
  27. public async Task CreateOneAsync(TdevDevStoreLogViewModel viewModel)
  28. {
  29. var content = _mapper.Map<TDEV_DevStoreLog>(viewModel);
  30. content.C_ID = Guid.NewGuid().ToString();
  31. content.C_CreateBy = _claims.ApiUserId;
  32. content.D_CreateOn = DateTime.Now;
  33. //content.C_Status = "1";
  34. _repository.Create(content);
  35. var result = await _repository.SaveAsync();
  36. if (!result)
  37. {
  38. throw new Exception("创建失败");
  39. }
  40. }
  41. public async Task DeleteAsync(Guid id)
  42. {
  43. var content = await _repository.GetByIdAsync(id);
  44. if (content == null)
  45. {
  46. throw new Exception("数据库中没有此数据");
  47. }
  48. //_repository.Delete(content);
  49. //var result = await _repository.SaveAsync();
  50. //content.C_LastUpdatedBy = _claims.ApiUserId;
  51. //content.D_LastUpdatedOn = DateTime.Now;
  52. //content.C_Status = "0";
  53. _repository.Update(content);
  54. var result = await _repository.SaveAsync();
  55. if (!result)
  56. {
  57. throw new Exception("删除失败");
  58. }
  59. }
  60. public async Task DeleteAsync(string code)
  61. {
  62. var items = await _repository.GetByConditionAsync(C => C.C_ID == code);
  63. var content = items.FirstOrDefault();
  64. if (content == null)
  65. {
  66. throw new Exception("没有此数据");
  67. }
  68. //content.C_LastUpdatedBy = _claims.ApiUserId;
  69. //content.D_LastUpdatedOn = DateTime.Now;
  70. //content.C_Status = "0";
  71. _repository.Update(content);
  72. var result = await _repository.SaveAsync();
  73. if (!result)
  74. {
  75. throw new Exception("删除失败");
  76. }
  77. }
  78. public async Task<IEnumerable<TdevDevStoreLogViewModel>> GetAllAsync()
  79. {
  80. var pagedList = await _repository.GetAllAsync();
  81. var contentDtoList = _mapper.Map<IEnumerable<TdevDevStoreLogViewModel>>(pagedList.ToList());
  82. return contentDtoList.ToList();
  83. }
  84. public async Task<IEnumerable<TdevDevStoreLogViewModel>> GetConditionAsync(TdevDevStoreLogSearchModel searchModel)
  85. {
  86. var predicate = PredicateBuilder.New<TDEV_DevStoreLog>(true);//查询条件,推荐后台使用这种方式灵活筛选
  87. #region 添加条件查询
  88. //predicate = predicate.And(i => i.C_Status.Equals("1"));
  89. if (!string.IsNullOrEmpty(searchModel.C_LogMsg))
  90. {
  91. predicate = predicate.And(i => i.C_LogMsg.Contains(searchModel.C_LogMsg));
  92. }
  93. if (!string.IsNullOrEmpty(searchModel.C_DeviceCode))
  94. {
  95. predicate = predicate.And(i => i.C_DeviceCode.Equals(searchModel.C_DeviceCode));
  96. }
  97. if (!string.IsNullOrEmpty(searchModel.C_ID))
  98. {
  99. predicate = predicate.And(i => i.C_ID.Equals(searchModel.C_ID));
  100. }
  101. if (!string.IsNullOrEmpty(searchModel.C_Type))
  102. {
  103. predicate = predicate.And(i => i.C_Type.Contains(searchModel.C_Type));
  104. }
  105. #endregion
  106. var list = await _repository.GetPageAsync(predicate, "C_Name,-D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
  107. searchModel.TotalCount = list.Totals;
  108. var dtoList = _mapper.Map<List<TDEV_DevStoreLog>, List<TdevDevStoreLogViewModel>>(list.Rows);
  109. return dtoList;
  110. }
  111. public async Task<TdevDevStoreLogViewModel> GetByIdAsync(Guid id)
  112. {
  113. var content = await _repository.GetByIdAsync(id);
  114. var contentDto = _mapper.Map<TdevDevStoreLogViewModel>(content);
  115. return contentDto;
  116. }
  117. public async Task UpdateAsync(string code, TdevDevStoreLogUpdateModel updateModel)
  118. {
  119. var items = await _repository.GetByConditionAsync(C => C.C_ID == code);
  120. var content = items.FirstOrDefault();
  121. if (content == null)
  122. {
  123. throw new Exception("没有此数据");
  124. }
  125. //content.C_LastUpdatedBy = _claims.ApiUserId;
  126. //content.D_LastUpdatedOn = DateTime.Now;
  127. _mapper.Map(updateModel, content, typeof(TdevDevStoreLogUpdateModel), typeof(TDEV_DevStoreLog));
  128. _repository.Update(content);
  129. var result = await _repository.SaveAsync();
  130. if (!result)
  131. {
  132. throw new Exception("更新失败");
  133. }
  134. }
  135. public Task<int> UpdateOneAsync(TdevDevStoreLogViewModel viewModel, params string[] fields)
  136. {
  137. throw new NotImplementedException();
  138. }
  139. public Task<bool> IsExistAsync(Guid id)
  140. {
  141. throw new NotImplementedException();
  142. }
  143. public Task<IEnumerable<TdevDevStoreLogViewModel>> GetByConditionAsync(Expression<Func<TdevDevStoreLogViewModel, bool>> expression)
  144. {
  145. throw new NotImplementedException();
  146. }
  147. public Task UpdateAsync(string code, TpntAreaUpdateModel updateModel)
  148. {
  149. throw new NotImplementedException();
  150. }
  151. public Task<IEnumerable<TdevDevStoreLogViewModel>> GetConditionAsync(TpntAreaSearchModel searchModel)
  152. {
  153. throw new NotImplementedException();
  154. }
  155. }
  156. }