wangxinhui
2024-12-28 39ee9078d88fd4787437360e7f69ed999aaf0b7b
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs
@@ -1,4 +1,6 @@
using SqlSugar.Extensions;

using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,6 +16,7 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.MES;
@@ -37,11 +40,11 @@
            {
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==WarehouseEnum.HA64.ToString());
                //获取库存记录
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                  x.WarehouseId == warehouse.WarehouseId && 
                  x.StockStatus==(int)StockStatusEmun.入库完成)
                .Includes(x => x.Details).Where(x => x.Details.Any(x => x.BatchNo == model.ToolCode)).First();
                if (stockInfo==null)
                  x.StockStatus==(int)StockStatusEmun.入库完成).Includes(x=>x.Details).ToList();
                Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x=>x.Details.Any(x=>x.BatchNo==model.ToolCode));
                if (stockInfo == null)
                {
                    return responseContent.Error($"测试架:{model.ToolCode}无可用库存");
                }
@@ -62,7 +65,7 @@
                    NextAddress = "",
                    Roadway = locationInfo.RoadwayNo,
                    SourceAddress = stockInfo.LocationCode,
                    TargetAddress = "",
                    TargetAddress = model.TargetAddressCode,
                    TaskStatus = (int)TaskStatusEnum.New,
                    TaskType = (int)TaskTypeEnum.Outbound,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
@@ -86,7 +89,7 @@
                //_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.StockLock);
                _unitOfWorkManage.CommitTran();
                //将任务推送到WCS
                PushTasksToWCS(new List<Dt_Task>() { taskOut },"AGV");
                PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV");
                responseContent.OK();
            }
            catch (Exception ex)
@@ -108,10 +111,10 @@
                //获取测试架原库存信息
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA64.ToString());
                //获取库存记录
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                  x.WarehouseId == warehouse.WarehouseId &&
                  x.StockStatus == (int)StockStatusEmun.出库完成)
                .Includes(x => x.Details).Where(x => x.Details.Any(x => x.BatchNo == backModel.TestToolCode)).First();
                  x.StockStatus == (int)StockStatusEmun.出库完成).Includes(x => x.Details).ToList();
                Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == backModel.TestToolCode));
                if (stockInfo==null)
                {
                    return responseContent.Error($"{backModel.TestToolCode}库存信息不存在");
@@ -134,10 +137,9 @@
                };
                //更改库存状态
                stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                _unitOfWorkManage.BeginTran();
                //将任务推送到WCS
                PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV");
                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                _unitOfWorkManage.CommitTran();
                responseContent.OK();
            }
            catch (Exception ex)
@@ -159,17 +161,18 @@
                //获取测试架批次号库存
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA64.ToString());
                //获取库存记录
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                  x.WarehouseId == warehouse.WarehouseId && x.StockStatus==StockStatusEmun.出库完成.ObjToInt())
                .Includes(x => x.Details).Where(x => x.Details.Any(x => x.BatchNo == toolScrap.ToolCode)).First();
                //获取库存记录
                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                  x.WarehouseId == warehouse.WarehouseId &&
                  x.StockStatus == (int)StockStatusEmun.出库完成).Includes(x => x.Details).ToList();
                Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == toolScrap.ToolCode));
                if (stockInfo == null)
                {
                    return responseContent.Error($"{toolScrap.ToolCode}库存信息不存在");
                }
                //清除库存信息
                _unitOfWorkManage.BeginTran();
                _stockRepository.StockInfoRepository.DeleteData(stockInfo);
                _stockRepository.StockInfoDetailRepository.DeleteData(stockInfo.Details);
                _stockRepository.StockInfoRepository.DeleteAndMoveIntoHty(stockInfo,OperateTypeEnum.自动删除);
                _stockRepository.StockInfoDetailRepository.DeleteAndMoveIntoHty(stockInfo.Details, OperateTypeEnum.自动删除);
                _unitOfWorkManage.CommitTran();
@@ -192,13 +195,28 @@
            try
            {
                Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x=>x.ApiCode==APIEnum.WMS_MES_TestToolSync.ToString());
                Root<TestToolSynInfo> root = new Root<TestToolSynInfo>()
                MESRoot<TestToolSynInfo> root = new MESRoot<TestToolSynInfo>()
                {
                    From = "WMS",
                    DateTime = DateTime.Now.ToString(),
                    DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    Content=toolSynInfo
                };
                JsonSerializerSettings settings = new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };
                string request = JsonConvert.SerializeObject(root, settings);
                string response = HttpMesHelper.Post(apiInfo.ApiAddress, request);
                MesResponseContent mesResponseContent = response.DeserializeObject<MesResponseContent>();
                //调用接口
                if (mesResponseContent.BSucc==true)
                {
                    content.OK(mesResponseContent.StrMsg);
                }
                else
                {
                    content.Error(mesResponseContent.StrMsg);
                }
            }
            catch (Exception ex)
            {