using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using WIDESEA_Common; using WIDESEA_Common.Tools; using WIDESEA_Core.EFDbContext; using WIDESEA_Core.Utilities; using WIDESEA_Entity.DomainModels; using WIDESEA_Services; using WIDESEA_Services.IRepositories; using WIDESEA_Services.Repositories; using WIDESEA_Services.Services; using WIDESEA_WCS.WCSClient; namespace WIDESEA_WCS.Jobs { public partial class EquipmentExecutor : SchedulerExecuteBase { private static int _readFJCBJSignalso = 0; /// /// 拆包站逻辑流程 /// /// /// public static void CBJtask() { if (Interlocked.Exchange(ref _readFJCBJSignalso, 1) == 0) { try { VOLContext Context = new VOLContext(); WebResponseContent responseContent = new WebResponseContent(); Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context); dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep); Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context); Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context); Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context); Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context); Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context); // 抓取PDA主盘表数据 var PDAtask = pdaRepository.FindFirst(v => v.ishandle == 1); if (PDAtask != null) { //查询起点站台的路由 var routes = routingRepository.Find(v => v.route_began == PDAtask.Devid).ToList(); foreach (var route in routes) { //判断终点位置是否可用 PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "负极1号AGV"); //读取PLC信号是否能放货 string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), route.route_end).ToString(); //查询WCS自己的货位判断是否有货 var location = locRepository.FindFirst(v => v.upper_code == route.route_end); if (isWork == "1" && location.location_state == LocationStateEnum.LocationState_Empty.ToString()) { //条件通过即可创建AGV任务 dt_agvtask agvtask = new dt_agvtask { agv_materbarcode = PDAtask.BarCode, agv_barcode = "", agv_code = "负极1号AGV", agv_createtime = DateTime.Now, agv_fromaddress = route.route_began, agv_grade = 1, agv_materielid = PDAtask.MaterialType, agv_qty = 1, agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep), agv_taskstate = "Create", agv_tasktype = "TaskType_Outbound", agv_toaddress = route.route_end, agv_userid = "WCS", agv_worktype = 1 }; agvRepository.Add(agvtask, true); WriteLog.Info("CBJtask").Write("CBJtask接口" + agvtask.agv_tasknum + DateTime.Now, "CBJtask"); //AGV任务生成后修改PDA组盘表 PDAtask.ishandle = 0; //pdaRepository.Delete(item, true); //修改终点货架存储状态 location.location_state = LocationStateEnum.LocationState_Lock.ToString(); locRepository.Update(location, true); //添加库存信息 bill_group_stock stock = new bill_group_stock(); stock.stock_id = Guid.NewGuid(); stock.MaterialType = PDAtask.MaterialType; stock.BarCode = PDAtask.BarCode; stock.MaterialStatus = PDAtask.MaterialStatus; stock.first_tb = 0; stock.TB_Status = ""; stock.FQ_Status = ""; stock.GY_Status = ""; stock.QX_Status = ""; stock.created_user = "WCS"; stock.created_time = DateTime.Now; stock.updated_user = "WCS"; stock.updated_time = DateTime.Now; groupRepository.Add(stock, true); //给MES回传物料移动信息 //MESAPIInvoke.BindMaterialDevid(PDAtask.Devid, route.route_end, PDAtask.MaterialType, PDAtask.BarCode, PDAtask.MaterialStatus); break; } } } } catch (Exception ex) { } finally { Interlocked.Exchange(ref _readCBJSignalso, 0); } //responseContent = SendTask(client.PLCName, () => //{ // //任务下发逻辑编写 // throw new Exception(); //}); } } } }