| | |
| | | |
| | | using Admin.NET.Core.Service; |
| | | using Elastic.Clients.Elasticsearch; |
| | | using StackExchange.Profiling.Internal; |
| | | using WCS.Application.Entity; |
| | | using WCS.Application.Service.WcsDevice.Dto; |
| | | |
| | |
| | | var query = _wcsDeviceRep.AsQueryable() |
| | | .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u => |
| | | u.Text.Contains(input.SearchKey) |
| | | || u.StationNum.Contains(input.SearchKey) |
| | | ) |
| | | .WhereIF(input.PlcId > 0, u => u.PlcId == input.PlcId) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.StationNum), u => u.StationNum.Contains(input.StationNum.Trim())) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.Text), u => u.Text.Contains(input.Text.Trim())) |
| | | //处理外键和TreeSelector相关字段的连接 |
| | | .LeftJoin<WcsPlc>((u, plcid) => u.PlcId == plcid.Id) |
| | |
| | | (result, var palletNo) = modConn.GetPlcDBValue(modPositionPalletNo.PosType, modDevice.DbNumber, modPositionPalletNo.PlcPos, modPositionPalletNo.StringLength); |
| | | modDevice.PalletNo = Convert.ToString(palletNo); |
| | | Console.WriteLine(modDevice.DbNumber + "." + modPositionPalletNo.PlcPos + "----------"); |
| | | } |
| | | if (cachePlc.Type == PLCTypeEnum.ConveyorLine) |
| | | } |
| | | if (cachePlc.Type == PLCTypeEnum.ConveyorLine || cachePlc.Type == PLCTypeEnum.StackingMachine) |
| | | { |
| | | //放货排 |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | |
| | | (result, var pickStorey) = modConn.GetPlcDBValue(modPositionPickStorey.PosType, modDevice.DbNumber, modPositionPickStorey.PlcPos); |
| | | modDevice.PickStorey = Convert.ToInt32(pickStorey); |
| | | } |
| | | |
| | | |
| | | if (cachePlc.Type == PLCTypeEnum.StackingMachine) |
| | | { |
| | | //跺机的起始工位用取货排列层 |
| | | modDevice.StartLocatNo = $"{modDevice.PickRow.ToString().PadLeft(2,'0')}{modDevice.PickCol.ToString().PadLeft(2, '0')}{modDevice.PickStorey.ToString().PadLeft(2, '0')}"; |
| | | //跺机的目的工位用放货排列层 |
| | | modDevice.EndLocatNo = $"{modDevice.ReleaseRow.ToString().PadLeft(2, '0')}{modDevice.ReleaseCol.ToString().PadLeft(2, '0')}{modDevice.ReleaseStorey.ToString().PadLeft(2, '0')}"; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | var listPosition = await _wcsDeviceRep.Context.Queryable<WcsPosition>().Where(s => s.DeviceId == modDevice.Id).ToListAsync(); |
| | | var result = new IoTClient.Result(); |
| | | //任务号 |
| | | if (!modDevice.TaskNo.IsNullOrEmpty()) |
| | | if (modDevice.TaskNo != null) |
| | | { |
| | | var modPositionTask = listPosition.FirstOrDefault(s => s.Text == "任务号"); |
| | | if (modPositionTask != null) |
| | | result = modUtil.SetPlcDBValue(modPositionTask.PosType, modDbDevice.DbNumber + "." + modPositionTask.PlcPos, modDevice.TaskNo); |
| | | result = modUtil.SetPlcDBValue(modPositionTask.PosType, modDbDevice.DbNumber, modPositionTask.PlcPos, modDevice.TaskNo); |
| | | } |
| | | //任务类型 |
| | | if (!modDevice.TaskType.IsNullOrEmpty()) |
| | | if (modDevice.TaskType != null) |
| | | { |
| | | var modPositionTaskType = listPosition.FirstOrDefault(s => s.Text == "任务类型"); |
| | | if (modPositionTaskType != null) |
| | | result = modUtil.SetPlcDBValue(modPositionTaskType.PosType, modDbDevice.DbNumber + "." + modPositionTaskType.PlcPos, ((int)modDevice.TaskType).ToString()); |
| | | result = modUtil.SetPlcDBValue(modPositionTaskType.PosType, modDbDevice.DbNumber, modPositionTaskType.PlcPos, ((int)modDevice.TaskType).ToString()); |
| | | } |
| | | //起始工位 |
| | | if (!modDevice.StartLocatNo.IsNullOrEmpty()) |
| | | if (modDevice.StartLocatNo != null) |
| | | { |
| | | var modPositionStartLocatNo = listPosition.FirstOrDefault(s => s.Text == "起始工位"); |
| | | if (modPositionStartLocatNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionStartLocatNo.PosType, modDbDevice.DbNumber + "." + modPositionStartLocatNo.PlcPos, modDevice.StartLocatNo.ToString()); |
| | | if (modPlc.Type == PLCTypeEnum.StackingMachine) |
| | | { |
| | | if (modDevice.StartLocatNo.Length != 6) |
| | | { |
| | | throw Oops.Bah("起始工位格式输入错误,请输入排列层,例:010203!"); |
| | | } |
| | | modDevice.PickRow = Convert.ToInt32(modDevice.StartLocatNo.Substring(0, 2)); |
| | | modDevice.PickCol = Convert.ToInt32(modDevice.StartLocatNo.Substring(2, 2)); |
| | | modDevice.PickStorey = Convert.ToInt32(modDevice.StartLocatNo.Substring(4, 2)); |
| | | |
| | | //取货排 |
| | | if (modDevice.PickRow != null) |
| | | { |
| | | var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排"); |
| | | if (modPositionPickRow != null) |
| | | modUtil.SetPlcDBValue(modPositionPickRow.PosType, modDbDevice.DbNumber, modPositionPickRow.PlcPos, modDevice.PickRow.ToString()); |
| | | } |
| | | //取货列 |
| | | if (modDevice.PickCol != null) |
| | | { |
| | | var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列"); |
| | | if (modPositionPickCol != null) |
| | | modUtil.SetPlcDBValue(modPositionPickCol.PosType, modDbDevice.DbNumber, modPositionPickCol.PlcPos, modDevice.PickCol.ToString()); |
| | | } |
| | | //取货层 |
| | | if (modDevice.PickStorey != null) |
| | | { |
| | | var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层"); |
| | | if (modPositionPickStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionPickStorey.PosType, modDbDevice.DbNumber, modPositionPickStorey.PlcPos, modDevice.PickStorey.ToString()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var modPositionStartLocatNo = listPosition.FirstOrDefault(s => s.Text == "起始工位"); |
| | | if (modPositionStartLocatNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionStartLocatNo.PosType, modDbDevice.DbNumber, modPositionStartLocatNo.PlcPos, modDevice.StartLocatNo.ToString()); |
| | | } |
| | | } |
| | | //目的工位 |
| | | if (!modDevice.EndLocatNo.IsNullOrEmpty()) |
| | | if (modDevice.EndLocatNo != null) |
| | | { |
| | | var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "目的工位"); |
| | | if (modPositionEndLocatNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionEndLocatNo.PosType, modDbDevice.DbNumber + "." + modPositionEndLocatNo.PlcPos, modDevice.EndLocatNo.ToString()); |
| | | if (modPlc.Type == PLCTypeEnum.StackingMachine) |
| | | { |
| | | if (modDevice.EndLocatNo.Length != 6) |
| | | { |
| | | throw Oops.Bah("目的工位格式输入错误,请输入排列层,例:010203!"); |
| | | } |
| | | modDevice.ReleaseRow = Convert.ToInt32(modDevice.EndLocatNo.Substring(0, 2)); |
| | | modDevice.ReleaseCol = Convert.ToInt32(modDevice.EndLocatNo.Substring(2, 2)); |
| | | modDevice.ReleaseStorey = Convert.ToInt32(modDevice.EndLocatNo.Substring(4, 2)); |
| | | |
| | | //放货排 |
| | | if (modDevice.ReleaseRow != null) |
| | | { |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | | if (modPositionReleaseRow != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseRow.PosType, modDbDevice.DbNumber, modPositionReleaseRow.PlcPos, modDevice.ReleaseRow.ToString()); |
| | | } |
| | | //放货列 |
| | | if (modDevice.ReleaseCol != null) |
| | | { |
| | | var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列"); |
| | | if (modPositionReleaseCol != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseCol.PosType, modDbDevice.DbNumber, modPositionReleaseCol.PlcPos, modDevice.ReleaseCol.ToString()); |
| | | } |
| | | //放货层 |
| | | if (modDevice.ReleaseStorey != null) |
| | | { |
| | | var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层"); |
| | | if (modPositionReleaseStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseStorey.PosType, modDbDevice.DbNumber, modPositionReleaseStorey.PlcPos, modDevice.ReleaseStorey.ToString()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "目的工位"); |
| | | if (modPositionEndLocatNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionEndLocatNo.PosType, modDbDevice.DbNumber, modPositionEndLocatNo.PlcPos, modDevice.EndLocatNo.ToString()); |
| | | } |
| | | } |
| | | //托盘码 |
| | | if (!modDevice.PalletNo.IsNullOrEmpty()) |
| | | if (modDevice.PalletNo != null) |
| | | { |
| | | var modPositionPalletNo = listPosition.FirstOrDefault(s => s.Text == "托盘码"); |
| | | if (modPositionPalletNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionPalletNo.PosType, modDbDevice.DbNumber + "." + modPositionPalletNo.PlcPos, modDevice.PalletNo.ToString()); |
| | | result = modUtil.SetPlcDBValue(modPositionPalletNo.PosType, modDbDevice.DbNumber, modPositionPalletNo.PlcPos, modDevice.PalletNo.ToString()); |
| | | } |
| | | if (modDevice.Plc != null) |
| | | { |
| | | var modPositionPLC = listPosition.FirstOrDefault(s => s.Text == "PLC流程字"); |
| | | if (modPositionPLC != null) |
| | | result = modUtil.SetPlcDBValue(modPositionPLC.PosType, modDbDevice.DbNumber, modPositionPLC.PlcPos, modDevice.Plc); |
| | | } |
| | | if (modDevice.Wcs != null) |
| | | { |
| | | var modPositionWCS = listPosition.FirstOrDefault(s => s.Text == "WCS流程字"); |
| | | if (modPositionWCS != null) |
| | | result = modUtil.SetPlcDBValue(modPositionWCS.PosType, modDbDevice.DbNumber, modPositionWCS.PlcPos, modDevice.Wcs); |
| | | } |
| | | if (modPlc.Type == PLCTypeEnum.ConveyorLine) |
| | | { |
| | |
| | | { |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | | if (modPositionReleaseRow != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseRow.PosType, modDbDevice.DbNumber + "." + modPositionReleaseRow.PlcPos, modDevice.ReleaseRow.ToString()); |
| | | modUtil.SetPlcDBValue(modPositionReleaseRow.PosType, modDbDevice.DbNumber, modPositionReleaseRow.PlcPos, modDevice.ReleaseRow.ToString()); |
| | | } |
| | | //放货列 |
| | | if (modDevice.ReleaseCol != null) |
| | | { |
| | | var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列"); |
| | | if (modPositionReleaseCol != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseCol.PosType, modDbDevice.DbNumber + "." + modPositionReleaseCol.PlcPos, modDevice.ReleaseCol.ToString()); |
| | | modUtil.SetPlcDBValue(modPositionReleaseCol.PosType, modDbDevice.DbNumber, modPositionReleaseCol.PlcPos, modDevice.ReleaseCol.ToString()); |
| | | } |
| | | //放货层 |
| | | if (modDevice.ReleaseStorey != null) |
| | | { |
| | | var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层"); |
| | | if (modPositionReleaseStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseStorey.PosType, modDbDevice.DbNumber + "." + modPositionReleaseStorey.PlcPos, modDevice.ReleaseStorey.ToString()); |
| | | modUtil.SetPlcDBValue(modPositionReleaseStorey.PosType, modDbDevice.DbNumber, modPositionReleaseStorey.PlcPos, modDevice.ReleaseStorey.ToString()); |
| | | } |
| | | //取货排 |
| | | if (modDevice.PickRow != null) |
| | | { |
| | | var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排"); |
| | | if (modPositionPickRow != null) |
| | | modUtil.SetPlcDBValue(modPositionPickRow.PosType, modDbDevice.DbNumber + "." + modPositionPickRow.PlcPos, modDevice.PickRow.ToString()); |
| | | modUtil.SetPlcDBValue(modPositionPickRow.PosType, modDbDevice.DbNumber, modPositionPickRow.PlcPos, modDevice.PickRow.ToString()); |
| | | } |
| | | //取货列 |
| | | if (modDevice.PickCol != null) |
| | | { |
| | | var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列"); |
| | | if (modPositionPickCol != null) |
| | | modUtil.SetPlcDBValue(modPositionPickCol.PosType, modDbDevice.DbNumber + "." + modPositionPickCol.PlcPos, modDevice.PickCol.ToString()); |
| | | modUtil.SetPlcDBValue(modPositionPickCol.PosType, modDbDevice.DbNumber, modPositionPickCol.PlcPos, modDevice.PickCol.ToString()); |
| | | } |
| | | //取货层 |
| | | if (modDevice.PickStorey != null) |
| | | { |
| | | var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层"); |
| | | if (modPositionPickStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionPickStorey.PosType, modDbDevice.DbNumber + "." + modPositionPickStorey.PlcPos, modDevice.PickStorey.ToString()); |
| | | modUtil.SetPlcDBValue(modPositionPickStorey.PosType, modDbDevice.DbNumber, modPositionPickStorey.PlcPos, modDevice.PickStorey.ToString()); |
| | | } |
| | | } |
| | | modUtil.Close(); |
| | |
| | | [DisplayName("获取设备对应工位列表")] |
| | | public async Task<List<WcsDeviceTaskOrderDto>> WcsPackStationPlcList([FromQuery] WcsDeviceBaseInput entry) |
| | | { |
| | | return await _wcsDeviceRep.Context.Queryable<WcsDevice>() |
| | | .LeftJoin<WcsCheckTask>((device, task) => device.StationNum == task.Port) |
| | | .Where((device, task) => device.PlcId == entry.PlcId) |
| | | .OrderBy((device, task) => device.CreateTime) |
| | | .Select((device, task) => new WcsDeviceTaskOrderDto() |
| | | //var list = await _wcsDeviceRep.AsQueryable() |
| | | // .LeftJoin<WcsPlc>((a, b) => a.PlcId == b.Id) |
| | | // .Where((a, b) => a.DeviceType == DeviceTypeEnum.Business) |
| | | // .Select<WcsDeviceOutput>((a, b) => new WcsDeviceOutput() { Type = b.Type }, true) |
| | | // .ToListAsync(); |
| | | |
| | | |
| | | var list = await _wcsDeviceRep.Context.Queryable<WcsDevice>() |
| | | .InnerJoin<WcsPlc>((device, plc) => device.PlcId == plc.Id) |
| | | .LeftJoin<WcsCheckTask>((device, plc, task) => device.StationNum == task.Port) |
| | | .Where((device, plc, task) => device.PlcId == entry.PlcId) |
| | | .OrderBy((device, plc, task) => device.CreateTime) |
| | | .Select((device, plc, task) => new WcsDeviceTaskOrderDto() |
| | | { |
| | | Id = device.Id, |
| | | Text = device.Text, |
| | |
| | | LineNo = task.LineNo, |
| | | Status = task.Status, |
| | | PZNo = task.PZNo, |
| | | Qty = task.Qty |
| | | Qty = task.Qty, |
| | | |
| | | PlcId=device.PlcId, |
| | | Type = plc.Type |
| | | }) |
| | | .ToListAsync(); |
| | | |
| | | bool connStatus = false; |
| | | //获取设备的状态 |
| | | var modPlc = await _wcsDeviceRep.Context.Queryable<WcsPlc>().FirstAsync(s => s.Id == list[0].PlcId); |
| | | PLCUtil modUtil = new PLCUtil(modPlc); |
| | | if (modUtil.Connected) |
| | | { |
| | | connStatus = true; |
| | | } |
| | | foreach (var item in list) |
| | | { |
| | | item.PlcStatus = connStatus; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | } |