|
using Admin.NET.Core.Service;
|
using Elastic.Clients.Elasticsearch;
|
using Microsoft.CodeAnalysis.Text;
|
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
using StackExchange.Profiling.Internal;
|
using System.Drawing.Drawing2D;
|
using WCS.Application.Entity;
|
using WCS.Application.Service.WcsDevice.Dto;
|
|
namespace WCS.Application;
|
|
/// <summary>
|
/// 设备信息服务
|
/// </summary>
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
public class WcsDeviceService : IDynamicApiController, ITransient
|
{
|
private readonly SqlSugarRepository<WcsPlc> _wcsPlcRep;
|
private readonly SqlSugarRepository<WcsDevice> _wcsDeviceRep;
|
private readonly SysCacheService _sysCacheService;
|
public WcsDeviceService(SqlSugarRepository<WcsPlc> wcsPlcRep, SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService)
|
{
|
_wcsPlcRep = wcsPlcRep;
|
_wcsDeviceRep = wcsDeviceRep;
|
_sysCacheService = sysCacheService;
|
}
|
|
#region 工作台操作
|
|
|
/// <summary>
|
/// 手动操作PLC锁定写入工位信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "WriteLocationInfo")]
|
[DisplayName("手动操作PLC锁定写入工位信息")]
|
public async Task WriteLocationInfo(WcsDeviceUpInfo input)
|
{
|
WcsPlc modPlc;
|
string DbNum = "";// DB块
|
|
if (string.IsNullOrWhiteSpace(input.LocatNo))//如果工位为空
|
{
|
throw Oops.Bah("工位不能为空");
|
}
|
var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync();
|
switch (input.Layer)
|
{
|
case "1":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "1层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
case "2":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "2层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "DB91";
|
break;
|
case "3":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "3层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
default:
|
throw Oops.Bah("楼层信息错误");
|
}
|
|
var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show);
|
if (device == null)
|
{
|
throw Oops.Bah("当前楼层未查询到该工位信息");
|
}
|
PLCUtil modUtil = new PLCUtil(modPlc);
|
|
switch (input.TypeName)
|
{
|
case "suoding": // 锁定
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo);
|
break;
|
|
default:
|
break;
|
}
|
|
modUtil.Close();
|
}
|
|
|
/// <summary>
|
/// 获取工位上信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "GetLocationInfo")]
|
[DisplayName("获取工位上信息")]
|
public async Task<WcsDeviceUpInfo> GetLocationInfo(WcsDeviceUpInfo input)
|
{
|
WcsPlc modPlc;
|
string DbNum = "";// DB块
|
|
if (string.IsNullOrWhiteSpace(input.LocatNo))//如果工位为空
|
{
|
throw Oops.Bah("工位不能为空");
|
}
|
var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync();
|
switch (input.Layer)
|
{
|
case "1":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "1层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
case "2":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "2层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "DB1100";
|
break;
|
case "3":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "3层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
default:
|
throw Oops.Bah("楼层信息错误");
|
}
|
|
var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show);
|
if (device == null)
|
{
|
throw Oops.Bah("当前楼层未查询到该工位信息");
|
}
|
PLCUtil modUtil = new PLCUtil(modPlc);
|
WcsDeviceUpInfo data = new WcsDeviceUpInfo();
|
data.FuncName = "";
|
data.Layer = "";
|
data.LocatNo = input.LocatNo;
|
data.TypeName = "";
|
var (result2, value2) = modUtil.GetPlcDBValue(PLCDataTypeEnum.String, DbNum, "4");
|
data.PalletNo = value2;
|
var (result3, value3) = modUtil.GetPlcDBValue(PLCDataTypeEnum.String, DbNum, "14");
|
data.TaskNo = value3;
|
var (result4, value4) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "34");
|
data.StartLoction = value4.ToString();
|
var (result5, value5) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "36");
|
data.EndLoction = value5.ToString();
|
|
var (result6, value6) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "38");
|
data.StartPai = value6.ToString();
|
var (result7, value7) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "40");
|
data.StartLie = value7.ToString();
|
var (result8, value8) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "42");
|
data.StartCeng = value8.ToString();
|
|
|
var (result9, value9) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "44");
|
data.EndPai = value9.ToString();
|
var (result10, value10) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "46");
|
data.EndLie = value10.ToString();
|
var (result11, value11) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48");
|
data.EndCeng = value11.ToString();
|
|
modUtil.Close();
|
return data;
|
}
|
/// <summary>
|
/// 手动操作PLC信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "WriteInfo")]
|
[DisplayName("手动操作Plc")]
|
public async Task WriteInfo(WcsDeviceUpInfo input)
|
{
|
WcsPlc modPlc;
|
string DbNum = "";// DB块
|
|
if (string.IsNullOrWhiteSpace(input.LocatNo))//如果工位为空
|
{
|
throw Oops.Bah("工位不能为空");
|
}
|
var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync();
|
switch (input.Layer)
|
{
|
case "1":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "1层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
case "2":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "2层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "DB91";
|
break;
|
case "3":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "3层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
default:
|
throw Oops.Bah("楼层信息错误");
|
}
|
|
var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show);
|
if (device == null)
|
{
|
throw Oops.Bah("当前楼层未查询到该工位信息");
|
}
|
PLCUtil modUtil = new PLCUtil(modPlc);
|
|
|
// true : 手动模式 false:自动模式
|
var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4");
|
if (result.IsSucceed)
|
{
|
if (input.TypeName != "shoudong" && value.ToString().ToLower() == "false" && input.TypeName != "huifu" && input.TypeName != "UpTask")
|
{
|
throw Oops.Bah("当前为自动模式,请先切换为手动模式");
|
}
|
}
|
else
|
{
|
throw Oops.Bah("读取PLC手自动值失败");
|
}
|
|
switch (input.TypeName)
|
{
|
case "zidong": // 自动
|
//modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4", "false");
|
break;
|
case "shoudong": // 手动
|
//modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4", "true");
|
break;
|
case "huifu": // 报警恢复
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "47.0", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "47.0", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
|
break;
|
case "1diandong": // 1点动
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.7", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.7", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "1liandong": // 1联动
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.3", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.3", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "2diandong":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.0", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.0", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "2liandong":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.4", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.4", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "3diandong":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.5", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.5", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "3liandong":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.1", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.1", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "4diandong":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.6", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.6", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "4liandong":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.2", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.2", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "yizaisheng":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.5", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.5", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "yizaijiang":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.6", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.6", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "fanzhuansheng":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.7", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.7", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "fanzhuanjiang":
|
if (input.FuncName == "true")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "52.0", "true");
|
}
|
else if (input.FuncName == "false")
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "52.0", "false");
|
}
|
else
|
{
|
throw Oops.Bah("事件结果错误");
|
}
|
break;
|
case "UpTask":
|
var (result1, value2) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0");
|
if (result.IsSucceed)
|
{
|
if (value2 == true)
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0", "false");
|
}
|
else
|
{
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0", "true");
|
}
|
}
|
else
|
{
|
throw Oops.Bah("读取PLC值失败");
|
}
|
|
|
break;
|
default:
|
break;
|
}
|
|
modUtil.Close();
|
}
|
|
|
/// <summary>
|
/// 手动写入PLC任务信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "WriteTaskInfo")]
|
[DisplayName("写入Plc任务信息")]
|
public async Task WriteTaskInfo(WcsDeviceUpInfo input)
|
{
|
WcsPlc modPlc;
|
string DbNum = "";// DB块
|
string TaskDbNum = "";// DB块
|
|
if (string.IsNullOrWhiteSpace(input.LocatNo))//如果工位为空
|
{
|
throw Oops.Bah("工位不能为空");
|
}
|
var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync();
|
switch (input.Layer)
|
{
|
case "1":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "1层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
case "2":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "2层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "DB91";
|
TaskDbNum = "DB1100";
|
break;
|
case "3":
|
modPlc = plcList.FirstOrDefault(m => m.Text == "3层托盘输送线");
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到{input.Layer}楼层PLC信息");
|
DbNum = "";
|
break;
|
default:
|
throw Oops.Bah("楼层信息错误");
|
}
|
|
var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show);
|
if (device == null)
|
{
|
throw Oops.Bah("当前楼层未查询到该工位信息");
|
}
|
|
PLCUtil modUtil = new PLCUtil(modPlc);
|
//var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0");
|
//if (result.IsSucceed)
|
//{
|
// if (value.ToString().ToLower() != "false")
|
// {
|
// throw Oops.Bah("请先切换为更改任务模式");
|
// }
|
//}
|
//else
|
//{
|
// throw Oops.Bah("读取PLC手自动值失败");
|
//}
|
//modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo);
|
switch (input.TypeName)
|
{
|
case "writeTask":
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.String, TaskDbNum, "4", input.PalletNo);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.String, TaskDbNum, "14", input.TaskNo);
|
//modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "34", input.StartLoction);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "36.0", input.EndLoction);
|
|
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "38", input.StartPai);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "40", input.StartLie);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "42", input.StartCeng);
|
|
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "44", input.EndPai);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "46", input.EndLie);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "48", input.EndCeng);
|
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.3", "true");
|
Thread.Sleep(1000);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.3", "false");
|
break;
|
case "writeTaskDelete":
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.2", "true");
|
Thread.Sleep(1000);
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.2", "false");
|
break;
|
|
default:
|
break;
|
}
|
|
modUtil.Close();
|
}
|
|
|
|
/// <summary>
|
/// 手动写入PLC启停信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "WriteStartStop")]
|
[DisplayName("写入PLC启停信息")]
|
public async Task WriteStartStop(WcsDeviceStartStop input)
|
{
|
switch (input.Type)
|
{
|
case "Shutter":
|
{
|
string Pos = "";
|
if (input.Layer == "2")
|
{
|
Pos = "1152";
|
}
|
else
|
{
|
Pos = "1154";
|
}
|
var modPlc = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine).FirstAsync();
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到输送线PLC信息");
|
PLCUtil modUtil = new PLCUtil(modPlc);
|
var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, "DB1000." + Pos);
|
if (result.IsSucceed)
|
{
|
if (input.FuncName == "Down")
|
{
|
if (value == 20)
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, "DB1000", Pos, "30");
|
}
|
else if (input.FuncName == "Up")
|
{
|
if (value == 0)
|
modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, "DB1000", Pos, "10");
|
}
|
modUtil.Close();
|
}
|
else
|
throw Oops.Bah(result.Err);
|
}
|
break;
|
case "ShuttleCar":
|
{
|
string text = "";
|
if (input.No == "1")
|
text = "穿梭车1";
|
if (input.No == "2")
|
text = "穿梭车2";
|
var modPlc = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ShuttleCar && s.Text == text).FirstAsync();
|
if (modPlc == null)
|
throw Oops.Bah($"未查询到穿梭车PLC信息");
|
ModbusUtil modUtil = new ModbusUtil(modPlc);
|
var result = modUtil.SetDBValue(PLCDataTypeEnum.UShort, input.Layer, input.FuncName);
|
if (result.IsSucceed)
|
{
|
modUtil.Close();
|
}
|
else
|
throw Oops.Bah(result.Err);
|
}
|
break;
|
default:
|
break;
|
}
|
//WcsPlc modPlc;
|
//string DbNum = "";// DB块
|
//var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine).ToListAsync();
|
//if (input.Layer == "1")
|
//{
|
// modPlc = plcList.FirstOrDefault(m => m.Text == "1层托盘输送线");
|
// if (modPlc == null)
|
// throw Oops.Bah($"未查询到1楼层PLC信息");
|
// DbNum = "";
|
//}
|
//else if (input.Layer == "2")
|
//{
|
// modPlc = plcList.FirstOrDefault(m => m.Text == "2层托盘输送线");
|
// if (modPlc == null)
|
// throw Oops.Bah($"未查询到2楼层PLC信息");
|
// DbNum = "DB91";
|
// PLCUtil modUtil = new PLCUtil(modPlc);
|
// switch (input.Type)
|
// {
|
// case "TwoPalletStart":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.0", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.0", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoPalletStop":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.1", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.1", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoMaStart":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.0", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.0", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoMaStop":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.1", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.1", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoMaTwoStart":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.2", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.2", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoMaTwoStop":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.3", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.3", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoBoxStart":
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.2", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.2", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// case "TwoBoxStop":
|
|
// if (input.FuncName == "true")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.3", "true");
|
// }
|
// else if (input.FuncName == "false")
|
// {
|
// modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.3", "false");
|
// }
|
// else
|
// {
|
// throw Oops.Bah("事件结果错误");
|
// }
|
// break;
|
// default:
|
// break;
|
// }
|
// modUtil.Close();
|
//}
|
//else if (input.Layer == "3")
|
//{
|
// modPlc = plcList.FirstOrDefault(m => m.Text == "3层托盘输送线");
|
// if (modPlc == null)
|
// throw Oops.Bah($"未查询到3楼层PLC信息");
|
// DbNum = "";
|
//}
|
//else
|
//{
|
// throw Oops.Bah("操作类型信息错误");
|
//}
|
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 分页查询设备信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Page")]
|
[DisplayName("分页查询设备信息")]
|
public async Task<SqlSugarPagedList<WcsDeviceOutput>> Page(PageWcsDeviceInput input)
|
{
|
if (input.Field.IsNullOrEmpty())
|
{
|
input.Field = "u.Id";
|
input.Order = "desc";
|
}
|
input.SearchKey = input.SearchKey?.Trim();
|
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)
|
.Select((u, plcid) => new WcsDeviceOutput
|
{
|
Id = u.Id,
|
PlcId = u.PlcId,
|
DeviceType = (DeviceTypeEnum)u.DeviceType,
|
PlcIdIP = plcid.IP,
|
Level = (DeviceLevelEnum)u.Level,
|
DbNumber = u.DbNumber,
|
StationNum = u.StationNum,
|
PlcPos = u.PlcPos,
|
WcsPos = u.WcsPos,
|
PosType = u.PosType,
|
LedIP = u.LedIP,
|
Text = u.Text,
|
CreateTime = u.CreateTime,
|
UpdateTime = u.UpdateTime,
|
CreateUserId = u.CreateUserId,
|
CreateUserName = u.CreateUserName,
|
UpdateUserId = u.UpdateUserId,
|
UpdateUserName = u.UpdateUserName,
|
CreateOrgId = u.CreateOrgId,
|
CreateOrgName = u.CreateOrgName,
|
IsDelete = u.IsDelete,
|
});
|
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
}
|
|
/// <summary>
|
/// 增加设备信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Add")]
|
[DisplayName("增加设备信息")]
|
public async Task<long> Add(AddWcsDeviceInput input)
|
{
|
var entity = input.Adapt<WcsDevice>();
|
await _wcsDeviceRep.InsertAsync(entity);
|
return entity.Id;
|
}
|
|
/// <summary>
|
/// 删除设备信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Delete")]
|
[DisplayName("删除设备信息")]
|
public async Task Delete(DeleteWcsDeviceInput input)
|
{
|
var entity = await _wcsDeviceRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
await _wcsDeviceRep.FakeDeleteAsync(entity); //假删除
|
//await _wcsDeviceRep.DeleteAsync(entity); //真删除
|
}
|
|
/// <summary>
|
/// 更新设备信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Update")]
|
[DisplayName("更新设备信息")]
|
public async Task Update(UpdateWcsDeviceInput input)
|
{
|
var entity = input.Adapt<WcsDevice>();
|
await _wcsDeviceRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
}
|
|
/// <summary>
|
/// 获取设备信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "Detail")]
|
[DisplayName("获取设备信息")]
|
public async Task<WcsDevice> Detail([FromQuery] QueryByIdWcsDeviceInput input)
|
{
|
return await _wcsDeviceRep.GetFirstAsync(u => u.Id == input.Id);
|
}
|
|
/// <summary>
|
/// 获取PlcId列表
|
/// </summary>
|
/// <returns></returns>
|
[ApiDescriptionSettings(Name = "WcsPlcPlcIdDropdown"), HttpGet]
|
[DisplayName("获取PlcId列表")]
|
public async Task<dynamic> WcsPlcPlcIdDropdown()
|
{
|
return await _wcsDeviceRep.Context.Queryable<WcsPlc>()
|
.Select(u => new
|
{
|
Label = u.Text,
|
Value = u.Id
|
}
|
).ToListAsync();
|
}
|
|
/// <summary>
|
/// 生成点位
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "GeneratePos")]
|
[DisplayName("生成点位")]
|
public async Task GeneratePos(GeneratePosInput input)
|
{
|
var modDevice = await _wcsDeviceRep.GetByIdAsync(input.Id);
|
|
var listPosition = new List<WcsPosition>();
|
listPosition.Add(new WcsPosition()
|
{
|
DeviceId = modDevice.Id,
|
StationNum = modDevice.StationNum,
|
PlcPos = input.Pos.ToString(),
|
PosType = PLCDataTypeEnum.String,
|
Text = "TaskNo"
|
});
|
listPosition.Add(new WcsPosition()
|
{
|
DeviceId = modDevice.Id,
|
StationNum = modDevice.StationNum,
|
PlcPos = (input.Pos + 4).ToString(),
|
PosType = PLCDataTypeEnum.UShort,
|
Text = "TaskType"
|
});
|
listPosition.Add(new WcsPosition()
|
{
|
DeviceId = modDevice.Id,
|
StationNum = modDevice.StationNum,
|
PlcPos = (input.Pos + 6).ToString(),
|
PosType = PLCDataTypeEnum.UShort,
|
Text = "StartLocatNo"
|
});
|
listPosition.Add(new WcsPosition()
|
{
|
DeviceId = modDevice.Id,
|
StationNum = modDevice.StationNum,
|
PlcPos = (input.Pos + 8).ToString(),
|
PosType = PLCDataTypeEnum.UShort,
|
Text = "EndLocatNo"
|
});
|
|
await _wcsDeviceRep.Context.Insertable(listPosition).ExecuteCommandAsync();
|
}
|
|
/// <summary>
|
/// 获取设备信息列表
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "List")]
|
[DisplayName("获取设备信息列表")]
|
public async Task<List<WcsDeviceOutput>> List([FromQuery] PageWcsDeviceInput input)
|
{
|
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();
|
//获取跺机的状态
|
foreach (var modDevice in list)
|
{
|
if (_sysCacheService.ExistKey("PLCCONN:" + modDevice.PlcId))
|
{
|
var cachePlc = _sysCacheService.Get<WcsPlc>("PLCCONN:" + modDevice.PlcId);
|
modDevice.Status = cachePlc.IsConn;
|
if (modDevice.Status)
|
{
|
//读取plc的值
|
var modConn = PLCTaskAction.listPlcConn.FirstOrDefault(s => s != null && s.PlcId == modDevice.PlcId);
|
if (modConn == null)
|
{
|
continue;
|
}
|
try
|
{
|
var listPosition = await _wcsDeviceRep.Context.Queryable<WcsPosition>().Where(s => s.DeviceId == modDevice.Id).ToListAsync();
|
(var result, var plc) = modConn.GetPlcDBValue(modDevice.PosType, modDevice.DbNumber, modDevice.PlcPos);
|
modDevice.Plc = Convert.ToString(plc);
|
(result, var wcs) = modConn.GetPlcDBValue(modDevice.PosType, modDevice.DbNumber, modDevice.WcsPos);
|
modDevice.Wcs = Convert.ToString(wcs);
|
//任务号
|
var modPositionTask = listPosition.FirstOrDefault(s => s.Text == "任务号");
|
if (modPositionTask != null)
|
{
|
(result, var taskNo) = modConn.GetPlcDBValue(modPositionTask.PosType, modDevice.DbNumber, modPositionTask.PlcPos, modPositionTask.StringLength);
|
modDevice.TaskNo = Convert.ToString(taskNo);
|
}
|
//任务类型
|
var modPositionTaskType = listPosition.FirstOrDefault(s => s.Text == "任务类型");
|
if (modPositionTaskType != null)
|
{
|
(result, var taskType) = modConn.GetPlcDBValue(modPositionTaskType.PosType, modDevice.DbNumber, modPositionTaskType.PlcPos);
|
modDevice.TaskType = (TaskTypeEnum)Convert.ToInt32(taskType);
|
}
|
//起始工位
|
var modPositionStartLocatNo = listPosition.FirstOrDefault(s => s.Text == "起始工位");
|
if (modPositionStartLocatNo != null)
|
{
|
(result, var startLocatNo) = modConn.GetPlcDBValue(modPositionStartLocatNo.PosType, modDevice.DbNumber, modPositionStartLocatNo.PlcPos);
|
modDevice.StartLocatNo = Convert.ToString(startLocatNo);
|
}
|
//目的工位
|
var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "目的工位");
|
if (modPositionEndLocatNo != null)
|
{
|
(result, var endLocatNo) = modConn.GetPlcDBValue(modPositionEndLocatNo.PosType, modDevice.DbNumber, modPositionEndLocatNo.PlcPos);
|
modDevice.EndLocatNo = Convert.ToString(endLocatNo);
|
}
|
//托盘码
|
var modPositionPalletNo = listPosition.FirstOrDefault(s => s.Text == "托盘码");
|
if (modPositionPalletNo != null)
|
{
|
(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 || cachePlc.Type == PLCTypeEnum.StackingMachine)
|
{
|
//放货排
|
var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排");
|
if (modPositionReleaseRow != null)
|
{
|
(result, var releaseRow) = modConn.GetPlcDBValue(modPositionReleaseRow.PosType, modDevice.DbNumber, modPositionReleaseRow.PlcPos);
|
modDevice.ReleaseRow = Convert.ToInt32(releaseRow);
|
}
|
//放货列
|
var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列");
|
if (modPositionReleaseCol != null)
|
{
|
(result, var releaseCol) = modConn.GetPlcDBValue(modPositionReleaseCol.PosType, modDevice.DbNumber, modPositionReleaseCol.PlcPos);
|
modDevice.ReleaseCol = Convert.ToInt32(releaseCol);
|
}
|
//放货层
|
var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层");
|
if (modPositionReleaseStorey != null)
|
{
|
(result, var releaseStorey) = modConn.GetPlcDBValue(modPositionReleaseStorey.PosType, modDevice.DbNumber, modPositionReleaseStorey.PlcPos);
|
modDevice.ReleaseStorey = Convert.ToInt32(releaseStorey);
|
}
|
//取货排
|
var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排");
|
if (modPositionPickRow != null)
|
{
|
(result, var pickRow) = modConn.GetPlcDBValue(modPositionPickRow.PosType, modDevice.DbNumber, modPositionPickRow.PlcPos);
|
modDevice.PickRow = Convert.ToInt32(pickRow);
|
}
|
//取货列
|
var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列");
|
if (modPositionPickCol != null)
|
{
|
(result, var pickCol) = modConn.GetPlcDBValue(modPositionPickCol.PosType, modDevice.DbNumber, modPositionPickCol.PlcPos);
|
modDevice.PickCol = Convert.ToInt32(pickCol);
|
}
|
//取货层
|
var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层");
|
if (modPositionPickStorey != null)
|
{
|
(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)
|
{
|
Console.WriteLine(ex.Message);
|
}
|
}
|
}
|
else
|
{
|
modDevice.Status = false;
|
}
|
|
//modDevice.TaskNo = "TK00001";
|
//modDevice.TaskType = TaskTypeEnum.In;
|
//modDevice.PalletNo = "2024209032";
|
//modDevice.StartLocatNo = "010101";
|
//modDevice.EndLocatNo = "020202";
|
//modDevice.Wcs = new Random().Next(100).ToString();
|
//modDevice.Plc = new Random().Next(100).ToString();
|
//modDevice.Status = true;
|
}
|
|
return list;
|
}
|
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "WriteValue")]
|
[DisplayName("写入值")]
|
public async Task WriteValue(WriteWcsDeviceInput modDevice)
|
{
|
var modPlc = await _wcsDeviceRep.Context.Queryable<WcsPlc>().FirstAsync(s => s.Id == modDevice.PlcId);
|
if (modPlc == null)
|
throw Oops.Bah("找不到PLC信息");
|
var modDbDevice = await _wcsDeviceRep.AsQueryable().FirstAsync(s => s.Id == modDevice.Id);
|
PLCUtil modUtil = new PLCUtil(modPlc);
|
var listPosition = await _wcsDeviceRep.Context.Queryable<WcsPosition>().Where(s => s.DeviceId == modDevice.Id).ToListAsync();
|
var result = new IoTClient.Result();
|
//任务号
|
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);
|
}
|
//任务类型
|
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());
|
}
|
//起始工位
|
if (modDevice.StartLocatNo != null)
|
{
|
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 != null)
|
{
|
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 != null)
|
{
|
var modPositionPalletNo = listPosition.FirstOrDefault(s => s.Text == "托盘码");
|
if (modPositionPalletNo != null)
|
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)
|
{
|
//放货排
|
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());
|
}
|
//取货排
|
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());
|
}
|
}
|
modUtil.Close();
|
}
|
|
#region 分拣码垛
|
/// <summary>
|
/// 获取码垛机器人和拆垛机器人列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "WcsPackPlcList")]
|
[DisplayName("获取码垛机器人和拆垛机器人列表")]
|
public async Task<dynamic> WcsPackPlcList()
|
{
|
return await _wcsDeviceRep.Context.Queryable<WcsPlc>()
|
.Where(w => w.Type == PLCTypeEnum.RobotPalletizer || w.Type == PLCTypeEnum.StackingRobot)
|
.OrderByDescending(o => o.Type)
|
.Select(u => new
|
{
|
id = u.Id,
|
name = u.Text
|
}
|
).ToListAsync();
|
}
|
/// <summary>
|
/// 获取设备对应工位列表
|
/// </summary>
|
/// <param name="entry"></param>
|
/// <returns></returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "WcsPackStationPlcList")]
|
[DisplayName("获取设备对应工位列表")]
|
public async Task<List<WcsDeviceTaskOrderDto>> WcsPackStationPlcList([FromQuery] WcsDeviceBaseInput entry)
|
{
|
//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,
|
TaskNo = task.TaskNo,
|
OrderNo = task.OrderNo,
|
LotNo = task.LotNo,
|
SkuNo = task.SkuNo,
|
SkuName = task.SkuName,
|
LineNo = task.LineNo,
|
Status = task.Status,
|
PZNo = task.PZNo,
|
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
|
}
|