Admin
2025-12-03 d41acebbd89f171b0eeb205fca4f68043ca85f95
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -5,6 +5,7 @@
using OfficeOpenXml.FormulaParsing.Excel.Functions.Database;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using SqlSugar;
using System.Diagnostics;
using System.Reflection.Emit;
using System.Text.RegularExpressions;
@@ -47,6 +48,7 @@
    private readonly IDt_ZdpStockRepository _ZdpStockRepository;
    private readonly IDt_ZdpStock_htyRepository _ZdpStock_HtyRepository;
    private readonly IDt_PreOutboundRepository _PreOutboundRepository;
    private readonly ILocationInfoRepository _locationInfoRepository;
    
    public Dt_TaskService(IDt_TaskRepository BaseDal,
@@ -72,7 +74,8 @@
                                IDt_ZdpStockRepository zdpStockRepository,
                                IDt_ZdpStock_htyRepository dt_ZdpStock_HtyRepository,
                                IDt_OutZdp_htyRepository dt_OutZdp_HtyRepository,
                                IDt_PreOutboundRepository dt_PreOutboundRepository) : base(BaseDal)
                                IDt_PreOutboundRepository dt_PreOutboundRepository,
                                ILocationInfoRepository locationInfoRepository) : base(BaseDal)
    {
        _unitOfWorkManage = unitOfWorkManage;
@@ -95,6 +98,7 @@
        _ZdpStock_HtyRepository = dt_ZdpStock_HtyRepository;
        _Dt_OutZdp_htyRepository = dt_OutZdp_HtyRepository;
        _PreOutboundRepository = dt_PreOutboundRepository;
        _locationInfoRepository = locationInfoRepository;
    }
    #region å¤–部接口方法
@@ -776,7 +780,7 @@
                        IsCheck = true,
                        Standards = stockInfo.Wheels_NewOrOld
                    };
                    task = new Dt_Task
                    {
@@ -816,7 +820,7 @@
            }
            // èŽ·å–WMS IP地址用于发送任务请求
            //获取WMS IP地址用于发送任务请求
            var wmsIpAddress = GetWCSIpReceiveTask();
            if (wmsIpAddress == null)
            {
@@ -840,6 +844,8 @@
                    _WheelsStockRepository.UpdateData(WheelList);
                }
            }
        }
        catch (Exception ex)
