222
schangxiang@126.com
2024-11-28 d3a84592bc645e929a702178497b570275e97ba8
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
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCC.StationService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DataAccess;
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 WZ.Useful.Commons;
using XiGang.Core.Model;
 
namespace iWareCC.ThreadService
{
    /// <summary>
    /// BZ30齐套验证
    /// </summary>
    public static class DataProcess_ValidateQiTao
    {
        public static async void Handler()
        {
            var alertMsg = "";
            LogType logType = LogType.DataProcess_ValidateQiTao;
            while (true)
            {
                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = string.Empty;
                try
                {
                    if (SystemValue.isAllowRuning_DataProcess_ValidateQiTao && SystemValue.isStartedModel)
                    {
                        var rgvLocation = StationLocationEnum.BZ39.ToString();
 
                        using (WmsDBModel wmsDB = new WmsDBModel())
                        {
                            var bz30Config = wmsDB.SysConfig.Where(x => x.Code == "wms_bz30_qitao").FirstOrDefault();
                            if (bz30Config == null)
                            {
                                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"没有配置 wms_bz30_qitao 值";
                                continue;
                            }
                            var configValue = bz30Config.Value;
                            if (string.IsNullOrEmpty(configValue) || configValue.IndexOf('|') <= -1)
                            {
                                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"配置 wms_bz30_qitao 值{configValue}为空或不正确";
                                continue;
                            }
                            var configValues = configValue.Split('|');
                            var packageCode = configValues[0];
                            var qitaoValue = configValues[1];//齐套  不齐套
 
                            //TODO:推送给PLC 去哪个方向?
                            /*
                            using (StationServiceClient client = new StationServiceClient())
                            {
                                var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.入库模式, rgvLocation);
                                if (!res.result)
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"{rgvLocation.ToString()}-推送给PLC切换模式 失败,ChangeModeAsync 返回:{res.resMsg}";
                                    continue;
                                }
                                else
                                {
                                    Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 成功,ChangeModeAsync,参数: 站点{rgvLocation}");
                                }
                            }
                            //*/
 
 
                            //更新值
                            bz30Config.Value = "";
                            var gahter = wmsDB.mes_package_gather.Where(x => x.PackageCode == packageCode).FirstOrDefault();
                            if (gahter != null)
                            {
                                gahter.UpiStatus = (int)UpiStatusEnum.已下线;
                                gahter.AreaCode = (int)AreaCodeEnum.下线区域;
                            }
                            var upiList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == packageCode).ToList();
                            foreach (var item in upiList)
                            {
                                item.UpiStatus = (int)UpiStatusEnum.已下线;
                                item.AreaCode = (int)AreaCodeEnum.下线区域;
                                item.UpdateTime = DateTime.Now;
                            }
                            //删除队列信息
                            var lineQueue = wmsDB.mes_package_linequeue.Where(x => x.PackageCode == packageCode).FirstOrDefault();
                            if (lineQueue != null)
                            {
                                wmsDB.mes_package_linequeue.Remove(lineQueue);
                            }
                            //新增下线记录
                            mes_package_unline_record record = new mes_package_unline_record();
                            record = ClassHelper.RotationMapping<mes_package_unline_record, mes_package_gather>(gahter);
                            record.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                            record.CreateTime = DateTime.Now;
                            record.UpdateTime = DateTime.Now;
                            record.OpRemark = "下线";
                            wmsDB.mes_package_unline_record.Add(record);
 
 
                            wmsDB.SaveChanges();
                        }
                    }
 
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
                }
            }
        }
 
    }
}