#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEA_TaskInfoService * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using AutoMapper; using SqlSugar; using System.Reflection; using System.Reflection.Emit; 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.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; using WIDESEA_DTO.Task; using WIDESEA_IBasicService; using WIDESEA_IInboundService; using WIDESEA_IOutboundService; using WIDESEA_IRecordService; using WIDESEA_IStockService; using WIDESEA_ITaskInfoService; using WIDESEA_Model.Models; namespace WIDESEA_TaskInfoService { public partial class TaskService : ServiceBase>, ITaskService { private readonly IMapper _mapper; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IStockInfoService _stockInfoService; private readonly IStockInfoDetailService _stockDetailService; private readonly ILocationInfoService _locationInfoService; public string ReceiveWCSTask = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWCSTask"]; public IRepository Repository => BaseDal; private Dictionary _taskOrderBy = new() { {nameof(Dt_Task.Grade),OrderByType.Desc }, {nameof(Dt_Task.CreateDate),OrderByType.Asc}, }; public List TaskTypes => typeof(TaskTypeEnum).GetEnumIndexList(); public List TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList(); public TaskService(IRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockInfoDetailService stockDetailService, ILocationInfoService locationInfoService) : base(BaseDal) { _mapper = mapper; _unitOfWorkManage = unitOfWorkManage; _stockInfoService = stockInfoService; _stockDetailService = stockDetailService; _locationInfoService = locationInfoService; } public int GetTaskNum(string sequenceName) { return Db.Ado.GetScalar($"SELECT NEXT VALUE FOR {sequenceName}").ObjToInt(); } //判断移库任务 public WebResponseContent IsRelocations(int TaskNum) { WebResponseContent content = new WebResponseContent(); List loca = new List(); try { Dt_Task task = BaseDal.QueryData().Where(x => x.TaskNum == TaskNum).FirstOrDefault(); if (task == null) return content.Error($"WMS未找到该任务信息,任务号:{TaskNum}"); string Locaddres = task.TaskType switch { (int)TaskTypeEnum.Outbound => task.SourceAddress, (int)TaskTypeEnum.Inbound => task.TargetAddress, _ => throw new Exception($"任务号:{TaskNum},当前申请的任务类型不对") }; if (string.IsNullOrEmpty(Locaddres)) return content.Error($"任务号:{TaskNum},需要判断的货位编号为空"); Dt_LocationInfo locationInfos = _locationInfoService.GetLocationInfo(task.WarehouseId,Locaddres); if (locationInfos == null) return content.Error($"未找到该货位信息,任务号:{TaskNum},:{Locaddres},巷道号:{task.Roadway} ,仓库编号:{task.WarehouseId}"); if (locationInfos.Depth != (int)LocationDepth.deep) return content.Error($"任务号:{TaskNum},当前货位到的不是深库位,不需要判断是否需要移库,货位编号:{Locaddres},巷道号:{task.Roadway} ,仓库编号:{task.WarehouseId}"); //查找当前浅货位 Dt_LocationInfo Shallowlocation = _locationInfoService.ShallowGetLocation(locationInfos); //传入深库位,获取浅库位 if (Shallowlocation == null) return content.Error($"需要判断移库的任务:{task.TaskNum},未查找到货位编号:{locationInfos.LocationCode}的浅货位"); if (Shallowlocation.EnableStatus == (int)LocationEnableEnum.Disable) return content.Error($"需要判断移库的任务:{task.TaskNum},当前任务的浅货位被禁用,不可进行移库,货位编号:{Shallowlocation.LocationCode}"); //判断浅货位是否有任务 Dt_Task Shalltask = BaseDal.QueryData(x => x.Roadway == Shallowlocation.LocationCode && x.WarehouseId == Shallowlocation.WarehouseId).Where(x => (x.SourceAddress == Shallowlocation.LocationCode || x.TargetAddress == Shallowlocation.LocationCode)).FirstOrDefault(); if(Shalltask!=null) return content.OK(data: Shalltask); //返回浅货位在做的任务 if (Shallowlocation.LocationStatus == (int)LocationStatusEnum.Free) return content.OK(data:task); //返回需要判断的任务,可正常出入库 if (Shallowlocation.LocationStatus != (int)LocationStatusEnum.InStock) return content.Error($"查找到浅库位,货位编号:{Shallowlocation.LocationCode}不是有货状态,不可生成移库任务"); Dt_StockInfo dt_StockInfo = _stockInfoService.Repository.QueryData(x => x.LocationCode == Shallowlocation.LocationCode).Where(x => x.StockStatus == (int)StockStatusEmun.已入库).FirstOrDefault(); if (dt_StockInfo == null) return content.Error($"未找到浅库位的库存信息,货位编号:{Shallowlocation.LocationCode}"); //查找新库位 Dt_LocationInfo NextLocation=_locationInfoService.GetLocation(Shallowlocation.WarehouseId, Shallowlocation.RoadwayNo, Shallowlocation.LocationType); if (NextLocation == null) return content.Error($"仓库id:{Shallowlocation.WarehouseId},巷道号:{Shallowlocation.RoadwayNo},货位类型:{Shallowlocation.LocationType},未查找到新货位,无法进行巷道内移库"); //创建任务 Dt_Task dt_Task = new() { PalletCode = dt_StockInfo.PalletCode, Roadway = locationInfos.RoadwayNo, TaskType = TaskTypeEnum.Relocation.ObjToInt(), TaskStatus = TaskRelocationStatusEnum.RelocationNew.ObjToInt(), SourceAddress = locationInfos.LocationCode, TargetAddress = NextLocation.LocationCode, CurrentAddress = locationInfos.LocationCode, NextAddress = NextLocation.LocationCode, Grade = 2, Creater = "WMS", CreateDate = DateTime.Now, TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), Depth = 0, WarehouseId=Shallowlocation.WarehouseId, }; locationInfos.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); NextLocation.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); loca.Add(NextLocation); loca.Add(locationInfos); _unitOfWorkManage.BeginTran(); _locationInfoService.UpdateData(loca); BaseDal.AddData(dt_Task); _unitOfWorkManage.CommitTran(); return content.OK(data: dt_Task); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content.Error($"任务编号:{TaskNum}调取移库接口出错,错误信息:{ex.Message}"); } } //任务阶段性完成 public WebResponseContent InOutTaskReporting(TaskReportRequest reportRequest) { WebResponseContent content = new WebResponseContent(); try { Dt_Task task = BaseDal.QueryData().Where(x => x.TaskNum == reportRequest.TaskNum).FirstOrDefault(); if (task == null) return content.Error($"WMS未找到该任务信息,任务号:{reportRequest.TaskNum}"); task.TaskStatus = reportRequest.TaskStatus; task.CurrentAddress = reportRequest.CurrentAddress; task.NextAddress = reportRequest.NextAddress; if (task.TaskType == (int)TaskTypeEnum.Outbound && task.TaskStatus==(int)TaskOutStatusEnum.SC_OutFinish) { //堆垛机出库完成后 //查找货位,库存 Dt_StockInfo stockInfo = _stockInfoService.GetStockInfo(task.PalletCode); Dt_StockInfoDetail dt_StockInfodetail = _stockDetailService.Repository.QueryData(x => x.Status == (int)StockStatusEmun.出库锁定).Where(x => x.StockId == stockInfo.Id).FirstOrDefault(); Dt_LocationInfo locationpoint = _locationInfoService.GetLocationInfo(task.WarehouseId, task.SourceAddress); locationpoint.LocationStatus = (int)LocationStatusEnum.Free; _unitOfWorkManage.BeginTran(); BaseDal.UpdateData(task); _locationInfoService.Repository.UpdateData(locationpoint); _stockInfoService.DeleteData(stockInfo); _stockDetailService.DeleteData(dt_StockInfodetail); _stockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成); _stockDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成); _unitOfWorkManage.CommitTran(); //删除库存数据 return content.OK("库存出库成功"); } else if(task.TaskType == (int)TaskTypeEnum.Inbound && task.TaskStatus == (int)TaskInStatusEnum.Line_InFinish) { //获取库位信息 Dt_LocationInfo NextLocation = _locationInfoService.GetLocation(task.WarehouseId, task.Roadway, 10); if (NextLocation == null) return content.Error($"仓库id:{task.WarehouseId},巷道号:1,未查找到新货位,无法进行入库"); task.TargetAddress = NextLocation.LocationCode; task.NextAddress = NextLocation.LocationCode; NextLocation.LocationStatus= (int)LocationStatusEnum.Lock; _unitOfWorkManage.BeginTran(); _locationInfoService.Repository.UpdateData(NextLocation); BaseDal.UpdateData(task); _unitOfWorkManage.CommitTran(); return content.OK(data: NextLocation.LocationCode); } _unitOfWorkManage.BeginTran(); BaseDal.UpdateData(task); _unitOfWorkManage.CommitTran(); return content.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content.Error("任务阶段性完成失败,系统接口原因:" + ex.Message); } } } }