TdevDeviceTempOpsContentService.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 TdevDeviceTempOpsContentService : ITdevDeviceTempOpsContentService
  17. {
  18. private readonly ITdevDeviceTempOpsContentRepository _repository;
  19. private readonly IMapper _mapper;
  20. private readonly IClaimsAccessor _claims;
  21. public TdevDeviceTempOpsContentService(IClaimsAccessor claims, ITdevDeviceTempOpsContentRepository repository, IMapper mapper)
  22. {
  23. _repository = repository;
  24. _mapper = mapper;
  25. _claims = claims;
  26. }
  27. public async Task CreateOneAsync(TdevDeviceTempOpsContentViewModel viewModel)
  28. {
  29. var content = _mapper.Map<TDEV_DeviceTempOpsContent>(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<TdevDeviceTempOpsContentViewModel>> GetAllAsync()
  79. {
  80. var pagedList = await _repository.GetAllAsync();
  81. var contentDtoList = _mapper.Map<IEnumerable<TdevDeviceTempOpsContentViewModel>>(pagedList.Where(i => i.C_Status == "1").ToList());
  82. return contentDtoList.ToList();
  83. }
  84. public async Task<IEnumerable<TdevDeviceTempOpsContentViewModel>> GetConditionAsync(TdevDeviceTempOpsContentSearchModel searchModel)
  85. {
  86. var predicate = PredicateBuilder.New<TDEV_DeviceTempOpsContent>(true);//查询条件,推荐后台使用这种方式灵活筛选
  87. #region 添加条件查询
  88. //predicate = predicate.And(i => i.C_Status.Equals("1"));
  89. if (!string.IsNullOrEmpty(searchModel.C_Status))
  90. {
  91. predicate = predicate.And(i => i.C_Status.Equals(searchModel.C_Status));
  92. }
  93. if (!string.IsNullOrEmpty(searchModel.C_DevTempCode))
  94. {
  95. predicate = predicate.And(i => i.C_DevTempCode.Equals(searchModel.C_DevTempCode));
  96. }
  97. if (!string.IsNullOrEmpty(searchModel.C_Type))
  98. {
  99. predicate = predicate.And(i => i.C_Type.Equals(searchModel.C_Type));
  100. }
  101. if (!string.IsNullOrEmpty(searchModel.C_ID))
  102. {
  103. predicate = predicate.And(i => i.C_ID.Equals(searchModel.C_ID));
  104. }
  105. if (!string.IsNullOrEmpty(searchModel.C_Name))
  106. {
  107. predicate = predicate.And(i => i.C_Name.Contains(searchModel.C_Name));
  108. }
  109. #endregion
  110. var list = await _repository.GetPageAsync(predicate, "I_Sort,D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
  111. searchModel.TotalCount = list.Totals;
  112. var dtoList = _mapper.Map<List<TDEV_DeviceTempOpsContent>, List<TdevDeviceTempOpsContentViewModel>>(list.Rows);
  113. return dtoList;
  114. }
  115. public async Task<TdevDeviceTempOpsContentViewModel> GetByIdAsync(Guid id)
  116. {
  117. var content = await _repository.GetByIdAsync(id);
  118. var contentDto = _mapper.Map<TdevDeviceTempOpsContentViewModel>(content);
  119. return contentDto;
  120. }
  121. public async Task UpdateAsync(string code, TdevDeviceTempOpsContentUpdateModel updateModel)
  122. {
  123. var items = await _repository.GetByConditionAsync(C => C.C_ID == code);
  124. var content = items.FirstOrDefault();
  125. if (content == null)
  126. {
  127. throw new Exception("没有此数据");
  128. }
  129. content.C_LastUpdatedBy = _claims.ApiUserId;
  130. content.D_LastUpdatedOn = DateTime.Now;
  131. _mapper.Map(updateModel, content, typeof(TdevDeviceTempOpsContentUpdateModel), typeof(TDEV_DeviceTempOpsContent));
  132. _repository.Update(content);
  133. var result = await _repository.SaveAsync();
  134. if (!result)
  135. {
  136. throw new Exception("更新失败");
  137. }
  138. }
  139. public Task<int> UpdateOneAsync(TdevDeviceTempOpsContentViewModel viewModel, params string[] fields)
  140. {
  141. throw new NotImplementedException();
  142. }
  143. public Task<bool> IsExistAsync(Guid id)
  144. {
  145. throw new NotImplementedException();
  146. }
  147. public Task<IEnumerable<TdevDeviceTempOpsContentViewModel>> GetByConditionAsync(Expression<Func<TdevDeviceTempOpsContentViewModel, bool>> expression)
  148. {
  149. throw new NotImplementedException();
  150. }
  151. public Task UpdateAsync(string code, TpntAreaUpdateModel updateModel)
  152. {
  153. throw new NotImplementedException();
  154. }
  155. public Task<IEnumerable<TdevDeviceTempOpsContentViewModel>> GetConditionAsync(TpntAreaSearchModel searchModel)
  156. {
  157. throw new NotImplementedException();
  158. }
  159. }
  160. }