| | |
| | | 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; |
| | |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | | public partial class TaskService |
| | | public partial class TaskService |
| | | { |
| | | static object lock_out = new object(); |
| | | |
| | | /// <summary> |
| | | /// æµè¯æ¶åºä» |
| | | /// </summary> |
| | |
| | | /// <returns></returns> |
| | | public MesResponseContent TestToolOut(TestToolOutModel model) |
| | | { |
| | | 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, (PalletTypeEnum)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"); |
| | | 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 |
| | | { |
| | | //è·ååºåè®°å½ warehouseIDæå®å
ç¨åºå®å¼ TEST |
| | | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == 1 && |
| | | x.PalletCode == model.ToolCode && |
| | | x.StockStatus==(int)StockStatusEmun.å
¥åºå®æ) |
| | | .Includes(x => x.Details).First(); |
| | | if (stockInfo==null) |
| | | //è·åæµè¯æ¶ååºåä¿¡æ¯ |
| | | 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($"æµè¯æ¶æç:{model.ToolCode}æ åºåè®°å½"); |
| | | return responseContent.Error($"{backModel.TestToolCode}åºåä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | 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) |
| | | //çæéåºä»»å¡ |
| | | Dt_Task taskIn = new() |
| | | { |
| | | return responseContent.Error($"è´§ä½:{stockInfo.LocationCode}åºåºæ¡ä»¶ä¸æ»¡è¶³"); |
| | | } |
| | | //çææµè¯æ¶åºåºä»»å¡ éå®åºå æ´æ¹è´§ä½ç¶æ |
| | | Dt_Task taskOut = new() |
| | | { |
| | | CurrentAddress = stockInfo.LocationCode, |
| | | CurrentAddress = backModel.SourceAddressCode, |
| | | Grade = 0, |
| | | PalletCode = stockInfo.PalletCode, |
| | | NextAddress = "", |
| | | Roadway = locationInfo.RoadwayNo, |
| | | SourceAddress = stockInfo.LocationCode, |
| | | Roadway = "", |
| | | SourceAddress = backModel.SourceAddressCode, |
| | | TargetAddress = "", |
| | | TaskStatus = (int)TaskOutStatusEnum.OutNew, |
| | | TaskType = (int)TaskOutboundTypeEnum.OutTestStand, |
| | | TaskStatus = (int)TaskStatusEnum.New, |
| | | TaskType = (int)TaskTypeEnum.ProductionReturn, |
| | | 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(); |
| | | //æ´æ°åºåç¶æ |
| | | //æ´æ¹åºåç¶æ |
| | | stockInfo.StockStatus = StockStatusEmun.éåº.ObjToInt(); |
| | | BaseDal.AddData(taskIn); |
| | | _stockRepository.StockInfoRepository.UpdateData(stockInfo); |
| | | //æ´æ°è´§ä½ç¶æ |
| | | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId); |
| | | //æ°å»ºä»»å¡ |
| | | BaseDal.AddData(taskOut); |
| | | //å å
¥è´§ä½åå¨è®°å½ |
| | | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum); |
| | | _unitOfWorkManage.CommitTran(); |
| | | //å°ä»»å¡æ¨éå°WCS |
| | | PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV"); ; |
| | | responseContent.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | } |
| | | 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; |
| | | } |
| | | } |
| | | } |