刘磊
2024-11-26 a1c804eed3b8d936e6392ce3ca82e9ad65e12094
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,17 +1,9 @@
using log4net.Core;
using Mapster;
using Mapster;
using Masuit.Tools;
using Masuit.Tools.Models;
using System.Linq;
using System.Threading.Tasks;
using WIDESEA_DTO.MOM;
using WIDESEA_DTO.WMS;
using WIDESEA_IStorageBasicRepository;
using WIDESEA_IStoragIntegrationServices;
using WIDESEA_Model.Models;
using WIDESEA_StorageBasicRepository;
using WIDESEA_StorageTaskRepository;
using WIDESEA_StoragIntegrationServices;
using WIDESEAWCS_BasicInfoRepository;
namespace WIDESEA_StorageOutTaskServices;
@@ -119,7 +111,8 @@
                await UpdateLocationAsync(loc);
                await DeleteStockInfoAsync(stock.Id);
                await DeleteStockInfoDetailsAsync(stock.StockInfoDetails);
                //await DeleteTaskAsync(task.TaskId);
                if (task.Roadway.Contains("FR"))   //如果是分容 将任务删除
                    await DeleteTaskAsync(task.TaskId);
            });
            return content.OK("任务完成成功");
@@ -183,7 +176,7 @@
    private (DtLocationInfo, Dt_Task) UpdateStockAndTaskStatus(DtStockInfo stock, Dt_Task task)
    {
        var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
        var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway);
        //var details = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id);
        location.LocationStatus = (int)LocationEnum.Free;
