NozzleService.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. using System.Transactions;
  9. using static FreeSql.Internal.GlobalFilter;
  10. namespace Fuel.Application.Service
  11. {
  12. public class NozzleService : INozzleService
  13. {
  14. private readonly EntityHelper _entityHelper;
  15. public NozzleService(EntityHelper entityHelper)
  16. {
  17. _entityHelper = entityHelper;
  18. }
  19. /// <summary>
  20. /// 上传油枪
  21. /// </summary>
  22. /// <param name="uploadNozzle"></param>
  23. /// <returns></returns>
  24. public async Task<bool> uploadNozzle(UploadNozzle uploadNozzle)
  25. {
  26. //RedisHelper.HSetAsync("Transaction", "11:22:33:44", "3232");
  27. //RedisHelper.SetAsync("33:22:33:44", "qweqweqwe", 3600);
  28. // var fsdds = RedisHelper.GetAsync("33:22:33:44");
  29. //var das = RedisHelper.ExpireAsync("33:22:33:44", 10);
  30. Guid guid = Guid.Parse("12345678-9abc-def0-1234-56789abcdef0");//站点id,先默认填这个
  31. if (uploadNozzle.type == 1)
  32. {
  33. var isproduct = await _entityHelper.GetEntitiesAsync<product>(_ => _.Buid == guid && _.ProductName == uploadNozzle.ProductName);
  34. var istanks = await _entityHelper.GetEntitiesAsync<tanks>(_ => _.Buid == guid && _.TankNumber == uploadNozzle.TankNumber);
  35. var isnozzle = await _entityHelper.GetEntitiesAsync<nozzle>(_ => _.Buid == guid && _.ExternalGunNumber == uploadNozzle.ExternalGunNumber);
  36. if (isproduct.Count > 0 || istanks.Count > 0 || isnozzle.Count > 0)
  37. {
  38. return false;
  39. }
  40. product product = new product();
  41. product.ProductPrice = uploadNozzle.ProductPrice;
  42. product.ProductName = uploadNozzle.ProductName;
  43. product.ProductCode = uploadNozzle.ProductCode;
  44. product.Buid = guid;
  45. var productid = await _entityHelper.InsertEntityAsync(product);
  46. tanks tanks = new tanks();
  47. tanks.Buid = guid;
  48. tanks.TankNumber = uploadNozzle.TankNumber;
  49. tanks.TankCapacity = uploadNozzle.TankCapacity;
  50. tanks.ProductId = productid.Id;
  51. tanks.ProductName = uploadNozzle.ProductName;
  52. var tanksid = await _entityHelper.InsertEntityAsync(tanks);
  53. nozzle nozzle = new nozzle();
  54. nozzle.Buid = guid;
  55. nozzle.PumpId = uploadNozzle.PumpID;
  56. nozzle.TankId = tanksid.Id;
  57. nozzle.InternalGunNumber = uploadNozzle.InternalGunNumber;
  58. nozzle.ExternalGunNumber = uploadNozzle.ExternalGunNumber;
  59. nozzle.ProductID = productid.Id;
  60. await _entityHelper.InsertEntityAsync(nozzle);
  61. }
  62. else if (uploadNozzle.type == 2)
  63. {
  64. }
  65. else if (uploadNozzle.type == 3)
  66. {
  67. }
  68. return true;
  69. }
  70. public async Task<List<NozzleInfo>> GetNozzleInfo(int Nozzleid)
  71. {
  72. Guid guid = Guid.Parse("12345678-9abc-def0-1234-56789abcdef0");
  73. return _entityHelper._fsql.Select<nozzle, tanks, product>()
  74. .LeftJoin((a, b, c) => a.TankId == b.Id)
  75. .LeftJoin((a, b, c) => a.ProductID == c.Id)
  76. .Where((a, b, c) => a.Buid == guid && a.ExternalGunNumber == Nozzleid)
  77. .ToList((a, b, c) => new NozzleInfo()
  78. {
  79. Nozzleid = a.ExternalGunNumber,
  80. ProductName = c.ProductName,
  81. ProductPrice = c.ProductPrice,
  82. Status = a.Status,
  83. TankNumber = b.TankNumber
  84. });
  85. }
  86. }
  87. }