using log4net.Core;
|
using Masuit.Tools;
|
using System.Collections.Generic;
|
using WIDESEA_Common;
|
using WIDESEA_Core.Const;
|
using WIDESEA_DTO.WMS;
|
using WIDESEA_StorageBasicRepository;
|
using WIDESEA_StorageTaskRepository;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob.Models;
|
|
namespace WIDESEA_StorageTaskServices;
|
|
public partial class Dt_TaskService : ServiceBase<Dt_Task, IDt_TaskRepository>, IDt_TaskService
|
{
|
#region 请求任务入库
|
/// <summary>
|
/// 请求入库
|
/// </summary>
|
/// <param name="input">请求模型</param>
|
/// <returns>包含任务信息的响应内容</returns>
|
public async Task<WebResponseContent> RequestInTask(RequestTaskDto input)
|
{
|
// 创建一个WebResponseContent对象
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
// 调用BaseDal.QueryFirstAsync方法,查询任务
|
var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode);
|
if (task != null)
|
{
|
{
|
WMSTaskDTO taskDTO = CreateTaskDTO(task);
|
return content.OK(data: taskDTO);
|
}
|
}
|
|
//查询创建的车轮信息
|
var inWheelsInfo = _InWheels_MesRepository.QueryFirst(x => x.Wheels_CurrentStatue == "0");
|
|
//查询创建的制动盘信息
|
//var inBrakeInfo = _InWheels_MesRepository.QueryFirst(x => x.Wheels_CurrentStatue == "0");
|
//if (inBrakeInfo == null) throw new Exception("当前无车轮或制动盘入库信息");
|
|
if (inWheelsInfo == null /*&& inBrakeInfo == null*/) throw new Exception("当前无车轮或制动盘入库信息");
|
|
var newtask = new Dt_Task
|
{
|
CurrentAddress = input.Position,
|
Grade = 1,
|
Roadway = input.Roadways,
|
TargetAddress = input.Roadways,
|
Dispatchertime = DateTime.Now,
|
MaterialNo = "",
|
NextAddress = input.Roadways,
|
OrderNo = null,
|
PalletCode = inWheelsInfo.Wheels_Num,
|
SourceAddress = input.Position,
|
TaskState = (int)TaskInStatusEnum.InNew,
|
TaskType = (int)TaskInboundTypeEnum.InWheels, //inWheelsInfo == null ? (int)TaskInboundTypeEnum.InBrake :
|
TaskNum = await BaseDal.GetTaskNo(),
|
CarType = inWheelsInfo.Wheels_CarType,
|
IsCheck = true,
|
wheels_mttype = inWheelsInfo.Wheels_mttype,
|
wheels_gkcc = inWheelsInfo.Wheels_gkcc,
|
WheelsNewOrOld = inWheelsInfo.Wheels_NewOrOld,
|
Creater = "Systeam"
|
};
|
|
// 尝试添加新任务
|
if (newtask == null) return content.Error();
|
var taskId = await BaseDal.AddDataAsync(newtask);
|
bool isResult = taskId > 0;
|
if (isResult)
|
{
|
// 创建WMS任务
|
WMSTaskDTO taskDTO = new WMSTaskDTO()
|
{
|
TaskNum = newtask.TaskNum.Value,
|
Grade = newtask.Grade.Value,
|
PalletCode = newtask.PalletCode,
|
RoadWay = newtask.Roadway,
|
SourceAddress = newtask.SourceAddress,
|
TargetAddress = newtask.TargetAddress,
|
TaskState = newtask.TaskState.Value,
|
Id = 0,
|
TaskType = newtask.TaskType,
|
wheels_mttype = newtask.wheels_mttype,
|
CarType = newtask.CarType,
|
wheels_gkcc = newtask.wheels_gkcc,
|
WheelsNewOrOld = newtask.WheelsNewOrOld,
|
IsCheck = newtask.IsCheck,
|
WheelsLX = newtask.WheelsLX,
|
};
|
|
inWheelsInfo.Wheels_CurrentStatue = "1";
|
_InWheels_MesRepository.UpdateData(inWheelsInfo);
|
|
content.OK(data: taskDTO);
|
}
|
else
|
content.Error("添加任务失败");
|
return content;
|
}
|
catch (Exception err)
|
{
|
// 如果发生异常,则调用content.Error方法,记录错误信息,并输出错误信息
|
content.Error(err.Message);
|
Console.WriteLine(err.Message);
|
}
|
// 返回content
|
return content;
|
}
|
#endregion 请求任务入库
|
|
#region 库位分配
|
#region 获取货位
|
object objLOCK = new object();
|
/// <summary>
|
/// 双升库位分配
|
/// </summary>
|
/// <param name="requestTask"></param>
|
/// <param name="locationInfos"></param>
|
/// <returns></returns>
|
public DtLocationInfo RequestLocation(RequestTaskDto requestTask, List<DtLocationInfo> locationInfos = null)
|
{
|
lock (objLOCK)
|
{
|
try
|
{
|
//List<DtLocationInfo> locations = new List<DtLocationInfo>();
|
if (locationInfos == null || locationInfos.Count == 0)
|
{
|
locationInfos = _locationRepository.QueryData(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1);
|
}
|
|
var location = GetEmptyLocation(locationInfos);
|
|
if (location != null)
|
{
|
if (location.Depth == 2)
|
{
|
int row = location.Row;
|
int relativeLine = row % 2 == 1 ? row + 1 : row - 1;
|
|
var insideLocation = _locationRepository.QueryFirst(x => x.Row == relativeLine && x.Layer == location.Layer && x.Column == location.Column);
|
|
if (insideLocation.LocationStatus != (int)LocationEnum.Free /*|| insideLocation.EnalbeStatus ==*/ )
|
{
|
locationInfos.Remove(location);
|
if (locationInfos.Count == 0) return null;
|
RequestLocation(requestTask, locationInfos);
|
}
|
}
|
}
|
if (location == null)
|
{
|
return null;
|
}
|
return location;
|
}
|
catch (Exception err)
|
{
|
Console.WriteLine(err.Message.ToString());
|
return null;
|
}
|
}
|
}
|
|
|
private DtLocationInfo GetEmptyLocation(List<DtLocationInfo> dtLocationInfos)
|
{
|
var locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1).OrderBy(x => x.Layer).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ThenBy(x => x.Column).FirstOrDefault();
|
|
return locationinfo;
|
}
|
|
#endregion 获取货位
|
#endregion 库位分配
|
|
|
private async Task UpdateLocationAsync(DtLocationInfo info)
|
{
|
var isStockUpdated = await _locationRepository.UpdateDataAsync(info);
|
if (!isStockUpdated)
|
{
|
throw new Exception("库位信息更新失败");
|
}
|
}
|
|
#region 更新检测任务
|
/// <summary>
|
/// 更新检测任务
|
/// </summary>
|
/// <param name="input">请求参数</param>
|
/// <returns></returns>
|
public async Task<WebResponseContent> UpdateCheckTask(RequestTaskDto input)
|
{
|
// 创建一个WebResponseContent对象
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
// 调用BaseDal.QueryFirstAsync方法,查询任务
|
var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode);
|
if (task == null)
|
{
|
return content.Error($"未知条码{input.PalletCode}任务");
|
}
|
|
task.TaskState = (int)TaskOutStatusEnum.Lien_Check;
|
task.CurrentAddress = input.Position;
|
task.NextAddress = "2021";
|
|
await BaseDal.Update(task);
|
return content.OK("更新成功");
|
}
|
catch (Exception err)
|
{
|
// 如果发生异常,则调用content.Error方法,记录错误信息,并输出错误信息
|
content.Error(err.Message);
|
Console.WriteLine(err.Message);
|
return content;
|
}
|
}
|
#endregion 更新检测任务
|
|
#region 请求车轮流向分配
|
/// <summary>
|
/// 请求车轮流向分配
|
/// </summary>
|
/// <param name="input">请求参数</param>
|
/// <returns></returns>
|
public async Task<WebResponseContent> RequestWheelsFlow(RequestTaskDto input)
|
{
|
// 创建一个WebResponseContent对象
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
var cacheinfo = await _CacheInfoRepository.QueryFirstAsync(x => x.czh == input.PalletCode);
|
|
if (cacheinfo == null) throw new Exception($"未找到{input.PalletCode}车轴缓存位信息");
|
|
return content.OK(data: cacheinfo.targetAddress);
|
}
|
catch (Exception err)
|
{
|
// 如果发生异常,则调用content.Error方法,记录错误信息,并输出错误信息
|
content.Error(err.Message);
|
Console.WriteLine($"车轮流向分配失败:{err.Message}");
|
return content;
|
}
|
}
|
#endregion
|
}
|