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
using Microsoft.CodeAnalysis;
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_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    public partial class StackerExecutor
    {
        public static object requestFJTBUP = new object();//requestZJJK
        private static int _readFTBSignalsoZ = 0;//_readZTBUPSignalso
        /// <summary>
        /// 负极涂布上料工作逻辑
        /// </summary>
        /// <param name="client"></param>
        public static void F_TBSB_UpTask()
        {
            if (Interlocked.Exchange(ref _readFTBSignalsoZ, 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)
                        {
                            string SB_Up_Location = "FJSL-TBSB" + TBSB.Replace("涂布机负极", "");//拼接涂布上料口
                            if (WCSService.Clients == null)
                            {
                                return;
                            }
                            PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB);
                            if (plc == null)
                            {
                                continue;
                            }
                            //当前设备有没有上料请求
                            bool GYR_RFX = plc.OmronPLCClient.OmronFinsNetClient.ReadBool("D11093.00").Content;
                            //Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), SB_Up_Location));
                            if (GYR_RFX)
                            {
                                //查看当前涂布机设备是否有AGV任务
                                var SBtask = agvRepository.FindFirst(f => f.agv_fromaddress == SB_Up_Location || f.agv_toaddress == SB_Up_Location);
                                //有结束本次循环
                                if (SBtask != null) { continue; }
                                #region 记录上料请求信号
                                WriteLog.GetLog().Write($"{plc.PLCName}上料请求:{GYR_RFX}---{DateTime.Now}", $"负极涂布上料请求");
                                #endregion
                                //找到对应箔材库货位(36号位置),并确认有料
                                base_ware_location location_36 = locRepository.FindFirst(t => t.upper_code == "FJ-BCHCJ36" && t.location_state == LoctionStateEnum.LocationState_Stored.ToString() && t.status == 1 && t.logic_col == 1 && t.task == 2);
 
                                if (location_36 != null)
                                {
                                    dt_agvtask agvtask_36 = agvRepository.Find(t => t.agv_fromaddress == location_36.upper_code).FirstOrDefault();
                                    if (agvtask_36 != null)
                                    {
                                        return;
                                    }
 
                                    //生成涂布机上料任务
                                    dt_agvtask agvtask = new dt_agvtask()
                                    {
                                        agv_id = Guid.NewGuid(),
                                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                        agv_fromaddress = location_36.upper_code,
                                        agv_toaddress = SB_Up_Location,
                                        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 = "",
                                    };
 
                                    //WriteLog.GetLog($"任务生成记录").Write($"任务号:{agvtask.agv_tasknum},起点{location_36.upper_code}光电:{location_36.created_user}=>终点:{SB_Up_Location},任务已生成", "任务生成记录");
 
 
                                    location_36.task = 1;
                                    location_36.update_time = DateTime.Now;
                                    int a = locRepository.Update(location_36, d => new { d.task, d.update_time }, true);
                                    if (a == 1)
                                    {
                                        agvRepository.Add(agvtask, true);
                                    }
                                    //WriteLog.GetLog("设备呼叫").Write($"设备{TBSB},呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫");
                                    break;
                                }
                                else
                                {
                                    //WriteLog.GetLog("设备呼叫").Write($"设备 {TBSB} 上料呼叫,未找到满足搬运条件的货架,任务生成失败", "设备呼叫");
                                }
                            }
 
 
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog.GetLog().Write($"负极棍分上料:{DateTime.Now} --------------{ex}", $"负极棍分上料调度");
                    }
                    finally
                    {
                        Interlocked.Exchange(ref _readFTBSignalsoZ, 0);
                    }
                });
                
            }
        }
 
    }
}