| | |
| | | using WIDESEA_Entity.DomainModels; |
| | | using WIDESEA_Comm; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | using WIDESEA_Comm.TaskNo; |
| | | |
| | | namespace WIDESEA_WCS.JobsPart.Common |
| | | { |
| | | public class StationTask |
| | | { |
| | | |
| | | FreeDB freeDB = new FreeDB(); |
| | | public void CreateTask() |
| | | static FreeDB freeDB = new FreeDB(); |
| | | /// <summary> |
| | | /// å建å
¥åºä»»å¡ |
| | | /// </summary> |
| | | public static void CreateTask() |
| | | { |
| | | VOLContext context = new VOLContext(); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); |
| | | Idt_WorkinfoRepository workinfoRepository = new dt_WorkinfoRepository(context); |
| | | |
| | | List<dt_stationinfo> stationinfos = stationinfoRepository.Find(x => x.stationCode.Contains('X')); |
| | | |
| | | foreach (var item in stationinfos) |
| | | try |
| | | { |
| | | //æ ¹æ®ä¸æå£çç»å®ä¿¡æ¯æ¥è¯¢å¯¹åºå·¥åï¼æ£æµæ¤å·¥åæ¯å¦å·²å®æ 宿å³å¯å°å
¶éå
¥åº |
| | | VOLContext context = new VOLContext(); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); |
| | | Idt_WorkinfoRepository workinfoRepository = new dt_WorkinfoRepository(context); |
| | | |
| | | dt_mes_head mesinfo = freeDB.Select<dt_mes_head>().Where(x => x.jobID == item.Number).First(); |
| | | int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum); |
| | | List<dt_stationinfo> stationinfos = freeDB.Select<dt_stationinfo>().Where(x => x.stationCode.Contains("X") && x.quantity > 0 && !string.IsNullOrEmpty(x.stationType)).ToList(); |
| | | |
| | | //å¤å®ä»»å¡æ¯å¦å·²å建//å¦å·²åå¨ |
| | | if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0) |
| | | continue; |
| | | |
| | | if (item.quantity == 5 || CompeletedNum == 0) //循ç¯è¯»å车轮æ°ä¸º5æè
订å已宿æ°éçä¸æå£ âå·¥å人工å
³éçå·¥å |
| | | foreach (var item in stationinfos) |
| | | { |
| | | if (mesinfo.quantity <= 50) //å°äº50ä»¶ç´æ¥åºåº |
| | | { |
| | | //todo 寻æ¾å¯æ¾è´§å¤åæ¾è´§å° |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_fromaddress = item.stationCode, |
| | | agv_id = Guid.NewGuid(), |
| | | agv_grade = 0, |
| | | agv_barcode = "", |
| | | agv_createtime = DateTime.Now, |
| | | agv_taskstate = TaskStatus.Created.ToString(), |
| | | //agv_toaddress = , |
| | | //æ ¹æ®ä¸æå£çç»å®ä¿¡æ¯æ¥è¯¢å¯¹åºå·¥åï¼æ£æµæ¤å·¥åæ¯å¦å·²å®æ 宿å³å¯å°å
¶éå
¥åº |
| | | |
| | | }; |
| | | freeDB.Add(agvtask); |
| | | } |
| | | else |
| | | { |
| | | dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item); |
| | | dt_mes_head mesinfo = freeDB.Select<dt_mes_head>().Where(x => x.jobID == item.Number).First(); |
| | | dt_geometry_data dt_Geometry_Data = freeDB.Select<dt_geometry_data>().Where(x => x.Description == mesinfo.drawingNo).First(); |
| | | int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum); |
| | | |
| | | if (TargetLocation != null) |
| | | |
| | | //å¤å®ä»»å¡æ¯å¦å·²å建//å¦å·²åå¨ |
| | | if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0) |
| | | continue; |
| | | |
| | | if (item.quantity == 5 || CompeletedNum == 0) //循ç¯è¯»å车轮æ°ä¸º5æè
订å已宿æ°éçä¸æå£ âå·¥å人工å
³éçå·¥å |
| | | { |
| | | |
| | | |
| | | if (mesinfo.quantity <= 50 || item.stationCode.Contains("3")) //å°äº50ä»¶ç´æ¥åºåº |
| | | { |
| | | //todo: è°ç¨WMSæ¥å£åå»ºä»»å¡ |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository); |
| | | //todo 寻æ¾å¯æ¾è´§å¤åæ¾è´§å° |
| | | if (TargetLocation != null) |
| | | { |
| | | agv_fromaddress = item.stationCode, |
| | | agv_id = Guid.NewGuid(), |
| | | agv_grade = 0, |
| | | agv_barcode = "", |
| | | agv_createtime = DateTime.Now, |
| | | agv_taskstate = TaskStatus.Created.ToString(), |
| | | agv_toaddress = TargetLocation.stationCode, |
| | | }; |
| | | 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, |
| | | agv_TrayStatus = item.tray_status |
| | | }; |
| | | |
| | | freeDB.Add(agvtask); |
| | | TargetLocation.location_state = LocationStateEnum.Busy.ToString(); |
| | | freeDB.Update(TargetLocation); |
| | | freeDB.Add(agvtask); |
| | | TargetLocation.location_state = LocationStateEnum.Busy.ToString(); |
| | | freeDB.Update(TargetLocation); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data.e); |
| | | |
| | | if (TargetLocation != null) |
| | | { |
| | | //todo: è°ç¨WMSæ¥å£åå»ºä»»å¡ |
| | | 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_Inbound", |
| | | agv_toaddress = TargetLocation.stationCode, |
| | | agv_userid = "ç³»ç»", |
| | | bindSN = item.bindSN, |
| | | agv_worktype = Convert.ToInt32(mesinfo.processCode), |
| | | agv_materbarcode = mesinfo.materialCode, |
| | | agv_Traytype = item.tray_type, |
| | | agv_TrayStatus = item.tray_status |
| | | }; |
| | | |
| | | freeDB.Add(agvtask); |
| | | TargetLocation.location_state = LocationStateEnum.Busy.ToString(); |
| | | freeDB.Update(TargetLocation); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="workinfo">订å</param> |
| | | /// <param name="stationinfo">䏿å£ä¿¡æ¯</param> |
| | | /// <returns></returns> |
| | | private dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo) |
| | | private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo, int CompeletedNum, float e) |
| | | { |
| | | //æ¾è´§ä½ |
| | | dt_stationinfo TargetLocation = null; |
| | | |
| | | |
| | | #region æ ¹æ®è®¢åæ°éæ¥å¯»æ¾å¯¹åºåºåºä¸åç©æç±»ååºä½ |
| | | //if (workinfo.PlannedQuantity < 50) //åºåº1 ç©æç±»åå¤ |
| | |
| | | //} |
| | | #endregion |
| | | |
| | | //æ ¹æ®è®¢åçå·/å·¥åå·/ç±»å |
| | | if (mesinfo.quantity >= 180) |
| | | var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First(); |
| | | dt_inventory inventory = null; |
| | | if (detail.heatID != null) |
| | | { |
| | | //æ¥è¯¢åºåè®°å½ä¸æ¯å¦åå¨åç±»å/å·¥å/çå·çè®°å½ å¦æåæ¾ç½®åä¸è¡ï¼æ åå¯»æ¾æ°åºä½ |
| | | var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First(); |
| | | var inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID /*&& x.*/).First(); |
| | | if (inventory != null) |
| | | inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First(); |
| | | } |
| | | else |
| | | { |
| | | inventory = freeDB.Select<dt_inventory>().Where(x => x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First(); |
| | | } |
| | | |
| | | if (inventory != null) |
| | | { |
| | | var station = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode); |
| | | if (CompeletedNum <= 15 || station.area == "1") |
| | | { |
| | | int line = Convert.ToInt16(inventory.stationCode.Split("-")[0]); |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == line && x.location_state == LocationStateEnum.Empty.ToString() && x.area == inventory.area).FirstOrDefault(); |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == station.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.line).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | TargetLocation = stationinfoRepository.Find(x => x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == station.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault(); |
| | | } |
| | | if (TargetLocation != null) return TargetLocation; |
| | | } |
| | | |
| | | if (CompeletedNum <= 15) |
| | | { |
| | | TargetLocation = stationinfoRepository.Find(x => x.line == 1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | //if (50 < mesinfo.quantity && mesinfo.quantity <= 180 && e < 1100) |
| | | // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).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); |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); |
| | | if (TargetLocation == null) |
| | | TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "4" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); |
| | | } |
| | | |
| | | #region |
| | | |
| | | //æ ¹æ®è®¢åçå·/å·¥åå·/ç±»å |
| | | //if (mesinfo.quantity >= 180) |
| | | //{ |
| | | // //æ¥è¯¢åºåè®°å½ä¸æ¯å¦åå¨åç±»å/å·¥å/çå·çè®°å½ å¦æåæ¾ç½®åä¸è¡ï¼æ åå¯»æ¾æ°åºä½ |
| | | // var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First(); |
| | | // var inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First(); |
| | | // if (inventory != null) |
| | | // { |
| | | // //int line = Convert.ToInt16(inventory.stationCode.Split("-")[0]); |
| | | // var line = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode).line; |
| | | // TargetLocation = stationinfoRepository.Find(x => x.line == line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault(); |
| | | // if (TargetLocation == null && CompeletedNum <= 15) |
| | | // { |
| | | // TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // TargetLocation = stationinfoRepository.Find(x => x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); |
| | | |
| | | // } |
| | | //} |
| | | #endregion |
| | | |
| | | if (TargetLocation == null) |
| | | { |
| | |
| | | return TargetLocation; |
| | | } |
| | | |
| | | private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository) |
| | | { |
| | | dt_stationinfo TargetLocation = null; |
| | | List<string> target = new List<string>() { "W01001001", "W01001002", "W01001003" }; |
| | | foreach (var item in target) |
| | | { |
| | | TargetLocation = stationinfoRepository.FindFirst(x => x.stationCode == item && x.location_state == LocationStateEnum.Empty.ToString() && x.enable); |
| | | if (TargetLocation != null) continue; |
| | | } |
| | | |
| | | if (TargetLocation == null) |
| | | { |
| | | throw new Exception("å¤åå
¥åºå£å·²æ»¡"); |
| | | } |
| | | return TargetLocation; |
| | | } |
| | | /// <summary> |
| | | /// æ ¹æ®è®¢åæ°éè¿ååºåº(ææ¶å¼ç¨) //æ´æ¢ä¸ºåºä½ç±»åå¹é
|
| | | /// </summary> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | private string GetArea(int quantity) |
| | | private static string GetArea(int quantity, float e) |
| | | { |
| | | if (quantity >= 50 && quantity < 180) |
| | | return "2"; |
| | | else if (quantity >= 180 && quantity < 180) |
| | | return "3"; |
| | | else if (quantity >= 180 && quantity < 220) |
| | | if (e < 1100) |
| | | { |
| | | if (quantity <= 180) |
| | | return "2"; |
| | | else if (quantity <= 225) |
| | | return "3"; |
| | | } |
| | | else |
| | | { |
| | | return "4"; |
| | | } |
| | | |
| | | //if (quantity > 50 && quantity <= 180 && e < 1100) |
| | | // return "2"; |
| | | //else if (quantity > 180 && quantity <= 225 && e < 1100) |
| | | // return "3"; |
| | | //else if (quantity > 50 && e > 1100) |
| | | // return "4"; |
| | | return null; |
| | | } |
| | | } |