schangxiang@126.com
2024-11-22 48f4481b61e6da5878415c3bc7ad5a1881244a93
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
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCC.StationService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DBModel;
using iWareSql.WmsDBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Configuration;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XiGang.Core.Model;
 
namespace iWareCC.ThreadService
{
    /// <summary>
    /// BZ01工位(清灰,洗板后工位)
    /// </summary>
    public static class DataProcess_BZ01
    {
        /// <summary>
        /// BZ01工位(清灰,洗板后工位)
        /// </summary>
        public static async void Handler()
        {
            var alertMsg = "";
            LogType logType = LogType.DataProcess_BZ01;
            while (true)
            {
                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = string.Empty;
                try
                {
                    if (SystemValue.isAllowRuning_DataProcess_BZ01 && SystemValue.isStartedModel)
                    {
                        var rgvLocation = StationLocationEnum.BZ01.ToString();
                        /*
                         * 1、从数据库中判断是否齐套
                         * 2、根据齐套结果,推送给PLC
                         */
                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
                        if (obj.R_ReqParseData)
                        {
                            var result = obj.R_ReadCodeResult;
                            if (string.IsNullOrEmpty(result))
                            {
                                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束";
                                continue;
                            }
                            var upiCode = result;
                            var qitaoReault = false;
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
                                if (upiObj == null)
                                {
                                    SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                                    continue;
                                }
                                //查询是否齐包
                                var allList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList();
                                var isQiTaoList = allList.Where(x => x.AreaCode == (int)AreaCodeEnum.待缓存分拣区
                                ||
                                x.AreaCode == (int)AreaCodeEnum.缓存分拣区
                                 ||
                                x.AreaCode == (int)AreaCodeEnum.码垛区域
                                  ||
                                x.AreaCode == (int)AreaCodeEnum.机器人岛缓存区域
                                ).ToList();
                                if (isQiTaoList.Count() != allList.Count())
                                {//不齐包
                                    qitaoReault = false;
                                    upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                }
                                else
                                {//齐包
                                    qitaoReault = true;
                                    upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
                                }
 
                                using (StationServiceClient client = new StationServiceClient())
                                {
                                    var res = await client.WriteQiTaoInfoAsync((int)EDevice.Station, rgvLocation, qitaoReault);
                                    if (!res.result)
                                    {
                                        SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-推送齐套结果失败,WriteQiTaoInfoAsync返回:{res.resMsg}";
                                        continue;
                                    }
                                    else
                                    {
                                        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送齐套结果成功,WriteQiTaoInfoAsync,参数: 站点{rgvLocation},齐套结果:{qitaoReault}");
                                    }
                                }
 
                                //更新UPI状态
                                var upiObjList = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).ToList();
                                foreach (var item in upiObjList)
                                {
                                    if (qitaoReault)
                                    {
                                        item.UpiStatus = (int)UpiStatusEnum.已齐包;
                                    }
                                    else
                                    {
                                        item.UpiStatus = (int)UpiStatusEnum.不齐包;
                                    }
                                }
                                //更新 最后一次在 BZ_01的系统处理的板件 数据
                                var rbRunMode = wmsDB.wms_rbline_runmode.FirstOrDefault();
                                rbRunMode.PlanNo = upiObj.PlanNo;
                                rbRunMode.OrderId = upiObj.OrderId;
                                rbRunMode.PackageCode = upiObj.PackageCode;
 
                                wmsDB.SaveChanges();
                            }
 
 
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_alert_DataProcess_BZ01 += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
                }
            }
        }
 
    }
}