hutongqing
2024-12-28 f4e01fb44b5428e61780e63d272df1d03f7281f3
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs
@@ -1,8 +1,12 @@
using System;

using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.APIEnum;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OtherEnum;
@@ -11,6 +15,8 @@
using WIDESEA_Common.WareHouseEnum;
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;
@@ -34,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.MaterielCode == 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}无可用库存");
                }
@@ -59,9 +65,9 @@
                    NextAddress = "",
                    Roadway = locationInfo.RoadwayNo,
                    SourceAddress = stockInfo.LocationCode,
                    TargetAddress = "",
                    TargetAddress = model.TargetAddressCode,
                    TaskStatus = (int)TaskStatusEnum.New,
                    TaskType = (int)TaskTypeEnum.TestOutbound,
                    TaskType = (int)TaskTypeEnum.Outbound,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    PalletType = stockInfo.PalletType,
                    WarehouseId = stockInfo.WarehouseId,
@@ -79,9 +85,11 @@
                BaseDal.AddData(taskOut);
                //加入货位变动记录
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum);
                //加入库存变动记录
                //_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.StockLock);
                _unitOfWorkManage.CommitTran();
                //将任务推送到WCS
                PushTasksToWCS();
                PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV");
                responseContent.OK();
            }
            catch (Exception ex)
@@ -95,15 +103,48 @@
        /// æµ‹è¯•架退库
        /// </summary>
        /// <returns></returns>
        public MesResponseContent TestReturnStock(TestToolBackModel backModel)
        public MesResponseContent TestToolBack(TestToolBackModel backModel)
        {
            MesResponseContent responseContent = new MesResponseContent();
            try
            {
                //获取测试架原库存信息
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA64.ToString());
                //获取库存记录
                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 == backModel.TestToolCode));
                if (stockInfo==null)
                {
                    return responseContent.Error($"{backModel.TestToolCode}库存信息不存在");
                }
                //生成退库任务
                Dt_Task taskIn = new()
                {
                    CurrentAddress = backModel.SourceAddressCode,
                    Grade = 0,
                    PalletCode = stockInfo.PalletCode,
                    NextAddress = "",
                    Roadway = "",
                    SourceAddress = backModel.SourceAddressCode,
                    TargetAddress = "",
                    TaskStatus = (int)TaskStatusEnum.New,
                    TaskType = (int)TaskTypeEnum.ProductionReturn,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    PalletType = stockInfo.PalletType,
                    WarehouseId = stockInfo.WarehouseId,
                };
                //更改库存状态
                stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                //将任务推送到WCS
                PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV");
                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                responseContent.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                responseContent.Error(ex.Message);
            }
            return responseContent;
@@ -120,12 +161,25 @@
                //获取测试架批次号库存
                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)
                .Includes(x => x.Details).Where(x => x.Details.Any(x => x.MaterielCode == 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.DeleteAndMoveIntoHty(stockInfo,OperateTypeEnum.自动删除);
                _stockRepository.StockInfoDetailRepository.DeleteAndMoveIntoHty(stockInfo.Details, OperateTypeEnum.自动删除);
                _unitOfWorkManage.CommitTran();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                responseContent.Error(ex.Message);
            }
            return responseContent;
@@ -140,10 +194,29 @@
            WebResponseContent content= new WebResponseContent();
            try
            {
                Root<TestToolSynInfo> root = new Root<TestToolSynInfo>()
                Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x=>x.ApiCode==APIEnum.WMS_MES_TestToolSync.ToString());
                MESRoot<TestToolSynInfo> root = new MESRoot<TestToolSynInfo>()
                {
                    From = "WMS",
                    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)
            {