wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
wcs-server-hbf/WIDESEA_WCS/SchedulerExecute/Equipment/Z_TSJ_DownTask.cs
@@ -1,6 +1,7 @@
using HslCommunication;
using System;
using System.Threading;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Common.Tools;
@@ -28,87 +29,89 @@
            if (Interlocked.Exchange(ref _readTSJDOWNSignalsoZTSJ, 1) == 0)
            {
                try
                Task.Run(() =>
                {
                    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);
                    Idt_agvtask_htyRepository agvhtyRepository = new dt_agvtask_htyRepository(Context);
                    Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
                    PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "正极箔材提升机");
                    if (plc == null)
                    try
                    {
                        //WriteLog.GetLog("TSJ下料呼叫").Write($"设备:正极箔材提升机  内容:未连接PLC  时间记录:{DateTime.Now}", "TSJ下料呼叫");
                        return;
                    }
                    //当前设备有没有下料请求
                    //bool TSJ_CL = Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), plc.PLCDescroption));
                    OperateResult<bool> TSJ_CL = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB51.93");
                    if (TSJ_CL.Content)
                    {
                        //查看当前辊分机设备是否有AGV任务
                        var SBtask = agvRepository.FindFirst(f => f.agv_fromaddress == plc.PLCDescroption);
                        //有结束本次循环
                        if (SBtask != null) { return; }
                        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);
                        Idt_agvtask_htyRepository agvhtyRepository = new dt_agvtask_htyRepository(Context);
                        Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
                        base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == "ZJ-BCHCJ35" && d.location_state == LoctionStateEnum.LocationState_Empty.ToString() && d.tpgd == 0 && d.status == 1 && d.task == 2);
                        if (ware_Locations != null)
                        PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "正极箔材提升机");
                        if (plc == null)
                        {
                            //生成提升机机下料任务
                            dt_agvtask agvtask = new dt_agvtask()
                            //WriteLog.GetLog("TSJ下料呼叫").Write($"设备:正极箔材提升机  内容:未连接PLC  时间记录:{DateTime.Now}", "TSJ下料呼叫");
                            return;
                        }
                        //当前设备有没有下料请求
                        //bool TSJ_CL = Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), plc.PLCDescroption));
                        OperateResult<bool> TSJ_CL = plc.SiemensPLCClient.SiemensS7NetClient.ReadBool("DB51.93");
                        if (TSJ_CL.Content)
                        {
                            //查看当前辊分机设备是否有AGV任务
                            var SBtask = agvRepository.FindFirst(f => f.agv_fromaddress == plc.PLCDescroption);
                            //有结束本次循环
                            if (SBtask != null) { return; }
                            base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == "ZJ-BCHCJ35" && d.location_state == LoctionStateEnum.LocationState_Empty.ToString() && d.tpgd == 0 && d.status == 1 && d.task == 2);
                            if (ware_Locations != null)
                            {
                                agv_id = Guid.NewGuid(),
                                agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                agv_fromaddress = plc.PLCDescroption,
                                agv_toaddress = ware_Locations.upper_code,
                                agv_code = "正极AGV调度",
                                agv_remark = "正极提升机下料",
                                agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                                agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
                                agv_worktype = 1,//工作类型
                                agv_materielid = "",
                                agv_qty = 1,
                                agv_createtime = DateTime.Now,
                                agv_grade = 0,//任务优先级
                                agv_userid = "WCS",
                                agv_barcode = "",
                            };
                            ware_Locations.update_time = DateTime.Now;
                            ware_Locations.task = 1;
                          int a=  locRepository.Update(ware_Locations, d => new { d.task, d.update_time }, true);
                            if (a==1)
                            {
                                agvRepository.Add(agvtask, true);
                                WriteDBLog.Info($"正极提升机下料任务生成").Write($"生成任务:{agvtask.agv_tasknum},终点货位【{ware_Locations.upper_code}】状态:托盘光电检测:{ware_Locations.tpgd},状态:{ware_Locations.location_state},更新时间:{ware_Locations.wireless_time}", $"正极提升机下料任务生成");
                                WriteDBLog.Info($"正极提升机下料任务生成").Write($"----------------任务生成成功  {DateTime.Now} -------------- {Environment.NewLine}", $"正极提升机下料任务生成");
                                //生成提升机机下料任务
                                dt_agvtask agvtask = new dt_agvtask()
                                {
                                    agv_id = Guid.NewGuid(),
                                    agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                    agv_fromaddress = plc.PLCDescroption,
                                    agv_toaddress = ware_Locations.upper_code,
                                    agv_code = "正极AGV调度",
                                    agv_remark = "正极提升机下料",
                                    agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                                    agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
                                    agv_worktype = 1,//工作类型
                                    agv_materielid = "",
                                    agv_qty = 1,
                                    agv_createtime = DateTime.Now,
                                    agv_grade = 0,//任务优先级
                                    agv_userid = "WCS",
                                    agv_barcode = "",
                                };
                                ware_Locations.update_time = DateTime.Now;
                                ware_Locations.task = 1;
                                int a = locRepository.Update(ware_Locations, d => new { d.task, d.update_time }, true);
                                if (a == 1)
                                {
                                    agvRepository.Add(agvtask, true);
                                    //WriteDBLog.Info($"正极提升机下料任务生成").Write($"生成任务:{agvtask.agv_tasknum},终点货位【{ware_Locations.upper_code}】状态:托盘光电检测:{ware_Locations.tpgd},状态:{ware_Locations.location_state},更新时间:{ware_Locations.wireless_time}", $"正极提升机下料任务生成");
                                    //WriteDBLog.Info($"正极提升机下料任务生成").Write($"----------------任务生成成功  {DateTime.Now} -------------- {Environment.NewLine}", $"正极提升机下料任务生成");
                                }
                                //WriteLog.GetLog("设备呼叫").Write($"设备{plc.PLCName}呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫");
                            }
                            //WriteLog.GetLog("设备呼叫").Write($"设备{plc.PLCName}呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫");
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog.GetLog().Write($"正极提升机下料:{DateTime.Now} --------------{ex}", $"正极提升机下料");
                    }
                    finally
                    {
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    Interlocked.Exchange(ref _readTSJDOWNSignalsoZTSJ, 0);
                }
                        Interlocked.Exchange(ref _readTSJDOWNSignalsoZTSJ, 0);
                    }
                });
            }
        }