分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-03-25 9c6f213884183f6f3a49f224fc9723e84e53f226
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
 
namespace WIDESEA_WCS.JobsPart.Common
{
    public class EmptyTrayTask
    {
 
        /// <summary>
        /// 创建补空托任务
        /// </summary>
        public static void CreateEmptyTrayTask()
        {
            try
            {
                var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "链条机");
                if (Pipeline_client == null) throw new Exception("链条机调度服务未开启!");
                if (!Pipeline_client.IsConnected) throw new Exception("与链条机连接超时!");
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
                List<string> strings = new List<string>() { };
                var stations = stationinfoRepository.Find(x => x.stationCode.Contains("X") || x.stationCode.Contains("W01001004") || x.stationCode.Contains("W01001005")).ToList();
                stations = stations.Where(x => x.location_state == "Empty" && x.enable).ToList();
                foreach (var station in stations)
                {
                    if (agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).Any())
                        continue;
                    var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", station.stationCode);//读取托盘信号:1:有,2无
                    var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", station.stationCode);//读取货物信号:1:有,2无
                    if (PalletSignal == 2 && MaterialSignal == 2)
                    {
                        dt_agvtask taskPart = new dt_agvtask()
                        {
                            agv_fromaddress = "",
                            agv_id = Guid.NewGuid(),
                            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                            agv_grade = 2,
                            agv_createtime = DateTime.Now,
                            agv_taskstate = "Queue",
                            agv_qty = 1,
                            agv_tasktype = "TaskType_EmptyPallet",
                            agv_toaddress = station.stationCode,
                            agv_userid = "系统",
                            agv_TrayStatus = "EmptyTray",// station.tray_status,
                            agv_Traytype = station.tray_type
                        };
                        station.location_state = LocationStateEnum.Busy.ToString();
                        stationinfoRepository.Update(station, true);
                        agvtaskRepository.Add(taskPart, true);
                        WriteDBLog.Success("创建补空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("创建补空托任务", $"错误信息:{ex.Message}", "PCS");
            }
        }
 
        /// <summary>
        /// 库内补空托任务
        /// </summary>
        public static void InEmptyTrayTask()
        {
            try
            {
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
                var stations = stationinfoRepository.Find(x => x.area == "2" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
                if (stations.Count < 1)
                {
                    stations = stationinfoRepository.Find(x => x.area == "3" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
                }
                foreach (var station in stations)
                {
                    if (agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).Any())
                        continue;
                    dt_agvtask taskPart = new dt_agvtask()
                    {
                        agv_fromaddress = "",
                        agv_id = Guid.NewGuid(),
                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                        agv_grade = 2,
                        agv_createtime = DateTime.Now,
                        agv_taskstate = "Queue",
                        agv_qty = 1,
                        agv_tasktype = "TaskType_EmptyPallet",
                        agv_toaddress = station.stationCode,
                        agv_userid = "系统",
                        agv_TrayStatus = "EmptyTray",// station.tray_status, "SmallTray" : "LargeTray"
                        agv_Traytype = station.area == "4" ? "LargeTray" : "SmallTray",
                    };
                    agvtaskRepository.Add(taskPart, true);
                    station.location_state = LocationStateEnum.InBusy.ToString();
                    stationinfoRepository.Update(station, true);
                    WriteDBLog.Success("创建补库内空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("创建补库内空托任务", $"错误信息:{ex.Message}", "PCS");
                //throw;
            }
        }
    }
}