Admin
5 天以前 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
using HslCommunication;
using Microsoft.EntityFrameworkCore;
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.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.ConveyorLine.InboundArea
{
    public partial class InboundAreaDispatch
    {
        private static string InboundWeighStationNo = "20201";
        public static void InboundWeighAction(IDt_TaskWCSinfoRepository taskWCSinfoRepository, PLCClient client)
        {
            //读取设备正常
            try
            {
                int weightingResult = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_Weighting.ToString(), InboundWeighStationNo).ToString());
                int barcode = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_Barcode.ToString(), InboundWeighStationNo).ToString());
                int taskNumber = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_TaskNumber.ToString(), InboundWeighStationNo).ToString());
                Dt_TaskWCSinfo wcsInfo = taskWCSinfoRepository.FindFirst(x => x.wcstask_barcode == barcode.ToString() && x.wcstask_taskNumber == taskNumber);
                if (null != wcsInfo)
                {
                    var currentdt_taskinfo = taskWCSinfoRepository.DbContext.ChangeTracker.Entries<Dt_TaskWCSinfo>().FirstOrDefault();
                    if (currentdt_taskinfo != null)
                        currentdt_taskinfo.State = EntityState.Detached;
 
                    //避免应急模式称重有问题
                    if (wcsInfo.wcstask_type != TaskType.TaskType_Box_Pallet_Inbound.ToString()
                          && wcsInfo.wcstask_type != TaskType.TaskType_Empty_Pallet_Inbound.ToString())
                    {
                        if (weightingResult == 1)
                            return;
                        else if (weightingResult == 2)
                            client.WriteValue(CLineInfoDBName.W_Line_Weight_OK.ToString(), true);
                        return;
                    }
 
                    string str = string.Empty;
                    //称重中
                    if (weightingResult == 1)
                    {
                        WebResponseContent content = WMSApi.PostTaskStateToWMS(barcode.ToString(), TaskState.TaskState_Weighing.ToString());
                        if (content.Status)
                        {
                            wcsInfo.wcstask_state = TaskState.TaskState_Weighing.ToString();
                            wcsInfo.wcstask_dispatcherTime = DateTime.Now;
                            taskWCSinfoRepository.Update(wcsInfo, true);
 
                            str = $"{DateTime.Now}开始称重上报WMS成功,托盘号:{wcsInfo.wcstask_barcode},任务号:【{wcsInfo.wcstask_taskNumber}】";
                        }
                        else
                            str = $"{DateTime.Now}开始称重上报WMS失败,托盘号:{wcsInfo.wcstask_barcode},任务号:【{wcsInfo.wcstask_taskNumber}】,错误信息:{content.Message}";
                        WriteLog.Info(InboundWeighStationNo).Write(str, InboundWeighStationNo);
 
                    }//称重完成
                    else if (weightingResult == 2)
                    {
                        int weightResult = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_Weight.ToString(), InboundWeighStationNo).ToString());
                        WebResponseContent content = WMSApi.TellWmsWeightResult(wcsInfo.wcstask_barcode, weightResult.ToString());
                        if (content.Status)
                        {
                            str = $"{DateTime.Now}称重完成上报WMS成功,托盘号:{wcsInfo.wcstask_barcode},任务号:{wcsInfo.wcstask_taskNumber}";
                            WriteLog.Info(InboundWeighStationNo).Write(str, InboundWeighStationNo);
                            //上报重量结果后,在此通知线体继续任务,该为了人工手动
                            client.WriteValue(CLineInfoDBName.W_Line_Weight_OK.ToString(), true);
 
                            //称重完成后,在此更新任务状态、上报WMS任务状态
                            content = WMSApi.PostTaskStateToWMS(wcsInfo.wcstask_barcode, TaskState.TaskState_ConveyorLineExecuting.ToString());
                            if (content.Status)
                            {
                                wcsInfo.wcstask_state = TaskState.TaskState_ConveyorLineExecuting.ToString();
                                wcsInfo.wcstask_dispatcherTime = DateTime.Now;
                                taskWCSinfoRepository.Update(wcsInfo, true);
                            }
                        }
                        else
                        {
                            str = $"{DateTime.Now}称重完成上报WMS失败,托盘号:{wcsInfo.wcstask_barcode},任务号:{wcsInfo.wcstask_taskNumber},错误:{content.Message}";
                            WriteLog.Info(InboundWeighStationNo).Write(str, InboundWeighStationNo);
                        }
                    }
                }
 
            }
            catch (Exception ex)
            {
                WriteLog.Info(InboundWeighStationNo).Write($"称重站台调度失败:{ex.Message}", InboundWeighStationNo);
            }
        }
 
    }
 
 
}