TsysRoleService.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using AutoMapper;
  2. using Ropin.Inspection.Common;
  3. using Ropin.Inspection.Common.Accessor.Interface;
  4. using Ropin.Inspection.Model;
  5. using Ropin.Inspection.Model.Entities;
  6. using Ropin.Inspection.Model.ViewModel;
  7. using Ropin.Inspection.Repository.Interface;
  8. using Ropin.Inspection.Service.SYS.Interface;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace Ropin.Inspection.Service.SYS
  15. {
  16. public class TsysRoleService : ITsysRoleService
  17. {
  18. private readonly ITsysRoleRepository _repository;
  19. private readonly IMapper _mapper;
  20. private readonly IClaimsAccessor _claims;
  21. public TsysRoleService(IClaimsAccessor claims, ITsysRoleRepository repository, IMapper mapper)
  22. {
  23. _repository = repository;
  24. _mapper = mapper;
  25. _claims = claims;
  26. }
  27. public async Task CreateOneAsync(TsysRoleViewModel viewModel)
  28. {
  29. var content = _mapper.Map<TSYS_Role>(viewModel);
  30. //content.C_LicenseCode = _claims.Linsence;
  31. content.C_Code = Guid.NewGuid();
  32. content.C_CreateBy = _claims.ApiUserId;
  33. content.D_CreateOn = DateTime.Now;
  34. content.C_Status = "1";
  35. _repository.Create(content);
  36. var result = await _repository.SaveAsync();
  37. if (!result)
  38. {
  39. throw new Exception("创建失败");
  40. }
  41. }
  42. public async Task CreateAsync(TsysRoleCreateViewModel viewModel)
  43. {
  44. var content = _mapper.Map<TSYS_Role>(viewModel);
  45. //content.C_LicenseCode = _claims.Linsence;
  46. content.C_Code = Guid.NewGuid();
  47. content.C_CreateBy = _claims.ApiUserId;
  48. content.D_CreateOn = DateTime.Now;
  49. content.C_Status = "1";
  50. _repository.Create(content);
  51. var result = await _repository.SaveAsync();
  52. if (!result)
  53. {
  54. throw new Exception("创建失败");
  55. }
  56. }
  57. public async Task DeleteAsync(Guid id)
  58. {
  59. var content = await _repository.GetByIdAsync(id);
  60. if (content == null)
  61. {
  62. throw new Exception("没有此数据");
  63. }
  64. content.C_Status = "0";
  65. content.C_LastUpdatedBy = _claims.ApiUserId;
  66. content.D_LastUpdatedOn = DateTime.Now;
  67. _repository.Update(content);
  68. var result = await _repository.SaveAsync();
  69. if (!result)
  70. {
  71. throw new Exception("删除失败");
  72. }
  73. }
  74. public async Task<IEnumerable<TsysRoleViewModel>> GetAllAsync()
  75. {
  76. IEnumerable<TSYS_Role> pagedList;
  77. //if (_claims.OrgTypeCode == "PARTY_TYPE_005")
  78. if (_claims.LicenseTypeCode == TsysLicenseType.SYSTEM)
  79. {
  80. pagedList = await _repository.GetAllAsync();
  81. }
  82. else
  83. {
  84. pagedList = await _repository.GetByConditionAsync(a => a.C_LicenseCode.Equals(_claims.Linsence));
  85. }
  86. var dtoList = _mapper.Map<IEnumerable<TsysRoleViewModel>>(pagedList);
  87. return dtoList;
  88. }
  89. public async Task<IEnumerable<TsysRoleOrgLicenseViewModel>> GetBylicenseCodeAsync(string licenseCode, string status)
  90. {
  91. IEnumerable<TsysRoleOrgLicenseViewModel> pagedList;
  92. //if (_claims.OrgTypeCode == "PARTY_TYPE_005")
  93. //if (_claims.LicenseTypeCode == TsysLicenseType.SYSTEM)
  94. //{
  95. // pagedList = await _repository.GetBylicenseCodeAsync(null);
  96. //}
  97. //else
  98. //{
  99. pagedList = await _repository.GetBylicenseCodeAsync(licenseCode, status);
  100. //}
  101. return pagedList;
  102. }
  103. public async Task<TsysRoleViewModel> GetByIdAsync(Guid id)
  104. {
  105. var content = await _repository.GetByIdAsync(id);
  106. var contentDto = _mapper.Map<TsysRoleViewModel>(content);
  107. return contentDto;
  108. }
  109. public Task<bool> IsExistAsync(Guid id)
  110. {
  111. throw new NotImplementedException();
  112. }
  113. public Task<int> UpdateOneAsync(TsysRoleViewModel viewModel, params string[] fields)
  114. {
  115. throw new NotImplementedException();
  116. }
  117. public async Task UpdateAsync(Guid id, TsysRoleUpdateViewModel updateModel)
  118. {
  119. var outlet = await _repository.GetByIdAsync(id);
  120. if (outlet == null)
  121. {
  122. throw new Exception("没有数据");
  123. }
  124. outlet.C_LastUpdatedBy = _claims.ApiUserId;
  125. outlet.D_LastUpdatedOn = DateTime.Now;
  126. _mapper.Map(updateModel, outlet, typeof(TsysRoleUpdateViewModel), typeof(TSYS_Role));
  127. _repository.Update(outlet);
  128. var result = await _repository.SaveAsync();
  129. if (!result)
  130. {
  131. throw new Exception("更新失败");
  132. }
  133. }
  134. }
  135. }