254 lines
9.8 KiB
C#
254 lines
9.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AutoMapper;
|
|
using HHWMS.Web.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using WalkingTec.Mvvm.Core;
|
|
|
|
namespace HHWMS.Web
|
|
{
|
|
/// <summary>
|
|
/// 提供WCS调用接口
|
|
/// 调用方向 WCS --> WMS
|
|
/// </summary>
|
|
[Public]
|
|
[ActionDescription("HHWMS.WCSApi")]
|
|
[ApiController]
|
|
[Route("api/[controller]/[action]"), ApiExplorerSettings(GroupName = "User")]
|
|
public class IWCSController : ApiController
|
|
{
|
|
private readonly IUnitWork _unitWork;
|
|
private readonly IMapper _mapper;
|
|
|
|
public IWCSController(IUnitWork unitWork, IMapper mapper)
|
|
{
|
|
_unitWork = unitWork;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 状态返回
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public IActionResult ReturnStatus(WcsRequest request)
|
|
{
|
|
// 返回状态 只接收100
|
|
if(request.State != 100)
|
|
{
|
|
return ApiResultError(msg:"State 不为100, 请检查后重新请求!");
|
|
}
|
|
|
|
// 判断任务是否合理
|
|
var task = _unitWork.FindSingle<TaskHeader>(x => x.TaskNo.Equals(request.TaskNo));
|
|
if(task == null)
|
|
{
|
|
return ApiResultError(msg: $"任务不存在, 任务号 {request.TaskNo} , 请检查后重新请求!");
|
|
}
|
|
|
|
// 根据任务类型 入/出 处理不同流程
|
|
switch (task.TaskType)
|
|
{
|
|
case TaskTypeEnum.立库入库:
|
|
// 1.更新库存
|
|
_unitWork.BatchUpdate<Inventory>(x => x.ContainerCode.Equals(task.ContainerCode), x => new Inventory
|
|
{
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS",
|
|
TaskStatus = InventoryTaskStatus.无任务
|
|
});
|
|
// 2.更新容器
|
|
_unitWork.BatchUpdate<Container>(x => x.Code.Equals(task.ContainerCode), x => new Container
|
|
{
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS",
|
|
IsLock = ContainerLockEnum.未锁,
|
|
LocationCode = task.ToLocation
|
|
});
|
|
// 3.更新库位
|
|
_unitWork.BatchUpdate<Location>(x => x.Code.Equals(task.ToLocation), x => new Location
|
|
{
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS",
|
|
Status = LocationStatus.空容器,
|
|
ContainerCode = task.ContainerCode
|
|
});
|
|
// 4.插入库存交易
|
|
// 1.将任务容器的库存查出来
|
|
var inventoryList = _unitWork.Find<Inventory>(x => x.ContainerCode.Equals(task.ContainerCode)).ToList();
|
|
if (inventoryList.Count > 0)
|
|
{
|
|
// 2.根据库存生成库存交易出库信息
|
|
var inventoryTransactions = inventoryList.Select(inventory => new InventoryTransaction
|
|
{
|
|
BillType = InventoryTranType.入库,
|
|
MaterialCode = inventory.MaterialCode,
|
|
MaterialName = inventory.MaterialName,
|
|
MaterialUnit = inventory.MaterialUnit,
|
|
Batch = inventory.Batch,
|
|
Lot = inventory.Lot,
|
|
LocationCode = inventory.LocationCode,
|
|
ContainerCode = inventory.ContainerCode,
|
|
Qty = inventory.Qty,
|
|
CreateTime = DateTime.Now,
|
|
CreateBy = "WMS",
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS"
|
|
}).ToList();
|
|
|
|
// 3.批量插入库存交易
|
|
_unitWork.BatchAdd(inventoryTransactions);
|
|
}
|
|
|
|
break;
|
|
case TaskTypeEnum.立库出库:
|
|
|
|
_unitWork.BatchUpdate<Container>(x => x.Code.Equals(task.ContainerCode), x => new Container
|
|
{
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS",
|
|
IsLock = ContainerLockEnum.未锁,
|
|
LocationCode = ""
|
|
});
|
|
_unitWork.BatchUpdate<Location>(x => x.Code.Equals(task.FromLocation), x => new Location
|
|
{
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS",
|
|
Status = LocationStatus.空仓位,
|
|
ContainerCode = ""
|
|
});
|
|
// 1.将任务容器的库存查出来
|
|
var inventoryList2 = _unitWork.Find<Inventory>(x => x.ContainerCode.Equals(task.ContainerCode)).ToList();
|
|
if (inventoryList2.Count > 0)
|
|
{
|
|
// 2.根据库存生成库存交易出库信息
|
|
var inventoryTransactions2 = inventoryList2.Select(inventory => new InventoryTransaction
|
|
{
|
|
BillType = InventoryTranType.出库,
|
|
MaterialCode = inventory.MaterialCode,
|
|
MaterialName = inventory.MaterialName,
|
|
MaterialUnit = inventory.MaterialUnit,
|
|
Batch = inventory.Batch,
|
|
Lot = inventory.Lot,
|
|
LocationCode = inventory.LocationCode,
|
|
ContainerCode = inventory.ContainerCode,
|
|
Qty = inventory.Qty,
|
|
CreateTime = DateTime.Now,
|
|
CreateBy = "WMS",
|
|
UpdateTime = DateTime.Now,
|
|
UpdateBy = "WMS"
|
|
}).ToList();
|
|
|
|
// 3.批量插入库存交易
|
|
_unitWork.BatchAdd(inventoryTransactions2);
|
|
|
|
_unitWork.BatchDelete<Inventory>(x => x.ContainerCode.Equals(task.ContainerCode));
|
|
}
|
|
// 下发AGV到出库口的任务
|
|
// 如果对接 执行下方任务,否则不执行
|
|
var interfaceAgv = _unitWork.FindSingle<SysCount>(x => x.Prefix == "interfaceAGV")?.Value;
|
|
if (interfaceAgv == 1)
|
|
{
|
|
|
|
var postAgv = new
|
|
{
|
|
task_id = "123456"
|
|
};
|
|
|
|
var res = Wtm.CallAPI<dynamic>("ACS", "task_mould_do", HttpMethodEnum.POST, postAgv);
|
|
// if (res.Result.Data.ack == 0)
|
|
// {
|
|
//
|
|
// }
|
|
}
|
|
|
|
break;
|
|
default:
|
|
return ApiResultError(msg:$"任务类型不正确!任务号{request.TaskNo}");
|
|
}
|
|
|
|
task.Status = TaskStatusEnum.完成;
|
|
// 插到历史表,或者接下来流程
|
|
|
|
_unitWork.Add(new TaskHeaderHistory
|
|
{
|
|
TaskNo = task.TaskNo,
|
|
TaskType = task.TaskType,
|
|
FromLocation = task.FromLocation,
|
|
ToLocation = task.ToLocation,
|
|
ContainerCode = task.ContainerCode,
|
|
Status = task.Status,
|
|
CreateTime = DateTime.Now,
|
|
CreateBy = "WMS"
|
|
});
|
|
|
|
_unitWork.Delete(task);
|
|
|
|
return ApiResult();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 满入
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public IActionResult FullIn(WcsRequest request)
|
|
{
|
|
var task = _unitWork.FindSingle<TaskHeader>(x => x.TaskNo.Equals(request.TaskNo));
|
|
if (task == null)
|
|
{
|
|
return ApiResultError(msg: $"任务不存在, 任务号 {request.TaskNo} , 请检查后重新请求!");
|
|
}
|
|
|
|
var location = _unitWork.FindSingle<Location>(x => x.Status == LocationStatus.空仓位);
|
|
if(location == null)
|
|
{
|
|
return ApiResultError(msg: "没有空仓位");
|
|
}
|
|
|
|
task.ToLocation = location.Code;
|
|
_unitWork.Update(task);
|
|
|
|
location.Status = LocationStatus.任务锁;
|
|
_unitWork.Update(location);
|
|
|
|
return ApiResult(new
|
|
{
|
|
locationCode = location.Code
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 空出
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public IActionResult EmptyOut(WcsRequest request)
|
|
{
|
|
var task = _unitWork.FindSingle<TaskHeader>(x => x.TaskNo.Equals(request.TaskNo));
|
|
if(task == null)
|
|
{
|
|
return ApiResultError(msg: $"任务不存在, 任务号 {request.TaskNo} , 请检查后重新请求!");
|
|
}
|
|
|
|
_unitWork.Add(new TaskHeaderHistory
|
|
{
|
|
TaskNo = task.TaskNo,
|
|
TaskType = task.TaskType,
|
|
FromLocation = task.FromLocation,
|
|
ToLocation = task.ToLocation,
|
|
ContainerCode = task.ContainerCode,
|
|
Status = task.Status,
|
|
CreateTime = DateTime.Now,
|
|
CreateBy = "WMS"
|
|
});
|
|
|
|
_unitWork.Delete(task);
|
|
return ApiResult();
|
|
}
|
|
|
|
}
|
|
}
|