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.

239 lines
6.7 KiB

using EC.Entity.Organization;
using EC.Entity.Transport;
using EC.Service.Base;
using System;
using System.Collections.Generic;
namespace EC.Service.Transport
{
public class TransportBillService : MvcService<TransportBillEntity>
{
public TransportBillService()
{
}
#region BLL
/// <summary>
/// 通过运单号查询运单信息
/// </summary>
/// <returns></returns>
public TransportBillEntity GetBillBySerialNumber(string serialNumber)
{
return SelectEntityByWhere($"SerialNumber='{serialNumber}'");
}
/// <summary>
/// 通过车牌号和状态获取运单信息
/// </summary>
/// <returns></returns>
public TransportBillEntity GetLastBillByLicensePlate(string licensePlate)
{
return SelectEntityByWhere($"LicensePlate='{licensePlate}' AND TIMESTAMPDIFF(HOUR, InStartTime, now()) < 24 order by id desc");
}
public List<TransportBillEntity> GetTodayBillList()
{
return SelectEntityListByWhere($"TIMESTAMPDIFF(HOUR, InStartTime, now())< 12 order by id desc");
}
#endregion BLL
#region Insert
public int InsertBillInStart(string serialNo, SiteEntity site, MonthPlanEntity plan, TruckEntity truck, PhotoEntity photo, int state)
{
var obj = new TransportBillEntity
{
SerialNumber = serialNo,
CompanyId = plan.CompanyId,
SiteId = site.Id,
SiteName = site.Name,
SupplierId = plan.SupplierId,
SupplierName = plan.SupplierName,
PlanSerialNumber = plan.SerialNumber,
MaterialNo = plan.MaterialNo,
TruckId = truck.Id,
LicensePlate = truck.LicensePlate,
InPicture1 = photo.SerialNumber,
InStartTime = DateTime.Now,
State = state
};
return SaveForm(obj);
}
#endregion Insert
#region Update
/// <summary>
///
/// </summary>
/// <param name="serialNumber">序号</param>
/// <param name="billWeight"></param>
/// <param name="inWeight"></param>
/// <param name="photo"></param>
/// <param name="state"></param>
/// <returns></returns>
public int UpdateBillInFinish(string serialNumber, decimal billWeight, decimal inWeight, PhotoEntity photo, int state)
{
var entity = GetBillBySerialNumber(serialNumber);//通过serialNumber查找对象
if (entity == null)
return -1;
//更新需要的值
entity.BillWeight = billWeight;
entity.InWeight = inWeight;
entity.InPicture2 = photo.SerialNumber;
entity.InFinishTime = DateTime.Now;
entity.State = state;
return SaveForm(entity);
}
/// <summary>
///
/// </summary>
/// <param name="serialNumber">序号</param>
/// <param name="billWeight"></param>
/// <param name="inWeight"></param>
/// <param name="trailer"></param>
/// <param name="driver1"></param>
/// <param name="driver2"></param>
/// <param name="photo"></param>
/// <param name="state"></param>
/// <returns></returns>
public int UpdateBillInFinish(string serialNumber, decimal billWeight, decimal inWeight, TrailerEntity trailer, DriverEntity driver1, DriverEntity driver2, PhotoEntity photo, int state)
{
var entity = GetBillBySerialNumber(serialNumber);//通过serialNumber查找对象
if (entity == null)
return -1;
//更新需要的值
entity.BillWeight = billWeight;
entity.InWeight = inWeight;
entity.TrailerId = trailer.Id;
entity.TrailerPlate = trailer.LicensePlate;
entity.DriverId = driver1.Id;
entity.DriverName = driver1.Name;
entity.Driver2Id = driver2.Id;
entity.Driver2Name = driver2.Name;
entity.InPicture2 = photo.SerialNumber;
entity.InFinishTime = DateTime.Now;
entity.State = state;
return SaveForm(entity);
}
/// <summary>
/// 空车入场称重时更新数据(状态、空车入场称重时间)
/// </summary>
/// <param name="entity"></param>
/// <param name="photo"></param>
/// <param name="state"></param>
/// <returns></returns>
public int UpdateBillOutStart(TransportBillEntity entity, PhotoEntity photo, int state)
{
if (entity == null)
return -1;
//更新需要的值
entity.OutPicture1 = photo.SerialNumber;
entity.OutStartTime = DateTime.Now;
entity.State = state;
return SaveForm(entity);
}
/// <summary>
/// 空车入场称重时更新数据(状态、空车入场称重时间)
/// </summary>
/// <returns></returns>
public int UpdateBillOutFinish(string serialNumber, decimal outWeight, decimal netWeight, PhotoEntity outPhoto2, int state)
{
var entity = GetBillBySerialNumber(serialNumber);//通过serialNumber查找对象
if (entity == null)
return -1;
//更新需要的值
entity.OutWeight = outWeight;
entity.NetWeight = netWeight;
entity.StandardRate = entity.BillWeight > 0 ? (double)Math.Round((entity.NetWeight / entity.BillWeight * 100), 2) : 0;
//entity.DriverId = driver1.Id;
//entity.DriverName = driver1.Name;
//entity.Driver2Id = driver2.Id;
//entity.Driver2Name = driver2.Name;
entity.OutPicture2 = outPhoto2.SerialNumber;
entity.OutFinishTime = DateTime.Now;
entity.State = state;
return SaveForm(entity);
}
/// <summary>
/// 空车入场称重时更新数据(状态、空车入场称重时间)
/// </summary>
/// <returns></returns>
public int UpdateBillOutFinish(string serialNumber, decimal outWeight, decimal netWeight, DriverEntity driver1, DriverEntity driver2, PhotoEntity outPhoto2, int state)
{
var entity = GetBillBySerialNumber(serialNumber);//通过serialNumber查找对象
if (entity == null)
return -1;
//更新需要的值
entity.OutWeight = outWeight;
entity.NetWeight = netWeight;
entity.StandardRate = entity.BillWeight > 0 ? (double)Math.Round((entity.NetWeight / entity.BillWeight * 100), 2) : 0;
entity.DriverId = driver1.Id;
entity.DriverName = driver1.Name;
entity.Driver2Id = driver2.Id;
entity.Driver2Name = driver2.Name;
entity.OutPicture2 = outPhoto2.SerialNumber;
entity.OutFinishTime = DateTime.Now;
entity.State = state;
return SaveForm(entity);
}
#endregion Update
#region Save
/// <summary>
/// 保存表单(新增、修改)
/// </summary>
/// <param name="entity">实体对象</param>
/// <returns></returns>
public int SaveForm(TransportBillEntity entity)
{
var oldEntity = (entity.Id > 0) ? SelectEntityByWhere($"Id='{entity.Id}'") : null;
if (oldEntity == null)
{
return db.Insert(entity);
}
else
{
oldEntity = EntityNewToOld(oldEntity, entity);
return db.Update(oldEntity);
}
}
#endregion Save
#region Compute
public int ComputeInCar8()
{
var list = SelectEntityListByWhere("State != 23 AND TIMESTAMPDIFF(HOUR, InStartTime, now()) < 24");
return list.Count;
}
public List<TransportBillEntity> ComputeInCarList()
{
var list = SelectEntityListByWhere("State != 23 AND TIMESTAMPDIFF(HOUR, InStartTime, now()) < 24 ORDER BY id asc");
return list;
}
#endregion Compute
}
}