using AngleSharp.Io;
|
using Mapster;
|
using Masuit.Tools;
|
using SqlSugar;
|
using System.Net.NetworkInformation;
|
using System.Reflection;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading.Tasks;
|
using WIDESEA_Cache;
|
using WIDESEA_Core.Const;
|
using WIDESEA_DTO.AGV;
|
using WIDESEA_DTO.WMS;
|
using WIDESEA_IServices;
|
using WIDESEA_IStorageSocketRepository;
|
using WIDESEA_IStorageSocketServices;
|
using WIDESEA_IStoragIntegrationServices;
|
using WIDESEA_Model.Models.AGV;
|
using WIDESEA_StorageSocketServices;
|
using WIDESEA_StorageTaskRepository;
|
using WIDESEAWCS_BasicInfoRepository;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEA_StorageTaskServices;
|
|
public partial class Dt_TaskService : ServiceBase<Dt_Task, IDt_TaskRepository>, IDt_TaskService
|
{
|
private readonly LogFactory LogFactory = new LogFactory();
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
private readonly IStockInfoRepository _stockInfoRepository;
|
private readonly IDt_Task_HtyRepository _task_HtyRepository;
|
private readonly IMapper _mapper;
|
private readonly ILocationInfoRepository _locationRepository;
|
|
public Dt_TaskService(IDt_TaskRepository BaseDal,
|
IUnitOfWorkManage unitOfWorkManage,
|
IStockInfoRepository stockInfoRepository,
|
IDt_Task_HtyRepository task_HtyRepository,
|
IMapper mapper,
|
ILocationInfoRepository locationRepository,
|
IStockInfoDetailRepository stockInfoDetailRepository) : base(BaseDal)
|
{
|
_unitOfWorkManage = unitOfWorkManage;
|
_stockInfoRepository = stockInfoRepository;
|
_task_HtyRepository = task_HtyRepository;
|
_mapper = mapper;
|
_locationRepository = locationRepository;
|
}
|
|
|
|
#region 外部接口方法
|
|
public WebResponseContent CompleteInboundTask(Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
locationInf.LocationStatus = (int)LocationEnum.InStock;
|
var stock = new DtStockInfo()
|
{
|
PalletCode = task.PalletCode,
|
LocationCode = task.TargetAddress,
|
CreateDate = DateTime.Now,
|
Creater = "system",
|
LocationId = locationInf.Id,
|
};
|
_stockInfoRepository.AddData(stock);
|
_locationRepository.UpdateData(locationInf);
|
TaskMoveHty(task);
|
_unitOfWorkManage.CommitTran();
|
return content.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return content.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent CompleteOutboundTask(Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
locationInf.LocationStatus = (int)LocationEnum.Free;
|
var stock = _stockInfoRepository.QueryFirst(x=>x.PalletCode == task.PalletCode);
|
|
DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>();
|
stockInfo_Hty.ModifyDate = DateTime.Now;
|
|
AddStockInfoHty(stockInfo_Hty);
|
|
_stockInfoRepository.DeleteData(stock);
|
_locationRepository.UpdateData(locationInf);
|
|
TaskMoveHty(task);
|
|
_unitOfWorkManage.CommitTran();
|
return content.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return content.Error(ex.Message);
|
}
|
}
|
|
public WebResponseContent CompleteRelocationboundTask(Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
|
var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
|
locationInf.LocationStatus = (int)LocationEnum.InStock;
|
location.LocationStatus = (int)LocationEnum.Free;
|
|
var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
|
|
stock.LocationCode = locationInf.LocationCode;
|
stock.LocationId = locationInf.Id;
|
|
|
_stockInfoRepository.UpdateData(stock);
|
_locationRepository.UpdateData(locationInf);
|
_locationRepository.UpdateData(location);
|
TaskMoveHty(task);
|
_unitOfWorkManage.CommitTran();
|
return content.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return content.Error(ex.Message);
|
}
|
}
|
public WebResponseContent TaskMoveHty(Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
var taskHtyNG = CreateHistoricalTask(task);
|
var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0;
|
var isTaskDelete = Delete(task.TaskId);
|
var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum).First();
|
if(AgvTask != null)
|
{
|
SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand();
|
}
|
_unitOfWorkManage.CommitTran();
|
return content.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return content.Error(ex.Message);
|
}
|
}
|
|
#endregion 外部接口方法
|
|
#region private 内部方法
|
|
/// <summary>
|
/// 创建历史任务记录
|
/// </summary>
|
/// <param name="task"></param>
|
/// <returns></returns>
|
public Dt_Task_Hty CreateHistoricalTask(Dt_Task task, bool isHand = false)
|
{
|
task.CurrentAddress = task.NextAddress;
|
|
// 创建历史任务
|
var taskHty = _mapper.Map<Dt_Task_Hty>(task);
|
taskHty.FinishTime = DateTime.Now;
|
taskHty.TaskId = 0;
|
taskHty.OperateType = isHand ? (int)OperateTypeEnum.人工删除 : App.User.UserName != null ? (int)OperateTypeEnum.人工完成 : (int)OperateTypeEnum.自动完成;
|
taskHty.SourceId = task.TaskId;
|
if (isHand)
|
{
|
taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
|
}
|
return taskHty;
|
}
|
/// <summary>
|
/// 删除一个任务
|
/// </summary>
|
/// <param name="id">任务ID</param>
|
/// <returns>是否删除成功</returns>
|
public bool Delete(int id)
|
{
|
return BaseDal.Delete(id);
|
}
|
private void AddStockInfoHty(DtStockInfo_Hty dtStock)
|
{
|
var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommand();
|
if (!isStockAdd)
|
{
|
throw new Exception("库存历史信息添加失败");
|
}
|
}
|
|
#endregion private 内部方法
|
}
|