dev_HandService.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Repository.DEV.Interface;
  5. using Ropin.Inspection.Repository;
  6. using Ropin.Inspection.Service.DEV.Interface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Ropin.Inspection.Model.ViewModel.DEV;
  13. using Ropin.Core.Common;
  14. using LinqKit;
  15. using Ropin.Inspection.Model;
  16. namespace Ropin.Inspection.Service.DEV
  17. {
  18. public class dev_HandService: IDev_HandService
  19. {
  20. private readonly Idev_HandRepository _repository;
  21. private readonly IMapper _mapper;
  22. private readonly IClaimsAccessor _claims;
  23. private readonly InspectionDbContext _sqlDBContext;
  24. public dev_HandService(IClaimsAccessor claims, InspectionDbContext sqlDBContext, Idev_HandRepository repository, IMapper mapper)
  25. {
  26. _repository = repository;
  27. _mapper = mapper;
  28. _claims = claims;
  29. _sqlDBContext = sqlDBContext;
  30. }
  31. public async Task CreateOneAsync(dev_HandModel viewModel)
  32. {
  33. var id = Guid.NewGuid();
  34. var content = _mapper.Map<TDEV_Hand>(viewModel);
  35. content.C_ID = id;
  36. var path = QRCoderHelper.RenderQrCode(id.ToString(), "M", _claims.Linsence);
  37. //if (string.IsNullOrEmpty(content.C_MachineCode))
  38. //{
  39. // content.C_MachineCode = "SC-" + id + "-" +DateTime.Now.ToString("yyyyMMdd");
  40. //}
  41. content.C_CreateBy = _claims.ApiUserId;
  42. content.D_CreateOn = DateTime.Now;
  43. content.C_QRCode = path;
  44. content.C_Status = "1";
  45. _repository.Create(content);
  46. var result = await _repository.SaveAsync();
  47. if (!result)
  48. {
  49. throw new Exception("创建失败");
  50. }
  51. }
  52. public async Task DeleteAsync(Guid id)
  53. {
  54. var content = await _repository.GetByIdAsync(id);
  55. if (content == null)
  56. {
  57. throw new Exception("数据库中没有此数据");
  58. }
  59. content.C_LastUpdatedBy = _claims.ApiUserId;
  60. content.D_LastUpdatedOn = DateTime.Now;
  61. content.C_Status = "0";
  62. _repository.Update(content);
  63. var result = await _repository.SaveAsync();
  64. if (!result)
  65. {
  66. throw new Exception("删除失败");
  67. }
  68. }
  69. public async Task UpdateAsync(Guid code, dev_HandModel updateModel)
  70. {
  71. var items = await _repository.GetByConditionAsync(C => C.C_ID == code);
  72. TDEV_Hand content = items.FirstOrDefault();
  73. if (content == null)
  74. {
  75. throw new Exception("没有此数据");
  76. }
  77. content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId : Guid.Parse("6e864cbc-5252-11ec-8681-fa163e02b3e4");
  78. content.D_LastUpdatedOn = DateTime.Now;
  79. _mapper.Map(updateModel, content, typeof(dev_HandModel), typeof(TDEV_Hand));
  80. _repository.Update(content);
  81. var result = await _repository.SaveAsync();
  82. if (!result)
  83. {
  84. throw new Exception("更新失败");
  85. }
  86. }
  87. public async Task<IEnumerable<devHandViewModel>> GetConditionAsync(TdevHandSearchModel searchModel)
  88. {
  89. var dtoList = await _repository.GetConditionAsync(searchModel);
  90. return dtoList;
  91. }
  92. public async Task<devHandViewModel> GetConditionByIdAsync(Guid code)
  93. {
  94. TdevHandSearchModel searchModel = new TdevHandSearchModel();
  95. searchModel.C_ID = code;
  96. searchModel.IsPagination = false;
  97. var items = await _repository.GetConditionAsync(searchModel);
  98. var content = items.FirstOrDefault();
  99. return content;
  100. }
  101. public Task<dev_HandModel> GetByIdAsync(Guid id)
  102. {
  103. throw new NotImplementedException();
  104. }
  105. public Task<bool> IsExistAsync(Guid id)
  106. {
  107. throw new NotImplementedException();
  108. }
  109. public Task<int> UpdateOneAsync(dev_HandModel viewModel, params string[] fields)
  110. {
  111. throw new NotImplementedException();
  112. }
  113. }
  114. }