#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEA_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using Magicodes.IE.Core;
|
using MailKit.Search;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Net.Http.Headers;
|
using System.Reflection;
|
using System.Reflection.Metadata;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Common.AGVEunm;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.Log;
|
using WIDESEA_DTO.Inbound;
|
using WIDESEA_DTO.Stock;
|
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_TaskInfoRepository;
|
|
namespace WIDESEA_TaskInfoService
|
{
|
public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
|
{
|
private readonly IMapper _mapper;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
|
private readonly IBasicService _basicService;
|
private readonly IOutboundService _outboundService;
|
private readonly IInboundService _inboundService;
|
private readonly IRecordService _recordService;
|
private readonly IStockService _stockService;
|
private readonly ITask_HtyService _taskHtyService;
|
private readonly ILocationInfoService _locationInfoService;
|
|
public ITaskRepository Repository => BaseDal;
|
|
public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService) : base(BaseDal)
|
{
|
_mapper = mapper;
|
_unitOfWorkManage = unitOfWorkManage;
|
_basicService = basicService;
|
_outboundService = outboundService;
|
_inboundService = inboundService;
|
_recordService = recordService;
|
_stockService = stockService;
|
_taskHtyService = taskHtyService;
|
_locationInfoService = locationInfoService;
|
}
|
|
/// <summary>
|
/// 手动任务完成
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <returns>返回处理结果</returns>
|
public WebResponseContent TaskCompleted(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null)
|
{
|
return WebResponseContent.Instance.Error("未找到任务信息");
|
}
|
//_unitOfWorkManage.BeginTran();
|
int TaskStatus = AGVTaskStatusEnum.AGV_Completion.ObjToInt();
|
_taskHtyService.AddTaskHty(task, TaskStatus);
|
HCJFree(task, TaskStatus);
|
BaseDal.DeleteData(task);
|
#region
|
//MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted");
|
//if (methodInfo != null)
|
//{
|
// WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task });
|
// if (responseContent != null)
|
// {
|
// if (App.User.UserId > 0)
|
// {
|
// var response = HttpHelper.Post<WebResponseContent>(url + "StackCraneTaskCompleted?taskNum=" + task.TaskNum, "", "任务完成");
|
// if (!response.Status)
|
// {
|
// _unitOfWorkManage.RollbackTran();
|
// return WebResponseContent.Instance.Error(response.Message);
|
// }
|
// _unitOfWorkManage.CommitTran();
|
// return content = responseContent;
|
// }
|
// _unitOfWorkManage.CommitTran();
|
// return content = responseContent;
|
// }
|
|
//}
|
#endregion
|
return content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
finally
|
{
|
WriteLog.GetLog("任务完成").Write($"操作人:{(App.User.UserId > 0 ? App.User.UserName : "System")}{Environment.NewLine}任务号:{taskNum}{Environment.NewLine}{JsonConvert.SerializeObject(content)}", "任务完成");
|
}
|
}
|
public WebResponseContent TaskCancel(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null)
|
{
|
return content = WebResponseContent.Instance.Error("未找到任务信息");
|
}
|
//_unitOfWorkManage.BeginTran();
|
int TaskStatus = AGVTaskStatusEnum.AGV_ManuallyCancel.ObjToInt();
|
_taskHtyService.AddTaskHty(task, TaskStatus);
|
//HCJFree(task, TaskStatus);
|
BaseDal.DeleteData(task);
|
#region
|
//MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCancel");
|
//if (methodInfo != null)
|
//{
|
// WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task });
|
// if (responseContent != null)
|
// {
|
// if (responseContent != null)
|
// {
|
// if (App.User.UserId > 0)
|
// {
|
// var response = HttpHelper.Post<WebResponseContent>(url + "TaskCancel?taskNum=" + task.TaskNum, "", "任务取消");
|
// if (!response.Status)
|
// {
|
// _unitOfWorkManage.RollbackTran();
|
// return content = WebResponseContent.Instance.Error(response.Message);
|
// }
|
// _unitOfWorkManage.CommitTran();
|
// return content = responseContent;
|
// }
|
// _unitOfWorkManage.CommitTran();
|
// return content = responseContent;
|
// }
|
// }
|
//}
|
#endregion
|
return content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
finally
|
{
|
WriteLog.GetLog("任务取消").Write($"操作人:{(App.User.UserId > 0 ? App.User.UserName : "System")}{Environment.NewLine}任务号:{taskNum}{Environment.NewLine}{JsonConvert.SerializeObject(content)}", "任务取消");
|
}
|
}
|
|
public WebResponseContent UpdateTaskStatus(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null)
|
{
|
return WebResponseContent.Instance.Error("未找到任务信息");
|
}
|
if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
|
{
|
task.TaskStatus = OutTaskStatusEnum.SC_OutExecuting.ObjToInt();
|
}
|
else if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())
|
{
|
task.TaskStatus = InTaskStatusEnum.SC_InExecuting.ObjToInt();
|
}
|
else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt())
|
{
|
task.TaskStatus = InTaskStatusEnum.RelocationExecuting.ObjToInt();
|
}
|
else
|
{
|
throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】");
|
}
|
_unitOfWorkManage.BeginTran();
|
task.Dispatchertime = DateTime.Now;
|
task.ModifyDate = DateTime.Now;
|
task.Modifier = App.User.UserId > 0 ? App.User.UserName : "System";
|
BaseDal.UpdateData(task);
|
_unitOfWorkManage.CommitTran();
|
return content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
public WebResponseContent InboundTaskCompleted(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
decimal beforeQuantity = 0;
|
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
stockInfo.LocationCode = locationInfo.LocationCode;
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
|
beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity);
|
|
int beforeStatus = locationInfo.LocationStatus;
|
locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false);
|
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
|
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, StockChangeType.Inbound, task.TaskNum);
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
|
}
|
|
/// <summary>
|
/// 空托盘入库完成处理
|
/// </summary>
|
/// <param name="task">任务实体对象</param>
|
/// <returns>返回处理结果</returns>
|
public WebResponseContent PalletInboundTaskCompleted(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
|
Dt_StockInfo stockInfo = new Dt_StockInfo()
|
{
|
PalletCode = task.PalletCode,
|
LocationCode = task.TargetAddress,
|
StockStatus = StockStatusEmun.已入库.ObjToInt(),
|
Creater = App.User.UserId > 0 ? App.User.UserName : "System",
|
CreateDate = DateTime.Now,
|
};
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
_stockService.StockInfoService.Repository.AddData(stockInfo);
|
|
int beforeStatus = locationInfo.LocationStatus;
|
locationInfo.LocationStatus = StatusEnum.Pallet.ObjToInt();
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false);
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
|
task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
/// <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, "成功");
|
}
|
|
public WebResponseContent OutboundTaskCompleted(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
decimal beforeQuantity = 0;
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
stockInfo.LocationCode = locationInfo.LocationCode;
|
stockInfo.StockStatus = StockStatusEmun.出库完成.ObjToInt();
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
int beforeStatus = locationInfo.LocationStatus;
|
if (locationInfo.Depth == 2)
|
{
|
if (DepthTask(locationInfo) == false)
|
{
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false);
|
|
}
|
}
|
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
|
task.TaskStatus = OutTaskStatusEnum.OutFinish.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
_stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
_stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) - beforeQuantity, StockChangeType.Outbound, task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return OnOutboundTaskCompleted?.Invoke(task) ?? WebResponseContent.Instance.OK();
|
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent PalletOutboundTaskCompleted(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
int beforeStatus = locationInfo.LocationStatus;
|
|
if (locationInfo.Depth == 2)
|
{
|
if (DepthTask(locationInfo) == false)
|
{
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false);
|
}
|
}
|
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
|
task.TaskStatus = OutTaskStatusEnum.OutFinish.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
_stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent RelocationTaskCompleted(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
Dt_LocationInfo locationStart = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
|
CheckCompleted(stockInfo, locationEnd);
|
|
stockInfo.LocationCode = locationEnd.LocationCode;
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
|
if (locationStart.Depth == 1)
|
{
|
if (DepthTask(locationStart) == false)
|
{
|
locationStart.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.LocationInfoService.RelocationFree(locationEnd, task.TaskNum);
|
_basicService.LocationInfoService.Repository.UpdateData(locationStart);
|
}
|
else
|
{
|
locationStart.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.LocationInfoService.Repository.UpdateData(locationStart);
|
}
|
}
|
|
_basicService.LocationInfoService.RelocationFree(locationEnd, task.TaskNum);
|
|
task.TaskStatus = InTaskStatusEnum.RelocationFinish.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent InboundTaskCancel(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
decimal beforeQuantity = 0;
|
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
|
beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity);
|
|
int beforeStatus = locationInfo.LocationStatus;
|
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
if (locationInfo.Depth == 2)
|
{
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false);
|
}
|
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
task.TaskStatus = InTaskStatusEnum.InCancel.ObjToInt();
|
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
|
}
|
|
public WebResponseContent PalletInboundTaskCancel(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
|
int beforeStatus = locationInfo.LocationStatus;
|
|
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
if (locationInfo.Depth == 2)
|
{
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false);
|
}
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
|
task.TaskStatus = InTaskStatusEnum.InCancel.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
|
public WebResponseContent OutboundTaskCancel(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
decimal beforeQuantity = 0;
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id);
|
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
stockInfo.LocationCode = locationInfo.LocationCode;
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
stockInfoDetail.OutboundQuantity = beforeQuantity;
|
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
|
int beforeStatus = locationInfo.LocationStatus;
|
|
if (locationInfo.Depth == 2)
|
{
|
if (DepthTask(locationInfo) == false)
|
{
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), true);
|
}
|
}
|
locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
|
|
task.TaskStatus = OutTaskStatusEnum.OutCancel.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) - beforeQuantity, StockChangeType.Outbound, task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent PalletOutboundTaskCancel(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
|
CheckCompleted(stockInfo, locationInfo);
|
|
int beforeStatus = locationInfo.LocationStatus;
|
|
if (locationInfo.Depth == 2)
|
{
|
if (DepthTask(locationInfo) == false)
|
{
|
_basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), true);
|
}
|
}
|
locationInfo.LocationStatus = StatusEnum.Pallet.ObjToInt();
|
_basicService.LocationInfoService.Repository.UpdateData(locationInfo);
|
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
|
task.TaskStatus = OutTaskStatusEnum.OutCancel.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent RelocationTaskCancel(Dt_Task task)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
|
|
Dt_LocationInfo locationEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
Dt_LocationInfo locationStart = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
|
stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
|
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
|
|
locationEnd.LocationStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.LocationInfoService.RelocationFree(locationStart, task.TaskNum);
|
_basicService.LocationInfoService.Repository.UpdateData(locationEnd);
|
|
task.TaskStatus = InTaskStatusEnum.RelocationCancel.ObjToInt();
|
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
|
|
_unitOfWorkManage.CommitTran();
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
public bool DepthTask(Dt_LocationInfo location)
|
{
|
if (location != null)
|
{
|
Dt_LocationInfo locations = _locationInfoService.Repository.QueryFirst(x => x.RoadwayNo == location.RoadwayNo && x.Column == location.Column && x.Layer == location.Layer && x.Depth != location.Depth && x.Row != location.Row && (SqlFunc.Abs(x.Row - location.Row) == 1));
|
if (locations != null)
|
{
|
Dt_Task tasks = BaseDal.QueryFirst(x => x.SourceAddress == locations.LocationCode);
|
return tasks != null ? true : false;
|
}
|
}
|
return false;
|
}
|
public WebResponseContent GetTaskInfo()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Expression<Func<Dt_Task, bool>> expression = x => true;
|
if (!App.User.IsSuperAdmin)
|
{
|
expression = x => x.Creater == App.User.UserName;
|
}
|
var task = BaseDal.Db.Queryable<Dt_Task>().OrderByDescending(x => x.CreateDate).Take(10).Select(x => new Dt_Task { TaskNum = x.TaskNum, PalletCode = x.PalletCode, TaskType = x.TaskType, SourceAddress = x.SourceAddress, TargetAddress = x.TargetAddress }).ToList();
|
content = WebResponseContent.Instance.OK(data: task);
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
/// <summary>
|
/// 原材料库大屏任务显示
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent GetAGVTaskData(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
string type = saveModel.MainData["AGVName"].ToString();
|
List<Dt_Task> agvtask = new List<Dt_Task>();
|
agvtask = BaseDal.QueryData(x => x.TaskStatus == AGVTaskStatusEnum.AGV_Query.ObjToInt()).ToList();
|
if (agvtask.Count <= 0) return content.Error("未找到任务");
|
foreach (var item in agvtask)
|
{
|
item.Remark = item.TaskStatus == AGVTaskStatusEnum.AGV_New.ObjToInt() ? "新建" : item.TaskStatus == AGVTaskStatusEnum.AGV_Query.ObjToInt() ? "队列中" : item.TaskStatus == AGVTaskStatusEnum.AGV_Executing.ObjToInt() ? "执行中" : item.TaskStatus == AGVTaskStatusEnum.AGV_SendOut.ObjToInt() ? "已下发" : "";
|
}
|
return content.OK(data: agvtask);
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
}
|
/// <summary>
|
/// 成品库大屏任务显示
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent GetAGVTaskDataCP(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
string type = saveModel.MainData["AGVName"].ToString();
|
List<Dt_Task> agvtask = new List<Dt_Task>();
|
agvtask = BaseDal.QueryData(x => x.TaskType == TaskTypeEnum.Inbound.ObjToInt()).ToList();
|
if (agvtask.Count <= 0) return content.Error("未找到任务");
|
foreach (var item in agvtask)
|
{
|
item.Remark = item.TaskStatus == AGVTaskStatusEnum.AGV_New.ObjToInt() ? "新建" : item.TaskStatus == AGVTaskStatusEnum.AGV_Query.ObjToInt() ? "队列中" : item.TaskStatus == AGVTaskStatusEnum.AGV_Executing.ObjToInt() ? "执行中" : item.TaskStatus == AGVTaskStatusEnum.AGV_SendOut.ObjToInt() ? "已下发" : "";
|
}
|
return content.OK(data: agvtask);
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
}
|
|
public WebResponseContent HCJLock(Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
Dt_CachePoint source = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.SourceAddress);
|
Dt_CachePoint target = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.TargetAddress);
|
if (target != null && source != null)
|
{
|
source.PointStatus = LocationStatusEnum.Lock.ObjToInt();
|
_basicService.CachePointService.Repository.UpdateData(source);
|
target.PointStatus = LocationStatusEnum.Lock.ObjToInt();
|
_basicService.CachePointService.Repository.UpdateData(target);
|
}
|
return content;
|
}
|
|
public WebResponseContent HCJFree(Dt_Task task, int TaskStatus)
|
{
|
WebResponseContent content = new WebResponseContent();
|
Dt_CachePoint source = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.SourceAddress);
|
Dt_CachePoint target = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.TargetAddress);
|
var toaddress = JsonConvert.SerializeObject(target);
|
if (target != null && source != null)
|
{
|
if (toaddress.Contains("成品库"))
|
{
|
source.PointStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.CachePointService.Repository.UpdateData(source);
|
target.PointStatus = LocationStatusEnum.InStock.ObjToInt();
|
_basicService.CachePointService.Repository.UpdateData(target);
|
}
|
else
|
{
|
source.PointStatus = LocationStatusEnum.Free.ObjToInt();
|
_basicService.CachePointService.Repository.UpdateData(source);
|
//target.PointStatus = LocationStatusEnum.Free.ObjToInt();
|
//_basicService.CachePointService.Repository.UpdateData(target);
|
}
|
}
|
return content;
|
}
|
public WebResponseContent CacheStatus(SaveModel saveModel)
|
{
|
WebResponseContent response = new WebResponseContent();
|
List<object> list = new List<object>();
|
try
|
{
|
List<Dt_CachePoint> cachePoints = _basicService.CachePointService.Repository.QueryData(x => x.PointCode.Contains("成品库")).ToList();
|
foreach (var cachePoint in cachePoints)
|
{
|
bool isState = (cachePoint.PointStatus == LocationStatusEnum.Free.ObjToInt());
|
string stateName = "";
|
switch (cachePoint.PointStatus)
|
{
|
case 0:
|
stateName = "空闲";
|
break;
|
case 1:
|
stateName = "锁定";
|
break;
|
case 2:
|
stateName = "有货";
|
break;
|
default:
|
break;
|
}
|
list.Add(new { name = cachePoint.Depth, state = isState, statename = stateName });
|
}
|
|
response.OK(data: new { list });
|
}
|
catch (Exception ex)
|
{
|
response.Error(ex.Message);
|
}
|
return response;
|
}
|
public WebResponseContent LEDloctionList()
|
{
|
WebResponseContent content = new WebResponseContent();
|
{
|
//List<areaLocation> areaBucket = new List<areaLocation>();
|
List<areaLocation> areaProduct = new List<areaLocation>();
|
////成品总货位
|
//List<Dt_locationinfo> productCount = locationinfoRepository.Find(x => x.location_areaid != "3" && x.location_areaid != "4");
|
////成品空货位
|
//List<Dt_locationinfo> emptyProductCount = locationinfoRepository.Find(x => x.location_areaid != "3" && x.location_areaid != "4" && x.location_state == LocationState.LocationState_Empty.ToString());
|
////成品有货货位
|
//List<Dt_locationinfo> storedyProductCount = locationinfoRepository.Find(x => x.location_areaid != "3" && x.location_areaid != "4" && x.location_state == LocationState.LocationState_Stored.ToString());
|
////成品锁定货位
|
//List<Dt_locationinfo> lockedProductCount = locationinfoRepository.Find(x => x.location_areaid != "3" && x.location_areaid != "4"
|
//&& x.location_state != LocationState.LocationState_Empty.ToString() && x.location_state != LocationState.LocationState_Stored.ToString());
|
//areaProduct.Add(new areaLocation { name = "空货位", count = emptyProductCount.Count });
|
//areaProduct.Add(new areaLocation { name = "总货位", count = productCount.Count });
|
//areaProduct.Add(new areaLocation { name = "执行货位", count = lockedProductCount.Count });
|
//areaProduct.Add(new areaLocation { name = "有货货位", count = storedyProductCount.Count });
|
//content.OK(data: new { areaBucket, areaProduct });
|
//成品总货位
|
List<Dt_CachePoint> productCount = _basicService.CachePointService.Repository.QueryData(x => x.PointCode.Contains("成品库"));
|
//成品空货位
|
List<Dt_CachePoint> emptyProductCount = _basicService.CachePointService.Repository.QueryData(x => x.PointCode.Contains("成品库") && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
|
//成品有货货位
|
List<Dt_CachePoint> storedyProductCount = _basicService.CachePointService.Repository.QueryData(x => x.PointCode.Contains("成品库") && x.PointStatus == LocationStatusEnum.InStock.ObjToInt());
|
//成品锁定货位
|
List<Dt_CachePoint> lockedProductCount = _basicService.CachePointService.Repository.QueryData(x => x.PointCode.Contains("成品库") && x.PointStatus == LocationStatusEnum.Lock.ObjToInt());
|
areaProduct.Add(new areaLocation { name = "空货位", count = emptyProductCount.Count });
|
areaProduct.Add(new areaLocation { name = "总货位", count = productCount.Count });
|
areaProduct.Add(new areaLocation { name = "执行货位", count = lockedProductCount.Count });
|
areaProduct.Add(new areaLocation { name = "有货货位", count = storedyProductCount.Count });
|
return content.OK(data: new { areaProduct });
|
}
|
}
|
private class areaLocation
|
{
|
public string name { get; set; }
|
public int count { get; set; }
|
}
|
}
|
}
|