#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEA_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using MailKit.Search;
|
using Microsoft.AspNetCore.SignalR;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Database;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using Org.BouncyCastle.Asn1.Tsp;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Linq;
|
using System.Reflection;
|
using System.Reflection.Metadata;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_BasicRepository;
|
using WIDESEA_Common;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.TaskEnum;
|
using WIDESEA_DTO.Inbound;
|
using WIDESEA_DTO.Stock;
|
using WIDESEA_DTO.Task;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IBasicService;
|
using WIDESEA_IInboundService;
|
using WIDESEA_IOutboundRepository;
|
using WIDESEA_IOutboundService;
|
using WIDESEA_IRecordService;
|
using WIDESEA_IStockRepository;
|
using WIDESEA_IStockService;
|
using WIDESEA_ITaskInfoRepository;
|
using WIDESEA_ITaskInfoService;
|
using WIDESEA_Model.Models;
|
using WIDESEA_StockRepository;
|
using WIDESEA_TaskInfoRepository;
|
using static WIDESEA_ITaskInfoService.ITaskService;
|
|
namespace WIDESEA_TaskInfoService
|
{
|
public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
|
{
|
private readonly IMapper _mapper;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
private readonly IStockRepository _stockRepository;
|
private readonly IBasicService _basicService;
|
private readonly IBasicRepository _basicRepository;
|
private readonly IOutboundService _outboundService;
|
private readonly IInboundService _inboundService;
|
private readonly IInboundOrderDetailService _inboundOrderDetailService;
|
private readonly IRecordService _recordService;
|
private readonly IStockService _stockService;
|
private readonly ITask_HtyService _taskHtyService;
|
private readonly ILocationInfoService _locationInfoService;
|
private readonly ITaskService _taskService;
|
private readonly IMaterielInfoService _materielInfoService;
|
private readonly IInboundOrder_HtyService _inboundOrder_HtyService;
|
private readonly IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService;
|
private readonly IOutboundOrder_HtyService _outboundOrder_HtyService;
|
private readonly IOutboundOrderDetail_HtyService _outboundOrderDetail_HtyService;
|
private readonly IPalletTypeInfoRepository _palletTypeInfoRepository;
|
private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
|
private readonly IStockInfoDetailRepository _stockInfoDetailRepository;
|
public ITaskRepository Repository => BaseDal;
|
|
public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IBasicRepository basicRepository, IStockInfoDetailRepository stockInfoDetailRepository, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal)
|
{
|
_mapper = mapper;
|
_stockRepository = stockRepository;
|
_unitOfWorkManage = unitOfWorkManage;
|
_basicService = basicService;
|
_outboundService = outboundService;
|
_inboundService = inboundService;
|
_recordService = recordService;
|
_stockService = stockService;
|
_taskHtyService = taskHtyService;
|
_locationInfoService = locationInfoService;
|
_inboundOrderDetailService = inboundOrderDetailService;
|
_materielInfoService = materielInfoService;
|
_inboundOrder_HtyService = inboundOrder_HtyService;
|
_inboundOrderDetail_HtyService = inboundOrderDetail_HtyService;
|
_outboundOrder_HtyService = outboundOrder_HtyService;
|
_outboundOrderDetail_HtyService = outboundOrderDetail_HtyService;
|
_outboundOrderDetailRepository = outboundOrderDetailRepository;
|
_basicRepository = basicRepository;
|
_stockInfoDetailRepository = stockInfoDetailRepository;
|
_palletTypeInfoRepository = palletTypeInfoRepository;
|
}
|
|
public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
|
public string ReceiveWMSTaskout = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskout"];
|
public string ReceiveWMSTaskAUT = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAUT"];
|
public string ReceiveWMSTaskAllocatein = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAllocatein"];
|
|
|
/// <summary>
|
/// 任务信息推送至WCS
|
/// </summary>
|
/// <returns></returns>
|
public WebResponseContent PushTasksToWCS(List<Dt_Task> tasks, string agvDescription = "")
|
{
|
try
|
{
|
List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
|
taskDTOs.ForEach(x =>
|
{
|
x.AGVArea = agvDescription;
|
});
|
string url = AppSettings.app("WCS");
|
if (string.IsNullOrEmpty(url))
|
{
|
return WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件");
|
}
|
string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize());
|
|
return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误");
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 放货完成
|
/// </summary>
|
/// <param name="code"></param>
|
/// <returns></returns>
|
public WebResponseContent PutFinish(string code)
|
{
|
try
|
{
|
string url = AppSettings.app("WCS");
|
if (string.IsNullOrEmpty(url))
|
{
|
return WebResponseContent.Instance.Error($"未找到WCSAApi地址,请检查配置文件");
|
}
|
string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish?code=" + code);
|
|
return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误");
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 任务完成
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <returns>返回处理结果</returns>
|
public async Task<WebResponseContent> TaskCompleted(int taskNum)
|
{
|
try
|
{
|
Dt_Task task = await Repository.QueryFirstAsync(x => x.TaskNum == taskNum);
|
if (task == null)
|
{
|
return await Task.FromResult(WebResponseContent.Instance.Error($"未找到任务信息"));
|
}
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
|
{
|
return await Task.FromResult(InboundTaskCompleted(taskNum));
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
|
{
|
return await Task.FromResult(OutboundTaskCompleted(taskNum));
|
}
|
//else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
|
//{
|
// return await Task.FromResult(RelocationTaskCompleted(task));
|
//}
|
else
|
{
|
return await Task.FromResult(WebResponseContent.Instance.Error($"未找到该类型任务,任务类型:{task.TaskType}"));
|
}
|
}
|
catch (Exception ex)
|
{
|
return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
|
}
|
}
|
|
|
|
/// <summary>
|
/// 修改任务状态
|
/// </summary>
|
/// <param name="task"></param>
|
/// <returns></returns>
|
public WebResponseContent UpdateTaskInfo(WCSTaskDTO task)
|
{
|
try
|
{
|
Dt_Task wmsTask = BaseDal.QueryFirst(x => x.TaskNum == task.TaskNum);
|
if (wmsTask != null)
|
{
|
wmsTask.TaskStatus = task.TaskState;
|
wmsTask.CurrentAddress = task.CurrentAddress;
|
wmsTask.NextAddress = task.NextAddress;
|
wmsTask.Dispatchertime = task.Dispatchertime;
|
BaseDal.UpdateData(wmsTask);
|
}
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
|
public WebResponseContent UpdateTaskStatus(int taskNum, int tasktype)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskType == tasktype);
|
if (task == null) return WebResponseContent.Instance.Error("未找到任务信息");
|
if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.InboundGroup)
|
{
|
task.TaskStatus = TaskInStatusEnum.InFinish.ObjToInt();
|
content = UpdateTaskStatusInFinish(task);
|
}
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
return content;
|
}
|
|
public WebResponseContent UpdateTaskStatusInFinish(Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//组盘库存
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//货位
|
var result = CheckCompleted(stockInfo, locationInfo);
|
if (!result.Item1)
|
{
|
throw new Exception(result.Item2);
|
}
|
|
if (stockInfo.StockStatus != StockStatusEmun.入库中.ObjToInt()) throw new Exception($"托盘[{task.PalletCode}],该组盘状态不可入库");
|
Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(x => x.StockId == stockInfo.Id);
|
|
List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.LocationCodesGetStockInfos(new List<string> { stockInfo.LocationCode }).Where(x => x.StockStatus == (int)StockStatusEmun.已入库.ObjToInt()).ToList();
|
if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt())
|
{
|
stockInfo.SerialNumber = stockInfos.Count + 1;
|
stockInfo.InDate = DateTime.Now;
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt();
|
locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
|
task.CurrentAddress = task.NextAddress;
|
task.NextAddress = string.Empty;
|
Db.Ado.BeginTran();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
|
Db.Ado.CommitTran();
|
return content;
|
}
|
#region 入库单
|
Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
|
if (inboundOrder != null || inboundOrder.Details.Count < 1) throw new Exception($"未找到托盘[{task.PalletCode}]的入库单明细信息");
|
Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo && x.MaterielCode == stockInfoDetail.MaterielCode);
|
inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
|
if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
|
{
|
inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
|
}
|
else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt())
|
{
|
inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
|
}
|
stockInfo.SerialNumber = stockInfos.Count + 1;
|
stockInfo.InDate = DateTime.Now;
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt();
|
locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
|
task.CurrentAddress = task.NextAddress;
|
task.NextAddress = string.Empty;
|
Db.Ado.BeginTran();
|
#region 任务和入库单
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
if (inboundOrder.OrderStatus != InboundStatusEnum.入库完成.ObjToInt())
|
{
|
_inboundService.InbounOrderService.Repository.UpdateData(inboundOrder);
|
_inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
|
}
|
else
|
{
|
List<Dt_InboundOrderDetail> orderDetails = inboundOrder.Details;
|
inboundOrder.Details = null;
|
_inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.自动完成);
|
_inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(orderDetails, OperateType.自动完成);
|
}
|
#endregion
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
|
//_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
Db.Ado.CommitTran();
|
#endregion
|
}
|
catch (Exception ex)
|
{
|
Db.Ado.RollbackTran();
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 验证数据
|
/// </summary>
|
/// <param name="stockInfo"></param>
|
/// <param name="locationInfo"></param>
|
/// <returns></returns>
|
private (bool, string) CheckCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true)
|
{
|
if (stockInfo == null)
|
{
|
return (false, "未找到组盘信息");
|
}
|
|
if (locationInfo == null)
|
{
|
return (false, "未找到货位信息");
|
}
|
|
if (isCheckStockDetail && (stockInfo.Details == null || stockInfo.Details.Count == 0))
|
{
|
return (false, "未找到组盘明细信息");
|
}
|
|
return (true, "成功");
|
}
|
|
#region 入库任务完成
|
public WebResponseContent InboundTaskCompleted(int taskNum)
|
{
|
return null;
|
}
|
#endregion
|
|
#region//出库任务完成
|
public WebResponseContent OutboundTaskCompleted(int taskNum)
|
{
|
return null;
|
}
|
#endregion
|
}
|
}
|