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.
139 lines
3.9 KiB
139 lines
3.9 KiB
using Entity.Api.Req;
|
|
using Entity.Base;
|
|
using Entity.DbModel.Station;
|
|
using Entity.Dto.Req;
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
using Repository.Station;
|
|
using Repository.System;
|
|
using Service.Mgr;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using HybirdFrameworkCore.Entity;
|
|
using log4net;
|
|
using Service.Execute;
|
|
using Service.Execute.Api;
|
|
using Service.Plc.Client;
|
|
|
|
namespace Service.Station
|
|
{
|
|
[Scope("SingleInstance")]
|
|
public class BinInfoService : BaseServices<BinInfo>
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(BinInfoService));
|
|
private BinInfoRepository _binInfoRepository;
|
|
public PlcTaskMgr PlcTaskMgr { get; set; }
|
|
|
|
public BinInfoService(BinInfoRepository dal)
|
|
{
|
|
_binInfoRepository = dal;
|
|
BaseDal = dal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 充电仓查询
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<PageResult<BinInfo>> ChargePositionQuery(ChargePositionQueryReq input)
|
|
{
|
|
RefAsync<int> total = 0;
|
|
var items = await _binInfoRepository.QueryPageAsync(
|
|
entity => true, false, entity => true,
|
|
!string.IsNullOrEmpty(input.No), u => u.No == input.No,
|
|
!string.IsNullOrEmpty(input.Name), u => u.Name == input.Name,
|
|
u => u.Id, input.PageNum, input.PageSize, total
|
|
);
|
|
return new PageResult<BinInfo>()
|
|
{
|
|
PageNum = input.PageNum,
|
|
PageSize = input.PageSize,
|
|
ToTal = total,
|
|
Rows = items,
|
|
};
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 消防移仓
|
|
/// </summary>
|
|
/// <param name="entrySelection"></param>
|
|
/// <returns></returns>
|
|
public Result<bool> FireProtectionRelocation(string entrySelection)
|
|
{
|
|
BinInfo? queryByClause =
|
|
_binInfoRepository.QueryByClause(i => i.No.Equals(entrySelection) && i.Exists == 1);
|
|
if (queryByClause == null)
|
|
{
|
|
return Result<bool>.Fail("无电池");
|
|
}
|
|
|
|
|
|
if (queryByClause.ChargeStatus == 1)
|
|
{
|
|
if (!StopCharge(entrySelection))
|
|
{
|
|
return Result<bool>.Fail("停止充电失败");
|
|
}
|
|
}
|
|
|
|
var result = PlcMgr.DistributeTask(0, ushort.Parse(entrySelection), 5);
|
|
|
|
if (!result)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
result = PlcMgr.ReadTaskStatus(5);
|
|
if (!result)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
result = PlcMgr.HoldOn();
|
|
if (!result)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
Log.Info($"FireProtectionRelocation task Manual removeBinNo={entrySelection} ");
|
|
|
|
|
|
return PlcTaskMgr.QueryPlcTask(5, 1100, 1101) ? Result<bool>.Success() : Result<bool>.Fail();
|
|
}
|
|
|
|
|
|
private bool StopCharge(string binNo)
|
|
{
|
|
|
|
bool success = false;
|
|
int count = 0;
|
|
while (!success)
|
|
{
|
|
ChargeApi.StopCharge(binNo);
|
|
BinInfo? bin = _binInfoRepository.QueryByClause(i => i.No.Equals(binNo));
|
|
|
|
if (bin.ChargeStatus == 4)
|
|
{
|
|
success = true;
|
|
}
|
|
|
|
Thread.Sleep(1000);
|
|
count++;
|
|
|
|
if (count > 10)
|
|
{
|
|
Log.Info($"StopCharge timeout");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |