wangxinhui
2024-12-26 78b99e5348592a29ca1393a5e13db619cc4eba56
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 Microsoft.CodeAnalysis;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
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
    {
        private static int _readRKSB_Up = 0;
        /// <summary>
        /// 入壳机上料
        /// </summary>
        /// <param name="client"></param>
        public static void RKSB_UpTask()
        {
            if (Interlocked.Exchange(ref _readRKSB_Up, 1) == 0)
            {
                Task.Run(() =>
                {
                    try
                    {
                        VOLContext Context = new VOLContext();
                        Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
                        Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                        Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
                        List<string> RKSBS = new List<string> { "入壳机1", "入壳机2"};
                        //循环处理入壳机设备上料请求
                        foreach (var RKSB in RKSBS)
                        {
                            if (WCSService.Clients == null)
                            {
                                return;
                            }
                            PLCClient plc = WCSService.Clients.Find(v => v.PLCName == RKSB);
                            if (plc == null)
                            {
                                continue;
                            }
                            string SB_Up_Location = "SL-RKSB" + RKSB.Replace("入壳机", "");//拼接入壳上料口
                            string equipType = "RKSB" + RKSB.Replace("入壳机", "");//设备
                            //获取当前入壳设备是否有上料AGV任务
                            var SBtask = agvRepository.FindFirst(f => f.agv_toaddress == SB_Up_Location);
                            //有结束本次循环
                            if (SBtask != null) { continue; }
                            //获取当前设备的上料请求
                            int requestRKUP = plc.ModbusPLCClient.ModbusTcpNetClient.ReadInt16("5306").Content;
                            if (requestRKUP==4)
                            {
                                //找到对应缓存架货位,并确认有料
                                dt_stationinfo location = stationinfoRepository.Find(x=>x.area== equipType && x.greenbutton == true 
                                && x.tpgd == true && x.wlgd == true && x.task == false).OrderBy(x=>x.greenbuttontime).FirstOrDefault();
                                if (location != null)
                                {
                                    #region 记录上料请求信号
                                    WriteLog.GetLog().Write($"{plc.PLCName}上料请求:{requestRKUP}---{DateTime.Now}", $"入壳机上料请求");
                                    #endregion
                                    //生成入壳机上料任务
                                    dt_agvtask agvtask = new dt_agvtask()
                                    {
                                        agv_id = Guid.NewGuid(),
                                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                        agv_fromaddress = location.stationCode,
                                        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 = "",
                                    };
                                    location.task = true;
                                    int changeCount = locRepository.Update(location, d => new { d.task }, true);
                                    if (changeCount == 1)
                                    {
                                        agvRepository.Add(agvtask, true);
                                    }
                                    break;
                                }
                            }
 
 
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog.GetLog().Write($"入壳机上料:{DateTime.Now} --------------{ex}", $"入壳机上料调度Error");
                    }
                    finally
                    {
                        Interlocked.Exchange(ref _readRKSB_Up, 0);
                    }
                });
 
            }
        }
 
    }
}