qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
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
using HslCommunication;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using WIDESEA_Common;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS.Jobs
{
    public partial class EquipmentExecutor : SchedulerExecuteBase
    {
        private static int _readZHKUPSignalso = 0;
        public static void Z_HKSB_UpTask()
        {
            if (Interlocked.Exchange(ref _readZHKUPSignalso, 1) == 0)
            {
                try
                {
                    VOLContext Context = new VOLContext();
                    WebResponseContent responseContent = new WebResponseContent();
                    Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
                    dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
                    Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
                    Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
                    Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
                    Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
                    Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
                    List<string> HKSBs = new List<string> { "正极3号烘烤机", "正极4号烘烤机", "正极5号烘烤机", "正极6号烘烤机",
                    "正极7号烘烤机", "正极8号烘烤机", "正极9号烘烤机", "正极10号烘烤机",
                        "负极3号烘烤机", "负极4号烘烤机","负极5号烘烤机", "负极6号烘烤机", "负极7号烘烤机", "负极8号烘烤机",
                     "负极9号烘烤机", "负极10号烘烤机" };
                    //List<string> HKSBs = new List<string> { "正极9号烘烤机", "正极10号烘烤机" };
                    foreach (var hksb in HKSBs)
                    {
                        WriteLog.Info($"{hksb}上料").Write($"{hksb}开始,时间:" + DateTime.Now + "   ----------", $"{hksb}上料");
                        PLCClient plc = WCSService.Clients.Find(v => v.PLCName == hksb);
                        if (plc == null)
                            continue;
                        var hxtask = agvRepository.FindFirst(f => f.agv_fromaddress.Contains("KPHLX") && f.agv_toaddress == plc.PLCDescroption);
                        if (hxtask != null) { GetEquipmentInfo(plc.PLCDescroption, "", "当前有烘箱回流任务", "", ""); continue; }
                        //启用工单
                        string IsBatchNo = plc.ReadValue(ConveyorLineInfoDBName.R_HKSB_IsWorkBatchNo.ToString(), plc.PLCDescroption).ToString();
                        if (IsBatchNo == "False") { GetEquipmentInfo(plc.PLCDescroption, "", "烘箱启用工单为"+IsBatchNo, "", ""); continue; }
                        WriteLog.Info($"{hksb}上料").Write($"IsBatchNo:{IsBatchNo},时间:" + DateTime.Now + "   ----------", $"{hksb}上料");
                        var task = new List<dt_agvtask>();
                        if (plc.PLCDescroption.Contains("ZJSL"))
                        {
                            task = agvRepository.Find(f => f.agv_remark.Contains("ZJSL") && f.agv_taskstate == "WaitStockOut").ToList();
                        }
                        else
                        {
                            task = agvRepository.Find(f => f.agv_remark.Contains("FJSL") && f.agv_taskstate == "WaitStockOut").ToList();
                        }
                        if (task.Count >= 1)
                            continue;
                        var stock = groupRepository.Find(v => v.Remark1 == plc.PLCDescroption).ToList();
                        if (stock.Count >= 1)
                            continue;
                        //获取上料请求
                        string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_HKSB_UPrequest.ToString(), plc.PLCDescroption).ToString();
                        WriteLog.Info($"{hksb}上料").Write($"isWork:{isWork},时间:" + DateTime.Now + "   ----------", $"{hksb}上料");
                        GetEquipmentInfo(plc.PLCDescroption, isWork, "", "", "");
                        if (isWork != "5")
                            continue;
                        WebResponseContent content = new WebResponseContent();
                        string[] tasknum = tasknumber.GetTaskNumber(tasknumberRep, 2).Split(";");
                        responseContent = agvRepository.DbContextBeginTransaction(() =>
                        {
                            for (int i = 0; i < 4; i++)
                            {
                                dt_agvtask agvtask = new dt_agvtask
                                {
                                    agv_materbarcode = "daiding",
                                    agv_barcode = "",
                                    //   agv_code = "正极1号AGV",
                                    agv_createtime = DateTime.Now,
                                    agv_realesstime = DateTime.Now,
                                    agv_fromaddress = "nou",
                                    agv_grade = 1,
                                    agv_materielid = "",
                                    agv_qty = 1,
                                    agv_tasknum = "KH-" + tasknum[i],
                                    agv_taskstate = "WaitStockOut",
                                    agv_tasktype = "TaskType_Outbound",
                                    agv_toaddress = "nou",
                                    agv_userid = "WCS",
                                    agv_worktype = 1,
                                    agv_remark = plc.PLCDescroption
                                };
                                if (plc.PLCDescroption.Contains("ZJSL"))
                                {
                                    agvtask.agv_code = "正极1号AGV";
                                    //调用WMS呼叫物料出库
                                    List<string> StockList = new List<string> { "ZXD0201", "ZXC0201", "ZXB0201", "ZXA0201" };
                                    MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(agvtask.agv_tasknum, StockList, 3, "", "", plc.PLCDescroption);
                                    WriteLog.Info($"{hksb}上料").Write($"正极1号AGV,MES返回数据:{JsonConvert.SerializeObject(WMSbackresult)},时间:" + DateTime.Now + "", $"{hksb}上料");
                                    if (WMSbackresult == null) { throw new Exception($"失败,任务号:{agvtask.agv_tasknum}"); }
                                    agvRepository.Add(agvtask, true);
                                    WriteLog.Info("Z_HKSB_UpTask").Write("Z_HKSB_UpTask" + agvtask.agv_tasknum + DateTime.Now, "Z_HKSB_UpTask");
                                }
                                else
                                {
                                    agvtask.agv_code = "负极1号AGV";
                                    //调用WMS呼叫物料出库
                                    List<string> StockList = new List<string> { "FXD0201", "FXC0201", "FXB0201", "FXA0201" };
                                    MESback WMSbackresult = MESAPIInvoke.OutNeedStosk(agvtask.agv_tasknum, StockList, 3, "", "", plc.PLCDescroption);
                                    WriteLog.Info($"{hksb}上料").Write($"负极1号AGV,MES返回数据:{JsonConvert.SerializeObject(WMSbackresult)},时间:" + DateTime.Now + "", $"{hksb}上料");
                                    if (WMSbackresult == null) { throw new Exception($"失败,任务号:{agvtask.agv_tasknum}"); }
                                    agvRepository.Add(agvtask, true);
                                    WriteLog.Info("Z_HKSB_UpTask").Write("Z_HKSB_UpTask" + agvtask.agv_tasknum + DateTime.Now, "Z_HKSB_UpTask");
                                }
                            }
                            plc.WriteValue(ConveyorLineInfoDBName.R_HKSB_IsWorkBatchNo.ToString(), plc.PLCDescroption, false).ToString();
                            return WebResponseContent.Instance.OK();
                        });
                        WriteLog.Info($"{hksb}上料").Write($"{hksb}结束,时间:" + DateTime.Now + $"   ----------{Environment.NewLine}", $"{hksb}上料");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    WriteLog.Info("Z_HKSB_UpTask").Write("Z_HKSB_UpTask" + ex.Message + DateTime.Now, "Z_HKSB_UpTask");
                }
                finally
                {
                    Interlocked.Exchange(ref _readZHKUPSignalso, 0);
                }
            }
        }
    }
}