|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | using WIDESEA_Common.StockEnum; | 
|---|
|  |  |  | using WIDESEA_Common.TaskEnum; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | using WIDESEA_ITaskInfoRepository; | 
|---|
|  |  |  | using WIDESEA_ITaskInfoService; | 
|---|
|  |  |  | using WIDESEA_Model.Models; | 
|---|
|  |  |  | using WIDESEA_Common.OrderEnum; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEA_TaskInfoService | 
|---|
|  |  |  | { | 
|---|
|  |  |  | public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService | 
|---|
|  |  |  | public partial class TaskService | 
|---|
|  |  |  | { | 
|---|
|  |  |  | static object lock_out = new object(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æµè¯æ¶åºä» | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public MesResponseContent TestToolOut(TestToolOutModel model) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return new MesResponseContent(); | 
|---|
|  |  |  | lock (lock_out) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MesResponseContent responseContent = new MesResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Task exsit = Repository.QueryFirst(x => x.TargetAddress == model.TargetAddressCode); | 
|---|
|  |  |  | if (exsit != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return responseContent.Error($"ç®æ å°åéå¤"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 == model.ToolCode)); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return responseContent.Error($"æµè¯æ¶:{model.ToolCode}æ å¯ç¨åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Task exsit2 = Repository.QueryFirst(x => x.PalletCode == stockInfo.PalletCode); | 
|---|
|  |  |  | if (exsit2 != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return responseContent.Error($"æµè¯æ¶æ¹æ¬¡å·éå¤"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode && | 
|---|
|  |  |  | x.WarehouseId == stockInfo.WarehouseId && | 
|---|
|  |  |  | x.LocationStatus == (int)LocationStatusEnum.InStock && | 
|---|
|  |  |  | (x.EnableStatus == (int)EnableStatusEnum.Normal || x.EnableStatus == (int)EnableStatusEnum.OnlyOut)); | 
|---|
|  |  |  | if (locationInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return responseContent.Error($"æµè¯æ¶è´§ä½:{stockInfo.LocationCode}åºåºæ¡ä»¶ä¸æ»¡è¶³"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //çææµè¯æ¶åºåºä»»å¡ éå®åºå æ´æ¹è´§ä½ç¶æ | 
|---|
|  |  |  | Dt_Task taskOut = new() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | CurrentAddress = stockInfo.LocationCode, | 
|---|
|  |  |  | Grade = 0, | 
|---|
|  |  |  | PalletCode = stockInfo.PalletCode, | 
|---|
|  |  |  | NextAddress = "", | 
|---|
|  |  |  | Roadway = locationInfo.RoadwayNo, | 
|---|
|  |  |  | SourceAddress = stockInfo.LocationCode, | 
|---|
|  |  |  | TargetAddress = model.TargetAddressCode, | 
|---|
|  |  |  | TaskStatus = (int)TaskStatusEnum.New, | 
|---|
|  |  |  | TaskType = (int)TaskTypeEnum.Outbound, | 
|---|
|  |  |  | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), | 
|---|
|  |  |  | PalletType = stockInfo.PalletType, | 
|---|
|  |  |  | WarehouseId = stockInfo.WarehouseId, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | stockInfo.StockStatus = (int)StockStatusEmun.åºåºéå®; | 
|---|
|  |  |  | LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus; | 
|---|
|  |  |  | locationInfo.LocationStatus = (int)LocationStatusEnum.Lock; | 
|---|
|  |  |  | //夿æ¯å¦æåºåºåä¿¡æ¯ | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | //æ´æ°åºåç¶æ | 
|---|
|  |  |  | _stockRepository.StockInfoRepository.UpdateData(stockInfo); | 
|---|
|  |  |  | //æ´æ°è´§ä½ç¶æ | 
|---|
|  |  |  | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId); | 
|---|
|  |  |  | //æ°å»ºä»»å¡ | 
|---|
|  |  |  | BaseDal.AddData(taskOut); | 
|---|
|  |  |  | //å å
¥è´§ä½åå¨è®°å½ | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | //å°ä»»å¡æ¨éå°WCS | 
|---|
|  |  |  | PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV_CSJ"); | 
|---|
|  |  |  | responseContent.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | responseContent.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return responseContent; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æµè¯æ¶éåº | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | BaseDal.AddData(taskIn); | 
|---|
|  |  |  | _stockRepository.StockInfoRepository.UpdateData(stockInfo); | 
|---|
|  |  |  | //å°ä»»å¡æ¨éå°WCS | 
|---|
|  |  |  | PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV_CSJ"); ; | 
|---|
|  |  |  | responseContent.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | responseContent.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return responseContent; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æµè¯æ¶æ¥åº | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public MesResponseContent TestScrap(TestToolScrap toolScraps) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | List<Dt_StockInfo> stockInfoUpdates = new List<Dt_StockInfo>(); | 
|---|
|  |  |  | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in toolScraps.ToolCodes) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == item)); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return responseContent.Error($"{item}åºåä¿¡æ¯ä¸åå¨"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | stockInfoUpdates.Add(stockInfo); | 
|---|
|  |  |  | stockInfoDetails.Add(stockInfo.Details.FirstOrDefault()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //æ¸
é¤åºåä¿¡æ¯ | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | _stockRepository.StockInfoRepository.DeleteAndMoveIntoHty(stockInfoUpdates, OperateTypeEnum.èªå¨å é¤); | 
|---|
|  |  |  | _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfoDetails, OperateTypeEnum.èªå¨å é¤); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | responseContent.OK($"æ¥åºæå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | responseContent.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return responseContent; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// åæ¥æµè¯æ¶å¯¿å½ | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="toolSynInfo"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent TestSynStock(TestToolSynInfo toolSynInfo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// ç©æåºåºï¼WMS忥åºåºç©ææ¹æ¬¡è³MES | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="model"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent UploadMesMaterialLotaAcept(MesMaterialLotaAceptModel model) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMS_MES_MaterialLotaAcept.ToString()); | 
|---|
|  |  |  | MESRoot<MesMaterialLotaAceptModel> root = new MESRoot<MesMaterialLotaAceptModel>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | From = "WMS", | 
|---|
|  |  |  | DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | 
|---|
|  |  |  | Content = model | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="stockInfo"></param> | 
|---|
|  |  |  | /// <param name="stockInfoDetail"></param> | 
|---|
|  |  |  | /// <param name="taskNo"></param> | 
|---|
|  |  |  | /// <param name="warehouseCode"></param> | 
|---|
|  |  |  | /// <param name="quantity"></param> | 
|---|
|  |  |  | /// <param name="cutedType"></param> | 
|---|
|  |  |  | /// <param name="ppWidth"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public MesMaterialLotaAceptModel GetMesMaterialLotaAceptModel(Dt_StockInfo stockInfo, Dt_StockInfoDetail stockInfoDetail, string taskNo, string warehouseCode, float quantity, string cutedType = "", float ppWidth = 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MesMaterialLotaAceptModel model = new MesMaterialLotaAceptModel() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | CarrierCode = stockInfo.PalletCode, | 
|---|
|  |  |  | CutedType = cutedType, | 
|---|
|  |  |  | ExpirationDate = stockInfoDetail.EffectiveDate, | 
|---|
|  |  |  | MaterialBarCode = stockInfoDetail.SerialNumber, | 
|---|
|  |  |  | MaterialCode = stockInfoDetail.MaterielCode, | 
|---|
|  |  |  | MaterialLot = stockInfoDetail.MaterielCode + "," + stockInfoDetail.BatchNo, | 
|---|
|  |  |  | MaterialName = stockInfoDetail.MaterielName, | 
|---|
|  |  |  | PPWidth = ppWidth, | 
|---|
|  |  |  | ProductionDate = stockInfoDetail.ProductionDate, | 
|---|
|  |  |  | Quantity = quantity, | 
|---|
|  |  |  | Supplier = "", | 
|---|
|  |  |  | TaskNo = taskNo, | 
|---|
|  |  |  | Type = 1, | 
|---|
|  |  |  | WarehouseArea = warehouseCode, | 
|---|
|  |  |  | WarehouseLocation = warehouseCode | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// åºæ¿åºåº | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="model"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public MesResponseContent SubstrateOut(SubstrateOutModel model) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA57.ToString()); | 
|---|
|  |  |  | if (warehouse == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return MesResponseContent.Instance.Error($"ä»åºåºç¡ä¿¡æ¯æªé
ç½®"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == model.MaterialCode); | 
|---|
|  |  |  | if (materielInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return MesResponseContent.Instance.Error($"æªæ¾å°è¯¥ç©æä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_MesOutboundOrder mesOutboundOrder = new Dt_MesOutboundOrder() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(), | 
|---|
|  |  |  | Line = model.Line, | 
|---|
|  |  |  | MaterialCode = model.MaterialCode, | 
|---|
|  |  |  | MaterialName = model.MaterialName, | 
|---|
|  |  |  | OrderQuantity = model.RequiredQuantity, | 
|---|
|  |  |  | TaskNo = model.TaskNo, | 
|---|
|  |  |  | Unit = model.Unit, | 
|---|
|  |  |  | OrderType = MesOutboundOrderTypeEnum.SubstrateOut.ObjToInt(), | 
|---|
|  |  |  | OrderStatus = OutOrderStatusEnum.æªå¼å§.ObjToInt(), | 
|---|
|  |  |  | WarehouseId = warehouse.WarehouseId | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_Task> tasks = new List<Dt_Task>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_StockInfo>? stockInfos = null; | 
|---|
|  |  |  | List<Dt_OutStockLockInfo>? outStockLockInfos = null; | 
|---|
|  |  |  | List<Dt_LocationInfo>? locationInfos = null; | 
|---|
|  |  |  | { | 
|---|
|  |  |  | (List<Dt_StockInfo>, Dt_MesOutboundOrder, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.MesOutboundOrderService.AssignStockOutbound(mesOutboundOrder); | 
|---|
|  |  |  | if (result.Item1 != null && result.Item1.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | tasks = GetTasks(result.Item1, TaskTypeEnum.MesOutbound); | 
|---|
|  |  |  | result.Item2.OrderStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); | 
|---|
|  |  |  | result.Item3.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.Status = OutLockStockStatusEnum.åºåºä¸.ObjToInt(); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfos = result.Item1; | 
|---|
|  |  |  | mesOutboundOrder = result.Item2; | 
|---|
|  |  |  | outStockLockInfos = result.Item3; | 
|---|
|  |  |  | locationInfos = result.Item4; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception("æ åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int id = BaseDal.AddData(tasks); | 
|---|
|  |  |  | outStockLockInfos.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.OrderNo = mesOutboundOrder.TaskNo; | 
|---|
|  |  |  | x.OrderDetailId = id; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | _outboundService.MesOutboundOrderService.Repository.AddData(mesOutboundOrder); | 
|---|
|  |  |  | if (stockInfos != null && stockInfos.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = _outboundService.MesOutboundOrderService.LockOutboundStockDataUpdate(stockInfos, outStockLockInfos, locationInfos, tasks: tasks); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | return MesResponseContent.Instance.Error(content.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | PushTasksToWCS(tasks); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return MesResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return MesResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// åºæ¿ä½æéåº | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="model"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public MesResponseContent SubstrateBack(SubstrateBackModel model) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => model.CarrierCode.Contains(x.CodeStartStr)); | 
|---|
|  |  |  | if (palletTypeInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return MesResponseContent.Instance.Error($"æªè¯å«è¯¥æçç±»åï¼è¯·ç¡®è®¤æçå·"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode == WarehouseEnum.HA57.ToString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_StockInfo stockInfo = new Dt_StockInfo() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | PalletCode = model.CarrierCode, | 
|---|
|  |  |  | PalletType = palletTypeInfo.PalletType, | 
|---|
|  |  |  | WarehouseId = warehouse.WarehouseId, | 
|---|
|  |  |  | StockStatus = StockStatusEmun.MESéåº.ObjToInt() | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_StockInfoDetail_Hty stockInfoDetail_Hty = _stockRepository.StockInfoDetail_HtyRepository.QueryFirst(x => x.BatchNo == model.MaterialLot && x.MaterielCode == model.MaterialCode); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | BatchNo = stockInfoDetail_Hty?.BatchNo ?? "", | 
|---|
|  |  |  | EffectiveDate = model.ExpirationDate, | 
|---|
|  |  |  | MaterielCode = model.MaterialCode, | 
|---|
|  |  |  | InboundOrderRowNo = stockInfoDetail_Hty?.InboundOrderRowNo ?? 0, | 
|---|
|  |  |  | MaterielName = model.MaterialCode, | 
|---|
|  |  |  | ProductionDate = model.ProductionDate, | 
|---|
|  |  |  | OrderNo = stockInfoDetail_Hty?.OrderNo ?? "", | 
|---|
|  |  |  | OutboundQuantity = 0, | 
|---|
|  |  |  | SerialNumber = stockInfoDetail_Hty?.SerialNumber ?? "0", | 
|---|
|  |  |  | StockQuantity = model.Quantity, | 
|---|
|  |  |  | Status = StockStatusEmun.MESéåº.ObjToInt(), | 
|---|
|  |  |  | Unit = model.Unit | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //Dt_Task task = new Dt_Task() | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    PalletCode = stockInfo.PalletCode, | 
|---|
|  |  |  | //    CurrentAddress = "", | 
|---|
|  |  |  | //    NextAddress = "", | 
|---|
|  |  |  | //    PalletType = stockInfo.PalletType, | 
|---|
|  |  |  | //    Roadway = "RGV01_BC", | 
|---|
|  |  |  | //    SourceAddress = "RGV01_BC", | 
|---|
|  |  |  | //    TargetAddress = "", | 
|---|
|  |  |  | //    TaskStatus = TaskStatusEnum.New.ObjToInt(), | 
|---|
|  |  |  | //    TaskType = TaskTypeEnum.MesMatReturn.ObjToInt(), | 
|---|
|  |  |  | //    WarehouseId = warehouse.WarehouseId | 
|---|
|  |  |  | //}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand(); | 
|---|
|  |  |  | //BaseDal.AddData(task); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return MesResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | return MesResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|