1
huanghongfeng
2025-03-24 4862490837e93ec1647acc537a4d79afb847be90
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Quartz;
using System.Text.RegularExpressions;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IOrderDetailsService _OrderDetailsService;
        private readonly IMapper _mapper;
 
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _OrderDetailsService = orderDetails;
            _mapper = mapper;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
               
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                
                if (conveyorLine != null)
                {
                    if (conveyorLine.Communicator.Read<bool>("DB7.3030.0"))   //申请
                    {
 
                        string Barcodes = conveyorLine.Communicator.Read<string>("DB7.3032");   //读条码
                        string pattern = @"\d+";  // 匹配数字
                        Match match = Regex.Match(Barcodes, pattern);
                        string barcodeNumber = match.Value;
                        if (barcodeNumber != "")
                        {
                            int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber);
                            if (toplc != -1)
                            {
                                conveyorLine.Communicator.Write("DB7.3022", (int)toplc);   //写入去向
                                conveyorLine.Communicator.Write("DB7.3028.0", (bool)true);    //写入反馈
                                WriteLog.Write_Log("扫码枪", "扫码站台", "成功", new { 信息 = $"条码:{barcodeNumber},写入去向{toplc}" });
                                if (conveyorLine.Communicator.Read<bool>("DB7.3116"))
                                {
                                    conveyorLine.Communicator.Write("DB7.3022", (int)0);   //清除写入去向
                                    conveyorLine.Communicator.Write("DB7.3028.0", (bool)false);   //清除写入反馈
                                    WriteLog.Write_Log("扫码枪", "扫码站台", "成功", new { 信息 = $"条码:{barcodeNumber},清除输送线反馈成功" });
                                    //调取反馈MES托盘条码
 
                                   var datast= _OrderDetailsService.ToMesBarc(int.Parse(barcodeNumber));
                                    if (datast.code==1)
                                    {
                                        WriteLog.Write_Log("ToMes", "条码反馈Mes", "成功", new { 信息 = $"条码:{barcodeNumber},反馈成功" });
                                    }
                                    else
                                    {
                                        WriteLog.Write_Log("ToMes", "条码反馈Mes", "失败", new { 信息 = $"条码:{barcodeNumber},反馈失败" });
                                    }
 
                                    
                                }
                                else
                                {
                                    WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { 信息 = $"条码:{barcodeNumber},清除输送线反馈失败" });
                                }
                            }
                            else
                            {
                                conveyorLine.Communicator.Write("DB7.3028.1", (bool)true);
                                WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { 信息 = $"条码:{barcodeNumber},未找到数据明细详情长度,写入报警信息" });
                            }
                        }
                        else
                        {
                            WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { 信息 = $"未读取到托盘条码,条码错误{barcodeNumber}" });
                        }
                    }
                    else
                    {
 
                        WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { 信息 = "未读取到扫码枪申请" });
                    }
                }
 
            }
            catch (Exception ex)
            {
                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
            }
            return Task.CompletedTask;
        }
 
        
    }
}