TdevDevOpeAccountService.cs 7.5 KB

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