using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Basic;
using WIDESEA_Model.Models;
namespace WIDESEA_TaskInfoService
{
public partial class TaskService
{
///
/// 空托盘出库任务
///
///
///
public async Task PalletOutboundTask(string endStation, string palletCode = "")
{
try
{
Dt_StockInfo stockInfo ;
if (string.IsNullOrEmpty(palletCode))
{
stockInfo = _stockRepository.Db.Queryable().Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt()).First();
}
else
{
stockInfo = _stockRepository.Db.Queryable().Where(x => x.PalletCode == palletCode) .First();
}
if (stockInfo == null)
{
return WebResponseContent.Instance.Error("未找到空托盘库存");
}
Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
if (locationInfo == null)
{
return WebResponseContent.Instance.Error("未找到空托盘库存对应的货位信息");
}
Dt_Task task = new Dt_Task()
{
CurrentAddress = stockInfo.LocationCode,
Grade = 0,
NextAddress = endStation,
PalletCode = stockInfo.PalletCode,
Roadway = locationInfo.RoadwayNo,
SourceAddress = stockInfo.LocationCode,
TargetAddress = endStation,
TaskStatus = TaskStatusEnum.New.ObjToInt(),
TaskType = TaskTypeEnum.OutEmpty.ObjToInt(),
WarehouseId = stockInfo.WarehouseId,
PalletType = stockInfo.PalletType
};
int beforeStatus = locationInfo.LocationStatus;
_unitOfWorkManage.BeginTran();
stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
int taskId = BaseDal.AddData(task);
task.TaskId = taskId;
_stockService.StockInfoService.UpdateData(stockInfo);
_locationInfoService.UpdateData(locationInfo);
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), "", task.TaskNum);
_unitOfWorkManage.CommitTran();
TaskModel esstask = new TaskModel()
{
taskType = "carry",
taskGroupCode = "",
groupPriority = 0,
tasks = new List
{
new()
{
taskCode=task.TaskNum.ToString(),
taskPriority=0,
taskDescribe=new TaskDescribeType{
containerCode=stockInfo.PalletCode,
containerType= "CT_KUBOT_STANDARD",
fromLocationCode=stockInfo.LocationCode??"",
toStationCode="",
toLocationCode=endStation,
deadline=0,storageTag=""
}
}
}
};
_logger.LogInformation("创建任务PalletOutboundTask Request: " + JsonConvert.SerializeObject(esstask));
var result = await _eSSApiService.CreateTaskAsync(esstask);
_logger.LogInformation("创建任务PalletOutboundTask 返回: " + result);
if (result)
{
return WebResponseContent.Instance.OK();
}
else
{
return WebResponseContent.Instance.Error("下发机器人任务失败!");
}
}
catch (Exception ex)
{
return WebResponseContent.Instance.Error(ex.Message);
}
}
}
}