using WIDESEA_Common.Constants;
|
using WIDESEA_Common.LocationEnum;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Common.WareHouseEnum;
|
using WIDESEA_Core;
|
using WIDESEA_DTO.Task;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_TaskInfoService
|
{
|
public partial class TaskService
|
{
|
#region 出库任务
|
|
/// <summary>
|
/// 根据指定的任务详情异步创建新的出库任务
|
/// </summary>
|
public async Task<WebResponseContent> CreateTaskOutboundAsync(CreateTaskDto taskDto)
|
{
|
try
|
{
|
var stockResult = await _stockInfoService.GetStockInfoAsync(taskDto.WarehouseId);
|
if (stockResult == null || !stockResult.Any())
|
return WebResponseContent.Instance.Error("未找到库存信息");
|
|
var taskList = stockResult.Select(item => new Dt_Task
|
{
|
WarehouseId = item.WarehouseId,
|
PalletCode = item.PalletCode,
|
PalletType = item.PalletType,
|
SourceAddress = item.LocationCode,
|
TargetAddress = taskDto.TargetAddress,
|
Roadway = item.LocationDetails.RoadwayNo,
|
TaskType = TaskTypeEnum.Outbound.GetHashCode(),
|
TaskStatus = TaskStatusEnum.New.GetHashCode(),
|
Grade = 1,
|
TaskNum = 0,
|
CurrentAddress = item.LocationCode,
|
NextAddress = taskDto.TargetAddress,
|
Creater = "system",
|
}).ToList();
|
|
var result = await BaseDal.AddDataAsync(taskList) > 0;
|
var wmstaskDto = result ? _mapper.Map<WMSTaskDTO>(taskList) : null;
|
return WebResponseContent.Instance.OK(result ? "任务创建成功" : "任务创建失败", wmstaskDto ?? new object());
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error($"任务创建失败: {ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 出库任务完成 :修改库存,修改货位状态,删除任务数据,添加历史任务数据
|
/// </summary>
|
public async Task<WebResponseContent> OutboundFinishTaskAsync(CreateTaskDto taskDto)
|
{
|
try
|
{
|
var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
|
if (task == null) return WebResponseContent.Instance.Error("未找到对应的任务");
|
|
var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.SourceAddress);
|
if (location == null) return WebResponseContent.Instance.Error("未找到对应的货位");
|
|
var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
|
if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息");
|
|
// 判断是不是极卷库任务
|
if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1)
|
{
|
OutTaskCompleteDto outTaskCompleteDto = new OutTaskCompleteDto()
|
{
|
TaskId = task.OrderNo ?? string.Empty,
|
DevId = task.TargetAddress ?? string.Empty,
|
ReqTime = DateTime.Now.ToString()
|
};
|
return await OutTaskComplete(outTaskCompleteDto);
|
}
|
|
WebResponseContent content = new WebResponseContent();
|
return await _unitOfWorkManage.BeginTranAsync(async () =>
|
{
|
stockInfo.LocationId = 0;
|
stockInfo.LocationCode = string.Empty;
|
stockInfo.OutboundDate = DateTime.Now;
|
|
location.LocationStatus = LocationStatusEnum.Free.GetHashCode();
|
|
var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
|
var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
|
if (!updateLocationResult || !updateStockResult)
|
return WebResponseContent.Instance.Error("任务完成失败");
|
|
// 高温2号出库到CWSC1时,自动创建入库任务到常温1号巷道
|
WMSTaskDTO? inboundTaskDto = null;
|
if (task.TargetAddress == TaskAddressConstants.GW2_ADDRESS)
|
{
|
var inboundTask = new Dt_Task
|
{
|
TaskNum = await BaseDal.GetTaskNo(),
|
PalletCode = task.PalletCode,
|
PalletType = task.PalletType,
|
Roadway = "CW1",
|
TaskType = TaskInboundTypeEnum.Inbound.GetHashCode(),
|
TaskStatus = TaskInStatusEnum.InNew.GetHashCode(),
|
SourceAddress = task.TargetAddress,
|
TargetAddress = task.TargetAddress,
|
CurrentAddress = task.TargetAddress,
|
NextAddress = task.TargetAddress,
|
WarehouseId = (int)WarehouseEnum.CW1,
|
Grade = 1,
|
Creater = "system_auto"
|
};
|
await Repository.AddDataAsync(inboundTask);
|
inboundTaskDto = _mapper.Map<WMSTaskDTO>(inboundTask);
|
}
|
|
var completeResult = await CompleteTaskAsync(task, "出库完成");
|
if (!completeResult.Status)
|
return completeResult;
|
|
// 返回入库任务信息(如果有)
|
if (inboundTaskDto != null)
|
{
|
return content.OK("出库完成,已创建入库任务", inboundTaskDto);
|
}
|
return content.OK("出库完成");
|
});
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error($"完成任务失败: {ex.Message}");
|
}
|
}
|
|
#endregion 出库任务
|
}
|
}
|