TdevDevStoreDocService.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using AutoMapper;
  2. using LinqKit;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.NodeServices;
  5. using Microsoft.EntityFrameworkCore;
  6. using Newtonsoft.Json;
  7. using Ropin.Core.Common;
  8. using Ropin.Inspection.Common;
  9. using Ropin.Inspection.Common.Accessor.Interface;
  10. using Ropin.Inspection.Common.Helper;
  11. using Ropin.Inspection.Model;
  12. using Ropin.Inspection.Model.Entities;
  13. using Ropin.Inspection.Repository;
  14. using Ropin.Inspection.Repository.Interface;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.ComponentModel;
  18. using System.ComponentModel.DataAnnotations;
  19. using System.Drawing;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Linq.Expressions;
  23. using System.Reflection;
  24. using System.Text;
  25. using System.Threading.Tasks;
  26. using System.Xml.Linq;
  27. using static System.Net.Mime.MediaTypeNames;
  28. namespace Ropin.Inspection.Service
  29. {
  30. public class TdevDevStoreDocService : ITdevDevStoreDocService
  31. {
  32. private readonly ITdevDevStoreDocRepository _repository;
  33. private readonly IMapper _mapper;
  34. private readonly IClaimsAccessor _claims;
  35. private readonly InspectionDbContext _sqlDBContext;
  36. private readonly ITmtnDevOpsRecordRepository _tmtnDevOpsRecordRepository;
  37. public TdevDevStoreDocService(ITmtnDevOpsRecordRepository tmtnDevOpsRecordRepository,IClaimsAccessor claims, InspectionDbContext sqlDBContext, ITdevDevStoreDocRepository repository, IMapper mapper)
  38. {
  39. _repository = repository;
  40. _mapper = mapper;
  41. _claims = claims;
  42. _sqlDBContext = sqlDBContext;
  43. _tmtnDevOpsRecordRepository = tmtnDevOpsRecordRepository;
  44. }
  45. public async Task CreateOneAsync(TdevDevStoreDocViewModel viewModel)
  46. {
  47. var id = Guid.NewGuid().ToString();
  48. //var path = QRCoderHelper.RenderQrCode(id, "M", _claims.Linsence);
  49. var content = _mapper.Map<TDEV_DevStoreDoc>(viewModel);
  50. content.C_ID = id;
  51. content.C_CreateBy = _claims.ApiUserId;
  52. content.D_CreateOn = DateTime.Now;
  53. content.C_Status = "1";
  54. //content.C_Url = path;
  55. _repository.Create(content);
  56. var result = await _repository.SaveAsync();
  57. if (!result)
  58. {
  59. throw new Exception("创建失败");
  60. }
  61. }
  62. public async Task DeleteAsync(string id)
  63. {
  64. var content = await _repository.GetByIdAsync(id);
  65. if (content == null)
  66. {
  67. throw new Exception("数据库中没有此数据");
  68. }
  69. content.C_LastUpdatedBy = _claims.ApiUserId;
  70. content.D_LastUpdatedOn = DateTime.Now;
  71. content.C_Status = "0";
  72. _repository.Update(content);
  73. var result = await _repository.SaveAsync();
  74. if (!result)
  75. {
  76. throw new Exception("删除失败");
  77. }
  78. }
  79. public async Task UpdateAsync(string code, TdevDevStoreDocViewModel updateModel)
  80. {
  81. var items = await _repository.GetByConditionAsync(C => C.C_ID == code);
  82. var content = items.FirstOrDefault();
  83. if (content == null)
  84. {
  85. throw new Exception("没有此数据");
  86. }
  87. content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId : Guid.Parse("6e864cbc-5252-11ec-8681-fa163e02b3e4");
  88. content.D_LastUpdatedOn = DateTime.Now;
  89. _mapper.Map(updateModel, content, typeof(TdevDevStoreDocViewModel), typeof(TDEV_DevStoreDoc));
  90. _repository.Update(content);
  91. var result = await _repository.SaveAsync();
  92. if (!result)
  93. {
  94. throw new Exception("更新失败");
  95. }
  96. }
  97. public async Task<IEnumerable<TdevDevStoreDocViewModel>> GetConditionAsync(TdevDevStoreDocSearchModel searchModel)
  98. {
  99. var predicate = PredicateBuilder.New<TDEV_DevStoreDoc>(true);//查询条件,推荐后台使用这种方式灵活筛选
  100. #region 添加条件查询
  101. if (!string.IsNullOrEmpty(searchModel.C_Status))
  102. {
  103. predicate = predicate.And(i => i.C_Status.Equals(searchModel.C_Status));
  104. }
  105. else
  106. {
  107. predicate = predicate.And(i => !i.C_Status.Equals("0"));
  108. }
  109. if (!string.IsNullOrEmpty(searchModel.C_DevStoreCode))
  110. {
  111. predicate = predicate.And(i => i.C_DevStoreCode.Equals(searchModel.C_DevStoreCode));
  112. }
  113. if (!string.IsNullOrEmpty(searchModel.C_ID))
  114. {
  115. predicate = predicate.And(i => i.C_ID.Equals(searchModel.C_ID));
  116. }
  117. if (!string.IsNullOrEmpty(searchModel.C_Name))
  118. {
  119. predicate = predicate.And(i => i.C_Name.Contains(searchModel.C_Name));
  120. }
  121. if (searchModel.IdList!=null&&searchModel.IdList.Count()>0)
  122. {
  123. predicate = predicate.And(i => searchModel.IdList.Contains(i.C_ID));
  124. }
  125. #endregion
  126. var list = await _repository.GetPageAsync(predicate, "C_Name,-D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
  127. searchModel.TotalCount = list.Totals;
  128. var dtoList = _mapper.Map<List<TDEV_DevStoreDoc>, List<TdevDevStoreDocViewModel>>(list.Rows);
  129. return dtoList;
  130. }
  131. /// <summary>
  132. /// 获取设备文档(包括关联的模板文档)
  133. /// </summary>
  134. /// <param name="searchModel"></param>
  135. /// <returns></returns>
  136. public Task<IEnumerable<TdevDevStoreDocViewModel>> GetDevFile(TdevDevStoreDocSearchModel searchModel)
  137. {
  138. return _repository.GetDevFile(searchModel);
  139. }
  140. public Task<TdevDevStoreDocViewModel> GetByIdAsync(string id)
  141. {
  142. throw new NotImplementedException();
  143. }
  144. public Task<bool> IsExistAsync(string id)
  145. {
  146. throw new NotImplementedException();
  147. }
  148. public Task<int> UpdateOneAsync(TdevDevStoreDocViewModel viewModel, params string[] fields)
  149. {
  150. throw new NotImplementedException();
  151. }
  152. }
  153. }