wanshenmean
2024-11-09 ad18b0c17b5b1f715c33cb2a2b39589c10434a00
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -81,105 +81,6 @@
    #region 出库任务完成
    /// <summary>
    /// 出库任务完成
    /// </summary>
    /// <param name="saveModel">任务数据合集</param>
    /// <returns>返回结果集</returns>
    //public async Task<WebResponseContent> CompleteStackTaskAsync(Dt_Task task, DtStockInfo stock)
    //{
    //    WebResponseContent content = new WebResponseContent();
    //    try
    //    {
    //        if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
    //        {
    //            var process = await SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>()
    //                 .FirstAsync(x => x.EquipmentName == task.Roadway);
    //            EquipmentParameterInfo info = JsonConvert.DeserializeObject<EquipmentParameterInfo>(process.ProcessValue);
    //            AgingOutputDto agingOutputDto = new AgingOutputDto()
    //            {
    //                OpFlag = 1,
    //                EquipmentCode = stock.LocationInfo.RoadwayNo,
    //                TrayBarcode = stock.PalletCode,
    //                SerialNos = stock.StockInfoDetails.Select(x => new SerialNoOutDto()
    //                {
    //                    SlotNo = x.OrderNo.ToInt32(),
    //                    SerialNo = x.SerialNumber,
    //                    SerialNoResult = true,
    //                    ParameterInfo = new List<ParameterInfo>()
    //                    {
    //                        new ParameterInfo()
    //                        {
    //                            LowerLomit =info.LowerControlLimit,
    //                            UpperLimit = info.UpperControlLimit,
    //                            ParameterResult = info.EquipmentAvailabilityFlag,
    //                            ParameterCode = info.ParameterCode,
    //                            ParameterDesc = info.Description,
    //                            TargetValue = info.TargetValue,
    //                            Value = info.TargetValue,
    //                            DefectCode = info.UOMCode
    //                        }
    //                    }
    //                }).ToList()
    //            };
    //            content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto);
    //            var result = JsonConvert.DeserializeObject<BasicResult>(content.ToString());
    //            if (!result.Success)
    //            {
    //                throw new Exception(result.MOMMessage);
    //            }
    //        }
    //        // 更新库存状态
    //        var loation = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
    //        var detail = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id);
    //        // 设置库位状态为空闲
    //        loation.LocationStatus = LocationEnum.Free.ObjToInt();
    //        // 更新任务状态
    //        task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt();
    //        task.CurrentAddress = task.NextAddress;
    //        task.NextAddress = task.TargetAddress;
    //        LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", "更新库存状态与任务状态");
    //        // 事务处理
    //        // 开始事务
    //        _unitOfWorkManage.BeginTran();
    //        // 删除库存信息
    //        var isStockUpdated = _stockInfoRepository.DeleteDataById(stock.Id);
    //        // 删除库存信息
    //        var isStockDetailUpdated = _stockInfoDetailRepository.DeleteDataByIds(detail.Select(x => (object)x.Id).ToArray());
    //        // 删除任务信息
    //        var isTaskUpdated = BaseDal.DeleteDataById(task.TaskId);
    //        // 如果库存信息和任务信息都更新成功
    //        if (isStockUpdated && isTaskUpdated && isStockDetailUpdated)
    //        {
    //            // 记录日志
    //            LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", $"事务处理完成,库存状态更新:{isStockUpdated},任务状态更新:{isTaskUpdated}");
    //            // 提交事务
    //            _unitOfWorkManage.CommitTran();
    //            // 返回成功结果
    //            return content.OK("任务完成成功");
    //        }
    //        else
    //        {
    //            // 记录日志
    //            LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", $"事务处理失败,库存状态更新:{isStockUpdated},任务状态更新:{isTaskUpdated}");
    //            // 回滚事务
    //            _unitOfWorkManage.RollbackTran();
    //            // 返回失败结果
    //            return content.Error("任务或库存更新失败");
    //        }
    //    }
    //    catch (Exception err)
    //    {
    //        LogFactory.GetLog("任务完成").InfoFormat(true, $"系统异常,异常信息:{err.Message}", "");
    //        Console.WriteLine(err.Message);
    //        return content.Error(err.Message);
    //    }
    //}
    public async Task<WebResponseContent> CompleteStackTaskAsync(Dt_Task task, DtStockInfo stock)
    {
@@ -190,7 +91,7 @@
            {
                var process = await SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>()
                    .FirstAsync(x => x.EquipmentName == task.Roadway);
                var info = JsonConvert.DeserializeObject<List<EquipmentParameterInfo>>(process.ProcessValue);
                var info = JsonConvert.DeserializeObject<ResponseEqptRunDto>(process.ProcessValue);
                var agingOutputDto = MapToAgingOutputDto(stock, info);
                content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto);
@@ -206,7 +107,7 @@
                await UpdateLocationAsync(loc);
                await DeleteStockInfoAsync(stock.Id);
                await DeleteStockInfoDetailsAsync(stock.StockInfoDetails);
                await DeleteTaskAsync(task.TaskId);
                //await DeleteTaskAsync(task.TaskId);
            });
            return content.OK("任务完成成功");
