上传版本
This commit is contained in:
parent
b78f8886eb
commit
dc3ec1d9e2
|
|
@ -25,7 +25,7 @@ public class WmsTaskController(WmsTaskService wmsTaskService) : ControllerBase
|
|||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("setStackerTask")]
|
||||
public WmsApiResponse GetStackerTask([FromBody] List<GetStackerRequest> request)
|
||||
public WmsApiResponse<List<GetStackerRequest>> GetStackerTask([FromBody] List<GetStackerRequest> request)
|
||||
{
|
||||
return _wmsTaskService.GetStackerTask(request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using WcsMain.DataBase.Dao;
|
|||
using WcsMain.DataBase.TableEntity;
|
||||
using WcsMain.Enum.Stacker;
|
||||
using WcsMain.ExtendMethod;
|
||||
using WcsMain.Plugins;
|
||||
using WcsMain.StaticData;
|
||||
using WcsMain.WcsAttribute.AutoFacAttribute;
|
||||
|
||||
|
|
@ -29,20 +30,51 @@ public class WmsTaskService(WmsTaskAction wmsTaskAction, AppWmsTaskDao wmsTaskDa
|
|||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public WmsApiResponse GetStackerTask(List<GetStackerRequest> request)
|
||||
public WmsApiResponse<List<GetStackerRequest>> GetStackerTask(List<GetStackerRequest> request)
|
||||
{
|
||||
if (request.Count < 1) return WmsApiResponseFactory.RequestErr("请求的任务数量为 0");
|
||||
if (request.Count < 1) return WmsApiResponseFactory.RequestErr<List<GetStackerRequest>>(null, "请求的任务数量为 0");
|
||||
List<GetStackerRequest> errRequest = []; // 存放错误的请求
|
||||
/* 插入库存信息 */ // ---- 库存由WMS管理,数据库表也无需操作
|
||||
List<AppWmsTask> wmsTasks = [];
|
||||
foreach (var taskData in request)
|
||||
{
|
||||
/* 检验传入的数据格式 */
|
||||
bool checkData = CheckData.CheckDataRules(taskData);
|
||||
if (!checkData) return WmsApiResponseFactory.RequestErr("请求的任务数据部分存在格式问题,请检查数据格式");
|
||||
if (!checkData)
|
||||
{
|
||||
var errorRequest = ObjectCopy.CopyProperties<GetStackerRequest, GetStackerRequest>(taskData);
|
||||
errRequest.Add(errorRequest);
|
||||
}
|
||||
/* 检验起点和终点是否正常 */
|
||||
if(taskData.TaskType == (int)WmsTaskTypeEnum.moveTask)
|
||||
{
|
||||
var existOringin = CommonData.AppLocations.ExistWmsLocation(taskData.Origin);
|
||||
var existDestination = CommonData.AppLocations.ExistWmsLocation(taskData.Destination);
|
||||
if(!existOringin || !existDestination) return WmsApiResponseFactory.RequestErr($"任务号:{taskData.TaskId} 的起点或者终点不正确");
|
||||
if (!existOringin || !existDestination)
|
||||
{
|
||||
var errorRequest = ObjectCopy.CopyProperties<GetStackerRequest, GetStackerRequest>(taskData);
|
||||
errRequest.Add(errorRequest);
|
||||
}
|
||||
}
|
||||
else if(taskData.TaskType == (int)WmsTaskTypeEnum.inTask)
|
||||
{
|
||||
var existDestination = CommonData.AppLocations.ExistWmsLocation(taskData.Destination);
|
||||
if (!existDestination)
|
||||
{
|
||||
var errorRequest = ObjectCopy.CopyProperties<GetStackerRequest, GetStackerRequest>(taskData);
|
||||
errRequest.Add(errorRequest);
|
||||
}
|
||||
}
|
||||
else if(taskData.TaskType == (int)WmsTaskTypeEnum.outTask)
|
||||
{
|
||||
var existOringin = CommonData.AppLocations.ExistWmsLocation(taskData.Origin);
|
||||
if (!existOringin)
|
||||
{
|
||||
var errorRequest = ObjectCopy.CopyProperties<GetStackerRequest, GetStackerRequest>(taskData);
|
||||
errRequest.Add(errorRequest);
|
||||
}
|
||||
}
|
||||
|
||||
/* 构造任务 */
|
||||
wmsTasks.Add(new AppWmsTask()
|
||||
{
|
||||
|
|
@ -61,27 +93,38 @@ public class WmsTaskService(WmsTaskAction wmsTaskAction, AppWmsTaskDao wmsTaskDa
|
|||
CreatePerson = StaticString.WMS,
|
||||
});
|
||||
}
|
||||
if(errRequest.Count > 0) // 如果有错误请求,则返回错误请求
|
||||
{
|
||||
return WmsApiResponseFactory.RequestErr(errRequest, "请求的任务数据存在异常");
|
||||
}
|
||||
List<string?> taskIds = []; // 存放任务号
|
||||
foreach (var checkEntity in wmsTasks)
|
||||
{
|
||||
/* 检查任务号是否重复 */
|
||||
List<AppWmsTask>? checkSame = _wmsTaskDao.Select(new AppWmsTask() { TaskId = checkEntity.TaskId });
|
||||
if (checkSame == default) return WmsApiResponseFactory.DataBaseErr();
|
||||
if (checkSame == default) return WmsApiResponseFactory.DataBaseErr(errRequest);
|
||||
if (checkSame.Count > 0 || taskIds.Exists(e => e == checkEntity.TaskId))
|
||||
{
|
||||
return WmsApiResponseFactory.RequestErr($"任务:{checkEntity.TaskId} 已存在,请勿重复");
|
||||
return WmsApiResponseFactory.RequestErr(errRequest, $"任务:{checkEntity.TaskId} 已存在,请勿重复");
|
||||
}
|
||||
taskIds.Add(checkEntity.TaskId);
|
||||
}
|
||||
/* 插入任务数据 */
|
||||
//int insertRows = _wmsTaskDao.Insert(wmsTasks.ToArray()); // ---- 直接插入任务数据
|
||||
int insertRows = _wmsTaskDao.InsertTaskAndMarkErr([.. wmsTasks]); // ---- 先清除这个料箱之前未作的任务,然后插入新数据
|
||||
if (insertRows > 0) return WmsApiResponseFactory.Success($"任务创建成功,任务号:{string.Join(',', taskIds)}");
|
||||
return WmsApiResponseFactory.Fail("数据插入失败,请稍后重试或者联系我们");
|
||||
if (insertRows > 0) return WmsApiResponseFactory.Success(errRequest, $"任务创建成功,任务号:{string.Join(',', taskIds)}");
|
||||
return WmsApiResponseFactory.Fail(errRequest, "数据插入失败,请稍后重试或者联系我们");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新任务状态
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ public class Pick1StandOutC3(ConveyOperation conveyOperation, DataBaseData dataB
|
|||
return;
|
||||
}
|
||||
/* 判断拣选任务中有没有 1 号台的任务,若有则给一号路向 */
|
||||
|
||||
var pickStand1Task = conveyTasks.Find(f => f.Location == "P1");
|
||||
if(pickStand1Task == default) // 不存在 1 号台任务
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,163 @@
|
|||
using WcsMain.Business.Convey.HistoryDataHandler.HisGetData.I;
|
||||
using WcsMain.Common;
|
||||
using WcsMain.DataBase.Dao;
|
||||
using WcsMain.DataBase.TableEntity;
|
||||
using WcsMain.DataService;
|
||||
using WcsMain.Enum.Convey;
|
||||
using WcsMain.EquipOperation.Convey;
|
||||
using WcsMain.EquipOperation.Entity;
|
||||
using WcsMain.ExtendMethod;
|
||||
|
||||
namespace WcsMain.Business.Convey.HistoryDataHandler.HisGetData;
|
||||
|
||||
/// <summary>
|
||||
/// 拣选 2 区出口扫码
|
||||
/// </summary>
|
||||
/// <param name="conveyOperation"></param>
|
||||
/// <param name="dataBaseData"></param>
|
||||
/// <param name="conveyTaskDao"></param>
|
||||
public class Pick2StandOutC4(ConveyOperation conveyOperation, DataBaseData dataBaseData, AppConveyTaskDao conveyTaskDao) : IBaseGetData
|
||||
{
|
||||
private readonly ConveyOperation _conveyOperation = conveyOperation;
|
||||
private readonly DataBaseData _dataBaseData = dataBaseData;
|
||||
private readonly AppConveyTaskDao _conveyTaskDao = conveyTaskDao;
|
||||
|
||||
/// <summary>
|
||||
/// 扫码失败
|
||||
/// </summary>
|
||||
/// <param name="disPlayName"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="area"></param>
|
||||
/// <param name="routerMethodData"></param>
|
||||
public void ReadFail(string? disPlayName, string msg, string? area, AppRouterMethod routerMethodData)
|
||||
{
|
||||
int plcId = _dataBaseData.GetNewPlcTaskId() ?? StaticData.StaticInt.ErrPlcId;
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go); // 读码失败,大环线继续
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 读码失败,写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 读码失败,写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫码成功
|
||||
/// </summary>
|
||||
/// <param name="disPlayName"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="area"></param>
|
||||
/// <param name="routerMethodData"></param>
|
||||
public void ReadSuccess(string? disPlayName, string msg, string? area, AppRouterMethod routerMethodData)
|
||||
{
|
||||
int plcId = _dataBaseData.GetNewPlcTaskId() ?? StaticData.StaticInt.ErrPlcId; // 获取一个 plcId
|
||||
(string code, string direction) = msg.FormatDir();
|
||||
/* 判断方向是否正确 */
|
||||
string? routerDirection = routerMethodData.AllowDirection;
|
||||
if (!string.IsNullOrEmpty(routerDirection))
|
||||
{
|
||||
string[] dirs = routerDirection.Split(',');
|
||||
if (!dirs.Contains(direction))
|
||||
{
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg} 方向:{direction} 方向不正确,允许的方向为:{routerDirection}");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go);
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* 判断条码有没有拣选任务 */
|
||||
List<AppConveyTask>? conveyTasks = _conveyTaskDao.Query(new AppConveyTask { VehicleNo = code, TaskStatus = (int)ConveyTaskStatusEnum.create });
|
||||
if (conveyTasks == default)
|
||||
{
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg} 查询任务失败,和服务器连接中断");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go); // 连接中断去往拣选区 1
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
if (conveyTasks.Count < 1)
|
||||
{
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg} 无拣选任务");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go);
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
/* 判断有没有 1~5 站台的任务,若有则直行前往 1 区 */
|
||||
List<AppConveyStand> pick1Stand = CommonData.AppConveyStands.FindAll(f => f.StandType == (int)ConveyStandTypeEnum.pick && f.Area == "pick1");
|
||||
List<string?> pick1Stands = pick1Stand.Select(f => f.StandId).ToList();
|
||||
bool exists = false; // 默认不存在 1~5 站台(pick1 区域) 任务
|
||||
foreach (var conveyTask in conveyTasks)
|
||||
{
|
||||
if (pick1Stands.Contains(conveyTask.Location))
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exists) // 存在该区域任务 1~5 站台(pick1 区域)
|
||||
{
|
||||
ConsoleLog.Info($"二区出口:{area} 箱码:{msg} 存在 1~5 站台任务");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go);
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
else // 6~9 站台(pick2 区域)
|
||||
{
|
||||
/* 检查有没有 6 站台的任务 */
|
||||
var pickStand6Task = conveyTasks.Find(f => f.Location == "P6");
|
||||
if (pickStand6Task == default) // 不存在 6 号台任务
|
||||
{
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg} 不存在6号台任务,环线运行");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Move); // 不存在6号台任务
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Info($"二区出口:{area} 箱码:{msg} 存在6号台任务,移栽 6 号站台");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Router_1); // 存在6号台任务
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
ConsoleLog.Success($"二区出口:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||||
return;
|
||||
}
|
||||
ConsoleLog.Warning($"【警告】二区出口:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ public class StackerOutC1(ConveyOperation conveyOperation, DataBaseData dataBase
|
|||
if(exists) // 存在该区域任务 1~5 站台(pick1 区域)
|
||||
{
|
||||
ConsoleLog.Info($"出库分流:{area} 箱码:{msg} 存在 1~5 站台任务");
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go); // 连接中断去往拣选站台
|
||||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go);
|
||||
string errText = _conveyOperation.WriteTask(area, plcTask);
|
||||
if (string.IsNullOrEmpty(errText))
|
||||
{
|
||||
|
|
|
|||
36
WcsMain/Plugins/ObjectCopy.cs
Normal file
36
WcsMain/Plugins/ObjectCopy.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
namespace WcsMain.Plugins;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// object 拷贝
|
||||
/// </summary>
|
||||
public class ObjectCopy
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 将一个类拷贝到另一个类
|
||||
/// </summary>
|
||||
/// <typeparam name="IN"></typeparam>
|
||||
/// <typeparam name="OUT"></typeparam>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static OUT CopyProperties<IN, OUT>(IN input) where OUT : class, new() where IN : class, new()
|
||||
{
|
||||
// 输出
|
||||
OUT newClass = Activator.CreateInstance<OUT>();
|
||||
Type outType = newClass.GetType();
|
||||
var outProperties = outType.GetProperties();
|
||||
if (outProperties == default || outProperties.Length == 0) return newClass;
|
||||
// 输入
|
||||
Type inType = typeof(IN);
|
||||
var inProperties = inType.GetProperties();
|
||||
foreach ( var inProperty in inProperties)
|
||||
{
|
||||
var outPropertie = outProperties.FirstOrDefault(s => s.Name == inProperty.Name);
|
||||
if(outPropertie == default) continue;
|
||||
outPropertie.SetValue(newClass, inProperty.GetValue(input));
|
||||
}
|
||||
return newClass;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user