using Yw.BLL;
namespace PBS.BLL
{
///
/// 电费
///
public partial class ElecPrice
{
private readonly PBS.CAL.IElecPrice _cal = CALCreateHelper.CreateCAL();
#region Query
///
/// 获取所有
///
public virtual async Task> GetAll()
{
var dtoList = await _cal.GetAll();
return Dto2Vmos(dtoList);
}
///
/// 通过 ID 获取
///
public virtual async Task GetByID(long ID)
{
var dto = await _cal.GetByID(ID);
return Dto2Vmo(dto);
}
///
/// 通过 Ids 获取
///
public virtual async Task> GetByIds(List Ids)
{
var dtoList = await _cal.GetByIds(Ids);
return Dto2Vmos(dtoList);
}
#endregion Query
#region Insert
///
/// 插入一条
///
public virtual async Task Insert(PBS.Vmo.ElecPriceVmo vmo)
{
var dto = Vmo2AddDto(vmo);
var id = await _cal.Insert(dto);
return id;
}
///
/// 插入多条
///
public virtual async Task Inserts(List vmoList)
{
var dtoList = Vmo2AddDtos(vmoList);
var bol = await _cal.Inserts(dtoList);
return bol;
}
#endregion Insert
#region Update
///
/// 更新
///
public virtual async Task Update(PBS.Vmo.ElecPriceVmo vmo)
{
var dto = Vmo2UpdateDto(vmo);
var bol = await _cal.Update(dto);
return bol;
}
///
/// 批量更新
///
public virtual async Task Updates(List vmoList)
{
var dtoList = Vmo2UpdateDtos(vmoList);
var bol = await _cal.Updates(dtoList);
return bol;
}
#endregion Update
#region Delete
///
/// 通过 ID 删除
///
public virtual async Task DeleteByID(long ID)
{
var bol = await _cal.DeleteByID(ID);
return bol;
}
#endregion Delete
public async Task CalcuShysElectricityFees(DateTime time, double el)
{
var allList = await GetAll();
var month = time.Month;
var hour = time.Hour;
var monthSettings = allList.First().Settings.MonthList.Find(x => month >= x.StartMonth && month <= x.EndMonth);
var hourList = monthSettings.HourList;
var item = hourList.Find(x => hour >= x.StartHour && hour < x.EndHour);
return el * item.Price;
}
public async Task PeakValleyFlatValid(DateTime time)
{
var allList = await GetAll();
var month = time.Month;
var hour = time.Hour;
var monthSettings = allList.First().Settings.MonthList.Find(x => month >= x.StartMonth && month <= x.EndMonth);
var hourList = monthSettings.HourList;
if (hour == 23)
{
var item = hourList.Find(x => x.EndHour == 23);
if (item.Name == "峰时段")
return 1;
if (item.Name == "谷时段")
return 2;
if (item.Name == "平时段")
return 3;
}
else
{
var item = hourList.Find(x => hour >= x.StartHour && hour < x.EndHour);
if (item.Name == "峰时段")
return 1;
if (item.Name == "谷时段")
return 2;
if (item.Name == "平时段")
return 3;
}
return 0;
}
}
}