分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-21 1a15a93fd26457ef3da68d931fd941e652945a9b
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using Confluent.Kafka;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using OfficeOpenXml.FormulaParsing.Excel.Operators;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.MES_Info;
using WIDESEA_Comm.MES_Info.Request;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.ToAGV;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static WIDESEA_Comm.MES_Info.BasicSN;
 
namespace WIDESEA_WMS.Common.AGVTask
{
    public class HandleTask_Mes
    {
        static FreeDB FreeDB = new FreeDB();
        /// <summary>
        /// 向MES反馈出入库信息
        /// </summary>
        /// <param name="task"></param>
        /// <exception cref="Exception"></exception>
        public static void UploadMESInfo(dt_agvtask task)
        {
            object obj = new object();  //上传MES数据
            string ActionName = "";  //调用MES方法名
            string name = "";
            MES_Response requestMes = new MES_Response();
            try
            {
                List<detail> list = new List<detail>(); //车轮信息
                if (task == null)
                {
                    throw new Exception("无任务数据");
                }
                VOLContext context = new VOLContext();
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
                Idt_info_to_mesRepository mesRepository = new dt_info_to_mesRepository(context);
                if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString() || task.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceCarry.ToString())
                {
                    if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString())
                    {
                        foreach (var item in task.bindSN.Split(","))
                        {
                            var work = workinfoRepository.Find(x => x.SN == item && x.processCode == task.agv_worktype.ToString()).FirstOrDefault();
                            detail detail = new detail();
                            detail.sn = item;
                            detail.jobID = work.jobID;
                            detail.processCode = work.processCode;
                            list.Add(detail);
                        }
                    }
                    else
                    {
                        foreach (var item in task.bindSN.Split(","))
                        {
                            detail detail = new detail();
                            detail.sn = item;
                            detail.jobID = task.jobID;
                            detail.processCode = task.agv_worktype.ToString();
                            list.Add(detail);
                        }
                    }
 
                    agvInWarehousePara outWarehousePara = new agvInWarehousePara()
                    {
                        WorkOrder = task.jobID,
                        zoneID = task.agv_fromaddress,
                        details = list,
                        layerNo = 1,
                        stackID = "1",
                        warehouseName = "Agv库",
                        Operator = "AGV自动",
                    };
                    obj = outWarehousePara;
                    ActionName = "agvOutWarehouse";//AGV->MES车轮出库
                    name = "AGV同步MES车轮出库";
                }
                else if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Inbound.ToString())
                {
                    foreach (var item in task.bindSN.Split(","))
                    {
                        var work = workinfoRepository.Find(x => x.SN == item && x.processCode == task.agv_worktype.ToString()).FirstOrDefault();
                        detail detail = new detail();
                        detail.sn = item;
                        detail.jobID = work.jobID;
                        detail.processCode = work.processCode;
                        list.Add(detail);
                    }
                    agvInWarehousePara inWarehousePara = new agvInWarehousePara()
                    {
                        WorkOrder = task.jobID,
                        zoneID = task.agv_toaddress,
                        details = list,
                        layerNo = 1,
                        stackID = "1",
                        warehouseName = "Agv库",
                        Operator = "AGV自动",
                    };
                    obj = inWarehousePara;
                    ActionName = "agvInWarehouse";//AGV->MES车轮入库
                    name = "AGV同步MES车轮入库";
                }
                else if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Carry.ToString())  //移库区分  库内移库
                {
                    List<detail1> list1 = new List<detail1>(); //车轮信息
                    foreach (var item in task.bindSN.Split(","))
                    {
                        detail1 detail = new detail1();
                        detail.sn = item;
                        list1.Add(detail);
                    }
                    agvMoveWarehousePara moveWarehousePara = new agvMoveWarehousePara()
                    {
                        fromZoneID = task.agv_fromaddress,
                        toZoneID = task.agv_toaddress,
                        details = list1,
                        fromLayerNo = "1",
                        fromStackID = "1",
                        fromWarehouseName = "Agv库",
                        toLayerNo = "1",
                        toStackID = "1",
                        toWarehouseName = "Agv库",
                        Operator = "AGV自动",
                    };
                    obj = moveWarehousePara;
                    ActionName = "agvMoveWarehouse";//AGV->MES车轮移库
                    name = "AGV同步MES车轮AB库移库";
                }
                var postJson = JsonConvert.SerializeObject(obj);
                if (!string.IsNullOrEmpty(ActionName))
                {
                    dt_info_to_mes info_To_Mes = new dt_info_to_mes()
                    {
                        Info = postJson,
                        ActionName = ActionName,
                        Createtime = DateTime.Now,
                        Remark = name,
                        State = false
                    };
                    mesRepository.Add(info_To_Mes, true);
                }
            }
            catch (Exception ex)
            {
 
            }
        }
    }
}