using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using log4net;
using Repository.Station;
using Service.Cloud.Client;
using Service.Cloud.Msg.Host.Req;
using Service.Init;
namespace Service.MyTask;
///
/// 仓位上传至云平台
///
[Scope]
public class BinInfoReportCloudTask : ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(BinInfoReportCloudTask));
private volatile bool _stop;
public BinInfoReportCloudTask(BinInfoRepository binInfoRepository)
{
BinInfoRepository = binInfoRepository;
}
private BinInfoRepository BinInfoRepository { get; set; }
public string Name()
{
return "BinInfoReportCloudTask";
}
public int Interval()
{
return 1000 * 3;
}
public void Handle()
{
List binInfList = BinInfoRepository.Query();
if (binInfList.Count <= 0)
{
return;
}
BinDataInfo binDataInfo = new BinDataInfo
{
stationNo = StaticStationInfo.StationNo,
binInfoList = binInfList.Select(binInfo => new BinData
{
binCode = binInfo.No,
existsFlag = binInfo.Exists,
batteryNo = binInfo.BatteryNo,
chargerNo = binInfo.ChargerNo,
waterCoolNo = binInfo.WaterCoolNo,
elecPluginFlag = binInfo.ElecPluginFlag,
elecPluginStatus = Convert.ToInt32(binInfo.ElecPluginStatus),
waterPluginFlag = Convert.ToInt32(binInfo.WaterPluginFlag),
amtLock = binInfo.AmtLock,
chargeStatus = binInfo.ChargeStatus,
status = binInfo.Status,
lastChargeFinishTime = binInfo.LastChargeFinishTime,
cacheBinFlag = binInfo.CacheBinFlag,
canSwapFlag = binInfo.CanSwapFlag,
canChargeFlag = binInfo.CanChargeFlag,
inTime = binInfo.InTime
}).ToList()
};
CloudClientMgr.CloudClient?.Publish(binDataInfo);
Log.Info("上报仓位数据到云平台成功");
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}