#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEA_TaskInfoService * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using AutoMapper; using HslCommunication.WebSocket; 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.CommonEnum; using WIDESEA_Common.LocationEnum; 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_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, ITaskService { private readonly IMapper _mapper; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IStockRepository _stockRepository; private readonly IBasicService _basicService; private readonly IRecordService _recordService; public ITaskRepository Repository => BaseDal; public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService) : base(BaseDal) { _mapper = mapper; _unitOfWorkManage = unitOfWorkManage; _stockRepository = stockRepository; _basicService = basicService; _recordService = recordService; } public WebResponseContent RequestInboundTask(string palletCode, string stationCode) { try { Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode); if (task != null) { return WebResponseContent.Instance.Error($"该托盘已生成任务"); } Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode); if (stockInfo == null) { return WebResponseContent.Instance.Error($"未找到组盘信息"); } if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt()) { return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库"); } if (!string.IsNullOrEmpty(stockInfo.LocationCode)) { return WebResponseContent.Instance.Error($"该托盘已绑定货位"); } //todo 通过站台号找巷道号 string roadwayNo = "RSC01"; PalletTypeEnum palletType = PalletTypeEnum.SmallPallet; Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, palletType); if (locationInfo == null) { return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位"); } Dt_Task newTask = new Dt_Task() { CurrentAddress = stationCode, Grade = 0, NextAddress = "", PalletCode = palletCode, Roadway = roadwayNo, SourceAddress = stationCode, TargetAddress = locationInfo.LocationCode, TaskType = TaskTypeEnum.Inbound.ObjToInt(), TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), }; LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt(); _unitOfWorkManage.BeginTran(); int taskId = BaseDal.AddData(newTask); newTask.TaskId = taskId; _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundAssignLocation); _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, palletType, LocationStatusEnum.Lock); _stockRepository.StockInfoRepository.UpdateData(stockInfo); _unitOfWorkManage.CommitTran(); return WebResponseContent.Instance.OK(data: newTask); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return WebResponseContent.Instance.Error(ex.Message); } } public WebResponseContent InboundTaskCompleted(int taskNum) { try { Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); if (task == null) { return WebResponseContent.Instance.Error($"未找到该任务信息"); } if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt()) { return WebResponseContent.Instance.Error($"任务类型错误"); } Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.Details).First(); if (stockInfo == null) { return WebResponseContent.Instance.Error($"未找到托盘对应的组盘信息"); } if (!string.IsNullOrEmpty(stockInfo.LocationCode)) { return WebResponseContent.Instance.Error($"该托盘已绑定货位"); } if (stockInfo.Details == null || stockInfo.Details.Count == 0) { return WebResponseContent.Instance.Error($"未找到该托盘库存明细信息"); } Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); if (locationInfo == null) { return WebResponseContent.Instance.Error($"未找到目标货位信息"); } if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { return WebResponseContent.Instance.Error($"货位状态不正确"); } LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); stockInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt(); stockInfo.LocationCode = locationInfo.LocationCode; _unitOfWorkManage.BeginTran(); BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.人工完成 : OperateTypeEnum.自动完成); _basicService.LocationInfoService.Repository.UpdateData(locationInfo); _stockRepository.StockInfoRepository.UpdateData(stockInfo); _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundCompleted); _unitOfWorkManage.CommitTran(); return WebResponseContent.Instance.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return WebResponseContent.Instance.Error(ex.Message); } } } }