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
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
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 _readFINOUTSignalso = 0;
        public static object requestFJJK = new object();
        /// <summary>
        /// 正极和负极大及卷库出入库逻辑
        /// </summary>
        /// <returns></returns>
        public static void F_InOut_Djjk()
        {
 
            if (Interlocked.Exchange(ref _readFINOUTSignalso, 1) == 0)
            {
                try
                {
                    VOLContext Context = new VOLContext();
                    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> HCJnos = new List<string> {  "FJSL-FQHCJ001",
                        "FJSL-TBHCJ007","FJSL-TBHCJ008","FJSL-TBHCJ009","FJSL-TBHCJ010","FJSL-TBHCJ011","FJSL-TBHCJ012",
                        "FJSL-TBHCJ001","FJSL-TBHCJ002","FJSL-TBHCJ003","FJSL-TBHCJ004","FJSL-TBHCJ005","FJSL-TBHCJ006",
                   "FJSL-FQHCJ002","FJSL-GYHCJ001","FJSL-GYHCJ002","FJSL-GYHCJ003","FJSL-QXHCJ001","FJSL-QXHCJ002"};
                    PLCClient plc = null;
                    string toadd = "";
                    var task = agvRepository.FindFirst(f => (f.agv_toaddress.Contains("JJK") && f.agv_fromaddress.Contains("FJ")) || (f.agv_fromaddress == "nou" && f.agv_toaddress.Contains("HCJ") && f.agv_toaddress.Contains("FJ")));
                    if (task != null)
                    {
                        WriteLog.Info("F_InOut_Djjk").Write("负极大极卷库有正在执行的任务" + DateTime.Now, "F_InOut_Djjk");
                        return;
                    }
                    foreach (var hcj in HCJnos)
                    {
                        toadd = "FJXL-JJK001";
                        plc = WCSService.Clients.Find(v => v.PLCName == "负极1号AGV");
                        if (plc == null)
                            continue;
                        var iswork = plc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), toadd).ToString();
                        if (iswork == "2")
                            continue;
                        //读取有货无货信号
                        var isemptyorwork = plc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), hcj).ToString();
                        GetEquipmentInfo(toadd, hcj+"的货位状态是"+ isemptyorwork, "", "", iswork);
                        if (isemptyorwork == "1")
                            continue;
                        var location = locRepository.FindFirst(v => v.upper_code == hcj);
                        var stock = groupRepository.Find(v => v.location_id == location.id).OrderByDescending(v => v.created_time).FirstOrDefault();
                        var loc = locRepository.FindFirst(f => f.upper_code == "FJSL-JJK001" && f.down_code == "FJXL-JJK001");
                        if (stock == null)
                            continue;
                        //判断当前状态是否有更新
                        if (hcj.Contains("TB") && hcj.Contains("FJ"))
                        {
                            if (string.IsNullOrEmpty(stock.TB_Status))
                            {
                                continue;
                            }
                        }
                        else if (hcj.Contains("FQ") && hcj.Contains("FJ"))
                        {
                            if (string.IsNullOrEmpty(stock.QX_Status))
                            {
                                continue;
                            }
                        }
                        else if (hcj.Contains("QX") && hcj.Contains("FJ"))
                        {
                            if (string.IsNullOrEmpty(stock.GY_Status))
                            {
                                continue;
                            }
                        }
                        else if (hcj.Contains("GY") && hcj.Contains("FJ"))
                        {
                            if (string.IsNullOrEmpty(stock.TB_Status))
                            {
                                continue;
                            }
                        }
                        lock (requestFJJK)
                        {
                            if (loc.location_state == LocationStateEnum.LocationState_Empty.ToString() && location.location_state == LocationStateEnum.LocationState_Stored.ToString() && stock.BarCode != null && stock.MaterialStatus != null)
                            {
                                WebResponseContent responseContent = new WebResponseContent();
                                responseContent = locRepository.DbContextBeginTransaction(() =>
                                {
                                    MESback WMSbackresult = MESAPIInvoke.PreTask(2);
                                    if (WMSbackresult == null) 
                                    { 
                                        return WebResponseContent.Instance.Error("负极大极卷库不通过入库申请"); 
                                    }
                                    dt_agvtask agvtask = new dt_agvtask
                                    {
                                        agv_materbarcode = stock.BarCode,
                                        agv_barcode = "",
                                        agv_code = plc.PLCName,
                                        agv_createtime = DateTime.Now,
                                        agv_fromaddress = hcj,
                                        agv_grade = 1,
                                        agv_materielid = stock.MaterialType,
                                        agv_qty = 1,
                                        agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
                                        agv_taskstate = "Create",
                                        agv_tasktype = "TaskType_Outbound",
                                        agv_toaddress = toadd,
                                        agv_userid = "WCS",
                                        agv_worktype = 1
                                    };
                                    agvRepository.Add(agvtask, true);
                                    WriteLog.Info("F_InOut_Djjk").Write("F_InOut_Djjk" + agvtask.agv_tasknum + stock.BarCode + DateTime.Now, "F_InOut_Djjk");
                                    location.location_state = LocationStateEnum.LocationState_Lock.ToString();
                                    loc.location_state = LocationStateEnum.LocationState_Lock.ToString();
                                    locRepository.Update(loc, true);
                                    locRepository.Update(location, true);
                                    return WebResponseContent.Instance.OK();
                                });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteLog.Info("F_InOut_Djjk").Write("F_InOut_Djjk" + ex.Message  + DateTime.Now, "F_InOut_Djjk");
                }
                finally
                {
                    Interlocked.Exchange(ref _readFINOUTSignalso, 0);
                }
            }
        }
    }
}