基础服务api
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

138 lines
6.4 KiB

  1. using BPA.SAAS.Manage.Application.Device.Dtos.Device;
  2. using BPA.SAAS.Manage.Application.Device.Interface;
  3. using BPA.SAAS.Manage.Core.Base;
  4. using BPA.SAAS.Manage.Core.Device;
  5. using BPA.SAAS.Manage.Core.Product;
  6. using LogicExtensions;
  7. using Microsoft.AspNetCore.Routing.Template;
  8. using NPOI.POIFS.Storage;
  9. using SqlSugar;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace BPA.SAAS.Manage.Application.Device.Services
  16. {
  17. public class TechnologyService : ITechnologyService, ITransient
  18. {
  19. private readonly ISqlSugarClient _db;
  20. public TechnologyService(ISqlSugarClient db)
  21. {
  22. _db=db;
  23. }
  24. /// <summary>
  25. /// 分页查询
  26. /// </summary>
  27. /// <param name="inputDto"></param>
  28. /// <returns></returns>
  29. public async Task<PageUtil> GetTechnologyExportRecodePage(TechnologyQueryInputDto inputDto)
  30. {
  31. var total = new RefAsync<int>();
  32. var data = await _db.Queryable<BPA_TechnologyExportRecode,BPA_ProductVesion, BPA_Product>((a, b,c) => new JoinQueryInfos(
  33. JoinType.Left, a.DeviceVersionId == b.Id,
  34. JoinType.Left, a.ProductId == c.Id
  35. ))
  36. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Vesion), (a, b, c) => b.Vesion == inputDto.Vesion)
  37. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.ProductName), (a, b, c) => inputDto.ProductName.Contains(c.Name))
  38. .Select((a, b,c) => new ProductVesionView
  39. {
  40. Id =a.Id,
  41. Vesion = b.Vesion,
  42. ProductName = c.Name,
  43. CreateAt = a.CreateAt,
  44. DeviceVersionId = b.Id,
  45. TemplatePath=a.TemplatePath
  46. })
  47. .OrderBy(a=>a.CreateAt, OrderByType.Desc)
  48. .Mapper(x =>
  49. {
  50. //var TechnologyInfo1 = _db.Queryable<BPA_Technology>().Where(p => p.DeviceVersionId == x.DeviceVersionId).Select(f => new TechnologyInfo() { Id = f.Id, Name = f.Name, DeviceVersionId = f.DeviceVersionId }).ToList();
  51. var TechnologyInfo = _db.Queryable<BPA_Technology>().Where(p => p.DeviceVersionId == x.DeviceVersionId).Select(f => new TechnologyInfo() { Id = f.Id, Name = f.Name, DeviceVersionId = f.DeviceVersionId,CreateAt=f.CreateAt }).Mapper(g =>
  52. {
  53. g.TechnologyActionInfo= _db.Queryable<BPA_TechnologyAction>().Where(d=>d.TechnologyId==g.Id).ToList();
  54. }).ToList();
  55. x.TechnologyInfo = TechnologyInfo;
  56. })
  57. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  58. return new PageUtil()
  59. {
  60. Data = data,
  61. Total = total
  62. };
  63. }
  64. /// <summary>
  65. /// 根据设备id查询设备工艺信息
  66. /// </summary>
  67. /// <param name="deviceId"></param>
  68. /// <returns></returns>
  69. public async Task<List<TechnologyView>> GetTechnologyList(string deviceId)
  70. {
  71. var device= _db.Queryable<BPA_DeviceInfo>().Where(x=>x.Id== deviceId).First();
  72. if (device == null) return new List<TechnologyView>();
  73. var data = await _db.Queryable<BPA_Technology>().Where(x=>x.DeviceVersionId== device.ProductVersionId).Select(a => new TechnologyView
  74. {
  75. Id = a.Id,
  76. Name = a.Name,
  77. DeviceVersionId = a.DeviceVersionId,
  78. CreateAt = a.CreateAt,
  79. }).OrderBy(a => a.CreateAt, OrderByType.Desc)
  80. .Mapper(x =>
  81. {
  82. //var TechnologyInfo1 = _db.Queryable<BPA_Technology>().Where(p => p.DeviceVersionId == x.DeviceVersionId).Select(f => new TechnologyInfo() { Id = f.Id, Name = f.Name, DeviceVersionId = f.DeviceVersionId }).ToList();
  83. var TechnologyInfo = _db.Queryable<BPA_TechnologyAction>().Where(d => d.TechnologyId == x.Id).ToList();
  84. x.TechnologyActionInfo = TechnologyInfo;
  85. })
  86. .ToListAsync();
  87. return data;
  88. }
  89. public async Task<List<TechnologyView>> GetTechnologyList_alm(string deviceId)
  90. {
  91. var device = _db.Queryable<BPA_DeviceInfo>().Where(x => x.Id == deviceId).First();
  92. var data = await _db.Queryable<BPA_Technology>().Where(x => x.DeviceVersionId == device.ProductVersionId).Select(a => new TechnologyView
  93. {
  94. Id = a.Id,
  95. Name = a.Name,
  96. DeviceVersionId = a.DeviceVersionId,
  97. CreateAt = a.CreateAt,
  98. }).OrderBy(a => a.CreateAt, OrderByType.Desc)
  99. .Mapper(x =>
  100. {
  101. //var TechnologyInfo1 = _db.Queryable<BPA_Technology>().Where(p => p.DeviceVersionId == x.DeviceVersionId).Select(f => new TechnologyInfo() { Id = f.Id, Name = f.Name, DeviceVersionId = f.DeviceVersionId }).ToList();
  102. var TechnologyInfo = _db.Queryable<BPA_TechnologyAction>().Where(d => d.TechnologyId == x.Id).ToList();
  103. x.TechnologyActionInfo = TechnologyInfo;
  104. })
  105. .ToListAsync();
  106. return data;
  107. }
  108. public async Task<bool> DeTechnologyExportRecode(string inputList)
  109. {
  110. try
  111. {
  112. _db.Ado.BeginTran();
  113. var datas = await _db.Queryable<BPA_TechnologyExportRecode>().Where(x => x.Id == inputList).FirstAsync();
  114. var Technology = _db.Queryable<BPA_Technology>().Where(p => p.DeviceVersionId == datas.DeviceVersionId).ToList();
  115. var TechnologyIds = Technology.Select(x => x.Id).ToArray();
  116. var TechnologyAction = _db.Queryable<BPA_TechnologyAction>().Where(p => TechnologyIds.Contains(p.TechnologyId)).ToList();
  117. _db.Deleteable(TechnologyAction).ExecuteCommand();
  118. _db.Deleteable(Technology).ExecuteCommand();
  119. _db.Deleteable(datas).ExecuteCommand();
  120. _db.Ado.CommitTran();
  121. return true;
  122. }
  123. catch (Exception)
  124. {
  125. _db.Ado.RollbackTran();
  126. throw Oops.Oh("删除失败");
  127. }
  128. }
  129. }
  130. }