@page "/Box/BoxAddDetail-复制" @using MasaBlazorApp3.Pojo.Config; @using MasaBlazorApp3.Pojo.Vo; @using MasaBlazorApp3.Util; @using Microsoft.Extensions.Options; @using Newtonsoft.Json; @using log4net; @if (CanTakeDrug) { } else { } @if (status < 2) { } @if (status == 2) { } @if (status <= 2) { } @code { @inject Radzen.DialogService dialogService; @inject IChannelListDao channelListDao; @inject IOptions setting; @inject IOptions portSetting; @inject NotificationService _message @inject PortUtil PortUtil; private readonly ILog logger = LogManager.GetLogger(typeof(OrderDetailDialog)); int status; [Parameter] public ChannelList boxChannelList { get; set; } private bool CanTakeDrug = true; public List data { get; set; } //称重取药数量 int[] WeightFinnalQuantity { get; set; } = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //开抽屉前操作标识 List DrawerNoColNoList = new List(); protected override async Task OnInitializedAsync() { data = await channelListDao.getTakeInfoByBox(boxChannelList); // 如果有【stockQuantity】字段说明有药品库存不足 if (data.Any(it => it.ChannelStock == null)) { CanTakeDrug = false; } base.OnInitializedAsync(); } async Task OpenDrawer() { this.status = 1; // 解析需要打开的抽屉列表 List drawerNos = this.data.GroupBy(it => it.ChannelStock.DrawerNo).Select(it => it.First()).ToList(); // for (int i = 0; i < data.Count; i++) // { // if (data[i].ChannelStock != null && data[i].ChannelStock.DrawerChanneStockList != null && data[i].ChannelStock.DrawerChanneStockList.Count > 0) // { // for (int j = 0; j < data[i].ChannelStock.DrawerChanneStockList.Count; j++) // { // if (data[i].ChannelStock.DrawerChanneStockList[j].TakeQuantity <= 0) // { // continue; // } // BoxTakeVo boxTakeVo = new BoxTakeVo() { ChannelStock = data[i].ChannelStock.DrawerChanneStockList[j] }; // if (!drawerNos.Contains(boxTakeVo)) // { // // if (!(drawerNos.Where(dn => dn.ChannelStock.DrawerNo == boxTakeVo.ChannelStock.DrawerNo).Count() > 0)) // // { // drawerNos.Add(boxTakeVo); // // } // } // } // } // } // 根据抽屉类型来决定打开前是否需要查询数量 var promiseUtil = new PromiseUtil(); await promiseUtil.taskAsyncLoop(500, 0, async (options, next, stop) => { var orderTakeVo = drawerNos[options._data]; var drawerNo = orderTakeVo.ChannelStock.DrawerNo; try { if (this.status == 0) { stop(); } // 开启抽屉 else if (this.status == 1) { if (orderTakeVo.Status == 0) { // 判断是否为单支抽屉 if (setting.Value.single.Contains(drawerNo)) { PortUtil.PowerOn(drawerNo); await Task.Delay(portSetting.Value.delayTime); byte[] quantity = await PortUtil.CheckQuantityByDrawer(drawerNo); orderTakeVo.BeforeQuantity = quantity.Select(it => Convert.ToInt32(it)).ToArray().Skip(3).Take(9).ToArray(); logger.Info($"单支抽屉,开抽屉前检测数量【{string.Join(",", orderTakeVo.BeforeQuantity)}】"); var drawerChanneStockList = data.Where(ot => ot.ChannelStock.DrawerNo == drawerNo).Select(ot => ot.ChannelStock.DrawerChanneStockList).ToList(); await PortUtil.HasLightOnByCol(drawerNo, drawerChanneStockList[0].Where(i => i.TakeQuantity > 0).ToList().Select(i => i.ColNo).ToArray()); } for (int i = 0; i < data.Count; i++) { if (!DrawerNoColNoList.Contains(data[i].ChannelStock.DrawerNo.ToString() + data[i].ChannelStock.ColNo)) { if (data[i].ChannelStock.BoardType.ToString().Contains("6")) { PortUtil.DrawerNo = data[i].ChannelStock.DrawerNo; PortUtil.ColNoLst.Add(data[i].ChannelStock.ColNo); data[i].BeforeQuantity[data[i].ChannelStock.ColNo - 1] = await PortUtil.CheckQuantityForSingle(data[i].ChannelStock.ColNo); logger.Info($"称重抽屉,开抽屉前检测数量【{string.Join(",", orderTakeVo.BeforeQuantity)}】"); await Task.Delay(200); } //是药盒抽屉开药盒 if (data[i].ChannelStock.BoardType.ToString().Contains("3")) { PortUtil.DrawerNo = data[i].ChannelStock.DrawerNo; await PortUtil.OpenBoxByColNo(data[i].ChannelStock.ColNo); await Task.Delay(200); } DrawerNoColNoList.Add(data[i].ChannelStock.DrawerNo.ToString() + data[i].ChannelStock.ColNo); } } var b = await PortUtil.OpenDrawerStatus(drawerNo); if (b) { PortUtil.speechSynthesizer.SpeakAsyncCancelAll(); PortUtil.SpeakAsync($"{drawerNo}号抽屉已经打开,请,取药"); orderTakeVo.Status = 1; next(); } else { _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"抽屉【{drawerNo}】打开失败,请检测硬件", Duration = 4000 } ); logger.Info($"抽屉打开失败"); if (setting.Value.single.Contains(drawerNo)) { PortUtil.PowerOff(drawerNo); } RestData(); stop(); } } // 检测状态 else if (orderTakeVo.Status == 1) { // 查询抽屉是否为关闭状态 var b = await PortUtil.CheckDrawerStatus2(drawerNo); // 关闭则改变状态并终止循环 if (b) { data.ForEach(cl => { if (cl.ChannelStock.DrawerNo == drawerNo) { cl.GetQuantity = cl.Quantity; } }); orderTakeVo.Status = 2; // if (data.Any(it => it.ChannelStock.BoardType.ToString().Contains("2"))) // { // //有单支抽屉则广播灭灯 // PortUtil.AllLightOff(); // } if (options._data == drawerNos.Count - 1) { PortUtil.speechSynthesizer.SpeakAsyncCancelAll(); PortUtil.speechSynthesizer.SpeakAsyncCancelAll(); PortUtil.SpeakAsync($"取药完成,请,点击完成按钮进行确认"); this.status = 2; string alertMessage = string.Empty; //检查是否称重抽屉,核对实际取出数量是否与应取数量一致,不一致则弹出提示 for (int i = 0; i < data.Count; i++) { if (data[i].ChannelStock.BoardType.ToString().Contains("6")) { PortUtil.DrawerNo = data[i].ChannelStock.DrawerNo;// drawerNo; PortUtil.ColNoLst.Add(data[i].ChannelStock.ColNo); orderTakeVo.AfterQuantity[data[i].ChannelStock.ColNo - 1] = await PortUtil.CheckQuantityForSingle(data[i].ChannelStock.ColNo); logger.Info($"称重抽屉,关抽屉后检测数量【{string.Join(",", orderTakeVo.AfterQuantity)}】"); WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1] = data[i].BeforeQuantity[data[i].ChannelStock.ColNo - 1] - orderTakeVo.AfterQuantity[data[i].ChannelStock.ColNo - 1]; if (data[i].Quantity != WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1]) { //称重自动计数数量与实际要取数量不一致弹出提示,确认后保存数据 alertMessage += $"{data[i].Drug.DrugName}应取数量【{data[i].Quantity}】,实际取出数量【{WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1]}】"; } await Task.Delay(200); } if (data[i].ChannelStock.BoardType.ToString().Contains("2") && data[i].ChannelStock.DrawerNo == drawerNo) { byte[] quantity = await PortUtil.CheckQuantityByDrawer(drawerNo); orderTakeVo.AfterQuantity = quantity.Select(it => Convert.ToInt32(it)).ToArray().Skip(3).Take(9).ToArray(); logger.Info($"单支抽屉,关抽屉后检测数量【{string.Join(",", orderTakeVo.AfterQuantity)}】"); // WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1] = orderTakeVo.BeforeQuantity[data[i].ChannelStock.ColNo - 1] - orderTakeVo.AfterQuantity[data[i].ChannelStock.ColNo - 1]; // if (data[i].Quantity != WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1]) // { // alertMessage += $"{data[i].Drug.DrugName}应取数量【{data[i].Quantity}】,实际取出数量【{WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1]}】"; // } for (int j = 0; j < data[i].ChannelStock.DrawerChanneStockList.Count; j++) { WeightFinnalQuantity[data[i].ChannelStock.DrawerChanneStockList[j].ColNo - 1] = orderTakeVo.BeforeQuantity[data[i].ChannelStock.DrawerChanneStockList[j].ColNo - 1] - orderTakeVo.AfterQuantity[data[i].ChannelStock.DrawerChanneStockList[j].ColNo - 1]; if (data[i].ChannelStock.DrawerChanneStockList[j].TakeQuantity != WeightFinnalQuantity[data[i].ChannelStock.DrawerChanneStockList[j].ColNo - 1]) { alertMessage += $"{data[i].Drug.DrugName}应取数量【{data[i].ChannelStock.DrawerChanneStockList[j].TakeQuantity}】,实际取出数量【{WeightFinnalQuantity[data[i].ChannelStock.ColNo - 1]}】"; } } } } //有单支抽屉则广播灭灯 if (setting.Value.single.Contains(drawerNo)) { PortUtil.PowerOff(drawerNo); } // if (!string.IsNullOrEmpty(alertMessage)) // { // //弹出确认对话框 alertMessage += "应取数与实际取出数不一致确认要保存吗?"; // //弹出确认提示框 // var confirm = await dialogService.OpenAsync( // $"保存确认", // new Dictionary() { { "confirmInfo", alertMessage } }, // new DialogOptions() { Width = "45vw", Resizable = true, Draggable = true, ShowClose = false }); logger.Info(alertMessage); // if (!confirm) // { // RestData(); // logger.Info("取消保存"); // // 关闭弹窗 // dialogService.Close(false); // } // } stop(); } else { options._data += 1; next(); } } else { next(); // continue iteration } } } } catch (Exception e) { RestData(); logger.Info($"{boxChannelList.DrawerNo}药盒取药发生错误,{e.Message}"); _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"发生错误,{e.Message}", Duration = 4000 } ); if (setting.Value.single.Contains(drawerNo)) { PortUtil.PowerOff(drawerNo); } stop(); } }); } void RestData() { PortUtil.speechSynthesizer.SpeakAsyncCancelAll(); this.status = 0; data.ForEach(it => { it.Status = 0; it.BeforeQuantity = new int[9]; it.AfterQuantity = new int[9]; }); this.WeightFinnalQuantity = new int[9]; DrawerNoColNoList.Clear(); } void Cancel() { RestData(); // 关闭弹窗 dialogService.Close(false); } async Task TakeFinish() { // 保存账册、操作记录 var b = await channelListDao.BoxTakeFinish(data, boxChannelList); if (!b) { _message.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"数据保存失败", Duration = 4000 }); logger.Error($"手术室药盒取药保存数据库失败,数据{JsonConvert.SerializeObject(data)}"); // 关闭弹窗 dialogService.Close(false); } else { // 关闭弹窗 dialogService.Close(true); } //重置状态 this.RestData(); } RadzenDataGrid grid; void OnCellClick(DataGridCellMouseEventArgs args) { this.grid.EditRow(args.Data); } }