库位表重新生成,一些数据使用enum type status
加上数据权限zoneCode
This commit is contained in:
1 parent
b0a6dcc035
commit
b005422b01
25 files changed
+361
-541
No files matched your search
@@ -30,14 +30,12 @@ namespace HHWMS.Web
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IMemoryCache _cache;
|
||||
private const int DEBOUNCE_INTERVAL_MS = 1000; // 防抖间隔1秒
|
||||
private readonly PLCHelper _plcHelper;
|
||||
|
||||
public IWCSController(IUnitWork unitWork, IMapper mapper, IMemoryCache cache, PLCHelper plcHelper)
|
||||
public IWCSController(IUnitWork unitWork, IMapper mapper, IMemoryCache cache)
|
||||
{
|
||||
_unitWork = unitWork;
|
||||
_mapper = mapper;
|
||||
_cache = cache;
|
||||
_plcHelper = plcHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,14 +106,6 @@ namespace HHWMS.Web
|
||||
private async Task ProcessRequestIn(WcsRequest request)
|
||||
{
|
||||
// TODO: 实现具体的入库处理逻辑
|
||||
var t = 0;
|
||||
var plc = new SiemensS7Net( SiemensPLCS.S1200, "10.211.55.4" );
|
||||
var read = await plc.ReadInt32Async( "V2634" );
|
||||
if (read.IsSuccess)
|
||||
{
|
||||
t = read.Content;
|
||||
}
|
||||
var write = await plc.WriteAsync( "V2634", t + 1 );
|
||||
await Task.Delay(1000); // 模拟异步处理
|
||||
}
|
||||
|
||||
@@ -150,19 +140,36 @@ namespace HHWMS.Web
|
||||
var code = vm.GetLocation(request);
|
||||
if (code.Status)
|
||||
{
|
||||
UpdateLocationAndContainer(code.Data.LocationCode, request.PalletNo);
|
||||
return Task.FromResult<IActionResult>(ApiResult(code.Data));
|
||||
var updateResult = UpdateLocationAndContainer(code.Data.LocationCode, request.PalletNo);
|
||||
return Task.FromResult<IActionResult>(updateResult);
|
||||
}
|
||||
return Task.FromResult<IActionResult>(ApiResultError("没有符合条件的可用库位"));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新库位和容器
|
||||
/// </summary>
|
||||
/// <param name="locationCode"></param>
|
||||
/// <param name="palletNo"></param>
|
||||
/// <returns></returns>
|
||||
private IActionResult UpdateLocationAndContainer(string locationCode, string palletNo)
|
||||
{
|
||||
var location = _unitWork.Find<Location>(x => x.Code == locationCode).FirstOrDefault();
|
||||
location.ContainerCode = palletNo;
|
||||
location.Status = LocationStatus.任务锁;
|
||||
_unitWork.Update(location);
|
||||
var resultNum = _unitWork.BatchUpdate<Location>(x => x.Code == locationCode && x.Version == location.Version,
|
||||
x => new Location()
|
||||
{
|
||||
ContainerCode = palletNo,
|
||||
// Status = LocationStatus.任务锁,
|
||||
UpdateTime = DateTime.Now,
|
||||
UpdateBy = "WMS",
|
||||
Version = Guid.NewGuid()
|
||||
});
|
||||
if (resultNum == 0)
|
||||
{
|
||||
//失败
|
||||
return ApiResult(ApiResultError("更新仓位失败!请重新请求!"));
|
||||
}
|
||||
|
||||
var container = _unitWork.Find<Container>(x => x.Code == palletNo).FirstOrDefault();
|
||||
if (container != null)
|
||||
@@ -173,117 +180,5 @@ namespace HHWMS.Web
|
||||
|
||||
return ApiResult(new { LocationCode = location.Code });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC通信测试接口
|
||||
/// </summary>
|
||||
/// <param name="request">通信参数</param>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CommunicateWithPLC(PlcCommunicationRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
return ApiResultError("请求参数不能为空");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 连接PLC
|
||||
if (!_plcHelper.Connect(PlcType.Siemens, request.IpAddress))
|
||||
{
|
||||
return ApiResultError(msg:"PLC连接失败");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 根据操作类型执行不同的读写操作
|
||||
switch (request.OperationType)
|
||||
{
|
||||
case "ReadInt32":
|
||||
var value = _plcHelper.ReadInt32(request.Address);
|
||||
return ApiResult(new { Value = value });
|
||||
|
||||
case "WriteInt16":
|
||||
if (!short.TryParse(request.Value, out short shortValue))
|
||||
{
|
||||
return ApiResultError(msg: "无效的数值");
|
||||
}
|
||||
var writeResult = _plcHelper.WriteInt16(request.Address, shortValue);
|
||||
return ApiResult(new { Success = writeResult });
|
||||
|
||||
case "ReadBool":
|
||||
var boolValue = _plcHelper.ReadBool(request.Address);
|
||||
return ApiResult(new { Value = boolValue });
|
||||
|
||||
case "WriteBool":
|
||||
if (!bool.TryParse(request.Value, out bool boolWriteValue))
|
||||
{
|
||||
return ApiResultError("无效的布尔值");
|
||||
}
|
||||
var boolWriteResult = _plcHelper.WriteBool(request.Address, boolWriteValue);
|
||||
return ApiResult(new { Success = boolWriteResult });
|
||||
|
||||
case "ReadString":
|
||||
if (!ushort.TryParse(request.StringLength, out ushort length))
|
||||
{
|
||||
return ApiResultError("无效的字符串长度");
|
||||
}
|
||||
var stringValue = _plcHelper.ReadString(request.Address, length);
|
||||
return ApiResult(new { Value = stringValue });
|
||||
|
||||
case "WriteString":
|
||||
if (!ushort.TryParse(request.StringLength, out ushort writeLength))
|
||||
{
|
||||
return ApiResultError("无效的字符串长度");
|
||||
}
|
||||
var stringWriteResult = _plcHelper.WriteString(request.Address, request.Value, writeLength);
|
||||
return ApiResult(new { Success = stringWriteResult });
|
||||
|
||||
default:
|
||||
return ApiResultError("不支持的操作类型");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 确保操作完成后断开连接
|
||||
_plcHelper.Disconnect();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ApiResultError($"PLC操作失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC通信请求参数类
|
||||
/// </summary>
|
||||
public class PlcCommunicationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC的IP地址
|
||||
/// </summary>
|
||||
public string IpAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作类型(ReadInt16, WriteInt16, ReadBool, WriteBool, ReadString, WriteString)
|
||||
/// </summary>
|
||||
public string OperationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PLC地址(例如"DB1.0")
|
||||
/// </summary>
|
||||
public string Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 要写入的值(用于写操作)
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字符串长度(用于字符串操作)
|
||||
/// </summary>
|
||||
public string StringLength { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user