@@ -314,8 +307,9 @@
            // 根据是否有组盘信息创建库存实例模型
            DtStockInfo stock = boxing == null ? CreateEmptyPalletStock(task, locationInf) : CreateFullPalletStock(task, locationInf, boxing);
            // 执行数据库事务
            bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId);
            bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId, boxing);
            if (isResult)
            {
                content.OK("入库任务完成成功");
@@ -349,13 +343,41 @@
            CreateDate = DateTime.Now,
            Creater = "system",
            IsFull = false,
            AreaCode = area.AreaCode,
            AreaCode = area.AreaCode ?? "",
            LocationId = loation.Id,
            StockInfoDetails = new List<DtStockInfoDetail>()
            {
                new DtStockInfoDetail()
                {
                    MaterielCode = "空托盘",
                    Id = 0,
                    Status = (int)StockStateEmun.已入库
                }
            }
        };
    }
    /// <summary>
    /// 创建分容的实托盘的库存实例模型
    /// </summary>
    private DtStockInfo CreateFullPalletStockByFR(Dt_Task task, DtLocationInfo locationInf)
    {
        var loation = _locationRepository.QueryFirst(x => x.RoadwayNo == task.Roadway && x.LocationCode == task.TargetAddress);
        var area = _areaInfoRepository.QueryFirst(x => x.AreaID == loation.AreaId);
        return new DtStockInfo()
        {
            PalletCode = task.PalletCode,
            LocationCode = task.TargetAddress,
            CreateDate = DateTime.Now,
            Creater = "system",
            IsFull = false,
            AreaCode = area.AreaCode ?? "",
            LocationId = loation.Id,
            StockInfoDetails = new List<DtStockInfoDetail>()
            {
                new DtStockInfoDetail()
                {
                    MaterielCode = "实托盘",
                    Id = 0,
                    Status = (int)StockStateEmun.已入库
                }
@@ -404,7 +426,7 @@
        stock.LinedProcessFeedbackTime = respone.LinedProcessFeedbackTime;
        stock.SpecialParameterDuration = respone.SpecialParameterDuration;
        //2024年11月16日:新增字段计算应出库时间
        stock.OutboundTime = Convert.ToDateTime(respone.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(respone.SpecialParameterDuration));
        stock.OutboundTime = Convert.ToDateTime(respone.LinedProcessFeedbackTime == null ? DateTime.Now : respone.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(respone.SpecialParameterDuration));
        stock.ProductionLine = respone.ProductionLine;
        stock.ParameterInfos = respone.ParameterInfos.ToJsonString();
        stock.StockStatus = 1;
@@ -440,9 +462,9 @@
        }
        LogFactory.GetLog("任务完成").InfoFormat(true, "验证任务是否存在", JsonConvert.SerializeObject(task));
        if(task.TaskType == (int)TaskOutboundTypeEnum.InToOut)
        if (task.TaskType == (int)TaskOutboundTypeEnum.InToOut)
        {
           return await CompleteInToOutTaskAsync(task);
            return await CompleteInToOutTaskAsync(task);
        }
        // 验证库存是否存在
@@ -541,7 +563,17 @@
            if (serialNosError.Count > 0)
            {
                // TODO 创建任务送至NG排出口
                List<string> NGStation = input.Position == "1088" ? new List<string>() { "1020" } : new List<string>() { "JZSC01" };
                var efg = _stationManagerRepository.QueryData(x => x.stationType == 1 && x.stationChildCode == input.Position && x.stationArea == area.AreaCode).ToList();
                //List<string> NGStation = input.Position == "1088" ? new List<string>() { "1020" } : new List<string>() { "JZSC01" };
                if (efg.Count <= 0)
                {
                    throw new Exception("未找到NG入库站台配置");
                }
                List<string> NGStation = efg.Select(x => x.stationNGLocation).ToList();
                if (NGStation.Count <= 0)
                {
                    NGStation = efg.Select(x => x.stationNGChildCode).ToList();
                }
                content = await CreateNewTask(input, NGStation, 2);
                return content.Error("存在异常电芯");
            }
@@ -552,6 +584,7 @@
                content = await RequestTrayInTaskAsync(input);
                return content;
            }
            //Console.WriteLine("qqqqq");
            // TODO 获取本地料框属性与整盘电芯属性获取的值进行对比,如果一致则继续,否则返回错误信息
            //var productions = await _productionRepository.QueryDataAsync(x => result.TrayBarcodePropertys.Select(x => x.TrayBarcodeProperty).ToList().Contains(x.TrayBarcodeProperty));
@@ -560,7 +593,8 @@
            // 调用CreateBoxingInfo方法,创建组盘信息
            var boxing = await CreateBoxingInfo(result, input.PalletCode);
            var boxing = CreateBoxingInfo(result, input.PalletCode);
            //Console.WriteLine(boxing.ToJsonString());
            if (boxing == null) return content.Error("组盘失败");
            // 调用GetProcessApplyAsync方法,获取工艺路线
@@ -584,8 +618,14 @@
            //// 调用GetProcessResponseAsync方法,获取工艺响应
            //var processResponse = await GetProcessResponseAsync(process, input.Position);
            List<string> strings = input.Position == "1088" ? new List<string>() { "CHSC01" } : new List<string>() { "JZSC01" };
            // 调用CreateNewTask方法,创建新任务
            //List<string> strings = input.Position == "1088" ? new List<string>() { "CHSC01" } : new List<string>() { "JZSC01" };
            var stationManagers = _stationManagerRepository.QueryData(x => x.stationType == 1 && x.stationChildCode == input.Position && x.stationArea == area.AreaCode).ToList();
            if (stationManagers.Count <= 0)
            {
                throw new Exception("未找到NG入库站台配置");
            }
            List<string> strings = stationManagers.Select(x => x.Roadway).ToList();
            //// 调用CreateNewTask方法,创建新任务
            content = await CreateNewTask(input, strings);
            if (content.Status)
            {
@@ -658,8 +698,15 @@
                return content.OK(data: task);
            }
            var stationManagers = _stationManagerRepository.QueryData(x => x.stationType == 1 && x.stationChildCode == input.Position).ToList();
            if (stationManagers.Count <= 0)
            {
                throw new Exception("未找到空托盘入库站台配置");
            }
            // 获取目标地址
            List<string> strings = input.Position == "1016" ? new List<string>() { "CHSC01" } : new List<string>() { "JZSC01" };
            List<string> strings = stationManagers.Select(x => x.Roadway).ToList();
            return await CreateNewTask(input, strings, 1);
        }
@@ -678,7 +725,7 @@
    }
    // 获取组盘信息
    private async Task<DtBoxingInfo> CreateBoxingInfo(ResultTrayCellsStatus result, string palletCode)
    private DtBoxingInfo CreateBoxingInfo(ResultTrayCellsStatus result, string palletCode)
    {
        return new DtBoxingInfo
        {
@@ -1184,12 +1231,14 @@
            {
                // 添加库存
                isUpdateStock = await _stockInfoRepository.AddDataNavAsync(stock);
                isDeleteBoxing = await _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id)
                   .Include(x => x.BoxingInfoDetails)
                   .ExecuteCommandAsync();
                if (boxingInfo != null)
                {
                    isDeleteBoxing = await _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id)
                                            .Include(x => x.BoxingInfoDetails)
                                            .ExecuteCommandAsync();
                }
            }
            // 添加历史任务
            var isTaskHtyAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0;