wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using HslCommunication;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Extensions;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    public partial class StackerExecutor
    {
        public static object requestFJGFUP = new object();//requestZJJK
        private static int _readGFBUPSignalsoF = 0;//_readZTBUPSignalso
        /// <summary>
        /// 负极辊分上料工作逻辑
        /// </summary>
        /// <param name="client"></param>
        public static void F_GFSB_UpTask()
        {
            if (Interlocked.Exchange(ref _readGFBUPSignalsoF, 1) == 0)
            {
                Task.Run(() =>
                {
                    try
                    {
                        VOLContext Context = new VOLContext();
                        Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
                        Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
                        Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
                        List<string> TBSBS = new List<string> { "辊分机负极1", "辊分机负极2", "辊分机负极3", "辊分机负极4" };
 
                        foreach (var TBSB in TBSBS)
                        {
                            PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB);
                            if (plc == null)
                            {
                                //WriteLog.GetLog("GFF上料呼叫").Write($"设备:{TBSB} 内容:未连接PLC 时间记录: { DateTime.Now }" , "GFF上料呼叫");
                                continue;
                            }
 
                            //当前设备有没有上料请求
                            OperateResult<bool> GYR_RFX = plc.MelsecPLCClient.MelsecMcNetClient.ReadBool("D5493.0");
                            Int16 tf = Convert.ToInt16(GYR_RFX.Content);
                            if (GYR_RFX.Content)
                            {
                                //查看当前辊分机设备是否有AGV任务
                                var SBtask = agvRepository.FindFirst(f => f.agv_toaddress == plc.EquipType);
                                //有结束本次循环
                                if (SBtask != null) { continue; }
                                #region 记录上料请求信号
                                WriteLog.GetLog().Write($"{plc.PLCName}上料请求:{GYR_RFX.Content}---{DateTime.Now}", $"负极棍分上料请求");
                                #endregion
                                List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == plc.EquipType);
                                List<base_ware_location> loctionList = new List<base_ware_location>();
                                foreach (var item in Routing_Table)
                                {
                                    base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == item.route_began && d.status == 1 && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.logic_col == 1 && d.task == 2);
                                    if (ware_Locations == null)
                                    {
                                        continue;
                                    }
                                    loctionList.Add(ware_Locations);
                                }
 
                                if (loctionList.Count != 0)
                                {
                                    base_ware_location Location = loctionList.OrderBy(d => d.update_time).FirstOrDefault();
 
                                    //生成辊分机上料任务
                                    dt_agvtask agvtask = new dt_agvtask()
                                    {
                                        agv_id = Guid.NewGuid(),
                                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                        agv_fromaddress = Location.upper_code,
                                        agv_toaddress = plc.EquipType,
                                        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 = "",
                                    };
 
                                    //Location.update_time = DateTime.Now;
                                    Location.task = 1;
                                    Location.logic_col = 1;
                                    var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                    if (entry != null)
                                    {
                                        entry.State = EntityState.Detached;
                                    }
                                    int a = locRepository.Update(Location, d => new { d.task, d.logic_col }, true);
                                    if (a == 1)
                                    {
                                        agvRepository.Add(agvtask, true);
                                    }
 
                                }
 
 
                            }
 
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog.GetLog().Write($"负极棍分上料:{DateTime.Now} --------------{ex}", $"负极棍分上料调度");
                    }
                    finally
                    {
                        Interlocked.Exchange(ref _readGFBUPSignalsoF, 0);
                    }
                });
               
            }
        }
 
    }
}