using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
namespace WebStarter.Controllers;
///
/// 换电大屏
///
[ApiController]
[Route("api/[controller]")]
public class BinInfoController : ControllerBase
{
private readonly BinInfoRepository _BinInfoRepository;
private readonly EquipInfoRepository _equipInfoRepository;
public BinInfoController(BinInfoRepository infoRepository,EquipInfoRepository equipInfoRepository)
{
_BinInfoRepository = infoRepository;
_equipInfoRepository = equipInfoRepository;
}
///
/// 启用禁用充电 :
/// id:仓位id
/// flag :1:启用 0:禁用
///
///
///
///
[HttpGet("UpdateCanChargeFlag/{id}/{flag}")]
public Result UpdateCanChargeFlag(int id, int flag)
{
_BinInfoRepository.Update(it => it.CanChargeFlag == flag, it => it.Id == id);
return Result.Success();
}
[HttpGet("insert")]
public Result insert()
{
_BinInfoRepository.Insert(new BinInfo()
{
No = "10"
});
BinInfo queryByClause = _BinInfoRepository.QueryByClause(i => i.Id == 16);
return Result.Success();
}
///
/// 启用禁用换电 :
/// id:仓位id
/// flag :1:启用 0:禁用
///
///
///
///
[HttpGet("UpdateCanSwapFlag/{id}/{flag}")]
public async Task> UpdateCanSwapFlag(int id, int flag)
{
_BinInfoRepository.Update(it => it.CanSwapFlag == flag, it => it.Id == id);
return Result.Success();
}
///
/// 获取仓位充电功率
///
///
///
[HttpGet("ChargePower/{code}")]
public Result ChargePower(string code)
{
BinInfo binInfo = _BinInfoRepository.QueryByClause(it => it.No == code);
if (binInfo == null)
{
return Result.Fail("仓位不存在");
}
EquipInfo equipInfo = _equipInfoRepository.QueryByClause(i => i.Code == binInfo.ChargerNo);
if (equipInfo == null)
{
return Result.Fail("充电机不存在");
}
float? chargePower = equipInfo.ChargePower;
if (chargePower == null)
{
return Result.Fail("该仓没有充电功率");
}
return Result.Success((float)chargePower);
}
}