@@ -909,6 +915,8 @@
        return await BaseDal.Delete(ids);
    }
    #region åˆ é™¤ä»»åŠ¡å›žæ»š
    public override WebResponseContent DeleteData(object[] key)
    {
        WebResponseContent content = new WebResponseContent();
@@ -924,6 +932,59 @@
            if (task.TaskState != (int)TaskInStatusEnum.InNew && task.TaskState != (int)TaskOutStatusEnum.OutNew && task.TaskState != (int)TaskStatus.Created)
            {
                return content.Error("任务不处于新建状态,禁止删除!");
            }
            ////入库枚举
            //List<int> TaskInboundTypeEnums = Enum.GetValues(typeof(TaskInboundTypeEnum)).Cast<int>().ToList();
            ////出库枚举
            //List<int> TaskOutboundTypeEnums = Enum.GetValues(typeof(TaskOutboundTypeEnum)).Cast<int>().ToList();
            ////移库枚举
            //List<int> TaskMoveTypeEnums = Enum.GetValues(typeof(TaskRelocationTypeEnum)).Cast<int>().ToList();
            //判断任务类型
            // æ ¹æ®ä»»åŠ¡ç±»åž‹è°ƒç”¨ç›¸åº”çš„å®Œæˆä»»åŠ¡æ–¹æ³•
            // éªŒè¯åº“存是否存在
            var stock = _WheelsStockRepository.QueryFirstNavAsync(x => x.Wheels_Num.Contains(task.PalletCode) && x.Wheels_Location == task.SourceAddress);
            var ZdpStock = _ZdpStockRepository.QueryFirstNavAsync(x => x.Zdp_code == task.PalletCode && x.Zdp_Location == task.SourceAddress);
            bool res = false;
            switch (task.TaskType)
            {
                case (int)TaskInboundTypeEnum.Inbound:
                case (int)TaskInboundTypeEnum.InWheels:
                case (int)TaskInboundTypeEnum.InBrake:
                    LogFactory.GetLog("任务完成").InfoFormat(true, "入库任务", "");
                        res = SellectLocationInfo(task,1);
                    break;
                case (int)TaskOutboundTypeEnum.Outbound:
                case (int)TaskOutboundTypeEnum.OutWheels:
                    LogFactory.GetLog("任务完成").InfoFormat(true, "出库任务", "");
                        res = SellectLocationInfo(task,2);
                    break;
                case (int)TaskOutboundTypeEnum.OutBrake:
                    LogFactory.GetLog("任务完成").InfoFormat(true, "制动盘出库任务", "");
                        res = SellectLocationInfo(task,3);
                    break;
                case (int)TaskRelocationTypeEnum.Relocation:
                    if (stock != null)
                    {
                        res = SellectLocationInfo(task,4);
                    }
                    else
                    {
                        res = SellectLocationInfo(task,5);
                    }
                    break;
                default:
                    return content.Error("任务类型不存在");
            }
            if (!res)
            {
                return content.Error("在执行任务分类的时候出现错误!");
            }
            var taskHtyNG = CreateHistoricalTask(task, true);
@@ -948,6 +1009,97 @@
    }
    /// <summary>
    /// èŽ·å–åº“ä½ä¿¡æ¯
    /// </summary>
    /// <param name="targetAddress"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    private bool SellectLocationInfo(Dt_Task task,int taskType)
    {
        // èŽ·å–åº“ä½ä¿¡æ¯
        DtLocationInfo locationInfoT = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
        DtLocationInfo locationInfoS = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
        Dt_WheelsStock stock = _WheelsStockRepository.QueryFirst(x => x.Wheels_Num.Contains(task.PalletCode) && x.Wheels_Location == task.SourceAddress);
        Dt_ZdpStock ZdpStock = _ZdpStockRepository.QueryFirst(x => x.Zdp_code == task.PalletCode && x.Zdp_Location == task.SourceAddress);
        //if (locationInfoT == null) return false;
        //if (locationInfoS == null) return false;
        //1-入库   2-出库   3-制动盘出库   4-移库
        var db = _locationInfoRepository.Db as SqlSugarClient;
        try
        {
            db.Ado.BeginTran();
            if (taskType == 1)
            {
                locationInfoT.LocationStatus = (int)LocationEnum.Free;
                bool res = _locationInfoRepository.UpdateData(locationInfoT);
                if (res)
                {
                    db.Ado.CommitTran();
                    return true;
                }
            }
            else if (taskType == 2)
            {
                locationInfoS.LocationStatus = (int)LocationEnum.InStock;
                bool res = _locationInfoRepository.UpdateData(locationInfoS);
                stock.Wheels_CurrentStatue = 1;
                bool ress = _WheelsStockRepository.UpdateData(stock);
                if (res && ress)
                {
                    db.Ado.CommitTran();
                    return true;
                }
            }
            else if (taskType == 3)
            {
                locationInfoS.LocationStatus = (int)LocationEnum.InStock;
                bool res = _locationInfoRepository.UpdateData(locationInfoS);
                ZdpStock.Zdp_CurrentStatue = 1;
                bool ress = _ZdpStockRepository.UpdateData(ZdpStock);
                if (res && ress)
                {
                    db.Ado.CommitTran();
                    return true;
                }
            }
            //移库
            else
            {
                locationInfoT.LocationStatus = (int)LocationEnum.Free;
                locationInfoS.LocationStatus = (int)LocationEnum.InStock;
                bool res = _locationInfoRepository.UpdateData(locationInfoT);
                bool res1 = _locationInfoRepository.UpdateData(locationInfoS);
                if(taskType == 4)
                {
                    stock.Wheels_CurrentStatue = 1;
                }
                else
                {
                    ZdpStock.Zdp_CurrentStatue = 1;
                }
                bool ress = taskType == 4 ? _WheelsStockRepository.UpdateData(stock) : _ZdpStockRepository.UpdateData(ZdpStock);
                if (res && res1 && ress)
                {
                    db.Ado.CommitTran();
                    return true;
                }
            }
            return false;
        }
        catch (Exception ex)
        {
            db.Ado.RollbackTran();
            return false;
        }
    }
    #endregion
    /// <summary>
    /// é€šè¿‡ID获取任务
    /// </summary>
    /// <param name="id">任务ID</param>