wangxinhui
2024-09-23 a3eb67538c4716aef9967f1e6301720cce095e3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using HslCommunication;
using System;
using System.Threading;
using WIDESEA_Common;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    public partial class StackerExecutor
    {
        public static object requestFJTSJ = new object();//requestZJJK
        private static int _readTSJDOWNSignalsoFTSJ = 0;//_readZTBUPSignalso
 
        /// <summary>
        /// 负极辊分下料工作逻辑
        /// </summary>
        /// <param name="client"></param>
        public static void F_TSJ_DownTask()
        {
 
            if (Interlocked.Exchange(ref _readTSJDOWNSignalsoFTSJ, 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);
                    Idt_agvtask_htyRepository agvhtyRepository = new dt_agvtask_htyRepository(Context);
                    Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
 
                    if (WCSService.Clients == null)
                    {
                        return;
                    }
                    PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "负极箔材提升机");
                    if (plc == null)
                    {
                        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 == "FJ-BCHCJ37" && d.location_state == LoctionStateEnum.LocationState_Empty.ToString() && d.tpgd == 0 && d.status == 1 && d.task == 2);
                        if (ware_Locations != null)
                        {
                            //生成提升机机下料任务
                            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.task = 1;
                            ware_Locations.update_time = DateTime.Now;
                          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.PLCDescroption} 呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫");
                        }
                    }
 
 
                }
                catch (Exception)
                {
 
                    throw;
                }
                finally
                {
 
                    Interlocked.Exchange(ref _readTSJDOWNSignalsoFTSJ, 0);
                }
            }
        }
 
    }
}