using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Comm; using WIDESEA_Comm.TaskNo; using WIDESEA_Common; using WIDESEA_Core.EFDbContext; using WIDESEA_Core.Utilities; using WIDESEA_Entity.DomainModels; using WIDESEA_WMS.IRepositories; using WIDESEA_WMS.Repositories; using static FreeSql.Internal.GlobalFilter; using static System.Collections.Specialized.BitVector32; namespace WIDESEA_WMS { public partial class ToMesServer { /// /// 库内移库 /// /// /// /// public WebResponseContent shiftingparking(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); VOLContext context = new VOLContext(); Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context); Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context); try { string user = saveModel.MainData["creator"].ToString(); string from_address = saveModel.MainData["from_address"].ToString(); string to_address = saveModel.MainData["to_address"].ToString(); var station1 = stationinfoRepository.Find(t => t.stationCode == from_address).FirstOrDefault(); if (station1 == null) return content.Error("请输入正确的起点地址!"); var station2 = stationinfoRepository.Find(t => t.stationCode == to_address).FirstOrDefault(); if (station2 == null) return content.Error("请输入正确的起点地址!"); if (!station1.tray_type.Contains("Small") && station2.area != "4") throw new Exception($"大托盘只能存放在库区4!"); if (agvtaskRepository.Find(x => x.agv_fromaddress.Contains(from_address) || x.agv_toaddress.Contains(from_address)).Any()) throw new Exception($"起点{from_address}已存在任务!"); if (agvtaskRepository.Find(x => x.agv_fromaddress.Contains(to_address) || x.agv_toaddress.Contains(to_address)).Any()) throw new Exception($"终点{to_address}已存在任务!"); if (station1.location_state != LocationStateEnum.Stroge.ToString()) throw new Exception($"起点{from_address}不是有货!"); if (station2.location_state != LocationStateEnum.Empty.ToString()) throw new Exception($"终点{to_address}不是空货位!"); if (string.IsNullOrEmpty(station1.stationType)) throw new Exception($"起点{from_address}未绑定物料类型!"); if (station2.area == "1") { if (stationinfoRepository.Find(x => x.area == station2.area && x.column == station2.column && x.location_state != LocationStateEnum.Empty.ToString() && x.stationType != station1.stationType).Any()) throw new Exception($"终点{to_address}同列存在与起点物料类型不匹配!"); } else { if (stationinfoRepository.Find(x => x.area == station2.area && x.line == station2.line && x.location_state != LocationStateEnum.Empty.ToString() && x.stationType != station1.stationType).Any()) throw new Exception($"终点{to_address}同行存在与起点物料类型不匹配!"); } var inventory = inventoryRepository.Find(x => x.stationCode == station1.stationCode).FirstOrDefault(); if (inventory == null) throw new Exception($"起点{from_address}未找到库存信息!"); dt_agvtask agvtask = new dt_agvtask() { agv_fromaddress = station1.stationCode, agv_id = Guid.NewGuid(), agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), agv_grade = 1, agv_createtime = DateTime.Now, agv_taskstate = "Create", agv_materielid = station1.stationType, agv_qty = station1.quantity, agv_tasktype = AGVTaskTypeEnum.TaskType_Carry.ToString(), agv_toaddress = station2.stationCode, agv_userid = user,//"系统", jobID = station1.Number,// mes_head.jobID, bindSN = station1.bindSN, agv_worktype = 0, //Convert.ToInt32(mes_head.processCode), agv_materbarcode = inventory.materialCode, agv_Traytype = station1.tray_type, agv_TrayStatus = station1.tray_status }; agvtaskRepository.Add(agvtask, true); station1.location_state = LocationStateEnum.OutBusy.ToString(); stationinfoRepository.Update(station1, true); station2.location_state = LocationStateEnum.InBusy.ToString(); station2.heatNumber = station1.heatNumber; station2.Number = station1.Number; station2.stationType = station1.stationType; stationinfoRepository.Update(station2, true); content.OK(); } catch (Exception ex) { content.Error($"呼叫AGV失败:{ex.Message}"); } return content; } } }