using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core;
using WIDESEA_Model.Models;
using WIDESEAWCS_DTO.WCSInfo;
using WIDESEA_DTO.WCSInfo;
namespace WIDESEA_TaskInfoService
{
public partial class TaskService
{
///
/// 输送线申请入库
///
///
///
public WebResponseContent ConveyorLineRequestInbound(ConveyorLineDTO lineDTO)
{
WebResponseContent content = new WebResponseContent().OK();
try
{
string ConveyorLineID = AppSettings.Configuration[nameof(ConveyorLineID)];
if (!ConveyorLineID.Split(",").Contains(lineDTO.stationCode)) throw new Exception($"未找到输送线编号[{lineDTO.stationCode}]的信息");
content = TransmissionlineRequest(lineDTO);
}
catch (Exception ex)
{
content.Code = 404;
content.Error(ex.Message);
}
return content;
}
///
/// 验证数据
///
/// 起始地址
/// 托盘编号
/// 是否检查组盘信息--区分物料入库和空托入库
/// 组盘信息--可空
/// 返回处理结果
private (bool, string) CheckRequestInbound(string stationCode, string palletCode, bool isCheckStock = true, Dt_StockInfo? stockInfo = null)
{
//if (BaseDal.QueryFirst(x => x.PalletCode == palletCode) != null)
//{
// return (false, "该托盘号已有任务");
//}
//if (BaseDal.QueryFirst(x => (x.SourceAddress == stationCode || x.CurrentAddress == stationCode) && x.TaskStatus == InTaskStatusEnum.AGV_InFinish.ObjToInt()) != null)
//{
// return (false, "当前入库站台已有一条任务");
//}
if (isCheckStock)
{
if (stockInfo == null)
{
return (false, "未找到组盘信息");
}
if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
{
return (false, "该组盘状态不可入库");
}
if (!string.IsNullOrEmpty(stockInfo.LocationCode))
{
return (false, "该托盘已绑定货位");
}
if (stockInfo.Details == null || stockInfo.Details.Count == 0)
{
return (false, "没有库存明细信息");
}
}
else
{
if (_stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == palletCode) != null)
{
return (false, "该托盘已存在库内");
}
}
return (true, "成功");
}
///
/// 输送线申请
///
///
///
public WebResponseContent TransmissionlineRequest(ConveyorLineDTO lineDTO)
{
WebResponseContent content = new WebResponseContent().OK();
try
{
//if (BaseDal.QueryFirst(x => (x.SourceAddress == lineDTO.stationCode || x.CurrentAddress == lineDTO.stationCode) && x.TaskStatus == InTaskStatusEnum.AGV_InFinish.ObjToInt()) != null)
//{
// throw new Exception($"当前入库站台[{lineDTO.stationCode}]已有一条任务");
//}
var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode);
if (task == null) throw new Exception($"未找到托盘号[{lineDTO.Barcode}]的入库任务");
if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) return content;
if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt()) throw new Exception($"未找到托盘号[{lineDTO.Barcode}]的入库任务");
//if (task.TaskState != (int)InTaskStatusEnum.AGV_InFinish) throw new Exception($"托盘号[{lineDTO.Barcode}]的入库任务状态不匹配");
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode);
(bool, string) result = CheckRequestInbound(lineDTO.stationCode, lineDTO.Barcode, true, stockInfo);
if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault();
if (/*lineDTO.Spec != 1 ||*/ lineDTO.Weight > 1500)//检测条件需更改!!!!!!!!!!
{
//task.NextAddress = "101";
task.TaskState = (int)InTaskStatusEnum.InException;
task.Remark = $"托盘[{lineDTO.Barcode}]超重";
//task.Remark = $"托盘[{lineDTO.Barcode}]信息不合格";
//stockInfo.StockStatus = StockStatusEmun.入库撤销.ObjToInt();
}
else
{
task.NextAddress = "1004";
task.CurrentAddress = lineDTO.stationCode;
task.Remark = string.Empty;
task.TaskState = (int)InTaskStatusEnum.Line_InExecuting;
stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
stockInfoDetail.Status = StockStatusEmun.入库确认.ObjToInt();
}
#region 事务
Db.Ado.BeginTran();
BaseDal.UpdateData(task);
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
//Db.Updateable(stockInfo).ExecuteCommand();
Db.Ado.CommitTran();
#endregion
if (!string.IsNullOrEmpty(task.Remark)) throw new Exception(task.Remark);
}
catch (Exception ex)
{
Db.Ado.RollbackTran();
content.Error(ex.Message);
}
return content;
}
}
}