NozzleService.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Fuel.Core.Nozzle.Dto;
  2. using FuelServer.Core.Entity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Fuel.Application.Service
  9. {
  10. public class NozzleService : INozzleService
  11. {
  12. private readonly EntityHelper _entityHelper;
  13. public NozzleService(EntityHelper entityHelper)
  14. {
  15. _entityHelper = entityHelper;
  16. }
  17. /// <summary>
  18. /// 上传油枪
  19. /// </summary>
  20. /// <param name="uploadNozzle"></param>
  21. /// <returns></returns>
  22. public async Task<bool> uploadNozzle(UploadNozzle uploadNozzle)
  23. {
  24. Guid guid = Guid.Parse("12345678-9abc-def0-1234-56789abcdef0");
  25. if (uploadNozzle.type == 1)
  26. {
  27. var isproduct = await _entityHelper.GetEntitiesAsync<product>(_ => _.Buid == guid && _.ProductName == uploadNozzle.ProductName);
  28. var istanks = await _entityHelper.GetEntitiesAsync<tanks>(_ => _.Buid == guid && _.TankNumber == uploadNozzle.TankNumber);
  29. var isnozzle = await _entityHelper.GetEntitiesAsync<nozzle>(_ => _.Buid == guid && _.ExternalGunNumber == uploadNozzle.ExternalGunNumber);
  30. if (isproduct.Count > 0 || istanks.Count > 0 || isnozzle.Count > 0)
  31. {
  32. return false;
  33. }
  34. product product = new product();
  35. product.ProductPrice = uploadNozzle.ProductPrice;
  36. product.ProductName = uploadNozzle.ProductName;
  37. product.ProductCode = uploadNozzle.ProductCode;
  38. product.Buid = guid;
  39. var productid = await _entityHelper.InsertEntityAsync(product);
  40. tanks tanks = new tanks();
  41. tanks.Buid = guid;
  42. tanks.TankNumber = uploadNozzle.TankNumber;
  43. tanks.TankCapacity = uploadNozzle.TankCapacity;
  44. tanks.ProductId = productid.Id;
  45. tanks.ProductName = uploadNozzle.ProductName;
  46. var tanksid = await _entityHelper.InsertEntityAsync(tanks);
  47. nozzle nozzle = new nozzle();
  48. nozzle.Buid = guid;
  49. nozzle.PumpId = uploadNozzle.PumpID;
  50. nozzle.TankId = tanksid.Id;
  51. nozzle.InternalGunNumber = uploadNozzle.InternalGunNumber;
  52. nozzle.ExternalGunNumber = uploadNozzle.ExternalGunNumber;
  53. nozzle.ProductID = productid.Id;
  54. await _entityHelper.InsertEntityAsync(nozzle);
  55. }
  56. else if (uploadNozzle.type == 2)
  57. {
  58. }
  59. else if (uploadNozzle.type == 3)
  60. {
  61. }
  62. return true;
  63. }
  64. public async Task<List<NozzleInfo>> GetNozzleInfo(int Nozzleid)
  65. {
  66. Guid guid = Guid.Parse("12345678-9abc-def0-1234-56789abcdef0");
  67. return _entityHelper._fsql.Select<nozzle, tanks, product>()
  68. .LeftJoin((a, b, c) => a.TankId == b.Id)
  69. .LeftJoin((a, b, c) => a.ProductID == c.Id)
  70. .Where((a, b, c) => a.Buid == guid && a.ExternalGunNumber == Nozzleid)
  71. .ToList((a, b, c) => new NozzleInfo()
  72. {
  73. Nozzleid = a.ExternalGunNumber,
  74. ProductName = c.ProductName,
  75. ProductPrice = c.ProductPrice,
  76. Status = a.Status,
  77. TankNumber = b.TankNumber
  78. });
  79. }
  80. }
  81. }