@@ -218,19 +119,20 @@
        }
    }
    private AgingOutputDto MapToAgingOutputDto(DtStockInfo stock, List<EquipmentParameterInfo> info)
    private AgingOutputDto MapToAgingOutputDto(DtStockInfo stock, ResponseEqptRunDto info)
    {
        return new AgingOutputDto
        {
            OpFlag = 1,
            EquipmentCode = stock.LocationInfo.RoadwayNo,
            Software = "WMS",
            EquipmentCode = "ECH001-B",
            TrayBarcode = stock.PalletCode,
            SerialNos = stock.StockInfoDetails.Select(x => new SerialNoOutDto
            {
                SlotNo = x.OrderNo.ToInt32(),
                SerialNo = x.SerialNumber,
                SerialNoResult = true,
                ParameterInfo = info.Select(x => new ParameterInfo()
                ParameterInfo = info.ParameterInfo.Select(x => new ParameterInfo()
                {
                    LowerLomit = x.LowerControlLimit,
                    UpperLimit = x.UpperControlLimit,
@@ -247,7 +149,7 @@
    private void ValidateResponse(WebResponseContent content)
    {
        var result = JsonConvert.DeserializeObject<BasicResult>(content.ToString());
        var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString());
        if (!result.Success)
        {
            throw new Exception(result.MOMMessage);
@@ -259,10 +161,10 @@
        var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
        var details = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id);
        location.LocationStatus = LocationEnum.Free.ObjToInt();
        task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt();
        task.CurrentAddress = task.NextAddress;
        task.NextAddress = task.TargetAddress;
        location.LocationStatus = (int)LocationEnum.Free;
        task.TaskState = (int)TaskOutStatusEnum.OutFinish;
        //task.CurrentAddress = task.NextAddress;
        //task.NextAddress = task.TargetAddress;
        LogFactory.GetLog("任务完成").Info(true, "更新库存状态与任务状态");
        return (location, task);
@@ -474,7 +376,7 @@
        LogFactory.GetLog("任务完成").InfoFormat(true, "验证任务是否存在", JsonConvert.SerializeObject(task));
        // 验证库存是否存在
        var stock = await _stockInfoRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode);
        var stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode);
        // 根据任务类型调用相应的完成任务方法
        switch (task.TaskType)
@@ -499,7 +401,7 @@
    #region 请求任务入库
    /// <summary>
    /// 请求任务
    /// 请求任务巷道
    /// </summary>
    /// <param name="input">请求模型</param>
    /// <returns>包含任务信息的响应内容</returns>
@@ -514,7 +416,7 @@
            var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode);
            if (task != null)
            {
                if (task.TaskState == (int)TaskInStatusEnum.InNew)
                //if (task.TaskState == (int)TaskInStatusEnum.InNew)
                {
                    // 创建WMS任务
                    WMSTaskDTO taskDTO = new WMSTaskDTO()
@@ -531,8 +433,6 @@
                    };
                    return content.OK(data: taskDTO);
                }
                content = await UpdateExistingTask(input, task);
                return content;
            }
            // 创建一个TrayCellsStatusDto对象,并赋值
            TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
@@ -563,8 +463,8 @@
            // 调用GetProcessResponseAsync方法,获取工艺响应
            var processResponse = await GetProcessResponseAsync(process, input.Position);
            // 如果task不为null,则调用UpdateExistingTask方法,更新任务;否则调用CreateNewTask方法,创建新任务
            content = task != null ? await UpdateExistingTask(input, task) : await CreateNewTask(input, processResponse);
            // 调用CreateNewTask方法,创建新任务
            content =  await CreateNewTask(input, processResponse);
            if (content.Status)
            {
                var isBox = await _boxingInfoRepository.AddDataNavAsync(boxing);
@@ -581,6 +481,35 @@
        return content;
    }
    /// <summary>
    /// 更新任务货位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<WebResponseContent> UpdateExistingTask(RequestTaskDto input)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode);
            if (task == null)
                return content.Error($"暂未找到【{input.PalletCode}】的任务");
            return content = await UpdateExistingTask(input, task);
        }
        catch (Exception err)
        {
            throw;
        }
    }
    /// <summary>
    /// 空托盘入库申请
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<WebResponseContent> RequestTrayInTaskAsync(RequestTaskDto input)
    {
        WebResponseContent content = new WebResponseContent();
@@ -816,6 +745,12 @@
    #region 任务状态更改
    /// <summary>
    /// 更新任务状态&出库解盘
    /// </summary>
    /// <param name="taskNum"></param>
    /// <param name="taskState"></param>
    /// <returns></returns>
    public async Task<WebResponseContent> UpdateTaskStatus(int taskNum, int taskState)
    {
        WebResponseContent content = new WebResponseContent();
@@ -824,12 +759,57 @@
            var task = await BaseDal.QueryFirstAsync(x => x.TaskNum == taskNum);
            if (task == null)
                return content.Error("未找到任务");
            task.TaskState = taskState;
            var asb = await BaseDal.UpdateDataAsync(task);
            if (asb)
            if (taskState == (int)TaskOutStatusEnum.Line_OutFinish)
            {
                var taskHty = CreateHistoricalTask(task);
                await _unitOfWorkManage.UseTranAsync(async () =>
                {
                    var asb = await BaseDal.DeleteDataByIdAsync(task.TaskId);
                    var asbHty = await _task_HtyRepository.AddDataAsync(taskHty) > 0;
                    if (asb && asbHty)
                        content.OK();
                    else
                        throw new Exception();
                });
                content.OK();
            }
            else
                content.Error();
            {
                task.TaskState = taskState;
                var asb = await BaseDal.UpdateDataAsync(task);
                if (asb)
                    content.OK();
                else
                    content.Error();
            }
        }
        catch (Exception ex)
        {
            content.Error(ex.Message);
        }
        return content;
    }
    #endregion
    #region 出库解盘
    /// <summary>
    /// 出库解盘接口
    /// </summary>
    /// <param name="taskNum"></param>
    /// <returns></returns>
    public async Task<WebResponseContent> OutUnblockInterface(int taskNum)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            var task = await BaseDal.QueryFirstAsync(x => x.TaskNum == taskNum);
            if (task == null)
                return content.Error("未找到任务");
            task.TaskState = (int)TaskOutStatusEnum.Line_OutFinish;
            var taskHty = CreateHistoricalTask(task);
        }
        catch (Exception ex)
        {