|
@@ -1,5 +1,8 @@
|
|
|
-using Fuel.Core.Nozzle.Dto;
|
|
|
+using Fuel.Core;
|
|
|
+using Fuel.Core.Models;
|
|
|
+using Fuel.Core.Nozzle.Dto;
|
|
|
using FuelServer.Core.Entity;
|
|
|
+using Org.BouncyCastle.Ocsp;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -13,69 +16,259 @@ namespace Fuel.Application.Service
|
|
|
public class NozzleService : INozzleService
|
|
|
{
|
|
|
private readonly EntityHelper _entityHelper;
|
|
|
- public NozzleService(EntityHelper entityHelper)
|
|
|
+ public readonly IFreeSql _fsql;
|
|
|
+ public NozzleService(EntityHelper entityHelper, IFreeSql fsql)
|
|
|
{
|
|
|
_entityHelper = entityHelper;
|
|
|
+ _fsql = fsql;
|
|
|
}
|
|
|
+ #region 油品
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> UploadProduct(UploadProduct uploadProduct)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _product = _fsql.Select<product>().Where(_ => _.Buid == guid && _.ProductId == uploadProduct.ProductId).First();
|
|
|
+ if (_product != null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油品已存在,请勿重复上传");
|
|
|
+ }
|
|
|
+ product product = new product();
|
|
|
+ product.Buid = guid;
|
|
|
+ product.ProductId = uploadProduct.ProductId;
|
|
|
+ product.ProductCode = uploadProduct.ProductCode;
|
|
|
+ product.ProductName = uploadProduct.ProductName;
|
|
|
+ product.ProductPrice = uploadProduct.ProductPrice;
|
|
|
+
|
|
|
+ int affectedRows = _fsql.Insert<product>().AppendData(product).ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油品信息插入失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok(product);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- public async Task<bool> uploadNozzle(UploadNozzle uploadNozzle)
|
|
|
+ public async Task<ServiceResponse> UpdateProduct(UploadProduct uploadProduct)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Guid guid = Guid.Parse("12345678-9abc-def0-1234-56789abcdef0");
|
|
|
- if (uploadNozzle.type == 1)
|
|
|
- {
|
|
|
- var isproduct = await _entityHelper.GetEntitiesAsync<product>(_ => _.Buid == guid && _.ProductName == uploadNozzle.ProductName);
|
|
|
- var istanks = await _entityHelper.GetEntitiesAsync<tanks>(_ => _.Buid == guid && _.TankNumber == uploadNozzle.TankNumber);
|
|
|
- var isnozzle = await _entityHelper.GetEntitiesAsync<nozzle>(_ => _.Buid == guid && _.ExternalGunNumber == uploadNozzle.ExternalGunNumber);
|
|
|
- if (isproduct.Count > 0 || istanks.Count > 0 || isnozzle.Count > 0)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
- product product = new product();
|
|
|
- product.ProductPrice = uploadNozzle.ProductPrice;
|
|
|
- product.ProductName = uploadNozzle.ProductName;
|
|
|
- product.ProductCode = uploadNozzle.ProductCode;
|
|
|
- product.Buid = guid;
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _product = _fsql.Select<product>().Where(_ => _.Buid == guid && _.ProductId == uploadProduct.ProductId).First();
|
|
|
+ if (_product == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("未找到油枪");
|
|
|
+ }
|
|
|
+ _product.ProductCode = uploadProduct.ProductCode;
|
|
|
+ _product.ProductName = uploadProduct.ProductName;
|
|
|
+ _product.ProductPrice = uploadProduct.ProductPrice;
|
|
|
+ int affectedRows = _fsql.Update<product>().SetSource(_product).ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油品信息更新失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok(_product);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> DeleteProduct(UploadProduct uploadProduct)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _product = _fsql.Select<product>().Where(_ => _.Buid == guid && _.ProductId == uploadProduct.ProductId).First();
|
|
|
+ if (_product == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("未找到油品");
|
|
|
+ }
|
|
|
+ int affectedRows = _fsql.Delete<product>()
|
|
|
+ .Where(p => p.ProductId == uploadProduct.ProductId)
|
|
|
+ .ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油品信息删除失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
|
|
|
- var productid = await _entityHelper.InsertEntityAsync(product);
|
|
|
+ #region 油罐
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> UploadTanks(UploadTanks uploadTanks)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _tanks = _fsql.Select<tanks>().Where(_ => _.Buid == guid && _.TankID == uploadTanks.TankID).First();
|
|
|
+ if (_tanks != null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油灌已存在,请勿重复上传");
|
|
|
+ }
|
|
|
+ tanks tanks = new tanks();
|
|
|
+ tanks.Buid = guid;
|
|
|
+ tanks.ProductId = uploadTanks.ProductId;
|
|
|
+ tanks.TankCapacity = uploadTanks.TankCapacity;
|
|
|
+ tanks.ProductName = uploadTanks.ProductName;
|
|
|
+ tanks.TankNumber = uploadTanks.TankNumber;
|
|
|
|
|
|
- tanks tanks = new tanks();
|
|
|
- tanks.Buid = guid;
|
|
|
- tanks.TankNumber = uploadNozzle.TankNumber;
|
|
|
- tanks.TankCapacity = uploadNozzle.TankCapacity;
|
|
|
- tanks.ProductId = productid.Id;
|
|
|
- tanks.ProductName = uploadNozzle.ProductName;
|
|
|
+ int affectedRows = _fsql.Insert<tanks>().AppendData(tanks).ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油灌信息插入失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok(tanks);
|
|
|
+ }
|
|
|
|
|
|
- var tanksid = await _entityHelper.InsertEntityAsync(tanks);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> UpdateTanks(UploadTanks uploadTanks)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _tanks = _fsql.Select<tanks>().Where(_ => _.Buid == guid && _.TankID == uploadTanks.TankID).First();
|
|
|
+ if (_tanks != null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油灌已存在,请勿重复上传");
|
|
|
+ }
|
|
|
+ _tanks.ProductId = uploadTanks.ProductId;
|
|
|
+ _tanks.TankCapacity = uploadTanks.TankCapacity;
|
|
|
+ _tanks.ProductName = uploadTanks.ProductName;
|
|
|
+ _tanks.TankNumber = uploadTanks.TankNumber;
|
|
|
+ int affectedRows = _fsql.Update<tanks>().SetSource(_tanks).ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油灌信息更新失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok(_tanks);
|
|
|
+ }
|
|
|
|
|
|
- nozzle nozzle = new nozzle();
|
|
|
- nozzle.Buid = guid;
|
|
|
- nozzle.PumpId = uploadNozzle.PumpID;
|
|
|
- nozzle.TankId = tanksid.Id;
|
|
|
- nozzle.InternalGunNumber = uploadNozzle.InternalGunNumber;
|
|
|
- nozzle.ExternalGunNumber = uploadNozzle.ExternalGunNumber;
|
|
|
- nozzle.ProductID = productid.Id;
|
|
|
- await _entityHelper.InsertEntityAsync(nozzle);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> DeleteTanks(UploadTanks uploadTanks)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _tanks = _fsql.Select<tanks>().Where(_ => _.Buid == guid && _.TankID == uploadTanks.TankID).First();
|
|
|
+ if (_tanks != null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油灌已存在,请勿重复上传");
|
|
|
}
|
|
|
- else if (uploadNozzle.type == 2)
|
|
|
+ int affectedRows = _fsql.Delete<tanks>()
|
|
|
+ .Where(p => p.TankID == uploadTanks.TankID)
|
|
|
+ .ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
{
|
|
|
+ return ServiceResponse.Error("油灌信息删除失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 油枪
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> uploadNozzle(UploadNozzle uploadNozzle)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _product = _fsql.Select<product>().Where(_ => _.Buid == guid && _.ProductName == uploadNozzle.ProductName).First();
|
|
|
+ var _tanks = _fsql.Select<tanks>().Where(_ => _.Buid == guid && _.TankNumber == uploadNozzle.TankNumber).First();
|
|
|
+ var isproduct = _fsql.Select<nozzle>().Where(_ => _.Buid == guid && _.NozzleId == uploadNozzle.NozzleId).First();
|
|
|
+ if (isproduct != null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油枪已存在");
|
|
|
+ }
|
|
|
+ if (_product != null || _tanks != null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油品或油罐信息为空");
|
|
|
+ }
|
|
|
+ nozzle _nozzle = new nozzle();
|
|
|
+ _nozzle.Buid = guid;
|
|
|
+ _nozzle.PumpId = uploadNozzle.PumpID;
|
|
|
+ _nozzle.TankId = _tanks.Id;
|
|
|
+ _nozzle.InternalGunNumber = uploadNozzle.InternalGunNumber;
|
|
|
+ _nozzle.ExternalGunNumber = uploadNozzle.ExternalGunNumber;
|
|
|
+ _nozzle.ProductID = _product.Id;
|
|
|
+ int affectedRows = _fsql.Insert<nozzle>().AppendData(_nozzle).ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油枪信息插入失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok(_nozzle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> UpdateNozzle(UploadNozzle uploadNozzle)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _nozzle = _fsql.Select<nozzle>().Where(_ => _.Buid == guid && _.NozzleId == uploadNozzle.NozzleId).First();
|
|
|
+ if (_nozzle == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("未找到油枪");
|
|
|
+ }
|
|
|
+ _nozzle.PumpId = uploadNozzle.PumpID;
|
|
|
+ _nozzle.InternalGunNumber = uploadNozzle.InternalGunNumber;
|
|
|
+ _nozzle.ExternalGunNumber = uploadNozzle.ExternalGunNumber;
|
|
|
+ int affectedRows = _fsql.Update<nozzle>().SetSource(_nozzle).ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油枪信息更新失败");
|
|
|
+ }
|
|
|
+ return ServiceResponse.Ok(_nozzle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<ServiceResponse> DeleteNozzle(UploadNozzle uploadNozzle)
|
|
|
+ {
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
+ var _nozzle = _fsql.Select<nozzle>().Where(_ => _.Buid == guid && _.NozzleId == uploadNozzle.NozzleId).First();
|
|
|
+ if (_nozzle == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("未找到油枪");
|
|
|
}
|
|
|
- else if (uploadNozzle.type == 3)
|
|
|
+ int affectedRows = _fsql.Delete<nozzle>()
|
|
|
+ .Where(p => p.NozzleId == uploadNozzle.NozzleId)
|
|
|
+ .ExecuteAffrows();
|
|
|
+ if (affectedRows <= 0)
|
|
|
{
|
|
|
+ return ServiceResponse.Error("油枪信息删除失败");
|
|
|
}
|
|
|
- return true;
|
|
|
+ return ServiceResponse.Ok();
|
|
|
}
|
|
|
+
|
|
|
public async Task<List<NozzleInfo>> GetNozzleInfo(int Nozzleid)
|
|
|
{
|
|
|
- Guid guid = Guid.Parse("12345678-9abc-def0-1234-56789abcdef0");
|
|
|
+ Guid guid = HttpRequestReader.GetCurrentBuId();
|
|
|
return _entityHelper._fsql.Select<nozzle, tanks, product>()
|
|
|
.LeftJoin((a, b, c) => a.TankId == b.Id)
|
|
|
.LeftJoin((a, b, c) => a.ProductID == c.Id)
|
|
@@ -89,5 +282,6 @@ namespace Fuel.Application.Service
|
|
|
TankNumber = b.TankNumber
|
|
|
});
|
|
|
}
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|