Admin
3 天以前 bd6818fc9d40f343547bafca0743658f3c0379dc
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
155
156
157
158
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.IRepositories;
using WIDESEA_WCS.Jobs;
using WIDESEA_WCS.WCSClient;
using static System.Collections.Specialized.BitVector32;
using System.Threading;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using WIDESEA_Core.Extensions;
using HslCommunication;
using WIDESEA_Services;
using WIDESEA_Core.Utilities;
using WIDESEA_Services.Services;
using WIDESEA_Common.TaskEnum;
using WIDESEA_WCS.Jobs.ConveyorLine;
using WIDESEA_Common.LogEnum;
using WIDESEA_Common.Tools;
using WIDESEA_WCS.Jobs.ConveyorLine.InboundArea;
using WIDESEA_WCS.Jobs.ConveyorLine.OutboundArea;
 
namespace WIDESEA_WCS
{
    [DisallowConcurrentExecution]
    public class ConveyorLineDispatchJob : JobBase, IJob
    {
        /// <summary>
        /// 获取输送线信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task Execute(IJobExecutionContext context)
        {
            return Task.Run(() =>
            {
                var executeLog = ExecuteJob(context, () => Run(context));
            });
        }
 
 
        public string Run(IJobExecutionContext context)
        {
 
            using (VOLContext dbCcontext = new VOLContext())
            {
                IDt_PLCinfoHeadRepository _PLCinfoHeadRepository = new Dt_PLCinfoHeadRepository(dbCcontext);
                IDt_StationManagerRepository stationManagerRepository = new Dt_StationManagerRepository(dbCcontext);
                List<Dt_PLCinfoHead> _PLCinfoHeads = _PLCinfoHeadRepository.Find(r => r.plcinfo_equiptype == "ConveyorLine" && r.plcinfo_state == "Enable");
                IDt_TaskWCSinfoRepository taskWCSinfoRepository = new Dt_TaskWCSinfoRepository(dbCcontext);
                IDt_TaskRGVinfoRepository taskRGVinfoRepository = new Dt_TaskRGVinfoRepository(dbCcontext);
                if (null != _PLCinfoHeads)
                {
                    PLCClient client = WCSService.Clients.Find(r => r.PLCName == "LineDevice");
                    if (null == client || !client.IsConnected)
                    {
                        string str = "PLC: " + client.PLCName + ", Ip: " + client.PLCIPAddress + ", 与调度系统断开连接";
                        WriteLog.Info("PLC异常").Write(str, "PLC异常");
                        return "";
                    }
                    //说明是入库区的调度,查看入库区线体的运行模式                    
                    int modelResult = int.Parse(client.ReadValue(CLineInfoDBName.R_System_Inline_Run_Model.ToString(), "System").ToString());
                    if (modelResult == 3)
                    {
                        //1=手动  2=单机 3=联机
                        //入库申请站台调度 20101
                        bool modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_Normal_Model.ToString(), "System").ToString());
                        if (modelResult1)
                        {
                            //入库口
                            InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound");
                            //测量站台逻辑  10301
                            InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B");
                            //入库站台确认
                            InboundAreaDispatch.InboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client);
 
                            //出库站台确认
                            InboundAreaDispatch.OutboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client);
                        }
                        else
                        {
                            //应急模式
                            modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_Emery_Model.ToString(), "System").ToString());
                            if (modelResult1)
                            {
                                //左侧可用
                                modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_LeftState.ToString(), "System").ToString());
                                if (!modelResult1)
                                {
                                    //入库站台确认
                                    InboundAreaDispatch.InboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, true);
                                    //出库站台确认
                                    InboundAreaDispatch.OutboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, true);
 
                                    InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B_YJ");
 
                                    InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound_YJ");
                                }
                                else
                                {
                                    //右侧可用
                                    modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_RightState.ToString(), "System").ToString());
                                    if (!modelResult1)
                                    {
                                        InboundAreaDispatch.InboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, false);
 
                                        //出库站台确认
                                        InboundAreaDispatch.OutboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, false);
 
                                        InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B");
 
                                        InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound");
                                    }
                                }
                            }
                        }
 
                        //InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound");
                        ////测量站台逻辑  10301
                        //InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B");
                        ////入库站台确认
                        //InboundAreaDispatch.InboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client);
                        ////出库站台确认
                        //InboundAreaDispatch.OutboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client);
 
                        //称重站台调度 20201
                        InboundAreaDispatch.InboundWeighAction(taskWCSinfoRepository, client);
                        //出库RFID确认(测量)
                        InboundAreaDispatch.CheckBarcodeAction(taskWCSinfoRepository, client, "30301");
                        InboundAreaDispatch.CheckBarcodeAction(taskWCSinfoRepository, client, "30302");
 
                    }
                    //说明是出库区的调度,查看入库区线体的运行模式                    
                    modelResult = int.Parse(client.ReadValue(CLineInfoDBName.R_System_Inline_Run_Model.ToString(), "OutSystem").ToString());
 
                    //string rel = client.ReadValue(CLineInfoDBName.W_System_RGVState.ToString()).ToString();
                    if (modelResult == 3)
                    {
                        //出库区域调度
                        OutboundAreaDispatch.OutboundAreaDispathAction(taskWCSinfoRepository, taskRGVinfoRepository, client);
                    }
                    else if (modelResult == 2)
                    {
                        client.WriteValue(CLineInfoDBName.W_System_RGVState.ToString(), true);
                    }
                }
 
            }
            return "";
        }
    }
}