using System; using System.Threading; using SHJX.Service.Model.Dao; using SHJX.Service.ServerClient; using SHJX.Service.Model.Control; using System.Collections.Generic; using SHJX.Service.Control.Modules; using SHJX.Service.Control.Interface; using SHJX.Service.Common.Logging; using Microsoft.Extensions.Logging; using System.Linq; using SHJX.Service.Common.ReadXML; namespace SHJX.Service.Control.Route.RouteController { /// /// 加水 /// public class DissolveAddWaterOperate : FlowControlOperateImp { private static readonly ILogger logger = LogFactory.BuildLogger(typeof(DissolveAddWaterOperate)); private const string OpName = "Water"; private string localtion; private OptClient _client; private DropLiquid _liquid; private EquipmentTask _task; public virtual bool Operate(ReadConfigUtil config, DataEventArgs data) { _task = data.Task; _client = data.Client; _liquid = data.DataManager.QueryLiquid(OpName); if (!_liquid.Enable) return true; localtion = _task.To; logger.LogInformation($"加水{localtion}"); DataCentre.GetStorageContent.Factory("Timer").Start(); Thread.Sleep(2000); DataCentre.GetStorageContent.Factory("Timer").Stop(); var res = _task.RouteType switch { "SY" => SYStep(), "BD" => BDStep(), "Wash" => WashStep(), _ => throw new ArgumentNullException(_task.RouteType), }; return res; } /// /// 润洗 && 清洗 /// /// private bool WashStep() { var value = _task.TaskType switch { "润洗" => _liquid.WashVolume, "清洗" => _liquid.ClearVolume, _ => throw new ArgumentNullException(_task.TaskType), }; var res = DataCentre.GetStorageContent.Factory(OpName).Start(localtion); Thread.Sleep(Convert.ToInt32(Math.Round(1000 * value))); res = res && DataCentre.GetStorageContent.Factory(OpName).Stop(localtion); LiquidTotal liquid1 = DataCentre._dataManager.Query().Where(it => it.LiquidName.Equals(OpName)).First(); liquid1.Total -= 45; //水减去 45毫升 res = res && DataCentre._dataManager.Update(liquid1) > 0; return res; } /// /// 水样 /// /// /// 水样任务需要分两次加液 private bool SYStep() { PortArgs tempPortArgs = new() { TypeName = "Heat" }; var tempRes = _client.Factory("Heat").Read(tempPortArgs) as Dictionary; if (DataCentre.GetConfig.AddWaterTemperature < tempRes["pv"]) { logger.LogInformation($"加水时温度不匹配:加水温度为:{DataCentre.GetConfig.AddWaterTemperature},实际温度为:{tempRes["pv"]}"); return false; } DataCentre.GetStorageContent.Factory(OpName).Start(localtion); Thread.Sleep(Convert.ToInt32(Math.Round(1000 * _liquid.SampleVolume * 0.6))); DataCentre.GetStorageContent.Factory(OpName).Stop(localtion); var res = DataCentre.GetStorageContent.Factory(OpName).Start(localtion); Thread.Sleep(Convert.ToInt32(Math.Round(1000 * _liquid.SampleVolume * 0.4))); res = res && DataCentre.GetStorageContent.Factory(OpName).Stop(localtion); LiquidTotal liquid1 = DataCentre._dataManager.Query().Where(it => it.LiquidName.Equals(OpName)).First(); liquid1.Total -= 45; //水减去 45毫升 res = res && DataCentre._dataManager.Update(liquid1) > 0; return res; } /// /// 标定 /// /// /// /// 标定任务需要分两个步骤加液 private bool BDStep() { DataCentre.GetStorageContent.Factory("Timer").Start(); Thread.Sleep(2000); DataCentre.GetStorageContent.Factory("Timer").Stop(); var res = DataCentre.GetStorageContent.Factory(OpName).Start(localtion); Thread.Sleep(Convert.ToInt32(Math.Round(1000 * _liquid.SampleVolume * 0.5))); res = res && DataCentre.GetStorageContent.Factory(OpName).Stop(localtion); LiquidTotal liquid1 = DataCentre._dataManager.Query().Where(it => it.LiquidName.Equals(OpName)).First(); liquid1.Total -= 45; //水减去 45毫升 res = res && DataCentre._dataManager.Update(liquid1) > 0; return res; } } }