| | |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); |
| | | Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(context); |
| | | Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context); |
| | | IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context); |
| | | |
| | | var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "龿¡æº"); |
| | | if (Pipeline_client == null) throw new Exception("龿¡æºè°åº¦æå¡æªå¼å¯ï¼"); |
| | |
| | | |
| | | foreach (var item in stationinfos) |
| | | { |
| | | //å¤å®ä»»å¡æ¯å¦å·²å建//å¦å·²åå¨ |
| | | if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any()) |
| | | continue; |
| | | |
| | | var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", item.stationCode);//读åæçä¿¡å·:1:æ,2æ |
| | | var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", item.stationCode);//读åè´§ç©ä¿¡å·:1:æ,2æ |
| | |
| | | |
| | | //æ ¹æ®ä¸æå£çç»å®ä¿¡æ¯æ¥è¯¢å¯¹åºå·¥åï¼æ£æµæ¤å·¥åæ¯å¦å·²å®æ 宿å³å¯å°å
¶éå
¥åº |
| | | |
| | | dt_mes_head mesinfo = mes_HeadRepository.Find(x => x.jobID == item.Number).FirstOrDefault(); |
| | | if (mesinfo == null) |
| | | var work = workinfoRepository.Find(x => x.workOrder == item.Number && x.drawingNo == item.stationType && x.heatID == item.heatNumber && x.processCode == "17").OrderByDescending(x => x.CreateTime).FirstOrDefault(); |
| | | if (work == null) |
| | | { |
| | | item.remark = "触åå
¥åºä»»å¡,使ªæ¾å°å·¥å头表ï¼"; |
| | | item.remark = "触åå
¥åºä»»å¡,使ªæ¾å°å·¥åä¿¡æ¯ï¼"; |
| | | item.location_state = LocationStateEnum.Abnormal.ToString(); |
| | | stationinfoRepository.Update(item, true); |
| | | stationinfoRepository.Update(item, x => new { x.remark, x.location_state }, true); |
| | | continue; |
| | | //throw new Exception("æªæ¾å°å·¥å头表ï¼å·¥åå·ï¼" + item.Number); |
| | | } |
| | | var dt_Geometry_Data = PipelineJob.QueryMateriel(mesinfo.drawingNo); |
| | | var dt_Geometry_Data1 = PipelineJob.QueryMateriel1(mesinfo.drawingNo); |
| | | |
| | | int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum); |
| | | |
| | | |
| | | //å¤å®ä»»å¡æ¯å¦å·²å建//å¦å·²åå¨ |
| | | if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any()) |
| | | var geometry = Pipeline.QueryMateriel(work.drawingNo); |
| | | if (geometry == null) |
| | | { |
| | | item.remark = "æªæ¾å°è½¦è½®ä¿¡æ¯ï¼"; |
| | | item.location_state = LocationStateEnum.Abnormal.ToString(); |
| | | stationinfoRepository.Update(item, x => new { x.remark, x.location_state }, true); |
| | | continue; |
| | | } |
| | | |
| | | dt_stationinfo TargetLocation = null; |
| | | string tasktype = ""; |
| | | if (item.quantity == 5 || CompeletedNum == 0) //循ç¯è¯»å车轮æ°ä¸º5æè
订å已宿æ°éçä¸æå£ âå·¥å人工å
³éçå·¥å |
| | | |
| | | //if (item.quantity == 5) |
| | | if (item.quantity == geometry.stackNoRange) |
| | | { |
| | | |
| | | |
| | | if (mesinfo.quantity <= 50 || item.stationCode.Contains("3")) //å°äº50ä»¶ç´æ¥åºåº |
| | | { |
| | | //todo 寻æ¾å¯æ¾è´§å¤åæ¾è´§å° |
| | | if (!string.IsNullOrEmpty(work.area) || item.stationCode.Contains("3")) |
| | | tasktype = "TaskType_OutsourceInbound"; |
| | | TargetLocation = GetEmptyLocation(stationinfoRepository); |
| | | #region MyRegion |
| | | //if (TargetLocation != null) |
| | | //{ |
| | | // dt_agvtask agvtask = new dt_agvtask() |
| | | // { |
| | | // agv_fromaddress = item.stationCode, |
| | | // agv_id = Guid.NewGuid(), |
| | | // agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), |
| | | // agv_grade = 1, |
| | | // agv_createtime = DateTime.Now, |
| | | // agv_taskstate = "Create", |
| | | // agv_materielid = item.stationType, |
| | | // agv_qty = item.quantity, |
| | | // agv_tasktype = "TaskType_OutsourceInbound", |
| | | // agv_toaddress = TargetLocation.stationCode, |
| | | // agv_userid = "ç³»ç»", |
| | | // bindSN = item.bindSN, |
| | | // agv_worktype = Convert.ToInt32(mesinfo.processCode), |
| | | // agv_materbarcode = mesinfo.materialCode, |
| | | // agv_Traytype = item.tray_type, |
| | | // jobID = item.Number, |
| | | // agv_TrayStatus = item.tray_status |
| | | // }; |
| | | |
| | | // agvtaskRepository.Add(agvtask, true); |
| | | // TargetLocation.location_state = LocationStateEnum.Busy.ToString(); |
| | | // TargetLocation.stationType = agvtask.agv_materielid; |
| | | // stationinfoRepository.Update(TargetLocation, true); |
| | | //} |
| | | #endregion |
| | | |
| | | } |
| | | else |
| | | { |
| | | //todo: è°ç¨WMSæ¥å£åå»ºä»»å¡ |
| | | tasktype = "TaskType_Inbound"; |
| | | TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data == null ? dt_Geometry_Data1.e : dt_Geometry_Data.e); |
| | | } |
| | | if (TargetLocation != null) |
| | | { |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_fromaddress = item.stationCode, |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), |
| | | agv_grade = 1, |
| | | agv_createtime = DateTime.Now, |
| | | agv_taskstate = "Create", |
| | | agv_materielid = item.stationType, |
| | | agv_qty = item.quantity, |
| | | agv_tasktype = tasktype, |
| | | agv_toaddress = TargetLocation.stationCode, |
| | | agv_userid = "ç³»ç»", |
| | | bindSN = item.bindSN, |
| | | agv_worktype = Convert.ToInt32(mesinfo.processCode), |
| | | agv_materbarcode = mesinfo.materialCode, |
| | | agv_Traytype = item.tray_type, |
| | | jobID = item.Number, |
| | | agv_TrayStatus = item.tray_status |
| | | }; |
| | | agvtaskRepository.Add(agvtask, true); |
| | | |
| | | item.location_state = LocationStateEnum.InBusy.ToString(); |
| | | stationinfoRepository.Update(item, true); |
| | | |
| | | TargetLocation.location_state = LocationStateEnum.InBusy.ToString(); |
| | | TargetLocation.stationType = agvtask.agv_materielid; |
| | | stationinfoRepository.Update(TargetLocation, true); |
| | | WriteDBLog.Success("å建å
¥åºä»»å¡", $"ä»»å¡ç¼å·ï¼{agvtask.agv_tasknum}", "PCS"); |
| | | } |
| | | AGVTask.AddQueueTask(stationinfoRepository, agvtaskRepository, item, tasktype, work); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | WriteDBLog.Error("å建å
¥åºä»»å¡", $"é误信æ¯ï¼ {ex.Message}", "PCS"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | dt_stationinfo TargetLocation = null; |
| | | |
| | | #region åç±»åæ¾ä¸è¡ |
| | | var area1 = GetArea(mesinfo.quantity, e); |
| | | TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault(); |
| | | //if (area1 == "1") |
| | | TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo).FirstOrDefault(); |
| | | |
| | | //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault(); |
| | | if (TargetLocation != null) |
| | | { |
| | | #region åä¸è¡åªå
许ä¸ä¸ªä»»å¡ |
| | |
| | | // return null; |
| | | #endregion |
| | | |
| | | #region åºåºä»»å¡ä¼å
,åå¨åºåºä»»å¡è¿ä¸è¡åä¸è½å
¥åº |
| | | var OutTask = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == area1 && x.location_state == LocationStateEnum.OutBusy.ToString()).Any(); |
| | | if (OutTask) return null; |
| | | #region åºåºä»»å¡ä¼å
,åå¨åºåºä»»å¡åä¸è½å
¥åº |
| | | bool OutTask = false; |
| | | if (TargetLocation.area == "1") |
| | | { |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderByDescending(x => x.line).FirstOrDefault(); |
| | | if (TargetLocation != null) |
| | | OutTask = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.OutBusy.ToString()).Any(); |
| | | if (OutTask)//è¿ååå¨åºåºä»»å¡,寻æ¾ä¸åç©ºè´§ä½ |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.column).FirstOrDefault(); |
| | | if (TargetLocation != null) return TargetLocation; |
| | | } |
| | | else |
| | | { |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.column).FirstOrDefault(); |
| | | if (TargetLocation != null) |
| | | OutTask = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any(); |
| | | //åºå
åå¨åºåºä»»å¡ï¼éæ°å¼ä¸è¡å
¥åº |
| | | if (OutTask) |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == (TargetLocation.area == "2" ? 1 : 10) && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).FirstOrDefault(); |
| | | if (TargetLocation != null) return TargetLocation; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault(); |
| | | if (TargetLocation != null) |
| | | return TargetLocation; |
| | | //TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault(); |
| | | //if (TargetLocation != null) |
| | | // return TargetLocation; |
| | | } |
| | | #endregion |
| | | |
| | |
| | | stationinfoRepository.Update(stationinfo, true); |
| | | return null; |
| | | } |
| | | |
| | | #region æ¥æ¾åºå |
| | | dt_inventory inventory = null; |
| | | if (detail.heatID != null) |
| | | { |
| | | inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).FirstOrDefault(); |
| | | inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).FirstOrDefault(); |
| | | inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault(); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®åºåæ¥æ¾å¯å
¥åºç©ºè´§ä½ |
| | | if (inventory != null) |
| | |
| | | |
| | | |
| | | |
| | | var area1 = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, e) : mesinfo.area; |
| | | |
| | | if (CompeletedNum <= 15) |
| | | if (CompeletedNum <= 15 || area1 == "1") |
| | | { |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault(); |
| | | } |
| | |
| | | //else if (180 < mesinfo.quantity && mesinfo.quantity <= 225 && e < 1100) |
| | | // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "3" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); |
| | | //if (50 < mesinfo.quantity && e > 1100 || TargetLocation == null) |
| | | var area = GetArea(mesinfo.quantity, e); |
| | | |
| | | //var area = GetArea(mesinfo.quantity, e); |
| | | |
| | | |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == (area1 == "2" ? 1 : 10) && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).OrderBy(x => x.column).FirstOrDefault(); |
| | | if (TargetLocation == null) |
| | | { |
| | | if (area == "2") |
| | | area = "3"; |
| | | else if (area == "3") |
| | | area = "2"; |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); |
| | | if (area1 == "2") |
| | | area1 = "3"; |
| | | else if (area1 == "3") |
| | | area1 = "2"; |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == (area1 == "2" ? 1 : 10) && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).OrderBy(x => x.column).FirstOrDefault(); |
| | | if (TargetLocation == null) |
| | | { |
| | | //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == "1").OrderByDescending(x => x.column).FirstOrDefault(); |
| | | |
| | | //if (TargetLocation != null) |
| | | // TargetLocation = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderByDescending(x => x.line).FirstOrDefault(); |
| | | //if (TargetLocation == null) |
| | | // TargetLocation = stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).OrderByDescending(x => x.line).FirstOrDefault(); |
| | | if (TargetLocation == null) |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault(); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | //if (TargetLocation == null) |
| | |
| | | } |
| | | return TargetLocation; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 临æ¶ä½¿ç¨ |
| | | /// </summary> |
| | | /// <param name="stationinfoRepository"></param> |
| | | /// <returns></returns> |
| | | public static dt_stationinfo GetEmptyLocation1(Idt_stationinfoRepository stationinfoRepository) |
| | | { |
| | | return stationinfoRepository.Find(x => x.line == 1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "3").OrderBy(x => x.column).FirstOrDefault();//è¡ååºåéåæ» |
| | | } |
| | | /// <summary> |
| | | /// å»å¤å |
| | | /// </summary> |
| | | /// <param name="stationinfoRepository"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository) |
| | | { |
| | | dt_stationinfo TargetLocation = null; |
| | |
| | | if (!Pipeline_client.IsConnected) throw new Exception("ä¸é¾æ¡æºè¿æ¥è¶
æ¶ï¼"); |
| | | foreach (var item in target) |
| | | { |
| | | TargetLocation = stationinfoRepository.Find(x => x.stationCode == item && x.location_state == "Empty" /*LocationStateEnum.Empty.ToString()*/ && x.enable).FirstOrDefault(); |
| | | TargetLocation = stationinfoRepository.Find(x => x.stationCode == item && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).FirstOrDefault(); |
| | | |
| | | var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", item);//读åæçä¿¡å·:1:æ,2æ |
| | | var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", item);//读åè´§ç©ä¿¡å·:1:æ,2æ |
| | | if (TargetLocation != null && PalletSignal == 2 && MaterialSignal == 2) return TargetLocation; |
| | | } |
| | | |
| | | if (TargetLocation == null) |
| | | { |
| | | throw new Exception("å¤åå
¥åºå£å·²æ»¡"); |
| | | } |
| | | //if (TargetLocation == null) |
| | | //{ |
| | | // throw new Exception("å¤åå
¥åºå£å·²æ»¡"); |
| | | //} |
| | | return TargetLocation; |
| | | } |
| | | /// <summary> |